events.c 78 KB

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