From 737e7a08b005b70aabfd7a4239e2a05c57483525 Mon Sep 17 00:00:00 2001 From: Alexander Bondar Date: Wed, 26 Feb 2014 08:04:10 +0200 Subject: [PATCH] PNO: Move and rename pno_start()/pno_stop() Move pno_start() and pno_stop() to scan.c as a more relevant location and rename them to wpas_start_pno()/wpas_stop_pno(). Signed-off-by: Alexander Bondar Signed-off-by: Ilan Peer --- wpa_supplicant/ctrl_iface.c | 106 +----------------------------------- wpa_supplicant/scan.c | 101 ++++++++++++++++++++++++++++++++++ wpa_supplicant/scan.h | 2 + 3 files changed, 105 insertions(+), 104 deletions(-) diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index fdf8ac366..7ef88712c 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -47,108 +47,6 @@ static int wpa_supplicant_global_iface_list(struct wpa_global *global, static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global, char *buf, int len); - -static int pno_start(struct wpa_supplicant *wpa_s) -{ - int ret, interval; - size_t i, num_ssid; - struct wpa_ssid *ssid; - struct wpa_driver_scan_params params; - - if (wpa_s->pno || wpa_s->pno_sched_pending) - return 0; - - if ((wpa_s->wpa_state > WPA_SCANNING) && - (wpa_s->wpa_state <= WPA_COMPLETED)) { - wpa_printf(MSG_ERROR, "PNO: In assoc process"); - return -EAGAIN; - } - - if (wpa_s->wpa_state == WPA_SCANNING) { - wpa_supplicant_cancel_scan(wpa_s); - if (wpa_s->sched_scanning) { - wpa_printf(MSG_DEBUG, "Schedule PNO on completion of " - "ongoing sched scan"); - wpa_supplicant_cancel_sched_scan(wpa_s); - wpa_s->pno_sched_pending = 1; - return 0; - } - } - - os_memset(¶ms, 0, sizeof(params)); - - num_ssid = 0; - ssid = wpa_s->conf->ssid; - while (ssid) { - if (!wpas_network_disabled(wpa_s, ssid)) - num_ssid++; - ssid = ssid->next; - } - if (num_ssid > WPAS_MAX_SCAN_SSIDS) { - wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from " - "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid); - num_ssid = WPAS_MAX_SCAN_SSIDS; - } - - if (num_ssid == 0) { - wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs"); - return -1; - } - - params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) * - num_ssid); - if (params.filter_ssids == NULL) - return -1; - i = 0; - ssid = wpa_s->conf->ssid; - while (ssid) { - if (!wpas_network_disabled(wpa_s, ssid)) { - params.ssids[i].ssid = ssid->ssid; - params.ssids[i].ssid_len = ssid->ssid_len; - params.num_ssids++; - os_memcpy(params.filter_ssids[i].ssid, ssid->ssid, - ssid->ssid_len); - params.filter_ssids[i].ssid_len = ssid->ssid_len; - params.num_filter_ssids++; - i++; - if (i == num_ssid) - break; - } - ssid = ssid->next; - } - - if (wpa_s->conf->filter_rssi) - params.filter_rssi = wpa_s->conf->filter_rssi; - - interval = wpa_s->conf->sched_scan_interval ? - wpa_s->conf->sched_scan_interval : 10; - - ret = wpa_supplicant_start_sched_scan(wpa_s, ¶ms, interval); - os_free(params.filter_ssids); - if (ret == 0) - wpa_s->pno = 1; - return ret; -} - - -static int pno_stop(struct wpa_supplicant *wpa_s) -{ - int ret = 0; - - if (wpa_s->pno || wpa_s->sched_scanning) { - wpa_s->pno = 0; - ret = wpa_supplicant_stop_sched_scan(wpa_s); - } - - wpa_s->pno_sched_pending = 0; - - if (wpa_s->wpa_state == WPA_SCANNING) - wpa_supplicant_req_scan(wpa_s, 0, 0); - - return ret; -} - - static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val) { char *pos; @@ -392,9 +290,9 @@ static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, #endif /* CONFIG_TDLS */ } else if (os_strcasecmp(cmd, "pno") == 0) { if (atoi(value)) - ret = pno_start(wpa_s); + ret = wpas_start_pno(wpa_s); else - ret = pno_stop(wpa_s); + ret = wpas_stop_pno(wpa_s); } else if (os_strcasecmp(cmd, "radio_disabled") == 0) { int disabled = atoi(value); if (wpa_drv_radio_disable(wpa_s, disabled) < 0) diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index f7eb53734..d44e4494b 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -1813,3 +1813,104 @@ void wpa_scan_free_params(struct wpa_driver_scan_params *params) os_free(params->filter_ssids); os_free(params); } + + +int wpas_start_pno(struct wpa_supplicant *wpa_s) +{ + int ret, interval; + size_t i, num_ssid; + struct wpa_ssid *ssid; + struct wpa_driver_scan_params params; + + if (wpa_s->pno || wpa_s->pno_sched_pending) + return 0; + + if ((wpa_s->wpa_state > WPA_SCANNING) && + (wpa_s->wpa_state <= WPA_COMPLETED)) { + wpa_printf(MSG_ERROR, "PNO: In assoc process"); + return -EAGAIN; + } + + if (wpa_s->wpa_state == WPA_SCANNING) { + wpa_supplicant_cancel_scan(wpa_s); + if (wpa_s->sched_scanning) { + wpa_printf(MSG_DEBUG, "Schedule PNO on completion of " + "ongoing sched scan"); + wpa_supplicant_cancel_sched_scan(wpa_s); + wpa_s->pno_sched_pending = 1; + return 0; + } + } + + os_memset(¶ms, 0, sizeof(params)); + + num_ssid = 0; + ssid = wpa_s->conf->ssid; + while (ssid) { + if (!wpas_network_disabled(wpa_s, ssid)) + num_ssid++; + ssid = ssid->next; + } + if (num_ssid > WPAS_MAX_SCAN_SSIDS) { + wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from " + "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid); + num_ssid = WPAS_MAX_SCAN_SSIDS; + } + + if (num_ssid == 0) { + wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs"); + return -1; + } + + params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) * + num_ssid); + if (params.filter_ssids == NULL) + return -1; + i = 0; + ssid = wpa_s->conf->ssid; + while (ssid) { + if (!wpas_network_disabled(wpa_s, ssid)) { + params.ssids[i].ssid = ssid->ssid; + params.ssids[i].ssid_len = ssid->ssid_len; + params.num_ssids++; + os_memcpy(params.filter_ssids[i].ssid, ssid->ssid, + ssid->ssid_len); + params.filter_ssids[i].ssid_len = ssid->ssid_len; + params.num_filter_ssids++; + i++; + if (i == num_ssid) + break; + } + ssid = ssid->next; + } + + if (wpa_s->conf->filter_rssi) + params.filter_rssi = wpa_s->conf->filter_rssi; + + interval = wpa_s->conf->sched_scan_interval ? + wpa_s->conf->sched_scan_interval : 10; + + ret = wpa_supplicant_start_sched_scan(wpa_s, ¶ms, interval); + os_free(params.filter_ssids); + if (ret == 0) + wpa_s->pno = 1; + return ret; +} + + +int wpas_stop_pno(struct wpa_supplicant *wpa_s) +{ + int ret = 0; + + if (wpa_s->pno || wpa_s->sched_scanning) { + wpa_s->pno = 0; + ret = wpa_supplicant_stop_sched_scan(wpa_s); + } + + wpa_s->pno_sched_pending = 0; + + if (wpa_s->wpa_state == WPA_SCANNING) + wpa_supplicant_req_scan(wpa_s, 0, 0); + + return ret; +} diff --git a/wpa_supplicant/scan.h b/wpa_supplicant/scan.h index e4c89895d..946d2b35e 100644 --- a/wpa_supplicant/scan.h +++ b/wpa_supplicant/scan.h @@ -46,5 +46,7 @@ int wpa_supplicant_stop_sched_scan(struct wpa_supplicant *wpa_s); struct wpa_driver_scan_params * wpa_scan_clone_params(const struct wpa_driver_scan_params *src); void wpa_scan_free_params(struct wpa_driver_scan_params *params); +int wpas_start_pno(struct wpa_supplicant *wpa_s); +int wpas_stop_pno(struct wpa_supplicant *wpa_s); #endif /* SCAN_H */