events.c 79 KB

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