events.c 74 KB

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