events.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771
  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 or if scan results should not
  841. * be shared with other virtual interfaces. */
  842. static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  843. union wpa_event_data *data)
  844. {
  845. struct wpa_bss *selected;
  846. struct wpa_ssid *ssid = NULL;
  847. struct wpa_scan_results *scan_res;
  848. int ap = 0;
  849. #ifdef CONFIG_AP
  850. if (wpa_s->ap_iface)
  851. ap = 1;
  852. #endif /* CONFIG_AP */
  853. wpa_supplicant_notify_scanning(wpa_s, 0);
  854. #ifdef CONFIG_P2P
  855. if (wpa_s->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
  856. wpa_s->global->p2p != NULL) {
  857. wpa_s->p2p_cb_on_scan_complete = 0;
  858. if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
  859. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
  860. "stopped scan processing");
  861. return -1;
  862. }
  863. }
  864. #endif /* CONFIG_P2P */
  865. scan_res = wpa_supplicant_get_scan_results(wpa_s,
  866. data ? &data->scan_info :
  867. NULL, 1);
  868. if (scan_res == NULL) {
  869. if (wpa_s->conf->ap_scan == 2 || ap)
  870. return -1;
  871. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
  872. "scanning again");
  873. wpa_supplicant_req_new_scan(wpa_s, 1, 0);
  874. return -1;
  875. }
  876. #ifndef CONFIG_NO_RANDOM_POOL
  877. size_t i, num;
  878. num = scan_res->num;
  879. if (num > 10)
  880. num = 10;
  881. for (i = 0; i < num; i++) {
  882. u8 buf[5];
  883. struct wpa_scan_res *res = scan_res->res[i];
  884. buf[0] = res->bssid[5];
  885. buf[1] = res->qual & 0xff;
  886. buf[2] = res->noise & 0xff;
  887. buf[3] = res->level & 0xff;
  888. buf[4] = res->tsf & 0xff;
  889. random_add_randomness(buf, sizeof(buf));
  890. }
  891. #endif /* CONFIG_NO_RANDOM_POOL */
  892. if (wpa_s->scan_res_handler) {
  893. void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
  894. struct wpa_scan_results *scan_res);
  895. scan_res_handler = wpa_s->scan_res_handler;
  896. wpa_s->scan_res_handler = NULL;
  897. scan_res_handler(wpa_s, scan_res);
  898. wpa_scan_results_free(scan_res);
  899. return -2;
  900. }
  901. if (ap) {
  902. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
  903. #ifdef CONFIG_AP
  904. if (wpa_s->ap_iface->scan_cb)
  905. wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
  906. #endif /* CONFIG_AP */
  907. wpa_scan_results_free(scan_res);
  908. return 0;
  909. }
  910. wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
  911. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  912. wpas_notify_scan_results(wpa_s);
  913. wpas_notify_scan_done(wpa_s, 1);
  914. if (sme_proc_obss_scan(wpa_s) > 0) {
  915. wpa_scan_results_free(scan_res);
  916. return 0;
  917. }
  918. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
  919. wpa_scan_results_free(scan_res);
  920. return 0;
  921. }
  922. if (autoscan_notify_scan(wpa_s, scan_res)) {
  923. wpa_scan_results_free(scan_res);
  924. return 0;
  925. }
  926. if (wpa_s->disconnected) {
  927. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  928. wpa_scan_results_free(scan_res);
  929. return 0;
  930. }
  931. if (!wpas_driver_bss_selection(wpa_s) &&
  932. bgscan_notify_scan(wpa_s, scan_res) == 1) {
  933. wpa_scan_results_free(scan_res);
  934. return 0;
  935. }
  936. selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
  937. if (selected) {
  938. int skip;
  939. skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
  940. scan_res);
  941. wpa_scan_results_free(scan_res);
  942. if (skip) {
  943. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  944. return 0;
  945. }
  946. if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
  947. wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
  948. return -1;
  949. }
  950. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  951. } else {
  952. wpa_scan_results_free(scan_res);
  953. wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
  954. ssid = wpa_supplicant_pick_new_network(wpa_s);
  955. if (ssid) {
  956. wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
  957. wpa_supplicant_associate(wpa_s, NULL, ssid);
  958. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  959. } else {
  960. int timeout_sec = wpa_s->scan_interval;
  961. int timeout_usec = 0;
  962. #ifdef CONFIG_P2P
  963. if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
  964. return 0;
  965. if (wpa_s->p2p_in_provisioning) {
  966. /*
  967. * Use shorter wait during P2P Provisioning
  968. * state to speed up group formation.
  969. */
  970. timeout_sec = 0;
  971. timeout_usec = 250000;
  972. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  973. timeout_usec);
  974. return 0;
  975. }
  976. #endif /* CONFIG_P2P */
  977. if (wpa_supplicant_req_sched_scan(wpa_s))
  978. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  979. timeout_usec);
  980. }
  981. }
  982. return 0;
  983. }
  984. static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  985. union wpa_event_data *data)
  986. {
  987. const char *rn, *rn2;
  988. struct wpa_supplicant *ifs;
  989. if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
  990. /*
  991. * If no scan results could be fetched, then no need to
  992. * notify those interfaces that did not actually request
  993. * this scan.
  994. */
  995. return;
  996. }
  997. /*
  998. * Check other interfaces to see if they have the same radio-name. If
  999. * so, they get updated with this same scan info.
  1000. */
  1001. if (!wpa_s->driver->get_radio_name)
  1002. return;
  1003. rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
  1004. if (rn == NULL || rn[0] == '\0')
  1005. return;
  1006. wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
  1007. "sharing same radio (%s) in event_scan_results", rn);
  1008. for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
  1009. if (ifs == wpa_s || !ifs->driver->get_radio_name)
  1010. continue;
  1011. rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
  1012. if (rn2 && os_strcmp(rn, rn2) == 0) {
  1013. wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
  1014. "sibling", ifs->ifname);
  1015. _wpa_supplicant_event_scan_results(ifs, data);
  1016. }
  1017. }
  1018. }
  1019. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1020. #ifdef CONFIG_WNM
  1021. static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
  1022. {
  1023. struct wpa_supplicant *wpa_s = eloop_ctx;
  1024. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1025. return;
  1026. wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
  1027. MAC2STR(wpa_s->bssid));
  1028. /* TODO: could skip this if normal data traffic has been sent */
  1029. /* TODO: Consider using some more appropriate data frame for this */
  1030. if (wpa_s->l2)
  1031. l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, (u8 *) "", 0);
  1032. #ifdef CONFIG_SME
  1033. if (wpa_s->sme.bss_max_idle_period) {
  1034. unsigned int msec;
  1035. msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
  1036. if (msec > 100)
  1037. msec -= 100;
  1038. eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
  1039. wnm_bss_keep_alive, wpa_s, NULL);
  1040. }
  1041. #endif /* CONFIG_SME */
  1042. }
  1043. static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
  1044. const u8 *ies, size_t ies_len)
  1045. {
  1046. struct ieee802_11_elems elems;
  1047. if (ies == NULL)
  1048. return;
  1049. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
  1050. return;
  1051. #ifdef CONFIG_SME
  1052. if (elems.bss_max_idle_period) {
  1053. unsigned int msec;
  1054. wpa_s->sme.bss_max_idle_period =
  1055. WPA_GET_LE16(elems.bss_max_idle_period);
  1056. wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
  1057. "TU)%s", wpa_s->sme.bss_max_idle_period,
  1058. (elems.bss_max_idle_period[2] & 0x01) ?
  1059. " (protected keep-live required)" : "");
  1060. if (wpa_s->sme.bss_max_idle_period == 0)
  1061. wpa_s->sme.bss_max_idle_period = 1;
  1062. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
  1063. eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
  1064. /* msec times 1000 */
  1065. msec = wpa_s->sme.bss_max_idle_period * 1024;
  1066. if (msec > 100)
  1067. msec -= 100;
  1068. eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
  1069. wnm_bss_keep_alive, wpa_s,
  1070. NULL);
  1071. }
  1072. }
  1073. #endif /* CONFIG_SME */
  1074. }
  1075. #endif /* CONFIG_WNM */
  1076. void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
  1077. {
  1078. #ifdef CONFIG_WNM
  1079. eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
  1080. #endif /* CONFIG_WNM */
  1081. }
  1082. static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  1083. union wpa_event_data *data)
  1084. {
  1085. int l, len, found = 0, wpa_found, rsn_found;
  1086. const u8 *p;
  1087. wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
  1088. if (data->assoc_info.req_ies)
  1089. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  1090. data->assoc_info.req_ies_len);
  1091. if (data->assoc_info.resp_ies) {
  1092. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  1093. data->assoc_info.resp_ies_len);
  1094. #ifdef CONFIG_TDLS
  1095. wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
  1096. data->assoc_info.resp_ies_len);
  1097. #endif /* CONFIG_TDLS */
  1098. #ifdef CONFIG_WNM
  1099. wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
  1100. data->assoc_info.resp_ies_len);
  1101. #endif /* CONFIG_WNM */
  1102. }
  1103. if (data->assoc_info.beacon_ies)
  1104. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  1105. data->assoc_info.beacon_ies,
  1106. data->assoc_info.beacon_ies_len);
  1107. if (data->assoc_info.freq)
  1108. wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
  1109. data->assoc_info.freq);
  1110. p = data->assoc_info.req_ies;
  1111. l = data->assoc_info.req_ies_len;
  1112. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  1113. while (p && l >= 2) {
  1114. len = p[1] + 2;
  1115. if (len > l) {
  1116. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1117. p, l);
  1118. break;
  1119. }
  1120. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1121. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  1122. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  1123. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  1124. break;
  1125. found = 1;
  1126. wpa_find_assoc_pmkid(wpa_s);
  1127. break;
  1128. }
  1129. l -= len;
  1130. p += len;
  1131. }
  1132. if (!found && data->assoc_info.req_ies)
  1133. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  1134. #ifdef CONFIG_IEEE80211R
  1135. #ifdef CONFIG_SME
  1136. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  1137. u8 bssid[ETH_ALEN];
  1138. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  1139. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  1140. data->assoc_info.resp_ies,
  1141. data->assoc_info.resp_ies_len,
  1142. bssid) < 0) {
  1143. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  1144. "Reassociation Response failed");
  1145. wpa_supplicant_deauthenticate(
  1146. wpa_s, WLAN_REASON_INVALID_IE);
  1147. return -1;
  1148. }
  1149. }
  1150. p = data->assoc_info.resp_ies;
  1151. l = data->assoc_info.resp_ies_len;
  1152. #ifdef CONFIG_WPS_STRICT
  1153. if (p && wpa_s->current_ssid &&
  1154. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  1155. struct wpabuf *wps;
  1156. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  1157. if (wps == NULL) {
  1158. wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
  1159. "include WPS IE in (Re)Association Response");
  1160. return -1;
  1161. }
  1162. if (wps_validate_assoc_resp(wps) < 0) {
  1163. wpabuf_free(wps);
  1164. wpa_supplicant_deauthenticate(
  1165. wpa_s, WLAN_REASON_INVALID_IE);
  1166. return -1;
  1167. }
  1168. wpabuf_free(wps);
  1169. }
  1170. #endif /* CONFIG_WPS_STRICT */
  1171. /* Go through the IEs and make a copy of the MDIE, if present. */
  1172. while (p && l >= 2) {
  1173. len = p[1] + 2;
  1174. if (len > l) {
  1175. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1176. p, l);
  1177. break;
  1178. }
  1179. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  1180. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  1181. wpa_s->sme.ft_used = 1;
  1182. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  1183. MOBILITY_DOMAIN_ID_LEN);
  1184. break;
  1185. }
  1186. l -= len;
  1187. p += len;
  1188. }
  1189. #endif /* CONFIG_SME */
  1190. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  1191. data->assoc_info.resp_ies_len);
  1192. #endif /* CONFIG_IEEE80211R */
  1193. /* WPA/RSN IE from Beacon/ProbeResp */
  1194. p = data->assoc_info.beacon_ies;
  1195. l = data->assoc_info.beacon_ies_len;
  1196. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  1197. */
  1198. wpa_found = rsn_found = 0;
  1199. while (p && l >= 2) {
  1200. len = p[1] + 2;
  1201. if (len > l) {
  1202. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  1203. p, l);
  1204. break;
  1205. }
  1206. if (!wpa_found &&
  1207. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1208. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  1209. wpa_found = 1;
  1210. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  1211. }
  1212. if (!rsn_found &&
  1213. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  1214. rsn_found = 1;
  1215. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  1216. }
  1217. l -= len;
  1218. p += len;
  1219. }
  1220. if (!wpa_found && data->assoc_info.beacon_ies)
  1221. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  1222. if (!rsn_found && data->assoc_info.beacon_ies)
  1223. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  1224. if (wpa_found || rsn_found)
  1225. wpa_s->ap_ies_from_associnfo = 1;
  1226. if (wpa_s->assoc_freq && data->assoc_info.freq &&
  1227. wpa_s->assoc_freq != data->assoc_info.freq) {
  1228. wpa_printf(MSG_DEBUG, "Operating frequency changed from "
  1229. "%u to %u MHz",
  1230. wpa_s->assoc_freq, data->assoc_info.freq);
  1231. wpa_supplicant_update_scan_results(wpa_s);
  1232. }
  1233. wpa_s->assoc_freq = data->assoc_info.freq;
  1234. return 0;
  1235. }
  1236. static struct wpa_bss * wpa_supplicant_get_new_bss(
  1237. struct wpa_supplicant *wpa_s, const u8 *bssid)
  1238. {
  1239. struct wpa_bss *bss = NULL;
  1240. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1241. if (ssid->ssid_len > 0)
  1242. bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
  1243. if (!bss)
  1244. bss = wpa_bss_get_bssid(wpa_s, bssid);
  1245. return bss;
  1246. }
  1247. static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
  1248. {
  1249. const u8 *bss_wpa = NULL, *bss_rsn = NULL;
  1250. if (!wpa_s->current_bss || !wpa_s->current_ssid)
  1251. return -1;
  1252. if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
  1253. return 0;
  1254. bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
  1255. WPA_IE_VENDOR_TYPE);
  1256. bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
  1257. if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
  1258. bss_wpa ? 2 + bss_wpa[1] : 0) ||
  1259. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
  1260. bss_rsn ? 2 + bss_rsn[1] : 0))
  1261. return -1;
  1262. return 0;
  1263. }
  1264. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  1265. union wpa_event_data *data)
  1266. {
  1267. u8 bssid[ETH_ALEN];
  1268. int ft_completed;
  1269. int bssid_changed;
  1270. struct wpa_driver_capa capa;
  1271. #ifdef CONFIG_AP
  1272. if (wpa_s->ap_iface) {
  1273. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  1274. data->assoc_info.addr,
  1275. data->assoc_info.req_ies,
  1276. data->assoc_info.req_ies_len,
  1277. data->assoc_info.reassoc);
  1278. return;
  1279. }
  1280. #endif /* CONFIG_AP */
  1281. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  1282. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  1283. return;
  1284. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  1285. if (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
  1286. os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
  1287. wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  1288. MACSTR, MAC2STR(bssid));
  1289. random_add_randomness(bssid, ETH_ALEN);
  1290. bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
  1291. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  1292. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1293. if (bssid_changed)
  1294. wpas_notify_bssid_changed(wpa_s);
  1295. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  1296. wpa_clear_keys(wpa_s, bssid);
  1297. }
  1298. if (wpa_supplicant_select_config(wpa_s) < 0) {
  1299. wpa_supplicant_disassociate(
  1300. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1301. return;
  1302. }
  1303. if (wpa_s->current_ssid) {
  1304. struct wpa_bss *bss = NULL;
  1305. bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
  1306. if (!bss) {
  1307. wpa_supplicant_update_scan_results(wpa_s);
  1308. /* Get the BSS from the new scan results */
  1309. bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
  1310. }
  1311. if (bss)
  1312. wpa_s->current_bss = bss;
  1313. }
  1314. if (wpa_s->conf->ap_scan == 1 &&
  1315. wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
  1316. if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
  1317. wpa_msg(wpa_s, MSG_WARNING,
  1318. "WPA/RSN IEs not updated");
  1319. }
  1320. }
  1321. #ifdef CONFIG_SME
  1322. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  1323. wpa_s->sme.prev_bssid_set = 1;
  1324. #endif /* CONFIG_SME */
  1325. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  1326. if (wpa_s->current_ssid) {
  1327. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  1328. * initialized before association, but for other modes,
  1329. * initialize PC/SC here, if the current configuration needs
  1330. * smartcard or SIM/USIM. */
  1331. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  1332. }
  1333. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  1334. if (wpa_s->l2)
  1335. l2_packet_notify_auth_start(wpa_s->l2);
  1336. /*
  1337. * Set portEnabled first to FALSE in order to get EAP state machine out
  1338. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  1339. * state machine may transit to AUTHENTICATING state based on obsolete
  1340. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  1341. * AUTHENTICATED without ever giving chance to EAP state machine to
  1342. * reset the state.
  1343. */
  1344. if (!ft_completed) {
  1345. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  1346. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  1347. }
  1348. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  1349. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  1350. /* 802.1X::portControl = Auto */
  1351. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  1352. wpa_s->eapol_received = 0;
  1353. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1354. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  1355. (wpa_s->current_ssid &&
  1356. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  1357. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1358. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1359. } else if (!ft_completed) {
  1360. /* Timeout for receiving the first EAPOL packet */
  1361. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  1362. }
  1363. wpa_supplicant_cancel_scan(wpa_s);
  1364. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1365. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1366. /*
  1367. * We are done; the driver will take care of RSN 4-way
  1368. * handshake.
  1369. */
  1370. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1371. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1372. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1373. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1374. } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1375. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1376. /*
  1377. * The driver will take care of RSN 4-way handshake, so we need
  1378. * to allow EAPOL supplicant to complete its work without
  1379. * waiting for WPA supplicant.
  1380. */
  1381. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1382. } else if (ft_completed) {
  1383. /*
  1384. * FT protocol completed - make sure EAPOL state machine ends
  1385. * up in authenticated.
  1386. */
  1387. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1388. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1389. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1390. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1391. }
  1392. if (wpa_s->pending_eapol_rx) {
  1393. struct os_time now, age;
  1394. os_get_time(&now);
  1395. os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  1396. if (age.sec == 0 && age.usec < 100000 &&
  1397. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  1398. 0) {
  1399. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
  1400. "frame that was received just before "
  1401. "association notification");
  1402. wpa_supplicant_rx_eapol(
  1403. wpa_s, wpa_s->pending_eapol_rx_src,
  1404. wpabuf_head(wpa_s->pending_eapol_rx),
  1405. wpabuf_len(wpa_s->pending_eapol_rx));
  1406. }
  1407. wpabuf_free(wpa_s->pending_eapol_rx);
  1408. wpa_s->pending_eapol_rx = NULL;
  1409. }
  1410. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1411. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1412. wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
  1413. capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
  1414. /* Set static WEP keys again */
  1415. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1416. }
  1417. #ifdef CONFIG_IBSS_RSN
  1418. if (wpa_s->current_ssid &&
  1419. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  1420. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  1421. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
  1422. wpa_s->ibss_rsn == NULL) {
  1423. wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
  1424. if (!wpa_s->ibss_rsn) {
  1425. wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
  1426. wpa_supplicant_deauthenticate(
  1427. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1428. return;
  1429. }
  1430. ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
  1431. }
  1432. #endif /* CONFIG_IBSS_RSN */
  1433. }
  1434. static int disconnect_reason_recoverable(u16 reason_code)
  1435. {
  1436. return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
  1437. reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
  1438. reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
  1439. }
  1440. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1441. u16 reason_code,
  1442. int locally_generated)
  1443. {
  1444. const u8 *bssid;
  1445. int authenticating;
  1446. u8 prev_pending_bssid[ETH_ALEN];
  1447. struct wpa_bss *fast_reconnect = NULL;
  1448. struct wpa_ssid *fast_reconnect_ssid = NULL;
  1449. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1450. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1451. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1452. /*
  1453. * At least Host AP driver and a Prism3 card seemed to be
  1454. * generating streams of disconnected events when configuring
  1455. * IBSS for WPA-None. Ignore them for now.
  1456. */
  1457. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
  1458. "IBSS/WPA-None mode");
  1459. return;
  1460. }
  1461. if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
  1462. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1463. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1464. "pre-shared key may be incorrect");
  1465. }
  1466. if (!wpa_s->auto_reconnect_disabled ||
  1467. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
  1468. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
  1469. "reconnect (wps=%d wpa_state=%d)",
  1470. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
  1471. wpa_s->wpa_state);
  1472. if (wpa_s->wpa_state == WPA_COMPLETED &&
  1473. wpa_s->current_ssid &&
  1474. wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
  1475. !locally_generated &&
  1476. disconnect_reason_recoverable(reason_code)) {
  1477. /*
  1478. * It looks like the AP has dropped association with
  1479. * us, but could allow us to get back in. Try to
  1480. * reconnect to the same BSS without full scan to save
  1481. * time for some common cases.
  1482. */
  1483. fast_reconnect = wpa_s->current_bss;
  1484. fast_reconnect_ssid = wpa_s->current_ssid;
  1485. } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  1486. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1487. else
  1488. wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
  1489. "immediate scan");
  1490. } else {
  1491. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
  1492. "try to re-connect");
  1493. wpa_s->reassociate = 0;
  1494. wpa_s->disconnected = 1;
  1495. wpa_supplicant_cancel_sched_scan(wpa_s);
  1496. }
  1497. bssid = wpa_s->bssid;
  1498. if (is_zero_ether_addr(bssid))
  1499. bssid = wpa_s->pending_bssid;
  1500. if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
  1501. wpas_connection_failed(wpa_s, bssid);
  1502. wpa_sm_notify_disassoc(wpa_s->wpa);
  1503. if (locally_generated)
  1504. wpa_s->disconnect_reason = -reason_code;
  1505. else
  1506. wpa_s->disconnect_reason = reason_code;
  1507. wpas_notify_disconnect_reason(wpa_s);
  1508. if (!is_zero_ether_addr(bssid) ||
  1509. wpa_s->wpa_state >= WPA_AUTHENTICATING) {
  1510. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1511. " reason=%d%s",
  1512. MAC2STR(bssid), reason_code,
  1513. locally_generated ? " locally_generated=1" : "");
  1514. }
  1515. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  1516. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
  1517. wpa_s->keys_cleared = 0;
  1518. wpa_clear_keys(wpa_s, wpa_s->bssid);
  1519. }
  1520. wpa_supplicant_mark_disassoc(wpa_s);
  1521. if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1522. sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
  1523. if (fast_reconnect) {
  1524. #ifndef CONFIG_NO_SCAN_PROCESSING
  1525. wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
  1526. if (wpa_supplicant_connect(wpa_s, fast_reconnect,
  1527. fast_reconnect_ssid) < 0) {
  1528. /* Recover through full scan */
  1529. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1530. }
  1531. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1532. }
  1533. }
  1534. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1535. void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
  1536. {
  1537. struct wpa_supplicant *wpa_s = eloop_ctx;
  1538. if (!wpa_s->pending_mic_error_report)
  1539. return;
  1540. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
  1541. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  1542. wpa_s->pending_mic_error_report = 0;
  1543. }
  1544. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1545. static void
  1546. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  1547. union wpa_event_data *data)
  1548. {
  1549. int pairwise;
  1550. struct os_time t;
  1551. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  1552. pairwise = (data && data->michael_mic_failure.unicast);
  1553. os_get_time(&t);
  1554. if ((wpa_s->last_michael_mic_error &&
  1555. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  1556. wpa_s->pending_mic_error_report) {
  1557. if (wpa_s->pending_mic_error_report) {
  1558. /*
  1559. * Send the pending MIC error report immediately since
  1560. * we are going to start countermeasures and AP better
  1561. * do the same.
  1562. */
  1563. wpa_sm_key_request(wpa_s->wpa, 1,
  1564. wpa_s->pending_mic_error_pairwise);
  1565. }
  1566. /* Send the new MIC error report immediately since we are going
  1567. * to start countermeasures and AP better do the same.
  1568. */
  1569. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1570. /* initialize countermeasures */
  1571. wpa_s->countermeasures = 1;
  1572. wpa_blacklist_add(wpa_s, wpa_s->bssid);
  1573. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  1574. /*
  1575. * Need to wait for completion of request frame. We do not get
  1576. * any callback for the message completion, so just wait a
  1577. * short while and hope for the best. */
  1578. os_sleep(0, 10000);
  1579. wpa_drv_set_countermeasures(wpa_s, 1);
  1580. wpa_supplicant_deauthenticate(wpa_s,
  1581. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1582. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  1583. wpa_s, NULL);
  1584. eloop_register_timeout(60, 0,
  1585. wpa_supplicant_stop_countermeasures,
  1586. wpa_s, NULL);
  1587. /* TODO: mark the AP rejected for 60 second. STA is
  1588. * allowed to associate with another AP.. */
  1589. } else {
  1590. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1591. if (wpa_s->mic_errors_seen) {
  1592. /*
  1593. * Reduce the effectiveness of Michael MIC error
  1594. * reports as a means for attacking against TKIP if
  1595. * more than one MIC failure is noticed with the same
  1596. * PTK. We delay the transmission of the reports by a
  1597. * random time between 0 and 60 seconds in order to
  1598. * force the attacker wait 60 seconds before getting
  1599. * the information on whether a frame resulted in a MIC
  1600. * failure.
  1601. */
  1602. u8 rval[4];
  1603. int sec;
  1604. if (os_get_random(rval, sizeof(rval)) < 0)
  1605. sec = os_random() % 60;
  1606. else
  1607. sec = WPA_GET_BE32(rval) % 60;
  1608. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
  1609. "report %d seconds", sec);
  1610. wpa_s->pending_mic_error_report = 1;
  1611. wpa_s->pending_mic_error_pairwise = pairwise;
  1612. eloop_cancel_timeout(
  1613. wpa_supplicant_delayed_mic_error_report,
  1614. wpa_s, NULL);
  1615. eloop_register_timeout(
  1616. sec, os_random() % 1000000,
  1617. wpa_supplicant_delayed_mic_error_report,
  1618. wpa_s, NULL);
  1619. } else {
  1620. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1621. }
  1622. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1623. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1624. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1625. }
  1626. wpa_s->last_michael_mic_error = t.sec;
  1627. wpa_s->mic_errors_seen++;
  1628. }
  1629. #ifdef CONFIG_TERMINATE_ONLASTIF
  1630. static int any_interfaces(struct wpa_supplicant *head)
  1631. {
  1632. struct wpa_supplicant *wpa_s;
  1633. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  1634. if (!wpa_s->interface_removed)
  1635. return 1;
  1636. return 0;
  1637. }
  1638. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1639. static void
  1640. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  1641. union wpa_event_data *data)
  1642. {
  1643. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  1644. return;
  1645. switch (data->interface_status.ievent) {
  1646. case EVENT_INTERFACE_ADDED:
  1647. if (!wpa_s->interface_removed)
  1648. break;
  1649. wpa_s->interface_removed = 0;
  1650. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
  1651. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  1652. wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
  1653. "driver after interface was added");
  1654. }
  1655. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1656. break;
  1657. case EVENT_INTERFACE_REMOVED:
  1658. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
  1659. wpa_s->interface_removed = 1;
  1660. wpa_supplicant_mark_disassoc(wpa_s);
  1661. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  1662. l2_packet_deinit(wpa_s->l2);
  1663. wpa_s->l2 = NULL;
  1664. #ifdef CONFIG_IBSS_RSN
  1665. ibss_rsn_deinit(wpa_s->ibss_rsn);
  1666. wpa_s->ibss_rsn = NULL;
  1667. #endif /* CONFIG_IBSS_RSN */
  1668. #ifdef CONFIG_TERMINATE_ONLASTIF
  1669. /* check if last interface */
  1670. if (!any_interfaces(wpa_s->global->ifaces))
  1671. eloop_terminate();
  1672. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1673. break;
  1674. }
  1675. }
  1676. #ifdef CONFIG_PEERKEY
  1677. static void
  1678. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  1679. union wpa_event_data *data)
  1680. {
  1681. if (data == NULL)
  1682. return;
  1683. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  1684. }
  1685. #endif /* CONFIG_PEERKEY */
  1686. #ifdef CONFIG_TDLS
  1687. static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
  1688. union wpa_event_data *data)
  1689. {
  1690. if (data == NULL)
  1691. return;
  1692. switch (data->tdls.oper) {
  1693. case TDLS_REQUEST_SETUP:
  1694. wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
  1695. break;
  1696. case TDLS_REQUEST_TEARDOWN:
  1697. wpa_tdls_send_teardown(wpa_s->wpa, data->tdls.peer,
  1698. data->tdls.reason_code);
  1699. break;
  1700. }
  1701. }
  1702. #endif /* CONFIG_TDLS */
  1703. #ifdef CONFIG_IEEE80211R
  1704. static void
  1705. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  1706. union wpa_event_data *data)
  1707. {
  1708. if (data == NULL)
  1709. return;
  1710. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  1711. data->ft_ies.ies_len,
  1712. data->ft_ies.ft_action,
  1713. data->ft_ies.target_ap,
  1714. data->ft_ies.ric_ies,
  1715. data->ft_ies.ric_ies_len) < 0) {
  1716. /* TODO: prevent MLME/driver from trying to associate? */
  1717. }
  1718. }
  1719. #endif /* CONFIG_IEEE80211R */
  1720. #ifdef CONFIG_IBSS_RSN
  1721. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  1722. union wpa_event_data *data)
  1723. {
  1724. struct wpa_ssid *ssid;
  1725. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1726. return;
  1727. if (data == NULL)
  1728. return;
  1729. ssid = wpa_s->current_ssid;
  1730. if (ssid == NULL)
  1731. return;
  1732. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  1733. return;
  1734. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  1735. }
  1736. #endif /* CONFIG_IBSS_RSN */
  1737. #ifdef CONFIG_IEEE80211R
  1738. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  1739. size_t len)
  1740. {
  1741. const u8 *sta_addr, *target_ap_addr;
  1742. u16 status;
  1743. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  1744. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1745. return; /* only SME case supported for now */
  1746. if (len < 1 + 2 * ETH_ALEN + 2)
  1747. return;
  1748. if (data[0] != 2)
  1749. return; /* Only FT Action Response is supported for now */
  1750. sta_addr = data + 1;
  1751. target_ap_addr = data + 1 + ETH_ALEN;
  1752. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  1753. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
  1754. MACSTR " TargetAP " MACSTR " status %u",
  1755. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  1756. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  1757. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  1758. " in FT Action Response", MAC2STR(sta_addr));
  1759. return;
  1760. }
  1761. if (status) {
  1762. wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
  1763. "failure (status code %d)", status);
  1764. /* TODO: report error to FT code(?) */
  1765. return;
  1766. }
  1767. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  1768. len - (1 + 2 * ETH_ALEN + 2), 1,
  1769. target_ap_addr, NULL, 0) < 0)
  1770. return;
  1771. #ifdef CONFIG_SME
  1772. {
  1773. struct wpa_bss *bss;
  1774. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  1775. if (bss)
  1776. wpa_s->sme.freq = bss->freq;
  1777. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  1778. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  1779. WLAN_AUTH_FT);
  1780. }
  1781. #endif /* CONFIG_SME */
  1782. }
  1783. #endif /* CONFIG_IEEE80211R */
  1784. static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
  1785. struct unprot_deauth *e)
  1786. {
  1787. #ifdef CONFIG_IEEE80211W
  1788. wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
  1789. "dropped: " MACSTR " -> " MACSTR
  1790. " (reason code %u)",
  1791. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1792. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1793. #endif /* CONFIG_IEEE80211W */
  1794. }
  1795. static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
  1796. struct unprot_disassoc *e)
  1797. {
  1798. #ifdef CONFIG_IEEE80211W
  1799. wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
  1800. "dropped: " MACSTR " -> " MACSTR
  1801. " (reason code %u)",
  1802. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1803. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1804. #endif /* CONFIG_IEEE80211W */
  1805. }
  1806. static void wnm_action_rx(struct wpa_supplicant *wpa_s, struct rx_action *rx)
  1807. {
  1808. u8 action, mode;
  1809. const u8 *pos, *end;
  1810. if (rx->data == NULL || rx->len == 0)
  1811. return;
  1812. pos = rx->data;
  1813. end = pos + rx->len;
  1814. action = *pos++;
  1815. wpa_printf(MSG_DEBUG, "WNM: RX action %u from " MACSTR,
  1816. action, MAC2STR(rx->sa));
  1817. switch (action) {
  1818. case WNM_BSS_TRANS_MGMT_REQ:
  1819. if (pos + 5 > end)
  1820. break;
  1821. wpa_printf(MSG_DEBUG, "WNM: BSS Transition Management "
  1822. "Request: dialog_token=%u request_mode=0x%x "
  1823. "disassoc_timer=%u validity_interval=%u",
  1824. pos[0], pos[1], WPA_GET_LE16(pos + 2), pos[4]);
  1825. mode = pos[1];
  1826. pos += 5;
  1827. if (mode & 0x08)
  1828. pos += 12; /* BSS Termination Duration */
  1829. if (mode & 0x10) {
  1830. char url[256];
  1831. if (pos + 1 > end || pos + 1 + pos[0] > end) {
  1832. wpa_printf(MSG_DEBUG, "WNM: Invalid BSS "
  1833. "Transition Management Request "
  1834. "(URL)");
  1835. break;
  1836. }
  1837. os_memcpy(url, pos + 1, pos[0]);
  1838. url[pos[0]] = '\0';
  1839. wpa_msg(wpa_s, MSG_INFO, "WNM: ESS Disassociation "
  1840. "Imminent - session_info_url=%s", url);
  1841. }
  1842. break;
  1843. }
  1844. }
  1845. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  1846. union wpa_event_data *data)
  1847. {
  1848. struct wpa_supplicant *wpa_s = ctx;
  1849. u16 reason_code = 0;
  1850. int locally_generated = 0;
  1851. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  1852. event != EVENT_INTERFACE_ENABLED &&
  1853. event != EVENT_INTERFACE_STATUS &&
  1854. event != EVENT_SCHED_SCAN_STOPPED) {
  1855. wpa_dbg(wpa_s, MSG_DEBUG,
  1856. "Ignore event %s (%d) while interface is disabled",
  1857. event_to_string(event), event);
  1858. return;
  1859. }
  1860. #ifndef CONFIG_NO_STDOUT_DEBUG
  1861. {
  1862. int level = MSG_DEBUG;
  1863. if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
  1864. const struct ieee80211_hdr *hdr;
  1865. u16 fc;
  1866. hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
  1867. fc = le_to_host16(hdr->frame_control);
  1868. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  1869. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
  1870. level = MSG_EXCESSIVE;
  1871. }
  1872. wpa_dbg(wpa_s, level, "Event %s (%d) received",
  1873. event_to_string(event), event);
  1874. }
  1875. #endif /* CONFIG_NO_STDOUT_DEBUG */
  1876. switch (event) {
  1877. case EVENT_AUTH:
  1878. sme_event_auth(wpa_s, data);
  1879. break;
  1880. case EVENT_ASSOC:
  1881. wpa_supplicant_event_assoc(wpa_s, data);
  1882. break;
  1883. case EVENT_DISASSOC:
  1884. wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
  1885. if (data) {
  1886. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
  1887. data->disassoc_info.reason_code,
  1888. data->disassoc_info.locally_generated ?
  1889. " (locally generated)" : "");
  1890. if (data->disassoc_info.addr)
  1891. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  1892. MAC2STR(data->disassoc_info.addr));
  1893. }
  1894. #ifdef CONFIG_AP
  1895. if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
  1896. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1897. data->disassoc_info.addr);
  1898. break;
  1899. }
  1900. if (wpa_s->ap_iface) {
  1901. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in "
  1902. "AP mode");
  1903. break;
  1904. }
  1905. #endif /* CONFIG_AP */
  1906. if (data) {
  1907. reason_code = data->disassoc_info.reason_code;
  1908. locally_generated =
  1909. data->disassoc_info.locally_generated;
  1910. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  1911. data->disassoc_info.ie,
  1912. data->disassoc_info.ie_len);
  1913. #ifdef CONFIG_P2P
  1914. wpas_p2p_disassoc_notif(
  1915. wpa_s, data->disassoc_info.addr, reason_code,
  1916. data->disassoc_info.ie,
  1917. data->disassoc_info.ie_len,
  1918. locally_generated);
  1919. #endif /* CONFIG_P2P */
  1920. }
  1921. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1922. sme_event_disassoc(wpa_s, data);
  1923. /* fall through */
  1924. case EVENT_DEAUTH:
  1925. if (event == EVENT_DEAUTH) {
  1926. wpa_dbg(wpa_s, MSG_DEBUG,
  1927. "Deauthentication notification");
  1928. if (data) {
  1929. reason_code = data->deauth_info.reason_code;
  1930. locally_generated =
  1931. data->deauth_info.locally_generated;
  1932. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
  1933. data->deauth_info.reason_code,
  1934. data->deauth_info.locally_generated ?
  1935. " (locally generated)" : "");
  1936. if (data->deauth_info.addr) {
  1937. wpa_dbg(wpa_s, MSG_DEBUG, " * address "
  1938. MACSTR,
  1939. MAC2STR(data->deauth_info.
  1940. addr));
  1941. }
  1942. wpa_hexdump(MSG_DEBUG,
  1943. "Deauthentication frame IE(s)",
  1944. data->deauth_info.ie,
  1945. data->deauth_info.ie_len);
  1946. }
  1947. }
  1948. #ifdef CONFIG_AP
  1949. if (wpa_s->ap_iface && data && data->deauth_info.addr) {
  1950. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1951. data->deauth_info.addr);
  1952. break;
  1953. }
  1954. if (wpa_s->ap_iface) {
  1955. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in "
  1956. "AP mode");
  1957. break;
  1958. }
  1959. #endif /* CONFIG_AP */
  1960. wpa_supplicant_event_disassoc(wpa_s, reason_code,
  1961. locally_generated);
  1962. #ifdef CONFIG_P2P
  1963. if (event == EVENT_DEAUTH && data) {
  1964. wpas_p2p_deauth_notif(wpa_s, data->deauth_info.addr,
  1965. reason_code,
  1966. data->deauth_info.ie,
  1967. data->deauth_info.ie_len,
  1968. locally_generated);
  1969. }
  1970. #endif /* CONFIG_P2P */
  1971. break;
  1972. case EVENT_MICHAEL_MIC_FAILURE:
  1973. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  1974. break;
  1975. #ifndef CONFIG_NO_SCAN_PROCESSING
  1976. case EVENT_SCAN_RESULTS:
  1977. wpa_supplicant_event_scan_results(wpa_s, data);
  1978. break;
  1979. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1980. case EVENT_ASSOCINFO:
  1981. wpa_supplicant_event_associnfo(wpa_s, data);
  1982. break;
  1983. case EVENT_INTERFACE_STATUS:
  1984. wpa_supplicant_event_interface_status(wpa_s, data);
  1985. break;
  1986. case EVENT_PMKID_CANDIDATE:
  1987. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  1988. break;
  1989. #ifdef CONFIG_PEERKEY
  1990. case EVENT_STKSTART:
  1991. wpa_supplicant_event_stkstart(wpa_s, data);
  1992. break;
  1993. #endif /* CONFIG_PEERKEY */
  1994. #ifdef CONFIG_TDLS
  1995. case EVENT_TDLS:
  1996. wpa_supplicant_event_tdls(wpa_s, data);
  1997. break;
  1998. #endif /* CONFIG_TDLS */
  1999. #ifdef CONFIG_IEEE80211R
  2000. case EVENT_FT_RESPONSE:
  2001. wpa_supplicant_event_ft_response(wpa_s, data);
  2002. break;
  2003. #endif /* CONFIG_IEEE80211R */
  2004. #ifdef CONFIG_IBSS_RSN
  2005. case EVENT_IBSS_RSN_START:
  2006. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  2007. break;
  2008. #endif /* CONFIG_IBSS_RSN */
  2009. case EVENT_ASSOC_REJECT:
  2010. if (data->assoc_reject.bssid)
  2011. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  2012. "bssid=" MACSTR " status_code=%u",
  2013. MAC2STR(data->assoc_reject.bssid),
  2014. data->assoc_reject.status_code);
  2015. else
  2016. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  2017. "status_code=%u",
  2018. data->assoc_reject.status_code);
  2019. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2020. sme_event_assoc_reject(wpa_s, data);
  2021. break;
  2022. case EVENT_AUTH_TIMED_OUT:
  2023. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2024. sme_event_auth_timed_out(wpa_s, data);
  2025. break;
  2026. case EVENT_ASSOC_TIMED_OUT:
  2027. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2028. sme_event_assoc_timed_out(wpa_s, data);
  2029. break;
  2030. case EVENT_TX_STATUS:
  2031. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
  2032. " type=%d stype=%d",
  2033. MAC2STR(data->tx_status.dst),
  2034. data->tx_status.type, data->tx_status.stype);
  2035. #ifdef CONFIG_AP
  2036. if (wpa_s->ap_iface == NULL) {
  2037. #ifdef CONFIG_OFFCHANNEL
  2038. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  2039. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  2040. offchannel_send_action_tx_status(
  2041. wpa_s, data->tx_status.dst,
  2042. data->tx_status.data,
  2043. data->tx_status.data_len,
  2044. data->tx_status.ack ?
  2045. OFFCHANNEL_SEND_ACTION_SUCCESS :
  2046. OFFCHANNEL_SEND_ACTION_NO_ACK);
  2047. #endif /* CONFIG_OFFCHANNEL */
  2048. break;
  2049. }
  2050. #endif /* CONFIG_AP */
  2051. #ifdef CONFIG_OFFCHANNEL
  2052. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
  2053. MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
  2054. /*
  2055. * Catch TX status events for Action frames we sent via group
  2056. * interface in GO mode.
  2057. */
  2058. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  2059. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  2060. os_memcmp(wpa_s->parent->pending_action_dst,
  2061. data->tx_status.dst, ETH_ALEN) == 0) {
  2062. offchannel_send_action_tx_status(
  2063. wpa_s->parent, data->tx_status.dst,
  2064. data->tx_status.data,
  2065. data->tx_status.data_len,
  2066. data->tx_status.ack ?
  2067. OFFCHANNEL_SEND_ACTION_SUCCESS :
  2068. OFFCHANNEL_SEND_ACTION_NO_ACK);
  2069. break;
  2070. }
  2071. #endif /* CONFIG_OFFCHANNEL */
  2072. #ifdef CONFIG_AP
  2073. switch (data->tx_status.type) {
  2074. case WLAN_FC_TYPE_MGMT:
  2075. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  2076. data->tx_status.data_len,
  2077. data->tx_status.stype,
  2078. data->tx_status.ack);
  2079. break;
  2080. case WLAN_FC_TYPE_DATA:
  2081. ap_tx_status(wpa_s, data->tx_status.dst,
  2082. data->tx_status.data,
  2083. data->tx_status.data_len,
  2084. data->tx_status.ack);
  2085. break;
  2086. }
  2087. #endif /* CONFIG_AP */
  2088. break;
  2089. #ifdef CONFIG_AP
  2090. case EVENT_EAPOL_TX_STATUS:
  2091. ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
  2092. data->eapol_tx_status.data,
  2093. data->eapol_tx_status.data_len,
  2094. data->eapol_tx_status.ack);
  2095. break;
  2096. case EVENT_DRIVER_CLIENT_POLL_OK:
  2097. ap_client_poll_ok(wpa_s, data->client_poll.addr);
  2098. break;
  2099. case EVENT_RX_FROM_UNKNOWN:
  2100. if (wpa_s->ap_iface == NULL)
  2101. break;
  2102. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
  2103. data->rx_from_unknown.wds);
  2104. break;
  2105. case EVENT_CH_SWITCH:
  2106. if (!data)
  2107. break;
  2108. if (!wpa_s->ap_iface) {
  2109. wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
  2110. "event in non-AP mode");
  2111. break;
  2112. }
  2113. #ifdef CONFIG_AP
  2114. wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
  2115. data->ch_switch.ht_enabled,
  2116. data->ch_switch.ch_offset);
  2117. #endif /* CONFIG_AP */
  2118. break;
  2119. case EVENT_RX_MGMT: {
  2120. u16 fc, stype;
  2121. const struct ieee80211_mgmt *mgmt;
  2122. mgmt = (const struct ieee80211_mgmt *)
  2123. data->rx_mgmt.frame;
  2124. fc = le_to_host16(mgmt->frame_control);
  2125. stype = WLAN_FC_GET_STYPE(fc);
  2126. if (wpa_s->ap_iface == NULL) {
  2127. #ifdef CONFIG_P2P
  2128. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  2129. data->rx_mgmt.frame_len > 24) {
  2130. const u8 *src = mgmt->sa;
  2131. const u8 *ie = mgmt->u.probe_req.variable;
  2132. size_t ie_len = data->rx_mgmt.frame_len -
  2133. (mgmt->u.probe_req.variable -
  2134. data->rx_mgmt.frame);
  2135. wpas_p2p_probe_req_rx(
  2136. wpa_s, src, mgmt->da,
  2137. mgmt->bssid, ie, ie_len,
  2138. data->rx_mgmt.ssi_signal);
  2139. break;
  2140. }
  2141. #endif /* CONFIG_P2P */
  2142. wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
  2143. "management frame in non-AP mode");
  2144. break;
  2145. }
  2146. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  2147. data->rx_mgmt.frame_len > 24) {
  2148. const u8 *ie = mgmt->u.probe_req.variable;
  2149. size_t ie_len = data->rx_mgmt.frame_len -
  2150. (mgmt->u.probe_req.variable -
  2151. data->rx_mgmt.frame);
  2152. wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
  2153. mgmt->bssid, ie, ie_len,
  2154. data->rx_mgmt.ssi_signal);
  2155. }
  2156. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  2157. break;
  2158. }
  2159. #endif /* CONFIG_AP */
  2160. case EVENT_RX_ACTION:
  2161. wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
  2162. " Category=%u DataLen=%d freq=%d MHz",
  2163. MAC2STR(data->rx_action.sa),
  2164. data->rx_action.category, (int) data->rx_action.len,
  2165. data->rx_action.freq);
  2166. #ifdef CONFIG_IEEE80211R
  2167. if (data->rx_action.category == WLAN_ACTION_FT) {
  2168. ft_rx_action(wpa_s, data->rx_action.data,
  2169. data->rx_action.len);
  2170. break;
  2171. }
  2172. #endif /* CONFIG_IEEE80211R */
  2173. #ifdef CONFIG_IEEE80211W
  2174. #ifdef CONFIG_SME
  2175. if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
  2176. sme_sa_query_rx(wpa_s, data->rx_action.sa,
  2177. data->rx_action.data,
  2178. data->rx_action.len);
  2179. break;
  2180. }
  2181. #endif /* CONFIG_SME */
  2182. #endif /* CONFIG_IEEE80211W */
  2183. #ifdef CONFIG_GAS
  2184. if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
  2185. gas_query_rx(wpa_s->gas, data->rx_action.da,
  2186. data->rx_action.sa, data->rx_action.bssid,
  2187. data->rx_action.data, data->rx_action.len,
  2188. data->rx_action.freq) == 0)
  2189. break;
  2190. #endif /* CONFIG_GAS */
  2191. if (data->rx_action.category == WLAN_ACTION_WNM) {
  2192. wnm_action_rx(wpa_s, &data->rx_action);
  2193. break;
  2194. }
  2195. #ifdef CONFIG_TDLS
  2196. if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
  2197. data->rx_action.len >= 4 &&
  2198. data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
  2199. wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
  2200. "Response from " MACSTR,
  2201. MAC2STR(data->rx_action.sa));
  2202. break;
  2203. }
  2204. #endif /* CONFIG_TDLS */
  2205. #ifdef CONFIG_P2P
  2206. wpas_p2p_rx_action(wpa_s, data->rx_action.da,
  2207. data->rx_action.sa,
  2208. data->rx_action.bssid,
  2209. data->rx_action.category,
  2210. data->rx_action.data,
  2211. data->rx_action.len, data->rx_action.freq);
  2212. #endif /* CONFIG_P2P */
  2213. break;
  2214. case EVENT_RX_PROBE_REQ:
  2215. if (data->rx_probe_req.sa == NULL ||
  2216. data->rx_probe_req.ie == NULL)
  2217. break;
  2218. #ifdef CONFIG_AP
  2219. if (wpa_s->ap_iface) {
  2220. hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
  2221. data->rx_probe_req.sa,
  2222. data->rx_probe_req.da,
  2223. data->rx_probe_req.bssid,
  2224. data->rx_probe_req.ie,
  2225. data->rx_probe_req.ie_len,
  2226. data->rx_probe_req.ssi_signal);
  2227. break;
  2228. }
  2229. #endif /* CONFIG_AP */
  2230. #ifdef CONFIG_P2P
  2231. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  2232. data->rx_probe_req.da,
  2233. data->rx_probe_req.bssid,
  2234. data->rx_probe_req.ie,
  2235. data->rx_probe_req.ie_len,
  2236. data->rx_probe_req.ssi_signal);
  2237. #endif /* CONFIG_P2P */
  2238. break;
  2239. case EVENT_REMAIN_ON_CHANNEL:
  2240. #ifdef CONFIG_OFFCHANNEL
  2241. offchannel_remain_on_channel_cb(
  2242. wpa_s, data->remain_on_channel.freq,
  2243. data->remain_on_channel.duration);
  2244. #endif /* CONFIG_OFFCHANNEL */
  2245. #ifdef CONFIG_P2P
  2246. wpas_p2p_remain_on_channel_cb(
  2247. wpa_s, data->remain_on_channel.freq,
  2248. data->remain_on_channel.duration);
  2249. #endif /* CONFIG_P2P */
  2250. break;
  2251. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  2252. #ifdef CONFIG_OFFCHANNEL
  2253. offchannel_cancel_remain_on_channel_cb(
  2254. wpa_s, data->remain_on_channel.freq);
  2255. #endif /* CONFIG_OFFCHANNEL */
  2256. #ifdef CONFIG_P2P
  2257. wpas_p2p_cancel_remain_on_channel_cb(
  2258. wpa_s, data->remain_on_channel.freq);
  2259. #endif /* CONFIG_P2P */
  2260. break;
  2261. #ifdef CONFIG_P2P
  2262. case EVENT_P2P_DEV_FOUND: {
  2263. struct p2p_peer_info peer_info;
  2264. os_memset(&peer_info, 0, sizeof(peer_info));
  2265. if (data->p2p_dev_found.dev_addr)
  2266. os_memcpy(peer_info.p2p_device_addr,
  2267. data->p2p_dev_found.dev_addr, ETH_ALEN);
  2268. if (data->p2p_dev_found.pri_dev_type)
  2269. os_memcpy(peer_info.pri_dev_type,
  2270. data->p2p_dev_found.pri_dev_type,
  2271. sizeof(peer_info.pri_dev_type));
  2272. if (data->p2p_dev_found.dev_name)
  2273. os_strlcpy(peer_info.device_name,
  2274. data->p2p_dev_found.dev_name,
  2275. sizeof(peer_info.device_name));
  2276. peer_info.config_methods = data->p2p_dev_found.config_methods;
  2277. peer_info.dev_capab = data->p2p_dev_found.dev_capab;
  2278. peer_info.group_capab = data->p2p_dev_found.group_capab;
  2279. /*
  2280. * FIX: new_device=1 is not necessarily correct. We should
  2281. * maintain a P2P peer database in wpa_supplicant and update
  2282. * this information based on whether the peer is truly new.
  2283. */
  2284. wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
  2285. break;
  2286. }
  2287. case EVENT_P2P_GO_NEG_REQ_RX:
  2288. wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
  2289. data->p2p_go_neg_req_rx.dev_passwd_id);
  2290. break;
  2291. case EVENT_P2P_GO_NEG_COMPLETED:
  2292. wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
  2293. break;
  2294. case EVENT_P2P_PROV_DISC_REQUEST:
  2295. wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
  2296. data->p2p_prov_disc_req.config_methods,
  2297. data->p2p_prov_disc_req.dev_addr,
  2298. data->p2p_prov_disc_req.pri_dev_type,
  2299. data->p2p_prov_disc_req.dev_name,
  2300. data->p2p_prov_disc_req.supp_config_methods,
  2301. data->p2p_prov_disc_req.dev_capab,
  2302. data->p2p_prov_disc_req.group_capab,
  2303. NULL, 0);
  2304. break;
  2305. case EVENT_P2P_PROV_DISC_RESPONSE:
  2306. wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
  2307. data->p2p_prov_disc_resp.config_methods);
  2308. break;
  2309. case EVENT_P2P_SD_REQUEST:
  2310. wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
  2311. data->p2p_sd_req.sa,
  2312. data->p2p_sd_req.dialog_token,
  2313. data->p2p_sd_req.update_indic,
  2314. data->p2p_sd_req.tlvs,
  2315. data->p2p_sd_req.tlvs_len);
  2316. break;
  2317. case EVENT_P2P_SD_RESPONSE:
  2318. wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
  2319. data->p2p_sd_resp.update_indic,
  2320. data->p2p_sd_resp.tlvs,
  2321. data->p2p_sd_resp.tlvs_len);
  2322. break;
  2323. #endif /* CONFIG_P2P */
  2324. case EVENT_EAPOL_RX:
  2325. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  2326. data->eapol_rx.data,
  2327. data->eapol_rx.data_len);
  2328. break;
  2329. case EVENT_SIGNAL_CHANGE:
  2330. bgscan_notify_signal_change(
  2331. wpa_s, data->signal_change.above_threshold,
  2332. data->signal_change.current_signal,
  2333. data->signal_change.current_noise,
  2334. data->signal_change.current_txrate);
  2335. break;
  2336. case EVENT_INTERFACE_ENABLED:
  2337. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
  2338. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  2339. wpa_supplicant_update_mac_addr(wpa_s);
  2340. #ifdef CONFIG_AP
  2341. if (!wpa_s->ap_iface) {
  2342. wpa_supplicant_set_state(wpa_s,
  2343. WPA_DISCONNECTED);
  2344. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2345. } else
  2346. wpa_supplicant_set_state(wpa_s,
  2347. WPA_COMPLETED);
  2348. #else /* CONFIG_AP */
  2349. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  2350. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2351. #endif /* CONFIG_AP */
  2352. }
  2353. break;
  2354. case EVENT_INTERFACE_DISABLED:
  2355. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
  2356. wpa_supplicant_mark_disassoc(wpa_s);
  2357. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  2358. break;
  2359. case EVENT_CHANNEL_LIST_CHANGED:
  2360. if (wpa_s->drv_priv == NULL)
  2361. break; /* Ignore event during drv initialization */
  2362. free_hw_features(wpa_s);
  2363. wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
  2364. wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
  2365. #ifdef CONFIG_P2P
  2366. wpas_p2p_update_channel_list(wpa_s);
  2367. #endif /* CONFIG_P2P */
  2368. break;
  2369. case EVENT_INTERFACE_UNAVAILABLE:
  2370. #ifdef CONFIG_P2P
  2371. wpas_p2p_interface_unavailable(wpa_s);
  2372. #endif /* CONFIG_P2P */
  2373. break;
  2374. case EVENT_BEST_CHANNEL:
  2375. wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
  2376. "(%d %d %d)",
  2377. data->best_chan.freq_24, data->best_chan.freq_5,
  2378. data->best_chan.freq_overall);
  2379. wpa_s->best_24_freq = data->best_chan.freq_24;
  2380. wpa_s->best_5_freq = data->best_chan.freq_5;
  2381. wpa_s->best_overall_freq = data->best_chan.freq_overall;
  2382. #ifdef CONFIG_P2P
  2383. wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
  2384. data->best_chan.freq_5,
  2385. data->best_chan.freq_overall);
  2386. #endif /* CONFIG_P2P */
  2387. break;
  2388. case EVENT_UNPROT_DEAUTH:
  2389. wpa_supplicant_event_unprot_deauth(wpa_s,
  2390. &data->unprot_deauth);
  2391. break;
  2392. case EVENT_UNPROT_DISASSOC:
  2393. wpa_supplicant_event_unprot_disassoc(wpa_s,
  2394. &data->unprot_disassoc);
  2395. break;
  2396. case EVENT_STATION_LOW_ACK:
  2397. #ifdef CONFIG_AP
  2398. if (wpa_s->ap_iface && data)
  2399. hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
  2400. data->low_ack.addr);
  2401. #endif /* CONFIG_AP */
  2402. #ifdef CONFIG_TDLS
  2403. if (data)
  2404. wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
  2405. #endif /* CONFIG_TDLS */
  2406. break;
  2407. case EVENT_IBSS_PEER_LOST:
  2408. #ifdef CONFIG_IBSS_RSN
  2409. ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
  2410. #endif /* CONFIG_IBSS_RSN */
  2411. break;
  2412. case EVENT_DRIVER_GTK_REKEY:
  2413. if (os_memcmp(data->driver_gtk_rekey.bssid,
  2414. wpa_s->bssid, ETH_ALEN))
  2415. break;
  2416. if (!wpa_s->wpa)
  2417. break;
  2418. wpa_sm_update_replay_ctr(wpa_s->wpa,
  2419. data->driver_gtk_rekey.replay_ctr);
  2420. break;
  2421. case EVENT_SCHED_SCAN_STOPPED:
  2422. wpa_s->sched_scanning = 0;
  2423. wpa_supplicant_notify_scanning(wpa_s, 0);
  2424. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  2425. break;
  2426. /*
  2427. * If we timed out, start a new sched scan to continue
  2428. * searching for more SSIDs.
  2429. */
  2430. if (wpa_s->sched_scan_timed_out)
  2431. wpa_supplicant_req_sched_scan(wpa_s);
  2432. break;
  2433. case EVENT_WPS_BUTTON_PUSHED:
  2434. #ifdef CONFIG_WPS
  2435. wpas_wps_start_pbc(wpa_s, NULL, 0);
  2436. #endif /* CONFIG_WPS */
  2437. break;
  2438. default:
  2439. wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
  2440. break;
  2441. }
  2442. }