events.c 79 KB

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