events.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  1. /*
  2. * WPA Supplicant - Driver event processing
  3. * Copyright (c) 2003-2008, 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 "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 "preauth.h"
  25. #include "pmksa_cache.h"
  26. #include "wpa_ctrl.h"
  27. #include "eap_peer/eap.h"
  28. #include "ctrl_iface_dbus.h"
  29. #include "ieee802_11_defs.h"
  30. #include "blacklist.h"
  31. #include "wpas_glue.h"
  32. #include "wps_supplicant.h"
  33. #include "ibss_rsn.h"
  34. #include "sme.h"
  35. static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
  36. {
  37. struct wpa_ssid *ssid;
  38. if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
  39. return 0;
  40. wpa_printf(MSG_DEBUG, "Select network based on association "
  41. "information");
  42. ssid = wpa_supplicant_get_ssid(wpa_s);
  43. if (ssid == NULL) {
  44. wpa_printf(MSG_INFO, "No network configuration found for the "
  45. "current AP");
  46. return -1;
  47. }
  48. if (ssid->disabled) {
  49. wpa_printf(MSG_DEBUG, "Selected network is disabled");
  50. return -1;
  51. }
  52. wpa_printf(MSG_DEBUG, "Network configuration found for the current "
  53. "AP");
  54. if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
  55. WPA_KEY_MGMT_WPA_NONE |
  56. WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X |
  57. WPA_KEY_MGMT_PSK_SHA256 |
  58. WPA_KEY_MGMT_IEEE8021X_SHA256)) {
  59. u8 wpa_ie[80];
  60. size_t wpa_ie_len = sizeof(wpa_ie);
  61. wpa_supplicant_set_suites(wpa_s, NULL, ssid,
  62. wpa_ie, &wpa_ie_len);
  63. } else {
  64. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  65. }
  66. if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
  67. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  68. wpa_s->current_ssid = ssid;
  69. wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
  70. wpa_supplicant_initiate_eapol(wpa_s);
  71. return 0;
  72. }
  73. static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
  74. void *sock_ctx)
  75. {
  76. struct wpa_supplicant *wpa_s = eloop_ctx;
  77. if (wpa_s->countermeasures) {
  78. wpa_s->countermeasures = 0;
  79. wpa_drv_set_countermeasures(wpa_s, 0);
  80. wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
  81. wpa_supplicant_req_scan(wpa_s, 0, 0);
  82. }
  83. }
  84. void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
  85. {
  86. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  87. os_memset(wpa_s->bssid, 0, ETH_ALEN);
  88. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  89. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  90. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  91. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  92. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  93. wpa_s->ap_ies_from_associnfo = 0;
  94. }
  95. static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
  96. {
  97. struct wpa_ie_data ie;
  98. int pmksa_set = -1;
  99. size_t i;
  100. if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
  101. ie.pmkid == NULL)
  102. return;
  103. for (i = 0; i < ie.num_pmkid; i++) {
  104. pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
  105. ie.pmkid + i * PMKID_LEN,
  106. NULL, NULL, 0);
  107. if (pmksa_set == 0) {
  108. eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
  109. break;
  110. }
  111. }
  112. wpa_printf(MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from PMKSA "
  113. "cache", pmksa_set == 0 ? "" : "not ");
  114. }
  115. static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
  116. union wpa_event_data *data)
  117. {
  118. if (data == NULL) {
  119. wpa_printf(MSG_DEBUG, "RSN: No data in PMKID candidate event");
  120. return;
  121. }
  122. wpa_printf(MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
  123. " index=%d preauth=%d",
  124. MAC2STR(data->pmkid_candidate.bssid),
  125. data->pmkid_candidate.index,
  126. data->pmkid_candidate.preauth);
  127. pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
  128. data->pmkid_candidate.index,
  129. data->pmkid_candidate.preauth);
  130. }
  131. static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
  132. {
  133. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  134. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
  135. return 0;
  136. #ifdef IEEE8021X_EAPOL
  137. if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
  138. wpa_s->current_ssid &&
  139. !(wpa_s->current_ssid->eapol_flags &
  140. (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  141. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
  142. /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
  143. * plaintext or static WEP keys). */
  144. return 0;
  145. }
  146. #endif /* IEEE8021X_EAPOL */
  147. return 1;
  148. }
  149. /**
  150. * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
  151. * @wpa_s: pointer to wpa_supplicant data
  152. * @ssid: Configuration data for the network
  153. * Returns: 0 on success, -1 on failure
  154. *
  155. * This function is called when starting authentication with a network that is
  156. * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
  157. */
  158. int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
  159. struct wpa_ssid *ssid)
  160. {
  161. #ifdef IEEE8021X_EAPOL
  162. int aka = 0, sim = 0, type;
  163. if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
  164. return 0;
  165. if (ssid->eap.eap_methods == NULL) {
  166. sim = 1;
  167. aka = 1;
  168. } else {
  169. struct eap_method_type *eap = ssid->eap.eap_methods;
  170. while (eap->vendor != EAP_VENDOR_IETF ||
  171. eap->method != EAP_TYPE_NONE) {
  172. if (eap->vendor == EAP_VENDOR_IETF) {
  173. if (eap->method == EAP_TYPE_SIM)
  174. sim = 1;
  175. else if (eap->method == EAP_TYPE_AKA)
  176. aka = 1;
  177. }
  178. eap++;
  179. }
  180. }
  181. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
  182. sim = 0;
  183. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
  184. aka = 0;
  185. if (!sim && !aka) {
  186. wpa_printf(MSG_DEBUG, "Selected network is configured to use "
  187. "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
  188. return 0;
  189. }
  190. wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM "
  191. "(sim=%d aka=%d) - initialize PCSC", sim, aka);
  192. if (sim && aka)
  193. type = SCARD_TRY_BOTH;
  194. else if (aka)
  195. type = SCARD_USIM_ONLY;
  196. else
  197. type = SCARD_GSM_SIM_ONLY;
  198. wpa_s->scard = scard_init(type);
  199. if (wpa_s->scard == NULL) {
  200. wpa_printf(MSG_WARNING, "Failed to initialize SIM "
  201. "(pcsc-lite)");
  202. return -1;
  203. }
  204. wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
  205. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  206. #endif /* IEEE8021X_EAPOL */
  207. return 0;
  208. }
  209. #ifndef CONFIG_NO_SCAN_PROCESSING
  210. static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
  211. struct wpa_ssid *ssid)
  212. {
  213. int i, privacy = 0;
  214. if (ssid->mixed_cell)
  215. return 1;
  216. #ifdef CONFIG_WPS
  217. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
  218. return 1;
  219. #endif /* CONFIG_WPS */
  220. for (i = 0; i < NUM_WEP_KEYS; i++) {
  221. if (ssid->wep_key_len[i]) {
  222. privacy = 1;
  223. break;
  224. }
  225. }
  226. #ifdef IEEE8021X_EAPOL
  227. if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  228. ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  229. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
  230. privacy = 1;
  231. #endif /* IEEE8021X_EAPOL */
  232. if (bss->caps & IEEE80211_CAP_PRIVACY)
  233. return privacy;
  234. return !privacy;
  235. }
  236. static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
  237. struct wpa_ssid *ssid,
  238. struct wpa_scan_res *bss)
  239. {
  240. struct wpa_ie_data ie;
  241. int proto_match = 0;
  242. const u8 *rsn_ie, *wpa_ie;
  243. int ret;
  244. ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
  245. if (ret >= 0)
  246. return ret;
  247. rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  248. while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
  249. proto_match++;
  250. if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
  251. wpa_printf(MSG_DEBUG, " skip RSN IE - parse failed");
  252. break;
  253. }
  254. if (!(ie.proto & ssid->proto)) {
  255. wpa_printf(MSG_DEBUG, " skip RSN IE - proto "
  256. "mismatch");
  257. break;
  258. }
  259. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  260. wpa_printf(MSG_DEBUG, " skip RSN IE - PTK cipher "
  261. "mismatch");
  262. break;
  263. }
  264. if (!(ie.group_cipher & ssid->group_cipher)) {
  265. wpa_printf(MSG_DEBUG, " skip RSN IE - GTK cipher "
  266. "mismatch");
  267. break;
  268. }
  269. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  270. wpa_printf(MSG_DEBUG, " skip RSN IE - key mgmt "
  271. "mismatch");
  272. break;
  273. }
  274. #ifdef CONFIG_IEEE80211W
  275. if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
  276. ssid->ieee80211w == IEEE80211W_REQUIRED) {
  277. wpa_printf(MSG_DEBUG, " skip RSN IE - no mgmt frame "
  278. "protection");
  279. break;
  280. }
  281. #endif /* CONFIG_IEEE80211W */
  282. wpa_printf(MSG_DEBUG, " selected based on RSN IE");
  283. return 1;
  284. }
  285. wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  286. while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
  287. proto_match++;
  288. if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
  289. wpa_printf(MSG_DEBUG, " skip WPA IE - parse failed");
  290. break;
  291. }
  292. if (!(ie.proto & ssid->proto)) {
  293. wpa_printf(MSG_DEBUG, " skip WPA IE - proto "
  294. "mismatch");
  295. break;
  296. }
  297. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  298. wpa_printf(MSG_DEBUG, " skip WPA IE - PTK cipher "
  299. "mismatch");
  300. break;
  301. }
  302. if (!(ie.group_cipher & ssid->group_cipher)) {
  303. wpa_printf(MSG_DEBUG, " skip WPA IE - GTK cipher "
  304. "mismatch");
  305. break;
  306. }
  307. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  308. wpa_printf(MSG_DEBUG, " skip WPA IE - key mgmt "
  309. "mismatch");
  310. break;
  311. }
  312. wpa_printf(MSG_DEBUG, " selected based on WPA IE");
  313. return 1;
  314. }
  315. if (proto_match == 0)
  316. wpa_printf(MSG_DEBUG, " skip - no WPA/RSN proto match");
  317. return 0;
  318. }
  319. static struct wpa_scan_res *
  320. wpa_supplicant_select_bss_wpa(struct wpa_supplicant *wpa_s,
  321. struct wpa_ssid *group,
  322. struct wpa_ssid **selected_ssid)
  323. {
  324. struct wpa_ssid *ssid;
  325. struct wpa_scan_res *bss;
  326. size_t i;
  327. struct wpa_blacklist *e;
  328. const u8 *ie;
  329. wpa_printf(MSG_DEBUG, "Try to find WPA-enabled AP");
  330. for (i = 0; i < wpa_s->scan_res->num; i++) {
  331. const u8 *ssid_;
  332. u8 wpa_ie_len, rsn_ie_len, ssid_len;
  333. bss = wpa_s->scan_res->res[i];
  334. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  335. ssid_ = ie ? ie + 2 : (u8 *) "";
  336. ssid_len = ie ? ie[1] : 0;
  337. ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  338. wpa_ie_len = ie ? ie[1] : 0;
  339. ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  340. rsn_ie_len = ie ? ie[1] : 0;
  341. wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
  342. "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
  343. (int) i, MAC2STR(bss->bssid),
  344. wpa_ssid_txt(ssid_, ssid_len),
  345. wpa_ie_len, rsn_ie_len, bss->caps);
  346. e = wpa_blacklist_get(wpa_s, bss->bssid);
  347. if (e && e->count > 1) {
  348. wpa_printf(MSG_DEBUG, " skip - blacklisted");
  349. continue;
  350. }
  351. if (wpa_ie_len == 0 && rsn_ie_len == 0) {
  352. wpa_printf(MSG_DEBUG, " skip - no WPA/RSN IE");
  353. continue;
  354. }
  355. for (ssid = group; ssid; ssid = ssid->pnext) {
  356. int check_ssid = 1;
  357. if (ssid->disabled) {
  358. wpa_printf(MSG_DEBUG, " skip - disabled");
  359. continue;
  360. }
  361. #ifdef CONFIG_WPS
  362. if (ssid->ssid_len == 0 &&
  363. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  364. check_ssid = 0;
  365. #endif /* CONFIG_WPS */
  366. if (check_ssid &&
  367. (ssid_len != ssid->ssid_len ||
  368. os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
  369. wpa_printf(MSG_DEBUG, " skip - "
  370. "SSID mismatch");
  371. continue;
  372. }
  373. if (ssid->bssid_set &&
  374. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
  375. {
  376. wpa_printf(MSG_DEBUG, " skip - "
  377. "BSSID mismatch");
  378. continue;
  379. }
  380. if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
  381. continue;
  382. wpa_printf(MSG_DEBUG, " selected WPA AP "
  383. MACSTR " ssid='%s'",
  384. MAC2STR(bss->bssid),
  385. wpa_ssid_txt(ssid_, ssid_len));
  386. *selected_ssid = ssid;
  387. return bss;
  388. }
  389. }
  390. return NULL;
  391. }
  392. static struct wpa_scan_res *
  393. wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant *wpa_s,
  394. struct wpa_ssid *group,
  395. struct wpa_ssid **selected_ssid)
  396. {
  397. struct wpa_ssid *ssid;
  398. struct wpa_scan_res *bss;
  399. size_t i;
  400. struct wpa_blacklist *e;
  401. const u8 *ie;
  402. wpa_printf(MSG_DEBUG, "Try to find non-WPA AP");
  403. for (i = 0; i < wpa_s->scan_res->num; i++) {
  404. const u8 *ssid_;
  405. u8 wpa_ie_len, rsn_ie_len, ssid_len;
  406. bss = wpa_s->scan_res->res[i];
  407. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  408. ssid_ = ie ? ie + 2 : (u8 *) "";
  409. ssid_len = ie ? ie[1] : 0;
  410. ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  411. wpa_ie_len = ie ? ie[1] : 0;
  412. ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  413. rsn_ie_len = ie ? ie[1] : 0;
  414. wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
  415. "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
  416. (int) i, MAC2STR(bss->bssid),
  417. wpa_ssid_txt(ssid_, ssid_len),
  418. wpa_ie_len, rsn_ie_len, bss->caps);
  419. e = wpa_blacklist_get(wpa_s, bss->bssid);
  420. if (e && e->count > 1) {
  421. wpa_printf(MSG_DEBUG, " skip - blacklisted");
  422. continue;
  423. }
  424. for (ssid = group; ssid; ssid = ssid->pnext) {
  425. int check_ssid = ssid->ssid_len != 0;
  426. if (ssid->disabled) {
  427. wpa_printf(MSG_DEBUG, " skip - disabled");
  428. continue;
  429. }
  430. #ifdef CONFIG_WPS
  431. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
  432. /* Only allow wildcard SSID match if an AP
  433. * advertises active WPS operation that matches
  434. * with our mode. */
  435. check_ssid = 1;
  436. if (ssid->ssid_len == 0 &&
  437. wpas_wps_ssid_wildcard_ok(wpa_s, ssid,
  438. 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 - "
  446. "SSID mismatch");
  447. continue;
  448. }
  449. if (ssid->bssid_set &&
  450. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
  451. {
  452. wpa_printf(MSG_DEBUG, " skip - "
  453. "BSSID mismatch");
  454. continue;
  455. }
  456. if (!(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. {
  460. wpa_printf(MSG_DEBUG, " skip - "
  461. "non-WPA network not allowed");
  462. continue;
  463. }
  464. if ((ssid->key_mgmt &
  465. (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK |
  466. WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK |
  467. WPA_KEY_MGMT_IEEE8021X_SHA256 |
  468. WPA_KEY_MGMT_PSK_SHA256)) &&
  469. (wpa_ie_len != 0 || rsn_ie_len != 0)) {
  470. wpa_printf(MSG_DEBUG, " skip - "
  471. "WPA network");
  472. continue;
  473. }
  474. if (!wpa_supplicant_match_privacy(bss, ssid)) {
  475. wpa_printf(MSG_DEBUG, " skip - "
  476. "privacy mismatch");
  477. continue;
  478. }
  479. if (bss->caps & IEEE80211_CAP_IBSS) {
  480. wpa_printf(MSG_DEBUG, " skip - "
  481. "IBSS (adhoc) network");
  482. continue;
  483. }
  484. wpa_printf(MSG_DEBUG, " selected non-WPA AP "
  485. MACSTR " ssid='%s'",
  486. MAC2STR(bss->bssid),
  487. wpa_ssid_txt(ssid_, ssid_len));
  488. *selected_ssid = ssid;
  489. return bss;
  490. }
  491. }
  492. return NULL;
  493. }
  494. static struct wpa_scan_res *
  495. wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, struct wpa_ssid *group,
  496. struct wpa_ssid **selected_ssid)
  497. {
  498. struct wpa_scan_res *selected;
  499. wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d",
  500. group->priority);
  501. /* First, try to find WPA-enabled AP */
  502. selected = wpa_supplicant_select_bss_wpa(wpa_s, group, selected_ssid);
  503. if (selected)
  504. return selected;
  505. /* If no WPA-enabled AP found, try to find non-WPA AP, if configuration
  506. * allows this. */
  507. return wpa_supplicant_select_bss_non_wpa(wpa_s, group, selected_ssid);
  508. }
  509. static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s)
  510. {
  511. int prio, timeout;
  512. struct wpa_scan_res *selected = NULL;
  513. struct wpa_ssid *ssid = NULL;
  514. wpa_supplicant_notify_scanning(wpa_s, 0);
  515. if (wpa_supplicant_get_scan_results(wpa_s) < 0) {
  516. if (wpa_s->conf->ap_scan == 2)
  517. return;
  518. wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
  519. "scanning again");
  520. timeout = 1;
  521. goto req_scan;
  522. }
  523. /*
  524. * Don't post the results if this was the initial cached
  525. * and there were no results.
  526. */
  527. if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1 &&
  528. wpa_s->scan_res->num == 0) {
  529. wpa_msg(wpa_s, MSG_DEBUG, "Cached scan results are "
  530. "empty - not posting");
  531. } else {
  532. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  533. wpa_supplicant_dbus_notify_scan_results(wpa_s);
  534. wpas_wps_notify_scan_results(wpa_s);
  535. }
  536. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)) ||
  537. wpa_s->disconnected)
  538. return;
  539. while (selected == NULL) {
  540. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  541. selected = wpa_supplicant_select_bss(
  542. wpa_s, wpa_s->conf->pssid[prio], &ssid);
  543. if (selected)
  544. break;
  545. }
  546. if (selected == NULL && wpa_s->blacklist) {
  547. wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
  548. "and try again");
  549. wpa_blacklist_clear(wpa_s);
  550. wpa_s->blacklist_cleared++;
  551. } else if (selected == NULL) {
  552. break;
  553. }
  554. }
  555. if (selected) {
  556. if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
  557. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
  558. "PBC session overlap");
  559. timeout = 10;
  560. goto req_scan;
  561. }
  562. /* Do not trigger new association unless the BSSID has changed
  563. * or if reassociation is requested. If we are in process of
  564. * associating with the selected BSSID, do not trigger new
  565. * attempt. */
  566. if (wpa_s->reassociate ||
  567. (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
  568. (wpa_s->wpa_state != WPA_ASSOCIATING ||
  569. os_memcmp(selected->bssid, wpa_s->pending_bssid,
  570. ETH_ALEN) != 0))) {
  571. if (wpa_supplicant_scard_init(wpa_s, ssid)) {
  572. wpa_supplicant_req_scan(wpa_s, 10, 0);
  573. return;
  574. }
  575. wpa_supplicant_associate(wpa_s, selected, ssid);
  576. } else {
  577. wpa_printf(MSG_DEBUG, "Already associated with the "
  578. "selected AP.");
  579. }
  580. rsn_preauth_scan_results(wpa_s->wpa, wpa_s->scan_res);
  581. } else {
  582. wpa_printf(MSG_DEBUG, "No suitable AP found.");
  583. timeout = 5;
  584. goto req_scan;
  585. }
  586. return;
  587. req_scan:
  588. if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1) {
  589. /*
  590. * Quick recovery if the initial scan results were not
  591. * complete when fetched before the first scan request.
  592. */
  593. wpa_s->scan_res_tried++;
  594. timeout = 0;
  595. }
  596. wpa_supplicant_req_scan(wpa_s, timeout, 0);
  597. }
  598. #endif /* CONFIG_NO_SCAN_PROCESSING */
  599. #ifdef CONFIG_IEEE80211R
  600. static void wpa_assoc_set_ft_params(struct wpa_supplicant *wpa_s,
  601. const u8 *ftie, const u8 *mdie)
  602. {
  603. const u8 *mobility_domain = NULL;
  604. const u8 *r0kh_id = NULL;
  605. size_t r0kh_id_len = 0;
  606. const u8 *r1kh_id = NULL;
  607. struct rsn_ftie *hdr;
  608. const u8 *pos, *end;
  609. if (mdie == NULL || ftie == NULL)
  610. return;
  611. if (mdie[1] >= MOBILITY_DOMAIN_ID_LEN) {
  612. mobility_domain = mdie + 2;
  613. #ifdef CONFIG_SME
  614. wpa_s->sme.ft_used = 1;
  615. os_memcpy(wpa_s->sme.mobility_domain, mobility_domain, 2);
  616. #endif /* CONFIG_SME */
  617. }
  618. if (ftie[1] >= sizeof(struct rsn_ftie)) {
  619. end = ftie + 2 + ftie[1];
  620. hdr = (struct rsn_ftie *) (ftie + 2);
  621. pos = (const u8 *) (hdr + 1);
  622. while (pos + 1 < end) {
  623. if (pos + 2 + pos[1] > end)
  624. break;
  625. if (pos[0] == FTIE_SUBELEM_R1KH_ID &&
  626. pos[1] == FT_R1KH_ID_LEN)
  627. r1kh_id = pos + 2;
  628. else if (pos[0] == FTIE_SUBELEM_R0KH_ID &&
  629. pos[1] >= 1 && pos[1] <= FT_R0KH_ID_MAX_LEN) {
  630. r0kh_id = pos + 2;
  631. r0kh_id_len = pos[1];
  632. }
  633. pos += 2 + pos[1];
  634. }
  635. }
  636. wpa_sm_set_ft_params(wpa_s->wpa, mobility_domain, r0kh_id,
  637. r0kh_id_len, r1kh_id);
  638. }
  639. #endif /* CONFIG_IEEE80211R */
  640. static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  641. union wpa_event_data *data)
  642. {
  643. int l, len, found = 0, wpa_found, rsn_found;
  644. const u8 *p;
  645. #ifdef CONFIG_IEEE80211R
  646. const u8 *mdie = NULL, *ftie = NULL;
  647. #endif /* CONFIG_IEEE80211R */
  648. wpa_printf(MSG_DEBUG, "Association info event");
  649. if (data->assoc_info.req_ies)
  650. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  651. data->assoc_info.req_ies_len);
  652. if (data->assoc_info.resp_ies)
  653. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  654. data->assoc_info.resp_ies_len);
  655. if (data->assoc_info.beacon_ies)
  656. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  657. data->assoc_info.beacon_ies,
  658. data->assoc_info.beacon_ies_len);
  659. p = data->assoc_info.req_ies;
  660. l = data->assoc_info.req_ies_len;
  661. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  662. while (p && l >= 2) {
  663. len = p[1] + 2;
  664. if (len > l) {
  665. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  666. p, l);
  667. break;
  668. }
  669. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  670. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  671. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  672. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  673. break;
  674. found = 1;
  675. wpa_find_assoc_pmkid(wpa_s);
  676. break;
  677. }
  678. l -= len;
  679. p += len;
  680. }
  681. if (!found && data->assoc_info.req_ies)
  682. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  683. #ifdef CONFIG_IEEE80211R
  684. p = data->assoc_info.resp_ies;
  685. l = data->assoc_info.resp_ies_len;
  686. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  687. while (p && l >= 2) {
  688. len = p[1] + 2;
  689. if (len > l) {
  690. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  691. p, l);
  692. break;
  693. }
  694. if (p[0] == WLAN_EID_FAST_BSS_TRANSITION)
  695. ftie = p;
  696. else if (p[0] == WLAN_EID_MOBILITY_DOMAIN)
  697. mdie = p;
  698. l -= len;
  699. p += len;
  700. }
  701. wpa_assoc_set_ft_params(wpa_s, ftie, mdie);
  702. #endif /* CONFIG_IEEE80211R */
  703. /* WPA/RSN IE from Beacon/ProbeResp */
  704. p = data->assoc_info.beacon_ies;
  705. l = data->assoc_info.beacon_ies_len;
  706. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  707. */
  708. wpa_found = rsn_found = 0;
  709. while (p && l >= 2) {
  710. len = p[1] + 2;
  711. if (len > l) {
  712. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  713. p, l);
  714. break;
  715. }
  716. if (!wpa_found &&
  717. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  718. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  719. wpa_found = 1;
  720. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  721. }
  722. if (!rsn_found &&
  723. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  724. rsn_found = 1;
  725. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  726. }
  727. l -= len;
  728. p += len;
  729. }
  730. if (!wpa_found && data->assoc_info.beacon_ies)
  731. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  732. if (!rsn_found && data->assoc_info.beacon_ies)
  733. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  734. if (wpa_found || rsn_found)
  735. wpa_s->ap_ies_from_associnfo = 1;
  736. }
  737. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  738. union wpa_event_data *data)
  739. {
  740. u8 bssid[ETH_ALEN];
  741. int ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  742. if (data)
  743. wpa_supplicant_event_associnfo(wpa_s, data);
  744. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  745. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
  746. os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
  747. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
  748. (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
  749. os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
  750. wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  751. MACSTR, MAC2STR(bssid));
  752. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  753. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  754. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  755. wpa_clear_keys(wpa_s, bssid);
  756. }
  757. if (wpa_supplicant_select_config(wpa_s) < 0) {
  758. wpa_supplicant_disassociate(
  759. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  760. return;
  761. }
  762. }
  763. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  764. if (wpa_s->current_ssid) {
  765. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  766. * initialized before association, but for other modes,
  767. * initialize PC/SC here, if the current configuration needs
  768. * smartcard or SIM/USIM. */
  769. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  770. }
  771. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  772. l2_packet_notify_auth_start(wpa_s->l2);
  773. /*
  774. * Set portEnabled first to FALSE in order to get EAP state machine out
  775. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  776. * state machine may transit to AUTHENTICATING state based on obsolete
  777. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  778. * AUTHENTICATED without ever giving chance to EAP state machine to
  779. * reset the state.
  780. */
  781. if (!ft_completed) {
  782. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  783. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  784. }
  785. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  786. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  787. /* 802.1X::portControl = Auto */
  788. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  789. wpa_s->eapol_received = 0;
  790. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  791. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  792. wpa_supplicant_cancel_auth_timeout(wpa_s);
  793. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  794. } else if (!ft_completed) {
  795. /* Timeout for receiving the first EAPOL packet */
  796. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  797. }
  798. wpa_supplicant_cancel_scan(wpa_s);
  799. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  800. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  801. /*
  802. * We are done; the driver will take care of RSN 4-way
  803. * handshake.
  804. */
  805. wpa_supplicant_cancel_auth_timeout(wpa_s);
  806. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  807. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  808. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  809. }
  810. }
  811. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s)
  812. {
  813. const u8 *bssid;
  814. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  815. /*
  816. * At least Host AP driver and a Prism3 card seemed to be
  817. * generating streams of disconnected events when configuring
  818. * IBSS for WPA-None. Ignore them for now.
  819. */
  820. wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
  821. "IBSS/WPA-None mode");
  822. return;
  823. }
  824. if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
  825. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  826. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  827. "pre-shared key may be incorrect");
  828. }
  829. if (wpa_s->wpa_state >= WPA_ASSOCIATED)
  830. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  831. bssid = wpa_s->bssid;
  832. if (is_zero_ether_addr(bssid))
  833. bssid = wpa_s->pending_bssid;
  834. wpa_blacklist_add(wpa_s, bssid);
  835. wpa_sm_notify_disassoc(wpa_s->wpa);
  836. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "- Disconnect event - "
  837. "remove keys");
  838. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  839. wpa_s->keys_cleared = 0;
  840. wpa_clear_keys(wpa_s, wpa_s->bssid);
  841. }
  842. wpa_supplicant_mark_disassoc(wpa_s);
  843. }
  844. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  845. static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
  846. void *sock_ctx)
  847. {
  848. struct wpa_supplicant *wpa_s = eloop_ctx;
  849. if (!wpa_s->pending_mic_error_report)
  850. return;
  851. wpa_printf(MSG_DEBUG, "WPA: Sending pending MIC error report");
  852. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  853. wpa_s->pending_mic_error_report = 0;
  854. }
  855. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  856. static void
  857. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  858. union wpa_event_data *data)
  859. {
  860. int pairwise;
  861. struct os_time t;
  862. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  863. pairwise = (data && data->michael_mic_failure.unicast);
  864. os_get_time(&t);
  865. if ((wpa_s->last_michael_mic_error &&
  866. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  867. wpa_s->pending_mic_error_report) {
  868. if (wpa_s->pending_mic_error_report) {
  869. /*
  870. * Send the pending MIC error report immediately since
  871. * we are going to start countermeasures and AP better
  872. * do the same.
  873. */
  874. wpa_sm_key_request(wpa_s->wpa, 1,
  875. wpa_s->pending_mic_error_pairwise);
  876. }
  877. /* Send the new MIC error report immediately since we are going
  878. * to start countermeasures and AP better do the same.
  879. */
  880. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  881. /* initialize countermeasures */
  882. wpa_s->countermeasures = 1;
  883. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  884. /*
  885. * Need to wait for completion of request frame. We do not get
  886. * any callback for the message completion, so just wait a
  887. * short while and hope for the best. */
  888. os_sleep(0, 10000);
  889. wpa_drv_set_countermeasures(wpa_s, 1);
  890. wpa_supplicant_deauthenticate(wpa_s,
  891. WLAN_REASON_MICHAEL_MIC_FAILURE);
  892. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  893. wpa_s, NULL);
  894. eloop_register_timeout(60, 0,
  895. wpa_supplicant_stop_countermeasures,
  896. wpa_s, NULL);
  897. /* TODO: mark the AP rejected for 60 second. STA is
  898. * allowed to associate with another AP.. */
  899. } else {
  900. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  901. if (wpa_s->mic_errors_seen) {
  902. /*
  903. * Reduce the effectiveness of Michael MIC error
  904. * reports as a means for attacking against TKIP if
  905. * more than one MIC failure is noticed with the same
  906. * PTK. We delay the transmission of the reports by a
  907. * random time between 0 and 60 seconds in order to
  908. * force the attacker wait 60 seconds before getting
  909. * the information on whether a frame resulted in a MIC
  910. * failure.
  911. */
  912. u8 rval[4];
  913. int sec;
  914. if (os_get_random(rval, sizeof(rval)) < 0)
  915. sec = os_random() % 60;
  916. else
  917. sec = WPA_GET_BE32(rval) % 60;
  918. wpa_printf(MSG_DEBUG, "WPA: Delay MIC error report %d "
  919. "seconds", sec);
  920. wpa_s->pending_mic_error_report = 1;
  921. wpa_s->pending_mic_error_pairwise = pairwise;
  922. eloop_cancel_timeout(
  923. wpa_supplicant_delayed_mic_error_report,
  924. wpa_s, NULL);
  925. eloop_register_timeout(
  926. sec, os_random() % 1000000,
  927. wpa_supplicant_delayed_mic_error_report,
  928. wpa_s, NULL);
  929. } else {
  930. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  931. }
  932. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  933. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  934. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  935. }
  936. wpa_s->last_michael_mic_error = t.sec;
  937. wpa_s->mic_errors_seen++;
  938. }
  939. #ifdef CONFIG_TERMINATE_ONLASTIF
  940. static int any_interfaces(struct wpa_supplicant *head)
  941. {
  942. struct wpa_supplicant *wpa_s;
  943. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  944. if (!wpa_s->interface_removed)
  945. return 1;
  946. return 0;
  947. }
  948. #endif /* CONFIG_TERMINATE_ONLASTIF */
  949. static void
  950. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  951. union wpa_event_data *data)
  952. {
  953. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  954. return;
  955. switch (data->interface_status.ievent) {
  956. case EVENT_INTERFACE_ADDED:
  957. if (!wpa_s->interface_removed)
  958. break;
  959. wpa_s->interface_removed = 0;
  960. wpa_printf(MSG_DEBUG, "Configured interface was added.");
  961. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  962. wpa_printf(MSG_INFO, "Failed to initialize the driver "
  963. "after interface was added.");
  964. }
  965. break;
  966. case EVENT_INTERFACE_REMOVED:
  967. wpa_printf(MSG_DEBUG, "Configured interface was removed.");
  968. wpa_s->interface_removed = 1;
  969. wpa_supplicant_mark_disassoc(wpa_s);
  970. l2_packet_deinit(wpa_s->l2);
  971. wpa_s->l2 = NULL;
  972. #ifdef CONFIG_TERMINATE_ONLASTIF
  973. /* check if last interface */
  974. if (!any_interfaces(wpa_s->global->ifaces))
  975. eloop_terminate();
  976. #endif /* CONFIG_TERMINATE_ONLASTIF */
  977. break;
  978. }
  979. }
  980. #ifdef CONFIG_PEERKEY
  981. static void
  982. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  983. union wpa_event_data *data)
  984. {
  985. if (data == NULL)
  986. return;
  987. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  988. }
  989. #endif /* CONFIG_PEERKEY */
  990. #ifdef CONFIG_IEEE80211R
  991. static void
  992. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  993. union wpa_event_data *data)
  994. {
  995. if (data == NULL)
  996. return;
  997. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  998. data->ft_ies.ies_len,
  999. data->ft_ies.ft_action,
  1000. data->ft_ies.target_ap,
  1001. data->ft_ies.ric_ies,
  1002. data->ft_ies.ric_ies_len) < 0) {
  1003. /* TODO: prevent MLME/driver from trying to associate? */
  1004. }
  1005. }
  1006. #endif /* CONFIG_IEEE80211R */
  1007. #ifdef CONFIG_IBSS_RSN
  1008. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  1009. union wpa_event_data *data)
  1010. {
  1011. if (data == NULL)
  1012. return;
  1013. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  1014. }
  1015. #endif /* CONFIG_IBSS_RSN */
  1016. void wpa_supplicant_event(void *ctx, wpa_event_type event,
  1017. union wpa_event_data *data)
  1018. {
  1019. struct wpa_supplicant *wpa_s = ctx;
  1020. switch (event) {
  1021. case EVENT_AUTH:
  1022. sme_event_auth(wpa_s, data);
  1023. break;
  1024. case EVENT_ASSOC:
  1025. wpa_supplicant_event_assoc(wpa_s, data);
  1026. break;
  1027. case EVENT_DEAUTH:
  1028. case EVENT_DISASSOC:
  1029. wpa_supplicant_event_disassoc(wpa_s);
  1030. break;
  1031. case EVENT_MICHAEL_MIC_FAILURE:
  1032. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  1033. break;
  1034. #ifndef CONFIG_NO_SCAN_PROCESSING
  1035. case EVENT_SCAN_RESULTS:
  1036. wpa_supplicant_event_scan_results(wpa_s);
  1037. break;
  1038. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1039. case EVENT_ASSOCINFO:
  1040. wpa_supplicant_event_associnfo(wpa_s, data);
  1041. break;
  1042. case EVENT_INTERFACE_STATUS:
  1043. wpa_supplicant_event_interface_status(wpa_s, data);
  1044. break;
  1045. case EVENT_PMKID_CANDIDATE:
  1046. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  1047. break;
  1048. #ifdef CONFIG_PEERKEY
  1049. case EVENT_STKSTART:
  1050. wpa_supplicant_event_stkstart(wpa_s, data);
  1051. break;
  1052. #endif /* CONFIG_PEERKEY */
  1053. #ifdef CONFIG_IEEE80211R
  1054. case EVENT_FT_RESPONSE:
  1055. wpa_supplicant_event_ft_response(wpa_s, data);
  1056. break;
  1057. #endif /* CONFIG_IEEE80211R */
  1058. #ifdef CONFIG_IBSS_RSN
  1059. case EVENT_IBSS_RSN_START:
  1060. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  1061. break;
  1062. #endif /* CONFIG_IBSS_RSN */
  1063. case EVENT_ASSOC_REJECT:
  1064. sme_event_assoc_reject(wpa_s, data);
  1065. break;
  1066. case EVENT_AUTH_TIMED_OUT:
  1067. sme_event_auth_timed_out(wpa_s, data);
  1068. break;
  1069. case EVENT_ASSOC_TIMED_OUT:
  1070. sme_event_assoc_timed_out(wpa_s, data);
  1071. break;
  1072. default:
  1073. wpa_printf(MSG_INFO, "Unknown event %d", event);
  1074. break;
  1075. }
  1076. }