events.c 78 KB

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