events.c 106 KB

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