events.c 76 KB

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