]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add RANGE=ALL|N1-N2 selection for ctrl_iface BSS command
authorDmitry Shmidt <dimitrysh@google.com>
Sat, 7 Apr 2012 09:49:31 +0000 (12:49 +0300)
committerJouni Malinen <j@w1.fi>
Thu, 9 Aug 2012 20:06:03 +0000 (23:06 +0300)
Add ability to get information about several BSS's in one call.

Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
(cherry picked from commit eff1a95b9763a7b8b5e25c8ef1eb911ab479afa0)

wpa_supplicant/ctrl_iface.c

index 2d9a6dbef8cff5a045f619f423bad76f1aac2386..76ff9cdd37d6a39eaabaa55555cee82e5021266a 100644 (file)
@@ -2389,10 +2389,54 @@ static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
        u8 bssid[ETH_ALEN];
        size_t i;
        struct wpa_bss *bss;
+       struct wpa_bss *bsslast = NULL;
+       struct dl_list *next;
+       int ret = 0;
+       int len;
        char *ctmp;
        unsigned long mask = WPA_BSS_MASK_ALL;
 
-       if (os_strcmp(cmd, "FIRST") == 0)
+       if (os_strncmp(cmd, "RANGE=", 6) == 0) {
+               if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
+                       bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
+                                           list_id);
+                       bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
+                                              list_id);
+               } else { /* N1-N2 */
+                       unsigned int id1, id2;
+
+                       if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
+                               wpa_printf(MSG_INFO, "Wrong BSS range "
+                                          "format");
+                               return 0;
+                       }
+
+                       id1 = atoi(cmd + 6);
+                       bss = wpa_bss_get_id(wpa_s, id1);
+                       id2 = atoi(ctmp + 1);
+                       if (id2 == 0)
+                               bsslast = dl_list_last(&wpa_s->bss_id,
+                                                      struct wpa_bss,
+                                                      list_id);
+                       else {
+                               bsslast = wpa_bss_get_id(wpa_s, id2);
+                               if (bsslast == NULL && bss && id2 > id1) {
+                                       struct wpa_bss *tmp = bss;
+                                       for (;;) {
+                                               next = tmp->list_id.next;
+                                               if (next == &wpa_s->bss_id)
+                                                       break;
+                                               tmp = dl_list_entry(
+                                                       next, struct wpa_bss,
+                                                       list_id);
+                                               if (tmp->id > id2)
+                                                       break;
+                                               bsslast = tmp;
+                                       }
+                               }
+                       }
+               }
+       } else if (os_strcmp(cmd, "FIRST") == 0)
                bss = dl_list_first(&wpa_s->bss, struct wpa_bss, list);
        else if (os_strncmp(cmd, "ID-", 3) == 0) {
                i = atoi(cmd + 3);
@@ -2401,7 +2445,7 @@ static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
                i = atoi(cmd + 5);
                bss = wpa_bss_get_id(wpa_s, i);
                if (bss) {
-                       struct dl_list *next = bss->list_id.next;
+                       next = bss->list_id.next;
                        if (next == &wpa_s->bss_id)
                                bss = NULL;
                        else
@@ -2439,7 +2483,22 @@ static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
        if (bss == NULL)
                return 0;
 
-       return print_bss_info(wpa_s, bss, mask, buf, buflen);
+       if (bsslast == NULL)
+               bsslast = bss;
+       do {
+               len = print_bss_info(wpa_s, bss, mask, buf, buflen);
+               ret += len;
+               buf += len;
+               buflen -= len;
+               if (bss == bsslast)
+                       break;
+               next = bss->list_id.next;
+               if (next == &wpa_s->bss_id)
+                       break;
+               bss = dl_list_entry(next, struct wpa_bss, list_id);
+       } while (bss && len);
+
+       return ret;
 }