P2P: Verify that p2p_connect forced frequency is allowed for P2P
authorJouni Malinen <jouni.malinen@atheros.com>
Thu, 14 Oct 2010 09:39:40 +0000 (12:39 +0300)
committerJouni Malinen <j@w1.fi>
Thu, 14 Oct 2010 09:42:17 +0000 (12:42 +0300)
Do not accept forced frequency unless the specified channel is
allowed for P2P, i.e., is included in the local list of
advertised channels.

src/p2p/p2p.c

index ff4d027..e8a2add 100644 (file)
@@ -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;