events.c 75 KB

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