From: Jouni Malinen Date: Thu, 9 Aug 2012 19:26:59 +0000 (+0300) Subject: AOSP: scanning X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f116e26aa0afdb5bf29300699489c2a878eaaced;p=thirdparty%2Fhostap.git AOSP: scanning --- diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index 2b003aee8..c13f4ea60 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -996,6 +996,18 @@ int p2p_find(struct p2p_data *p2p, unsigned int timeout, return res; } +#ifdef ANDROID_P2P +int p2p_search_pending(struct p2p_data *p2p) +{ + if(p2p == NULL) + return 0; + + if(p2p->state == P2P_SEARCH_WHEN_READY) + return 1; + + return 0; +} +#endif int p2p_other_scan_completed(struct p2p_data *p2p) { @@ -3844,6 +3856,15 @@ p2p_get_peer_found(struct p2p_data *p2p, const u8 *addr, int next) return &dev->info; } +#ifdef ANDROID_P2P +int p2p_search_in_progress(struct p2p_data *p2p) +{ + if (p2p == NULL) + return 0; + + return p2p->state == P2P_SEARCH; +} +#endif int p2p_in_progress(struct p2p_data *p2p) { diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index ce3a79b00..fe98f5ebc 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -1614,6 +1614,22 @@ int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel, */ int p2p_in_progress(struct p2p_data *p2p); +#ifdef ANDROID_P2P +/** + * p2p_search_in_progress - Check whether a P2P SEARCH is in progress + * @p2p: P2P module context from p2p_init() + * Returns: 0 if P2P module is idle or 1 if an operation is in progress + */ +int p2p_search_in_progress(struct p2p_data *p2p); + +/** + * p2p_search_pending - Check whether there is a deferred P2P SEARCH + * @p2p: P2P module context from p2p_init() + * Returns: 0 if there is no deferred P2P search or 1 if there is one + */ +int p2p_search_pending(struct p2p_data *p2p); +#endif + /** * p2p_other_scan_completed - Notify completion of non-P2P scan * @p2p: P2P module context from p2p_init() diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index 26c0d447b..74a5bb515 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -116,6 +116,9 @@ void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) return; wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); +#ifdef ANDROID + wpa_s->conf->ap_scan = DEFAULT_AP_SCAN; +#endif bssid_changed = !is_zero_ether_addr(wpa_s->bssid); os_memset(wpa_s->bssid, 0, ETH_ALEN); os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); @@ -993,8 +996,13 @@ static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, /* Return < 0 if no scan results could be fetched. */ +#ifdef ANDROID_P2P +static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, + union wpa_event_data *data, int suppress_event) +#else static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, union wpa_event_data *data) +#endif { struct wpa_bss *selected; struct wpa_ssid *ssid = NULL; @@ -1009,7 +1017,11 @@ static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, wpa_supplicant_notify_scanning(wpa_s, 0); #ifdef CONFIG_P2P +#ifdef ANDROID_P2P + if (p2p_search_pending(wpa_s->global->p2p) && !wpa_s->global->p2p_disabled && +#else if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled && +#endif wpa_s->global->p2p != NULL) { wpa_s->p2p_cb_on_scan_complete = 0; if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) { @@ -1070,10 +1082,14 @@ static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, wpa_scan_results_free(scan_res); return 0; } - - wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available"); - wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); - wpas_notify_scan_results(wpa_s); +#ifdef ANDROID_P2P + if(!suppress_event) +#endif + { + wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available"); + wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); + wpas_notify_scan_results(wpa_s); + } wpas_notify_scan_done(wpa_s, 1); @@ -1149,8 +1165,11 @@ static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, { const char *rn, *rn2; struct wpa_supplicant *ifs; - +#ifdef ANDROID_P2P + if (_wpa_supplicant_event_scan_results(wpa_s, data, 0) < 0) { +#else if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) { +#endif /* * If no scan results could be fetched, then no need to * notify those interfaces that did not actually request @@ -1181,7 +1200,27 @@ static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, if (rn2 && os_strcmp(rn, rn2) == 0) { wpa_printf(MSG_DEBUG, "%s: Updating scan results from " "sibling", ifs->ifname); +#ifdef ANDROID_P2P + if ( (ifs->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) || (ifs->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)) { + /* Do not update the scan results from STA interface to p2p interfaces */ + wpa_printf(MSG_DEBUG, "Not Updating scan results on interface %s from " + "sibling %s", ifs->ifname, wpa_s->ifname); + continue; + } + else { + /* P2P_FIND will result in too many SCAN_RESULT_EVENTS within + * no time. Avoid announcing it to application as it may not + * be that useful (since results will be that of only 1,6,11). + * over to any other interface as it + */ + if(p2p_search_in_progress(wpa_s->global->p2p)) + _wpa_supplicant_event_scan_results(ifs, data, 1); + else + _wpa_supplicant_event_scan_results(ifs, data, 0); + } +#else _wpa_supplicant_event_scan_results(ifs, data); +#endif } } } @@ -1642,7 +1681,11 @@ static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, fast_reconnect = wpa_s->current_bss; fast_reconnect_ssid = wpa_s->current_ssid; } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) +#ifdef ANDROID + wpa_supplicant_req_scan(wpa_s, 0, 500000); +#else wpa_supplicant_req_scan(wpa_s, 0, 100000); +#endif else wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new " "immediate scan"); diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 5e7edc8cf..0be698f5d 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -47,7 +47,9 @@ #define P2P_MAX_CLIENT_IDLE 10 #endif /* P2P_MAX_CLIENT_IDLE */ - +#ifdef ANDROID_P2P +static int wpas_global_scan_in_progress(struct wpa_supplicant *wpa_s); +#endif static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx); static struct wpa_supplicant * wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated, @@ -63,6 +65,22 @@ static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s); static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx); static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s); +#ifdef ANDROID_P2P +static int wpas_global_scan_in_progress(struct wpa_supplicant *wpa_s) +{ + struct wpa_supplicant *iface = NULL; + + for (iface = wpa_s->global->ifaces; iface; iface = iface->next) { + if(iface->scanning || iface->wpa_state == WPA_SCANNING) { + wpa_printf(MSG_DEBUG, "P2P: Scan in progress on %s," + "defer P2P SEARCH", iface->ifname); + return 1; + } + } + + return 0; +} +#endif static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res) @@ -157,7 +175,11 @@ static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq, if (ret) { wpa_s->scan_res_handler = NULL; +#ifdef ANDROID_P2P + if (wpa_s->scanning || was_in_p2p_scan || wpas_global_scan_in_progress(wpa_s)) { +#else if (wpa_s->scanning || was_in_p2p_scan) { +#endif wpa_s->p2p_cb_on_scan_complete = 1; ret = 1; } diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index 2cb4e323e..5aee7ffad 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -238,13 +238,18 @@ wpa_supplicant_start_sched_scan(struct wpa_supplicant *wpa_s, int interval) { int ret; - +#ifndef ANDROID_P2P wpa_supplicant_notify_scanning(wpa_s, 1); +#endif ret = wpa_drv_sched_scan(wpa_s, params, interval * 1000); if (ret) wpa_supplicant_notify_scanning(wpa_s, 0); - else + else { wpa_s->sched_scanning = 1; +#ifdef ANDROID_P2P + wpa_supplicant_notify_scanning(wpa_s, 1); +#endif + } return ret; } @@ -527,12 +532,14 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx) wpa_s->prev_scan_wildcard = 0; wpa_supplicant_assoc_try(wpa_s, ssid); return; +#ifndef ANDROID } else if (wpa_s->conf->ap_scan == 2) { /* * User-initiated scan request in ap_scan == 2; scan with * wildcard SSID. */ ssid = NULL; +#endif } else { struct wpa_ssid *start = ssid, *tssid; int freqs_set = 0; @@ -660,6 +667,7 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx) */ void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec) { +#ifndef ANDROID /* If there's at least one network that should be specifically scanned * then don't cancel the scan and reschedule. Some drivers do * background scanning which generates frequent scan results, and that @@ -681,7 +689,7 @@ void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec) return; } } - +#endif wpa_dbg(wpa_s, MSG_DEBUG, "Setting scan request: %d sec %d usec", sec, usec); eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL); @@ -779,9 +787,11 @@ int wpa_supplicant_req_sched_scan(struct wpa_supplicant *wpa_s) sizeof(struct wpa_driver_scan_filter)); prev_state = wpa_s->wpa_state; +#ifndef ANDROID_P2P if (wpa_s->wpa_state == WPA_DISCONNECTED || wpa_s->wpa_state == WPA_INACTIVE) wpa_supplicant_set_state(wpa_s, WPA_SCANNING); +#endif /* Find the starting point from which to continue scanning */ ssid = wpa_s->conf->ssid; @@ -909,6 +919,9 @@ void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s) { wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling scan request"); eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL); +#ifdef ANDROID + wpa_supplicant_notify_scanning(wpa_s, 0); +#endif } @@ -933,7 +946,12 @@ void wpa_supplicant_notify_scanning(struct wpa_supplicant *wpa_s, int scanning) { if (wpa_s->scanning != scanning) { +#ifdef ANDROID_P2P + if(!wpa_s->sched_scanning) + wpa_s->scanning = scanning; +#else wpa_s->scanning = scanning; +#endif wpas_notify_scanning(wpa_s); } }