Browse Source

P2P: Verify that p2p_connect forced frequency is allowed for P2P

Do not accept forced frequency unless the specified channel is
allowed for P2P, i.e., is included in the local list of
advertised channels.
Jouni Malinen 14 years ago
parent
commit
1e19f73495
1 changed files with 24 additions and 4 deletions
  1. 24 4
      src/p2p/p2p.c

+ 24 - 4
src/p2p/p2p.c

@@ -812,14 +812,24 @@ int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
 		wps_method, persistent_group);
 
 	if (force_freq) {
+		u8 op_reg_class, op_channel;
 		if (p2p_freq_to_channel(p2p->cfg->country, force_freq,
-					&p2p->op_reg_class, &p2p->op_channel) <
-		    0) {
+					&op_reg_class, &op_channel) < 0) {
 			wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
 				"P2P: Unsupported frequency %u MHz",
 				force_freq);
 			return -1;
 		}
+		if (!p2p_channels_includes(&p2p->cfg->channels, op_reg_class,
+					   op_channel)) {
+			wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
+				"P2P: Frequency %u MHz (oper_class %u "
+				"channel %u) not allowed for P2P",
+				force_freq, op_reg_class, op_channel);
+			return -1;
+		}
+		p2p->op_reg_class = op_reg_class;
+		p2p->op_channel = op_channel;
 		p2p->channels.reg_classes = 1;
 		p2p->channels.reg_class[0].channels = 1;
 		p2p->channels.reg_class[0].reg_class = p2p->op_reg_class;
@@ -919,14 +929,24 @@ int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr,
 		wps_method, persistent_group);
 
 	if (force_freq) {
+		u8 op_reg_class, op_channel;
 		if (p2p_freq_to_channel(p2p->cfg->country, force_freq,
-					&p2p->op_reg_class, &p2p->op_channel) <
-		    0) {
+					&op_reg_class, &op_channel) < 0) {
 			wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
 				"P2P: Unsupported frequency %u MHz",
 				force_freq);
 			return -1;
 		}
+		if (!p2p_channels_includes(&p2p->cfg->channels, op_reg_class,
+					   op_channel)) {
+			wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
+				"P2P: Frequency %u MHz (oper_class %u "
+				"channel %u) not allowed for P2P",
+				force_freq, op_reg_class, op_channel);
+			return -1;
+		}
+		p2p->op_reg_class = op_reg_class;
+		p2p->op_channel = op_channel;
 		p2p->channels.reg_classes = 1;
 		p2p->channels.reg_class[0].channels = 1;
 		p2p->channels.reg_class[0].reg_class = p2p->op_reg_class;