P2P: Verify operating channel validity for NFC connection handover
[mech_eap.git] / src / p2p / p2p.c
index bcc7e64..ea82ae8 100644 (file)
@@ -4463,12 +4463,24 @@ static struct wpabuf * p2p_build_nfc_handover(struct p2p_data *p2p,
        p2p_buf_add_device_info(buf, p2p, NULL);
 
        if (p2p->num_groups > 0) {
+               int freq = p2p_group_get_freq(p2p->groups[0]);
                role = P2P_GO_IN_A_GROUP;
-               p2p_freq_to_channel(p2p_group_get_freq(p2p->groups[0]),
-                                   &op_class, &channel);
+               if (p2p_freq_to_channel(freq, &op_class, &channel) < 0) {
+                       p2p_dbg(p2p,
+                               "Unknown GO operating frequency %d MHz for NFC handover",
+                               freq);
+                       wpabuf_free(buf);
+                       return NULL;
+               }
        } else if (client_freq > 0) {
                role = P2P_CLIENT_IN_A_GROUP;
-               p2p_freq_to_channel(client_freq, &op_class, &channel);
+               if (p2p_freq_to_channel(client_freq, &op_class, &channel) < 0) {
+                       p2p_dbg(p2p,
+                               "Unknown client operating frequency %d MHz for NFC handover",
+                               client_freq);
+                       wpabuf_free(buf);
+                       return NULL;
+               }
        }
 
        p2p_buf_add_oob_go_neg_channel(buf, p2p->cfg->country, op_class,