P2P: Reject multi-channel concurrent operations depending on driver
[libeap.git] / wpa_supplicant / p2p_supplicant.c
index 71b08ad..3a153ec 100644 (file)
@@ -445,15 +445,17 @@ static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s,
                char psk[65];
                wpa_snprintf_hex(psk, sizeof(psk), ssid->psk, 32);
                wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
-                       "%s GO ssid=\"%s\" psk=%s go_dev_addr=" MACSTR "%s",
-                       wpa_s->ifname, ssid_txt, psk, MAC2STR(go_dev_addr),
+                       "%s GO ssid=\"%s\" freq=%d psk=%s go_dev_addr=" MACSTR
+                       "%s",
+                       wpa_s->ifname, ssid_txt, ssid->frequency, psk,
+                       MAC2STR(go_dev_addr),
                        persistent ? " [PERSISTENT]" : "");
                wpas_p2p_cross_connect_setup(wpa_s);
        } else {
                wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
-                       "%s GO ssid=\"%s\" passphrase=\"%s\" go_dev_addr="
-                       MACSTR "%s",
-                       wpa_s->ifname, ssid_txt,
+                       "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
+                       "go_dev_addr=" MACSTR "%s",
+                       wpa_s->ifname, ssid_txt, ssid->frequency,
                        ssid && ssid->passphrase ? ssid->passphrase : "",
                        MAC2STR(go_dev_addr),
                        persistent ? " [PERSISTENT]" : "");
@@ -698,11 +700,14 @@ static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s,
 static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s,
                                    struct p2p_go_neg_results *res)
 {
+       wpa_printf(MSG_DEBUG, "P2P: Start WPS Enrollee for peer " MACSTR,
+                  MAC2STR(res->peer_interface_addr));
+       wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID",
+                         res->ssid, res->ssid_len);
        wpa_supplicant_ap_deinit(wpa_s);
        wpas_copy_go_neg_results(wpa_s, res);
        if (res->wps_method == WPS_PBC)
-               wpas_wps_start_pbc(wpa_s, NULL /* res->peer_interface_addr */,
-                                  1);
+               wpas_wps_start_pbc(wpa_s, res->peer_interface_addr, 1);
        else {
                u16 dev_pw_id = DEV_PW_DEFAULT;
                if (wpa_s->p2p_wps_method == WPS_PIN_KEYPAD)
@@ -723,10 +728,11 @@ static void p2p_go_configured(void *ctx, void *data)
        if (ssid && ssid->mode == WPAS_MODE_P2P_GO) {
                wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning");
                wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
-                       "%s GO ssid=\"%s\" passphrase=\"%s\" go_dev_addr="
-                       MACSTR "%s",
+                       "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
+                       "go_dev_addr=" MACSTR "%s",
                        wpa_s->ifname,
                        wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
+                       ssid->frequency,
                        params->passphrase ? params->passphrase : "",
                        MAC2STR(wpa_s->parent->own_addr),
                        params->persistent_group ? " [PERSISTENT]" : "");
@@ -980,9 +986,9 @@ void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res)
        eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
 
        eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
-       /* TODO: add peer Config Timeout */
-       eloop_register_timeout(15, 0, wpas_p2p_group_formation_timeout, wpa_s,
-                              NULL);
+       eloop_register_timeout(15 + res->peer_config_timeout / 100,
+                              (res->peer_config_timeout % 100) * 10000,
+                              wpas_p2p_group_formation_timeout, wpa_s, NULL);
 }
 
 
@@ -1016,7 +1022,7 @@ static int wpas_start_listen(void *ctx, unsigned int freq,
 {
        struct wpa_supplicant *wpa_s = ctx;
 
-       wpa_drv_set_ap_wps_ie(wpa_s, NULL, probe_resp_ie);
+       wpa_drv_set_ap_wps_ie(wpa_s, NULL, probe_resp_ie, NULL);
 
        if (wpa_drv_probe_req_report(wpa_s, 1) < 0) {
                wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver to "
@@ -1043,7 +1049,7 @@ static int wpas_start_listen(void *ctx, unsigned int freq,
 static void wpas_stop_listen(void *ctx)
 {
        struct wpa_supplicant *wpa_s = ctx;
-       if (wpa_s->off_channel_freq) {
+       if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
                wpa_drv_cancel_remain_on_channel(wpa_s);
                wpa_s->off_channel_freq = 0;
                wpa_s->roc_waiting_drv_freq = 0;
@@ -1830,7 +1836,7 @@ static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid,
                if (s) {
                        wpas_p2p_group_add_persistent(
                                wpa_s, s, s->mode == WPAS_MODE_P2P_GO, 0);
-               } else {
+               } else if (bssid) {
                        wpas_p2p_join(wpa_s, bssid, go_dev_addr,
                                      wpa_s->p2p_wps_method);
                }
@@ -2196,6 +2202,8 @@ int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
                          p2p.ssid_postfix_len);
        }
 
+       p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss;
+
        global->p2p = p2p_init(&p2p);
        if (global->p2p == NULL)
                return -1;
@@ -2268,6 +2276,15 @@ void wpas_p2p_deinit_global(struct wpa_global *global)
                os_free(ifname);
        }
 
+       /*
+        * Deinit GO data on any possibly remaining interface (if main
+        * interface is used as GO).
+        */
+       for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
+               if (wpa_s->ap_iface)
+                       wpas_p2p_group_deinit(wpa_s);
+       }
+
        p2p_deinit(global->p2p);
        global->p2p = NULL;
 }
@@ -2490,6 +2507,15 @@ static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s)
        res.wps_method = wpa_s->pending_join_wps_method;
        wpas_start_wps_enrollee(group, &res);
 
