]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P: Do not start multiple copies of same persistent group
authorJouni Malinen <jouni.malinen@atheros.com>
Fri, 19 Nov 2010 10:57:36 +0000 (12:57 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 19 Nov 2010 10:57:36 +0000 (12:57 +0200)
When running p2p_group_add persistent=<id>, verify whether the
requested group is already running and if so, do not try to
start another copy of it.

wpa_supplicant/p2p_supplicant.c

index fe96ff4576ee0a1daa26bbe0a386b069a65cbec8..318391b51d86c81eccd46ecf420c08c7e1e42f86 100644 (file)
@@ -180,6 +180,31 @@ static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface)
 }
 
 
+static struct wpa_supplicant * wpas_get_p2p_group(struct wpa_supplicant *wpa_s,
+                                                 const u8 *ssid,
+                                                 size_t ssid_len, int *go)
+{
+       struct wpa_ssid *s;
+
+       for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
+               for (s = wpa_s->conf->ssid; s; s = s->next) {
+                       if (s->disabled != 0 || !s->p2p_group ||
+                           s->ssid_len != ssid_len ||
+                           os_memcmp(ssid, s->ssid, ssid_len) != 0)
+                               continue;
+                       if (s->mode == WPAS_MODE_P2P_GO &&
+                           s != wpa_s->current_ssid)
+                               continue;
+                       if (go)
+                               *go = s->mode == WPAS_MODE_P2P_GO;
+                       return wpa_s;
+               }
+       }
+
+       return NULL;
+}
+
+
 static void wpas_p2p_group_delete(struct wpa_supplicant *wpa_s)
 {
        struct wpa_ssid *ssid;
@@ -3137,10 +3162,18 @@ int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s,
                                  int freq)
 {
        struct p2p_go_neg_results params;
+       int go = 0;
 
        if (ssid->disabled != 2 || ssid->ssid == NULL)
                return -1;
 
+       if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) &&
+           go == (ssid->mode == WPAS_MODE_P2P_GO)) {
+               wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is "
+                          "already running");
+               return 0;
+       }
+
        wpa_s->p2p_long_listen = 0;
        eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);