events.c 77 KB

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