events.c 77 KB

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