events.c 74 KB

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