events.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626
  1. /*
  2. * WPA Supplicant - Driver event processing
  3. * Copyright (c) 2003-2012, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "eapol_supp/eapol_supp_sm.h"
  11. #include "rsn_supp/wpa.h"
  12. #include "eloop.h"
  13. #include "config.h"
  14. #include "l2_packet/l2_packet.h"
  15. #include "wpa_supplicant_i.h"
  16. #include "driver_i.h"
  17. #include "pcsc_funcs.h"
  18. #include "rsn_supp/preauth.h"
  19. #include "rsn_supp/pmksa_cache.h"
  20. #include "common/wpa_ctrl.h"
  21. #include "eap_peer/eap.h"
  22. #include "ap/hostapd.h"
  23. #include "p2p/p2p.h"
  24. #include "notify.h"
  25. #include "common/ieee802_11_defs.h"
  26. #include "common/ieee802_11_common.h"
  27. #include "crypto/random.h"
  28. #include "blacklist.h"
  29. #include "wpas_glue.h"
  30. #include "wps_supplicant.h"
  31. #include "ibss_rsn.h"
  32. #include "sme.h"
  33. #include "gas_query.h"
  34. #include "p2p_supplicant.h"
  35. #include "bgscan.h"
  36. #include "ap.h"
  37. #include "bss.h"
  38. #include "scan.h"
  39. #include "offchannel.h"
  40. static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
  41. {
  42. struct wpa_ssid *ssid, *old_ssid;
  43. if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
  44. return 0;
  45. wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
  46. "information");
  47. ssid = wpa_supplicant_get_ssid(wpa_s);
  48. if (ssid == NULL) {
  49. wpa_msg(wpa_s, MSG_INFO,
  50. "No network configuration found for the current AP");
  51. return -1;
  52. }
  53. if (ssid->disabled) {
  54. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
  55. return -1;
  56. }
  57. wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
  58. "current AP");
  59. if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
  60. u8 wpa_ie[80];
  61. size_t wpa_ie_len = sizeof(wpa_ie);
  62. wpa_supplicant_set_suites(wpa_s, NULL, ssid,
  63. wpa_ie, &wpa_ie_len);
  64. } else {
  65. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  66. }
  67. if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
  68. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  69. old_ssid = wpa_s->current_ssid;
  70. wpa_s->current_ssid = ssid;
  71. wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
  72. wpa_supplicant_initiate_eapol(wpa_s);
  73. if (old_ssid != wpa_s->current_ssid)
  74. wpas_notify_network_changed(wpa_s);
  75. return 0;
  76. }
  77. void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
  78. {
  79. struct wpa_supplicant *wpa_s = eloop_ctx;
  80. if (wpa_s->countermeasures) {
  81. wpa_s->countermeasures = 0;
  82. wpa_drv_set_countermeasures(wpa_s, 0);
  83. wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
  84. wpa_supplicant_req_scan(wpa_s, 0, 0);
  85. }
  86. }
  87. void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
  88. {
  89. int bssid_changed;
  90. #ifdef CONFIG_IBSS_RSN
  91. ibss_rsn_deinit(wpa_s->ibss_rsn);
  92. wpa_s->ibss_rsn = NULL;
  93. #endif /* CONFIG_IBSS_RSN */
  94. #ifdef CONFIG_AP
  95. wpa_supplicant_ap_deinit(wpa_s);
  96. #endif /* CONFIG_AP */
  97. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  98. return;
  99. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  100. bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
  101. os_memset(wpa_s->bssid, 0, ETH_ALEN);
  102. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  103. #ifdef CONFIG_P2P
  104. os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
  105. #endif /* CONFIG_P2P */
  106. wpa_s->current_bss = NULL;
  107. wpa_s->assoc_freq = 0;
  108. #ifdef CONFIG_IEEE80211R
  109. #ifdef CONFIG_SME
  110. if (wpa_s->sme.ft_ies)
  111. sme_update_ft_ies(wpa_s, NULL, NULL, 0);
  112. #endif /* CONFIG_SME */
  113. #endif /* CONFIG_IEEE80211R */
  114. if (bssid_changed)
  115. wpas_notify_bssid_changed(wpa_s);
  116. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  117. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  118. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  119. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  120. wpa_s->ap_ies_from_associnfo = 0;
  121. }
  122. static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
  123. {
  124. struct wpa_ie_data ie;
  125. int pmksa_set = -1;
  126. size_t i;
  127. if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
  128. ie.pmkid == NULL)
  129. return;
  130. for (i = 0; i < ie.num_pmkid; i++) {
  131. pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
  132. ie.pmkid + i * PMKID_LEN,
  133. NULL, NULL, 0);
  134. if (pmksa_set == 0) {
  135. eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
  136. break;
  137. }
  138. }
  139. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
  140. "PMKSA cache", pmksa_set == 0 ? "" : "not ");
  141. }
  142. static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
  143. union wpa_event_data *data)
  144. {
  145. if (data == NULL) {
  146. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
  147. "event");
  148. return;
  149. }
  150. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
  151. " index=%d preauth=%d",
  152. MAC2STR(data->pmkid_candidate.bssid),
  153. data->pmkid_candidate.index,
  154. data->pmkid_candidate.preauth);
  155. pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
  156. data->pmkid_candidate.index,
  157. data->pmkid_candidate.preauth);
  158. }
  159. static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
  160. {
  161. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  162. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
  163. return 0;
  164. #ifdef IEEE8021X_EAPOL
  165. if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
  166. wpa_s->current_ssid &&
  167. !(wpa_s->current_ssid->eapol_flags &
  168. (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  169. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
  170. /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
  171. * plaintext or static WEP keys). */
  172. return 0;
  173. }
  174. #endif /* IEEE8021X_EAPOL */
  175. return 1;
  176. }
  177. /**
  178. * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
  179. * @wpa_s: pointer to wpa_supplicant data
  180. * @ssid: Configuration data for the network
  181. * Returns: 0 on success, -1 on failure
  182. *
  183. * This function is called when starting authentication with a network that is
  184. * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
  185. */
  186. int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
  187. struct wpa_ssid *ssid)
  188. {
  189. #ifdef IEEE8021X_EAPOL
  190. #ifdef PCSC_FUNCS
  191. int aka = 0, sim = 0, type;
  192. if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
  193. return 0;
  194. if (ssid->eap.eap_methods == NULL) {
  195. sim = 1;
  196. aka = 1;
  197. } else {
  198. struct eap_method_type *eap = ssid->eap.eap_methods;
  199. while (eap->vendor != EAP_VENDOR_IETF ||
  200. eap->method != EAP_TYPE_NONE) {
  201. if (eap->vendor == EAP_VENDOR_IETF) {
  202. if (eap->method == EAP_TYPE_SIM)
  203. sim = 1;
  204. else if (eap->method == EAP_TYPE_AKA)
  205. aka = 1;
  206. }
  207. eap++;
  208. }
  209. }
  210. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
  211. sim = 0;
  212. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
  213. aka = 0;
  214. if (!sim && !aka) {
  215. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
  216. "use SIM, but neither EAP-SIM nor EAP-AKA are "
  217. "enabled");
  218. return 0;
  219. }
  220. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
  221. "(sim=%d aka=%d) - initialize PCSC", sim, aka);
  222. if (sim && aka)
  223. type = SCARD_TRY_BOTH;
  224. else if (aka)
  225. type = SCARD_USIM_ONLY;
  226. else
  227. type = SCARD_GSM_SIM_ONLY;
  228. wpa_s->scard = scard_init(type, NULL);
  229. if (wpa_s->scard == NULL) {
  230. wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
  231. "(pcsc-lite)");
  232. return -1;
  233. }
  234. wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
  235. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  236. #endif /* PCSC_FUNCS */
  237. #endif /* IEEE8021X_EAPOL */
  238. return 0;
  239. }
  240. #ifndef CONFIG_NO_SCAN_PROCESSING
  241. static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
  242. struct wpa_ssid *ssid)
  243. {
  244. int i, privacy = 0;
  245. if (ssid->mixed_cell)
  246. return 1;
  247. #ifdef CONFIG_WPS
  248. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
  249. return 1;
  250. #endif /* CONFIG_WPS */
  251. for (i = 0; i < NUM_WEP_KEYS; i++) {
  252. if (ssid->wep_key_len[i]) {
  253. privacy = 1;
  254. break;
  255. }
  256. }
  257. #ifdef IEEE8021X_EAPOL
  258. if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  259. ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  260. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
  261. privacy = 1;
  262. #endif /* IEEE8021X_EAPOL */
  263. if (wpa_key_mgmt_wpa(ssid->key_mgmt))
  264. privacy = 1;
  265. if (bss->caps & IEEE80211_CAP_PRIVACY)
  266. return privacy;
  267. return !privacy;
  268. }
  269. static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
  270. struct wpa_ssid *ssid,
  271. struct wpa_scan_res *bss)
  272. {
  273. struct wpa_ie_data ie;
  274. int proto_match = 0;
  275. const u8 *rsn_ie, *wpa_ie;
  276. int ret;
  277. int wep_ok;
  278. ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
  279. if (ret >= 0)
  280. return ret;
  281. /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
  282. wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
  283. (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
  284. ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
  285. (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
  286. rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  287. while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
  288. proto_match++;
  289. if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
  290. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
  291. "failed");
  292. break;
  293. }
  294. if (wep_ok &&
  295. (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
  296. {
  297. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
  298. "in RSN IE");
  299. return 1;
  300. }
  301. if (!(ie.proto & ssid->proto)) {
  302. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
  303. "mismatch");
  304. break;
  305. }
  306. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  307. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
  308. "cipher mismatch");
  309. break;
  310. }
  311. if (!(ie.group_cipher & ssid->group_cipher)) {
  312. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
  313. "cipher mismatch");
  314. break;
  315. }
  316. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  317. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
  318. "mismatch");
  319. break;
  320. }
  321. #ifdef CONFIG_IEEE80211W
  322. if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
  323. ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
  324. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
  325. "frame protection");
  326. break;
  327. }
  328. #endif /* CONFIG_IEEE80211W */
  329. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
  330. return 1;
  331. }
  332. wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  333. while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
  334. proto_match++;
  335. if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
  336. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
  337. "failed");
  338. break;
  339. }
  340. if (wep_ok &&
  341. (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
  342. {
  343. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
  344. "in WPA IE");
  345. return 1;
  346. }
  347. if (!(ie.proto & ssid->proto)) {
  348. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
  349. "mismatch");
  350. break;
  351. }
  352. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  353. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
  354. "cipher mismatch");
  355. break;
  356. }
  357. if (!(ie.group_cipher & ssid->group_cipher)) {
  358. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
  359. "cipher mismatch");
  360. break;
  361. }
  362. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  363. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
  364. "mismatch");
  365. break;
  366. }
  367. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
  368. return 1;
  369. }
  370. if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
  371. wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
  372. wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
  373. return 0;
  374. }
  375. if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
  376. wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
  377. return 1;
  378. }
  379. wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
  380. "WPA/WPA2");
  381. return 0;
  382. }
  383. static int freq_allowed(int *freqs, int freq)
  384. {
  385. int i;
  386. if (freqs == NULL)
  387. return 1;
  388. for (i = 0; freqs[i]; i++)
  389. if (freqs[i] == freq)
  390. return 1;
  391. return 0;
  392. }
  393. static int ht_supported(const struct hostapd_hw_modes *mode)
  394. {
  395. if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) {
  396. /*
  397. * The driver did not indicate whether it supports HT. Assume
  398. * it does to avoid connection issues.
  399. */
  400. return 1;
  401. }
  402. /*
  403. * IEEE Std 802.11n-2009 20.1.1:
  404. * An HT non-AP STA shall support all EQM rates for one spatial stream.
  405. */
  406. return mode->mcs_set[0] == 0xff;
  407. }
  408. static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_scan_res *bss)
  409. {
  410. const struct hostapd_hw_modes *mode = NULL, *modes;
  411. const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
  412. const u8 *rate_ie;
  413. int i, j, k;
  414. if (bss->freq == 0)
  415. return 1; /* Cannot do matching without knowing band */
  416. modes = wpa_s->hw.modes;
  417. if (modes == NULL) {
  418. /*
  419. * The driver does not provide any additional information
  420. * about the utilized hardware, so allow the connection attempt
  421. * to continue.
  422. */
  423. return 1;
  424. }
  425. for (i = 0; i < wpa_s->hw.num_modes; i++) {
  426. for (j = 0; j < modes[i].num_channels; j++) {
  427. int freq = modes[i].channels[j].freq;
  428. if (freq == bss->freq) {
  429. if (mode &&
  430. mode->mode == HOSTAPD_MODE_IEEE80211G)
  431. break; /* do not allow 802.11b replace
  432. * 802.11g */
  433. mode = &modes[i];
  434. break;
  435. }
  436. }
  437. }
  438. if (mode == NULL)
  439. return 0;
  440. for (i = 0; i < (int) sizeof(scan_ie); i++) {
  441. rate_ie = wpa_scan_get_ie(bss, scan_ie[i]);
  442. if (rate_ie == NULL)
  443. continue;
  444. for (j = 2; j < rate_ie[1] + 2; j++) {
  445. int flagged = !!(rate_ie[j] & 0x80);
  446. int r = (rate_ie[j] & 0x7f) * 5;
  447. /*
  448. * IEEE Std 802.11n-2009 7.3.2.2:
  449. * The new BSS Membership selector value is encoded
  450. * like a legacy basic rate, but it is not a rate and
  451. * only indicates if the BSS members are required to
  452. * support the mandatory features of Clause 20 [HT PHY]
  453. * in order to join the BSS.
  454. */
  455. if (flagged && ((rate_ie[j] & 0x7f) ==
  456. BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
  457. if (!ht_supported(mode)) {
  458. wpa_dbg(wpa_s, MSG_DEBUG,
  459. " hardware does not support "
  460. "HT PHY");
  461. return 0;
  462. }
  463. continue;
  464. }
  465. if (!flagged)
  466. continue;
  467. /* check for legacy basic rates */
  468. for (k = 0; k < mode->num_rates; k++) {
  469. if (mode->rates[k] == r)
  470. break;
  471. }
  472. if (k == mode->num_rates) {
  473. /*
  474. * IEEE Std 802.11-2007 7.3.2.2 demands that in
  475. * order to join a BSS all required rates
  476. * have to be supported by the hardware.
  477. */
  478. wpa_dbg(wpa_s, MSG_DEBUG, " hardware does "
  479. "not support required rate %d.%d Mbps",
  480. r / 10, r % 10);
  481. return 0;
  482. }
  483. }
  484. }
  485. return 1;
  486. }
  487. static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
  488. int i, struct wpa_scan_res *bss,
  489. struct wpa_ssid *group)
  490. {
  491. const u8 *ssid_;
  492. u8 wpa_ie_len, rsn_ie_len, ssid_len;
  493. int wpa;
  494. struct wpa_blacklist *e;
  495. const u8 *ie;
  496. struct wpa_ssid *ssid;
  497. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  498. ssid_ = ie ? ie + 2 : (u8 *) "";
  499. ssid_len = ie ? ie[1] : 0;
  500. ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  501. wpa_ie_len = ie ? ie[1] : 0;
  502. ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  503. rsn_ie_len = ie ? ie[1] : 0;
  504. wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
  505. "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
  506. i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
  507. wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
  508. wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
  509. e = wpa_blacklist_get(wpa_s, bss->bssid);
  510. if (e) {
  511. int limit = 1;
  512. if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) {
  513. /*
  514. * When only a single network is enabled, we can
  515. * trigger blacklisting on the first failure. This
  516. * should not be done with multiple enabled networks to
  517. * avoid getting forced to move into a worse ESS on
  518. * single error if there are no other BSSes of the
  519. * current ESS.
  520. */
  521. limit = 0;
  522. }
  523. if (e->count > limit) {
  524. wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
  525. "(count=%d limit=%d)", e->count, limit);
  526. return NULL;
  527. }
  528. }
  529. if (ssid_len == 0) {
  530. wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
  531. return NULL;
  532. }
  533. wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
  534. for (ssid = group; ssid; ssid = ssid->pnext) {
  535. int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
  536. if (ssid->disabled) {
  537. wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
  538. continue;
  539. }
  540. #ifdef CONFIG_WPS
  541. if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
  542. wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
  543. "(WPS)");
  544. continue;
  545. }
  546. if (wpa && ssid->ssid_len == 0 &&
  547. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  548. check_ssid = 0;
  549. if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
  550. /* Only allow wildcard SSID match if an AP
  551. * advertises active WPS operation that matches
  552. * with our mode. */
  553. check_ssid = 1;
  554. if (ssid->ssid_len == 0 &&
  555. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  556. check_ssid = 0;
  557. }
  558. #endif /* CONFIG_WPS */
  559. if (ssid->bssid_set && ssid->ssid_len == 0 &&
  560. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
  561. check_ssid = 0;
  562. if (check_ssid &&
  563. (ssid_len != ssid->ssid_len ||
  564. os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
  565. wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
  566. continue;
  567. }
  568. if (ssid->bssid_set &&
  569. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
  570. wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
  571. continue;
  572. }
  573. if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
  574. continue;
  575. if (!wpa &&
  576. !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
  577. !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
  578. !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
  579. wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
  580. "not allowed");
  581. continue;
  582. }
  583. if (!wpa_supplicant_match_privacy(bss, ssid)) {
  584. wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
  585. "mismatch");
  586. continue;
  587. }
  588. if (bss->caps & IEEE80211_CAP_IBSS) {
  589. wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
  590. "network");
  591. continue;
  592. }
  593. if (!freq_allowed(ssid->freq_list, bss->freq)) {
  594. wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
  595. "allowed");
  596. continue;
  597. }
  598. if (!rate_match(wpa_s, bss)) {
  599. wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
  600. "not match");
  601. continue;
  602. }
  603. #ifdef CONFIG_P2P
  604. /*
  605. * TODO: skip the AP if its P2P IE has Group Formation
  606. * bit set in the P2P Group Capability Bitmap and we
  607. * are not in Group Formation with that device.
  608. */
  609. #endif /* CONFIG_P2P */
  610. /* Matching configuration found */
  611. return ssid;
  612. }
  613. /* No matching configuration found */
  614. return NULL;
  615. }
  616. static struct wpa_bss *
  617. wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
  618. struct wpa_scan_results *scan_res,
  619. struct wpa_ssid *group,
  620. struct wpa_ssid **selected_ssid)
  621. {
  622. size_t i;
  623. wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
  624. group->priority);
  625. for (i = 0; i < scan_res->num; i++) {
  626. struct wpa_scan_res *bss = scan_res->res[i];
  627. const u8 *ie, *ssid;
  628. u8 ssid_len;
  629. *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
  630. if (!*selected_ssid)
  631. continue;
  632. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  633. ssid = ie ? ie + 2 : (u8 *) "";
  634. ssid_len = ie ? ie[1] : 0;
  635. wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
  636. " ssid='%s'",
  637. MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
  638. return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
  639. }
  640. return NULL;
  641. }
  642. static struct wpa_bss *
  643. wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
  644. struct wpa_scan_results *scan_res,
  645. struct wpa_ssid **selected_ssid)
  646. {
  647. struct wpa_bss *selected = NULL;
  648. int prio;
  649. while (selected == NULL) {
  650. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  651. selected = wpa_supplicant_select_bss(
  652. wpa_s, scan_res, wpa_s->conf->pssid[prio],
  653. selected_ssid);
  654. if (selected)
  655. break;
  656. }
  657. if (selected == NULL && wpa_s->blacklist &&
  658. !wpa_s->countermeasures) {
  659. wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
  660. "blacklist and try again");
  661. wpa_blacklist_clear(wpa_s);
  662. wpa_s->blacklist_cleared++;
  663. } else if (selected == NULL)
  664. break;
  665. }
  666. return selected;
  667. }
  668. static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
  669. int timeout_sec, int timeout_usec)
  670. {
  671. if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
  672. /*
  673. * No networks are enabled; short-circuit request so
  674. * we don't wait timeout seconds before transitioning
  675. * to INACTIVE state.
  676. */
  677. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  678. return;
  679. }
  680. wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
  681. }
  682. int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
  683. struct wpa_bss *selected,
  684. struct wpa_ssid *ssid)
  685. {
  686. if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
  687. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
  688. "PBC session overlap");
  689. #ifdef CONFIG_P2P
  690. if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
  691. return -1;
  692. #endif /* CONFIG_P2P */
  693. #ifdef CONFIG_WPS
  694. wpas_wps_cancel(wpa_s);
  695. #endif /* CONFIG_WPS */
  696. return -1;
  697. }
  698. /*
  699. * Do not trigger new association unless the BSSID has changed or if
  700. * reassociation is requested. If we are in process of associating with
  701. * the selected BSSID, do not trigger new attempt.
  702. */
  703. if (wpa_s->reassociate ||
  704. (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
  705. ((wpa_s->wpa_state != WPA_ASSOCIATING &&
  706. wpa_s->wpa_state != WPA_AUTHENTICATING) ||
  707. os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
  708. 0))) {
  709. if (wpa_supplicant_scard_init(wpa_s, ssid)) {
  710. wpa_supplicant_req_new_scan(wpa_s, 10, 0);
  711. return 0;
  712. }
  713. wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
  714. "reassociate: %d selected: "MACSTR " bssid: " MACSTR
  715. " pending: " MACSTR " wpa_state: %s",
  716. wpa_s->reassociate, MAC2STR(selected->bssid),
  717. MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
  718. wpa_supplicant_state_txt(wpa_s->wpa_state));
  719. wpa_supplicant_associate(wpa_s, selected, ssid);
  720. } else {
  721. wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
  722. "selected AP");
  723. }
  724. return 0;
  725. }
  726. static struct wpa_ssid *
  727. wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
  728. {
  729. int prio;
  730. struct wpa_ssid *ssid;
  731. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  732. for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
  733. {
  734. if (ssid->disabled)
  735. continue;
  736. if (ssid->mode == IEEE80211_MODE_IBSS ||
  737. ssid->mode == IEEE80211_MODE_AP)
  738. return ssid;
  739. }
  740. }
  741. return NULL;
  742. }
  743. /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
  744. * on BSS added and BSS changed events */
  745. static void wpa_supplicant_rsn_preauth_scan_results(
  746. struct wpa_supplicant *wpa_s)
  747. {
  748. struct wpa_bss *bss;
  749. if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
  750. return;
  751. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  752. const u8 *ssid, *rsn;
  753. ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
  754. if (ssid == NULL)
  755. continue;
  756. rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  757. if (rsn == NULL)
  758. continue;
  759. rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
  760. }
  761. }
  762. static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
  763. struct wpa_bss *selected,
  764. struct wpa_ssid *ssid,
  765. struct wpa_scan_results *scan_res)
  766. {
  767. size_t i;
  768. struct wpa_scan_res *current_bss = NULL;
  769. int min_diff;
  770. if (wpa_s->reassociate)
  771. return 1; /* explicit request to reassociate */
  772. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  773. return 1; /* we are not associated; continue */
  774. if (wpa_s->current_ssid == NULL)
  775. return 1; /* unknown current SSID */
  776. if (wpa_s->current_ssid != ssid)
  777. return 1; /* different network block */
  778. if (wpas_driver_bss_selection(wpa_s))
  779. return 0; /* Driver-based roaming */
  780. for (i = 0; i < scan_res->num; i++) {
  781. struct wpa_scan_res *res = scan_res->res[i];
  782. const u8 *ie;
  783. if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
  784. continue;
  785. ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
  786. if (ie == NULL)
  787. continue;
  788. if (ie[1] != wpa_s->current_ssid->ssid_len ||
  789. os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
  790. continue;
  791. current_bss = res;
  792. break;
  793. }
  794. if (!current_bss)
  795. return 1; /* current BSS not seen in scan results */
  796. #ifndef CONFIG_NO_ROAMING
  797. wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
  798. wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
  799. MAC2STR(current_bss->bssid), current_bss->level);
  800. wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
  801. MAC2STR(selected->bssid), selected->level);
  802. if (wpa_s->current_ssid->bssid_set &&
  803. os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
  804. 0) {
  805. wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
  806. "has preferred BSSID");
  807. return 1;
  808. }
  809. min_diff = 2;
  810. if (current_bss->level < 0) {
  811. if (current_bss->level < -85)
  812. min_diff = 1;
  813. else if (current_bss->level < -80)
  814. min_diff = 2;
  815. else if (current_bss->level < -75)
  816. min_diff = 3;
  817. else if (current_bss->level < -70)
  818. min_diff = 4;
  819. else
  820. min_diff = 5;
  821. }
  822. if (abs(current_bss->level - selected->level) < min_diff) {
  823. wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
  824. "in signal level");
  825. return 0;
  826. }
  827. return 1;
  828. #else /* CONFIG_NO_ROAMING */
  829. return 0;
  830. #endif /* CONFIG_NO_ROAMING */
  831. }
  832. /* Return < 0 if no scan results could be fetched. */
  833. static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  834. union wpa_event_data *data)
  835. {
  836. struct wpa_bss *selected;
  837. struct wpa_ssid *ssid = NULL;
  838. struct wpa_scan_results *scan_res;
  839. int ap = 0;
  840. #ifdef CONFIG_AP
  841. if (wpa_s->ap_iface)
  842. ap = 1;
  843. #endif /* CONFIG_AP */
  844. wpa_supplicant_notify_scanning(wpa_s, 0);
  845. #ifdef CONFIG_P2P
  846. if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
  847. wpa_s->global->p2p != NULL) {
  848. wpa_s->p2p_cb_on_scan_complete = 0;
  849. if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
  850. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
  851. "stopped scan processing");
  852. return -1;
  853. }
  854. }
  855. #endif /* CONFIG_P2P */
  856. scan_res = wpa_supplicant_get_scan_results(wpa_s,
  857. data ? &data->scan_info :
  858. NULL, 1);
  859. if (scan_res == NULL) {
  860. if (wpa_s->conf->ap_scan == 2 || ap)
  861. return -1;
  862. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
  863. "scanning again");
  864. wpa_supplicant_req_new_scan(wpa_s, 1, 0);
  865. return -1;
  866. }
  867. #ifndef CONFIG_NO_RANDOM_POOL
  868. size_t i, num;
  869. num = scan_res->num;
  870. if (num > 10)
  871. num = 10;
  872. for (i = 0; i < num; i++) {
  873. u8 buf[5];
  874. struct wpa_scan_res *res = scan_res->res[i];
  875. buf[0] = res->bssid[5];
  876. buf[1] = res->qual & 0xff;
  877. buf[2] = res->noise & 0xff;
  878. buf[3] = res->level & 0xff;
  879. buf[4] = res->tsf & 0xff;
  880. random_add_randomness(buf, sizeof(buf));
  881. }
  882. #endif /* CONFIG_NO_RANDOM_POOL */
  883. if (wpa_s->scan_res_handler) {
  884. void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
  885. struct wpa_scan_results *scan_res);
  886. scan_res_handler = wpa_s->scan_res_handler;
  887. wpa_s->scan_res_handler = NULL;
  888. scan_res_handler(wpa_s, scan_res);
  889. wpa_scan_results_free(scan_res);
  890. return 0;
  891. }
  892. if (ap) {
  893. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
  894. #ifdef CONFIG_AP
  895. if (wpa_s->ap_iface->scan_cb)
  896. wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
  897. #endif /* CONFIG_AP */
  898. wpa_scan_results_free(scan_res);
  899. return 0;
  900. }
  901. wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
  902. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  903. wpas_notify_scan_results(wpa_s);
  904. wpas_notify_scan_done(wpa_s, 1);
  905. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
  906. wpa_scan_results_free(scan_res);
  907. return 0;
  908. }
  909. if (wpa_s->disconnected) {
  910. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  911. wpa_scan_results_free(scan_res);
  912. return 0;
  913. }
  914. if (!wpas_driver_bss_selection(wpa_s) &&
  915. bgscan_notify_scan(wpa_s, scan_res) == 1) {
  916. wpa_scan_results_free(scan_res);
  917. return 0;
  918. }
  919. selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
  920. if (selected) {
  921. int skip;
  922. skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
  923. scan_res);
  924. wpa_scan_results_free(scan_res);
  925. if (skip) {
  926. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  927. return 0;
  928. }
  929. if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
  930. wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
  931. return -1;
  932. }
  933. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  934. } else {
  935. wpa_scan_results_free(scan_res);
  936. wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
  937. ssid = wpa_supplicant_pick_new_network(wpa_s);
  938. if (ssid) {
  939. wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
  940. wpa_supplicant_associate(wpa_s, NULL, ssid);
  941. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  942. } else {
  943. int timeout_sec = wpa_s->scan_interval;
  944. int timeout_usec = 0;
  945. #ifdef CONFIG_P2P
  946. if (wpa_s->p2p_in_provisioning) {
  947. /*
  948. * Use shorter wait during P2P Provisioning
  949. * state to speed up group formation.
  950. */
  951. timeout_sec = 0;
  952. timeout_usec = 250000;
  953. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  954. timeout_usec);
  955. return 0;
  956. }
  957. #endif /* CONFIG_P2P */
  958. if (wpa_supplicant_req_sched_scan(wpa_s))
  959. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  960. timeout_usec);
  961. }
  962. }
  963. return 0;
  964. }
  965. static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  966. union wpa_event_data *data)
  967. {
  968. const char *rn, *rn2;
  969. struct wpa_supplicant *ifs;
  970. if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
  971. /*
  972. * If no scan results could be fetched, then no need to
  973. * notify those interfaces that did not actually request
  974. * this scan.
  975. */
  976. return;
  977. }
  978. /*
  979. * Check other interfaces to see if they have the same radio-name. If
  980. * so, they get updated with this same scan info.
  981. */
  982. if (!wpa_s->driver->get_radio_name)
  983. return;
  984. rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
  985. if (rn == NULL || rn[0] == '\0')
  986. return;
  987. wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
  988. "sharing same radio (%s) in event_scan_results", rn);
  989. for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
  990. if (ifs == wpa_s || !ifs->driver->get_radio_name)
  991. continue;
  992. rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
  993. if (rn2 && os_strcmp(rn, rn2) == 0) {
  994. wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
  995. "sibling", ifs->ifname);
  996. _wpa_supplicant_event_scan_results(ifs, data);
  997. }
  998. }
  999. }
  1000. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1001. static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  1002. union wpa_event_data *data)
  1003. {
  1004. int l, len, found = 0, wpa_found, rsn_found;
  1005. const u8 *p;
  1006. wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
  1007. if (data->assoc_info.req_ies)
  1008. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  1009. data->assoc_info.req_ies_len);
  1010. if (data->assoc_info.resp_ies) {
  1011. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  1012. data->assoc_info.resp_ies_len);
  1013. #ifdef CONFIG_TDLS
  1014. wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
  1015. data->assoc_info.resp_ies_len);
  1016. #endif /* CONFIG_TDLS */
  1017. }
  1018. if (data->assoc_info.beacon_ies)
  1019. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  1020. data->assoc_info.beacon_ies,
  1021. data->assoc_info.beacon_ies_len);
  1022. if (data->assoc_info.freq)
  1023. wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
  1024. data->assoc_info.freq);
  1025. p = data->assoc_info.req_ies;
  1026. l = data->assoc_info.req_ies_len;
  1027. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  1028. while (p && l >= 2) {
  1029. len = p[1] + 2;
  1030. if (len > l) {
  1031. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1032. p, l);
  1033. break;
  1034. }
  1035. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1036. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  1037. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  1038. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  1039. break;
  1040. found = 1;
  1041. wpa_find_assoc_pmkid(wpa_s);
  1042. break;
  1043. }
  1044. l -= len;
  1045. p += len;
  1046. }
  1047. if (!found && data->assoc_info.req_ies)
  1048. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  1049. #ifdef CONFIG_IEEE80211R
  1050. #ifdef CONFIG_SME
  1051. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  1052. u8 bssid[ETH_ALEN];
  1053. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  1054. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  1055. data->assoc_info.resp_ies,
  1056. data->assoc_info.resp_ies_len,
  1057. bssid) < 0) {
  1058. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  1059. "Reassociation Response failed");
  1060. wpa_supplicant_deauthenticate(
  1061. wpa_s, WLAN_REASON_INVALID_IE);
  1062. return -1;
  1063. }
  1064. }
  1065. p = data->assoc_info.resp_ies;
  1066. l = data->assoc_info.resp_ies_len;
  1067. #ifdef CONFIG_WPS_STRICT
  1068. if (p && wpa_s->current_ssid &&
  1069. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  1070. struct wpabuf *wps;
  1071. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  1072. if (wps == NULL) {
  1073. wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
  1074. "include WPS IE in (Re)Association Response");
  1075. return -1;
  1076. }
  1077. if (wps_validate_assoc_resp(wps) < 0) {
  1078. wpabuf_free(wps);
  1079. wpa_supplicant_deauthenticate(
  1080. wpa_s, WLAN_REASON_INVALID_IE);
  1081. return -1;
  1082. }
  1083. wpabuf_free(wps);
  1084. }
  1085. #endif /* CONFIG_WPS_STRICT */
  1086. /* Go through the IEs and make a copy of the MDIE, if present. */
  1087. while (p && l >= 2) {
  1088. len = p[1] + 2;
  1089. if (len > l) {
  1090. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1091. p, l);
  1092. break;
  1093. }
  1094. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  1095. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  1096. wpa_s->sme.ft_used = 1;
  1097. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  1098. MOBILITY_DOMAIN_ID_LEN);
  1099. break;
  1100. }
  1101. l -= len;
  1102. p += len;
  1103. }
  1104. #endif /* CONFIG_SME */
  1105. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  1106. data->assoc_info.resp_ies_len);
  1107. #endif /* CONFIG_IEEE80211R */
  1108. /* WPA/RSN IE from Beacon/ProbeResp */
  1109. p = data->assoc_info.beacon_ies;
  1110. l = data->assoc_info.beacon_ies_len;
  1111. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  1112. */
  1113. wpa_found = rsn_found = 0;
  1114. while (p && l >= 2) {
  1115. len = p[1] + 2;
  1116. if (len > l) {
  1117. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  1118. p, l);
  1119. break;
  1120. }
  1121. if (!wpa_found &&
  1122. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1123. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  1124. wpa_found = 1;
  1125. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  1126. }
  1127. if (!rsn_found &&
  1128. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  1129. rsn_found = 1;
  1130. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  1131. }
  1132. l -= len;
  1133. p += len;
  1134. }
  1135. if (!wpa_found && data->assoc_info.beacon_ies)
  1136. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  1137. if (!rsn_found && data->assoc_info.beacon_ies)
  1138. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  1139. if (wpa_found || rsn_found)
  1140. wpa_s->ap_ies_from_associnfo = 1;
  1141. if (wpa_s->assoc_freq && data->assoc_info.freq &&
  1142. wpa_s->assoc_freq != data->assoc_info.freq) {
  1143. wpa_printf(MSG_DEBUG, "Operating frequency changed from "
  1144. "%u to %u MHz",
  1145. wpa_s->assoc_freq, data->assoc_info.freq);
  1146. wpa_supplicant_update_scan_results(wpa_s);
  1147. }
  1148. wpa_s->assoc_freq = data->assoc_info.freq;
  1149. return 0;
  1150. }
  1151. static struct wpa_bss * wpa_supplicant_get_new_bss(
  1152. struct wpa_supplicant *wpa_s, const u8 *bssid)
  1153. {
  1154. struct wpa_bss *bss = NULL;
  1155. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1156. if (ssid->ssid_len > 0)
  1157. bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
  1158. if (!bss)
  1159. bss = wpa_bss_get_bssid(wpa_s, bssid);
  1160. return bss;
  1161. }
  1162. static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
  1163. {
  1164. const u8 *bss_wpa = NULL, *bss_rsn = NULL;
  1165. if (!wpa_s->current_bss || !wpa_s->current_ssid)
  1166. return -1;
  1167. if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
  1168. return 0;
  1169. bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
  1170. WPA_IE_VENDOR_TYPE);
  1171. bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
  1172. if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
  1173. bss_wpa ? 2 + bss_wpa[1] : 0) ||
  1174. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
  1175. bss_rsn ? 2 + bss_rsn[1] : 0))
  1176. return -1;
  1177. return 0;
  1178. }
  1179. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  1180. union wpa_event_data *data)
  1181. {
  1182. u8 bssid[ETH_ALEN];
  1183. int ft_completed;
  1184. int bssid_changed;
  1185. struct wpa_driver_capa capa;
  1186. #ifdef CONFIG_AP
  1187. if (wpa_s->ap_iface) {
  1188. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  1189. data->assoc_info.addr,
  1190. data->assoc_info.req_ies,
  1191. data->assoc_info.req_ies_len,
  1192. data->assoc_info.reassoc);
  1193. return;
  1194. }
  1195. #endif /* CONFIG_AP */
  1196. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  1197. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  1198. return;
  1199. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  1200. if (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
  1201. os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
  1202. wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  1203. MACSTR, MAC2STR(bssid));
  1204. random_add_randomness(bssid, ETH_ALEN);
  1205. bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
  1206. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  1207. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1208. if (bssid_changed)
  1209. wpas_notify_bssid_changed(wpa_s);
  1210. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  1211. wpa_clear_keys(wpa_s, bssid);
  1212. }
  1213. if (wpa_supplicant_select_config(wpa_s) < 0) {
  1214. wpa_supplicant_disassociate(
  1215. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1216. return;
  1217. }
  1218. if (wpa_s->current_ssid) {
  1219. struct wpa_bss *bss = NULL;
  1220. bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
  1221. if (!bss) {
  1222. wpa_supplicant_update_scan_results(wpa_s);
  1223. /* Get the BSS from the new scan results */
  1224. bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
  1225. }
  1226. if (bss)
  1227. wpa_s->current_bss = bss;
  1228. }
  1229. if (wpa_s->conf->ap_scan == 1 &&
  1230. wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
  1231. if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
  1232. wpa_msg(wpa_s, MSG_WARNING,
  1233. "WPA/RSN IEs not updated");
  1234. }
  1235. }
  1236. #ifdef CONFIG_SME
  1237. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  1238. wpa_s->sme.prev_bssid_set = 1;
  1239. #endif /* CONFIG_SME */
  1240. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  1241. if (wpa_s->current_ssid) {
  1242. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  1243. * initialized before association, but for other modes,
  1244. * initialize PC/SC here, if the current configuration needs
  1245. * smartcard or SIM/USIM. */
  1246. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  1247. }
  1248. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  1249. if (wpa_s->l2)
  1250. l2_packet_notify_auth_start(wpa_s->l2);
  1251. /*
  1252. * Set portEnabled first to FALSE in order to get EAP state machine out
  1253. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  1254. * state machine may transit to AUTHENTICATING state based on obsolete
  1255. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  1256. * AUTHENTICATED without ever giving chance to EAP state machine to
  1257. * reset the state.
  1258. */
  1259. if (!ft_completed) {
  1260. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  1261. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  1262. }
  1263. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  1264. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  1265. /* 802.1X::portControl = Auto */
  1266. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  1267. wpa_s->eapol_received = 0;
  1268. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1269. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  1270. (wpa_s->current_ssid &&
  1271. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  1272. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1273. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1274. } else if (!ft_completed) {
  1275. /* Timeout for receiving the first EAPOL packet */
  1276. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  1277. }
  1278. wpa_supplicant_cancel_scan(wpa_s);
  1279. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1280. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1281. /*
  1282. * We are done; the driver will take care of RSN 4-way
  1283. * handshake.
  1284. */
  1285. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1286. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1287. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1288. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1289. } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1290. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1291. /*
  1292. * The driver will take care of RSN 4-way handshake, so we need
  1293. * to allow EAPOL supplicant to complete its work without
  1294. * waiting for WPA supplicant.
  1295. */
  1296. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1297. } else if (ft_completed) {
  1298. /*
  1299. * FT protocol completed - make sure EAPOL state machine ends
  1300. * up in authenticated.
  1301. */
  1302. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1303. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1304. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1305. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1306. }
  1307. if (wpa_s->pending_eapol_rx) {
  1308. struct os_time now, age;
  1309. os_get_time(&now);
  1310. os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  1311. if (age.sec == 0 && age.usec < 100000 &&
  1312. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  1313. 0) {
  1314. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
  1315. "frame that was received just before "
  1316. "association notification");
  1317. wpa_supplicant_rx_eapol(
  1318. wpa_s, wpa_s->pending_eapol_rx_src,
  1319. wpabuf_head(wpa_s->pending_eapol_rx),
  1320. wpabuf_len(wpa_s->pending_eapol_rx));
  1321. }
  1322. wpabuf_free(wpa_s->pending_eapol_rx);
  1323. wpa_s->pending_eapol_rx = NULL;
  1324. }
  1325. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1326. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1327. wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
  1328. capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
  1329. /* Set static WEP keys again */
  1330. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1331. }
  1332. #ifdef CONFIG_IBSS_RSN
  1333. if (wpa_s->current_ssid &&
  1334. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  1335. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  1336. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
  1337. wpa_s->ibss_rsn == NULL) {
  1338. wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
  1339. if (!wpa_s->ibss_rsn) {
  1340. wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
  1341. wpa_supplicant_deauthenticate(
  1342. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1343. return;
  1344. }
  1345. ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
  1346. }
  1347. #endif /* CONFIG_IBSS_RSN */
  1348. }
  1349. static int disconnect_reason_recoverable(u16 reason_code)
  1350. {
  1351. return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
  1352. reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
  1353. reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
  1354. }
  1355. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1356. u16 reason_code,
  1357. int locally_generated)
  1358. {
  1359. const u8 *bssid;
  1360. int authenticating;
  1361. u8 prev_pending_bssid[ETH_ALEN];
  1362. struct wpa_bss *fast_reconnect = NULL;
  1363. struct wpa_ssid *fast_reconnect_ssid = NULL;
  1364. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1365. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1366. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1367. /*
  1368. * At least Host AP driver and a Prism3 card seemed to be
  1369. * generating streams of disconnected events when configuring
  1370. * IBSS for WPA-None. Ignore them for now.
  1371. */
  1372. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
  1373. "IBSS/WPA-None mode");
  1374. return;
  1375. }
  1376. if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
  1377. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1378. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1379. "pre-shared key may be incorrect");
  1380. }
  1381. if (!wpa_s->auto_reconnect_disabled ||
  1382. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
  1383. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
  1384. "reconnect (wps=%d wpa_state=%d)",
  1385. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
  1386. wpa_s->wpa_state);
  1387. if (wpa_s->wpa_state == WPA_COMPLETED &&
  1388. wpa_s->current_ssid &&
  1389. wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
  1390. !locally_generated &&
  1391. disconnect_reason_recoverable(reason_code)) {
  1392. /*
  1393. * It looks like the AP has dropped association with
  1394. * us, but could allow us to get back in. Try to
  1395. * reconnect to the same BSS without full scan to save
  1396. * time for some common cases.
  1397. */
  1398. fast_reconnect = wpa_s->current_bss;
  1399. fast_reconnect_ssid = wpa_s->current_ssid;
  1400. } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  1401. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1402. else
  1403. wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
  1404. "immediate scan");
  1405. } else {
  1406. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
  1407. "try to re-connect");
  1408. wpa_s->reassociate = 0;
  1409. wpa_s->disconnected = 1;
  1410. wpa_supplicant_cancel_sched_scan(wpa_s);
  1411. }
  1412. bssid = wpa_s->bssid;
  1413. if (is_zero_ether_addr(bssid))
  1414. bssid = wpa_s->pending_bssid;
  1415. if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
  1416. wpas_connection_failed(wpa_s, bssid);
  1417. wpa_sm_notify_disassoc(wpa_s->wpa);
  1418. if (!is_zero_ether_addr(bssid) ||
  1419. wpa_s->wpa_state >= WPA_AUTHENTICATING) {
  1420. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1421. " reason=%d%s",
  1422. MAC2STR(bssid), reason_code,
  1423. locally_generated ? " locally_generated=1" : "");
  1424. }
  1425. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  1426. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
  1427. wpa_s->keys_cleared = 0;
  1428. wpa_clear_keys(wpa_s, wpa_s->bssid);
  1429. }
  1430. wpa_supplicant_mark_disassoc(wpa_s);
  1431. if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1432. sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
  1433. if (fast_reconnect) {
  1434. #ifndef CONFIG_NO_SCAN_PROCESSING
  1435. wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
  1436. if (wpa_supplicant_connect(wpa_s, fast_reconnect,
  1437. fast_reconnect_ssid) < 0) {
  1438. /* Recover through full scan */
  1439. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1440. }
  1441. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1442. }
  1443. }
  1444. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1445. void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
  1446. {
  1447. struct wpa_supplicant *wpa_s = eloop_ctx;
  1448. if (!wpa_s->pending_mic_error_report)
  1449. return;
  1450. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
  1451. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  1452. wpa_s->pending_mic_error_report = 0;
  1453. }
  1454. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1455. static void
  1456. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  1457. union wpa_event_data *data)
  1458. {
  1459. int pairwise;
  1460. struct os_time t;
  1461. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  1462. pairwise = (data && data->michael_mic_failure.unicast);
  1463. os_get_time(&t);
  1464. if ((wpa_s->last_michael_mic_error &&
  1465. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  1466. wpa_s->pending_mic_error_report) {
  1467. if (wpa_s->pending_mic_error_report) {
  1468. /*
  1469. * Send the pending MIC error report immediately since
  1470. * we are going to start countermeasures and AP better
  1471. * do the same.
  1472. */
  1473. wpa_sm_key_request(wpa_s->wpa, 1,
  1474. wpa_s->pending_mic_error_pairwise);
  1475. }
  1476. /* Send the new MIC error report immediately since we are going
  1477. * to start countermeasures and AP better do the same.
  1478. */
  1479. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1480. /* initialize countermeasures */
  1481. wpa_s->countermeasures = 1;
  1482. wpa_blacklist_add(wpa_s, wpa_s->bssid);
  1483. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  1484. /*
  1485. * Need to wait for completion of request frame. We do not get
  1486. * any callback for the message completion, so just wait a
  1487. * short while and hope for the best. */
  1488. os_sleep(0, 10000);
  1489. wpa_drv_set_countermeasures(wpa_s, 1);
  1490. wpa_supplicant_deauthenticate(wpa_s,
  1491. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1492. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  1493. wpa_s, NULL);
  1494. eloop_register_timeout(60, 0,
  1495. wpa_supplicant_stop_countermeasures,
  1496. wpa_s, NULL);
  1497. /* TODO: mark the AP rejected for 60 second. STA is
  1498. * allowed to associate with another AP.. */
  1499. } else {
  1500. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1501. if (wpa_s->mic_errors_seen) {
  1502. /*
  1503. * Reduce the effectiveness of Michael MIC error
  1504. * reports as a means for attacking against TKIP if
  1505. * more than one MIC failure is noticed with the same
  1506. * PTK. We delay the transmission of the reports by a
  1507. * random time between 0 and 60 seconds in order to
  1508. * force the attacker wait 60 seconds before getting
  1509. * the information on whether a frame resulted in a MIC
  1510. * failure.
  1511. */
  1512. u8 rval[4];
  1513. int sec;
  1514. if (os_get_random(rval, sizeof(rval)) < 0)
  1515. sec = os_random() % 60;
  1516. else
  1517. sec = WPA_GET_BE32(rval) % 60;
  1518. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
  1519. "report %d seconds", sec);
  1520. wpa_s->pending_mic_error_report = 1;
  1521. wpa_s->pending_mic_error_pairwise = pairwise;
  1522. eloop_cancel_timeout(
  1523. wpa_supplicant_delayed_mic_error_report,
  1524. wpa_s, NULL);
  1525. eloop_register_timeout(
  1526. sec, os_random() % 1000000,
  1527. wpa_supplicant_delayed_mic_error_report,
  1528. wpa_s, NULL);
  1529. } else {
  1530. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1531. }
  1532. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1533. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1534. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1535. }
  1536. wpa_s->last_michael_mic_error = t.sec;
  1537. wpa_s->mic_errors_seen++;
  1538. }
  1539. #ifdef CONFIG_TERMINATE_ONLASTIF
  1540. static int any_interfaces(struct wpa_supplicant *head)
  1541. {
  1542. struct wpa_supplicant *wpa_s;
  1543. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  1544. if (!wpa_s->interface_removed)
  1545. return 1;
  1546. return 0;
  1547. }
  1548. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1549. static void
  1550. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  1551. union wpa_event_data *data)
  1552. {
  1553. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  1554. return;
  1555. switch (data->interface_status.ievent) {
  1556. case EVENT_INTERFACE_ADDED:
  1557. if (!wpa_s->interface_removed)
  1558. break;
  1559. wpa_s->interface_removed = 0;
  1560. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
  1561. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  1562. wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
  1563. "driver after interface was added");
  1564. }
  1565. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1566. break;
  1567. case EVENT_INTERFACE_REMOVED:
  1568. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
  1569. wpa_s->interface_removed = 1;
  1570. wpa_supplicant_mark_disassoc(wpa_s);
  1571. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  1572. l2_packet_deinit(wpa_s->l2);
  1573. wpa_s->l2 = NULL;
  1574. #ifdef CONFIG_IBSS_RSN
  1575. ibss_rsn_deinit(wpa_s->ibss_rsn);
  1576. wpa_s->ibss_rsn = NULL;
  1577. #endif /* CONFIG_IBSS_RSN */
  1578. #ifdef CONFIG_TERMINATE_ONLASTIF
  1579. /* check if last interface */
  1580. if (!any_interfaces(wpa_s->global->ifaces))
  1581. eloop_terminate();
  1582. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1583. break;
  1584. }
  1585. }
  1586. #ifdef CONFIG_PEERKEY
  1587. static void
  1588. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  1589. union wpa_event_data *data)
  1590. {
  1591. if (data == NULL)
  1592. return;
  1593. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  1594. }
  1595. #endif /* CONFIG_PEERKEY */
  1596. #ifdef CONFIG_TDLS
  1597. static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
  1598. union wpa_event_data *data)
  1599. {
  1600. if (data == NULL)
  1601. return;
  1602. switch (data->tdls.oper) {
  1603. case TDLS_REQUEST_SETUP:
  1604. wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
  1605. break;
  1606. case TDLS_REQUEST_TEARDOWN:
  1607. wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
  1608. data->tdls.reason_code);
  1609. break;
  1610. }
  1611. }
  1612. #endif /* CONFIG_TDLS */
  1613. #ifdef CONFIG_IEEE80211R
  1614. static void
  1615. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  1616. union wpa_event_data *data)
  1617. {
  1618. if (data == NULL)
  1619. return;
  1620. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  1621. data->ft_ies.ies_len,
  1622. data->ft_ies.ft_action,
  1623. data->ft_ies.target_ap,
  1624. data->ft_ies.ric_ies,
  1625. data->ft_ies.ric_ies_len) < 0) {
  1626. /* TODO: prevent MLME/driver from trying to associate? */
  1627. }
  1628. }
  1629. #endif /* CONFIG_IEEE80211R */
  1630. #ifdef CONFIG_IBSS_RSN
  1631. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  1632. union wpa_event_data *data)
  1633. {
  1634. struct wpa_ssid *ssid;
  1635. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1636. return;
  1637. if (data == NULL)
  1638. return;
  1639. ssid = wpa_s->current_ssid;
  1640. if (ssid == NULL)
  1641. return;
  1642. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  1643. return;
  1644. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  1645. }
  1646. #endif /* CONFIG_IBSS_RSN */
  1647. #ifdef CONFIG_IEEE80211R
  1648. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  1649. size_t len)
  1650. {
  1651. const u8 *sta_addr, *target_ap_addr;
  1652. u16 status;
  1653. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  1654. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1655. return; /* only SME case supported for now */
  1656. if (len < 1 + 2 * ETH_ALEN + 2)
  1657. return;
  1658. if (data[0] != 2)
  1659. return; /* Only FT Action Response is supported for now */
  1660. sta_addr = data + 1;
  1661. target_ap_addr = data + 1 + ETH_ALEN;
  1662. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  1663. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
  1664. MACSTR " TargetAP " MACSTR " status %u",
  1665. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  1666. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  1667. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  1668. " in FT Action Response", MAC2STR(sta_addr));
  1669. return;
  1670. }
  1671. if (status) {
  1672. wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
  1673. "failure (status code %d)", status);
  1674. /* TODO: report error to FT code(?) */
  1675. return;
  1676. }
  1677. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  1678. len - (1 + 2 * ETH_ALEN + 2), 1,
  1679. target_ap_addr, NULL, 0) < 0)
  1680. return;
  1681. #ifdef CONFIG_SME
  1682. {
  1683. struct wpa_bss *bss;
  1684. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  1685. if (bss)
  1686. wpa_s->sme.freq = bss->freq;
  1687. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  1688. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  1689. WLAN_AUTH_FT);
  1690. }
  1691. #endif /* CONFIG_SME */
  1692. }
  1693. #endif /* CONFIG_IEEE80211R */
  1694. static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
  1695. struct unprot_deauth *e)
  1696. {
  1697. #ifdef CONFIG_IEEE80211W
  1698. wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
  1699. "dropped: " MACSTR " -> " MACSTR
  1700. " (reason code %u)",
  1701. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1702. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1703. #endif /* CONFIG_IEEE80211W */
  1704. }
  1705. static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
  1706. struct unprot_disassoc *e)
  1707. {
  1708. #ifdef CONFIG_IEEE80211W
  1709. wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
  1710. "dropped: " MACSTR " -> " MACSTR
  1711. " (reason code %u)",
  1712. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1713. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1714. #endif /* CONFIG_IEEE80211W */
  1715. }
  1716. static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
  1717. {
  1718. u8 action, mode;
  1719. const u8 *pos, *end;
  1720. if (rx->data == NULL || rx->len == 0)
  1721. return;
  1722. pos = rx->data;
  1723. end = pos + rx->len;
  1724. action = *pos++;
  1725. wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
  1726. action, MAC2STR(rx->sa));
  1727. switch (action) {
  1728. case WNM_BSS_TRANS_MGMT_REQ:
  1729. if (pos + 5 > end)
  1730. break;
  1731. wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
  1732. "Request: dialog_token=%u request_mode=0x%x "
  1733. "disassoc_timer=%u validity_interval=%u",
  1734. pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
  1735. mode = pos[1];
  1736. pos += 5;
  1737. if (mode & 0x08)
  1738. pos += 12; /* BSS Termination Duration */
  1739. if (mode & 0x10) {
  1740. char url[256];
  1741. if (pos + 1 > end || pos + 1 + pos[0] > end) {
  1742. wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
  1743. "Transition Management Request "
  1744. "(URL)");
  1745. break;
  1746. }
  1747. os_memcpy(url, pos + 1, pos[0]);
  1748. url[pos[0]] = '\0';
  1749. wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
  1750. "Imminent - session_info_url=%s", url);
  1751. }
  1752. break;
  1753. }
  1754. }
  1755. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  1756. union wpa_event_data *data)
  1757. {
  1758. struct wpa_supplicant *wpa_s = ctx;
  1759. u16 reason_code = 0;
  1760. int locally_generated = 0;
  1761. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  1762. event != EVENT_INTERFACE_ENABLED &&
  1763. event != EVENT_INTERFACE_STATUS &&
  1764. event != EVENT_SCHED_SCAN_STOPPED) {
  1765. wpa_dbg(wpa_s, MSG_DEBUG,
  1766. "Ignore event %s (%d) while interface is disabled",
  1767. event_to_string(event), event);
  1768. return;
  1769. }
  1770. #ifndef CONFIG_NO_STDOUT_DEBUG
  1771. {
  1772. int level = MSG_DEBUG;
  1773. if (event == EVENT_RX_MGMT && data && data->rx_mgmt.frame &&
  1774. data->rx_mgmt.frame_len >= 24) {
  1775. const struct ieee80211_hdr *hdr;
  1776. u16 fc;
  1777. hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
  1778. fc = le_to_host16(hdr->frame_control);
  1779. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  1780. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
  1781. level = MSG_EXCESSIVE;
  1782. }
  1783. wpa_dbg(wpa_s, level, "Event %s (%d) received",
  1784. event_to_string(event), event);
  1785. }
  1786. #endif /* CONFIG_NO_STDOUT_DEBUG */
  1787. switch (event) {
  1788. case EVENT_AUTH:
  1789. sme_event_auth(wpa_s, data);
  1790. break;
  1791. case EVENT_ASSOC:
  1792. wpa_supplicant_event_assoc(wpa_s, data);
  1793. break;
  1794. case EVENT_DISASSOC:
  1795. wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
  1796. if (data) {
  1797. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
  1798. data->disassoc_info.reason_code,
  1799. data->disassoc_info.locally_generated ?
  1800. " (locally generated)" : "");
  1801. if (data->disassoc_info.addr)
  1802. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  1803. MAC2STR(data->disassoc_info.addr));
  1804. }
  1805. #ifdef CONFIG_AP
  1806. if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
  1807. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1808. data->disassoc_info.addr);
  1809. break;
  1810. }
  1811. if (wpa_s->ap_iface) {
  1812. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
  1813. "AP mode");
  1814. break;
  1815. }
  1816. #endif /* CONFIG_AP */
  1817. if (data) {
  1818. reason_code = data->disassoc_info.reason_code;
  1819. locally_generated =
  1820. data->disassoc_info.locally_generated;
  1821. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  1822. data->disassoc_info.ie,
  1823. data->disassoc_info.ie_len);
  1824. #ifdef CONFIG_P2P
  1825. wpas_p2p_disassoc_notif(
  1826. wpa_s, data->disassoc_info.addr, reason_code,
  1827. data->disassoc_info.ie,
  1828. data->disassoc_info.ie_len);
  1829. #endif /* CONFIG_P2P */
  1830. }
  1831. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1832. sme_event_disassoc(wpa_s, data);
  1833. /* fall through */
  1834. case EVENT_DEAUTH:
  1835. if (event == EVENT_DEAUTH) {
  1836. wpa_dbg(wpa_s, MSG_DEBUG,
  1837. "Deauthentication notification");
  1838. if (data) {
  1839. reason_code = data->deauth_info.reason_code;
  1840. locally_generated =
  1841. data->deauth_info.locally_generated;
  1842. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
  1843. data->deauth_info.reason_code,
  1844. data->deauth_info.locally_generated ?
  1845. " (locally generated)" : "");
  1846. if (data->deauth_info.addr) {
  1847. wpa_dbg(wpa_s, MSG_DEBUG, " * address "
  1848. MACSTR,
  1849. MAC2STR(data->deauth_info.
  1850. addr));
  1851. }
  1852. wpa_hexdump(MSG_DEBUG,
  1853. "Deauthentication frame IE(s)",
  1854. data->deauth_info.ie,
  1855. data->deauth_info.ie_len);
  1856. #ifdef CONFIG_P2P
  1857. wpas_p2p_deauth_notif(
  1858. wpa_s, data->deauth_info.addr,
  1859. reason_code,
  1860. data->deauth_info.ie,
  1861. data->deauth_info.ie_len);
  1862. #endif /* CONFIG_P2P */
  1863. }
  1864. }
  1865. #ifdef CONFIG_AP
  1866. if (wpa_s->ap_iface && data && data->deauth_info.addr) {
  1867. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1868. data->deauth_info.addr);
  1869. break;
  1870. }
  1871. if (wpa_s->ap_iface) {
  1872. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
  1873. "AP mode");
  1874. break;
  1875. }
  1876. #endif /* CONFIG_AP */
  1877. wpa_supplicant_event_disassoc(wpa_s, reason_code,
  1878. locally_generated);
  1879. break;
  1880. case EVENT_MICHAEL_MIC_FAILURE:
  1881. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  1882. break;
  1883. #ifndef CONFIG_NO_SCAN_PROCESSING
  1884. case EVENT_SCAN_RESULTS:
  1885. wpa_supplicant_event_scan_results(wpa_s, data);
  1886. break;
  1887. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1888. case EVENT_ASSOCINFO:
  1889. wpa_supplicant_event_associnfo(wpa_s, data);
  1890. break;
  1891. case EVENT_INTERFACE_STATUS:
  1892. wpa_supplicant_event_interface_status(wpa_s, data);
  1893. break;
  1894. case EVENT_PMKID_CANDIDATE:
  1895. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  1896. break;
  1897. #ifdef CONFIG_PEERKEY
  1898. case EVENT_STKSTART:
  1899. wpa_supplicant_event_stkstart(wpa_s, data);
  1900. break;
  1901. #endif /* CONFIG_PEERKEY */
  1902. #ifdef CONFIG_TDLS
  1903. case EVENT_TDLS:
  1904. wpa_supplicant_event_tdls(wpa_s, data);
  1905. break;
  1906. #endif /* CONFIG_TDLS */
  1907. #ifdef CONFIG_IEEE80211R
  1908. case EVENT_FT_RESPONSE:
  1909. wpa_supplicant_event_ft_response(wpa_s, data);
  1910. break;
  1911. #endif /* CONFIG_IEEE80211R */
  1912. #ifdef CONFIG_IBSS_RSN
  1913. case EVENT_IBSS_RSN_START:
  1914. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  1915. break;
  1916. #endif /* CONFIG_IBSS_RSN */
  1917. case EVENT_ASSOC_REJECT:
  1918. if (data->assoc_reject.bssid)
  1919. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  1920. "bssid=" MACSTR " status_code=%u",
  1921. MAC2STR(data->assoc_reject.bssid),
  1922. data->assoc_reject.status_code);
  1923. else
  1924. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  1925. "status_code=%u",
  1926. data->assoc_reject.status_code);
  1927. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1928. sme_event_assoc_reject(wpa_s, data);
  1929. break;
  1930. case EVENT_AUTH_TIMED_OUT:
  1931. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1932. sme_event_auth_timed_out(wpa_s, data);
  1933. break;
  1934. case EVENT_ASSOC_TIMED_OUT:
  1935. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1936. sme_event_assoc_timed_out(wpa_s, data);
  1937. break;
  1938. case EVENT_TX_STATUS:
  1939. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
  1940. " type=%d stype=%d",
  1941. MAC2STR(data->tx_status.dst),
  1942. data->tx_status.type, data->tx_status.stype);
  1943. #ifdef CONFIG_AP
  1944. if (wpa_s->ap_iface == NULL) {
  1945. #ifdef CONFIG_OFFCHANNEL
  1946. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1947. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  1948. offchannel_send_action_tx_status(
  1949. wpa_s, data->tx_status.dst,
  1950. data->tx_status.data,
  1951. data->tx_status.data_len,
  1952. data->tx_status.ack ?
  1953. OFFCHANNEL_SEND_ACTION_SUCCESS :
  1954. OFFCHANNEL_SEND_ACTION_NO_ACK);
  1955. #endif /* CONFIG_OFFCHANNEL */
  1956. break;
  1957. }
  1958. #endif /* CONFIG_AP */
  1959. #ifdef CONFIG_OFFCHANNEL
  1960. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
  1961. MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
  1962. /*
  1963. * Catch TX status events for Action frames we sent via group
  1964. * interface in GO mode.
  1965. */
  1966. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1967. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  1968. os_memcmp(wpa_s->parent->pending_action_dst,
  1969. data->tx_status.dst, ETH_ALEN) == 0) {
  1970. offchannel_send_action_tx_status(
  1971. wpa_s->parent, data->tx_status.dst,
  1972. data->tx_status.data,
  1973. data->tx_status.data_len,
  1974. data->tx_status.ack ?
  1975. OFFCHANNEL_SEND_ACTION_SUCCESS :
  1976. OFFCHANNEL_SEND_ACTION_NO_ACK);
  1977. break;
  1978. }
  1979. #endif /* CONFIG_OFFCHANNEL */
  1980. #ifdef CONFIG_AP
  1981. switch (data->tx_status.type) {
  1982. case WLAN_FC_TYPE_MGMT:
  1983. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  1984. data->tx_status.data_len,
  1985. data->tx_status.stype,
  1986. data->tx_status.ack);
  1987. break;
  1988. case WLAN_FC_TYPE_DATA:
  1989. ap_tx_status(wpa_s, data->tx_status.dst,
  1990. data->tx_status.data,
  1991. data->tx_status.data_len,
  1992. data->tx_status.ack);
  1993. break;
  1994. }
  1995. #endif /* CONFIG_AP */
  1996. break;
  1997. #ifdef CONFIG_AP
  1998. case EVENT_EAPOL_TX_STATUS:
  1999. ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
  2000. data->eapol_tx_status.data,
  2001. data->eapol_tx_status.data_len,
  2002. data->eapol_tx_status.ack);
  2003. break;
  2004. case EVENT_DRIVER_CLIENT_POLL_OK:
  2005. ap_client_poll_ok(wpa_s, data->client_poll.addr);
  2006. break;
  2007. case EVENT_RX_FROM_UNKNOWN:
  2008. if (wpa_s->ap_iface == NULL)
  2009. break;
  2010. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
  2011. data->rx_from_unknown.wds);
  2012. break;
  2013. case EVENT_RX_MGMT:
  2014. if (wpa_s->ap_iface == NULL) {
  2015. #ifdef CONFIG_P2P
  2016. u16 fc, stype;
  2017. const struct ieee80211_mgmt *mgmt;
  2018. mgmt = (const struct ieee80211_mgmt *)
  2019. data->rx_mgmt.frame;
  2020. fc = le_to_host16(mgmt->frame_control);
  2021. stype = WLAN_FC_GET_STYPE(fc);
  2022. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  2023. data->rx_mgmt.frame_len > 24) {
  2024. const u8 *src = mgmt->sa;
  2025. const u8 *ie = mgmt->u.probe_req.variable;
  2026. size_t ie_len = data->rx_mgmt.frame_len -
  2027. (mgmt->u.probe_req.variable -
  2028. data->rx_mgmt.frame);
  2029. wpas_p2p_probe_req_rx(wpa_s, src, mgmt->da,
  2030. mgmt->bssid, ie, ie_len);
  2031. break;
  2032. }
  2033. #endif /* CONFIG_P2P */
  2034. wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
  2035. "management frame in non-AP mode");
  2036. break;
  2037. }
  2038. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  2039. break;
  2040. #endif /* CONFIG_AP */
  2041. case EVENT_RX_ACTION:
  2042. wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
  2043. " Category=%u DataLen=%d freq=%d MHz",
  2044. MAC2STR(data->rx_action.sa),
  2045. data->rx_action.category, (int) data->rx_action.len,
  2046. data->rx_action.freq);
  2047. #ifdef CONFIG_IEEE80211R
  2048. if (data->rx_action.category == WLAN_ACTION_FT) {
  2049. ft_rx_action(wpa_s, data->rx_action.data,
  2050. data->rx_action.len);
  2051. break;
  2052. }
  2053. #endif /* CONFIG_IEEE80211R */
  2054. #ifdef CONFIG_IEEE80211W
  2055. #ifdef CONFIG_SME
  2056. if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
  2057. sme_sa_query_rx(wpa_s, data->rx_action.sa,
  2058. data->rx_action.data,
  2059. data->rx_action.len);
  2060. break;
  2061. }
  2062. #endif /* CONFIG_SME */
  2063. #endif /* CONFIG_IEEE80211W */
  2064. #ifdef CONFIG_GAS
  2065. if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
  2066. gas_query_rx(wpa_s->gas, data->rx_action.da,
  2067. data->rx_action.sa, data->rx_action.bssid,
  2068. data->rx_action.data, data->rx_action.len,
  2069. data->rx_action.freq) == 0)
  2070. break;
  2071. #endif /* CONFIG_GAS */
  2072. if (data->rx_action.category == WLAN_ACTION_WNM) {
  2073. wnm_action_rx(wpa_s, &data->rx_action);
  2074. break;
  2075. }
  2076. #ifdef CONFIG_TDLS
  2077. if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
  2078. data->rx_action.len >= 4 &&
  2079. data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
  2080. wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
  2081. "Response from " MACSTR,
  2082. MAC2STR(data->rx_action.sa));
  2083. break;
  2084. }
  2085. #endif /* CONFIG_TDLS */
  2086. #ifdef CONFIG_P2P
  2087. wpas_p2p_rx_action(wpa_s, data->rx_action.da,
  2088. data->rx_action.sa,
  2089. data->rx_action.bssid,
  2090. data->rx_action.category,
  2091. data->rx_action.data,
  2092. data->rx_action.len, data->rx_action.freq);
  2093. #endif /* CONFIG_P2P */
  2094. break;
  2095. case EVENT_RX_PROBE_REQ:
  2096. if (data->rx_probe_req.sa == NULL ||
  2097. data->rx_probe_req.ie == NULL)
  2098. break;
  2099. #ifdef CONFIG_AP
  2100. if (wpa_s->ap_iface) {
  2101. hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
  2102. data->rx_probe_req.sa,
  2103. data->rx_probe_req.da,
  2104. data->rx_probe_req.bssid,
  2105. data->rx_probe_req.ie,
  2106. data->rx_probe_req.ie_len);
  2107. break;
  2108. }
  2109. #endif /* CONFIG_AP */
  2110. #ifdef CONFIG_P2P
  2111. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  2112. data->rx_probe_req.da,
  2113. data->rx_probe_req.bssid,
  2114. data->rx_probe_req.ie,
  2115. data->rx_probe_req.ie_len);
  2116. #endif /* CONFIG_P2P */
  2117. break;
  2118. case EVENT_REMAIN_ON_CHANNEL:
  2119. #ifdef CONFIG_OFFCHANNEL
  2120. offchannel_remain_on_channel_cb(
  2121. wpa_s, data->remain_on_channel.freq,
  2122. data->remain_on_channel.duration);
  2123. #endif /* CONFIG_OFFCHANNEL */
  2124. #ifdef CONFIG_P2P
  2125. wpas_p2p_remain_on_channel_cb(
  2126. wpa_s, data->remain_on_channel.freq,
  2127. data->remain_on_channel.duration);
  2128. #endif /* CONFIG_P2P */
  2129. break;
  2130. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  2131. #ifdef CONFIG_OFFCHANNEL
  2132. offchannel_cancel_remain_on_channel_cb(
  2133. wpa_s, data->remain_on_channel.freq);
  2134. #endif /* CONFIG_OFFCHANNEL */
  2135. #ifdef CONFIG_P2P
  2136. wpas_p2p_cancel_remain_on_channel_cb(
  2137. wpa_s, data->remain_on_channel.freq);
  2138. #endif /* CONFIG_P2P */
  2139. break;
  2140. #ifdef CONFIG_P2P
  2141. case EVENT_P2P_DEV_FOUND: {
  2142. struct p2p_peer_info peer_info;
  2143. os_memset(&peer_info, 0, sizeof(peer_info));
  2144. if (data->p2p_dev_found.dev_addr)
  2145. os_memcpy(peer_info.p2p_device_addr,
  2146. data->p2p_dev_found.dev_addr, ETH_ALEN);
  2147. if (data->p2p_dev_found.pri_dev_type)
  2148. os_memcpy(peer_info.pri_dev_type,
  2149. data->p2p_dev_found.pri_dev_type,
  2150. sizeof(peer_info.pri_dev_type));
  2151. if (data->p2p_dev_found.dev_name)
  2152. os_strlcpy(peer_info.device_name,
  2153. data->p2p_dev_found.dev_name,
  2154. sizeof(peer_info.device_name));
  2155. peer_info.config_methods = data->p2p_dev_found.config_methods;
  2156. peer_info.dev_capab = data->p2p_dev_found.dev_capab;
  2157. peer_info.group_capab = data->p2p_dev_found.group_capab;
  2158. /*
  2159. * FIX: new_device=1 is not necessarily correct. We should
  2160. * maintain a P2P peer database in wpa_supplicant and update
  2161. * this information based on whether the peer is truly new.
  2162. */
  2163. wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
  2164. break;
  2165. }
  2166. case EVENT_P2P_GO_NEG_REQ_RX:
  2167. wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
  2168. data->p2p_go_neg_req_rx.dev_passwd_id);
  2169. break;
  2170. case EVENT_P2P_GO_NEG_COMPLETED:
  2171. wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
  2172. break;
  2173. case EVENT_P2P_PROV_DISC_REQUEST:
  2174. wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
  2175. data->p2p_prov_disc_req.config_methods,
  2176. data->p2p_prov_disc_req.dev_addr,
  2177. data->p2p_prov_disc_req.pri_dev_type,
  2178. data->p2p_prov_disc_req.dev_name,
  2179. data->p2p_prov_disc_req.supp_config_methods,
  2180. data->p2p_prov_disc_req.dev_capab,
  2181. data->p2p_prov_disc_req.group_capab,
  2182. NULL, 0);
  2183. break;
  2184. case EVENT_P2P_PROV_DISC_RESPONSE:
  2185. wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
  2186. data->p2p_prov_disc_resp.config_methods);
  2187. break;
  2188. case EVENT_P2P_SD_REQUEST:
  2189. wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
  2190. data->p2p_sd_req.sa,
  2191. data->p2p_sd_req.dialog_token,
  2192. data->p2p_sd_req.update_indic,
  2193. data->p2p_sd_req.tlvs,
  2194. data->p2p_sd_req.tlvs_len);
  2195. break;
  2196. case EVENT_P2P_SD_RESPONSE:
  2197. wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
  2198. data->p2p_sd_resp.update_indic,
  2199. data->p2p_sd_resp.tlvs,
  2200. data->p2p_sd_resp.tlvs_len);
  2201. break;
  2202. #endif /* CONFIG_P2P */
  2203. case EVENT_EAPOL_RX:
  2204. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  2205. data->eapol_rx.data,
  2206. data->eapol_rx.data_len);
  2207. break;
  2208. case EVENT_SIGNAL_CHANGE:
  2209. bgscan_notify_signal_change(
  2210. wpa_s, data->signal_change.above_threshold,
  2211. data->signal_change.current_signal,
  2212. data->signal_change.current_noise,
  2213. data->signal_change.current_txrate);
  2214. break;
  2215. case EVENT_INTERFACE_ENABLED:
  2216. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
  2217. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  2218. wpa_supplicant_update_mac_addr(wpa_s);
  2219. #ifdef CONFIG_AP
  2220. if (!wpa_s->ap_iface) {
  2221. wpa_supplicant_set_state(wpa_s,
  2222. WPA_DISCONNECTED);
  2223. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2224. } else
  2225. wpa_supplicant_set_state(wpa_s,
  2226. WPA_COMPLETED);
  2227. #else /* CONFIG_AP */
  2228. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  2229. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2230. #endif /* CONFIG_AP */
  2231. }
  2232. break;
  2233. case EVENT_INTERFACE_DISABLED:
  2234. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
  2235. wpa_supplicant_mark_disassoc(wpa_s);
  2236. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  2237. break;
  2238. case EVENT_CHANNEL_LIST_CHANGED:
  2239. if (wpa_s->drv_priv == NULL)
  2240. break; /* Ignore event during drv initialization */
  2241. free_hw_features(wpa_s);
  2242. wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
  2243. wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
  2244. #ifdef CONFIG_P2P
  2245. wpas_p2p_update_channel_list(wpa_s);
  2246. #endif /* CONFIG_P2P */
  2247. break;
  2248. case EVENT_INTERFACE_UNAVAILABLE:
  2249. #ifdef CONFIG_P2P
  2250. wpas_p2p_interface_unavailable(wpa_s);
  2251. #endif /* CONFIG_P2P */
  2252. break;
  2253. case EVENT_BEST_CHANNEL:
  2254. wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
  2255. "(%d %d %d)",
  2256. data->best_chan.freq_24, data->best_chan.freq_5,
  2257. data->best_chan.freq_overall);
  2258. wpa_s->best_24_freq = data->best_chan.freq_24;
  2259. wpa_s->best_5_freq = data->best_chan.freq_5;
  2260. wpa_s->best_overall_freq = data->best_chan.freq_overall;
  2261. #ifdef CONFIG_P2P
  2262. wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
  2263. data->best_chan.freq_5,
  2264. data->best_chan.freq_overall);
  2265. #endif /* CONFIG_P2P */
  2266. break;
  2267. case EVENT_UNPROT_DEAUTH:
  2268. wpa_supplicant_event_unprot_deauth(wpa_s,
  2269. &data->unprot_deauth);
  2270. break;
  2271. case EVENT_UNPROT_DISASSOC:
  2272. wpa_supplicant_event_unprot_disassoc(wpa_s,
  2273. &data->unprot_disassoc);
  2274. break;
  2275. case EVENT_STATION_LOW_ACK:
  2276. #ifdef CONFIG_AP
  2277. if (wpa_s->ap_iface && data)
  2278. hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
  2279. data->low_ack.addr);
  2280. #endif /* CONFIG_AP */
  2281. #ifdef CONFIG_TDLS
  2282. if (data)
  2283. wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
  2284. #endif /* CONFIG_TDLS */
  2285. break;
  2286. case EVENT_IBSS_PEER_LOST:
  2287. #ifdef CONFIG_IBSS_RSN
  2288. ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
  2289. #endif /* CONFIG_IBSS_RSN */
  2290. break;
  2291. case EVENT_DRIVER_GTK_REKEY:
  2292. if (os_memcmp(data->driver_gtk_rekey.bssid,
  2293. wpa_s->bssid, ETH_ALEN))
  2294. break;
  2295. if (!wpa_s->wpa)
  2296. break;
  2297. wpa_sm_update_replay_ctr(wpa_s->wpa,
  2298. data->driver_gtk_rekey.replay_ctr);
  2299. break;
  2300. case EVENT_SCHED_SCAN_STOPPED:
  2301. wpa_s->sched_scanning = 0;
  2302. wpa_supplicant_notify_scanning(wpa_s, 0);
  2303. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  2304. break;
  2305. /*
  2306. * If we timed out, start a new sched scan to continue
  2307. * searching for more SSIDs.
  2308. */
  2309. if (wpa_s->sched_scan_timed_out)
  2310. wpa_supplicant_req_sched_scan(wpa_s);
  2311. break;
  2312. case EVENT_WPS_BUTTON_PUSHED:
  2313. #ifdef CONFIG_WPS
  2314. wpas_wps_start_pbc(wpa_s, NULL, 0);
  2315. #endif /* CONFIG_WPS */
  2316. break;
  2317. default:
  2318. wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
  2319. break;
  2320. }
  2321. }