OSDN Git Service

Add blacklist command
authorDmitry Shmidt <dimitrysh@google.com>
Wed, 16 Mar 2011 21:32:18 +0000 (14:32 -0700)
committerDmitry Shmidt <dimitrysh@google.com>
Mon, 9 May 2011 21:24:52 +0000 (14:24 -0700)
This command allows to network manager to avoid AP

Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
wpa_supplicant/ctrl_iface.c

index 8604d16..14a2e54 100644 (file)
@@ -38,6 +38,7 @@
 #include "bss.h"
 #include "scan.h"
 #include "ctrl_iface.h"
+#include "blacklist.h"
 
 extern struct wpa_driver_ops *wpa_drivers[];
 
@@ -910,6 +911,55 @@ static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
 }
 
 
+static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
+                                       char *cmd, char *buf, size_t buflen)
+{
+       u8 bssid[ETH_ALEN];
+       struct wpa_blacklist *e;
+       char *pos, *end;
+       int ret;
+
+       /* cmd: "BLACKLIST [<BSSID>]" */
+       if (*cmd == '\0') {
+               pos = buf;
+               end = buf + buflen;
+               e = wpa_s->blacklist;
+               while (e) {
+                       ret = os_snprintf(pos, end-pos, MACSTR"\n", MAC2STR(e->bssid));
+                       if ((ret < 0) || (ret >= end - pos))
+                               return pos - buf;
+                       pos += ret;
+                       e = e->next;
+               }
+               return pos - buf;
+       }
+
+       cmd++;
+       if (os_strncmp(cmd, "clear", 5) == 0) {
+               wpa_blacklist_clear(wpa_s);
+               os_memcpy(buf, "OK\n", 3);
+               return 3;
+       }
+
+       wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
+       if (hwaddr_aton(cmd, bssid)) {
+               wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", cmd);
+               return -1;
+       }
+
+       /* Add the BSSID twice, so its count will be 2, causing it to be
+          skipped when processing scan results. */
+       ret = wpa_blacklist_add(wpa_s, bssid);
+       if (ret < 0)
+               return -1;
+       ret = wpa_blacklist_add(wpa_s, bssid);
+       if (ret < 0)
+               return -1;
+       os_memcpy(buf, "OK\n", 3);
+       return 3;
+}
+
+
 static int wpa_supplicant_ctrl_iface_list_networks(
        struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
 {
@@ -3171,6 +3221,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
                if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
                        reply_len = -1;
+       } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
+               reply_len = wpa_supplicant_ctrl_iface_blacklist(wpa_s, buf + 9,
+                                                       reply, reply_size);
        } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
                reply_len = wpa_supplicant_ctrl_iface_list_networks(
                        wpa_s, reply, reply_size);