events.c 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835
  1. /*
  2. * WPA Supplicant - Driver event processing
  3. * Copyright (c) 2003-2015, 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 "fst/fst.h"
  25. #include "wnm_sta.h"
  26. #include "notify.h"
  27. #include "common/ieee802_11_defs.h"
  28. #include "common/ieee802_11_common.h"
  29. #include "crypto/random.h"
  30. #include "blacklist.h"
  31. #include "wpas_glue.h"
  32. #include "wps_supplicant.h"
  33. #include "ibss_rsn.h"
  34. #include "sme.h"
  35. #include "gas_query.h"
  36. #include "p2p_supplicant.h"
  37. #include "bgscan.h"
  38. #include "autoscan.h"
  39. #include "ap.h"
  40. #include "bss.h"
  41. #include "scan.h"
  42. #include "offchannel.h"
  43. #include "interworking.h"
  44. #include "mesh.h"
  45. #include "mesh_mpm.h"
  46. #include "wmm_ac.h"
  47. #ifndef CONFIG_NO_SCAN_PROCESSING
  48. static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
  49. int new_scan, int own_request);
  50. #endif /* CONFIG_NO_SCAN_PROCESSING */
  51. static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
  52. struct wpa_ssid *ssid)
  53. {
  54. struct os_reltime now;
  55. if (ssid == NULL || ssid->disabled_until.sec == 0)
  56. return 0;
  57. os_get_reltime(&now);
  58. if (ssid->disabled_until.sec > now.sec)
  59. return ssid->disabled_until.sec - now.sec;
  60. wpas_clear_temp_disabled(wpa_s, ssid, 0);
  61. return 0;
  62. }
  63. /**
  64. * wpas_reenabled_network_time - Time until first network is re-enabled
  65. * @wpa_s: Pointer to wpa_supplicant data
  66. * Returns: If all enabled networks are temporarily disabled, returns the time
  67. * (in sec) until the first network is re-enabled. Otherwise returns 0.
  68. *
  69. * This function is used in case all enabled networks are temporarily disabled,
  70. * in which case it returns the time (in sec) that the first network will be
  71. * re-enabled. The function assumes that at least one network is enabled.
  72. */
  73. static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
  74. {
  75. struct wpa_ssid *ssid;
  76. int disabled_for, res = 0;
  77. #ifdef CONFIG_INTERWORKING
  78. if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
  79. wpa_s->conf->cred)
  80. return 0;
  81. #endif /* CONFIG_INTERWORKING */
  82. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  83. if (ssid->disabled)
  84. continue;
  85. disabled_for = wpas_temp_disabled(wpa_s, ssid);
  86. if (!disabled_for)
  87. return 0;
  88. if (!res || disabled_for < res)
  89. res = disabled_for;
  90. }
  91. return res;
  92. }
  93. void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
  94. {
  95. struct wpa_supplicant *wpa_s = eloop_ctx;
  96. if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
  97. return;
  98. wpa_dbg(wpa_s, MSG_DEBUG,
  99. "Try to associate due to network getting re-enabled");
  100. if (wpa_supplicant_fast_associate(wpa_s) != 1) {
  101. wpa_supplicant_cancel_sched_scan(wpa_s);
  102. wpa_supplicant_req_scan(wpa_s, 0, 0);
  103. }
  104. }
  105. static struct wpa_bss * wpa_supplicant_get_new_bss(
  106. struct wpa_supplicant *wpa_s, const u8 *bssid)
  107. {
  108. struct wpa_bss *bss = NULL;
  109. struct wpa_ssid *ssid = wpa_s->current_ssid;
  110. if (ssid->ssid_len > 0)
  111. bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
  112. if (!bss)
  113. bss = wpa_bss_get_bssid(wpa_s, bssid);
  114. return bss;
  115. }
  116. static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
  117. {
  118. struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
  119. if (!bss) {
  120. wpa_supplicant_update_scan_results(wpa_s);
  121. /* Get the BSS from the new scan results */
  122. bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
  123. }
  124. if (bss)
  125. wpa_s->current_bss = bss;
  126. }
  127. static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
  128. {
  129. struct wpa_ssid *ssid, *old_ssid;
  130. u8 drv_ssid[SSID_MAX_LEN];
  131. size_t drv_ssid_len;
  132. int res;
  133. if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
  134. wpa_supplicant_update_current_bss(wpa_s);
  135. if (wpa_s->current_ssid->ssid_len == 0)
  136. return 0; /* current profile still in use */
  137. res = wpa_drv_get_ssid(wpa_s, drv_ssid);
  138. if (res < 0) {
  139. wpa_msg(wpa_s, MSG_INFO,
  140. "Failed to read SSID from driver");
  141. return 0; /* try to use current profile */
  142. }
  143. drv_ssid_len = res;
  144. if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
  145. os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
  146. drv_ssid_len) == 0)
  147. return 0; /* current profile still in use */
  148. wpa_msg(wpa_s, MSG_DEBUG,
  149. "Driver-initiated BSS selection changed the SSID to %s",
  150. wpa_ssid_txt(drv_ssid, drv_ssid_len));
  151. /* continue selecting a new network profile */
  152. }
  153. wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
  154. "information");
  155. ssid = wpa_supplicant_get_ssid(wpa_s);
  156. if (ssid == NULL) {
  157. wpa_msg(wpa_s, MSG_INFO,
  158. "No network configuration found for the current AP");
  159. return -1;
  160. }
  161. if (wpas_network_disabled(wpa_s, ssid)) {
  162. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
  163. return -1;
  164. }
  165. if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
  166. disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
  167. wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
  168. return -1;
  169. }
  170. res = wpas_temp_disabled(wpa_s, ssid);
  171. if (res > 0) {
  172. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
  173. "disabled for %d second(s)", res);
  174. return -1;
  175. }
  176. wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
  177. "current AP");
  178. if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
  179. u8 wpa_ie[80];
  180. size_t wpa_ie_len = sizeof(wpa_ie);
  181. if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
  182. wpa_ie, &wpa_ie_len) < 0)
  183. wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
  184. } else {
  185. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  186. }
  187. if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
  188. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  189. old_ssid = wpa_s->current_ssid;
  190. wpa_s->current_ssid = ssid;
  191. wpa_supplicant_update_current_bss(wpa_s);
  192. wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
  193. wpa_supplicant_initiate_eapol(wpa_s);
  194. if (old_ssid != wpa_s->current_ssid)
  195. wpas_notify_network_changed(wpa_s);
  196. return 0;
  197. }
  198. void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
  199. {
  200. struct wpa_supplicant *wpa_s = eloop_ctx;
  201. if (wpa_s->countermeasures) {
  202. wpa_s->countermeasures = 0;
  203. wpa_drv_set_countermeasures(wpa_s, 0);
  204. wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
  205. /*
  206. * It is possible that the device is sched scanning, which means
  207. * that a connection attempt will be done only when we receive
  208. * scan results. However, in this case, it would be preferable
  209. * to scan and connect immediately, so cancel the sched_scan and
  210. * issue a regular scan flow.
  211. */
  212. wpa_supplicant_cancel_sched_scan(wpa_s);
  213. wpa_supplicant_req_scan(wpa_s, 0, 0);
  214. }
  215. }
  216. void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
  217. {
  218. int bssid_changed;
  219. wnm_bss_keep_alive_deinit(wpa_s);
  220. #ifdef CONFIG_IBSS_RSN
  221. ibss_rsn_deinit(wpa_s->ibss_rsn);
  222. wpa_s->ibss_rsn = NULL;
  223. #endif /* CONFIG_IBSS_RSN */
  224. #ifdef CONFIG_AP
  225. wpa_supplicant_ap_deinit(wpa_s);
  226. #endif /* CONFIG_AP */
  227. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  228. return;
  229. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  230. bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
  231. os_memset(wpa_s->bssid, 0, ETH_ALEN);
  232. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  233. sme_clear_on_disassoc(wpa_s);
  234. wpa_s->current_bss = NULL;
  235. wpa_s->assoc_freq = 0;
  236. if (bssid_changed)
  237. wpas_notify_bssid_changed(wpa_s);
  238. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  239. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  240. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  241. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  242. wpa_s->ap_ies_from_associnfo = 0;
  243. wpa_s->current_ssid = NULL;
  244. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  245. wpa_s->key_mgmt = 0;
  246. wpas_rrm_reset(wpa_s);
  247. }
  248. static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
  249. {
  250. struct wpa_ie_data ie;
  251. int pmksa_set = -1;
  252. size_t i;
  253. if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
  254. ie.pmkid == NULL)
  255. return;
  256. for (i = 0; i < ie.num_pmkid; i++) {
  257. pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
  258. ie.pmkid + i * PMKID_LEN,
  259. NULL, NULL, 0);
  260. if (pmksa_set == 0) {
  261. eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
  262. break;
  263. }
  264. }
  265. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
  266. "PMKSA cache", pmksa_set == 0 ? "" : "not ");
  267. }
  268. static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
  269. union wpa_event_data *data)
  270. {
  271. if (data == NULL) {
  272. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
  273. "event");
  274. return;
  275. }
  276. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
  277. " index=%d preauth=%d",
  278. MAC2STR(data->pmkid_candidate.bssid),
  279. data->pmkid_candidate.index,
  280. data->pmkid_candidate.preauth);
  281. pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
  282. data->pmkid_candidate.index,
  283. data->pmkid_candidate.preauth);
  284. }
  285. static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
  286. {
  287. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  288. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
  289. return 0;
  290. #ifdef IEEE8021X_EAPOL
  291. if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
  292. wpa_s->current_ssid &&
  293. !(wpa_s->current_ssid->eapol_flags &
  294. (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  295. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
  296. /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
  297. * plaintext or static WEP keys). */
  298. return 0;
  299. }
  300. #endif /* IEEE8021X_EAPOL */
  301. return 1;
  302. }
  303. /**
  304. * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
  305. * @wpa_s: pointer to wpa_supplicant data
  306. * @ssid: Configuration data for the network
  307. * Returns: 0 on success, -1 on failure
  308. *
  309. * This function is called when starting authentication with a network that is
  310. * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
  311. */
  312. int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
  313. struct wpa_ssid *ssid)
  314. {
  315. #ifdef IEEE8021X_EAPOL
  316. #ifdef PCSC_FUNCS
  317. int aka = 0, sim = 0;
  318. if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
  319. wpa_s->scard != NULL || wpa_s->conf->external_sim)
  320. return 0;
  321. if (ssid == NULL || ssid->eap.eap_methods == NULL) {
  322. sim = 1;
  323. aka = 1;
  324. } else {
  325. struct eap_method_type *eap = ssid->eap.eap_methods;
  326. while (eap->vendor != EAP_VENDOR_IETF ||
  327. eap->method != EAP_TYPE_NONE) {
  328. if (eap->vendor == EAP_VENDOR_IETF) {
  329. if (eap->method == EAP_TYPE_SIM)
  330. sim = 1;
  331. else if (eap->method == EAP_TYPE_AKA ||
  332. eap->method == EAP_TYPE_AKA_PRIME)
  333. aka = 1;
  334. }
  335. eap++;
  336. }
  337. }
  338. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
  339. sim = 0;
  340. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
  341. eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
  342. NULL)
  343. aka = 0;
  344. if (!sim && !aka) {
  345. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
  346. "use SIM, but neither EAP-SIM nor EAP-AKA are "
  347. "enabled");
  348. return 0;
  349. }
  350. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
  351. "(sim=%d aka=%d) - initialize PCSC", sim, aka);
  352. wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
  353. if (wpa_s->scard == NULL) {
  354. wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
  355. "(pcsc-lite)");
  356. return -1;
  357. }
  358. wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
  359. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  360. #endif /* PCSC_FUNCS */
  361. #endif /* IEEE8021X_EAPOL */
  362. return 0;
  363. }
  364. #ifndef CONFIG_NO_SCAN_PROCESSING
  365. static int has_wep_key(struct wpa_ssid *ssid)
  366. {
  367. int i;
  368. for (i = 0; i < NUM_WEP_KEYS; i++) {
  369. if (ssid->wep_key_len[i])
  370. return 1;
  371. }
  372. return 0;
  373. }
  374. static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
  375. struct wpa_ssid *ssid)
  376. {
  377. int privacy = 0;
  378. if (ssid->mixed_cell)
  379. return 1;
  380. #ifdef CONFIG_WPS
  381. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
  382. return 1;
  383. #endif /* CONFIG_WPS */
  384. if (has_wep_key(ssid))
  385. privacy = 1;
  386. #ifdef IEEE8021X_EAPOL
  387. if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  388. ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  389. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
  390. privacy = 1;
  391. #endif /* IEEE8021X_EAPOL */
  392. if (wpa_key_mgmt_wpa(ssid->key_mgmt))
  393. privacy = 1;
  394. if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
  395. privacy = 1;
  396. if (bss->caps & IEEE80211_CAP_PRIVACY)
  397. return privacy;
  398. return !privacy;
  399. }
  400. static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
  401. struct wpa_ssid *ssid,
  402. struct wpa_bss *bss)
  403. {
  404. struct wpa_ie_data ie;
  405. int proto_match = 0;
  406. const u8 *rsn_ie, *wpa_ie;
  407. int ret;
  408. int wep_ok;
  409. ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
  410. if (ret >= 0)
  411. return ret;
  412. /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
  413. wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
  414. (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
  415. ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
  416. (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
  417. rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  418. while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
  419. proto_match++;
  420. if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
  421. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
  422. "failed");
  423. break;
  424. }
  425. if (wep_ok &&
  426. (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
  427. {
  428. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
  429. "in RSN IE");
  430. return 1;
  431. }
  432. if (!(ie.proto & ssid->proto)) {
  433. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
  434. "mismatch");
  435. break;
  436. }
  437. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  438. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
  439. "cipher mismatch");
  440. break;
  441. }
  442. if (!(ie.group_cipher & ssid->group_cipher)) {
  443. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
  444. "cipher mismatch");
  445. break;
  446. }
  447. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  448. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
  449. "mismatch");
  450. break;
  451. }
  452. #ifdef CONFIG_IEEE80211W
  453. if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
  454. wpas_get_ssid_pmf(wpa_s, ssid) ==
  455. MGMT_FRAME_PROTECTION_REQUIRED) {
  456. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
  457. "frame protection");
  458. break;
  459. }
  460. #endif /* CONFIG_IEEE80211W */
  461. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
  462. return 1;
  463. }
  464. wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  465. while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
  466. proto_match++;
  467. if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
  468. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
  469. "failed");
  470. break;
  471. }
  472. if (wep_ok &&
  473. (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
  474. {
  475. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
  476. "in WPA IE");
  477. return 1;
  478. }
  479. if (!(ie.proto & ssid->proto)) {
  480. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
  481. "mismatch");
  482. break;
  483. }
  484. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  485. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
  486. "cipher mismatch");
  487. break;
  488. }
  489. if (!(ie.group_cipher & ssid->group_cipher)) {
  490. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
  491. "cipher mismatch");
  492. break;
  493. }
  494. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  495. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
  496. "mismatch");
  497. break;
  498. }
  499. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
  500. return 1;
  501. }
  502. if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie &&
  503. !rsn_ie) {
  504. wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X");
  505. return 1;
  506. }
  507. if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
  508. wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
  509. wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
  510. return 0;
  511. }
  512. if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) &&
  513. wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) {
  514. wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN");
  515. return 1;
  516. }
  517. if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
  518. wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
  519. return 1;
  520. }
  521. wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
  522. "WPA/WPA2");
  523. return 0;
  524. }
  525. static int freq_allowed(int *freqs, int freq)
  526. {
  527. int i;
  528. if (freqs == NULL)
  529. return 1;
  530. for (i = 0; freqs[i]; i++)
  531. if (freqs[i] == freq)
  532. return 1;
  533. return 0;
  534. }
  535. static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
  536. {
  537. const struct hostapd_hw_modes *mode = NULL, *modes;
  538. const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES };
  539. const u8 *rate_ie;
  540. int i, j, k;
  541. if (bss->freq == 0)
  542. return 1; /* Cannot do matching without knowing band */
  543. modes = wpa_s->hw.modes;
  544. if (modes == NULL) {
  545. /*
  546. * The driver does not provide any additional information
  547. * about the utilized hardware, so allow the connection attempt
  548. * to continue.
  549. */
  550. return 1;
  551. }
  552. for (i = 0; i < wpa_s->hw.num_modes; i++) {
  553. for (j = 0; j < modes[i].num_channels; j++) {
  554. int freq = modes[i].channels[j].freq;
  555. if (freq == bss->freq) {
  556. if (mode &&
  557. mode->mode == HOSTAPD_MODE_IEEE80211G)
  558. break; /* do not allow 802.11b replace
  559. * 802.11g */
  560. mode = &modes[i];
  561. break;
  562. }
  563. }
  564. }
  565. if (mode == NULL)
  566. return 0;
  567. for (i = 0; i < (int) sizeof(scan_ie); i++) {
  568. rate_ie = wpa_bss_get_ie(bss, scan_ie[i]);
  569. if (rate_ie == NULL)
  570. continue;
  571. for (j = 2; j < rate_ie[1] + 2; j++) {
  572. int flagged = !!(rate_ie[j] & 0x80);
  573. int r = (rate_ie[j] & 0x7f) * 5;
  574. /*
  575. * IEEE Std 802.11n-2009 7.3.2.2:
  576. * The new BSS Membership selector value is encoded
  577. * like a legacy basic rate, but it is not a rate and
  578. * only indicates if the BSS members are required to
  579. * support the mandatory features of Clause 20 [HT PHY]
  580. * in order to join the BSS.
  581. */
  582. if (flagged && ((rate_ie[j] & 0x7f) ==
  583. BSS_MEMBERSHIP_SELECTOR_HT_PHY)) {
  584. if (!ht_supported(mode)) {
  585. wpa_dbg(wpa_s, MSG_DEBUG,
  586. " hardware does not support "
  587. "HT PHY");
  588. return 0;
  589. }
  590. continue;
  591. }
  592. /* There's also a VHT selector for 802.11ac */
  593. if (flagged && ((rate_ie[j] & 0x7f) ==
  594. BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) {
  595. if (!vht_supported(mode)) {
  596. wpa_dbg(wpa_s, MSG_DEBUG,
  597. " hardware does not support "
  598. "VHT PHY");
  599. return 0;
  600. }
  601. continue;
  602. }
  603. if (!flagged)
  604. continue;
  605. /* check for legacy basic rates */
  606. for (k = 0; k < mode->num_rates; k++) {
  607. if (mode->rates[k] == r)
  608. break;
  609. }
  610. if (k == mode->num_rates) {
  611. /*
  612. * IEEE Std 802.11-2007 7.3.2.2 demands that in
  613. * order to join a BSS all required rates
  614. * have to be supported by the hardware.
  615. */
  616. wpa_dbg(wpa_s, MSG_DEBUG,
  617. " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)",
  618. r / 10, r % 10,
  619. bss->freq, mode->mode, mode->num_rates);
  620. return 0;
  621. }
  622. }
  623. }
  624. return 1;
  625. }
  626. /*
  627. * Test whether BSS is in an ESS.
  628. * This is done differently in DMG (60 GHz) and non-DMG bands
  629. */
  630. static int bss_is_ess(struct wpa_bss *bss)
  631. {
  632. if (bss_is_dmg(bss)) {
  633. return (bss->caps & IEEE80211_CAP_DMG_MASK) ==
  634. IEEE80211_CAP_DMG_AP;
  635. }
  636. return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) ==
  637. IEEE80211_CAP_ESS);
  638. }
  639. static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask)
  640. {
  641. size_t i;
  642. for (i = 0; i < ETH_ALEN; i++) {
  643. if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i]))
  644. return 0;
  645. }
  646. return 1;
  647. }
  648. static int addr_in_list(const u8 *addr, const u8 *list, size_t num)
  649. {
  650. size_t i;
  651. for (i = 0; i < num; i++) {
  652. const u8 *a = list + i * ETH_ALEN * 2;
  653. const u8 *m = a + ETH_ALEN;
  654. if (match_mac_mask(a, addr, m))
  655. return 1;
  656. }
  657. return 0;
  658. }
  659. static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
  660. int i, struct wpa_bss *bss,
  661. struct wpa_ssid *group,
  662. int only_first_ssid)
  663. {
  664. u8 wpa_ie_len, rsn_ie_len;
  665. int wpa;
  666. struct wpa_blacklist *e;
  667. const u8 *ie;
  668. struct wpa_ssid *ssid;
  669. int osen;
  670. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  671. wpa_ie_len = ie ? ie[1] : 0;
  672. ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  673. rsn_ie_len = ie ? ie[1] : 0;
  674. ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
  675. osen = ie != NULL;
  676. wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
  677. "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s",
  678. i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len),
  679. wpa_ie_len, rsn_ie_len, bss->caps, bss->level, bss->freq,
  680. wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "",
  681. (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
  682. wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ?
  683. " p2p" : "",
  684. osen ? " osen=1" : "");
  685. e = wpa_blacklist_get(wpa_s, bss->bssid);
  686. if (e) {
  687. int limit = 1;
  688. if (wpa_supplicant_enabled_networks(wpa_s) == 1) {
  689. /*
  690. * When only a single network is enabled, we can
  691. * trigger blacklisting on the first failure. This
  692. * should not be done with multiple enabled networks to
  693. * avoid getting forced to move into a worse ESS on
  694. * single error if there are no other BSSes of the
  695. * current ESS.
  696. */
  697. limit = 0;
  698. }
  699. if (e->count > limit) {
  700. wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
  701. "(count=%d limit=%d)", e->count, limit);
  702. return NULL;
  703. }
  704. }
  705. if (bss->ssid_len == 0) {
  706. wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
  707. return NULL;
  708. }
  709. if (disallowed_bssid(wpa_s, bss->bssid)) {
  710. wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed");
  711. return NULL;
  712. }
  713. if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) {
  714. wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed");
  715. return NULL;
  716. }
  717. wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
  718. for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
  719. int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
  720. int res;
  721. if (wpas_network_disabled(wpa_s, ssid)) {
  722. wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
  723. continue;
  724. }
  725. res = wpas_temp_disabled(wpa_s, ssid);
  726. if (res > 0) {
  727. wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled "
  728. "temporarily for %d second(s)", res);
  729. continue;
  730. }
  731. #ifdef CONFIG_WPS
  732. if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
  733. wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
  734. "(WPS)");
  735. continue;
  736. }
  737. if (wpa && ssid->ssid_len == 0 &&
  738. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  739. check_ssid = 0;
  740. if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
  741. /* Only allow wildcard SSID match if an AP
  742. * advertises active WPS operation that matches
  743. * with our mode. */
  744. check_ssid = 1;
  745. if (ssid->ssid_len == 0 &&
  746. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  747. check_ssid = 0;
  748. }
  749. #endif /* CONFIG_WPS */
  750. if (ssid->bssid_set && ssid->ssid_len == 0 &&
  751. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0)
  752. check_ssid = 0;
  753. if (check_ssid &&
  754. (bss->ssid_len != ssid->ssid_len ||
  755. os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) {
  756. wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
  757. continue;
  758. }
  759. if (ssid->bssid_set &&
  760. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
  761. wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
  762. continue;
  763. }
  764. /* check blacklist */
  765. if (ssid->num_bssid_blacklist &&
  766. addr_in_list(bss->bssid, ssid->bssid_blacklist,
  767. ssid->num_bssid_blacklist)) {
  768. wpa_dbg(wpa_s, MSG_DEBUG,
  769. " skip - BSSID blacklisted");
  770. continue;
  771. }
  772. /* if there is a whitelist, only accept those APs */
  773. if (ssid->num_bssid_whitelist &&
  774. !addr_in_list(bss->bssid, ssid->bssid_whitelist,
  775. ssid->num_bssid_whitelist)) {
  776. wpa_dbg(wpa_s, MSG_DEBUG,
  777. " skip - BSSID not in whitelist");
  778. continue;
  779. }
  780. if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
  781. continue;
  782. if (!osen && !wpa &&
  783. !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
  784. !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
  785. !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
  786. wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
  787. "not allowed");
  788. continue;
  789. }
  790. if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
  791. has_wep_key(ssid)) {
  792. wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block");
  793. continue;
  794. }
  795. if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) {
  796. wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network "
  797. "not allowed");
  798. continue;
  799. }
  800. if (!wpa_supplicant_match_privacy(bss, ssid)) {
  801. wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
  802. "mismatch");
  803. continue;
  804. }
  805. if (!bss_is_ess(bss)) {
  806. wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network");
  807. continue;
  808. }
  809. if (!freq_allowed(ssid->freq_list, bss->freq)) {
  810. wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
  811. "allowed");
  812. continue;
  813. }
  814. if (!rate_match(wpa_s, bss)) {
  815. wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do "
  816. "not match");
  817. continue;
  818. }
  819. #ifdef CONFIG_P2P
  820. if (ssid->p2p_group &&
  821. !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
  822. !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
  823. wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen");
  824. continue;
  825. }
  826. if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
  827. struct wpabuf *p2p_ie;
  828. u8 dev_addr[ETH_ALEN];
  829. ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
  830. if (ie == NULL) {
  831. wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
  832. continue;
  833. }
  834. p2p_ie = wpa_bss_get_vendor_ie_multi(
  835. bss, P2P_IE_VENDOR_TYPE);
  836. if (p2p_ie == NULL) {
  837. wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
  838. continue;
  839. }
  840. if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
  841. || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
  842. ETH_ALEN) != 0) {
  843. wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
  844. wpabuf_free(p2p_ie);
  845. continue;
  846. }
  847. wpabuf_free(p2p_ie);
  848. }
  849. /*
  850. * TODO: skip the AP if its P2P IE has Group Formation
  851. * bit set in the P2P Group Capability Bitmap and we
  852. * are not in Group Formation with that device.
  853. */
  854. #endif /* CONFIG_P2P */
  855. if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time))
  856. {
  857. struct os_reltime diff;
  858. os_reltime_sub(&wpa_s->scan_min_time,
  859. &bss->last_update, &diff);
  860. wpa_dbg(wpa_s, MSG_DEBUG,
  861. " skip - scan result not recent enough (%u.%06u seconds too old)",
  862. (unsigned int) diff.sec,
  863. (unsigned int) diff.usec);
  864. continue;
  865. }
  866. /* Matching configuration found */
  867. return ssid;
  868. }
  869. /* No matching configuration found */
  870. return NULL;
  871. }
  872. static struct wpa_bss *
  873. wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
  874. struct wpa_ssid *group,
  875. struct wpa_ssid **selected_ssid,
  876. int only_first_ssid)
  877. {
  878. unsigned int i;
  879. if (only_first_ssid)
  880. wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d",
  881. group->id);
  882. else
  883. wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
  884. group->priority);
  885. for (i = 0; i < wpa_s->last_scan_res_used; i++) {
  886. struct wpa_bss *bss = wpa_s->last_scan_res[i];
  887. *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group,
  888. only_first_ssid);
  889. if (!*selected_ssid)
  890. continue;
  891. wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
  892. " ssid='%s'",
  893. MAC2STR(bss->bssid),
  894. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  895. return bss;
  896. }
  897. return NULL;
  898. }
  899. struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
  900. struct wpa_ssid **selected_ssid)
  901. {
  902. struct wpa_bss *selected = NULL;
  903. int prio;
  904. struct wpa_ssid *next_ssid = NULL;
  905. struct wpa_ssid *ssid;
  906. if (wpa_s->last_scan_res == NULL ||
  907. wpa_s->last_scan_res_used == 0)
  908. return NULL; /* no scan results from last update */
  909. if (wpa_s->next_ssid) {
  910. /* check that next_ssid is still valid */
  911. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  912. if (ssid == wpa_s->next_ssid)
  913. break;
  914. }
  915. next_ssid = ssid;
  916. wpa_s->next_ssid = NULL;
  917. }
  918. while (selected == NULL) {
  919. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  920. if (next_ssid && next_ssid->priority ==
  921. wpa_s->conf->pssid[prio]->priority) {
  922. selected = wpa_supplicant_select_bss(
  923. wpa_s, next_ssid, selected_ssid, 1);
  924. if (selected)
  925. break;
  926. }
  927. selected = wpa_supplicant_select_bss(
  928. wpa_s, wpa_s->conf->pssid[prio],
  929. selected_ssid, 0);
  930. if (selected)
  931. break;
  932. }
  933. if (selected == NULL && wpa_s->blacklist &&
  934. !wpa_s->countermeasures) {
  935. wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
  936. "blacklist and try again");
  937. wpa_blacklist_clear(wpa_s);
  938. wpa_s->blacklist_cleared++;
  939. } else if (selected == NULL)
  940. break;
  941. }
  942. ssid = *selected_ssid;
  943. if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set &&
  944. !ssid->passphrase && !ssid->ext_psk) {
  945. const char *field_name, *txt = NULL;
  946. wpa_dbg(wpa_s, MSG_DEBUG,
  947. "PSK/passphrase not yet available for the selected network");
  948. wpas_notify_network_request(wpa_s, ssid,
  949. WPA_CTRL_REQ_PSK_PASSPHRASE, NULL);
  950. field_name = wpa_supplicant_ctrl_req_to_string(
  951. WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt);
  952. if (field_name == NULL)
  953. return NULL;
  954. wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
  955. selected = NULL;
  956. }
  957. return selected;
  958. }
  959. static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
  960. int timeout_sec, int timeout_usec)
  961. {
  962. if (!wpa_supplicant_enabled_networks(wpa_s)) {
  963. /*
  964. * No networks are enabled; short-circuit request so
  965. * we don't wait timeout seconds before transitioning
  966. * to INACTIVE state.
  967. */
  968. wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
  969. "since there are no enabled networks");
  970. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  971. return;
  972. }
  973. wpa_s->scan_for_connection = 1;
  974. wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
  975. }
  976. int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
  977. struct wpa_bss *selected,
  978. struct wpa_ssid *ssid)
  979. {
  980. if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
  981. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
  982. "PBC session overlap");
  983. wpas_notify_wps_event_pbc_overlap(wpa_s);
  984. #ifdef CONFIG_P2P
  985. if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
  986. wpa_s->p2p_in_provisioning) {
  987. eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb,
  988. wpa_s, NULL);
  989. return -1;
  990. }
  991. #endif /* CONFIG_P2P */
  992. #ifdef CONFIG_WPS
  993. wpas_wps_pbc_overlap(wpa_s);
  994. wpas_wps_cancel(wpa_s);
  995. #endif /* CONFIG_WPS */
  996. return -1;
  997. }
  998. wpa_msg(wpa_s, MSG_DEBUG,
  999. "Considering connect request: reassociate: %d selected: "
  1000. MACSTR " bssid: " MACSTR " pending: " MACSTR
  1001. " wpa_state: %s ssid=%p current_ssid=%p",
  1002. wpa_s->reassociate, MAC2STR(selected->bssid),
  1003. MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
  1004. wpa_supplicant_state_txt(wpa_s->wpa_state),
  1005. ssid, wpa_s->current_ssid);
  1006. /*
  1007. * Do not trigger new association unless the BSSID has changed or if
  1008. * reassociation is requested. If we are in process of associating with
  1009. * the selected BSSID, do not trigger new attempt.
  1010. */
  1011. if (wpa_s->reassociate ||
  1012. (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
  1013. ((wpa_s->wpa_state != WPA_ASSOCIATING &&
  1014. wpa_s->wpa_state != WPA_AUTHENTICATING) ||
  1015. (!is_zero_ether_addr(wpa_s->pending_bssid) &&
  1016. os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
  1017. 0) ||
  1018. (is_zero_ether_addr(wpa_s->pending_bssid) &&
  1019. ssid != wpa_s->current_ssid)))) {
  1020. if (wpa_supplicant_scard_init(wpa_s, ssid)) {
  1021. wpa_supplicant_req_new_scan(wpa_s, 10, 0);
  1022. return 0;
  1023. }
  1024. wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
  1025. MAC2STR(selected->bssid));
  1026. wpa_supplicant_associate(wpa_s, selected, ssid);
  1027. } else {
  1028. wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
  1029. "connect with the selected AP");
  1030. }
  1031. return 0;
  1032. }
  1033. static struct wpa_ssid *
  1034. wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
  1035. {
  1036. int prio;
  1037. struct wpa_ssid *ssid;
  1038. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  1039. for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
  1040. {
  1041. if (wpas_network_disabled(wpa_s, ssid))
  1042. continue;
  1043. if (ssid->mode == IEEE80211_MODE_IBSS ||
  1044. ssid->mode == IEEE80211_MODE_AP ||
  1045. ssid->mode == IEEE80211_MODE_MESH)
  1046. return ssid;
  1047. }
  1048. }
  1049. return NULL;
  1050. }
  1051. /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
  1052. * on BSS added and BSS changed events */
  1053. static void wpa_supplicant_rsn_preauth_scan_results(
  1054. struct wpa_supplicant *wpa_s)
  1055. {
  1056. struct wpa_bss *bss;
  1057. if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
  1058. return;
  1059. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  1060. const u8 *ssid, *rsn;
  1061. ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
  1062. if (ssid == NULL)
  1063. continue;
  1064. rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  1065. if (rsn == NULL)
  1066. continue;
  1067. rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
  1068. }
  1069. }
  1070. static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
  1071. struct wpa_bss *selected,
  1072. struct wpa_ssid *ssid)
  1073. {
  1074. struct wpa_bss *current_bss = NULL;
  1075. #ifndef CONFIG_NO_ROAMING
  1076. int min_diff;
  1077. #endif /* CONFIG_NO_ROAMING */
  1078. if (wpa_s->reassociate)
  1079. return 1; /* explicit request to reassociate */
  1080. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1081. return 1; /* we are not associated; continue */
  1082. if (wpa_s->current_ssid == NULL)
  1083. return 1; /* unknown current SSID */
  1084. if (wpa_s->current_ssid != ssid)
  1085. return 1; /* different network block */
  1086. if (wpas_driver_bss_selection(wpa_s))
  1087. return 0; /* Driver-based roaming */
  1088. if (wpa_s->current_ssid->ssid)
  1089. current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
  1090. wpa_s->current_ssid->ssid,
  1091. wpa_s->current_ssid->ssid_len);
  1092. if (!current_bss)
  1093. current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
  1094. if (!current_bss)
  1095. return 1; /* current BSS not seen in scan results */
  1096. if (current_bss == selected)
  1097. return 0;
  1098. if (selected->last_update_idx > current_bss->last_update_idx)
  1099. return 1; /* current BSS not seen in the last scan */
  1100. #ifndef CONFIG_NO_ROAMING
  1101. wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
  1102. wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR
  1103. " level=%d snr=%d est_throughput=%u",
  1104. MAC2STR(current_bss->bssid), current_bss->level,
  1105. current_bss->snr, current_bss->est_throughput);
  1106. wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR
  1107. " level=%d snr=%d est_throughput=%u",
  1108. MAC2STR(selected->bssid), selected->level,
  1109. selected->snr, selected->est_throughput);
  1110. if (wpa_s->current_ssid->bssid_set &&
  1111. os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
  1112. 0) {
  1113. wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
  1114. "has preferred BSSID");
  1115. return 1;
  1116. }
  1117. if (selected->est_throughput > current_bss->est_throughput + 5000) {
  1118. wpa_dbg(wpa_s, MSG_DEBUG,
  1119. "Allow reassociation - selected BSS has better estimated throughput");
  1120. return 1;
  1121. }
  1122. if (current_bss->level < 0 && current_bss->level > selected->level) {
  1123. wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
  1124. "signal level");
  1125. return 0;
  1126. }
  1127. min_diff = 2;
  1128. if (current_bss->level < 0) {
  1129. if (current_bss->level < -85)
  1130. min_diff = 1;
  1131. else if (current_bss->level < -80)
  1132. min_diff = 2;
  1133. else if (current_bss->level < -75)
  1134. min_diff = 3;
  1135. else if (current_bss->level < -70)
  1136. min_diff = 4;
  1137. else
  1138. min_diff = 5;
  1139. }
  1140. if (abs(current_bss->level - selected->level) < min_diff) {
  1141. wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
  1142. "in signal level");
  1143. return 0;
  1144. }
  1145. return 1;
  1146. #else /* CONFIG_NO_ROAMING */
  1147. return 0;
  1148. #endif /* CONFIG_NO_ROAMING */
  1149. }
  1150. /* Return != 0 if no scan results could be fetched or if scan results should not
  1151. * be shared with other virtual interfaces. */
  1152. static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  1153. union wpa_event_data *data,
  1154. int own_request)
  1155. {
  1156. struct wpa_scan_results *scan_res = NULL;
  1157. int ret = 0;
  1158. int ap = 0;
  1159. #ifndef CONFIG_NO_RANDOM_POOL
  1160. size_t i, num;
  1161. #endif /* CONFIG_NO_RANDOM_POOL */
  1162. #ifdef CONFIG_AP
  1163. if (wpa_s->ap_iface)
  1164. ap = 1;
  1165. #endif /* CONFIG_AP */
  1166. wpa_supplicant_notify_scanning(wpa_s, 0);
  1167. scan_res = wpa_supplicant_get_scan_results(wpa_s,
  1168. data ? &data->scan_info :
  1169. NULL, 1);
  1170. if (scan_res == NULL) {
  1171. if (wpa_s->conf->ap_scan == 2 || ap ||
  1172. wpa_s->scan_res_handler == scan_only_handler)
  1173. return -1;
  1174. if (!own_request)
  1175. return -1;
  1176. if (data && data->scan_info.external_scan)
  1177. return -1;
  1178. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
  1179. "scanning again");
  1180. wpa_supplicant_req_new_scan(wpa_s, 1, 0);
  1181. ret = -1;
  1182. goto scan_work_done;
  1183. }
  1184. #ifndef CONFIG_NO_RANDOM_POOL
  1185. num = scan_res->num;
  1186. if (num > 10)
  1187. num = 10;
  1188. for (i = 0; i < num; i++) {
  1189. u8 buf[5];
  1190. struct wpa_scan_res *res = scan_res->res[i];
  1191. buf[0] = res->bssid[5];
  1192. buf[1] = res->qual & 0xff;
  1193. buf[2] = res->noise & 0xff;
  1194. buf[3] = res->level & 0xff;
  1195. buf[4] = res->tsf & 0xff;
  1196. random_add_randomness(buf, sizeof(buf));
  1197. }
  1198. #endif /* CONFIG_NO_RANDOM_POOL */
  1199. if (own_request && wpa_s->scan_res_handler &&
  1200. !(data && data->scan_info.external_scan)) {
  1201. void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
  1202. struct wpa_scan_results *scan_res);
  1203. scan_res_handler = wpa_s->scan_res_handler;
  1204. wpa_s->scan_res_handler = NULL;
  1205. scan_res_handler(wpa_s, scan_res);
  1206. ret = -2;
  1207. goto scan_work_done;
  1208. }
  1209. if (ap) {
  1210. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
  1211. #ifdef CONFIG_AP
  1212. if (wpa_s->ap_iface->scan_cb)
  1213. wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
  1214. #endif /* CONFIG_AP */
  1215. goto scan_work_done;
  1216. }
  1217. wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)",
  1218. wpa_s->own_scan_running,
  1219. data ? data->scan_info.external_scan : 0);
  1220. if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
  1221. wpa_s->manual_scan_use_id && wpa_s->own_scan_running &&
  1222. own_request && !(data && data->scan_info.external_scan)) {
  1223. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u",
  1224. wpa_s->manual_scan_id);
  1225. wpa_s->manual_scan_use_id = 0;
  1226. } else {
  1227. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  1228. }
  1229. wpas_notify_scan_results(wpa_s);
  1230. wpas_notify_scan_done(wpa_s, 1);
  1231. if (data && data->scan_info.external_scan) {
  1232. wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection");
  1233. wpa_scan_results_free(scan_res);
  1234. return 0;
  1235. }
  1236. if (wnm_scan_process(wpa_s, 1) > 0)
  1237. goto scan_work_done;
  1238. if (sme_proc_obss_scan(wpa_s) > 0)
  1239. goto scan_work_done;
  1240. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)))
  1241. goto scan_work_done;
  1242. if (autoscan_notify_scan(wpa_s, scan_res))
  1243. goto scan_work_done;
  1244. if (wpa_s->disconnected) {
  1245. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1246. goto scan_work_done;
  1247. }
  1248. if (!wpas_driver_bss_selection(wpa_s) &&
  1249. bgscan_notify_scan(wpa_s, scan_res) == 1)
  1250. goto scan_work_done;
  1251. wpas_wps_update_ap_info(wpa_s, scan_res);
  1252. wpa_scan_results_free(scan_res);
  1253. if (own_request && wpa_s->scan_work) {
  1254. struct wpa_radio_work *work = wpa_s->scan_work;
  1255. wpa_s->scan_work = NULL;
  1256. radio_work_done(work);
  1257. }
  1258. return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
  1259. scan_work_done:
  1260. wpa_scan_results_free(scan_res);
  1261. if (own_request && wpa_s->scan_work) {
  1262. struct wpa_radio_work *work = wpa_s->scan_work;
  1263. wpa_s->scan_work = NULL;
  1264. radio_work_done(work);
  1265. }
  1266. return ret;
  1267. }
  1268. static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
  1269. int new_scan, int own_request)
  1270. {
  1271. struct wpa_bss *selected;
  1272. struct wpa_ssid *ssid = NULL;
  1273. int time_to_reenable = wpas_reenabled_network_time(wpa_s);
  1274. if (time_to_reenable > 0) {
  1275. wpa_dbg(wpa_s, MSG_DEBUG,
  1276. "Postpone network selection by %d seconds since all networks are disabled",
  1277. time_to_reenable);
  1278. eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
  1279. eloop_register_timeout(time_to_reenable, 0,
  1280. wpas_network_reenabled, wpa_s, NULL);
  1281. return 0;
  1282. }
  1283. if (wpa_s->p2p_mgmt)
  1284. return 0; /* no normal connection on p2p_mgmt interface */
  1285. selected = wpa_supplicant_pick_network(wpa_s, &ssid);
  1286. if (selected) {
  1287. int skip;
  1288. skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
  1289. if (skip) {
  1290. if (new_scan)
  1291. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  1292. return 0;
  1293. }
  1294. if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
  1295. wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
  1296. return -1;
  1297. }
  1298. if (new_scan)
  1299. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  1300. /*
  1301. * Do not notify other virtual radios of scan results since we do not
  1302. * want them to start other associations at the same time.
  1303. */
  1304. return 1;
  1305. } else {
  1306. #ifdef CONFIG_MESH
  1307. if (wpa_s->ifmsh) {
  1308. wpa_msg(wpa_s, MSG_INFO,
  1309. "Avoiding join because we already joined a mesh group");
  1310. return 0;
  1311. }
  1312. #endif /* CONFIG_MESH */
  1313. wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
  1314. ssid = wpa_supplicant_pick_new_network(wpa_s);
  1315. if (ssid) {
  1316. wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
  1317. wpa_supplicant_associate(wpa_s, NULL, ssid);
  1318. if (new_scan)
  1319. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  1320. } else if (own_request) {
  1321. /*
  1322. * No SSID found. If SCAN results are as a result of
  1323. * own scan request and not due to a scan request on
  1324. * another shared interface, try another scan.
  1325. */
  1326. int timeout_sec = wpa_s->scan_interval;
  1327. int timeout_usec = 0;
  1328. #ifdef CONFIG_P2P
  1329. int res;
  1330. res = wpas_p2p_scan_no_go_seen(wpa_s);
  1331. if (res == 2)
  1332. return 2;
  1333. if (res == 1)
  1334. return 0;
  1335. if (wpa_s->p2p_in_provisioning ||
  1336. wpa_s->show_group_started ||
  1337. wpa_s->p2p_in_invitation) {
  1338. /*
  1339. * Use shorter wait during P2P Provisioning
  1340. * state and during P2P join-a-group operation
  1341. * to speed up group formation.
  1342. */
  1343. timeout_sec = 0;
  1344. timeout_usec = 250000;
  1345. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  1346. timeout_usec);
  1347. return 0;
  1348. }
  1349. #endif /* CONFIG_P2P */
  1350. #ifdef CONFIG_INTERWORKING
  1351. if (wpa_s->conf->auto_interworking &&
  1352. wpa_s->conf->interworking &&
  1353. wpa_s->conf->cred) {
  1354. wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
  1355. "start ANQP fetch since no matching "
  1356. "networks found");
  1357. wpa_s->network_select = 1;
  1358. wpa_s->auto_network_select = 1;
  1359. interworking_start_fetch_anqp(wpa_s);
  1360. return 1;
  1361. }
  1362. #endif /* CONFIG_INTERWORKING */
  1363. #ifdef CONFIG_WPS
  1364. if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) {
  1365. wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing");
  1366. timeout_sec = 0;
  1367. timeout_usec = 500000;
  1368. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  1369. timeout_usec);
  1370. return 0;
  1371. }
  1372. #endif /* CONFIG_WPS */
  1373. if (wpa_supplicant_req_sched_scan(wpa_s))
  1374. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  1375. timeout_usec);
  1376. wpa_msg_ctrl(wpa_s, MSG_INFO,
  1377. WPA_EVENT_NETWORK_NOT_FOUND);
  1378. }
  1379. }
  1380. return 0;
  1381. }
  1382. static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  1383. union wpa_event_data *data)
  1384. {
  1385. struct wpa_supplicant *ifs;
  1386. int res;
  1387. res = _wpa_supplicant_event_scan_results(wpa_s, data, 1);
  1388. if (res == 2) {
  1389. /*
  1390. * Interface may have been removed, so must not dereference
  1391. * wpa_s after this.
  1392. */
  1393. return 1;
  1394. }
  1395. if (res != 0) {
  1396. /*
  1397. * If no scan results could be fetched, then no need to
  1398. * notify those interfaces that did not actually request
  1399. * this scan. Similarly, if scan results started a new operation on this
  1400. * interface, do not notify other interfaces to avoid concurrent
  1401. * operations during a connection attempt.
  1402. */
  1403. return 0;
  1404. }
  1405. /*
  1406. * Check other interfaces to see if they share the same radio. If
  1407. * so, they get updated with this same scan info.
  1408. */
  1409. dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
  1410. radio_list) {
  1411. if (ifs != wpa_s) {
  1412. wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
  1413. "sibling", ifs->ifname);
  1414. _wpa_supplicant_event_scan_results(ifs, data, 0);
  1415. }
  1416. }
  1417. return 0;
  1418. }
  1419. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1420. int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
  1421. {
  1422. #ifdef CONFIG_NO_SCAN_PROCESSING
  1423. return -1;
  1424. #else /* CONFIG_NO_SCAN_PROCESSING */
  1425. struct os_reltime now;
  1426. if (wpa_s->last_scan_res_used == 0)
  1427. return -1;
  1428. os_get_reltime(&now);
  1429. if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
  1430. wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
  1431. return -1;
  1432. }
  1433. return wpas_select_network_from_last_scan(wpa_s, 0, 1);
  1434. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1435. }
  1436. #ifdef CONFIG_WNM
  1437. static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
  1438. {
  1439. struct wpa_supplicant *wpa_s = eloop_ctx;
  1440. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1441. return;
  1442. if (!wpa_s->no_keep_alive) {
  1443. wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
  1444. MAC2STR(wpa_s->bssid));
  1445. /* TODO: could skip this if normal data traffic has been sent */
  1446. /* TODO: Consider using some more appropriate data frame for
  1447. * this */
  1448. if (wpa_s->l2)
  1449. l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
  1450. (u8 *) "", 0);
  1451. }
  1452. #ifdef CONFIG_SME
  1453. if (wpa_s->sme.bss_max_idle_period) {
  1454. unsigned int msec;
  1455. msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
  1456. if (msec > 100)
  1457. msec -= 100;
  1458. eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
  1459. wnm_bss_keep_alive, wpa_s, NULL);
  1460. }
  1461. #endif /* CONFIG_SME */
  1462. }
  1463. static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
  1464. const u8 *ies, size_t ies_len)
  1465. {
  1466. struct ieee802_11_elems elems;
  1467. if (ies == NULL)
  1468. return;
  1469. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
  1470. return;
  1471. #ifdef CONFIG_SME
  1472. if (elems.bss_max_idle_period) {
  1473. unsigned int msec;
  1474. wpa_s->sme.bss_max_idle_period =
  1475. WPA_GET_LE16(elems.bss_max_idle_period);
  1476. wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
  1477. "TU)%s", wpa_s->sme.bss_max_idle_period,
  1478. (elems.bss_max_idle_period[2] & 0x01) ?
  1479. " (protected keep-live required)" : "");
  1480. if (wpa_s->sme.bss_max_idle_period == 0)
  1481. wpa_s->sme.bss_max_idle_period = 1;
  1482. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
  1483. eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
  1484. /* msec times 1000 */
  1485. msec = wpa_s->sme.bss_max_idle_period * 1024;
  1486. if (msec > 100)
  1487. msec -= 100;
  1488. eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
  1489. wnm_bss_keep_alive, wpa_s,
  1490. NULL);
  1491. }
  1492. }
  1493. #endif /* CONFIG_SME */
  1494. }
  1495. #endif /* CONFIG_WNM */
  1496. void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
  1497. {
  1498. #ifdef CONFIG_WNM
  1499. eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
  1500. #endif /* CONFIG_WNM */
  1501. }
  1502. #ifdef CONFIG_INTERWORKING
  1503. static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
  1504. size_t len)
  1505. {
  1506. int res;
  1507. wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
  1508. res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
  1509. if (res) {
  1510. wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
  1511. }
  1512. return res;
  1513. }
  1514. static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
  1515. const u8 *ies, size_t ies_len)
  1516. {
  1517. struct ieee802_11_elems elems;
  1518. if (ies == NULL)
  1519. return;
  1520. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
  1521. return;
  1522. if (elems.qos_map_set) {
  1523. wpas_qos_map_set(wpa_s, elems.qos_map_set,
  1524. elems.qos_map_set_len);
  1525. }
  1526. }
  1527. #endif /* CONFIG_INTERWORKING */
  1528. static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  1529. union wpa_event_data *data)
  1530. {
  1531. int l, len, found = 0, wpa_found, rsn_found;
  1532. const u8 *p;
  1533. #ifdef CONFIG_IEEE80211R
  1534. u8 bssid[ETH_ALEN];
  1535. #endif /* CONFIG_IEEE80211R */
  1536. wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
  1537. if (data->assoc_info.req_ies)
  1538. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  1539. data->assoc_info.req_ies_len);
  1540. if (data->assoc_info.resp_ies) {
  1541. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  1542. data->assoc_info.resp_ies_len);
  1543. #ifdef CONFIG_TDLS
  1544. wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
  1545. data->assoc_info.resp_ies_len);
  1546. #endif /* CONFIG_TDLS */
  1547. #ifdef CONFIG_WNM
  1548. wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
  1549. data->assoc_info.resp_ies_len);
  1550. #endif /* CONFIG_WNM */
  1551. #ifdef CONFIG_INTERWORKING
  1552. interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
  1553. data->assoc_info.resp_ies_len);
  1554. #endif /* CONFIG_INTERWORKING */
  1555. }
  1556. if (data->assoc_info.beacon_ies)
  1557. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  1558. data->assoc_info.beacon_ies,
  1559. data->assoc_info.beacon_ies_len);
  1560. if (data->assoc_info.freq)
  1561. wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
  1562. data->assoc_info.freq);
  1563. p = data->assoc_info.req_ies;
  1564. l = data->assoc_info.req_ies_len;
  1565. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  1566. while (p && l >= 2) {
  1567. len = p[1] + 2;
  1568. if (len > l) {
  1569. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1570. p, l);
  1571. break;
  1572. }
  1573. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1574. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  1575. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  1576. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  1577. break;
  1578. found = 1;
  1579. wpa_find_assoc_pmkid(wpa_s);
  1580. break;
  1581. }
  1582. l -= len;
  1583. p += len;
  1584. }
  1585. if (!found && data->assoc_info.req_ies)
  1586. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  1587. #ifdef CONFIG_IEEE80211R
  1588. #ifdef CONFIG_SME
  1589. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  1590. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  1591. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  1592. data->assoc_info.resp_ies,
  1593. data->assoc_info.resp_ies_len,
  1594. bssid) < 0) {
  1595. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  1596. "Reassociation Response failed");
  1597. wpa_supplicant_deauthenticate(
  1598. wpa_s, WLAN_REASON_INVALID_IE);
  1599. return -1;
  1600. }
  1601. }
  1602. p = data->assoc_info.resp_ies;
  1603. l = data->assoc_info.resp_ies_len;
  1604. #ifdef CONFIG_WPS_STRICT
  1605. if (p && wpa_s->current_ssid &&
  1606. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  1607. struct wpabuf *wps;
  1608. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  1609. if (wps == NULL) {
  1610. wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
  1611. "include WPS IE in (Re)Association Response");
  1612. return -1;
  1613. }
  1614. if (wps_validate_assoc_resp(wps) < 0) {
  1615. wpabuf_free(wps);
  1616. wpa_supplicant_deauthenticate(
  1617. wpa_s, WLAN_REASON_INVALID_IE);
  1618. return -1;
  1619. }
  1620. wpabuf_free(wps);
  1621. }
  1622. #endif /* CONFIG_WPS_STRICT */
  1623. /* Go through the IEs and make a copy of the MDIE, if present. */
  1624. while (p && l >= 2) {
  1625. len = p[1] + 2;
  1626. if (len > l) {
  1627. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1628. p, l);
  1629. break;
  1630. }
  1631. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  1632. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  1633. wpa_s->sme.ft_used = 1;
  1634. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  1635. MOBILITY_DOMAIN_ID_LEN);
  1636. break;
  1637. }
  1638. l -= len;
  1639. p += len;
  1640. }
  1641. #endif /* CONFIG_SME */
  1642. /* Process FT when SME is in the driver */
  1643. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
  1644. wpa_ft_is_completed(wpa_s->wpa)) {
  1645. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  1646. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  1647. data->assoc_info.resp_ies,
  1648. data->assoc_info.resp_ies_len,
  1649. bssid) < 0) {
  1650. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  1651. "Reassociation Response failed");
  1652. wpa_supplicant_deauthenticate(
  1653. wpa_s, WLAN_REASON_INVALID_IE);
  1654. return -1;
  1655. }
  1656. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
  1657. }
  1658. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  1659. data->assoc_info.resp_ies_len);
  1660. #endif /* CONFIG_IEEE80211R */
  1661. /* WPA/RSN IE from Beacon/ProbeResp */
  1662. p = data->assoc_info.beacon_ies;
  1663. l = data->assoc_info.beacon_ies_len;
  1664. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  1665. */
  1666. wpa_found = rsn_found = 0;
  1667. while (p && l >= 2) {
  1668. len = p[1] + 2;
  1669. if (len > l) {
  1670. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  1671. p, l);
  1672. break;
  1673. }
  1674. if (!wpa_found &&
  1675. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1676. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  1677. wpa_found = 1;
  1678. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  1679. }
  1680. if (!rsn_found &&
  1681. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  1682. rsn_found = 1;
  1683. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  1684. }
  1685. l -= len;
  1686. p += len;
  1687. }
  1688. if (!wpa_found && data->assoc_info.beacon_ies)
  1689. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  1690. if (!rsn_found && data->assoc_info.beacon_ies)
  1691. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  1692. if (wpa_found || rsn_found)
  1693. wpa_s->ap_ies_from_associnfo = 1;
  1694. #ifdef CONFIG_FST
  1695. wpabuf_free(wpa_s->received_mb_ies);
  1696. wpa_s->received_mb_ies = NULL;
  1697. if (wpa_s->fst) {
  1698. struct mb_ies_info mb_ies;
  1699. wpa_printf(MSG_DEBUG, "Looking for MB IE");
  1700. if (!mb_ies_info_by_ies(&mb_ies, data->assoc_info.resp_ies,
  1701. data->assoc_info.resp_ies_len))
  1702. wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies);
  1703. }
  1704. #endif /* CONFIG_FST */
  1705. if (wpa_s->assoc_freq && data->assoc_info.freq &&
  1706. wpa_s->assoc_freq != data->assoc_info.freq) {
  1707. wpa_printf(MSG_DEBUG, "Operating frequency changed from "
  1708. "%u to %u MHz",
  1709. wpa_s->assoc_freq, data->assoc_info.freq);
  1710. wpa_supplicant_update_scan_results(wpa_s);
  1711. }
  1712. wpa_s->assoc_freq = data->assoc_info.freq;
  1713. return 0;
  1714. }
  1715. static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
  1716. {
  1717. const u8 *bss_wpa = NULL, *bss_rsn = NULL;
  1718. if (!wpa_s->current_bss || !wpa_s->current_ssid)
  1719. return -1;
  1720. if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
  1721. return 0;
  1722. bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
  1723. WPA_IE_VENDOR_TYPE);
  1724. bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
  1725. if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
  1726. bss_wpa ? 2 + bss_wpa[1] : 0) ||
  1727. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
  1728. bss_rsn ? 2 + bss_rsn[1] : 0))
  1729. return -1;
  1730. return 0;
  1731. }
  1732. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  1733. union wpa_event_data *data)
  1734. {
  1735. u8 bssid[ETH_ALEN];
  1736. int ft_completed;
  1737. int new_bss = 0;
  1738. #ifdef CONFIG_AP
  1739. if (wpa_s->ap_iface) {
  1740. if (!data)
  1741. return;
  1742. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  1743. data->assoc_info.addr,
  1744. data->assoc_info.req_ies,
  1745. data->assoc_info.req_ies_len,
  1746. data->assoc_info.reassoc);
  1747. return;
  1748. }
  1749. #endif /* CONFIG_AP */
  1750. eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
  1751. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  1752. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  1753. return;
  1754. if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
  1755. wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
  1756. wpa_supplicant_deauthenticate(
  1757. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1758. return;
  1759. }
  1760. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  1761. if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
  1762. wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  1763. MACSTR, MAC2STR(bssid));
  1764. new_bss = 1;
  1765. random_add_randomness(bssid, ETH_ALEN);
  1766. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  1767. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1768. wpas_notify_bssid_changed(wpa_s);
  1769. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  1770. wpa_clear_keys(wpa_s, bssid);
  1771. }
  1772. if (wpa_supplicant_select_config(wpa_s) < 0) {
  1773. wpa_supplicant_deauthenticate(
  1774. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1775. return;
  1776. }
  1777. }
  1778. if (wpa_s->conf->ap_scan == 1 &&
  1779. wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
  1780. if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
  1781. wpa_msg(wpa_s, MSG_WARNING,
  1782. "WPA/RSN IEs not updated");
  1783. }
  1784. #ifdef CONFIG_SME
  1785. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  1786. wpa_s->sme.prev_bssid_set = 1;
  1787. wpa_s->sme.last_unprot_disconnect.sec = 0;
  1788. #endif /* CONFIG_SME */
  1789. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  1790. if (wpa_s->current_ssid) {
  1791. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  1792. * initialized before association, but for other modes,
  1793. * initialize PC/SC here, if the current configuration needs
  1794. * smartcard or SIM/USIM. */
  1795. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  1796. }
  1797. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  1798. if (wpa_s->l2)
  1799. l2_packet_notify_auth_start(wpa_s->l2);
  1800. /*
  1801. * Set portEnabled first to FALSE in order to get EAP state machine out
  1802. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  1803. * state machine may transit to AUTHENTICATING state based on obsolete
  1804. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  1805. * AUTHENTICATED without ever giving chance to EAP state machine to
  1806. * reset the state.
  1807. */
  1808. if (!ft_completed) {
  1809. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  1810. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  1811. }
  1812. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  1813. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  1814. /* 802.1X::portControl = Auto */
  1815. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  1816. wpa_s->eapol_received = 0;
  1817. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1818. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  1819. (wpa_s->current_ssid &&
  1820. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  1821. if (wpa_s->current_ssid &&
  1822. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
  1823. (wpa_s->drv_flags &
  1824. WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
  1825. /*
  1826. * Set the key after having received joined-IBSS event
  1827. * from the driver.
  1828. */
  1829. wpa_supplicant_set_wpa_none_key(wpa_s,
  1830. wpa_s->current_ssid);
  1831. }
  1832. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1833. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1834. } else if (!ft_completed) {
  1835. /* Timeout for receiving the first EAPOL packet */
  1836. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  1837. }
  1838. wpa_supplicant_cancel_scan(wpa_s);
  1839. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1840. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1841. /*
  1842. * We are done; the driver will take care of RSN 4-way
  1843. * handshake.
  1844. */
  1845. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1846. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1847. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1848. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1849. } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1850. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1851. /*
  1852. * The driver will take care of RSN 4-way handshake, so we need
  1853. * to allow EAPOL supplicant to complete its work without
  1854. * waiting for WPA supplicant.
  1855. */
  1856. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1857. } else if (ft_completed) {
  1858. /*
  1859. * FT protocol completed - make sure EAPOL state machine ends
  1860. * up in authenticated.
  1861. */
  1862. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1863. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1864. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1865. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1866. }
  1867. wpa_s->last_eapol_matches_bssid = 0;
  1868. if (wpa_s->pending_eapol_rx) {
  1869. struct os_reltime now, age;
  1870. os_get_reltime(&now);
  1871. os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  1872. if (age.sec == 0 && age.usec < 100000 &&
  1873. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  1874. 0) {
  1875. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
  1876. "frame that was received just before "
  1877. "association notification");
  1878. wpa_supplicant_rx_eapol(
  1879. wpa_s, wpa_s->pending_eapol_rx_src,
  1880. wpabuf_head(wpa_s->pending_eapol_rx),
  1881. wpabuf_len(wpa_s->pending_eapol_rx));
  1882. }
  1883. wpabuf_free(wpa_s->pending_eapol_rx);
  1884. wpa_s->pending_eapol_rx = NULL;
  1885. }
  1886. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1887. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1888. wpa_s->current_ssid &&
  1889. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
  1890. /* Set static WEP keys again */
  1891. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1892. }
  1893. #ifdef CONFIG_IBSS_RSN
  1894. if (wpa_s->current_ssid &&
  1895. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  1896. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  1897. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
  1898. wpa_s->ibss_rsn == NULL) {
  1899. wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
  1900. if (!wpa_s->ibss_rsn) {
  1901. wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
  1902. wpa_supplicant_deauthenticate(
  1903. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1904. return;
  1905. }
  1906. ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
  1907. }
  1908. #endif /* CONFIG_IBSS_RSN */
  1909. wpas_wps_notify_assoc(wpa_s, bssid);
  1910. if (data) {
  1911. wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
  1912. data->assoc_info.resp_ies_len,
  1913. &data->assoc_info.wmm_params);
  1914. if (wpa_s->reassoc_same_bss)
  1915. wmm_ac_restore_tspecs(wpa_s);
  1916. }
  1917. }
  1918. static int disconnect_reason_recoverable(u16 reason_code)
  1919. {
  1920. return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
  1921. reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
  1922. reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
  1923. }
  1924. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1925. u16 reason_code,
  1926. int locally_generated)
  1927. {
  1928. const u8 *bssid;
  1929. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1930. /*
  1931. * At least Host AP driver and a Prism3 card seemed to be
  1932. * generating streams of disconnected events when configuring
  1933. * IBSS for WPA-None. Ignore them for now.
  1934. */
  1935. return;
  1936. }
  1937. bssid = wpa_s->bssid;
  1938. if (is_zero_ether_addr(bssid))
  1939. bssid = wpa_s->pending_bssid;
  1940. if (!is_zero_ether_addr(bssid) ||
  1941. wpa_s->wpa_state >= WPA_AUTHENTICATING) {
  1942. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1943. " reason=%d%s",
  1944. MAC2STR(bssid), reason_code,
  1945. locally_generated ? " locally_generated=1" : "");
  1946. }
  1947. }
  1948. static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
  1949. int locally_generated)
  1950. {
  1951. if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
  1952. !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  1953. return 0; /* Not in 4-way handshake with PSK */
  1954. /*
  1955. * It looks like connection was lost while trying to go through PSK
  1956. * 4-way handshake. Filter out known disconnection cases that are caused
  1957. * by something else than PSK mismatch to avoid confusing reports.
  1958. */
  1959. if (locally_generated) {
  1960. if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
  1961. return 0;
  1962. }
  1963. return 1;
  1964. }
  1965. static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
  1966. u16 reason_code,
  1967. int locally_generated)
  1968. {
  1969. const u8 *bssid;
  1970. int authenticating;
  1971. u8 prev_pending_bssid[ETH_ALEN];
  1972. struct wpa_bss *fast_reconnect = NULL;
  1973. struct wpa_ssid *fast_reconnect_ssid = NULL;
  1974. struct wpa_ssid *last_ssid;
  1975. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1976. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1977. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1978. /*
  1979. * At least Host AP driver and a Prism3 card seemed to be
  1980. * generating streams of disconnected events when configuring
  1981. * IBSS for WPA-None. Ignore them for now.
  1982. */
  1983. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
  1984. "IBSS/WPA-None mode");
  1985. return;
  1986. }
  1987. if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
  1988. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1989. "pre-shared key may be incorrect");
  1990. if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
  1991. return; /* P2P group removed */
  1992. wpas_auth_failed(wpa_s, "WRONG_KEY");
  1993. }
  1994. if (!wpa_s->disconnected &&
  1995. (!wpa_s->auto_reconnect_disabled ||
  1996. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
  1997. wpas_wps_searching(wpa_s))) {
  1998. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
  1999. "reconnect (wps=%d/%d wpa_state=%d)",
  2000. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
  2001. wpas_wps_searching(wpa_s),
  2002. wpa_s->wpa_state);
  2003. if (wpa_s->wpa_state == WPA_COMPLETED &&
  2004. wpa_s->current_ssid &&
  2005. wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
  2006. !locally_generated &&
  2007. disconnect_reason_recoverable(reason_code)) {
  2008. /*
  2009. * It looks like the AP has dropped association with
  2010. * us, but could allow us to get back in. Try to
  2011. * reconnect to the same BSS without full scan to save
  2012. * time for some common cases.
  2013. */
  2014. fast_reconnect = wpa_s->current_bss;
  2015. fast_reconnect_ssid = wpa_s->current_ssid;
  2016. } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  2017. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  2018. else
  2019. wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
  2020. "immediate scan");
  2021. } else {
  2022. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
  2023. "try to re-connect");
  2024. wpa_s->reassociate = 0;
  2025. wpa_s->disconnected = 1;
  2026. if (!wpa_s->pno)
  2027. wpa_supplicant_cancel_sched_scan(wpa_s);
  2028. }
  2029. bssid = wpa_s->bssid;
  2030. if (is_zero_ether_addr(bssid))
  2031. bssid = wpa_s->pending_bssid;
  2032. if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
  2033. wpas_connection_failed(wpa_s, bssid);
  2034. wpa_sm_notify_disassoc(wpa_s->wpa);
  2035. if (locally_generated)
  2036. wpa_s->disconnect_reason = -reason_code;
  2037. else
  2038. wpa_s->disconnect_reason = reason_code;
  2039. wpas_notify_disconnect_reason(wpa_s);
  2040. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  2041. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
  2042. wpa_clear_keys(wpa_s, wpa_s->bssid);
  2043. }
  2044. last_ssid = wpa_s->current_ssid;
  2045. wpa_supplicant_mark_disassoc(wpa_s);
  2046. if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
  2047. sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
  2048. wpa_s->current_ssid = last_ssid;
  2049. }
  2050. if (fast_reconnect &&
  2051. !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
  2052. !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
  2053. !disallowed_ssid(wpa_s, fast_reconnect->ssid,
  2054. fast_reconnect->ssid_len) &&
  2055. !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) {
  2056. #ifndef CONFIG_NO_SCAN_PROCESSING
  2057. wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
  2058. if (wpa_supplicant_connect(wpa_s, fast_reconnect,
  2059. fast_reconnect_ssid) < 0) {
  2060. /* Recover through full scan */
  2061. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  2062. }
  2063. #endif /* CONFIG_NO_SCAN_PROCESSING */
  2064. } else if (fast_reconnect) {
  2065. /*
  2066. * Could not reconnect to the same BSS due to network being
  2067. * disabled. Use a new scan to match the alternative behavior
  2068. * above, i.e., to continue automatic reconnection attempt in a
  2069. * way that enforces disabled network rules.
  2070. */
  2071. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  2072. }
  2073. }
  2074. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  2075. void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
  2076. {
  2077. struct wpa_supplicant *wpa_s = eloop_ctx;
  2078. if (!wpa_s->pending_mic_error_report)
  2079. return;
  2080. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
  2081. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  2082. wpa_s->pending_mic_error_report = 0;
  2083. }
  2084. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  2085. static void
  2086. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  2087. union wpa_event_data *data)
  2088. {
  2089. int pairwise;
  2090. struct os_reltime t;
  2091. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  2092. pairwise = (data && data->michael_mic_failure.unicast);
  2093. os_get_reltime(&t);
  2094. if ((wpa_s->last_michael_mic_error.sec &&
  2095. !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
  2096. wpa_s->pending_mic_error_report) {
  2097. if (wpa_s->pending_mic_error_report) {
  2098. /*
  2099. * Send the pending MIC error report immediately since
  2100. * we are going to start countermeasures and AP better
  2101. * do the same.
  2102. */
  2103. wpa_sm_key_request(wpa_s->wpa, 1,
  2104. wpa_s->pending_mic_error_pairwise);
  2105. }
  2106. /* Send the new MIC error report immediately since we are going
  2107. * to start countermeasures and AP better do the same.
  2108. */
  2109. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  2110. /* initialize countermeasures */
  2111. wpa_s->countermeasures = 1;
  2112. wpa_blacklist_add(wpa_s, wpa_s->bssid);
  2113. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  2114. /*
  2115. * Need to wait for completion of request frame. We do not get
  2116. * any callback for the message completion, so just wait a
  2117. * short while and hope for the best. */
  2118. os_sleep(0, 10000);
  2119. wpa_drv_set_countermeasures(wpa_s, 1);
  2120. wpa_supplicant_deauthenticate(wpa_s,
  2121. WLAN_REASON_MICHAEL_MIC_FAILURE);
  2122. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  2123. wpa_s, NULL);
  2124. eloop_register_timeout(60, 0,
  2125. wpa_supplicant_stop_countermeasures,
  2126. wpa_s, NULL);
  2127. /* TODO: mark the AP rejected for 60 second. STA is
  2128. * allowed to associate with another AP.. */
  2129. } else {
  2130. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  2131. if (wpa_s->mic_errors_seen) {
  2132. /*
  2133. * Reduce the effectiveness of Michael MIC error
  2134. * reports as a means for attacking against TKIP if
  2135. * more than one MIC failure is noticed with the same
  2136. * PTK. We delay the transmission of the reports by a
  2137. * random time between 0 and 60 seconds in order to
  2138. * force the attacker wait 60 seconds before getting
  2139. * the information on whether a frame resulted in a MIC
  2140. * failure.
  2141. */
  2142. u8 rval[4];
  2143. int sec;
  2144. if (os_get_random(rval, sizeof(rval)) < 0)
  2145. sec = os_random() % 60;
  2146. else
  2147. sec = WPA_GET_BE32(rval) % 60;
  2148. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
  2149. "report %d seconds", sec);
  2150. wpa_s->pending_mic_error_report = 1;
  2151. wpa_s->pending_mic_error_pairwise = pairwise;
  2152. eloop_cancel_timeout(
  2153. wpa_supplicant_delayed_mic_error_report,
  2154. wpa_s, NULL);
  2155. eloop_register_timeout(
  2156. sec, os_random() % 1000000,
  2157. wpa_supplicant_delayed_mic_error_report,
  2158. wpa_s, NULL);
  2159. } else {
  2160. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  2161. }
  2162. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  2163. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  2164. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  2165. }
  2166. wpa_s->last_michael_mic_error = t;
  2167. wpa_s->mic_errors_seen++;
  2168. }
  2169. #ifdef CONFIG_TERMINATE_ONLASTIF
  2170. static int any_interfaces(struct wpa_supplicant *head)
  2171. {
  2172. struct wpa_supplicant *wpa_s;
  2173. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  2174. if (!wpa_s->interface_removed)
  2175. return 1;
  2176. return 0;
  2177. }
  2178. #endif /* CONFIG_TERMINATE_ONLASTIF */
  2179. static void
  2180. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  2181. union wpa_event_data *data)
  2182. {
  2183. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  2184. return;
  2185. switch (data->interface_status.ievent) {
  2186. case EVENT_INTERFACE_ADDED:
  2187. if (!wpa_s->interface_removed)
  2188. break;
  2189. wpa_s->interface_removed = 0;
  2190. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
  2191. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  2192. wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
  2193. "driver after interface was added");
  2194. }
  2195. #ifdef CONFIG_P2P
  2196. if (!wpa_s->global->p2p &&
  2197. !wpa_s->global->p2p_disabled &&
  2198. !wpa_s->conf->p2p_disabled &&
  2199. (wpa_s->drv_flags &
  2200. WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
  2201. wpas_p2p_add_p2pdev_interface(
  2202. wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
  2203. wpa_printf(MSG_INFO,
  2204. "P2P: Failed to enable P2P Device interface");
  2205. /* Try to continue without. P2P will be disabled. */
  2206. }
  2207. #endif /* CONFIG_P2P */
  2208. break;
  2209. case EVENT_INTERFACE_REMOVED:
  2210. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
  2211. wpa_s->interface_removed = 1;
  2212. wpa_supplicant_mark_disassoc(wpa_s);
  2213. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  2214. l2_packet_deinit(wpa_s->l2);
  2215. wpa_s->l2 = NULL;
  2216. #ifdef CONFIG_P2P
  2217. if (wpa_s->global->p2p &&
  2218. wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
  2219. (wpa_s->drv_flags &
  2220. WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
  2221. wpa_dbg(wpa_s, MSG_DEBUG,
  2222. "Removing P2P Device interface");
  2223. wpa_supplicant_remove_iface(
  2224. wpa_s->global, wpa_s->global->p2p_init_wpa_s,
  2225. 0);
  2226. wpa_s->global->p2p_init_wpa_s = NULL;
  2227. }
  2228. #endif /* CONFIG_P2P */
  2229. #ifdef CONFIG_TERMINATE_ONLASTIF
  2230. /* check if last interface */
  2231. if (!any_interfaces(wpa_s->global->ifaces))
  2232. eloop_terminate();
  2233. #endif /* CONFIG_TERMINATE_ONLASTIF */
  2234. break;
  2235. }
  2236. }
  2237. #ifdef CONFIG_PEERKEY
  2238. static void
  2239. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  2240. union wpa_event_data *data)
  2241. {
  2242. if (data == NULL)
  2243. return;
  2244. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  2245. }
  2246. #endif /* CONFIG_PEERKEY */
  2247. #ifdef CONFIG_TDLS
  2248. static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
  2249. union wpa_event_data *data)
  2250. {
  2251. if (data == NULL)
  2252. return;
  2253. switch (data->tdls.oper) {
  2254. case TDLS_REQUEST_SETUP:
  2255. wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
  2256. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  2257. wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
  2258. else
  2259. wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
  2260. break;
  2261. case TDLS_REQUEST_TEARDOWN:
  2262. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  2263. wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
  2264. data->tdls.reason_code);
  2265. else
  2266. wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
  2267. data->tdls.peer);
  2268. break;
  2269. case TDLS_REQUEST_DISCOVER:
  2270. wpa_tdls_send_discovery_request(wpa_s->wpa,
  2271. data->tdls.peer);
  2272. break;
  2273. }
  2274. }
  2275. #endif /* CONFIG_TDLS */
  2276. #ifdef CONFIG_WNM
  2277. static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
  2278. union wpa_event_data *data)
  2279. {
  2280. if (data == NULL)
  2281. return;
  2282. switch (data->wnm.oper) {
  2283. case WNM_OPER_SLEEP:
  2284. wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
  2285. "(action=%d, intval=%d)",
  2286. data->wnm.sleep_action, data->wnm.sleep_intval);
  2287. ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
  2288. data->wnm.sleep_intval, NULL);
  2289. break;
  2290. }
  2291. }
  2292. #endif /* CONFIG_WNM */
  2293. #ifdef CONFIG_IEEE80211R
  2294. static void
  2295. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  2296. union wpa_event_data *data)
  2297. {
  2298. if (data == NULL)
  2299. return;
  2300. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  2301. data->ft_ies.ies_len,
  2302. data->ft_ies.ft_action,
  2303. data->ft_ies.target_ap,
  2304. data->ft_ies.ric_ies,
  2305. data->ft_ies.ric_ies_len) < 0) {
  2306. /* TODO: prevent MLME/driver from trying to associate? */
  2307. }
  2308. }
  2309. #endif /* CONFIG_IEEE80211R */
  2310. #ifdef CONFIG_IBSS_RSN
  2311. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  2312. union wpa_event_data *data)
  2313. {
  2314. struct wpa_ssid *ssid;
  2315. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  2316. return;
  2317. if (data == NULL)
  2318. return;
  2319. ssid = wpa_s->current_ssid;
  2320. if (ssid == NULL)
  2321. return;
  2322. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  2323. return;
  2324. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  2325. }
  2326. static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
  2327. union wpa_event_data *data)
  2328. {
  2329. struct wpa_ssid *ssid = wpa_s->current_ssid;
  2330. if (ssid == NULL)
  2331. return;
  2332. /* check if the ssid is correctly configured as IBSS/RSN */
  2333. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  2334. return;
  2335. ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
  2336. data->rx_mgmt.frame_len);
  2337. }
  2338. #endif /* CONFIG_IBSS_RSN */
  2339. #ifdef CONFIG_IEEE80211R
  2340. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  2341. size_t len)
  2342. {
  2343. const u8 *sta_addr, *target_ap_addr;
  2344. u16 status;
  2345. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  2346. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  2347. return; /* only SME case supported for now */
  2348. if (len < 1 + 2 * ETH_ALEN + 2)
  2349. return;
  2350. if (data[0] != 2)
  2351. return; /* Only FT Action Response is supported for now */
  2352. sta_addr = data + 1;
  2353. target_ap_addr = data + 1 + ETH_ALEN;
  2354. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  2355. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
  2356. MACSTR " TargetAP " MACSTR " status %u",
  2357. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  2358. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  2359. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  2360. " in FT Action Response", MAC2STR(sta_addr));
  2361. return;
  2362. }
  2363. if (status) {
  2364. wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
  2365. "failure (status code %d)", status);
  2366. /* TODO: report error to FT code(?) */
  2367. return;
  2368. }
  2369. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  2370. len - (1 + 2 * ETH_ALEN + 2), 1,
  2371. target_ap_addr, NULL, 0) < 0)
  2372. return;
  2373. #ifdef CONFIG_SME
  2374. {
  2375. struct wpa_bss *bss;
  2376. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  2377. if (bss)
  2378. wpa_s->sme.freq = bss->freq;
  2379. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  2380. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  2381. WLAN_AUTH_FT);
  2382. }
  2383. #endif /* CONFIG_SME */
  2384. }
  2385. #endif /* CONFIG_IEEE80211R */
  2386. static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
  2387. struct unprot_deauth *e)
  2388. {
  2389. #ifdef CONFIG_IEEE80211W
  2390. wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
  2391. "dropped: " MACSTR " -> " MACSTR
  2392. " (reason code %u)",
  2393. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  2394. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  2395. #endif /* CONFIG_IEEE80211W */
  2396. }
  2397. static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
  2398. struct unprot_disassoc *e)
  2399. {
  2400. #ifdef CONFIG_IEEE80211W
  2401. wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
  2402. "dropped: " MACSTR " -> " MACSTR
  2403. " (reason code %u)",
  2404. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  2405. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  2406. #endif /* CONFIG_IEEE80211W */
  2407. }
  2408. static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
  2409. u16 reason_code, int locally_generated,
  2410. const u8 *ie, size_t ie_len, int deauth)
  2411. {
  2412. #ifdef CONFIG_AP
  2413. if (wpa_s->ap_iface && addr) {
  2414. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
  2415. return;
  2416. }
  2417. if (wpa_s->ap_iface) {
  2418. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
  2419. return;
  2420. }
  2421. #endif /* CONFIG_AP */
  2422. if (!locally_generated)
  2423. wpa_s->own_disconnect_req = 0;
  2424. wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
  2425. if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
  2426. ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  2427. (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
  2428. eapol_sm_failed(wpa_s->eapol))) &&
  2429. !wpa_s->eap_expected_failure))
  2430. wpas_auth_failed(wpa_s, "AUTH_FAILED");
  2431. #ifdef CONFIG_P2P
  2432. if (deauth && reason_code > 0) {
  2433. if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
  2434. locally_generated) > 0) {
  2435. /*
  2436. * The interface was removed, so cannot continue
  2437. * processing any additional operations after this.
  2438. */
  2439. return;
  2440. }
  2441. }
  2442. #endif /* CONFIG_P2P */
  2443. wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
  2444. locally_generated);
  2445. }
  2446. static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
  2447. struct disassoc_info *info)
  2448. {
  2449. u16 reason_code = 0;
  2450. int locally_generated = 0;
  2451. const u8 *addr = NULL;
  2452. const u8 *ie = NULL;
  2453. size_t ie_len = 0;
  2454. wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
  2455. if (info) {
  2456. addr = info->addr;
  2457. ie = info->ie;
  2458. ie_len = info->ie_len;
  2459. reason_code = info->reason_code;
  2460. locally_generated = info->locally_generated;
  2461. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
  2462. locally_generated ? " (locally generated)" : "");
  2463. if (addr)
  2464. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  2465. MAC2STR(addr));
  2466. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  2467. ie, ie_len);
  2468. }
  2469. #ifdef CONFIG_AP
  2470. if (wpa_s->ap_iface && info && info->addr) {
  2471. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
  2472. return;
  2473. }
  2474. if (wpa_s->ap_iface) {
  2475. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
  2476. return;
  2477. }
  2478. #endif /* CONFIG_AP */
  2479. #ifdef CONFIG_P2P
  2480. if (info) {
  2481. wpas_p2p_disassoc_notif(
  2482. wpa_s, info->addr, reason_code, info->ie, info->ie_len,
  2483. locally_generated);
  2484. }
  2485. #endif /* CONFIG_P2P */
  2486. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2487. sme_event_disassoc(wpa_s, info);
  2488. wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
  2489. ie, ie_len, 0);
  2490. }
  2491. static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
  2492. struct deauth_info *info)
  2493. {
  2494. u16 reason_code = 0;
  2495. int locally_generated = 0;
  2496. const u8 *addr = NULL;
  2497. const u8 *ie = NULL;
  2498. size_t ie_len = 0;
  2499. wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
  2500. if (info) {
  2501. addr = info->addr;
  2502. ie = info->ie;
  2503. ie_len = info->ie_len;
  2504. reason_code = info->reason_code;
  2505. locally_generated = info->locally_generated;
  2506. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
  2507. reason_code,
  2508. locally_generated ? " (locally generated)" : "");
  2509. if (addr) {
  2510. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  2511. MAC2STR(addr));
  2512. }
  2513. wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
  2514. ie, ie_len);
  2515. }
  2516. wpa_reset_ft_completed(wpa_s->wpa);
  2517. wpas_event_disconnect(wpa_s, addr, reason_code,
  2518. locally_generated, ie, ie_len, 1);
  2519. }
  2520. static const char * reg_init_str(enum reg_change_initiator init)
  2521. {
  2522. switch (init) {
  2523. case REGDOM_SET_BY_CORE:
  2524. return "CORE";
  2525. case REGDOM_SET_BY_USER:
  2526. return "USER";
  2527. case REGDOM_SET_BY_DRIVER:
  2528. return "DRIVER";
  2529. case REGDOM_SET_BY_COUNTRY_IE:
  2530. return "COUNTRY_IE";
  2531. case REGDOM_BEACON_HINT:
  2532. return "BEACON_HINT";
  2533. }
  2534. return "?";
  2535. }
  2536. static const char * reg_type_str(enum reg_type type)
  2537. {
  2538. switch (type) {
  2539. case REGDOM_TYPE_UNKNOWN:
  2540. return "UNKNOWN";
  2541. case REGDOM_TYPE_COUNTRY:
  2542. return "COUNTRY";
  2543. case REGDOM_TYPE_WORLD:
  2544. return "WORLD";
  2545. case REGDOM_TYPE_CUSTOM_WORLD:
  2546. return "CUSTOM_WORLD";
  2547. case REGDOM_TYPE_INTERSECTION:
  2548. return "INTERSECTION";
  2549. }
  2550. return "?";
  2551. }
  2552. static void wpa_supplicant_update_channel_list(
  2553. struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
  2554. {
  2555. struct wpa_supplicant *ifs;
  2556. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
  2557. reg_init_str(info->initiator), reg_type_str(info->type),
  2558. info->alpha2[0] ? " alpha2=" : "",
  2559. info->alpha2[0] ? info->alpha2 : "");
  2560. if (wpa_s->drv_priv == NULL)
  2561. return; /* Ignore event during drv initialization */
  2562. dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
  2563. radio_list) {
  2564. wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
  2565. ifs->ifname);
  2566. free_hw_features(ifs);
  2567. ifs->hw.modes = wpa_drv_get_hw_feature_data(
  2568. ifs, &ifs->hw.num_modes, &ifs->hw.flags);
  2569. }
  2570. /* Restart sched_scan with updated channel list */
  2571. if (wpa_s->sched_scanning) {
  2572. wpa_dbg(wpa_s, MSG_DEBUG,
  2573. "Channel list changed restart sched scan.");
  2574. wpa_supplicant_cancel_sched_scan(wpa_s);
  2575. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2576. }
  2577. wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
  2578. }
  2579. static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
  2580. const u8 *frame, size_t len, int freq,
  2581. int rssi)
  2582. {
  2583. const struct ieee80211_mgmt *mgmt;
  2584. const u8 *payload;
  2585. size_t plen;
  2586. u8 category;
  2587. if (len < IEEE80211_HDRLEN + 2)
  2588. return;
  2589. mgmt = (const struct ieee80211_mgmt *) frame;
  2590. payload = frame + IEEE80211_HDRLEN;
  2591. category = *payload++;
  2592. plen = len - IEEE80211_HDRLEN - 1;
  2593. wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
  2594. " Category=%u DataLen=%d freq=%d MHz",
  2595. MAC2STR(mgmt->sa), category, (int) plen, freq);
  2596. if (category == WLAN_ACTION_WMM) {
  2597. wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
  2598. return;
  2599. }
  2600. #ifdef CONFIG_IEEE80211R
  2601. if (category == WLAN_ACTION_FT) {
  2602. ft_rx_action(wpa_s, payload, plen);
  2603. return;
  2604. }
  2605. #endif /* CONFIG_IEEE80211R */
  2606. #ifdef CONFIG_IEEE80211W
  2607. #ifdef CONFIG_SME
  2608. if (category == WLAN_ACTION_SA_QUERY) {
  2609. sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
  2610. return;
  2611. }
  2612. #endif /* CONFIG_SME */
  2613. #endif /* CONFIG_IEEE80211W */
  2614. #ifdef CONFIG_WNM
  2615. if (mgmt->u.action.category == WLAN_ACTION_WNM) {
  2616. ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
  2617. return;
  2618. }
  2619. #endif /* CONFIG_WNM */
  2620. #ifdef CONFIG_GAS
  2621. if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
  2622. mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
  2623. gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
  2624. mgmt->u.action.category,
  2625. payload, plen, freq) == 0)
  2626. return;
  2627. #endif /* CONFIG_GAS */
  2628. #ifdef CONFIG_TDLS
  2629. if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
  2630. payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
  2631. wpa_dbg(wpa_s, MSG_DEBUG,
  2632. "TDLS: Received Discovery Response from " MACSTR,
  2633. MAC2STR(mgmt->sa));
  2634. return;
  2635. }
  2636. #endif /* CONFIG_TDLS */
  2637. #ifdef CONFIG_INTERWORKING
  2638. if (category == WLAN_ACTION_QOS && plen >= 1 &&
  2639. payload[0] == QOS_QOS_MAP_CONFIG) {
  2640. const u8 *pos = payload + 1;
  2641. size_t qlen = plen - 1;
  2642. wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
  2643. MACSTR, MAC2STR(mgmt->sa));
  2644. if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
  2645. qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
  2646. pos[1] <= qlen - 2 && pos[1] >= 16)
  2647. wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
  2648. return;
  2649. }
  2650. #endif /* CONFIG_INTERWORKING */
  2651. if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
  2652. payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
  2653. wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
  2654. return;
  2655. }
  2656. if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
  2657. payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
  2658. wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
  2659. payload + 1, plen - 1,
  2660. rssi);
  2661. return;
  2662. }
  2663. #ifdef CONFIG_FST
  2664. if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
  2665. fst_rx_action(wpa_s->fst, mgmt, len);
  2666. return;
  2667. }
  2668. #endif /* CONFIG_FST */
  2669. wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
  2670. category, payload, plen, freq);
  2671. if (wpa_s->ifmsh)
  2672. mesh_mpm_action_rx(wpa_s, mgmt, len);
  2673. }
  2674. static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
  2675. union wpa_event_data *event)
  2676. {
  2677. struct wpa_freq_range_list *list;
  2678. char *str = NULL;
  2679. list = &event->freq_range;
  2680. if (list->num)
  2681. str = freq_range_list_str(list);
  2682. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
  2683. str ? str : "");
  2684. #ifdef CONFIG_P2P
  2685. if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
  2686. wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
  2687. __func__);
  2688. } else {
  2689. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
  2690. /*
  2691. * The update channel flow will also take care of moving a GO
  2692. * from the unsafe frequency if needed.
  2693. */
  2694. wpas_p2p_update_channel_list(wpa_s,
  2695. WPAS_P2P_CHANNEL_UPDATE_AVOID);
  2696. }
  2697. #endif /* CONFIG_P2P */
  2698. os_free(str);
  2699. }
  2700. static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
  2701. union wpa_event_data *data)
  2702. {
  2703. wpa_dbg(wpa_s, MSG_DEBUG,
  2704. "Connection authorized by device, previous state %d",
  2705. wpa_s->wpa_state);
  2706. if (wpa_s->wpa_state == WPA_ASSOCIATED) {
  2707. wpa_supplicant_cancel_auth_timeout(wpa_s);
  2708. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  2709. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  2710. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  2711. }
  2712. wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
  2713. wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
  2714. data->assoc_info.ptk_kck_len,
  2715. data->assoc_info.ptk_kek,
  2716. data->assoc_info.ptk_kek_len);
  2717. }
  2718. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  2719. union wpa_event_data *data)
  2720. {
  2721. struct wpa_supplicant *wpa_s = ctx;
  2722. int resched;
  2723. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  2724. event != EVENT_INTERFACE_ENABLED &&
  2725. event != EVENT_INTERFACE_STATUS &&
  2726. event != EVENT_SCHED_SCAN_STOPPED) {
  2727. wpa_dbg(wpa_s, MSG_DEBUG,
  2728. "Ignore event %s (%d) while interface is disabled",
  2729. event_to_string(event), event);
  2730. return;
  2731. }
  2732. #ifndef CONFIG_NO_STDOUT_DEBUG
  2733. {
  2734. int level = MSG_DEBUG;
  2735. if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
  2736. const struct ieee80211_hdr *hdr;
  2737. u16 fc;
  2738. hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
  2739. fc = le_to_host16(hdr->frame_control);
  2740. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  2741. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
  2742. level = MSG_EXCESSIVE;
  2743. }
  2744. wpa_dbg(wpa_s, level, "Event %s (%d) received",
  2745. event_to_string(event), event);
  2746. }
  2747. #endif /* CONFIG_NO_STDOUT_DEBUG */
  2748. switch (event) {
  2749. case EVENT_AUTH:
  2750. sme_event_auth(wpa_s, data);
  2751. break;
  2752. case EVENT_ASSOC:
  2753. wpa_supplicant_event_assoc(wpa_s, data);
  2754. if (data && data->assoc_info.authorized)
  2755. wpa_supplicant_event_assoc_auth(wpa_s, data);
  2756. break;
  2757. case EVENT_DISASSOC:
  2758. wpas_event_disassoc(wpa_s,
  2759. data ? &data->disassoc_info : NULL);
  2760. break;
  2761. case EVENT_DEAUTH:
  2762. wpas_event_deauth(wpa_s,
  2763. data ? &data->deauth_info : NULL);
  2764. break;
  2765. case EVENT_MICHAEL_MIC_FAILURE:
  2766. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  2767. break;
  2768. #ifndef CONFIG_NO_SCAN_PROCESSING
  2769. case EVENT_SCAN_STARTED:
  2770. if (wpa_s->own_scan_requested ||
  2771. (data && !data->scan_info.external_scan)) {
  2772. struct os_reltime diff;
  2773. os_get_reltime(&wpa_s->scan_start_time);
  2774. os_reltime_sub(&wpa_s->scan_start_time,
  2775. &wpa_s->scan_trigger_time, &diff);
  2776. wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
  2777. diff.sec, diff.usec);
  2778. wpa_s->own_scan_requested = 0;
  2779. wpa_s->own_scan_running = 1;
  2780. if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
  2781. wpa_s->manual_scan_use_id) {
  2782. wpa_msg_ctrl(wpa_s, MSG_INFO,
  2783. WPA_EVENT_SCAN_STARTED "id=%u",
  2784. wpa_s->manual_scan_id);
  2785. } else {
  2786. wpa_msg_ctrl(wpa_s, MSG_INFO,
  2787. WPA_EVENT_SCAN_STARTED);
  2788. }
  2789. } else {
  2790. wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
  2791. wpa_s->radio->external_scan_running = 1;
  2792. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
  2793. }
  2794. break;
  2795. case EVENT_SCAN_RESULTS:
  2796. if (!(data && data->scan_info.external_scan) &&
  2797. os_reltime_initialized(&wpa_s->scan_start_time)) {
  2798. struct os_reltime now, diff;
  2799. os_get_reltime(&now);
  2800. os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
  2801. wpa_s->scan_start_time.sec = 0;
  2802. wpa_s->scan_start_time.usec = 0;
  2803. wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
  2804. diff.sec, diff.usec);
  2805. }
  2806. if (wpa_supplicant_event_scan_results(wpa_s, data))
  2807. break; /* interface may have been removed */
  2808. if (!(data && data->scan_info.external_scan))
  2809. wpa_s->own_scan_running = 0;
  2810. if (data && data->scan_info.nl_scan_event)
  2811. wpa_s->radio->external_scan_running = 0;
  2812. radio_work_check_next(wpa_s);
  2813. break;
  2814. #endif /* CONFIG_NO_SCAN_PROCESSING */
  2815. case EVENT_ASSOCINFO:
  2816. wpa_supplicant_event_associnfo(wpa_s, data);
  2817. break;
  2818. case EVENT_INTERFACE_STATUS:
  2819. wpa_supplicant_event_interface_status(wpa_s, data);
  2820. break;
  2821. case EVENT_PMKID_CANDIDATE:
  2822. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  2823. break;
  2824. #ifdef CONFIG_PEERKEY
  2825. case EVENT_STKSTART:
  2826. wpa_supplicant_event_stkstart(wpa_s, data);
  2827. break;
  2828. #endif /* CONFIG_PEERKEY */
  2829. #ifdef CONFIG_TDLS
  2830. case EVENT_TDLS:
  2831. wpa_supplicant_event_tdls(wpa_s, data);
  2832. break;
  2833. #endif /* CONFIG_TDLS */
  2834. #ifdef CONFIG_WNM
  2835. case EVENT_WNM:
  2836. wpa_supplicant_event_wnm(wpa_s, data);
  2837. break;
  2838. #endif /* CONFIG_WNM */
  2839. #ifdef CONFIG_IEEE80211R
  2840. case EVENT_FT_RESPONSE:
  2841. wpa_supplicant_event_ft_response(wpa_s, data);
  2842. break;
  2843. #endif /* CONFIG_IEEE80211R */
  2844. #ifdef CONFIG_IBSS_RSN
  2845. case EVENT_IBSS_RSN_START:
  2846. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  2847. break;
  2848. #endif /* CONFIG_IBSS_RSN */
  2849. case EVENT_ASSOC_REJECT:
  2850. if (data->assoc_reject.bssid)
  2851. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  2852. "bssid=" MACSTR " status_code=%u",
  2853. MAC2STR(data->assoc_reject.bssid),
  2854. data->assoc_reject.status_code);
  2855. else
  2856. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  2857. "status_code=%u",
  2858. data->assoc_reject.status_code);
  2859. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2860. sme_event_assoc_reject(wpa_s, data);
  2861. else {
  2862. const u8 *bssid = data->assoc_reject.bssid;
  2863. if (bssid == NULL || is_zero_ether_addr(bssid))
  2864. bssid = wpa_s->pending_bssid;
  2865. wpas_connection_failed(wpa_s, bssid);
  2866. wpa_supplicant_mark_disassoc(wpa_s);
  2867. }
  2868. break;
  2869. case EVENT_AUTH_TIMED_OUT:
  2870. /* It is possible to get this event from earlier connection */
  2871. if (wpa_s->current_ssid &&
  2872. wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
  2873. wpa_dbg(wpa_s, MSG_DEBUG,
  2874. "Ignore AUTH_TIMED_OUT in mesh configuration");
  2875. break;
  2876. }
  2877. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2878. sme_event_auth_timed_out(wpa_s, data);
  2879. break;
  2880. case EVENT_ASSOC_TIMED_OUT:
  2881. /* It is possible to get this event from earlier connection */
  2882. if (wpa_s->current_ssid &&
  2883. wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
  2884. wpa_dbg(wpa_s, MSG_DEBUG,
  2885. "Ignore ASSOC_TIMED_OUT in mesh configuration");
  2886. break;
  2887. }
  2888. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2889. sme_event_assoc_timed_out(wpa_s, data);
  2890. break;
  2891. case EVENT_TX_STATUS:
  2892. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
  2893. " type=%d stype=%d",
  2894. MAC2STR(data->tx_status.dst),
  2895. data->tx_status.type, data->tx_status.stype);
  2896. #ifdef CONFIG_AP
  2897. if (wpa_s->ap_iface == NULL) {
  2898. #ifdef CONFIG_OFFCHANNEL
  2899. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  2900. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  2901. offchannel_send_action_tx_status(
  2902. wpa_s, data->tx_status.dst,
  2903. data->tx_status.data,
  2904. data->tx_status.data_len,
  2905. data->tx_status.ack ?
  2906. OFFCHANNEL_SEND_ACTION_SUCCESS :
  2907. OFFCHANNEL_SEND_ACTION_NO_ACK);
  2908. #endif /* CONFIG_OFFCHANNEL */
  2909. break;
  2910. }
  2911. #endif /* CONFIG_AP */
  2912. #ifdef CONFIG_OFFCHANNEL
  2913. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
  2914. MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
  2915. /*
  2916. * Catch TX status events for Action frames we sent via group
  2917. * interface in GO mode.
  2918. */
  2919. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  2920. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  2921. os_memcmp(wpa_s->parent->pending_action_dst,
  2922. data->tx_status.dst, ETH_ALEN) == 0) {
  2923. offchannel_send_action_tx_status(
  2924. wpa_s->parent, data->tx_status.dst,
  2925. data->tx_status.data,
  2926. data->tx_status.data_len,
  2927. data->tx_status.ack ?
  2928. OFFCHANNEL_SEND_ACTION_SUCCESS :
  2929. OFFCHANNEL_SEND_ACTION_NO_ACK);
  2930. break;
  2931. }
  2932. #endif /* CONFIG_OFFCHANNEL */
  2933. #ifdef CONFIG_AP
  2934. switch (data->tx_status.type) {
  2935. case WLAN_FC_TYPE_MGMT:
  2936. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  2937. data->tx_status.data_len,
  2938. data->tx_status.stype,
  2939. data->tx_status.ack);
  2940. break;
  2941. case WLAN_FC_TYPE_DATA:
  2942. ap_tx_status(wpa_s, data->tx_status.dst,
  2943. data->tx_status.data,
  2944. data->tx_status.data_len,
  2945. data->tx_status.ack);
  2946. break;
  2947. }
  2948. #endif /* CONFIG_AP */
  2949. break;
  2950. #ifdef CONFIG_AP
  2951. case EVENT_EAPOL_TX_STATUS:
  2952. ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
  2953. data->eapol_tx_status.data,
  2954. data->eapol_tx_status.data_len,
  2955. data->eapol_tx_status.ack);
  2956. break;
  2957. case EVENT_DRIVER_CLIENT_POLL_OK:
  2958. ap_client_poll_ok(wpa_s, data->client_poll.addr);
  2959. break;
  2960. case EVENT_RX_FROM_UNKNOWN:
  2961. if (wpa_s->ap_iface == NULL)
  2962. break;
  2963. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
  2964. data->rx_from_unknown.wds);
  2965. break;
  2966. case EVENT_CH_SWITCH:
  2967. if (!data)
  2968. break;
  2969. if (!wpa_s->ap_iface) {
  2970. wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
  2971. "event in non-AP mode");
  2972. break;
  2973. }
  2974. wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
  2975. data->ch_switch.ht_enabled,
  2976. data->ch_switch.ch_offset,
  2977. data->ch_switch.ch_width,
  2978. data->ch_switch.cf1,
  2979. data->ch_switch.cf2);
  2980. break;
  2981. #ifdef NEED_AP_MLME
  2982. case EVENT_DFS_RADAR_DETECTED:
  2983. if (data)
  2984. wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
  2985. break;
  2986. case EVENT_DFS_CAC_STARTED:
  2987. if (data)
  2988. wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
  2989. break;
  2990. case EVENT_DFS_CAC_FINISHED:
  2991. if (data)
  2992. wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
  2993. break;
  2994. case EVENT_DFS_CAC_ABORTED:
  2995. if (data)
  2996. wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
  2997. break;
  2998. case EVENT_DFS_NOP_FINISHED:
  2999. if (data)
  3000. wpas_event_dfs_cac_nop_finished(wpa_s,
  3001. &data->dfs_event);
  3002. break;
  3003. #endif /* NEED_AP_MLME */
  3004. #endif /* CONFIG_AP */
  3005. case EVENT_RX_MGMT: {
  3006. u16 fc, stype;
  3007. const struct ieee80211_mgmt *mgmt;
  3008. #ifdef CONFIG_TESTING_OPTIONS
  3009. if (wpa_s->ext_mgmt_frame_handling) {
  3010. struct rx_mgmt *rx = &data->rx_mgmt;
  3011. size_t hex_len = 2 * rx->frame_len + 1;
  3012. char *hex = os_malloc(hex_len);
  3013. if (hex) {
  3014. wpa_snprintf_hex(hex, hex_len,
  3015. rx->frame, rx->frame_len);
  3016. wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
  3017. rx->freq, rx->datarate, rx->ssi_signal,
  3018. hex);
  3019. os_free(hex);
  3020. }
  3021. break;
  3022. }
  3023. #endif /* CONFIG_TESTING_OPTIONS */
  3024. mgmt = (const struct ieee80211_mgmt *)
  3025. data->rx_mgmt.frame;
  3026. fc = le_to_host16(mgmt->frame_control);
  3027. stype = WLAN_FC_GET_STYPE(fc);
  3028. #ifdef CONFIG_AP
  3029. if (wpa_s->ap_iface == NULL) {
  3030. #endif /* CONFIG_AP */
  3031. #ifdef CONFIG_P2P
  3032. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  3033. data->rx_mgmt.frame_len > 24) {
  3034. const u8 *src = mgmt->sa;
  3035. const u8 *ie = mgmt->u.probe_req.variable;
  3036. size_t ie_len = data->rx_mgmt.frame_len -
  3037. (mgmt->u.probe_req.variable -
  3038. data->rx_mgmt.frame);
  3039. wpas_p2p_probe_req_rx(
  3040. wpa_s, src, mgmt->da,
  3041. mgmt->bssid, ie, ie_len,
  3042. data->rx_mgmt.freq,
  3043. data->rx_mgmt.ssi_signal);
  3044. break;
  3045. }
  3046. #endif /* CONFIG_P2P */
  3047. #ifdef CONFIG_IBSS_RSN
  3048. if (wpa_s->current_ssid &&
  3049. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  3050. stype == WLAN_FC_STYPE_AUTH &&
  3051. data->rx_mgmt.frame_len >= 30) {
  3052. wpa_supplicant_event_ibss_auth(wpa_s, data);
  3053. break;
  3054. }
  3055. #endif /* CONFIG_IBSS_RSN */
  3056. if (stype == WLAN_FC_STYPE_ACTION) {
  3057. wpas_event_rx_mgmt_action(
  3058. wpa_s, data->rx_mgmt.frame,
  3059. data->rx_mgmt.frame_len,
  3060. data->rx_mgmt.freq,
  3061. data->rx_mgmt.ssi_signal);
  3062. break;
  3063. }
  3064. if (wpa_s->ifmsh) {
  3065. mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
  3066. break;
  3067. }
  3068. wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
  3069. "management frame in non-AP mode");
  3070. break;
  3071. #ifdef CONFIG_AP
  3072. }
  3073. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  3074. data->rx_mgmt.frame_len > 24) {
  3075. const u8 *ie = mgmt->u.probe_req.variable;
  3076. size_t ie_len = data->rx_mgmt.frame_len -
  3077. (mgmt->u.probe_req.variable -
  3078. data->rx_mgmt.frame);
  3079. wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
  3080. mgmt->bssid, ie, ie_len,
  3081. data->rx_mgmt.ssi_signal);
  3082. }
  3083. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  3084. #endif /* CONFIG_AP */
  3085. break;
  3086. }
  3087. case EVENT_RX_PROBE_REQ:
  3088. if (data->rx_probe_req.sa == NULL ||
  3089. data->rx_probe_req.ie == NULL)
  3090. break;
  3091. #ifdef CONFIG_AP
  3092. if (wpa_s->ap_iface) {
  3093. hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
  3094. data->rx_probe_req.sa,
  3095. data->rx_probe_req.da,
  3096. data->rx_probe_req.bssid,
  3097. data->rx_probe_req.ie,
  3098. data->rx_probe_req.ie_len,
  3099. data->rx_probe_req.ssi_signal);
  3100. break;
  3101. }
  3102. #endif /* CONFIG_AP */
  3103. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  3104. data->rx_probe_req.da,
  3105. data->rx_probe_req.bssid,
  3106. data->rx_probe_req.ie,
  3107. data->rx_probe_req.ie_len,
  3108. 0,
  3109. data->rx_probe_req.ssi_signal);
  3110. break;
  3111. case EVENT_REMAIN_ON_CHANNEL:
  3112. #ifdef CONFIG_OFFCHANNEL
  3113. offchannel_remain_on_channel_cb(
  3114. wpa_s, data->remain_on_channel.freq,
  3115. data->remain_on_channel.duration);
  3116. #endif /* CONFIG_OFFCHANNEL */
  3117. wpas_p2p_remain_on_channel_cb(
  3118. wpa_s, data->remain_on_channel.freq,
  3119. data->remain_on_channel.duration);
  3120. break;
  3121. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  3122. #ifdef CONFIG_OFFCHANNEL
  3123. offchannel_cancel_remain_on_channel_cb(
  3124. wpa_s, data->remain_on_channel.freq);
  3125. #endif /* CONFIG_OFFCHANNEL */
  3126. wpas_p2p_cancel_remain_on_channel_cb(
  3127. wpa_s, data->remain_on_channel.freq);
  3128. break;
  3129. case EVENT_EAPOL_RX:
  3130. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  3131. data->eapol_rx.data,
  3132. data->eapol_rx.data_len);
  3133. break;
  3134. case EVENT_SIGNAL_CHANGE:
  3135. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
  3136. "above=%d signal=%d noise=%d txrate=%d",
  3137. data->signal_change.above_threshold,
  3138. data->signal_change.current_signal,
  3139. data->signal_change.current_noise,
  3140. data->signal_change.current_txrate);
  3141. wpa_bss_update_level(wpa_s->current_bss,
  3142. data->signal_change.current_signal);
  3143. bgscan_notify_signal_change(
  3144. wpa_s, data->signal_change.above_threshold,
  3145. data->signal_change.current_signal,
  3146. data->signal_change.current_noise,
  3147. data->signal_change.current_txrate);
  3148. break;
  3149. case EVENT_INTERFACE_ENABLED:
  3150. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
  3151. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  3152. wpa_supplicant_update_mac_addr(wpa_s);
  3153. if (wpa_s->p2p_mgmt) {
  3154. wpa_supplicant_set_state(wpa_s,
  3155. WPA_DISCONNECTED);
  3156. break;
  3157. }
  3158. #ifdef CONFIG_AP
  3159. if (!wpa_s->ap_iface) {
  3160. wpa_supplicant_set_state(wpa_s,
  3161. WPA_DISCONNECTED);
  3162. wpa_s->scan_req = NORMAL_SCAN_REQ;
  3163. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3164. } else
  3165. wpa_supplicant_set_state(wpa_s,
  3166. WPA_COMPLETED);
  3167. #else /* CONFIG_AP */
  3168. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  3169. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3170. #endif /* CONFIG_AP */
  3171. }
  3172. break;
  3173. case EVENT_INTERFACE_DISABLED:
  3174. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
  3175. #ifdef CONFIG_P2P
  3176. if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
  3177. (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
  3178. wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
  3179. /*
  3180. * Mark interface disabled if this happens to end up not
  3181. * being removed as a separate P2P group interface.
  3182. */
  3183. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  3184. /*
  3185. * The interface was externally disabled. Remove
  3186. * it assuming an external entity will start a
  3187. * new session if needed.
  3188. */
  3189. if (wpa_s->current_ssid &&
  3190. wpa_s->current_ssid->p2p_group)
  3191. wpas_p2p_interface_unavailable(wpa_s);
  3192. else
  3193. wpas_p2p_disconnect(wpa_s);
  3194. /*
  3195. * wpa_s instance may have been freed, so must not use
  3196. * it here anymore.
  3197. */
  3198. break;
  3199. }
  3200. if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
  3201. p2p_in_progress(wpa_s->global->p2p) > 1) {
  3202. /* This radio work will be cancelled, so clear P2P
  3203. * state as well.
  3204. */
  3205. p2p_stop_find(wpa_s->global->p2p);
  3206. }
  3207. #endif /* CONFIG_P2P */
  3208. if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
  3209. /*
  3210. * Indicate disconnection to keep ctrl_iface events
  3211. * consistent.
  3212. */
  3213. wpa_supplicant_event_disassoc(
  3214. wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
  3215. }
  3216. wpa_supplicant_mark_disassoc(wpa_s);
  3217. radio_remove_works(wpa_s, NULL, 0);
  3218. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  3219. break;
  3220. case EVENT_CHANNEL_LIST_CHANGED:
  3221. wpa_supplicant_update_channel_list(
  3222. wpa_s, &data->channel_list_changed);
  3223. break;
  3224. case EVENT_INTERFACE_UNAVAILABLE:
  3225. wpas_p2p_interface_unavailable(wpa_s);
  3226. break;
  3227. case EVENT_BEST_CHANNEL:
  3228. wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
  3229. "(%d %d %d)",
  3230. data->best_chan.freq_24, data->best_chan.freq_5,
  3231. data->best_chan.freq_overall);
  3232. wpa_s->best_24_freq = data->best_chan.freq_24;
  3233. wpa_s->best_5_freq = data->best_chan.freq_5;
  3234. wpa_s->best_overall_freq = data->best_chan.freq_overall;
  3235. wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
  3236. data->best_chan.freq_5,
  3237. data->best_chan.freq_overall);
  3238. break;
  3239. case EVENT_UNPROT_DEAUTH:
  3240. wpa_supplicant_event_unprot_deauth(wpa_s,
  3241. &data->unprot_deauth);
  3242. break;
  3243. case EVENT_UNPROT_DISASSOC:
  3244. wpa_supplicant_event_unprot_disassoc(wpa_s,
  3245. &data->unprot_disassoc);
  3246. break;
  3247. case EVENT_STATION_LOW_ACK:
  3248. #ifdef CONFIG_AP
  3249. if (wpa_s->ap_iface && data)
  3250. hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
  3251. data->low_ack.addr);
  3252. #endif /* CONFIG_AP */
  3253. #ifdef CONFIG_TDLS
  3254. if (data)
  3255. wpa_tdls_disable_unreachable_link(wpa_s->wpa,
  3256. data->low_ack.addr);
  3257. #endif /* CONFIG_TDLS */
  3258. break;
  3259. case EVENT_IBSS_PEER_LOST:
  3260. #ifdef CONFIG_IBSS_RSN
  3261. ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
  3262. #endif /* CONFIG_IBSS_RSN */
  3263. break;
  3264. case EVENT_DRIVER_GTK_REKEY:
  3265. if (os_memcmp(data->driver_gtk_rekey.bssid,
  3266. wpa_s->bssid, ETH_ALEN))
  3267. break;
  3268. if (!wpa_s->wpa)
  3269. break;
  3270. wpa_sm_update_replay_ctr(wpa_s->wpa,
  3271. data->driver_gtk_rekey.replay_ctr);
  3272. break;
  3273. case EVENT_SCHED_SCAN_STOPPED:
  3274. wpa_s->pno = 0;
  3275. wpa_s->sched_scanning = 0;
  3276. resched = wpa_s->scanning;
  3277. wpa_supplicant_notify_scanning(wpa_s, 0);
  3278. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3279. break;
  3280. /*
  3281. * Start a new sched scan to continue searching for more SSIDs
  3282. * either if timed out or PNO schedule scan is pending.
  3283. */
  3284. if (wpa_s->sched_scan_timed_out) {
  3285. wpa_supplicant_req_sched_scan(wpa_s);
  3286. } else if (wpa_s->pno_sched_pending) {
  3287. wpa_s->pno_sched_pending = 0;
  3288. wpas_start_pno(wpa_s);
  3289. } else if (resched) {
  3290. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3291. }
  3292. break;
  3293. case EVENT_WPS_BUTTON_PUSHED:
  3294. #ifdef CONFIG_WPS
  3295. wpas_wps_start_pbc(wpa_s, NULL, 0);
  3296. #endif /* CONFIG_WPS */
  3297. break;
  3298. case EVENT_AVOID_FREQUENCIES:
  3299. wpa_supplicant_notify_avoid_freq(wpa_s, data);
  3300. break;
  3301. case EVENT_CONNECT_FAILED_REASON:
  3302. #ifdef CONFIG_AP
  3303. if (!wpa_s->ap_iface || !data)
  3304. break;
  3305. hostapd_event_connect_failed_reason(
  3306. wpa_s->ap_iface->bss[0],
  3307. data->connect_failed_reason.addr,
  3308. data->connect_failed_reason.code);
  3309. #endif /* CONFIG_AP */
  3310. break;
  3311. case EVENT_NEW_PEER_CANDIDATE:
  3312. #ifdef CONFIG_MESH
  3313. if (!wpa_s->ifmsh || !data)
  3314. break;
  3315. wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
  3316. data->mesh_peer.ies,
  3317. data->mesh_peer.ie_len);
  3318. #endif /* CONFIG_MESH */
  3319. break;
  3320. default:
  3321. wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
  3322. break;
  3323. }
  3324. }