]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P: Send received Presence Response information to ctrl_iface monitors
authorJouni Malinen <j@w1.fi>
Wed, 1 Jan 2014 16:44:44 +0000 (18:44 +0200)
committerJouni Malinen <j@w1.fi>
Wed, 1 Jan 2014 16:44:44 +0000 (18:44 +0200)
The P2P_PRESENCE_REQ command did not give any easily available
indication of the response received from the GO. Make this more useful
by providing such response (if received) as a ctrl_iface monitor event
(P2P-PRESENCE-RESPONSE).

Signed-hostap: Jouni Malinen <j@w1.fi>

src/common/wpa_ctrl.h
src/p2p/p2p.c
src/p2p/p2p.h
wpa_supplicant/README-P2P
wpa_supplicant/p2p_supplicant.c
wpa_supplicant/wpa_supplicant_i.h

index 1c9588164ca44df3065172cf882973575f0c6413..030df130da63ba27f2f8e41f45ca6b3fc5b13f95 100644 (file)
@@ -147,6 +147,7 @@ extern "C" {
 #define P2P_EVENT_INVITATION_RESULT "P2P-INVITATION-RESULT "
 #define P2P_EVENT_FIND_STOPPED "P2P-FIND-STOPPED "
 #define P2P_EVENT_PERSISTENT_PSK_FAIL "P2P-PERSISTENT-PSK-FAIL id="
+#define P2P_EVENT_PRESENCE_RESPONSE "P2P-PRESENCE-RESPONSE "
 
 /* parameters: <PMF enabled> <timeout in ms> <Session Information URL> */
 #define ESS_DISASSOC_IMMINENT "ESS-DISASSOC-IMMINENT "
index 23b74c0eb9df4fe4727dca389f8a5cadfd87a87a..2a13736cdd9bc8cdf734eb4fa203626638691c72 100644 (file)
@@ -3770,6 +3770,11 @@ static void p2p_process_presence_resp(struct p2p_data *p2p, const u8 *da,
                return;
        }
 
+       if (p2p->cfg->presence_resp) {
+               p2p->cfg->presence_resp(p2p->cfg->cb_ctx, sa, *msg.status,
+                                       msg.noa, msg.noa_len);
+       }
+
        if (*msg.status) {
                p2p_dbg(p2p, "P2P Presence Request was rejected: status %u",
                        *msg.status);
index bff78ef99fecaf34bba68cd2db41f66b7484b10c..f35a2363eb83677cf3d22643e4e9f634b65a130c 100644 (file)
@@ -778,6 +778,17 @@ struct p2p_config {
         * or 0 if not.
         */
        int (*go_connected)(void *ctx, const u8 *dev_addr);
+
+       /**
+        * presence_resp - Callback on Presence Response
+        * @ctx: Callback context from cb_ctx
+        * @src: Source address (GO's P2P Interface Address)
+        * @status: Result of the request (P2P_SC_*)
+        * @noa: Returned NoA value
+        * @noa_len: Length of the NoA buffer in octets
+        */
+       void (*presence_resp)(void *ctx, const u8 *src, u8 status,
+                             const u8 *noa, size_t noa_len);
 };
 
 
index ffc2baf06bdc1d21fbce40c92857c0a3516fb0bf..08d39e246656e5284d57ed799a4e3470e068c2ca 100644 (file)
@@ -418,9 +418,11 @@ p2p_presence_req [<duration> <interval>] [<duration> <interval>]
 Send a P2P Presence Request to the GO (this is only available when
 acting as a P2P client). If no duration/interval pairs are given, the
 request indicates that this client has no special needs for GO
-presence. the first parameter pair gives the preferred duration and
+presence. The first parameter pair gives the preferred duration and
 interval values in microseconds. If the second pair is included, that
-indicates which value would be acceptable.
+indicates which value would be acceptable. This command returns OK
+immediately and the response from the GO is indicated in a
+P2P-PRESENCE-RESPONSE event message.
 
 Parameters
 
index c01c684017fd8c518aa080b7284813c15211804a..a71cbbec959dd575ac7f8ae277e4a80462c35903 100644 (file)
@@ -489,6 +489,8 @@ static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s,
        os_free(wpa_s->go_params);
        wpa_s->go_params = NULL;
 
+       wpa_s->waiting_presence_resp = 0;
+
        wpa_printf(MSG_DEBUG, "P2P: Remove temporary group network");
        if (ssid && (ssid->p2p_group ||
                     ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION ||
@@ -3364,6 +3366,28 @@ int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s)
 }
 
 
+static void wpas_presence_resp(void *ctx, const u8 *src, u8 status,
+                              const u8 *noa, size_t noa_len)
+{
+       struct wpa_supplicant *wpa_s, *intf = ctx;
+       char hex[100];
+
+       for (wpa_s = intf->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
+               if (wpa_s->waiting_presence_resp)
+                       break;
+       }
+       if (!wpa_s) {
+               wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No group interface was waiting for presence response");
+               return;
+       }
+       wpa_s->waiting_presence_resp = 0;
+
+       wpa_snprintf_hex(hex, sizeof(hex), noa, noa_len);
+       wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PRESENCE_RESPONSE "src=" MACSTR
+               " status=%u noa=%s", MAC2STR(src), status, hex);
+}
+
+
 /**
  * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
  * @global: Pointer to global data from wpa_supplicant_init()
@@ -3409,6 +3433,7 @@ int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
        p2p.invitation_result = wpas_invitation_result;
        p2p.get_noa = wpas_get_noa;
        p2p.go_connected = wpas_go_connected;
+       p2p.presence_resp = wpas_presence_resp;
 
        os_memcpy(wpa_s->global->p2p_dev_addr, wpa_s->own_addr, ETH_ALEN);
        os_memcpy(p2p.dev_addr, wpa_s->global->p2p_dev_addr, ETH_ALEN);
@@ -5434,6 +5459,8 @@ done:
 int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1,
                          u32 interval1, u32 duration2, u32 interval2)
 {
+       int ret;
+
        if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
                return -1;
 
@@ -5442,9 +5469,13 @@ int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1,
            wpa_s->current_ssid->mode != WPAS_MODE_INFRA)
                return -1;
 
-       return p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid,
-                               wpa_s->own_addr, wpa_s->assoc_freq,
-                               duration1, interval1, duration2, interval2);
+       ret = p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid,
+                              wpa_s->own_addr, wpa_s->assoc_freq,
+                              duration1, interval1, duration2, interval2);
+       if (ret == 0)
+               wpa_s->waiting_presence_resp = 1;
+
+       return ret;
 }
 
 
index 29ed0241824081d2104d07df282b65b3776addb2..2e3f24494c15a3282cb9ddb141394eb2cafdbcf4 100644 (file)
@@ -663,6 +663,7 @@ struct wpa_supplicant {
        unsigned int p2p_go_vht:1;
        unsigned int user_initiated_pd:1;
        unsigned int p2p_go_group_formation_completed:1;
+       unsigned int waiting_presence_resp;
        int p2p_first_connection_timeout;
        int p2p_persistent_go_freq;
        int p2p_persistent_id;