[RFC v1 PATCH 1/2] events: Handle survey event properly into wpa_supplicant
Tomasz Bursztyka
tomasz.bursztyka
Mon Sep 9 03:30:48 PDT 2013
Let's reuse hostapd code for such handling. This will be useful to get
ACS support into wpa_supplicant where this one needs to handle the
survey event so it fills in the result ACS subsystem will require.
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka at linux.intel.com>
---
src/ap/drv_callbacks.c | 132 ++++++++++++++++++++++++------------------------
src/ap/hostapd.h | 4 ++
wpa_supplicant/events.c | 7 +++
3 files changed, 77 insertions(+), 66 deletions(-)
diff --git a/src/ap/drv_callbacks.c b/src/ap/drv_callbacks.c
index d6bc98d..427e31b 100644
--- a/src/ap/drv_callbacks.c
+++ b/src/ap/drv_callbacks.c
@@ -438,6 +438,72 @@ int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
}
+static struct hostapd_channel_data * hostapd_get_mode_channel(
+ struct hostapd_iface *iface, unsigned int freq)
+{
+ int i;
+ struct hostapd_channel_data *chan;
+
+ for (i = 0; i < iface->current_mode->num_channels; i++) {
+ chan = &iface->current_mode->channels[i];
+ if (!chan)
+ return NULL;
+ if ((unsigned int) chan->freq == freq)
+ return chan;
+ }
+
+ return NULL;
+}
+
+
+static void hostapd_update_nf(struct hostapd_iface *iface,
+ struct hostapd_channel_data *chan,
+ struct freq_survey *survey)
+{
+ if (!iface->chans_surveyed) {
+ chan->min_nf = survey->nf;
+ iface->lowest_nf = survey->nf;
+ } else {
+ if (dl_list_empty(&chan->survey_list))
+ chan->min_nf = survey->nf;
+ else if (survey->nf < chan->min_nf)
+ chan->min_nf = survey->nf;
+ if (survey->nf < iface->lowest_nf)
+ iface->lowest_nf = survey->nf;
+ }
+}
+
+
+void hostapd_event_get_survey(struct hostapd_data *hapd,
+ struct survey_results *survey_results)
+{
+ struct hostapd_iface *iface = hapd->iface;
+ struct freq_survey *survey, *tmp;
+ struct hostapd_channel_data *chan;
+
+ if (dl_list_empty(&survey_results->survey_list)) {
+ wpa_printf(MSG_DEBUG, "No survey data received");
+ return;
+ }
+
+ dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
+ struct freq_survey, list) {
+ chan = hostapd_get_mode_channel(iface, survey->freq);
+ if (!chan)
+ continue;
+ if (chan->flag & HOSTAPD_CHAN_DISABLED)
+ continue;
+
+ dl_list_del(&survey->list);
+ dl_list_add_tail(&chan->survey_list, &survey->list);
+
+ hostapd_update_nf(iface, chan, survey);
+
+ iface->chans_surveyed++;
+ }
+}
+
+
#ifdef HOSTAPD
#ifdef CONFIG_IEEE80211R
@@ -719,72 +785,6 @@ static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
}
-static struct hostapd_channel_data * hostapd_get_mode_channel(
- struct hostapd_iface *iface, unsigned int freq)
-{
- int i;
- struct hostapd_channel_data *chan;
-
- for (i = 0; i < iface->current_mode->num_channels; i++) {
- chan = &iface->current_mode->channels[i];
- if (!chan)
- return NULL;
- if ((unsigned int) chan->freq == freq)
- return chan;
- }
-
- return NULL;
-}
-
-
-static void hostapd_update_nf(struct hostapd_iface *iface,
- struct hostapd_channel_data *chan,
- struct freq_survey *survey)
-{
- if (!iface->chans_surveyed) {
- chan->min_nf = survey->nf;
- iface->lowest_nf = survey->nf;
- } else {
- if (dl_list_empty(&chan->survey_list))
- chan->min_nf = survey->nf;
- else if (survey->nf < chan->min_nf)
- chan->min_nf = survey->nf;
- if (survey->nf < iface->lowest_nf)
- iface->lowest_nf = survey->nf;
- }
-}
-
-
-static void hostapd_event_get_survey(struct hostapd_data *hapd,
- struct survey_results *survey_results)
-{
- struct hostapd_iface *iface = hapd->iface;
- struct freq_survey *survey, *tmp;
- struct hostapd_channel_data *chan;
-
- if (dl_list_empty(&survey_results->survey_list)) {
- wpa_printf(MSG_DEBUG, "No survey data received");
- return;
- }
-
- dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
- struct freq_survey, list) {
- chan = hostapd_get_mode_channel(iface, survey->freq);
- if (!chan)
- continue;
- if (chan->flag & HOSTAPD_CHAN_DISABLED)
- continue;
-
- dl_list_del(&survey->list);
- dl_list_add_tail(&chan->survey_list, &survey->list);
-
- hostapd_update_nf(iface, chan, survey);
-
- iface->chans_surveyed++;
- }
-}
-
-
void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
union wpa_event_data *data)
{
diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h
index dbf1b52..0ab9564 100644
--- a/src/ap/hostapd.h
+++ b/src/ap/hostapd.h
@@ -380,4 +380,8 @@ const struct hostapd_eap_user *
hostapd_get_eap_user(struct hostapd_data *hapd, const u8 *identity,
size_t identity_len, int phase2);
+struct survey_results;
+void hostapd_event_get_survey(struct hostapd_data *hapd,
+ struct survey_results *survey_results);
+
#endif /* HOSTAPD_H */
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index 69e4030..0020229 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -3141,6 +3141,13 @@ void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
data->connect_failed_reason.code);
#endif /* CONFIG_AP */
break;
+ case EVENT_SURVEY: {
+ struct hostapd_data hapd = {};
+ hapd.iface = wpa_s->ap_iface;
+
+ hostapd_event_get_survey(&hapd, &data->survey_results);
+ break;
+ }
default:
wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
break;
--
1.8.3.2
More information about the Hostap
mailing list