[PATCH] Add blacklist command

Dmitry Shmidt dimitrysh
Wed Mar 16 14:32:18 PDT 2011


This command allows to network manager to avoid AP

Signed-off-by: Dmitry Shmidt <dimitrysh at google.com>
---
 wpa_supplicant/ctrl_iface.c |   62 +++++++++++++++++++++++++++++++++++++++=
++++
 1 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 9f06115..3c03680 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -38,6 +38,7 @@
 #include "bss.h"
 #include "scan.h"
 #include "ctrl_iface.h"
+#include "blacklist.h"

 extern struct wpa_driver_ops *wpa_drivers[];

@@ -899,6 +900,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 =3D=3D '\0') {
+		pos =3D buf;
+		end =3D buf + buflen;
+		e =3D wpa_s->blacklist;
+		while (e) {
+			ret =3D os_snprintf(pos, end-pos, MACSTR"\n", MAC2STR(e->bssid));
+			if ((ret < 0) || (ret >=3D end - pos))
+				return pos - buf;
+			pos +=3D ret;
+			e =3D e->next;
+		}
+		return pos - buf;
+	}
+
+	cmd++;
+	if (os_strncmp(cmd, "clear", 5) =3D=3D 0) {
+		wpa_blacklist_clear(wpa_s);
+		os_memcpy(buf, "OK\n", 3);
+		return 3;
+	}
+
+	wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid=3D'%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 =3D wpa_blacklist_add(wpa_s, bssid);
+	if (ret < 0)
+		return -1;
+	ret =3D 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)
 {
@@ -3113,6 +3163,18 @@ char * wpa_supplicant_ctrl_iface_process(struct
wpa_supplicant *wpa_s,
 	} else if (os_strncmp(buf, "BSSID ", 6) =3D=3D 0) {
 		if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
 			reply_len =3D -1;
+	} else if (os_strncmp(buf, "BLACKLIST", 9) =3D=3D 0) {
+		reply_len =3D wpa_supplicant_ctrl_iface_blacklist(wpa_s, buf + 9,
+							reply, reply_size);
+		if ((os_strlen(buf) > 10) && (reply_len =3D=3D 3)) {
+			struct wpa_blacklist *bl =3D wpa_s->blacklist;
+			if (os_strncmp(buf + 10, "clear", 5) =3D=3D 0 ||
+			    ((bl !=3D NULL) && (os_memcmp(bl->bssid, wpa_s->bssid, ETH_ALEN) =
=3D=3D 0))) {
+				wpa_s->disconnected =3D 0;
+				wpa_s->reassociate =3D 1;
+				wpa_supplicant_req_scan(wpa_s, 0, 0);
+			}
+		}
 	} else if (os_strcmp(buf, "LIST_NETWORKS") =3D=3D 0) {
 		reply_len =3D wpa_supplicant_ctrl_iface_list_networks(
 			wpa_s, reply, reply_size);
--=20
1.7.3.1


On Wed, Mar 16, 2011 at 2:37 PM, Dmitry Shmidt <dimitrysh at google.com> wrote=
:
> From 182ab2ccb445513decf835000a411ac41e4359ba Mon Sep 17 00:00:00 2001
> From: Dmitry Shmidt <dimitrysh at google.com>
> Date: Wed, 16 Mar 2011 14:32:18 -0700
> Subject: [PATCH] Add blacklist command
>
> This command allows to network manager to avoid AP
>
> Signed-off-by: Dmitry Shmidt <dimitrysh at google.com>
> ---
> =A0wpa_supplicant/ctrl_iface.c | =A0 62 +++++++++++++++++++++++++++++++++=
++++++++++
> =A01 files changed, 62 insertions(+), 0 deletions(-)
>
> diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
> index 9f06115..3c03680 100644
> --- a/wpa_supplicant/ctrl_iface.c
> +++ b/wpa_supplicant/ctrl_iface.c
> @@ -38,6 +38,7 @@
> =A0#include "bss.h"
> =A0#include "scan.h"
> =A0#include "ctrl_iface.h"
> +#include "blacklist.h"
>
> =A0extern struct wpa_driver_ops *wpa_drivers[];
>
> @@ -899,6 +900,55 @@ static int wpa_supplicant_ctrl_iface_bssid(struct
> wpa_supplicant *wpa_s,
> =A0}
>
>
> +static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wp=
a_s,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 char *cmd, char *buf, size_t buflen)
> +{
> + =A0 =A0 =A0 u8 bssid[ETH_ALEN];
> + =A0 =A0 =A0 struct wpa_blacklist *e;
> + =A0 =A0 =A0 char *pos, *end;
> + =A0 =A0 =A0 int ret;
> +
> + =A0 =A0 =A0 /* cmd: "BLACKLIST [<BSSID>]" */
> + =A0 =A0 =A0 if (*cmd =3D=3D '\0') {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 pos =3D buf;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 end =3D buf + buflen;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 e =3D wpa_s->blacklist;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 while (e) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D os_snprintf(pos, en=
d-pos, MACSTR"\n", MAC2STR(e->bssid));
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ((ret < 0) || (ret >=3D =
end - pos))
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return pos =
- buf;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pos +=3D ret;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 e =3D e->next;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return pos - buf;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 cmd++;
> + =A0 =A0 =A0 if (os_strncmp(cmd, "clear", 5) =3D=3D 0) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 wpa_blacklist_clear(wpa_s);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 os_memcpy(buf, "OK\n", 3);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 3;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid=3D'%s'",=
 cmd);
> + =A0 =A0 =A0 if (hwaddr_aton(cmd, bssid)) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid =
BSSID '%s'", cmd);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -1;
> + =A0 =A0 =A0 }
> +
> + =A0 =A0 =A0 /* Add the BSSID twice, so its count will be 2, causing it =
to be
> + =A0 =A0 =A0 =A0 =A0skipped when processing scan results. */
> + =A0 =A0 =A0 ret =3D wpa_blacklist_add(wpa_s, bssid);
> + =A0 =A0 =A0 if (ret !=3D 0)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -1;
> + =A0 =A0 =A0 ret =3D wpa_blacklist_add(wpa_s, bssid);
> + =A0 =A0 =A0 if (ret !=3D 0)
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -1;
> + =A0 =A0 =A0 os_memcpy(buf, "OK\n", 3);
> + =A0 =A0 =A0 return 3;
> +}
> +
> +
> =A0static int wpa_supplicant_ctrl_iface_list_networks(
> =A0 =A0 =A0 =A0struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
> =A0{
> @@ -3113,6 +3163,18 @@ char * wpa_supplicant_ctrl_iface_process(struct
> wpa_supplicant *wpa_s,
> =A0 =A0 =A0 =A0} else if (os_strncmp(buf, "BSSID ", 6) =3D=3D 0) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (wpa_supplicant_ctrl_iface_bssid(wpa_s,=
 buf + 6))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0reply_len =3D -1;
> + =A0 =A0 =A0 } else if (os_strncmp(buf, "BLACKLIST", 9) =3D=3D 0) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 reply_len =3D wpa_supplicant_ctrl_iface_bla=
cklist(wpa_s, buf + 9,
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 reply, reply_size);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 if ((os_strlen(buf) > 10) && (reply_len =3D=
=3D 3)) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct wpa_blacklist *bl =
=3D wpa_s->blacklist;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (os_strncmp(buf + 10, "c=
lear", 5) =3D=3D 0 ||
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ((bl !=3D NULL) && =
(os_memcmp(bl->bssid, wpa_s->bssid, ETH_ALEN) =3D=3D 0))) {
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 wpa_s->disc=
onnected =3D 0;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 wpa_s->reas=
sociate =3D 1;
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 wpa_supplic=
ant_req_scan(wpa_s, 0, 0);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0} else if (os_strcmp(buf, "LIST_NETWORKS") =3D=3D 0) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0reply_len =3D wpa_supplicant_ctrl_iface_li=
st_networks(
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0wpa_s, reply, reply_size);
> --
> 1.7.3.1
>



More information about the Hostap mailing list