events.c 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886
  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. struct wpa_scan_results *scan_res)
  809. {
  810. size_t i;
  811. struct wpa_scan_res *current_bss = NULL;
  812. int min_diff;
  813. if (wpa_s->reassociate)
  814. return 1; /* explicit request to reassociate */
  815. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  816. return 1; /* we are not associated; continue */
  817. if (wpa_s->current_ssid == NULL)
  818. return 1; /* unknown current SSID */
  819. if (wpa_s->current_ssid != ssid)
  820. return 1; /* different network block */
  821. if (wpas_driver_bss_selection(wpa_s))
  822. return 0; /* Driver-based roaming */
  823. for (i = 0; i < scan_res->num; i++) {
  824. struct wpa_scan_res *res = scan_res->res[i];
  825. const u8 *ie;
  826. if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
  827. continue;
  828. ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
  829. if (ie == NULL)
  830. continue;
  831. if (ie[1] != wpa_s->current_ssid->ssid_len ||
  832. os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
  833. continue;
  834. current_bss = res;
  835. break;
  836. }
  837. if (!current_bss)
  838. return 1; /* current BSS not seen in scan results */
  839. #ifndef CONFIG_NO_ROAMING
  840. wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
  841. wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
  842. MAC2STR(current_bss->bssid), current_bss->level);
  843. wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
  844. MAC2STR(selected->bssid), selected->level);
  845. if (wpa_s->current_ssid->bssid_set &&
  846. os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
  847. 0) {
  848. wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
  849. "has preferred BSSID");
  850. return 1;
  851. }
  852. min_diff = 2;
  853. if (current_bss->level < 0) {
  854. if (current_bss->level < -85)
  855. min_diff = 1;
  856. else if (current_bss->level < -80)
  857. min_diff = 2;
  858. else if (current_bss->level < -75)
  859. min_diff = 3;
  860. else if (current_bss->level < -70)
  861. min_diff = 4;
  862. else
  863. min_diff = 5;
  864. }
  865. if (abs(current_bss->level - selected->level) < min_diff) {
  866. wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
  867. "in signal level");
  868. return 0;
  869. }
  870. return 1;
  871. #else /* CONFIG_NO_ROAMING */
  872. return 0;
  873. #endif /* CONFIG_NO_ROAMING */
  874. }
  875. /* Return < 0 if no scan results could be fetched or if scan results should not
  876. * be shared with other virtual interfaces. */
  877. static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  878. union wpa_event_data *data)
  879. {
  880. struct wpa_bss *selected;
  881. struct wpa_ssid *ssid = NULL;
  882. struct wpa_scan_results *scan_res;
  883. int ap = 0;
  884. #ifndef CONFIG_NO_RANDOM_POOL
  885. size_t i, num;
  886. #endif /* CONFIG_NO_RANDOM_POOL */
  887. #ifdef CONFIG_AP
  888. if (wpa_s->ap_iface)
  889. ap = 1;
  890. #endif /* CONFIG_AP */
  891. wpa_supplicant_notify_scanning(wpa_s, 0);
  892. #ifdef CONFIG_P2P
  893. if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
  894. wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending) {
  895. wpa_s->p2p_cb_on_scan_complete = 0;
  896. if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
  897. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
  898. "stopped scan processing");
  899. return -1;
  900. }
  901. }
  902. wpa_s->sta_scan_pending = 0;
  903. #endif /* CONFIG_P2P */
  904. scan_res = wpa_supplicant_get_scan_results(wpa_s,
  905. data ? &data->scan_info :
  906. NULL, 1);
  907. if (scan_res == NULL) {
  908. if (wpa_s->conf->ap_scan == 2 || ap)
  909. return -1;
  910. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
  911. "scanning again");
  912. wpa_supplicant_req_new_scan(wpa_s, 1, 0);
  913. return -1;
  914. }
  915. #ifndef CONFIG_NO_RANDOM_POOL
  916. num = scan_res->num;
  917. if (num > 10)
  918. num = 10;
  919. for (i = 0; i < num; i++) {
  920. u8 buf[5];
  921. struct wpa_scan_res *res = scan_res->res[i];
  922. buf[0] = res->bssid[5];
  923. buf[1] = res->qual & 0xff;
  924. buf[2] = res->noise & 0xff;
  925. buf[3] = res->level & 0xff;
  926. buf[4] = res->tsf & 0xff;
  927. random_add_randomness(buf, sizeof(buf));
  928. }
  929. #endif /* CONFIG_NO_RANDOM_POOL */
  930. if (wpa_s->scan_res_handler) {
  931. void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
  932. struct wpa_scan_results *scan_res);
  933. scan_res_handler = wpa_s->scan_res_handler;
  934. wpa_s->scan_res_handler = NULL;
  935. scan_res_handler(wpa_s, scan_res);
  936. wpa_scan_results_free(scan_res);
  937. return -2;
  938. }
  939. if (ap) {
  940. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
  941. #ifdef CONFIG_AP
  942. if (wpa_s->ap_iface->scan_cb)
  943. wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
  944. #endif /* CONFIG_AP */
  945. wpa_scan_results_free(scan_res);
  946. return 0;
  947. }
  948. wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
  949. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  950. wpas_notify_scan_results(wpa_s);
  951. wpas_notify_scan_done(wpa_s, 1);
  952. if (sme_proc_obss_scan(wpa_s) > 0) {
  953. wpa_scan_results_free(scan_res);
  954. return 0;
  955. }
  956. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
  957. wpa_scan_results_free(scan_res);
  958. return 0;
  959. }
  960. if (autoscan_notify_scan(wpa_s, scan_res)) {
  961. wpa_scan_results_free(scan_res);
  962. return 0;
  963. }
  964. if (wpa_s->disconnected) {
  965. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  966. wpa_scan_results_free(scan_res);
  967. return 0;
  968. }
  969. if (!wpas_driver_bss_selection(wpa_s) &&
  970. bgscan_notify_scan(wpa_s, scan_res) == 1) {
  971. wpa_scan_results_free(scan_res);
  972. return 0;
  973. }
  974. wpas_wps_update_ap_info(wpa_s, scan_res);
  975. selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
  976. if (selected) {
  977. int skip;
  978. skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
  979. scan_res);
  980. wpa_scan_results_free(scan_res);
  981. if (skip) {
  982. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  983. return 0;
  984. }
  985. if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
  986. wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
  987. return -1;
  988. }
  989. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  990. } else {
  991. wpa_scan_results_free(scan_res);
  992. wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
  993. ssid = wpa_supplicant_pick_new_network(wpa_s);
  994. if (ssid) {
  995. wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
  996. wpa_supplicant_associate(wpa_s, NULL, ssid);
  997. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  998. } else {
  999. int timeout_sec = wpa_s->scan_interval;
  1000. int timeout_usec = 0;
  1001. #ifdef CONFIG_P2P
  1002. if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
  1003. return 0;
  1004. if (wpa_s->p2p_in_provisioning) {
  1005. /*
  1006. * Use shorter wait during P2P Provisioning
  1007. * state to speed up group formation.
  1008. */
  1009. timeout_sec = 0;
  1010. timeout_usec = 250000;
  1011. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  1012. timeout_usec);
  1013. return 0;
  1014. }
  1015. #endif /* CONFIG_P2P */
  1016. #ifdef CONFIG_INTERWORKING
  1017. if (wpa_s->conf->auto_interworking &&
  1018. wpa_s->conf->interworking &&
  1019. wpa_s->conf->cred) {
  1020. wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
  1021. "start ANQP fetch since no matching "
  1022. "networks found");
  1023. wpa_s->network_select = 1;
  1024. wpa_s->auto_network_select = 1;
  1025. interworking_start_fetch_anqp(wpa_s);
  1026. return 0;
  1027. }
  1028. #endif /* CONFIG_INTERWORKING */
  1029. if (wpa_supplicant_req_sched_scan(wpa_s))
  1030. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  1031. timeout_usec);
  1032. }
  1033. }
  1034. return 0;
  1035. }
  1036. static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  1037. union wpa_event_data *data)
  1038. {
  1039. const char *rn, *rn2;
  1040. struct wpa_supplicant *ifs;
  1041. if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
  1042. /*
  1043. * If no scan results could be fetched, then no need to
  1044. * notify those interfaces that did not actually request
  1045. * this scan.
  1046. */
  1047. return;
  1048. }
  1049. /*
  1050. * Check other interfaces to see if they have the same radio-name. If
  1051. * so, they get updated with this same scan info.
  1052. */
  1053. if (!wpa_s->driver->get_radio_name)
  1054. return;
  1055. rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
  1056. if (rn == NULL || rn[0] == '\0')
  1057. return;
  1058. wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
  1059. "sharing same radio (%s) in event_scan_results", rn);
  1060. for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
  1061. if (ifs == wpa_s || !ifs->driver->get_radio_name)
  1062. continue;
  1063. rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
  1064. if (rn2 && os_strcmp(rn, rn2) == 0) {
  1065. wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
  1066. "sibling", ifs->ifname);
  1067. _wpa_supplicant_event_scan_results(ifs, data);
  1068. }
  1069. }
  1070. }
  1071. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1072. #ifdef CONFIG_WNM
  1073. static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
  1074. {
  1075. struct wpa_supplicant *wpa_s = eloop_ctx;
  1076. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1077. return;
  1078. wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
  1079. MAC2STR(wpa_s->bssid));
  1080. /* TODO: could skip this if normal data traffic has been sent */
  1081. /* TODO: Consider using some more appropriate data frame for this */
  1082. if (wpa_s->l2)
  1083. l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
  1084. #ifdef CONFIG_SME
  1085. if (wpa_s->sme.bss_max_idle_period) {
  1086. unsigned int msec;
  1087. msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
  1088. if (msec > 100)
  1089. msec -= 100;
  1090. eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
  1091. wnm_bss_keep_alive, wpa_s, NULL);
  1092. }
  1093. #endif /* CONFIG_SME */
  1094. }
  1095. static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
  1096. const u8 *ies, size_t ies_len)
  1097. {
  1098. struct ieee802_11_elems elems;
  1099. if (ies == NULL)
  1100. return;
  1101. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
  1102. return;
  1103. #ifdef CONFIG_SME
  1104. if (elems.bss_max_idle_period) {
  1105. unsigned int msec;
  1106. wpa_s->sme.bss_max_idle_period =
  1107. WPA_GET_LE16(elems.bss_max_idle_period);
  1108. wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
  1109. "TU)%s", wpa_s->sme.bss_max_idle_period,
  1110. (elems.bss_max_idle_period[2] & 0x01) ?
  1111. " (protected keep-live required)" : "");
  1112. if (wpa_s->sme.bss_max_idle_period == 0)
  1113. wpa_s->sme.bss_max_idle_period = 1;
  1114. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
  1115. eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
  1116. /* msec times 1000 */
  1117. msec = wpa_s->sme.bss_max_idle_period * 1024;
  1118. if (msec > 100)
  1119. msec -= 100;
  1120. eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
  1121. wnm_bss_keep_alive, wpa_s,
  1122. NULL);
  1123. }
  1124. }
  1125. #endif /* CONFIG_SME */
  1126. }
  1127. #endif /* CONFIG_WNM */
  1128. void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
  1129. {
  1130. #ifdef CONFIG_WNM
  1131. eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
  1132. #endif /* CONFIG_WNM */
  1133. }
  1134. static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  1135. union wpa_event_data *data)
  1136. {
  1137. int l, len, found = 0, wpa_found, rsn_found;
  1138. const u8 *p;
  1139. wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
  1140. if (data->assoc_info.req_ies)
  1141. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  1142. data->assoc_info.req_ies_len);
  1143. if (data->assoc_info.resp_ies) {
  1144. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  1145. data->assoc_info.resp_ies_len);
  1146. #ifdef CONFIG_TDLS
  1147. wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
  1148. data->assoc_info.resp_ies_len);
  1149. #endif /* CONFIG_TDLS */
  1150. #ifdef CONFIG_WNM
  1151. wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
  1152. data->assoc_info.resp_ies_len);
  1153. #endif /* CONFIG_WNM */
  1154. }
  1155. if (data->assoc_info.beacon_ies)
  1156. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  1157. data->assoc_info.beacon_ies,
  1158. data->assoc_info.beacon_ies_len);
  1159. if (data->assoc_info.freq)
  1160. wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
  1161. data->assoc_info.freq);
  1162. p = data->assoc_info.req_ies;
  1163. l = data->assoc_info.req_ies_len;
  1164. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  1165. while (p && l >= 2) {
  1166. len = p[1] + 2;
  1167. if (len > l) {
  1168. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1169. p, l);
  1170. break;
  1171. }
  1172. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1173. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  1174. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  1175. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  1176. break;
  1177. found = 1;
  1178. wpa_find_assoc_pmkid(wpa_s);
  1179. break;
  1180. }
  1181. l -= len;
  1182. p += len;
  1183. }
  1184. if (!found && data->assoc_info.req_ies)
  1185. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  1186. #ifdef CONFIG_IEEE80211R
  1187. #ifdef CONFIG_SME
  1188. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  1189. u8 bssid[ETH_ALEN];
  1190. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  1191. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  1192. data->assoc_info.resp_ies,
  1193. data->assoc_info.resp_ies_len,
  1194. bssid) < 0) {
  1195. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  1196. "Reassociation Response failed");
  1197. wpa_supplicant_deauthenticate(
  1198. wpa_s, WLAN_REASON_INVALID_IE);
  1199. return -1;
  1200. }
  1201. }
  1202. p = data->assoc_info.resp_ies;
  1203. l = data->assoc_info.resp_ies_len;
  1204. #ifdef CONFIG_WPS_STRICT
  1205. if (p && wpa_s->current_ssid &&
  1206. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  1207. struct wpabuf *wps;
  1208. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  1209. if (wps == NULL) {
  1210. wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
  1211. "include WPS IE in (Re)Association Response");
  1212. return -1;
  1213. }
  1214. if (wps_validate_assoc_resp(wps) < 0) {
  1215. wpabuf_free(wps);
  1216. wpa_supplicant_deauthenticate(
  1217. wpa_s, WLAN_REASON_INVALID_IE);
  1218. return -1;
  1219. }
  1220. wpabuf_free(wps);
  1221. }
  1222. #endif /* CONFIG_WPS_STRICT */
  1223. /* Go through the IEs and make a copy of the MDIE, if present. */
  1224. while (p && l >= 2) {
  1225. len = p[1] + 2;
  1226. if (len > l) {
  1227. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1228. p, l);
  1229. break;
  1230. }
  1231. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  1232. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  1233. wpa_s->sme.ft_used = 1;
  1234. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  1235. MOBILITY_DOMAIN_ID_LEN);
  1236. break;
  1237. }
  1238. l -= len;
  1239. p += len;
  1240. }
  1241. #endif /* CONFIG_SME */
  1242. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  1243. data->assoc_info.resp_ies_len);
  1244. #endif /* CONFIG_IEEE80211R */
  1245. /* WPA/RSN IE from Beacon/ProbeResp */
  1246. p = data->assoc_info.beacon_ies;
  1247. l = data->assoc_info.beacon_ies_len;
  1248. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  1249. */
  1250. wpa_found = rsn_found = 0;
  1251. while (p && l >= 2) {
  1252. len = p[1] + 2;
  1253. if (len > l) {
  1254. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  1255. p, l);
  1256. break;
  1257. }
  1258. if (!wpa_found &&
  1259. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1260. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  1261. wpa_found = 1;
  1262. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  1263. }
  1264. if (!rsn_found &&
  1265. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  1266. rsn_found = 1;
  1267. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  1268. }
  1269. l -= len;
  1270. p += len;
  1271. }
  1272. if (!wpa_found && data->assoc_info.beacon_ies)
  1273. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  1274. if (!rsn_found && data->assoc_info.beacon_ies)
  1275. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  1276. if (wpa_found || rsn_found)
  1277. wpa_s->ap_ies_from_associnfo = 1;
  1278. if (wpa_s->assoc_freq && data->assoc_info.freq &&
  1279. wpa_s->assoc_freq != data->assoc_info.freq) {
  1280. wpa_printf(MSG_DEBUG, "Operating frequency changed from "
  1281. "%u to %u MHz",
  1282. wpa_s->assoc_freq, data->assoc_info.freq);
  1283. wpa_supplicant_update_scan_results(wpa_s);
  1284. }
  1285. wpa_s->assoc_freq = data->assoc_info.freq;
  1286. return 0;
  1287. }
  1288. static struct wpa_bss * wpa_supplicant_get_new_bss(
  1289. struct wpa_supplicant *wpa_s, const u8 *bssid)
  1290. {
  1291. struct wpa_bss *bss = NULL;
  1292. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1293. if (ssid->ssid_len > 0)
  1294. bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
  1295. if (!bss)
  1296. bss = wpa_bss_get_bssid(wpa_s, bssid);
  1297. return bss;
  1298. }
  1299. static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
  1300. {
  1301. const u8 *bss_wpa = NULL, *bss_rsn = NULL;
  1302. if (!wpa_s->current_bss || !wpa_s->current_ssid)
  1303. return -1;
  1304. if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
  1305. return 0;
  1306. bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
  1307. WPA_IE_VENDOR_TYPE);
  1308. bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
  1309. if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
  1310. bss_wpa ? 2 + bss_wpa[1] : 0) ||
  1311. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
  1312. bss_rsn ? 2 + bss_rsn[1] : 0))
  1313. return -1;
  1314. return 0;
  1315. }
  1316. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  1317. union wpa_event_data *data)
  1318. {
  1319. u8 bssid[ETH_ALEN];
  1320. int ft_completed;
  1321. struct wpa_driver_capa capa;
  1322. #ifdef CONFIG_AP
  1323. if (wpa_s->ap_iface) {
  1324. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  1325. data->assoc_info.addr,
  1326. data->assoc_info.req_ies,
  1327. data->assoc_info.req_ies_len,
  1328. data->assoc_info.reassoc);
  1329. return;
  1330. }
  1331. #endif /* CONFIG_AP */
  1332. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  1333. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  1334. return;
  1335. if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
  1336. wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
  1337. wpa_supplicant_disassociate(
  1338. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1339. return;
  1340. }
  1341. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  1342. if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
  1343. wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  1344. MACSTR, MAC2STR(bssid));
  1345. random_add_randomness(bssid, ETH_ALEN);
  1346. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  1347. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1348. wpas_notify_bssid_changed(wpa_s);
  1349. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  1350. wpa_clear_keys(wpa_s, bssid);
  1351. }
  1352. if (wpa_supplicant_select_config(wpa_s) < 0) {
  1353. wpa_supplicant_disassociate(
  1354. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1355. return;
  1356. }
  1357. if (wpa_s->current_ssid) {
  1358. struct wpa_bss *bss = NULL;
  1359. bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
  1360. if (!bss) {
  1361. wpa_supplicant_update_scan_results(wpa_s);
  1362. /* Get the BSS from the new scan results */
  1363. bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
  1364. }
  1365. if (bss)
  1366. wpa_s->current_bss = bss;
  1367. }
  1368. if (wpa_s->conf->ap_scan == 1 &&
  1369. wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
  1370. if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
  1371. wpa_msg(wpa_s, MSG_WARNING,
  1372. "WPA/RSN IEs not updated");
  1373. }
  1374. }
  1375. #ifdef CONFIG_SME
  1376. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  1377. wpa_s->sme.prev_bssid_set = 1;
  1378. #endif /* CONFIG_SME */
  1379. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  1380. if (wpa_s->current_ssid) {
  1381. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  1382. * initialized before association, but for other modes,
  1383. * initialize PC/SC here, if the current configuration needs
  1384. * smartcard or SIM/USIM. */
  1385. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  1386. }
  1387. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  1388. if (wpa_s->l2)
  1389. l2_packet_notify_auth_start(wpa_s->l2);
  1390. /*
  1391. * Set portEnabled first to FALSE in order to get EAP state machine out
  1392. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  1393. * state machine may transit to AUTHENTICATING state based on obsolete
  1394. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  1395. * AUTHENTICATED without ever giving chance to EAP state machine to
  1396. * reset the state.
  1397. */
  1398. if (!ft_completed) {
  1399. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  1400. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  1401. }
  1402. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  1403. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  1404. /* 802.1X::portControl = Auto */
  1405. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  1406. wpa_s->eapol_received = 0;
  1407. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1408. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  1409. (wpa_s->current_ssid &&
  1410. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  1411. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1412. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1413. } else if (!ft_completed) {
  1414. /* Timeout for receiving the first EAPOL packet */
  1415. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  1416. }
  1417. wpa_supplicant_cancel_scan(wpa_s);
  1418. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1419. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1420. /*
  1421. * We are done; the driver will take care of RSN 4-way
  1422. * handshake.
  1423. */
  1424. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1425. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1426. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1427. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1428. } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1429. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1430. /*
  1431. * The driver will take care of RSN 4-way handshake, so we need
  1432. * to allow EAPOL supplicant to complete its work without
  1433. * waiting for WPA supplicant.
  1434. */
  1435. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1436. } else if (ft_completed) {
  1437. /*
  1438. * FT protocol completed - make sure EAPOL state machine ends
  1439. * up in authenticated.
  1440. */
  1441. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1442. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1443. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1444. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1445. }
  1446. if (wpa_s->pending_eapol_rx) {
  1447. struct os_time now, age;
  1448. os_get_time(&now);
  1449. os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  1450. if (age.sec == 0 && age.usec < 100000 &&
  1451. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  1452. 0) {
  1453. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
  1454. "frame that was received just before "
  1455. "association notification");
  1456. wpa_supplicant_rx_eapol(
  1457. wpa_s, wpa_s->pending_eapol_rx_src,
  1458. wpabuf_head(wpa_s->pending_eapol_rx),
  1459. wpabuf_len(wpa_s->pending_eapol_rx));
  1460. }
  1461. wpabuf_free(wpa_s->pending_eapol_rx);
  1462. wpa_s->pending_eapol_rx = NULL;
  1463. }
  1464. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1465. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1466. wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
  1467. capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
  1468. /* Set static WEP keys again */
  1469. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1470. }
  1471. #ifdef CONFIG_IBSS_RSN
  1472. if (wpa_s->current_ssid &&
  1473. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  1474. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  1475. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
  1476. wpa_s->ibss_rsn == NULL) {
  1477. wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
  1478. if (!wpa_s->ibss_rsn) {
  1479. wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
  1480. wpa_supplicant_deauthenticate(
  1481. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1482. return;
  1483. }
  1484. ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
  1485. }
  1486. #endif /* CONFIG_IBSS_RSN */
  1487. wpas_wps_notify_assoc(wpa_s, bssid);
  1488. }
  1489. static int disconnect_reason_recoverable(u16 reason_code)
  1490. {
  1491. return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
  1492. reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
  1493. reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
  1494. }
  1495. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1496. u16 reason_code,
  1497. int locally_generated)
  1498. {
  1499. const u8 *bssid;
  1500. int authenticating;
  1501. u8 prev_pending_bssid[ETH_ALEN];
  1502. struct wpa_bss *fast_reconnect = NULL;
  1503. struct wpa_ssid *fast_reconnect_ssid = NULL;
  1504. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1505. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1506. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1507. /*
  1508. * At least Host AP driver and a Prism3 card seemed to be
  1509. * generating streams of disconnected events when configuring
  1510. * IBSS for WPA-None. Ignore them for now.
  1511. */
  1512. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
  1513. "IBSS/WPA-None mode");
  1514. return;
  1515. }
  1516. if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
  1517. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1518. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1519. "pre-shared key may be incorrect");
  1520. wpas_auth_failed(wpa_s);
  1521. }
  1522. if (!wpa_s->auto_reconnect_disabled ||
  1523. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
  1524. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
  1525. "reconnect (wps=%d wpa_state=%d)",
  1526. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
  1527. wpa_s->wpa_state);
  1528. if (wpa_s->wpa_state == WPA_COMPLETED &&
  1529. wpa_s->current_ssid &&
  1530. wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
  1531. !locally_generated &&
  1532. disconnect_reason_recoverable(reason_code)) {
  1533. /*
  1534. * It looks like the AP has dropped association with
  1535. * us, but could allow us to get back in. Try to
  1536. * reconnect to the same BSS without full scan to save
  1537. * time for some common cases.
  1538. */
  1539. fast_reconnect = wpa_s->current_bss;
  1540. fast_reconnect_ssid = wpa_s->current_ssid;
  1541. } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  1542. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1543. else
  1544. wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
  1545. "immediate scan");
  1546. } else {
  1547. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
  1548. "try to re-connect");
  1549. wpa_s->reassociate = 0;
  1550. wpa_s->disconnected = 1;
  1551. wpa_supplicant_cancel_sched_scan(wpa_s);
  1552. }
  1553. bssid = wpa_s->bssid;
  1554. if (is_zero_ether_addr(bssid))
  1555. bssid = wpa_s->pending_bssid;
  1556. if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
  1557. wpas_connection_failed(wpa_s, bssid);
  1558. wpa_sm_notify_disassoc(wpa_s->wpa);
  1559. if (locally_generated)
  1560. wpa_s->disconnect_reason = -reason_code;
  1561. else
  1562. wpa_s->disconnect_reason = reason_code;
  1563. wpas_notify_disconnect_reason(wpa_s);
  1564. if (!is_zero_ether_addr(bssid) ||
  1565. wpa_s->wpa_state >= WPA_AUTHENTICATING) {
  1566. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1567. " reason=%d%s",
  1568. MAC2STR(bssid), reason_code,
  1569. locally_generated ? " locally_generated=1" : "");
  1570. }
  1571. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  1572. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
  1573. wpa_s->keys_cleared = 0;
  1574. wpa_clear_keys(wpa_s, wpa_s->bssid);
  1575. }
  1576. wpa_supplicant_mark_disassoc(wpa_s);
  1577. if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1578. sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
  1579. if (fast_reconnect) {
  1580. #ifndef CONFIG_NO_SCAN_PROCESSING
  1581. wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
  1582. if (wpa_supplicant_connect(wpa_s, fast_reconnect,
  1583. fast_reconnect_ssid) < 0) {
  1584. /* Recover through full scan */
  1585. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1586. }
  1587. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1588. }
  1589. }
  1590. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1591. void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
  1592. {
  1593. struct wpa_supplicant *wpa_s = eloop_ctx;
  1594. if (!wpa_s->pending_mic_error_report)
  1595. return;
  1596. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
  1597. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  1598. wpa_s->pending_mic_error_report = 0;
  1599. }
  1600. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1601. static void
  1602. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  1603. union wpa_event_data *data)
  1604. {
  1605. int pairwise;
  1606. struct os_time t;
  1607. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  1608. pairwise = (data && data->michael_mic_failure.unicast);
  1609. os_get_time(&t);
  1610. if ((wpa_s->last_michael_mic_error &&
  1611. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  1612. wpa_s->pending_mic_error_report) {
  1613. if (wpa_s->pending_mic_error_report) {
  1614. /*
  1615. * Send the pending MIC error report immediately since
  1616. * we are going to start countermeasures and AP better
  1617. * do the same.
  1618. */
  1619. wpa_sm_key_request(wpa_s->wpa, 1,
  1620. wpa_s->pending_mic_error_pairwise);
  1621. }
  1622. /* Send the new MIC error report immediately since we are going
  1623. * to start countermeasures and AP better do the same.
  1624. */
  1625. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1626. /* initialize countermeasures */
  1627. wpa_s->countermeasures = 1;
  1628. wpa_blacklist_add(wpa_s, wpa_s->bssid);
  1629. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  1630. /*
  1631. * Need to wait for completion of request frame. We do not get
  1632. * any callback for the message completion, so just wait a
  1633. * short while and hope for the best. */
  1634. os_sleep(0, 10000);
  1635. wpa_drv_set_countermeasures(wpa_s, 1);
  1636. wpa_supplicant_deauthenticate(wpa_s,
  1637. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1638. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  1639. wpa_s, NULL);
  1640. eloop_register_timeout(60, 0,
  1641. wpa_supplicant_stop_countermeasures,
  1642. wpa_s, NULL);
  1643. /* TODO: mark the AP rejected for 60 second. STA is
  1644. * allowed to associate with another AP.. */
  1645. } else {
  1646. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1647. if (wpa_s->mic_errors_seen) {
  1648. /*
  1649. * Reduce the effectiveness of Michael MIC error
  1650. * reports as a means for attacking against TKIP if
  1651. * more than one MIC failure is noticed with the same
  1652. * PTK. We delay the transmission of the reports by a
  1653. * random time between 0 and 60 seconds in order to
  1654. * force the attacker wait 60 seconds before getting
  1655. * the information on whether a frame resulted in a MIC
  1656. * failure.
  1657. */
  1658. u8 rval[4];
  1659. int sec;
  1660. if (os_get_random(rval, sizeof(rval)) < 0)
  1661. sec = os_random() % 60;
  1662. else
  1663. sec = WPA_GET_BE32(rval) % 60;
  1664. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
  1665. "report %d seconds", sec);
  1666. wpa_s->pending_mic_error_report = 1;
  1667. wpa_s->pending_mic_error_pairwise = pairwise;
  1668. eloop_cancel_timeout(
  1669. wpa_supplicant_delayed_mic_error_report,
  1670. wpa_s, NULL);
  1671. eloop_register_timeout(
  1672. sec, os_random() % 1000000,
  1673. wpa_supplicant_delayed_mic_error_report,
  1674. wpa_s, NULL);
  1675. } else {
  1676. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1677. }
  1678. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1679. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1680. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1681. }
  1682. wpa_s->last_michael_mic_error = t.sec;
  1683. wpa_s->mic_errors_seen++;
  1684. }
  1685. #ifdef CONFIG_TERMINATE_ONLASTIF
  1686. static int any_interfaces(struct wpa_supplicant *head)
  1687. {
  1688. struct wpa_supplicant *wpa_s;
  1689. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  1690. if (!wpa_s->interface_removed)
  1691. return 1;
  1692. return 0;
  1693. }
  1694. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1695. static void
  1696. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  1697. union wpa_event_data *data)
  1698. {
  1699. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  1700. return;
  1701. switch (data->interface_status.ievent) {
  1702. case EVENT_INTERFACE_ADDED:
  1703. if (!wpa_s->interface_removed)
  1704. break;
  1705. wpa_s->interface_removed = 0;
  1706. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
  1707. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  1708. wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
  1709. "driver after interface was added");
  1710. }
  1711. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1712. break;
  1713. case EVENT_INTERFACE_REMOVED:
  1714. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
  1715. wpa_s->interface_removed = 1;
  1716. wpa_supplicant_mark_disassoc(wpa_s);
  1717. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  1718. l2_packet_deinit(wpa_s->l2);
  1719. wpa_s->l2 = NULL;
  1720. #ifdef CONFIG_IBSS_RSN
  1721. ibss_rsn_deinit(wpa_s->ibss_rsn);
  1722. wpa_s->ibss_rsn = NULL;
  1723. #endif /* CONFIG_IBSS_RSN */
  1724. #ifdef CONFIG_TERMINATE_ONLASTIF
  1725. /* check if last interface */
  1726. if (!any_interfaces(wpa_s->global->ifaces))
  1727. eloop_terminate();
  1728. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1729. break;
  1730. }
  1731. }
  1732. #ifdef CONFIG_PEERKEY
  1733. static void
  1734. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  1735. union wpa_event_data *data)
  1736. {
  1737. if (data == NULL)
  1738. return;
  1739. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  1740. }
  1741. #endif /* CONFIG_PEERKEY */
  1742. #ifdef CONFIG_TDLS
  1743. static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
  1744. union wpa_event_data *data)
  1745. {
  1746. if (data == NULL)
  1747. return;
  1748. switch (data->tdls.oper) {
  1749. case TDLS_REQUEST_SETUP:
  1750. wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
  1751. break;
  1752. case TDLS_REQUEST_TEARDOWN:
  1753. wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
  1754. data->tdls.reason_code);
  1755. break;
  1756. }
  1757. }
  1758. #endif /* CONFIG_TDLS */
  1759. #ifdef CONFIG_IEEE80211V
  1760. static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
  1761. union wpa_event_data *data)
  1762. {
  1763. if (data == NULL)
  1764. return;
  1765. switch (data->wnm.oper) {
  1766. case WNM_OPER_SLEEP:
  1767. wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
  1768. "(action=%d, intval=%d)",
  1769. data->wnm.sleep_action, data->wnm.sleep_intval);
  1770. ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
  1771. data->wnm.sleep_intval);
  1772. break;
  1773. }
  1774. }
  1775. #endif /* CONFIG_IEEE80211V */
  1776. #ifdef CONFIG_IEEE80211R
  1777. static void
  1778. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  1779. union wpa_event_data *data)
  1780. {
  1781. if (data == NULL)
  1782. return;
  1783. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  1784. data->ft_ies.ies_len,
  1785. data->ft_ies.ft_action,
  1786. data->ft_ies.target_ap,
  1787. data->ft_ies.ric_ies,
  1788. data->ft_ies.ric_ies_len) < 0) {
  1789. /* TODO: prevent MLME/driver from trying to associate? */
  1790. }
  1791. }
  1792. #endif /* CONFIG_IEEE80211R */
  1793. #ifdef CONFIG_IBSS_RSN
  1794. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  1795. union wpa_event_data *data)
  1796. {
  1797. struct wpa_ssid *ssid;
  1798. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1799. return;
  1800. if (data == NULL)
  1801. return;
  1802. ssid = wpa_s->current_ssid;
  1803. if (ssid == NULL)
  1804. return;
  1805. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  1806. return;
  1807. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  1808. }
  1809. #endif /* CONFIG_IBSS_RSN */
  1810. #ifdef CONFIG_IEEE80211R
  1811. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  1812. size_t len)
  1813. {
  1814. const u8 *sta_addr, *target_ap_addr;
  1815. u16 status;
  1816. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  1817. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1818. return; /* only SME case supported for now */
  1819. if (len < 1 + 2 * ETH_ALEN + 2)
  1820. return;
  1821. if (data[0] != 2)
  1822. return; /* Only FT Action Response is supported for now */
  1823. sta_addr = data + 1;
  1824. target_ap_addr = data + 1 + ETH_ALEN;
  1825. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  1826. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
  1827. MACSTR " TargetAP " MACSTR " status %u",
  1828. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  1829. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  1830. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  1831. " in FT Action Response", MAC2STR(sta_addr));
  1832. return;
  1833. }
  1834. if (status) {
  1835. wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
  1836. "failure (status code %d)", status);
  1837. /* TODO: report error to FT code(?) */
  1838. return;
  1839. }
  1840. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  1841. len - (1 + 2 * ETH_ALEN + 2), 1,
  1842. target_ap_addr, NULL, 0) < 0)
  1843. return;
  1844. #ifdef CONFIG_SME
  1845. {
  1846. struct wpa_bss *bss;
  1847. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  1848. if (bss)
  1849. wpa_s->sme.freq = bss->freq;
  1850. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  1851. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  1852. WLAN_AUTH_FT);
  1853. }
  1854. #endif /* CONFIG_SME */
  1855. }
  1856. #endif /* CONFIG_IEEE80211R */
  1857. static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
  1858. struct unprot_deauth *e)
  1859. {
  1860. #ifdef CONFIG_IEEE80211W
  1861. wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
  1862. "dropped: " MACSTR " -> " MACSTR
  1863. " (reason code %u)",
  1864. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1865. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1866. #endif /* CONFIG_IEEE80211W */
  1867. }
  1868. static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
  1869. struct unprot_disassoc *e)
  1870. {
  1871. #ifdef CONFIG_IEEE80211W
  1872. wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
  1873. "dropped: " MACSTR " -> " MACSTR
  1874. " (reason code %u)",
  1875. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1876. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1877. #endif /* CONFIG_IEEE80211W */
  1878. }
  1879. static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
  1880. {
  1881. u8 action, mode;
  1882. const u8 *pos, *end;
  1883. if (rx->data == NULL || rx->len == 0)
  1884. return;
  1885. pos = rx->data;
  1886. end = pos + rx->len;
  1887. action = *pos++;
  1888. wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
  1889. action, MAC2STR(rx->sa));
  1890. switch (action) {
  1891. case WNM_BSS_TRANS_MGMT_REQ:
  1892. if (pos + 5 > end)
  1893. break;
  1894. wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
  1895. "Request: dialog_token=%u request_mode=0x%x "
  1896. "disassoc_timer=%u validity_interval=%u",
  1897. pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
  1898. mode = pos[1];
  1899. pos += 5;
  1900. if (mode & 0x08)
  1901. pos += 12; /* BSS Termination Duration */
  1902. if (mode & 0x10) {
  1903. char url[256];
  1904. if (pos + 1 > end || pos + 1 + pos[0] > end) {
  1905. wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
  1906. "Transition Management Request "
  1907. "(URL)");
  1908. break;
  1909. }
  1910. os_memcpy(url, pos + 1, pos[0]);
  1911. url[pos[0]] = '\0';
  1912. wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
  1913. "Imminent - session_info_url=%s", url);
  1914. }
  1915. break;
  1916. }
  1917. }
  1918. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  1919. union wpa_event_data *data)
  1920. {
  1921. struct wpa_supplicant *wpa_s = ctx;
  1922. u16 reason_code = 0;
  1923. int locally_generated = 0;
  1924. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  1925. event != EVENT_INTERFACE_ENABLED &&
  1926. event != EVENT_INTERFACE_STATUS &&
  1927. event != EVENT_SCHED_SCAN_STOPPED) {
  1928. wpa_dbg(wpa_s, MSG_DEBUG,
  1929. "Ignore event %s (%d) while interface is disabled",
  1930. event_to_string(event), event);
  1931. return;
  1932. }
  1933. #ifndef CONFIG_NO_STDOUT_DEBUG
  1934. {
  1935. int level = MSG_DEBUG;
  1936. if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
  1937. const struct ieee80211_hdr *hdr;
  1938. u16 fc;
  1939. hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
  1940. fc = le_to_host16(hdr->frame_control);
  1941. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  1942. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
  1943. level = MSG_EXCESSIVE;
  1944. }
  1945. wpa_dbg(wpa_s, level, "Event %s (%d) received",
  1946. event_to_string(event), event);
  1947. }
  1948. #endif /* CONFIG_NO_STDOUT_DEBUG */
  1949. switch (event) {
  1950. case EVENT_AUTH:
  1951. sme_event_auth(wpa_s, data);
  1952. break;
  1953. case EVENT_ASSOC:
  1954. wpa_supplicant_event_assoc(wpa_s, data);
  1955. break;
  1956. case EVENT_DISASSOC:
  1957. wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
  1958. if (data) {
  1959. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
  1960. data->disassoc_info.reason_code,
  1961. data->disassoc_info.locally_generated ?
  1962. " (locally generated)" : "");
  1963. if (data->disassoc_info.addr)
  1964. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  1965. MAC2STR(data->disassoc_info.addr));
  1966. }
  1967. #ifdef CONFIG_AP
  1968. if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
  1969. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1970. data->disassoc_info.addr);
  1971. break;
  1972. }
  1973. if (wpa_s->ap_iface) {
  1974. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
  1975. "AP mode");
  1976. break;
  1977. }
  1978. #endif /* CONFIG_AP */
  1979. if (data) {
  1980. reason_code = data->disassoc_info.reason_code;
  1981. locally_generated =
  1982. data->disassoc_info.locally_generated;
  1983. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  1984. data->disassoc_info.ie,
  1985. data->disassoc_info.ie_len);
  1986. #ifdef CONFIG_P2P
  1987. wpas_p2p_disassoc_notif(
  1988. wpa_s, data->disassoc_info.addr, reason_code,
  1989. data->disassoc_info.ie,
  1990. data->disassoc_info.ie_len,
  1991. locally_generated);
  1992. #endif /* CONFIG_P2P */
  1993. }
  1994. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1995. sme_event_disassoc(wpa_s, data);
  1996. /* fall through */
  1997. case EVENT_DEAUTH:
  1998. if (event == EVENT_DEAUTH) {
  1999. wpa_dbg(wpa_s, MSG_DEBUG,
  2000. "Deauthentication notification");
  2001. if (data) {
  2002. reason_code = data->deauth_info.reason_code;
  2003. locally_generated =
  2004. data->deauth_info.locally_generated;
  2005. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
  2006. data->deauth_info.reason_code,
  2007. data->deauth_info.locally_generated ?
  2008. " (locally generated)" : "");
  2009. if (data->deauth_info.addr) {
  2010. wpa_dbg(wpa_s, MSG_DEBUG, " * address "
  2011. MACSTR,
  2012. MAC2STR(data->deauth_info.
  2013. addr));
  2014. }
  2015. wpa_hexdump(MSG_DEBUG,
  2016. "Deauthentication frame IE(s)",
  2017. data->deauth_info.ie,
  2018. data->deauth_info.ie_len);
  2019. }
  2020. }
  2021. #ifdef CONFIG_AP
  2022. if (wpa_s->ap_iface && data && data->deauth_info.addr) {
  2023. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  2024. data->deauth_info.addr);
  2025. break;
  2026. }
  2027. if (wpa_s->ap_iface) {
  2028. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
  2029. "AP mode");
  2030. break;
  2031. }
  2032. #endif /* CONFIG_AP */
  2033. wpa_supplicant_event_disassoc(wpa_s, reason_code,
  2034. locally_generated);
  2035. if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
  2036. ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  2037. (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
  2038. eapol_sm_failed(wpa_s->eapol)))
  2039. wpas_auth_failed(wpa_s);
  2040. #ifdef CONFIG_P2P
  2041. if (event == EVENT_DEAUTH && data) {
  2042. wpas_p2p_deauth_notif(wpa_s, data->deauth_info.addr,
  2043. reason_code,
  2044. data->deauth_info.ie,
  2045. data->deauth_info.ie_len,
  2046. locally_generated);
  2047. }
  2048. #endif /* CONFIG_P2P */
  2049. break;
  2050. case EVENT_MICHAEL_MIC_FAILURE:
  2051. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  2052. break;
  2053. #ifndef CONFIG_NO_SCAN_PROCESSING
  2054. case EVENT_SCAN_RESULTS:
  2055. wpa_supplicant_event_scan_results(wpa_s, data);
  2056. #ifdef CONFIG_P2P
  2057. if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
  2058. wpa_s->global->p2p != NULL &&
  2059. wpa_s->wpa_state != WPA_AUTHENTICATING &&
  2060. wpa_s->wpa_state != WPA_ASSOCIATING) {
  2061. wpa_s->p2p_cb_on_scan_complete = 0;
  2062. if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
  2063. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
  2064. "continued after scan result processing");
  2065. }
  2066. }
  2067. #endif /* CONFIG_P2P */
  2068. break;
  2069. #endif /* CONFIG_NO_SCAN_PROCESSING */
  2070. case EVENT_ASSOCINFO:
  2071. wpa_supplicant_event_associnfo(wpa_s, data);
  2072. break;
  2073. case EVENT_INTERFACE_STATUS:
  2074. wpa_supplicant_event_interface_status(wpa_s, data);
  2075. break;
  2076. case EVENT_PMKID_CANDIDATE:
  2077. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  2078. break;
  2079. #ifdef CONFIG_PEERKEY
  2080. case EVENT_STKSTART:
  2081. wpa_supplicant_event_stkstart(wpa_s, data);
  2082. break;
  2083. #endif /* CONFIG_PEERKEY */
  2084. #ifdef CONFIG_TDLS
  2085. case EVENT_TDLS:
  2086. wpa_supplicant_event_tdls(wpa_s, data);
  2087. break;
  2088. #endif /* CONFIG_TDLS */
  2089. #ifdef CONFIG_IEEE80211V
  2090. case EVENT_WNM:
  2091. wpa_supplicant_event_wnm(wpa_s, data);
  2092. break;
  2093. #endif /* CONFIG_IEEE80211V */
  2094. #ifdef CONFIG_IEEE80211R
  2095. case EVENT_FT_RESPONSE:
  2096. wpa_supplicant_event_ft_response(wpa_s, data);
  2097. break;
  2098. #endif /* CONFIG_IEEE80211R */
  2099. #ifdef CONFIG_IBSS_RSN
  2100. case EVENT_IBSS_RSN_START:
  2101. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  2102. break;
  2103. #endif /* CONFIG_IBSS_RSN */
  2104. case EVENT_ASSOC_REJECT:
  2105. if (data->assoc_reject.bssid)
  2106. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  2107. "bssid=" MACSTR " status_code=%u",
  2108. MAC2STR(data->assoc_reject.bssid),
  2109. data->assoc_reject.status_code);
  2110. else
  2111. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  2112. "status_code=%u",
  2113. data->assoc_reject.status_code);
  2114. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2115. sme_event_assoc_reject(wpa_s, data);
  2116. break;
  2117. case EVENT_AUTH_TIMED_OUT:
  2118. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2119. sme_event_auth_timed_out(wpa_s, data);
  2120. break;
  2121. case EVENT_ASSOC_TIMED_OUT:
  2122. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2123. sme_event_assoc_timed_out(wpa_s, data);
  2124. break;
  2125. case EVENT_TX_STATUS:
  2126. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
  2127. " type=%d stype=%d",
  2128. MAC2STR(data->tx_status.dst),
  2129. data->tx_status.type, data->tx_status.stype);
  2130. #ifdef CONFIG_AP
  2131. if (wpa_s->ap_iface == NULL) {
  2132. #ifdef CONFIG_OFFCHANNEL
  2133. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  2134. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  2135. offchannel_send_action_tx_status(
  2136. wpa_s, data->tx_status.dst,
  2137. data->tx_status.data,
  2138. data->tx_status.data_len,
  2139. data->tx_status.ack ?
  2140. OFFCHANNEL_SEND_ACTION_SUCCESS :
  2141. OFFCHANNEL_SEND_ACTION_NO_ACK);
  2142. #endif /* CONFIG_OFFCHANNEL */
  2143. break;
  2144. }
  2145. #endif /* CONFIG_AP */
  2146. #ifdef CONFIG_OFFCHANNEL
  2147. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
  2148. MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
  2149. /*
  2150. * Catch TX status events for Action frames we sent via group
  2151. * interface in GO mode.
  2152. */
  2153. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  2154. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  2155. os_memcmp(wpa_s->parent->pending_action_dst,
  2156. data->tx_status.dst, ETH_ALEN) == 0) {
  2157. offchannel_send_action_tx_status(
  2158. wpa_s->parent, data->tx_status.dst,
  2159. data->tx_status.data,
  2160. data->tx_status.data_len,
  2161. data->tx_status.ack ?
  2162. OFFCHANNEL_SEND_ACTION_SUCCESS :
  2163. OFFCHANNEL_SEND_ACTION_NO_ACK);
  2164. break;
  2165. }
  2166. #endif /* CONFIG_OFFCHANNEL */
  2167. #ifdef CONFIG_AP
  2168. switch (data->tx_status.type) {
  2169. case WLAN_FC_TYPE_MGMT:
  2170. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  2171. data->tx_status.data_len,
  2172. data->tx_status.stype,
  2173. data->tx_status.ack);
  2174. break;
  2175. case WLAN_FC_TYPE_DATA:
  2176. ap_tx_status(wpa_s, data->tx_status.dst,
  2177. data->tx_status.data,
  2178. data->tx_status.data_len,
  2179. data->tx_status.ack);
  2180. break;
  2181. }
  2182. #endif /* CONFIG_AP */
  2183. break;
  2184. #ifdef CONFIG_AP
  2185. case EVENT_EAPOL_TX_STATUS:
  2186. ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
  2187. data->eapol_tx_status.data,
  2188. data->eapol_tx_status.data_len,
  2189. data->eapol_tx_status.ack);
  2190. break;
  2191. case EVENT_DRIVER_CLIENT_POLL_OK:
  2192. ap_client_poll_ok(wpa_s, data->client_poll.addr);
  2193. break;
  2194. case EVENT_RX_FROM_UNKNOWN:
  2195. if (wpa_s->ap_iface == NULL)
  2196. break;
  2197. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
  2198. data->rx_from_unknown.wds);
  2199. break;
  2200. case EVENT_CH_SWITCH:
  2201. if (!data)
  2202. break;
  2203. if (!wpa_s->ap_iface) {
  2204. wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
  2205. "event in non-AP mode");
  2206. break;
  2207. }
  2208. #ifdef CONFIG_AP
  2209. wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
  2210. data->ch_switch.ht_enabled,
  2211. data->ch_switch.ch_offset);
  2212. #endif /* CONFIG_AP */
  2213. break;
  2214. case EVENT_RX_MGMT: {
  2215. u16 fc, stype;
  2216. const struct ieee80211_mgmt *mgmt;
  2217. mgmt = (const struct ieee80211_mgmt *)
  2218. data->rx_mgmt.frame;
  2219. fc = le_to_host16(mgmt->frame_control);
  2220. stype = WLAN_FC_GET_STYPE(fc);
  2221. if (wpa_s->ap_iface == NULL) {
  2222. #ifdef CONFIG_P2P
  2223. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  2224. data->rx_mgmt.frame_len > 24) {
  2225. const u8 *src = mgmt->sa;
  2226. const u8 *ie = mgmt->u.probe_req.variable;
  2227. size_t ie_len = data->rx_mgmt.frame_len -
  2228. (mgmt->u.probe_req.variable -
  2229. data->rx_mgmt.frame);
  2230. wpas_p2p_probe_req_rx(
  2231. wpa_s, src, mgmt->da,
  2232. mgmt->bssid, ie, ie_len,
  2233. data->rx_mgmt.ssi_signal);
  2234. break;
  2235. }
  2236. #endif /* CONFIG_P2P */
  2237. wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
  2238. "management frame in non-AP mode");
  2239. break;
  2240. }
  2241. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  2242. data->rx_mgmt.frame_len > 24) {
  2243. const u8 *ie = mgmt->u.probe_req.variable;
  2244. size_t ie_len = data->rx_mgmt.frame_len -
  2245. (mgmt->u.probe_req.variable -
  2246. data->rx_mgmt.frame);
  2247. wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
  2248. mgmt->bssid, ie, ie_len,
  2249. data->rx_mgmt.ssi_signal);
  2250. }
  2251. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  2252. break;
  2253. }
  2254. #endif /* CONFIG_AP */
  2255. case EVENT_RX_ACTION:
  2256. wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
  2257. " Category=%u DataLen=%d freq=%d MHz",
  2258. MAC2STR(data->rx_action.sa),
  2259. data->rx_action.category, (int) data->rx_action.len,
  2260. data->rx_action.freq);
  2261. #ifdef CONFIG_IEEE80211R
  2262. if (data->rx_action.category == WLAN_ACTION_FT) {
  2263. ft_rx_action(wpa_s, data->rx_action.data,
  2264. data->rx_action.len);
  2265. break;
  2266. }
  2267. #endif /* CONFIG_IEEE80211R */
  2268. #ifdef CONFIG_IEEE80211W
  2269. #ifdef CONFIG_SME
  2270. if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
  2271. sme_sa_query_rx(wpa_s, data->rx_action.sa,
  2272. data->rx_action.data,
  2273. data->rx_action.len);
  2274. break;
  2275. }
  2276. #endif /* CONFIG_SME */
  2277. #endif /* CONFIG_IEEE80211W */
  2278. #ifdef CONFIG_IEEE80211V
  2279. if (data->rx_action.category == WLAN_ACTION_WNM) {
  2280. ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
  2281. break;
  2282. }
  2283. #endif /* CONFIG_IEEE80211V */
  2284. #ifdef CONFIG_GAS
  2285. if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
  2286. gas_query_rx(wpa_s->gas, data->rx_action.da,
  2287. data->rx_action.sa, data->rx_action.bssid,
  2288. data->rx_action.data, data->rx_action.len,
  2289. data->rx_action.freq) == 0)
  2290. break;
  2291. #endif /* CONFIG_GAS */
  2292. if (data->rx_action.category == WLAN_ACTION_WNM) {
  2293. wnm_action_rx(wpa_s, &data->rx_action);
  2294. break;
  2295. }
  2296. #ifdef CONFIG_TDLS
  2297. if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
  2298. data->rx_action.len >= 4 &&
  2299. data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
  2300. wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
  2301. "Response from " MACSTR,
  2302. MAC2STR(data->rx_action.sa));
  2303. break;
  2304. }
  2305. #endif /* CONFIG_TDLS */
  2306. #ifdef CONFIG_P2P
  2307. wpas_p2p_rx_action(wpa_s, data->rx_action.da,
  2308. data->rx_action.sa,
  2309. data->rx_action.bssid,
  2310. data->rx_action.category,
  2311. data->rx_action.data,
  2312. data->rx_action.len, data->rx_action.freq);
  2313. #endif /* CONFIG_P2P */
  2314. break;
  2315. case EVENT_RX_PROBE_REQ:
  2316. if (data->rx_probe_req.sa == NULL ||
  2317. data->rx_probe_req.ie == NULL)
  2318. break;
  2319. #ifdef CONFIG_AP
  2320. if (wpa_s->ap_iface) {
  2321. hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
  2322. data->rx_probe_req.sa,
  2323. data->rx_probe_req.da,
  2324. data->rx_probe_req.bssid,
  2325. data->rx_probe_req.ie,
  2326. data->rx_probe_req.ie_len,
  2327. data->rx_probe_req.ssi_signal);
  2328. break;
  2329. }
  2330. #endif /* CONFIG_AP */
  2331. #ifdef CONFIG_P2P
  2332. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  2333. data->rx_probe_req.da,
  2334. data->rx_probe_req.bssid,
  2335. data->rx_probe_req.ie,
  2336. data->rx_probe_req.ie_len,
  2337. data->rx_probe_req.ssi_signal);
  2338. #endif /* CONFIG_P2P */
  2339. break;
  2340. case EVENT_REMAIN_ON_CHANNEL:
  2341. #ifdef CONFIG_OFFCHANNEL
  2342. offchannel_remain_on_channel_cb(
  2343. wpa_s, data->remain_on_channel.freq,
  2344. data->remain_on_channel.duration);
  2345. #endif /* CONFIG_OFFCHANNEL */
  2346. #ifdef CONFIG_P2P
  2347. wpas_p2p_remain_on_channel_cb(
  2348. wpa_s, data->remain_on_channel.freq,
  2349. data->remain_on_channel.duration);
  2350. #endif /* CONFIG_P2P */
  2351. break;
  2352. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  2353. #ifdef CONFIG_OFFCHANNEL
  2354. offchannel_cancel_remain_on_channel_cb(
  2355. wpa_s, data->remain_on_channel.freq);
  2356. #endif /* CONFIG_OFFCHANNEL */
  2357. #ifdef CONFIG_P2P
  2358. wpas_p2p_cancel_remain_on_channel_cb(
  2359. wpa_s, data->remain_on_channel.freq);
  2360. #endif /* CONFIG_P2P */
  2361. break;
  2362. #ifdef CONFIG_P2P
  2363. case EVENT_P2P_DEV_FOUND: {
  2364. struct p2p_peer_info peer_info;
  2365. os_memset(&peer_info, 0, sizeof(peer_info));
  2366. if (data->p2p_dev_found.dev_addr)
  2367. os_memcpy(peer_info.p2p_device_addr,
  2368. data->p2p_dev_found.dev_addr, ETH_ALEN);
  2369. if (data->p2p_dev_found.pri_dev_type)
  2370. os_memcpy(peer_info.pri_dev_type,
  2371. data->p2p_dev_found.pri_dev_type,
  2372. sizeof(peer_info.pri_dev_type));
  2373. if (data->p2p_dev_found.dev_name)
  2374. os_strlcpy(peer_info.device_name,
  2375. data->p2p_dev_found.dev_name,
  2376. sizeof(peer_info.device_name));
  2377. peer_info.config_methods = data->p2p_dev_found.config_methods;
  2378. peer_info.dev_capab = data->p2p_dev_found.dev_capab;
  2379. peer_info.group_capab = data->p2p_dev_found.group_capab;
  2380. /*
  2381. * FIX: new_device=1 is not necessarily correct. We should
  2382. * maintain a P2P peer database in wpa_supplicant and update
  2383. * this information based on whether the peer is truly new.
  2384. */
  2385. wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
  2386. break;
  2387. }
  2388. case EVENT_P2P_GO_NEG_REQ_RX:
  2389. wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
  2390. data->p2p_go_neg_req_rx.dev_passwd_id);
  2391. break;
  2392. case EVENT_P2P_GO_NEG_COMPLETED:
  2393. wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
  2394. break;
  2395. case EVENT_P2P_PROV_DISC_REQUEST:
  2396. wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
  2397. data->p2p_prov_disc_req.config_methods,
  2398. data->p2p_prov_disc_req.dev_addr,
  2399. data->p2p_prov_disc_req.pri_dev_type,
  2400. data->p2p_prov_disc_req.dev_name,
  2401. data->p2p_prov_disc_req.supp_config_methods,
  2402. data->p2p_prov_disc_req.dev_capab,
  2403. data->p2p_prov_disc_req.group_capab,
  2404. NULL, 0);
  2405. break;
  2406. case EVENT_P2P_PROV_DISC_RESPONSE:
  2407. wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
  2408. data->p2p_prov_disc_resp.config_methods);
  2409. break;
  2410. case EVENT_P2P_SD_REQUEST:
  2411. wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
  2412. data->p2p_sd_req.sa,
  2413. data->p2p_sd_req.dialog_token,
  2414. data->p2p_sd_req.update_indic,
  2415. data->p2p_sd_req.tlvs,
  2416. data->p2p_sd_req.tlvs_len);
  2417. break;
  2418. case EVENT_P2P_SD_RESPONSE:
  2419. wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
  2420. data->p2p_sd_resp.update_indic,
  2421. data->p2p_sd_resp.tlvs,
  2422. data->p2p_sd_resp.tlvs_len);
  2423. break;
  2424. #endif /* CONFIG_P2P */
  2425. case EVENT_EAPOL_RX:
  2426. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  2427. data->eapol_rx.data,
  2428. data->eapol_rx.data_len);
  2429. break;
  2430. case EVENT_SIGNAL_CHANGE:
  2431. bgscan_notify_signal_change(
  2432. wpa_s, data->signal_change.above_threshold,
  2433. data->signal_change.current_signal,
  2434. data->signal_change.current_noise,
  2435. data->signal_change.current_txrate);
  2436. break;
  2437. case EVENT_INTERFACE_ENABLED:
  2438. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
  2439. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  2440. wpa_supplicant_update_mac_addr(wpa_s);
  2441. #ifdef CONFIG_AP
  2442. if (!wpa_s->ap_iface) {
  2443. wpa_supplicant_set_state(wpa_s,
  2444. WPA_DISCONNECTED);
  2445. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2446. } else
  2447. wpa_supplicant_set_state(wpa_s,
  2448. WPA_COMPLETED);
  2449. #else /* CONFIG_AP */
  2450. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  2451. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2452. #endif /* CONFIG_AP */
  2453. }
  2454. break;
  2455. case EVENT_INTERFACE_DISABLED:
  2456. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
  2457. wpa_supplicant_mark_disassoc(wpa_s);
  2458. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  2459. break;
  2460. case EVENT_CHANNEL_LIST_CHANGED:
  2461. if (wpa_s->drv_priv == NULL)
  2462. break; /* Ignore event during drv initialization */
  2463. free_hw_features(wpa_s);
  2464. wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
  2465. wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
  2466. #ifdef CONFIG_P2P
  2467. wpas_p2p_update_channel_list(wpa_s);
  2468. #endif /* CONFIG_P2P */
  2469. break;
  2470. case EVENT_INTERFACE_UNAVAILABLE:
  2471. #ifdef CONFIG_P2P
  2472. wpas_p2p_interface_unavailable(wpa_s);
  2473. #endif /* CONFIG_P2P */
  2474. break;
  2475. case EVENT_BEST_CHANNEL:
  2476. wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
  2477. "(%d %d %d)",
  2478. data->best_chan.freq_24, data->best_chan.freq_5,
  2479. data->best_chan.freq_overall);
  2480. wpa_s->best_24_freq = data->best_chan.freq_24;
  2481. wpa_s->best_5_freq = data->best_chan.freq_5;
  2482. wpa_s->best_overall_freq = data->best_chan.freq_overall;
  2483. #ifdef CONFIG_P2P
  2484. wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
  2485. data->best_chan.freq_5,
  2486. data->best_chan.freq_overall);
  2487. #endif /* CONFIG_P2P */
  2488. break;
  2489. case EVENT_UNPROT_DEAUTH:
  2490. wpa_supplicant_event_unprot_deauth(wpa_s,
  2491. &data->unprot_deauth);
  2492. break;
  2493. case EVENT_UNPROT_DISASSOC:
  2494. wpa_supplicant_event_unprot_disassoc(wpa_s,
  2495. &data->unprot_disassoc);
  2496. break;
  2497. case EVENT_STATION_LOW_ACK:
  2498. #ifdef CONFIG_AP
  2499. if (wpa_s->ap_iface && data)
  2500. hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
  2501. data->low_ack.addr);
  2502. #endif /* CONFIG_AP */
  2503. #ifdef CONFIG_TDLS
  2504. if (data)
  2505. wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
  2506. #endif /* CONFIG_TDLS */
  2507. break;
  2508. case EVENT_IBSS_PEER_LOST:
  2509. #ifdef CONFIG_IBSS_RSN
  2510. ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
  2511. #endif /* CONFIG_IBSS_RSN */
  2512. break;
  2513. case EVENT_DRIVER_GTK_REKEY:
  2514. if (os_memcmp(data->driver_gtk_rekey.bssid,
  2515. wpa_s->bssid, ETH_ALEN))
  2516. break;
  2517. if (!wpa_s->wpa)
  2518. break;
  2519. wpa_sm_update_replay_ctr(wpa_s->wpa,
  2520. data->driver_gtk_rekey.replay_ctr);
  2521. break;
  2522. case EVENT_SCHED_SCAN_STOPPED:
  2523. wpa_s->sched_scanning = 0;
  2524. wpa_supplicant_notify_scanning(wpa_s, 0);
  2525. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  2526. break;
  2527. /*
  2528. * If we timed out, start a new sched scan to continue
  2529. * searching for more SSIDs.
  2530. */
  2531. if (wpa_s->sched_scan_timed_out)
  2532. wpa_supplicant_req_sched_scan(wpa_s);
  2533. break;
  2534. case EVENT_WPS_BUTTON_PUSHED:
  2535. #ifdef CONFIG_WPS
  2536. wpas_wps_start_pbc(wpa_s, NULL, 0);
  2537. #endif /* CONFIG_WPS */
  2538. break;
  2539. default:
  2540. wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
  2541. break;
  2542. }
  2543. }