events.c 49 KB

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