events.c 117 KB

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