events.c 76 KB

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