]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Fix p2p service discovery android-jb
authorIrfan Sheriff <isheriff@google.com>
Thu, 9 Aug 2012 15:40:48 +0000 (18:40 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 24 Nov 2013 20:46:39 +0000 (22:46 +0200)
- Fix listen timing to improve SD reliability
- Fix SD packet scheduling

Bug: 6629112
Change-Id: I01365279439116256372d019bdbfd4b2113bf2ce

src/p2p/p2p.c
src/p2p/p2p_i.h
src/p2p/p2p_sd.c

index e52822de5224cb15751da7531ccf67808f86e712..3181b51c5c73eaf2b0a2f001093ab6c5782c8f41 100644 (file)
@@ -83,6 +83,12 @@ static void p2p_expire_peers(struct p2p_data *p2p)
 
                p2p_dbg(p2p, "Expiring old peer entry " MACSTR,
                        MAC2STR(dev->info.p2p_device_addr));
+#ifdef ANDROID_P2P
+               /* SD_FAIR_POLICY: Update the current sd_dev_list pointer to
+                * next device */
+               if (&dev->list == p2p->sd_dev_list)
+                       p2p->sd_dev_list = dev->list.next;
+#endif /* ANDROID_P2P */
                dl_list_del(&dev->list);
                p2p_device_free(p2p, dev);
        }
@@ -382,6 +388,12 @@ static struct p2p_device * p2p_create_device(struct p2p_data *p2p,
        }
        if (count + 1 > p2p->cfg->max_peers && oldest) {
                p2p_dbg(p2p, "Remove oldest peer entry to make room for a new peer");
+#ifdef ANDROID_P2P
+               /* SD_FAIR_POLICY: Update the current sd_dev_list pointer to
+                * next device */
+               if (&oldest->list == p2p->sd_dev_list)
+                       p2p->sd_dev_list = oldest->list.next;
+#endif /* ANDROID_P2P */
                dl_list_del(&oldest->list);
                p2p_device_free(p2p, oldest);
        }
@@ -923,7 +935,17 @@ static int p2p_run_after_scan(struct p2p_data *p2p)
                                      p2p->after_scan_tx->wait_time);
                os_free(p2p->after_scan_tx);
                p2p->after_scan_tx = NULL;
+#ifdef ANDROID_P2P
+               /* For SD frames, there is a scenario, where we can receive a
+                * SD request frame during p2p_scan. At that moment, we will
+                * send the SD response from this context. After sending the SD
+                * response, we need to continue p2p_find. But if we return 1
+                * from here, p2p_find is going to be stopped.
+                */
+               return 0;
+#else /* ANDROID_P2P */
                return 1;
+#endif /* ANDROID_P2P */
        }
 
        op = p2p->start_after_scan;
@@ -2384,7 +2406,18 @@ struct p2p_data * p2p_init(const struct p2p_config *cfg)
                        p2p->cfg->num_pref_chan = 0;
        }
 
+#ifdef ANDROID_P2P
+       /*
+        * 100 ms listen time is too short to receive the response frames in
+        * some scenarios. Increase min listen time to 200 ms.
+        */
+       p2p->min_disc_int = 2;
+       /* SD_FAIR_POLICY: Initializing the SD current serviced pointer to NULL
+        */
+       p2p->sd_dev_list = NULL;
+#else /* ANDROID_P2P */
        p2p->min_disc_int = 1;
+#endif /* ANDROID_P2P */
        p2p->max_disc_int = 3;
        p2p->max_disc_tu = -1;
 
@@ -2459,6 +2492,11 @@ void p2p_flush(struct p2p_data *p2p)
                dl_list_del(&dev->list);
                p2p_device_free(p2p, dev);
        }
+#ifdef ANDROID_P2P
+       /* SD_FAIR_POLICY: Initializing the SD current serviced pointer to NULL
+        */
+       p2p->sd_dev_list = NULL;
+#endif /* ANDROID_P2P */
        p2p_free_sd_queries(p2p);
        os_free(p2p->after_scan_tx);
        p2p->after_scan_tx = NULL;
