events.c 52 KB

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