events.c 121 KB

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