events.c 79 KB

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