events.c 124 KB

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