[PATCH 1/2] New bgscan operation for list of candidates

Gery Kahn geryk
Thu Jul 28 06:40:44 PDT 2011


Add new bgscan operation list_candidates which fills provided buffer with
candidates information.
The solution exists only for bgscan_learn, because there is no
candidates in bgscan_simple.

Signed-off-by: Gery Kahn <geryk at ti.com>
---
 wpa_supplicant/bgscan.c       |   10 ++++++++++
 wpa_supplicant/bgscan.h       |    9 +++++++++
 wpa_supplicant/bgscan_learn.c |   39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/wpa_supplicant/bgscan.c b/wpa_supplicant/bgscan.c
index 5661830..6d9491c 100644
--- a/wpa_supplicant/bgscan.c
+++ b/wpa_supplicant/bgscan.c
@@ -121,3 +121,13 @@ void bgscan_notify_signal_change(struct wpa_supplicant *wpa_s, int above,
 						    current_noise,
 						    current_txrate);
 }
+
+int bgscan_list_candidates(struct wpa_supplicant *wpa_s,
+			    char *buf, size_t buflen)
+{
+	if (wpa_s->bgscan && wpa_s->bgscan_priv &&
+	    wpa_s->bgscan->list_candidates)
+		return wpa_s->bgscan->list_candidates(wpa_s->bgscan_priv,
+						      buf, buflen);
+	return 0;
+}
diff --git a/wpa_supplicant/bgscan.h b/wpa_supplicant/bgscan.h
index ae94a48..7d4dddf 100644
--- a/wpa_supplicant/bgscan.h
+++ b/wpa_supplicant/bgscan.h
@@ -31,6 +31,7 @@ struct bgscan_ops {
 				     int current_signal,
 				     int current_noise,
 				     int current_txrate);
+	int (*list_candidates)(void *priv, char *buf, size_t buflen);
 };
 
 #ifdef CONFIG_BGSCAN
@@ -43,6 +44,8 @@ void bgscan_notify_beacon_loss(struct wpa_supplicant *wpa_s);
 void bgscan_notify_signal_change(struct wpa_supplicant *wpa_s, int above,
 				 int current_signal, int current_noise,
 				 int current_txrate);
+int bgscan_list_candidates(struct wpa_supplicant *wpa_s,
+			    char *buf, size_t buflen);
 
 #else /* CONFIG_BGSCAN */
 
@@ -73,6 +76,12 @@ static inline void bgscan_notify_signal_change(struct wpa_supplicant *wpa_s,
 {
 }
 
+static inline int bgscan_list_candidates(struct wpa_supplicant *wpa_s,
+				   char *buf, size_t buflen)
+{
+	return 0;
+}
+
 #endif /* CONFIG_BGSCAN */
 
 #endif /* BGSCAN_H */
diff --git a/wpa_supplicant/bgscan_learn.c b/wpa_supplicant/bgscan_learn.c
index ee79511..2e60bf8 100644
--- a/wpa_supplicant/bgscan_learn.c
+++ b/wpa_supplicant/bgscan_learn.c
@@ -603,6 +603,44 @@ static void bgscan_learn_notify_signal_change(void *priv, int above,
 	}
 }
 
+static int bgscan_learn_list_candidates(void *priv, char *buf, size_t buflen)
+{
+	char *pos, *end;
+	int ret;
+	struct bgscan_learn_bss *bss;
+	struct bgscan_learn_data *data = priv;
+
+	pos = buf;
+	end = buf + buflen;
+
+	if (!data)
+		return pos - buf;
+
+	dl_list_for_each(bss, &data->bss, struct bgscan_learn_bss, list) {
+		ret = os_snprintf(pos, end - pos,
+			"BSS " MACSTR " %d\n",
+			MAC2STR(bss->bssid), bss->freq);
+		if (ret < 0 || ret >= end - pos)
+			return pos - buf;
+		pos += ret;
+	}
+
+	dl_list_for_each(bss, &data->bss, struct bgscan_learn_bss, list) {
+		size_t i;
+		for (i = 0; i < bss->num_neigh; i++) {
+			ret = os_snprintf(pos, end - pos,
+				"NEIGHBOR " MACSTR " " MACSTR "\n",
+				MAC2STR(bss->bssid),
+				MAC2STR(bss->neigh + i * ETH_ALEN));
+			if (ret < 0 || ret >= end - pos)
+				return pos - buf;
+			pos += ret;
+		}
+	}
+
+	return pos - buf;
+}
+
 
 const struct bgscan_ops bgscan_learn_ops = {
 	.name = "learn",
@@ -611,4 +649,5 @@ const struct bgscan_ops bgscan_learn_ops = {
 	.notify_scan = bgscan_learn_notify_scan,
 	.notify_beacon_loss = bgscan_learn_notify_beacon_loss,
 	.notify_signal_change = bgscan_learn_notify_signal_change,
+	.list_candidates = bgscan_learn_list_candidates,
 };
-- 
1.7.0.4




More information about the Hostap mailing list