events.c 50 KB

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