events.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214
  1. /*
  2. * WPA Supplicant - Driver event processing
  3. * Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "includes.h"
  15. #include "common.h"
  16. #include "eapol_supp/eapol_supp_sm.h"
  17. #include "rsn_supp/wpa.h"
  18. #include "eloop.h"
  19. #include "config.h"
  20. #include "l2_packet/l2_packet.h"
  21. #include "wpa_supplicant_i.h"
  22. #include "driver_i.h"
  23. #include "pcsc_funcs.h"
  24. #include "rsn_supp/preauth.h"
  25. #include "rsn_supp/pmksa_cache.h"
  26. #include "common/wpa_ctrl.h"
  27. #include "eap_peer/eap.h"
  28. #include "ap/hostapd.h"
  29. #include "p2p/p2p.h"
  30. #include "notify.h"
  31. #include "common/ieee802_11_defs.h"
  32. #include "common/ieee802_11_common.h"
  33. #include "crypto/random.h"
  34. #include "blacklist.h"
  35. #include "wpas_glue.h"
  36. #include "wps_supplicant.h"
  37. #include "ibss_rsn.h"
  38. #include "sme.h"
  39. #include "p2p_supplicant.h"
  40. #include "bgscan.h"
  41. #include "ap.h"
  42. #include "bss.h"
  43. #include "mlme.h"
  44. #include "scan.h"
  45. static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
  46. {
  47. struct wpa_ssid *ssid, *old_ssid;
  48. if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
  49. return 0;
  50. wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
  51. "information");
  52. ssid = wpa_supplicant_get_ssid(wpa_s);
  53. if (ssid == NULL) {
  54. wpa_msg(wpa_s, MSG_INFO,
  55. "No network configuration found for the current AP");
  56. return -1;
  57. }
  58. if (ssid->disabled) {
  59. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
  60. return -1;
  61. }
  62. wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
  63. "current AP");
  64. if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
  65. WPA_KEY_MGMT_WPA_NONE |
  66. WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X |
  67. WPA_KEY_MGMT_PSK_SHA256 |
  68. WPA_KEY_MGMT_IEEE8021X_SHA256)) {
  69. u8 wpa_ie[80];
  70. size_t wpa_ie_len = sizeof(wpa_ie);
  71. wpa_supplicant_set_suites(wpa_s, NULL, ssid,
  72. wpa_ie, &wpa_ie_len);
  73. } else {
  74. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  75. }
  76. if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
  77. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  78. old_ssid = wpa_s->current_ssid;
  79. wpa_s->current_ssid = ssid;
  80. wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
  81. wpa_supplicant_initiate_eapol(wpa_s);
  82. if (old_ssid != wpa_s->current_ssid)
  83. wpas_notify_network_changed(wpa_s);
  84. return 0;
  85. }
  86. static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
  87. void *sock_ctx)
  88. {
  89. struct wpa_supplicant *wpa_s = eloop_ctx;
  90. if (wpa_s->countermeasures) {
  91. wpa_s->countermeasures = 0;
  92. wpa_drv_set_countermeasures(wpa_s, 0);
  93. wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
  94. wpa_supplicant_req_scan(wpa_s, 0, 0);
  95. }
  96. }
  97. void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
  98. {
  99. int bssid_changed;
  100. #ifdef CONFIG_IBSS_RSN
  101. ibss_rsn_deinit(wpa_s->ibss_rsn);
  102. wpa_s->ibss_rsn = NULL;
  103. #endif /* CONFIG_IBSS_RSN */
  104. #ifdef CONFIG_AP
  105. wpa_supplicant_ap_deinit(wpa_s);
  106. #endif /* CONFIG_AP */
  107. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  108. return;
  109. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  110. bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
  111. os_memset(wpa_s->bssid, 0, ETH_ALEN);
  112. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  113. wpa_s->current_bss = NULL;
  114. wpa_s->assoc_freq = 0;
  115. if (bssid_changed)
  116. wpas_notify_bssid_changed(wpa_s);
  117. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  118. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  119. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  120. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  121. wpa_s->ap_ies_from_associnfo = 0;
  122. }
  123. static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
  124. {
  125. struct wpa_ie_data ie;
  126. int pmksa_set = -1;
  127. size_t i;
  128. if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
  129. ie.pmkid == NULL)
  130. return;
  131. for (i = 0; i < ie.num_pmkid; i++) {
  132. pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
  133. ie.pmkid + i * PMKID_LEN,
  134. NULL, NULL, 0);
  135. if (pmksa_set == 0) {
  136. eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
  137. break;
  138. }
  139. }
  140. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
  141. "PMKSA cache", pmksa_set == 0 ? "" : "not ");
  142. }
  143. static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
  144. union wpa_event_data *data)
  145. {
  146. if (data == NULL) {
  147. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
  148. "event");
  149. return;
  150. }
  151. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
  152. " index=%d preauth=%d",
  153. MAC2STR(data->pmkid_candidate.bssid),
  154. data->pmkid_candidate.index,
  155. data->pmkid_candidate.preauth);
  156. pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
  157. data->pmkid_candidate.index,
  158. data->pmkid_candidate.preauth);
  159. }
  160. static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
  161. {
  162. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  163. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
  164. return 0;
  165. #ifdef IEEE8021X_EAPOL
  166. if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
  167. wpa_s->current_ssid &&
  168. !(wpa_s->current_ssid->eapol_flags &
  169. (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  170. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
  171. /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
  172. * plaintext or static WEP keys). */
  173. return 0;
  174. }
  175. #endif /* IEEE8021X_EAPOL */
  176. return 1;
  177. }
  178. /**
  179. * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
  180. * @wpa_s: pointer to wpa_supplicant data
  181. * @ssid: Configuration data for the network
  182. * Returns: 0 on success, -1 on failure
  183. *
  184. * This function is called when starting authentication with a network that is
  185. * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
  186. */
  187. int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
  188. struct wpa_ssid *ssid)
  189. {
  190. #ifdef IEEE8021X_EAPOL
  191. int aka = 0, sim = 0, type;
  192. if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
  193. return 0;
  194. if (ssid->eap.eap_methods == NULL) {
  195. sim = 1;
  196. aka = 1;
  197. } else {
  198. struct eap_method_type *eap = ssid->eap.eap_methods;
  199. while (eap->vendor != EAP_VENDOR_IETF ||
  200. eap->method != EAP_TYPE_NONE) {
  201. if (eap->vendor == EAP_VENDOR_IETF) {
  202. if (eap->method == EAP_TYPE_SIM)
  203. sim = 1;
  204. else if (eap->method == EAP_TYPE_AKA)
  205. aka = 1;
  206. }
  207. eap++;
  208. }
  209. }
  210. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
  211. sim = 0;
  212. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
  213. aka = 0;
  214. if (!sim && !aka) {
  215. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
  216. "use SIM, but neither EAP-SIM nor EAP-AKA are "
  217. "enabled");
  218. return 0;
  219. }
  220. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
  221. "(sim=%d aka=%d) - initialize PCSC", sim, aka);
  222. if (sim && aka)
  223. type = SCARD_TRY_BOTH;
  224. else if (aka)
  225. type = SCARD_USIM_ONLY;
  226. else
  227. type = SCARD_GSM_SIM_ONLY;
  228. wpa_s->scard = scard_init(type);
  229. if (wpa_s->scard == NULL) {
  230. wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
  231. "(pcsc-lite)");
  232. return -1;
  233. }
  234. wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
  235. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  236. #endif /* IEEE8021X_EAPOL */
  237. return 0;
  238. }
  239. #ifndef CONFIG_NO_SCAN_PROCESSING
  240. static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
  241. struct wpa_ssid *ssid)
  242. {
  243. int i, privacy = 0;
  244. if (ssid->mixed_cell)
  245. return 1;
  246. #ifdef CONFIG_WPS
  247. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
  248. return 1;
  249. #endif /* CONFIG_WPS */
  250. for (i = 0; i < NUM_WEP_KEYS; i++) {
  251. if (ssid->wep_key_len[i]) {
  252. privacy = 1;
  253. break;
  254. }
  255. }
  256. #ifdef IEEE8021X_EAPOL
  257. if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  258. ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  259. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
  260. privacy = 1;
  261. #endif /* IEEE8021X_EAPOL */
  262. if (wpa_key_mgmt_wpa(ssid->key_mgmt))
  263. privacy = 1;
  264. if (bss->caps & IEEE80211_CAP_PRIVACY)
  265. return privacy;
  266. return !privacy;
  267. }
  268. static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
  269. struct wpa_ssid *ssid,
  270. struct wpa_scan_res *bss)
  271. {
  272. struct wpa_ie_data ie;
  273. int proto_match = 0;
  274. const u8 *rsn_ie, *wpa_ie;
  275. int ret;
  276. int wep_ok;
  277. ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
  278. if (ret >= 0)
  279. return ret;
  280. /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
  281. wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
  282. (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
  283. ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
  284. (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
  285. rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  286. while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
  287. proto_match++;
  288. if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
  289. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
  290. "failed");
  291. break;
  292. }
  293. if (wep_ok &&
  294. (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
  295. {
  296. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
  297. "in RSN IE");
  298. return 1;
  299. }
  300. if (!(ie.proto & ssid->proto)) {
  301. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
  302. "mismatch");
  303. break;
  304. }
  305. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  306. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
  307. "cipher mismatch");
  308. break;
  309. }
  310. if (!(ie.group_cipher & ssid->group_cipher)) {
  311. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
  312. "cipher mismatch");
  313. break;
  314. }
  315. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  316. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
  317. "mismatch");
  318. break;
  319. }
  320. #ifdef CONFIG_IEEE80211W
  321. if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
  322. ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
  323. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
  324. "frame protection");
  325. break;
  326. }
  327. #endif /* CONFIG_IEEE80211W */
  328. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
  329. return 1;
  330. }
  331. wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  332. while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
  333. proto_match++;
  334. if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
  335. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
  336. "failed");
  337. break;
  338. }
  339. if (wep_ok &&
  340. (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
  341. {
  342. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
  343. "in WPA IE");
  344. return 1;
  345. }
  346. if (!(ie.proto & ssid->proto)) {
  347. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
  348. "mismatch");
  349. break;
  350. }
  351. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  352. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
  353. "cipher mismatch");
  354. break;
  355. }
  356. if (!(ie.group_cipher & ssid->group_cipher)) {
  357. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
  358. "cipher mismatch");
  359. break;
  360. }
  361. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  362. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
  363. "mismatch");
  364. break;
  365. }
  366. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
  367. return 1;
  368. }
  369. if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
  370. wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
  371. wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
  372. return 0;
  373. }
  374. if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
  375. wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
  376. return 1;
  377. }
  378. wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
  379. "WPA/WPA2");
  380. return 0;
  381. }
  382. static int freq_allowed(int *freqs, int freq)
  383. {
  384. int i;
  385. if (freqs == NULL)
  386. return 1;
  387. for (i = 0; freqs[i]; i++)
  388. if (freqs[i] == freq)
  389. return 1;
  390. return 0;
  391. }
  392. static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
  393. int i, struct wpa_scan_res *bss,
  394. struct wpa_ssid *group)
  395. {
  396. const u8 *ssid_;
  397. u8 wpa_ie_len, rsn_ie_len, ssid_len;
  398. int wpa;
  399. struct wpa_blacklist *e;
  400. const u8 *ie;
  401. struct wpa_ssid *ssid;
  402. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  403. ssid_ = ie ? ie + 2 : (u8 *) "";
  404. ssid_len = ie ? ie[1] : 0;
  405. ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  406. wpa_ie_len = ie ? ie[1] : 0;
  407. ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  408. rsn_ie_len = ie ? ie[1] : 0;
  409. wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
  410. "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
  411. i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
  412. wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
  413. wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
  414. e = wpa_blacklist_get(wpa_s, bss->bssid);
  415. if (e) {
  416. int limit = 1;
  417. if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) {
  418. /*
  419. * When only a single network is enabled, we can
  420. * trigger blacklisting on the first failure. This
  421. * should not be done with multiple enabled networks to
  422. * avoid getting forced to move into a worse ESS on
  423. * single error if there are no other BSSes of the
  424. * current ESS.
  425. */
  426. limit = 0;
  427. }
  428. if (e->count > limit) {
  429. wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
  430. "(count=%d limit=%d)", e->count, limit);
  431. return NULL;
  432. }
  433. }
  434. if (ssid_len == 0) {
  435. wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
  436. return NULL;
  437. }
  438. wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
  439. for (ssid = group; ssid; ssid = ssid->pnext) {
  440. int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
  441. if (ssid->disabled) {
  442. wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
  443. continue;
  444. }
  445. #ifdef CONFIG_WPS
  446. if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
  447. wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
  448. "(WPS)");
  449. continue;
  450. }
  451. if (wpa && ssid->ssid_len == 0 &&
  452. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  453. check_ssid = 0;
  454. if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
  455. /* Only allow wildcard SSID match if an AP
  456. * advertises active WPS operation that matches
  457. * with our mode. */
  458. check_ssid = 1;
  459. if (ssid->ssid_len == 0 &&
  460. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  461. check_ssid = 0;
  462. }
  463. #endif /* CONFIG_WPS */
  464. if (check_ssid &&
  465. (ssid_len != ssid->ssid_len ||
  466. os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
  467. wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
  468. continue;
  469. }
  470. if (ssid->bssid_set &&
  471. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
  472. wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
  473. continue;
  474. }
  475. if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
  476. continue;
  477. if (!wpa &&
  478. !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
  479. !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
  480. !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
  481. wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
  482. "not allowed");
  483. continue;
  484. }
  485. if (!wpa_supplicant_match_privacy(bss, ssid)) {
  486. wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
  487. "mismatch");
  488. continue;
  489. }
  490. if (bss->caps & IEEE80211_CAP_IBSS) {
  491. wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
  492. "network");
  493. continue;
  494. }
  495. if (!freq_allowed(ssid->freq_list, bss->freq)) {
  496. wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
  497. "allowed");
  498. continue;
  499. }
  500. #ifdef CONFIG_P2P
  501. /*
  502. * TODO: skip the AP if its P2P IE has Group Formation
  503. * bit set in the P2P Group Capability Bitmap and we
  504. * are not in Group Formation with that device.
  505. */
  506. #endif /* CONFIG_P2P */
  507. /* Matching configuration found */
  508. return ssid;
  509. }
  510. /* No matching configuration found */
  511. return NULL;
  512. }
  513. static struct wpa_bss *
  514. wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
  515. struct wpa_scan_results *scan_res,
  516. struct wpa_ssid *group,
  517. struct wpa_ssid **selected_ssid)
  518. {
  519. size_t i;
  520. wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
  521. group->priority);
  522. for (i = 0; i < scan_res->num; i++) {
  523. struct wpa_scan_res *bss = scan_res->res[i];
  524. const u8 *ie, *ssid;
  525. u8 ssid_len;
  526. *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
  527. if (!*selected_ssid)
  528. continue;
  529. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  530. ssid = ie ? ie + 2 : (u8 *) "";
  531. ssid_len = ie ? ie[1] : 0;
  532. wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
  533. " ssid='%s'",
  534. MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
  535. return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
  536. }
  537. return NULL;
  538. }
  539. static struct wpa_bss *
  540. wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
  541. struct wpa_scan_results *scan_res,
  542. struct wpa_ssid **selected_ssid)
  543. {
  544. struct wpa_bss *selected = NULL;
  545. int prio;
  546. while (selected == NULL) {
  547. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  548. selected = wpa_supplicant_select_bss(
  549. wpa_s, scan_res, wpa_s->conf->pssid[prio],
  550. selected_ssid);
  551. if (selected)
  552. break;
  553. }
  554. if (selected == NULL && wpa_s->blacklist) {
  555. wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
  556. "blacklist and try again");
  557. wpa_blacklist_clear(wpa_s);
  558. wpa_s->blacklist_cleared++;
  559. } else if (selected == NULL)
  560. break;
  561. }
  562. return selected;
  563. }
  564. static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
  565. int timeout_sec, int timeout_usec)
  566. {
  567. if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
  568. /*
  569. * No networks are enabled; short-circuit request so
  570. * we don't wait timeout seconds before transitioning
  571. * to INACTIVE state.
  572. */
  573. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  574. return;
  575. }
  576. wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
  577. }
  578. void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
  579. struct wpa_bss *selected,
  580. struct wpa_ssid *ssid)
  581. {
  582. if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
  583. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
  584. "PBC session overlap");
  585. #ifdef CONFIG_P2P
  586. if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
  587. return;
  588. #endif /* CONFIG_P2P */
  589. #ifdef CONFIG_WPS
  590. wpas_wps_cancel(wpa_s);
  591. #endif /* CONFIG_WPS */
  592. return;
  593. }
  594. /*
  595. * Do not trigger new association unless the BSSID has changed or if
  596. * reassociation is requested. If we are in process of associating with
  597. * the selected BSSID, do not trigger new attempt.
  598. */
  599. if (wpa_s->reassociate ||
  600. (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
  601. ((wpa_s->wpa_state != WPA_ASSOCIATING &&
  602. wpa_s->wpa_state != WPA_AUTHENTICATING) ||
  603. os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
  604. 0))) {
  605. if (wpa_supplicant_scard_init(wpa_s, ssid)) {
  606. wpa_supplicant_req_new_scan(wpa_s, 10, 0);
  607. return;
  608. }
  609. wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
  610. "reassociate: %d selected: "MACSTR " bssid: " MACSTR
  611. " pending: " MACSTR " wpa_state: %s",
  612. wpa_s->reassociate, MAC2STR(selected->bssid),
  613. MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
  614. wpa_supplicant_state_txt(wpa_s->wpa_state));
  615. wpa_supplicant_associate(wpa_s, selected, ssid);
  616. } else {
  617. wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
  618. "selected AP");
  619. }
  620. }
  621. static struct wpa_ssid *
  622. wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
  623. {
  624. int prio;
  625. struct wpa_ssid *ssid;
  626. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  627. for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
  628. {
  629. if (ssid->disabled)
  630. continue;
  631. if (ssid->mode == IEEE80211_MODE_IBSS ||
  632. ssid->mode == IEEE80211_MODE_AP)
  633. return ssid;
  634. }
  635. }
  636. return NULL;
  637. }
  638. /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
  639. * on BSS added and BSS changed events */
  640. static void wpa_supplicant_rsn_preauth_scan_results(
  641. struct wpa_supplicant *wpa_s)
  642. {
  643. struct wpa_bss *bss;
  644. if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
  645. return;
  646. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  647. const u8 *ssid, *rsn;
  648. ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
  649. if (ssid == NULL)
  650. continue;
  651. rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  652. if (rsn == NULL)
  653. continue;
  654. rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
  655. }
  656. }
  657. static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
  658. struct wpa_bss *selected,
  659. struct wpa_ssid *ssid,
  660. struct wpa_scan_results *scan_res)
  661. {
  662. size_t i;
  663. struct wpa_scan_res *current_bss = NULL;
  664. int min_diff;
  665. if (wpa_s->reassociate)
  666. return 1; /* explicit request to reassociate */
  667. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  668. return 1; /* we are not associated; continue */
  669. if (wpa_s->current_ssid == NULL)
  670. return 1; /* unknown current SSID */
  671. if (wpa_s->current_ssid != ssid)
  672. return 1; /* different network block */
  673. for (i = 0; i < scan_res->num; i++) {
  674. struct wpa_scan_res *res = scan_res->res[i];
  675. const u8 *ie;
  676. if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
  677. continue;
  678. ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
  679. if (ie == NULL)
  680. continue;
  681. if (ie[1] != wpa_s->current_ssid->ssid_len ||
  682. os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
  683. continue;
  684. current_bss = res;
  685. break;
  686. }
  687. if (!current_bss)
  688. return 1; /* current BSS not seen in scan results */
  689. wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
  690. wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
  691. MAC2STR(current_bss->bssid), current_bss->level);
  692. wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
  693. MAC2STR(selected->bssid), selected->level);
  694. if (wpa_s->current_ssid->bssid_set &&
  695. os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
  696. 0) {
  697. wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
  698. "has preferred BSSID");
  699. return 1;
  700. }
  701. min_diff = 2;
  702. if (current_bss->level < 0) {
  703. if (current_bss->level < -85)
  704. min_diff = 1;
  705. else if (current_bss->level < -80)
  706. min_diff = 2;
  707. else if (current_bss->level < -75)
  708. min_diff = 3;
  709. else if (current_bss->level < -70)
  710. min_diff = 4;
  711. else
  712. min_diff = 5;
  713. }
  714. if (abs(current_bss->level - selected->level) < min_diff) {
  715. wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
  716. "in signal level");
  717. return 0;
  718. }
  719. return 1;
  720. }
  721. /* Return < 0 if no scan results could be fetched. */
  722. static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  723. union wpa_event_data *data)
  724. {
  725. struct wpa_bss *selected;
  726. struct wpa_ssid *ssid = NULL;
  727. struct wpa_scan_results *scan_res;
  728. int ap = 0;
  729. #ifdef CONFIG_AP
  730. if (wpa_s->ap_iface)
  731. ap = 1;
  732. #endif /* CONFIG_AP */
  733. wpa_supplicant_notify_scanning(wpa_s, 0);
  734. scan_res = wpa_supplicant_get_scan_results(wpa_s,
  735. data ? &data->scan_info :
  736. NULL, 1);
  737. if (scan_res == NULL) {
  738. if (wpa_s->conf->ap_scan == 2 || ap)
  739. return -1;
  740. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
  741. "scanning again");
  742. wpa_supplicant_req_new_scan(wpa_s, 1, 0);
  743. return -1;
  744. }
  745. #ifndef CONFIG_NO_RANDOM_POOL
  746. size_t i, num;
  747. num = scan_res->num;
  748. if (num > 10)
  749. num = 10;
  750. for (i = 0; i < num; i++) {
  751. u8 buf[5];
  752. struct wpa_scan_res *res = scan_res->res[i];
  753. buf[0] = res->bssid[5];
  754. buf[1] = res->qual & 0xff;
  755. buf[2] = res->noise & 0xff;
  756. buf[3] = res->level & 0xff;
  757. buf[4] = res->tsf & 0xff;
  758. random_add_randomness(buf, sizeof(buf));
  759. }
  760. #endif /* CONFIG_NO_RANDOM_POOL */
  761. if (wpa_s->scan_res_handler) {
  762. void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
  763. struct wpa_scan_results *scan_res);
  764. scan_res_handler = wpa_s->scan_res_handler;
  765. wpa_s->scan_res_handler = NULL;
  766. scan_res_handler(wpa_s, scan_res);
  767. wpa_scan_results_free(scan_res);
  768. return 0;
  769. }
  770. if (ap) {
  771. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
  772. #ifdef CONFIG_AP
  773. if (wpa_s->ap_iface->scan_cb)
  774. wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
  775. #endif /* CONFIG_AP */
  776. wpa_scan_results_free(scan_res);
  777. return 0;
  778. }
  779. wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
  780. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  781. wpas_notify_scan_results(wpa_s);
  782. wpas_notify_scan_done(wpa_s, 1);
  783. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
  784. wpa_scan_results_free(scan_res);
  785. return 0;
  786. }
  787. if (wpa_s->disconnected) {
  788. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  789. wpa_scan_results_free(scan_res);
  790. return 0;
  791. }
  792. if (bgscan_notify_scan(wpa_s, scan_res) == 1) {
  793. wpa_scan_results_free(scan_res);
  794. return 0;
  795. }
  796. selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
  797. if (selected) {
  798. int skip;
  799. skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
  800. scan_res);
  801. wpa_scan_results_free(scan_res);
  802. if (skip)
  803. return 0;
  804. wpa_supplicant_connect(wpa_s, selected, ssid);
  805. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  806. } else {
  807. wpa_scan_results_free(scan_res);
  808. wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
  809. ssid = wpa_supplicant_pick_new_network(wpa_s);
  810. if (ssid) {
  811. wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
  812. wpa_supplicant_associate(wpa_s, NULL, ssid);
  813. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  814. } else {
  815. int timeout_sec = wpa_s->scan_interval;
  816. int timeout_usec = 0;
  817. #ifdef CONFIG_P2P
  818. if (wpa_s->p2p_in_provisioning) {
  819. /*
  820. * Use shorter wait during P2P Provisioning
  821. * state to speed up group formation.
  822. */
  823. timeout_sec = 0;
  824. timeout_usec = 250000;
  825. }
  826. #endif /* CONFIG_P2P */
  827. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  828. timeout_usec);
  829. }
  830. }
  831. return 0;
  832. }
  833. static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  834. union wpa_event_data *data)
  835. {
  836. const char *rn, *rn2;
  837. struct wpa_supplicant *ifs;
  838. if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
  839. /*
  840. * If no scan results could be fetched, then no need to
  841. * notify those interfaces that did not actually request
  842. * this scan.
  843. */
  844. return;
  845. }
  846. /*
  847. * Check other interfaces to see if they have the same radio-name. If
  848. * so, they get updated with this same scan info.
  849. */
  850. if (!wpa_s->driver->get_radio_name)
  851. return;
  852. rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
  853. if (rn == NULL || rn[0] == '\0')
  854. return;
  855. wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
  856. "sharing same radio (%s) in event_scan_results", rn);
  857. for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
  858. if (ifs == wpa_s || !ifs->driver->get_radio_name)
  859. continue;
  860. rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
  861. if (rn2 && os_strcmp(rn, rn2) == 0) {
  862. wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
  863. "sibling", ifs->ifname);
  864. _wpa_supplicant_event_scan_results(ifs, data);
  865. }
  866. }
  867. }
  868. #endif /* CONFIG_NO_SCAN_PROCESSING */
  869. static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  870. union wpa_event_data *data)
  871. {
  872. int l, len, found = 0, wpa_found, rsn_found;
  873. const u8 *p;
  874. wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
  875. if (data->assoc_info.req_ies)
  876. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  877. data->assoc_info.req_ies_len);
  878. if (data->assoc_info.resp_ies) {
  879. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  880. data->assoc_info.resp_ies_len);
  881. #ifdef CONFIG_TDLS
  882. wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
  883. data->assoc_info.resp_ies_len);
  884. #endif /* CONFIG_TDLS */
  885. }
  886. if (data->assoc_info.beacon_ies)
  887. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  888. data->assoc_info.beacon_ies,
  889. data->assoc_info.beacon_ies_len);
  890. if (data->assoc_info.freq)
  891. wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
  892. data->assoc_info.freq);
  893. p = data->assoc_info.req_ies;
  894. l = data->assoc_info.req_ies_len;
  895. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  896. while (p && l >= 2) {
  897. len = p[1] + 2;
  898. if (len > l) {
  899. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  900. p, l);
  901. break;
  902. }
  903. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  904. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  905. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  906. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  907. break;
  908. found = 1;
  909. wpa_find_assoc_pmkid(wpa_s);
  910. break;
  911. }
  912. l -= len;
  913. p += len;
  914. }
  915. if (!found && data->assoc_info.req_ies)
  916. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  917. #ifdef CONFIG_IEEE80211R
  918. #ifdef CONFIG_SME
  919. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  920. u8 bssid[ETH_ALEN];
  921. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  922. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  923. data->assoc_info.resp_ies,
  924. data->assoc_info.resp_ies_len,
  925. bssid) < 0) {
  926. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  927. "Reassociation Response failed");
  928. wpa_supplicant_deauthenticate(
  929. wpa_s, WLAN_REASON_INVALID_IE);
  930. return -1;
  931. }
  932. }
  933. p = data->assoc_info.resp_ies;
  934. l = data->assoc_info.resp_ies_len;
  935. #ifdef CONFIG_WPS_STRICT
  936. if (p && wpa_s->current_ssid &&
  937. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  938. struct wpabuf *wps;
  939. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  940. if (wps == NULL) {
  941. wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
  942. "include WPS IE in (Re)Association Response");
  943. return -1;
  944. }
  945. if (wps_validate_assoc_resp(wps) < 0) {
  946. wpabuf_free(wps);
  947. wpa_supplicant_deauthenticate(
  948. wpa_s, WLAN_REASON_INVALID_IE);
  949. return -1;
  950. }
  951. wpabuf_free(wps);
  952. }
  953. #endif /* CONFIG_WPS_STRICT */
  954. /* Go through the IEs and make a copy of the MDIE, if present. */
  955. while (p && l >= 2) {
  956. len = p[1] + 2;
  957. if (len > l) {
  958. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  959. p, l);
  960. break;
  961. }
  962. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  963. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  964. wpa_s->sme.ft_used = 1;
  965. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  966. MOBILITY_DOMAIN_ID_LEN);
  967. break;
  968. }
  969. l -= len;
  970. p += len;
  971. }
  972. #endif /* CONFIG_SME */
  973. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  974. data->assoc_info.resp_ies_len);
  975. #endif /* CONFIG_IEEE80211R */
  976. /* WPA/RSN IE from Beacon/ProbeResp */
  977. p = data->assoc_info.beacon_ies;
  978. l = data->assoc_info.beacon_ies_len;
  979. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  980. */
  981. wpa_found = rsn_found = 0;
  982. while (p && l >= 2) {
  983. len = p[1] + 2;
  984. if (len > l) {
  985. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  986. p, l);
  987. break;
  988. }
  989. if (!wpa_found &&
  990. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  991. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  992. wpa_found = 1;
  993. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  994. }
  995. if (!rsn_found &&
  996. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  997. rsn_found = 1;
  998. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  999. }
  1000. l -= len;
  1001. p += len;
  1002. }
  1003. if (!wpa_found && data->assoc_info.beacon_ies)
  1004. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  1005. if (!rsn_found && data->assoc_info.beacon_ies)
  1006. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  1007. if (wpa_found || rsn_found)
  1008. wpa_s->ap_ies_from_associnfo = 1;
  1009. if (wpa_s->assoc_freq && data->assoc_info.freq &&
  1010. wpa_s->assoc_freq != data->assoc_info.freq) {
  1011. wpa_printf(MSG_DEBUG, "Operating frequency changed from "
  1012. "%u to %u MHz",
  1013. wpa_s->assoc_freq, data->assoc_info.freq);
  1014. wpa_supplicant_update_scan_results(wpa_s);
  1015. }
  1016. wpa_s->assoc_freq = data->assoc_info.freq;
  1017. return 0;
  1018. }
  1019. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  1020. union wpa_event_data *data)
  1021. {
  1022. u8 bssid[ETH_ALEN];
  1023. int ft_completed;
  1024. int bssid_changed;
  1025. struct wpa_driver_capa capa;
  1026. #ifdef CONFIG_AP
  1027. if (wpa_s->ap_iface) {
  1028. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  1029. data->assoc_info.addr,
  1030. data->assoc_info.req_ies,
  1031. data->assoc_info.req_ies_len,
  1032. data->assoc_info.reassoc);
  1033. return;
  1034. }
  1035. #endif /* CONFIG_AP */
  1036. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  1037. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  1038. return;
  1039. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  1040. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
  1041. os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
  1042. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
  1043. (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
  1044. os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
  1045. wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  1046. MACSTR, MAC2STR(bssid));
  1047. random_add_randomness(bssid, ETH_ALEN);
  1048. bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
  1049. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  1050. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1051. if (bssid_changed)
  1052. wpas_notify_bssid_changed(wpa_s);
  1053. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  1054. wpa_clear_keys(wpa_s, bssid);
  1055. }
  1056. if (wpa_supplicant_select_config(wpa_s) < 0) {
  1057. wpa_supplicant_disassociate(
  1058. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1059. return;
  1060. }
  1061. if (wpa_s->current_ssid) {
  1062. struct wpa_bss *bss = NULL;
  1063. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1064. if (ssid->ssid_len > 0)
  1065. bss = wpa_bss_get(wpa_s, bssid,
  1066. ssid->ssid, ssid->ssid_len);
  1067. if (!bss)
  1068. bss = wpa_bss_get_bssid(wpa_s, bssid);
  1069. if (bss)
  1070. wpa_s->current_bss = bss;
  1071. }
  1072. }
  1073. #ifdef CONFIG_SME
  1074. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  1075. wpa_s->sme.prev_bssid_set = 1;
  1076. #endif /* CONFIG_SME */
  1077. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  1078. if (wpa_s->current_ssid) {
  1079. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  1080. * initialized before association, but for other modes,
  1081. * initialize PC/SC here, if the current configuration needs
  1082. * smartcard or SIM/USIM. */
  1083. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  1084. }
  1085. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  1086. if (wpa_s->l2)
  1087. l2_packet_notify_auth_start(wpa_s->l2);
  1088. /*
  1089. * Set portEnabled first to FALSE in order to get EAP state machine out
  1090. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  1091. * state machine may transit to AUTHENTICATING state based on obsolete
  1092. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  1093. * AUTHENTICATED without ever giving chance to EAP state machine to
  1094. * reset the state.
  1095. */
  1096. if (!ft_completed) {
  1097. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  1098. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  1099. }
  1100. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  1101. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  1102. /* 802.1X::portControl = Auto */
  1103. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  1104. wpa_s->eapol_received = 0;
  1105. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1106. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  1107. (wpa_s->current_ssid &&
  1108. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  1109. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1110. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1111. } else if (!ft_completed) {
  1112. /* Timeout for receiving the first EAPOL packet */
  1113. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  1114. }
  1115. wpa_supplicant_cancel_scan(wpa_s);
  1116. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1117. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1118. /*
  1119. * We are done; the driver will take care of RSN 4-way
  1120. * handshake.
  1121. */
  1122. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1123. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1124. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1125. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1126. } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1127. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1128. /*
  1129. * The driver will take care of RSN 4-way handshake, so we need
  1130. * to allow EAPOL supplicant to complete its work without
  1131. * waiting for WPA supplicant.
  1132. */
  1133. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1134. } else if (ft_completed) {
  1135. /*
  1136. * FT protocol completed - make sure EAPOL state machine ends
  1137. * up in authenticated.
  1138. */
  1139. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1140. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1141. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1142. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1143. }
  1144. if (wpa_s->pending_eapol_rx) {
  1145. struct os_time now, age;
  1146. os_get_time(&now);
  1147. os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  1148. if (age.sec == 0 && age.usec < 100000 &&
  1149. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  1150. 0) {
  1151. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
  1152. "frame that was received just before "
  1153. "association notification");
  1154. wpa_supplicant_rx_eapol(
  1155. wpa_s, wpa_s->pending_eapol_rx_src,
  1156. wpabuf_head(wpa_s->pending_eapol_rx),
  1157. wpabuf_len(wpa_s->pending_eapol_rx));
  1158. }
  1159. wpabuf_free(wpa_s->pending_eapol_rx);
  1160. wpa_s->pending_eapol_rx = NULL;
  1161. }
  1162. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1163. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1164. wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
  1165. capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
  1166. /* Set static WEP keys again */
  1167. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1168. }
  1169. #ifdef CONFIG_IBSS_RSN
  1170. if (wpa_s->current_ssid &&
  1171. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  1172. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  1173. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
  1174. wpa_s->ibss_rsn == NULL) {
  1175. wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
  1176. if (!wpa_s->ibss_rsn) {
  1177. wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
  1178. wpa_supplicant_deauthenticate(
  1179. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1180. return;
  1181. }
  1182. ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
  1183. }
  1184. #endif /* CONFIG_IBSS_RSN */
  1185. }
  1186. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1187. u16 reason_code)
  1188. {
  1189. const u8 *bssid;
  1190. int authenticating;
  1191. u8 prev_pending_bssid[ETH_ALEN];
  1192. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1193. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1194. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1195. /*
  1196. * At least Host AP driver and a Prism3 card seemed to be
  1197. * generating streams of disconnected events when configuring
  1198. * IBSS for WPA-None. Ignore them for now.
  1199. */
  1200. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
  1201. "IBSS/WPA-None mode");
  1202. return;
  1203. }
  1204. if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
  1205. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1206. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1207. "pre-shared key may be incorrect");
  1208. }
  1209. if (!wpa_s->auto_reconnect_disabled ||
  1210. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
  1211. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect enabled: try to "
  1212. "reconnect (wps=%d)",
  1213. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
  1214. if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  1215. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1216. } else {
  1217. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect disabled: do not "
  1218. "try to re-connect");
  1219. wpa_s->reassociate = 0;
  1220. wpa_s->disconnected = 1;
  1221. }
  1222. bssid = wpa_s->bssid;
  1223. if (is_zero_ether_addr(bssid))
  1224. bssid = wpa_s->pending_bssid;
  1225. wpas_connection_failed(wpa_s, bssid);
  1226. wpa_sm_notify_disassoc(wpa_s->wpa);
  1227. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1228. " reason=%d",
  1229. MAC2STR(bssid), reason_code);
  1230. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  1231. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
  1232. wpa_s->keys_cleared = 0;
  1233. wpa_clear_keys(wpa_s, wpa_s->bssid);
  1234. }
  1235. wpa_supplicant_mark_disassoc(wpa_s);
  1236. if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1237. sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
  1238. }
  1239. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1240. static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
  1241. void *sock_ctx)
  1242. {
  1243. struct wpa_supplicant *wpa_s = eloop_ctx;
  1244. if (!wpa_s->pending_mic_error_report)
  1245. return;
  1246. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
  1247. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  1248. wpa_s->pending_mic_error_report = 0;
  1249. }
  1250. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1251. static void
  1252. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  1253. union wpa_event_data *data)
  1254. {
  1255. int pairwise;
  1256. struct os_time t;
  1257. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  1258. pairwise = (data && data->michael_mic_failure.unicast);
  1259. os_get_time(&t);
  1260. if ((wpa_s->last_michael_mic_error &&
  1261. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  1262. wpa_s->pending_mic_error_report) {
  1263. if (wpa_s->pending_mic_error_report) {
  1264. /*
  1265. * Send the pending MIC error report immediately since
  1266. * we are going to start countermeasures and AP better
  1267. * do the same.
  1268. */
  1269. wpa_sm_key_request(wpa_s->wpa, 1,
  1270. wpa_s->pending_mic_error_pairwise);
  1271. }
  1272. /* Send the new MIC error report immediately since we are going
  1273. * to start countermeasures and AP better do the same.
  1274. */
  1275. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1276. /* initialize countermeasures */
  1277. wpa_s->countermeasures = 1;
  1278. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  1279. /*
  1280. * Need to wait for completion of request frame. We do not get
  1281. * any callback for the message completion, so just wait a
  1282. * short while and hope for the best. */
  1283. os_sleep(0, 10000);
  1284. wpa_drv_set_countermeasures(wpa_s, 1);
  1285. wpa_supplicant_deauthenticate(wpa_s,
  1286. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1287. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  1288. wpa_s, NULL);
  1289. eloop_register_timeout(60, 0,
  1290. wpa_supplicant_stop_countermeasures,
  1291. wpa_s, NULL);
  1292. /* TODO: mark the AP rejected for 60 second. STA is
  1293. * allowed to associate with another AP.. */
  1294. } else {
  1295. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1296. if (wpa_s->mic_errors_seen) {
  1297. /*
  1298. * Reduce the effectiveness of Michael MIC error
  1299. * reports as a means for attacking against TKIP if
  1300. * more than one MIC failure is noticed with the same
  1301. * PTK. We delay the transmission of the reports by a
  1302. * random time between 0 and 60 seconds in order to
  1303. * force the attacker wait 60 seconds before getting
  1304. * the information on whether a frame resulted in a MIC
  1305. * failure.
  1306. */
  1307. u8 rval[4];
  1308. int sec;
  1309. if (os_get_random(rval, sizeof(rval)) < 0)
  1310. sec = os_random() % 60;
  1311. else
  1312. sec = WPA_GET_BE32(rval) % 60;
  1313. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
  1314. "report %d seconds", sec);
  1315. wpa_s->pending_mic_error_report = 1;
  1316. wpa_s->pending_mic_error_pairwise = pairwise;
  1317. eloop_cancel_timeout(
  1318. wpa_supplicant_delayed_mic_error_report,
  1319. wpa_s, NULL);
  1320. eloop_register_timeout(
  1321. sec, os_random() % 1000000,
  1322. wpa_supplicant_delayed_mic_error_report,
  1323. wpa_s, NULL);
  1324. } else {
  1325. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1326. }
  1327. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1328. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1329. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1330. }
  1331. wpa_s->last_michael_mic_error = t.sec;
  1332. wpa_s->mic_errors_seen++;
  1333. }
  1334. #ifdef CONFIG_TERMINATE_ONLASTIF
  1335. static int any_interfaces(struct wpa_supplicant *head)
  1336. {
  1337. struct wpa_supplicant *wpa_s;
  1338. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  1339. if (!wpa_s->interface_removed)
  1340. return 1;
  1341. return 0;
  1342. }
  1343. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1344. static void
  1345. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  1346. union wpa_event_data *data)
  1347. {
  1348. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  1349. return;
  1350. switch (data->interface_status.ievent) {
  1351. case EVENT_INTERFACE_ADDED:
  1352. if (!wpa_s->interface_removed)
  1353. break;
  1354. wpa_s->interface_removed = 0;
  1355. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
  1356. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  1357. wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
  1358. "driver after interface was added");
  1359. }
  1360. break;
  1361. case EVENT_INTERFACE_REMOVED:
  1362. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
  1363. wpa_s->interface_removed = 1;
  1364. wpa_supplicant_mark_disassoc(wpa_s);
  1365. l2_packet_deinit(wpa_s->l2);
  1366. wpa_s->l2 = NULL;
  1367. #ifdef CONFIG_IBSS_RSN
  1368. ibss_rsn_deinit(wpa_s->ibss_rsn);
  1369. wpa_s->ibss_rsn = NULL;
  1370. #endif /* CONFIG_IBSS_RSN */
  1371. #ifdef CONFIG_TERMINATE_ONLASTIF
  1372. /* check if last interface */
  1373. if (!any_interfaces(wpa_s->global->ifaces))
  1374. eloop_terminate();
  1375. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1376. break;
  1377. }
  1378. }
  1379. #ifdef CONFIG_PEERKEY
  1380. static void
  1381. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  1382. union wpa_event_data *data)
  1383. {
  1384. if (data == NULL)
  1385. return;
  1386. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  1387. }
  1388. #endif /* CONFIG_PEERKEY */
  1389. #ifdef CONFIG_TDLS
  1390. static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
  1391. union wpa_event_data *data)
  1392. {
  1393. if (data == NULL)
  1394. return;
  1395. switch (data->tdls.oper) {
  1396. case TDLS_REQUEST_SETUP:
  1397. wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
  1398. break;
  1399. case TDLS_REQUEST_TEARDOWN:
  1400. /* request from driver to add FTIE */
  1401. wpa_tdls_recv_teardown_notify(wpa_s->wpa, data->tdls.peer,
  1402. data->tdls.reason_code);
  1403. break;
  1404. }
  1405. }
  1406. #endif /* CONFIG_TDLS */
  1407. #ifdef CONFIG_IEEE80211R
  1408. static void
  1409. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  1410. union wpa_event_data *data)
  1411. {
  1412. if (data == NULL)
  1413. return;
  1414. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  1415. data->ft_ies.ies_len,
  1416. data->ft_ies.ft_action,
  1417. data->ft_ies.target_ap,
  1418. data->ft_ies.ric_ies,
  1419. data->ft_ies.ric_ies_len) < 0) {
  1420. /* TODO: prevent MLME/driver from trying to associate? */
  1421. }
  1422. }
  1423. #endif /* CONFIG_IEEE80211R */
  1424. #ifdef CONFIG_IBSS_RSN
  1425. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  1426. union wpa_event_data *data)
  1427. {
  1428. struct wpa_ssid *ssid;
  1429. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1430. return;
  1431. if (data == NULL)
  1432. return;
  1433. ssid = wpa_s->current_ssid;
  1434. if (ssid == NULL)
  1435. return;
  1436. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  1437. return;
  1438. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  1439. }
  1440. #endif /* CONFIG_IBSS_RSN */
  1441. #ifdef CONFIG_IEEE80211R
  1442. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  1443. size_t len)
  1444. {
  1445. const u8 *sta_addr, *target_ap_addr;
  1446. u16 status;
  1447. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  1448. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1449. return; /* only SME case supported for now */
  1450. if (len < 1 + 2 * ETH_ALEN + 2)
  1451. return;
  1452. if (data[0] != 2)
  1453. return; /* Only FT Action Response is supported for now */
  1454. sta_addr = data + 1;
  1455. target_ap_addr = data + 1 + ETH_ALEN;
  1456. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  1457. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
  1458. MACSTR " TargetAP " MACSTR " status %u",
  1459. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  1460. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  1461. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  1462. " in FT Action Response", MAC2STR(sta_addr));
  1463. return;
  1464. }
  1465. if (status) {
  1466. wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
  1467. "failure (status code %d)", status);
  1468. /* TODO: report error to FT code(?) */
  1469. return;
  1470. }
  1471. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  1472. len - (1 + 2 * ETH_ALEN + 2), 1,
  1473. target_ap_addr, NULL, 0) < 0)
  1474. return;
  1475. #ifdef CONFIG_SME
  1476. {
  1477. struct wpa_bss *bss;
  1478. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  1479. if (bss)
  1480. wpa_s->sme.freq = bss->freq;
  1481. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  1482. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  1483. WLAN_AUTH_FT);
  1484. }
  1485. #endif /* CONFIG_SME */
  1486. }
  1487. #endif /* CONFIG_IEEE80211R */
  1488. static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
  1489. struct unprot_deauth *e)
  1490. {
  1491. #ifdef CONFIG_IEEE80211W
  1492. wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
  1493. "dropped: " MACSTR " -> " MACSTR
  1494. " (reason code %u)",
  1495. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1496. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1497. #endif /* CONFIG_IEEE80211W */
  1498. }
  1499. static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
  1500. struct unprot_disassoc *e)
  1501. {
  1502. #ifdef CONFIG_IEEE80211W
  1503. wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
  1504. "dropped: " MACSTR " -> " MACSTR
  1505. " (reason code %u)",
  1506. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1507. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1508. #endif /* CONFIG_IEEE80211W */
  1509. }
  1510. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  1511. union wpa_event_data *data)
  1512. {
  1513. struct wpa_supplicant *wpa_s = ctx;
  1514. u16 reason_code = 0;
  1515. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  1516. event != EVENT_INTERFACE_ENABLED &&
  1517. event != EVENT_INTERFACE_STATUS) {
  1518. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore event %d while interface is "
  1519. "disabled", event);
  1520. return;
  1521. }
  1522. wpa_dbg(wpa_s, MSG_DEBUG, "Event %d received on interface %s",
  1523. event, wpa_s->ifname);
  1524. switch (event) {
  1525. case EVENT_AUTH:
  1526. sme_event_auth(wpa_s, data);
  1527. break;
  1528. case EVENT_ASSOC:
  1529. wpa_supplicant_event_assoc(wpa_s, data);
  1530. break;
  1531. case EVENT_DISASSOC:
  1532. wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
  1533. if (data) {
  1534. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
  1535. data->disassoc_info.reason_code);
  1536. if (data->disassoc_info.addr)
  1537. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  1538. MAC2STR(data->disassoc_info.addr));
  1539. }
  1540. #ifdef CONFIG_AP
  1541. if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
  1542. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1543. data->disassoc_info.addr);
  1544. break;
  1545. }
  1546. #endif /* CONFIG_AP */
  1547. if (data) {
  1548. reason_code = data->disassoc_info.reason_code;
  1549. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  1550. data->disassoc_info.ie,
  1551. data->disassoc_info.ie_len);
  1552. #ifdef CONFIG_P2P
  1553. wpas_p2p_disassoc_notif(
  1554. wpa_s, data->disassoc_info.addr, reason_code,
  1555. data->disassoc_info.ie,
  1556. data->disassoc_info.ie_len);
  1557. #endif /* CONFIG_P2P */
  1558. }
  1559. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1560. sme_event_disassoc(wpa_s, data);
  1561. /* fall through */
  1562. case EVENT_DEAUTH:
  1563. if (event == EVENT_DEAUTH) {
  1564. wpa_dbg(wpa_s, MSG_DEBUG,
  1565. "Deauthentication notification");
  1566. if (data) {
  1567. reason_code = data->deauth_info.reason_code;
  1568. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
  1569. data->deauth_info.reason_code);
  1570. if (data->deauth_info.addr) {
  1571. wpa_dbg(wpa_s, MSG_DEBUG, " * address "
  1572. MACSTR,
  1573. MAC2STR(data->deauth_info.
  1574. addr));
  1575. }
  1576. wpa_hexdump(MSG_DEBUG,
  1577. "Deauthentication frame IE(s)",
  1578. data->deauth_info.ie,
  1579. data->deauth_info.ie_len);
  1580. #ifdef CONFIG_P2P
  1581. wpas_p2p_deauth_notif(
  1582. wpa_s, data->deauth_info.addr,
  1583. reason_code,
  1584. data->deauth_info.ie,
  1585. data->deauth_info.ie_len);
  1586. #endif /* CONFIG_P2P */
  1587. }
  1588. }
  1589. #ifdef CONFIG_AP
  1590. if (wpa_s->ap_iface && data && data->deauth_info.addr) {
  1591. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1592. data->deauth_info.addr);
  1593. break;
  1594. }
  1595. #endif /* CONFIG_AP */
  1596. wpa_supplicant_event_disassoc(wpa_s, reason_code);
  1597. break;
  1598. case EVENT_MICHAEL_MIC_FAILURE:
  1599. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  1600. break;
  1601. #ifndef CONFIG_NO_SCAN_PROCESSING
  1602. case EVENT_SCAN_RESULTS:
  1603. wpa_supplicant_event_scan_results(wpa_s, data);
  1604. break;
  1605. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1606. case EVENT_ASSOCINFO:
  1607. wpa_supplicant_event_associnfo(wpa_s, data);
  1608. break;
  1609. case EVENT_INTERFACE_STATUS:
  1610. wpa_supplicant_event_interface_status(wpa_s, data);
  1611. break;
  1612. case EVENT_PMKID_CANDIDATE:
  1613. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  1614. break;
  1615. #ifdef CONFIG_PEERKEY
  1616. case EVENT_STKSTART:
  1617. wpa_supplicant_event_stkstart(wpa_s, data);
  1618. break;
  1619. #endif /* CONFIG_PEERKEY */
  1620. #ifdef CONFIG_TDLS
  1621. case EVENT_TDLS:
  1622. wpa_supplicant_event_tdls(wpa_s, data);
  1623. break;
  1624. #endif /* CONFIG_TDLS */
  1625. #ifdef CONFIG_IEEE80211R
  1626. case EVENT_FT_RESPONSE:
  1627. wpa_supplicant_event_ft_response(wpa_s, data);
  1628. break;
  1629. #endif /* CONFIG_IEEE80211R */
  1630. #ifdef CONFIG_IBSS_RSN
  1631. case EVENT_IBSS_RSN_START:
  1632. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  1633. break;
  1634. #endif /* CONFIG_IBSS_RSN */
  1635. case EVENT_ASSOC_REJECT:
  1636. if (data->assoc_reject.bssid)
  1637. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  1638. "bssid=" MACSTR " status_code=%u",
  1639. MAC2STR(data->assoc_reject.bssid),
  1640. data->assoc_reject.status_code);
  1641. else
  1642. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  1643. "status_code=%u",
  1644. data->assoc_reject.status_code);
  1645. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1646. sme_event_assoc_reject(wpa_s, data);
  1647. break;
  1648. case EVENT_AUTH_TIMED_OUT:
  1649. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1650. sme_event_auth_timed_out(wpa_s, data);
  1651. break;
  1652. case EVENT_ASSOC_TIMED_OUT:
  1653. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1654. sme_event_assoc_timed_out(wpa_s, data);
  1655. break;
  1656. #ifdef CONFIG_AP
  1657. case EVENT_TX_STATUS:
  1658. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
  1659. " type=%d stype=%d",
  1660. MAC2STR(data->tx_status.dst),
  1661. data->tx_status.type, data->tx_status.stype);
  1662. if (wpa_s->ap_iface == NULL) {
  1663. #ifdef CONFIG_P2P
  1664. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1665. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  1666. wpas_send_action_tx_status(
  1667. wpa_s, data->tx_status.dst,
  1668. data->tx_status.data,
  1669. data->tx_status.data_len,
  1670. data->tx_status.ack ?
  1671. P2P_SEND_ACTION_SUCCESS :
  1672. P2P_SEND_ACTION_NO_ACK);
  1673. #endif /* CONFIG_P2P */
  1674. break;
  1675. }
  1676. #ifdef CONFIG_P2P
  1677. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
  1678. MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
  1679. /*
  1680. * Catch TX status events for Action frames we sent via group
  1681. * interface in GO mode.
  1682. */
  1683. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1684. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  1685. os_memcmp(wpa_s->parent->pending_action_dst,
  1686. data->tx_status.dst, ETH_ALEN) == 0) {
  1687. wpas_send_action_tx_status(
  1688. wpa_s->parent, data->tx_status.dst,
  1689. data->tx_status.data,
  1690. data->tx_status.data_len,
  1691. data->tx_status.ack ?
  1692. P2P_SEND_ACTION_SUCCESS :
  1693. P2P_SEND_ACTION_NO_ACK);
  1694. break;
  1695. }
  1696. #endif /* CONFIG_P2P */
  1697. switch (data->tx_status.type) {
  1698. case WLAN_FC_TYPE_MGMT:
  1699. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  1700. data->tx_status.data_len,
  1701. data->tx_status.stype,
  1702. data->tx_status.ack);
  1703. break;
  1704. case WLAN_FC_TYPE_DATA:
  1705. ap_tx_status(wpa_s, data->tx_status.dst,
  1706. data->tx_status.data,
  1707. data->tx_status.data_len,
  1708. data->tx_status.ack);
  1709. break;
  1710. }
  1711. break;
  1712. case EVENT_RX_FROM_UNKNOWN:
  1713. if (wpa_s->ap_iface == NULL)
  1714. break;
  1715. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
  1716. data->rx_from_unknown.len);
  1717. break;
  1718. case EVENT_RX_MGMT:
  1719. if (wpa_s->ap_iface == NULL) {
  1720. #ifdef CONFIG_P2P
  1721. u16 fc, stype;
  1722. const struct ieee80211_mgmt *mgmt;
  1723. mgmt = (const struct ieee80211_mgmt *)
  1724. data->rx_mgmt.frame;
  1725. fc = le_to_host16(mgmt->frame_control);
  1726. stype = WLAN_FC_GET_STYPE(fc);
  1727. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  1728. data->rx_mgmt.frame_len > 24) {
  1729. const u8 *src = mgmt->sa;
  1730. const u8 *ie = mgmt->u.probe_req.variable;
  1731. size_t ie_len = data->rx_mgmt.frame_len -
  1732. (mgmt->u.probe_req.variable -
  1733. data->rx_mgmt.frame);
  1734. wpas_p2p_probe_req_rx(wpa_s, src, ie, ie_len);
  1735. break;
  1736. }
  1737. #endif /* CONFIG_P2P */
  1738. wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
  1739. "management frame in non-AP mode");
  1740. break;
  1741. }
  1742. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  1743. break;
  1744. #endif /* CONFIG_AP */
  1745. case EVENT_RX_ACTION:
  1746. wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
  1747. " Category=%u DataLen=%d freq=%d MHz",
  1748. MAC2STR(data->rx_action.sa),
  1749. data->rx_action.category, (int) data->rx_action.len,
  1750. data->rx_action.freq);
  1751. #ifdef CONFIG_IEEE80211R
  1752. if (data->rx_action.category == WLAN_ACTION_FT) {
  1753. ft_rx_action(wpa_s, data->rx_action.data,
  1754. data->rx_action.len);
  1755. break;
  1756. }
  1757. #endif /* CONFIG_IEEE80211R */
  1758. #ifdef CONFIG_IEEE80211W
  1759. #ifdef CONFIG_SME
  1760. if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
  1761. sme_sa_query_rx(wpa_s, data->rx_action.sa,
  1762. data->rx_action.data,
  1763. data->rx_action.len);
  1764. break;
  1765. }
  1766. #endif /* CONFIG_SME */
  1767. #endif /* CONFIG_IEEE80211W */
  1768. #ifdef CONFIG_P2P
  1769. wpas_p2p_rx_action(wpa_s, data->rx_action.da,
  1770. data->rx_action.sa,
  1771. data->rx_action.bssid,
  1772. data->rx_action.category,
  1773. data->rx_action.data,
  1774. data->rx_action.len, data->rx_action.freq);
  1775. #endif /* CONFIG_P2P */
  1776. break;
  1777. case EVENT_RX_PROBE_REQ:
  1778. if (data->rx_probe_req.sa == NULL ||
  1779. data->rx_probe_req.ie == NULL)
  1780. break;
  1781. #ifdef CONFIG_AP
  1782. if (wpa_s->ap_iface) {
  1783. hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
  1784. data->rx_probe_req.sa,
  1785. data->rx_probe_req.ie,
  1786. data->rx_probe_req.ie_len);
  1787. break;
  1788. }
  1789. #endif /* CONFIG_AP */
  1790. #ifdef CONFIG_P2P
  1791. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  1792. data->rx_probe_req.ie,
  1793. data->rx_probe_req.ie_len);
  1794. #endif /* CONFIG_P2P */
  1795. break;
  1796. #ifdef CONFIG_P2P
  1797. case EVENT_REMAIN_ON_CHANNEL:
  1798. wpas_p2p_remain_on_channel_cb(
  1799. wpa_s, data->remain_on_channel.freq,
  1800. data->remain_on_channel.duration);
  1801. break;
  1802. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  1803. wpas_p2p_cancel_remain_on_channel_cb(
  1804. wpa_s, data->remain_on_channel.freq);
  1805. break;
  1806. case EVENT_P2P_DEV_FOUND: {
  1807. struct p2p_peer_info peer_info;
  1808. os_memset(&peer_info, 0, sizeof(peer_info));
  1809. if (data->p2p_dev_found.dev_addr)
  1810. os_memcpy(peer_info.p2p_device_addr,
  1811. data->p2p_dev_found.dev_addr, ETH_ALEN);
  1812. if (data->p2p_dev_found.pri_dev_type)
  1813. os_memcpy(peer_info.pri_dev_type,
  1814. data->p2p_dev_found.pri_dev_type,
  1815. sizeof(peer_info.pri_dev_type));
  1816. if (data->p2p_dev_found.dev_name)
  1817. os_strlcpy(peer_info.device_name,
  1818. data->p2p_dev_found.dev_name,
  1819. sizeof(peer_info.device_name));
  1820. peer_info.config_methods = data->p2p_dev_found.config_methods;
  1821. peer_info.dev_capab = data->p2p_dev_found.dev_capab;
  1822. peer_info.group_capab = data->p2p_dev_found.group_capab;
  1823. /*
  1824. * FIX: new_device=1 is not necessarily correct. We should
  1825. * maintain a P2P peer database in wpa_supplicant and update
  1826. * this information based on whether the peer is truly new.
  1827. */
  1828. wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
  1829. break;
  1830. }
  1831. case EVENT_P2P_GO_NEG_REQ_RX:
  1832. wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
  1833. data->p2p_go_neg_req_rx.dev_passwd_id);
  1834. break;
  1835. case EVENT_P2P_GO_NEG_COMPLETED:
  1836. wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
  1837. break;
  1838. case EVENT_P2P_PROV_DISC_REQUEST:
  1839. wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
  1840. data->p2p_prov_disc_req.config_methods,
  1841. data->p2p_prov_disc_req.dev_addr,
  1842. data->p2p_prov_disc_req.pri_dev_type,
  1843. data->p2p_prov_disc_req.dev_name,
  1844. data->p2p_prov_disc_req.supp_config_methods,
  1845. data->p2p_prov_disc_req.dev_capab,
  1846. data->p2p_prov_disc_req.group_capab);
  1847. break;
  1848. case EVENT_P2P_PROV_DISC_RESPONSE:
  1849. wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
  1850. data->p2p_prov_disc_resp.config_methods);
  1851. break;
  1852. case EVENT_P2P_SD_REQUEST:
  1853. wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
  1854. data->p2p_sd_req.sa,
  1855. data->p2p_sd_req.dialog_token,
  1856. data->p2p_sd_req.update_indic,
  1857. data->p2p_sd_req.tlvs,
  1858. data->p2p_sd_req.tlvs_len);
  1859. break;
  1860. case EVENT_P2P_SD_RESPONSE:
  1861. wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
  1862. data->p2p_sd_resp.update_indic,
  1863. data->p2p_sd_resp.tlvs,
  1864. data->p2p_sd_resp.tlvs_len);
  1865. break;
  1866. #endif /* CONFIG_P2P */
  1867. #ifdef CONFIG_CLIENT_MLME
  1868. case EVENT_MLME_RX: {
  1869. struct ieee80211_rx_status rx_status;
  1870. os_memset(&rx_status, 0, sizeof(rx_status));
  1871. rx_status.freq = data->mlme_rx.freq;
  1872. rx_status.channel = data->mlme_rx.channel;
  1873. rx_status.ssi = data->mlme_rx.ssi;
  1874. ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
  1875. &rx_status);
  1876. break;
  1877. }
  1878. #endif /* CONFIG_CLIENT_MLME */
  1879. case EVENT_EAPOL_RX:
  1880. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  1881. data->eapol_rx.data,
  1882. data->eapol_rx.data_len);
  1883. break;
  1884. case EVENT_SIGNAL_CHANGE:
  1885. bgscan_notify_signal_change(
  1886. wpa_s, data->signal_change.above_threshold,
  1887. data->signal_change.current_signal,
  1888. data->signal_change.current_noise,
  1889. data->signal_change.current_txrate);
  1890. break;
  1891. case EVENT_INTERFACE_ENABLED:
  1892. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
  1893. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  1894. #ifdef CONFIG_AP
  1895. if (!wpa_s->ap_iface) {
  1896. wpa_supplicant_set_state(wpa_s,
  1897. WPA_DISCONNECTED);
  1898. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1899. } else
  1900. wpa_supplicant_set_state(wpa_s,
  1901. WPA_COMPLETED);
  1902. #else /* CONFIG_AP */
  1903. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1904. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1905. #endif /* CONFIG_AP */
  1906. }
  1907. break;
  1908. case EVENT_INTERFACE_DISABLED:
  1909. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
  1910. wpa_supplicant_mark_disassoc(wpa_s);
  1911. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  1912. break;
  1913. case EVENT_CHANNEL_LIST_CHANGED:
  1914. if (wpa_s->drv_priv == NULL)
  1915. break; /* Ignore event during drv initialization */
  1916. #ifdef CONFIG_P2P
  1917. wpas_p2p_update_channel_list(wpa_s);
  1918. #endif /* CONFIG_P2P */
  1919. break;
  1920. case EVENT_INTERFACE_UNAVAILABLE:
  1921. #ifdef CONFIG_P2P
  1922. wpas_p2p_interface_unavailable(wpa_s);
  1923. #endif /* CONFIG_P2P */
  1924. break;
  1925. case EVENT_BEST_CHANNEL:
  1926. wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
  1927. "(%d %d %d)",
  1928. data->best_chan.freq_24, data->best_chan.freq_5,
  1929. data->best_chan.freq_overall);
  1930. wpa_s->best_24_freq = data->best_chan.freq_24;
  1931. wpa_s->best_5_freq = data->best_chan.freq_5;
  1932. wpa_s->best_overall_freq = data->best_chan.freq_overall;
  1933. #ifdef CONFIG_P2P
  1934. wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
  1935. data->best_chan.freq_5,
  1936. data->best_chan.freq_overall);
  1937. #endif /* CONFIG_P2P */
  1938. break;
  1939. case EVENT_UNPROT_DEAUTH:
  1940. wpa_supplicant_event_unprot_deauth(wpa_s,
  1941. &data->unprot_deauth);
  1942. break;
  1943. case EVENT_UNPROT_DISASSOC:
  1944. wpa_supplicant_event_unprot_disassoc(wpa_s,
  1945. &data->unprot_disassoc);
  1946. break;
  1947. case EVENT_STATION_LOW_ACK:
  1948. #ifdef CONFIG_AP
  1949. if (wpa_s->ap_iface && data)
  1950. hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
  1951. data->low_ack.addr);
  1952. #endif /* CONFIG_AP */
  1953. break;
  1954. case EVENT_IBSS_PEER_LOST:
  1955. #ifdef CONFIG_IBSS_RSN
  1956. ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
  1957. #endif /* CONFIG_IBSS_RSN */
  1958. break;
  1959. default:
  1960. wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
  1961. break;
  1962. }
  1963. }