events.c 115 KB

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