+       /*
+        * Allow a longer timeout for join-a-running-group than normal 15
+        * second group formation timeout since the GO may not have authorized
+        * our connection yet.
+        */
+       eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
+       eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout,
+                              wpa_s, NULL);
+
        return 0;
 }
 
@@ -2506,14 +2532,16 @@ static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s)
  *     initiating Group Owner negotiation
  * @go_intent: GO Intent or -1 to use default
  * @freq: Frequency for the group or 0 for auto-selection
- * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on failure
+ * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
+ *     failure, -2 on failure due to channel not currently available,
+ *     -3 if forced channel is not supported
  */
 int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
                     const char *pin, enum p2p_wps_method wps_method,
                     int persistent_group, int join, int auth, int go_intent,
                     int freq)
 {
-       int force_freq = 0;
+       int force_freq = 0, oper_freq = 0;
        u8 bssid[ETH_ALEN];
        int ret = 0;
        enum wpa_driver_if_type iftype;
@@ -2559,21 +2587,52 @@ int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
                return ret;
        }
 
-       if (freq > 0)
-               force_freq = freq;
-       else if (wpa_s->current_ssid && wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
-                wpa_s->assoc_freq)
-               force_freq = wpa_s->assoc_freq;
+       if (wpa_s->current_ssid && wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
+           wpa_s->assoc_freq)
+               oper_freq = wpa_s->assoc_freq;
        else {
-               force_freq = wpa_drv_shared_freq(wpa_s);
-               if (force_freq < 0)
-                       force_freq = 0;
+               oper_freq = wpa_drv_shared_freq(wpa_s);
+               if (oper_freq < 0)
+                       oper_freq = 0;
        }
 
-       if (force_freq > 0) {
+       if (freq > 0) {
+               if (!p2p_supported_freq(wpa_s->global->p2p, freq)) {
+                       wpa_printf(MSG_DEBUG, "P2P: The forced channel "
+                                  "(%u MHz) is not supported for P2P uses",
+                                  freq);
+                       return -3;
+               }
+
+               if (oper_freq > 0 && freq != oper_freq &&
+                   !(wpa_s->drv_flags &
+                     WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT)) {
+                       wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group "
+                                  "on %u MHz while connected on another "
+                                  "channel (%u MHz)", freq, oper_freq);
+                       return -2;
+               }
+               wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
+                          "requested channel (%u MHz)", freq);
+               force_freq = freq;
+       } else if (oper_freq > 0 &&
+                  !p2p_supported_freq(wpa_s->global->p2p, oper_freq)) {
+               if (!(wpa_s->drv_flags &
+                     WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT)) {
+                       wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group "
+                                  "while connected on non-P2P supported "
+                                  "channel (%u MHz)", oper_freq);
+                       return -2;
+               }
+               wpa_printf(MSG_DEBUG, "P2P: Current operating channel "
+                          "(%u MHz) not available for P2P - try to use "
+                          "another channel", oper_freq);
+               force_freq = 0;
+       } else if (oper_freq > 0) {
                wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
                           "channel we are already using (%u MHz) on another "
-                          "interface", force_freq);
+                          "interface", oper_freq);
+               force_freq = oper_freq;
        }
 
        wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s);
@@ -3249,15 +3308,16 @@ void wpas_p2p_completed(struct wpa_supplicant *wpa_s)
                char psk[65];
                wpa_snprintf_hex(psk, sizeof(psk), ssid->psk, 32);
                wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
-                       "%s client ssid=\"%s\" psk=%s go_dev_addr=" MACSTR
-                       "%s",
-                       wpa_s->ifname, ssid_txt, psk, MAC2STR(go_dev_addr),
+                       "%s client ssid=\"%s\" freq=%d psk=%s go_dev_addr="
+                       MACSTR "%s",
+                       wpa_s->ifname, ssid_txt, ssid->frequency, psk,
+                       MAC2STR(go_dev_addr),
                        persistent ? " [PERSISTENT]" : "");
        } else {
                wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
-                       "%s client ssid=\"%s\" passphrase=\"%s\" go_dev_addr="
-                       MACSTR "%s",
-                       wpa_s->ifname, ssid_txt,
+                       "%s client ssid=\"%s\" freq=%d passphrase=\"%s\" "
+                       "go_dev_addr=" MACSTR "%s",
+                       wpa_s->ifname, ssid_txt, ssid->frequency,
                        ssid->passphrase ? ssid->passphrase : "",
                        MAC2STR(go_dev_addr),
                        persistent ? " [PERSISTENT]" : "");
@@ -3317,6 +3377,9 @@ void wpas_p2p_update_config(struct wpa_supplicant *wpa_s)
        if (p2p == NULL)
                return;
 
+       if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
+               return;
+
        if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME)
                p2p_set_dev_name(p2p, wpa_s->conf->device_name);
 
@@ -3368,6 +3431,9 @@ void wpas_p2p_update_config(struct wpa_supplicant *wpa_s)
                                     os_strlen(wpa_s->conf->p2p_ssid_postfix) :
                                     0);
        }
+
+       if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS)
+               p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss);
 }
 
 
@@ -3511,3 +3577,16 @@ static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s)
                break;
        }
 }
+
+
+int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s)
+{
+       if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT &&
+           !wpa_s->p2p_in_provisioning)
+               return 0; /* not P2P client operation */
+
+       wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC "
+                  "session overlap");
+       wpas_group_formation_completed(wpa_s, 0);
+       return 1;
+}