events.c 63 KB

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