events.c 76 KB

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