events.c 63 KB

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