@@ -2636,8 +2674,41 @@ int p2p_set_country(struct p2p_data *p2p, const char *country)
 void p2p_continue_find(struct p2p_data *p2p)
 {
        struct p2p_device *dev;
+#ifdef ANDROID_P2P
+       int skip = 1;
+#endif /* ANDROID_P2P */
        p2p_set_state(p2p, P2P_SEARCH);
        dl_list_for_each(dev, &p2p->devices, struct p2p_device, list) {
+#ifdef ANDROID_P2P
+               /* SD_FAIR_POLICY: We need to give chance to all devices in the
+                * device list. There may be a scenario, where a particular
+                * peer device have not registered any query response. When we
+                * send a SD request to such device, no response will be
+                * received. And if we continue to get probe responses from
+                * that device, and if that device happens to be on top in our
+                * device list, we will always continue to send SD requests
+                * always to that peer only. We will not be able to send SD
+                * requests to other devices in that case. This implementation
+                * keeps track of last serviced peer device. And then takes the
+                * next one from the device list, in the next iteration.
+                */
+               if (p2p->sd_dev_list && p2p->sd_dev_list != &p2p->devices) {
+                       if (skip) {
+                               if ((&dev->list == p2p->sd_dev_list)) {
+                                       skip = 0;
+                                       if (dev->list.next == &p2p->devices)
+                                               p2p->sd_dev_list = NULL;
+                               }
+                               continue;
+                       }
+               }
+               p2p->sd_dev_list = &dev->list;
+               wpa_printf(MSG_DEBUG, "P2P: ### Servicing %p dev->flags 0x%x "
+                          "SD schedule %s devaddr " MACSTR,
+                          p2p->sd_dev_list, dev->flags,
+                          dev->flags & P2P_DEV_SD_SCHEDULE ? "TRUE": "FALSE",
+                          MAC2STR(dev->info.p2p_device_addr));
+#endif /* ANDROID_P2P */
                if (dev->flags & P2P_DEV_SD_SCHEDULE) {
                        if (p2p_start_sd(p2p, dev) == 0)
                                return;
index efc163a08cff8dc880002b0b48281d71a59b7290..3a7ada5887f6418b8c2a07933667be505e87ae6e 100644 (file)
@@ -237,6 +237,14 @@ struct p2p_data {
         */
        struct dl_list devices;
 
+#ifdef ANDROID_P2P
+       /**
+        * sd_dev_list - device pointer to be serviced next
+        * for service discovery
+        */
+       struct dl_list *sd_dev_list;
+#endif /* ANDROID_P2P */
+
        /**
         * go_neg_peer - Pointer to GO Negotiation peer
         */
index 0e0c7f121e2f3b97943485a9225581bbe47a4ab8..8aeb3c98b817c75e20cdaee0d2840c62ff7c4fcb 100644 (file)
@@ -819,6 +819,20 @@ void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst,
                      const struct wpabuf *tlvs)
 {
        struct p2p_sd_query *q;
+#ifdef ANDROID_P2P
+       /* Currently, supplicant doesn't support more than one pending
+        * broadcast SD request. So reject if application is registering
+        * another one before cancelling the existing one.
+        */
+       for (q = p2p->sd_queries; q; q = q->next) {
+               if ((q->for_all_peers == 1) && !dst) {
+                       wpa_printf(MSG_ERROR, "P2P: Already one pending "
+                                  "Broadcast request. Please cancel the "
+                                  "current one before adding a new one");
+                       return NULL;
+               }
+       }
+#endif /* ANDROID_P2P */
 
        q = os_zalloc(sizeof(*q));
        if (q == NULL)
@@ -837,7 +851,7 @@ void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst,
 
        q->next = p2p->sd_queries;
        p2p->sd_queries = q;
-       p2p_dbg(p2p, "Added SD Query %p", q);
+       p2p_dbg(p2p, "Added SD Query %p for_all_peers %d", q, q->for_all_peers);
 
        if (dst == NULL) {
                struct p2p_device *dev;
@@ -871,7 +885,24 @@ void p2p_sd_service_update(struct p2p_data *p2p)
 int p2p_sd_cancel_request(struct p2p_data *p2p, void *req)
 {
        if (p2p_unlink_sd_query(p2p, req)) {
+#ifdef ANDROID_P2P
+       struct p2p_device *dev;
+       struct p2p_sd_query *q = req;
+#endif /* ANDROID_P2P */
                p2p_dbg(p2p, "Cancel pending SD query %p", req);
+#ifdef ANDROID_P2P
+               /* If the request is a bcast query, then clear the
+                * P2P_DEV_SD_INFO flag so that when new sd query is
+                * registered,* we will send the SD request frames to peer
+                * devices.
+                */
+               if (q->for_all_peers) {
+                       p2p->sd_dev_list = NULL;
+                       dl_list_for_each(dev, &p2p->devices,
+                                        struct p2p_device, list)
+                               dev->flags &= ~P2P_DEV_SD_INFO;
+               }
+#endif /* ANDROID_P2P */
                p2p_free_sd_query(req);
                return 0;
        }