wpa_supplicant.c 144 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231
  1. /*
  2. * WPA Supplicant
  3. * Copyright (c) 2003-2014, 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. * This file implements functions for registering and unregistering
  9. * %wpa_supplicant interfaces. In addition, this file contains number of
  10. * functions for managing network connections.
  11. */
  12. #include "includes.h"
  13. #include "common.h"
  14. #include "crypto/random.h"
  15. #include "crypto/sha1.h"
  16. #include "eapol_supp/eapol_supp_sm.h"
  17. #include "eap_peer/eap.h"
  18. #include "eap_peer/eap_proxy.h"
  19. #include "eap_server/eap_methods.h"
  20. #include "rsn_supp/wpa.h"
  21. #include "eloop.h"
  22. #include "config.h"
  23. #include "utils/ext_password.h"
  24. #include "l2_packet/l2_packet.h"
  25. #include "wpa_supplicant_i.h"
  26. #include "driver_i.h"
  27. #include "ctrl_iface.h"
  28. #include "pcsc_funcs.h"
  29. #include "common/version.h"
  30. #include "rsn_supp/preauth.h"
  31. #include "rsn_supp/pmksa_cache.h"
  32. #include "common/wpa_ctrl.h"
  33. #include "common/ieee802_11_defs.h"
  34. #include "p2p/p2p.h"
  35. #include "blacklist.h"
  36. #include "wpas_glue.h"
  37. #include "wps_supplicant.h"
  38. #include "ibss_rsn.h"
  39. #include "sme.h"
  40. #include "gas_query.h"
  41. #include "ap.h"
  42. #include "p2p_supplicant.h"
  43. #include "wifi_display.h"
  44. #include "notify.h"
  45. #include "bgscan.h"
  46. #include "autoscan.h"
  47. #include "bss.h"
  48. #include "scan.h"
  49. #include "offchannel.h"
  50. #include "hs20_supplicant.h"
  51. #include "wnm_sta.h"
  52. #include "wpas_kay.h"
  53. #include "mesh.h"
  54. const char *wpa_supplicant_version =
  55. "wpa_supplicant v" VERSION_STR "\n"
  56. "Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi> and contributors";
  57. const char *wpa_supplicant_license =
  58. "This software may be distributed under the terms of the BSD license.\n"
  59. "See README for more details.\n"
  60. #ifdef EAP_TLS_OPENSSL
  61. "\nThis product includes software developed by the OpenSSL Project\n"
  62. "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n"
  63. #endif /* EAP_TLS_OPENSSL */
  64. ;
  65. #ifndef CONFIG_NO_STDOUT_DEBUG
  66. /* Long text divided into parts in order to fit in C89 strings size limits. */
  67. const char *wpa_supplicant_full_license1 =
  68. "";
  69. const char *wpa_supplicant_full_license2 =
  70. "This software may be distributed under the terms of the BSD license.\n"
  71. "\n"
  72. "Redistribution and use in source and binary forms, with or without\n"
  73. "modification, are permitted provided that the following conditions are\n"
  74. "met:\n"
  75. "\n";
  76. const char *wpa_supplicant_full_license3 =
  77. "1. Redistributions of source code must retain the above copyright\n"
  78. " notice, this list of conditions and the following disclaimer.\n"
  79. "\n"
  80. "2. Redistributions in binary form must reproduce the above copyright\n"
  81. " notice, this list of conditions and the following disclaimer in the\n"
  82. " documentation and/or other materials provided with the distribution.\n"
  83. "\n";
  84. const char *wpa_supplicant_full_license4 =
  85. "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
  86. " names of its contributors may be used to endorse or promote products\n"
  87. " derived from this software without specific prior written permission.\n"
  88. "\n"
  89. "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
  90. "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
  91. "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
  92. "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n";
  93. const char *wpa_supplicant_full_license5 =
  94. "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
  95. "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
  96. "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
  97. "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
  98. "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
  99. "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
  100. "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
  101. "\n";
  102. #endif /* CONFIG_NO_STDOUT_DEBUG */
  103. /* Configure default/group WEP keys for static WEP */
  104. int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
  105. {
  106. int i, set = 0;
  107. for (i = 0; i < NUM_WEP_KEYS; i++) {
  108. if (ssid->wep_key_len[i] == 0)
  109. continue;
  110. set = 1;
  111. wpa_drv_set_key(wpa_s, WPA_ALG_WEP, NULL,
  112. i, i == ssid->wep_tx_keyidx, NULL, 0,
  113. ssid->wep_key[i], ssid->wep_key_len[i]);
  114. }
  115. return set;
  116. }
  117. int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s,
  118. struct wpa_ssid *ssid)
  119. {
  120. u8 key[32];
  121. size_t keylen;
  122. enum wpa_alg alg;
  123. u8 seq[6] = { 0 };
  124. /* IBSS/WPA-None uses only one key (Group) for both receiving and
  125. * sending unicast and multicast packets. */
  126. if (ssid->mode != WPAS_MODE_IBSS) {
  127. wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid mode %d (not "
  128. "IBSS/ad-hoc) for WPA-None", ssid->mode);
  129. return -1;
  130. }
  131. if (!ssid->psk_set) {
  132. wpa_msg(wpa_s, MSG_INFO, "WPA: No PSK configured for "
  133. "WPA-None");
  134. return -1;
  135. }
  136. switch (wpa_s->group_cipher) {
  137. case WPA_CIPHER_CCMP:
  138. os_memcpy(key, ssid->psk, 16);
  139. keylen = 16;
  140. alg = WPA_ALG_CCMP;
  141. break;
  142. case WPA_CIPHER_GCMP:
  143. os_memcpy(key, ssid->psk, 16);
  144. keylen = 16;
  145. alg = WPA_ALG_GCMP;
  146. break;
  147. case WPA_CIPHER_TKIP:
  148. /* WPA-None uses the same Michael MIC key for both TX and RX */
  149. os_memcpy(key, ssid->psk, 16 + 8);
  150. os_memcpy(key + 16 + 8, ssid->psk + 16, 8);
  151. keylen = 32;
  152. alg = WPA_ALG_TKIP;
  153. break;
  154. default:
  155. wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid group cipher %d for "
  156. "WPA-None", wpa_s->group_cipher);
  157. return -1;
  158. }
  159. /* TODO: should actually remember the previously used seq#, both for TX
  160. * and RX from each STA.. */
  161. return wpa_drv_set_key(wpa_s, alg, NULL, 0, 1, seq, 6, key, keylen);
  162. }
  163. static void wpa_supplicant_timeout(void *eloop_ctx, void *timeout_ctx)
  164. {
  165. struct wpa_supplicant *wpa_s = eloop_ctx;
  166. const u8 *bssid = wpa_s->bssid;
  167. if (is_zero_ether_addr(bssid))
  168. bssid = wpa_s->pending_bssid;
  169. wpa_msg(wpa_s, MSG_INFO, "Authentication with " MACSTR " timed out.",
  170. MAC2STR(bssid));
  171. wpa_blacklist_add(wpa_s, bssid);
  172. wpa_sm_notify_disassoc(wpa_s->wpa);
  173. wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  174. wpa_s->reassociate = 1;
  175. /*
  176. * If we timed out, the AP or the local radio may be busy.
  177. * So, wait a second until scanning again.
  178. */
  179. wpa_supplicant_req_scan(wpa_s, 1, 0);
  180. }
  181. /**
  182. * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication
  183. * @wpa_s: Pointer to wpa_supplicant data
  184. * @sec: Number of seconds after which to time out authentication
  185. * @usec: Number of microseconds after which to time out authentication
  186. *
  187. * This function is used to schedule a timeout for the current authentication
  188. * attempt.
  189. */
  190. void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s,
  191. int sec, int usec)
  192. {
  193. if (wpa_s->conf->ap_scan == 0 &&
  194. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED))
  195. return;
  196. wpa_dbg(wpa_s, MSG_DEBUG, "Setting authentication timeout: %d sec "
  197. "%d usec", sec, usec);
  198. eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
  199. eloop_register_timeout(sec, usec, wpa_supplicant_timeout, wpa_s, NULL);
  200. }
  201. /**
  202. * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout
  203. * @wpa_s: Pointer to wpa_supplicant data
  204. *
  205. * This function is used to cancel authentication timeout scheduled with
  206. * wpa_supplicant_req_auth_timeout() and it is called when authentication has
  207. * been completed.
  208. */
  209. void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s)
  210. {
  211. wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling authentication timeout");
  212. eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
  213. wpa_blacklist_del(wpa_s, wpa_s->bssid);
  214. }
  215. /**
  216. * wpa_supplicant_initiate_eapol - Configure EAPOL state machine
  217. * @wpa_s: Pointer to wpa_supplicant data
  218. *
  219. * This function is used to configure EAPOL state machine based on the selected
  220. * authentication mode.
  221. */
  222. void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s)
  223. {
  224. #ifdef IEEE8021X_EAPOL
  225. struct eapol_config eapol_conf;
  226. struct wpa_ssid *ssid = wpa_s->current_ssid;
  227. #ifdef CONFIG_IBSS_RSN
  228. if (ssid->mode == WPAS_MODE_IBSS &&
  229. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  230. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
  231. /*
  232. * RSN IBSS authentication is per-STA and we can disable the
  233. * per-BSSID EAPOL authentication.
  234. */
  235. eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized);
  236. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  237. eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE);
  238. return;
  239. }
  240. #endif /* CONFIG_IBSS_RSN */
  241. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  242. eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE);
  243. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  244. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
  245. eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized);
  246. else
  247. eapol_sm_notify_portControl(wpa_s->eapol, Auto);
  248. os_memset(&eapol_conf, 0, sizeof(eapol_conf));
  249. if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  250. eapol_conf.accept_802_1x_keys = 1;
  251. eapol_conf.required_keys = 0;
  252. if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_UNICAST) {
  253. eapol_conf.required_keys |= EAPOL_REQUIRE_KEY_UNICAST;
  254. }
  255. if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_BROADCAST) {
  256. eapol_conf.required_keys |=
  257. EAPOL_REQUIRE_KEY_BROADCAST;
  258. }
  259. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)
  260. eapol_conf.required_keys = 0;
  261. }
  262. eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
  263. eapol_conf.workaround = ssid->eap_workaround;
  264. eapol_conf.eap_disabled =
  265. !wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) &&
  266. wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
  267. wpa_s->key_mgmt != WPA_KEY_MGMT_WPS;
  268. eapol_conf.external_sim = wpa_s->conf->external_sim;
  269. #ifdef CONFIG_WPS
  270. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
  271. eapol_conf.wps |= EAPOL_LOCAL_WPS_IN_USE;
  272. if (wpa_s->current_bss) {
  273. struct wpabuf *ie;
  274. ie = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss,
  275. WPS_IE_VENDOR_TYPE);
  276. if (ie) {
  277. if (wps_is_20(ie))
  278. eapol_conf.wps |=
  279. EAPOL_PEER_IS_WPS20_AP;
  280. wpabuf_free(ie);
  281. }
  282. }
  283. }
  284. #endif /* CONFIG_WPS */
  285. eapol_sm_notify_config(wpa_s->eapol, &ssid->eap, &eapol_conf);
  286. ieee802_1x_alloc_kay_sm(wpa_s, ssid);
  287. #endif /* IEEE8021X_EAPOL */
  288. }
  289. /**
  290. * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode
  291. * @wpa_s: Pointer to wpa_supplicant data
  292. * @ssid: Configuration data for the network
  293. *
  294. * This function is used to configure WPA state machine and related parameters
  295. * to a mode where WPA is not enabled. This is called as part of the
  296. * authentication configuration when the selected network does not use WPA.
  297. */
  298. void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s,
  299. struct wpa_ssid *ssid)
  300. {
  301. int i;
  302. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
  303. wpa_s->key_mgmt = WPA_KEY_MGMT_WPS;
  304. else if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)
  305. wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
  306. else
  307. wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
  308. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  309. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  310. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  311. wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
  312. wpa_s->group_cipher = WPA_CIPHER_NONE;
  313. wpa_s->mgmt_group_cipher = 0;
  314. for (i = 0; i < NUM_WEP_KEYS; i++) {
  315. if (ssid->wep_key_len[i] > 5) {
  316. wpa_s->pairwise_cipher = WPA_CIPHER_WEP104;
  317. wpa_s->group_cipher = WPA_CIPHER_WEP104;
  318. break;
  319. } else if (ssid->wep_key_len[i] > 0) {
  320. wpa_s->pairwise_cipher = WPA_CIPHER_WEP40;
  321. wpa_s->group_cipher = WPA_CIPHER_WEP40;
  322. break;
  323. }
  324. }
  325. wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, 0);
  326. wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
  327. wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
  328. wpa_s->pairwise_cipher);
  329. wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
  330. #ifdef CONFIG_IEEE80211W
  331. wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
  332. wpa_s->mgmt_group_cipher);
  333. #endif /* CONFIG_IEEE80211W */
  334. pmksa_cache_clear_current(wpa_s->wpa);
  335. }
  336. void free_hw_features(struct wpa_supplicant *wpa_s)
  337. {
  338. int i;
  339. if (wpa_s->hw.modes == NULL)
  340. return;
  341. for (i = 0; i < wpa_s->hw.num_modes; i++) {
  342. os_free(wpa_s->hw.modes[i].channels);
  343. os_free(wpa_s->hw.modes[i].rates);
  344. }
  345. os_free(wpa_s->hw.modes);
  346. wpa_s->hw.modes = NULL;
  347. }
  348. static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
  349. {
  350. int i;
  351. bgscan_deinit(wpa_s);
  352. autoscan_deinit(wpa_s);
  353. scard_deinit(wpa_s->scard);
  354. wpa_s->scard = NULL;
  355. wpa_sm_set_scard_ctx(wpa_s->wpa, NULL);
  356. eapol_sm_register_scard_ctx(wpa_s->eapol, NULL);
  357. l2_packet_deinit(wpa_s->l2);
  358. wpa_s->l2 = NULL;
  359. if (wpa_s->l2_br) {
  360. l2_packet_deinit(wpa_s->l2_br);
  361. wpa_s->l2_br = NULL;
  362. }
  363. #ifdef CONFIG_TESTING_OPTIONS
  364. l2_packet_deinit(wpa_s->l2_test);
  365. wpa_s->l2_test = NULL;
  366. #endif /* CONFIG_TESTING_OPTIONS */
  367. if (wpa_s->conf != NULL) {
  368. struct wpa_ssid *ssid;
  369. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
  370. wpas_notify_network_removed(wpa_s, ssid);
  371. }
  372. os_free(wpa_s->confname);
  373. wpa_s->confname = NULL;
  374. os_free(wpa_s->confanother);
  375. wpa_s->confanother = NULL;
  376. wpa_sm_set_eapol(wpa_s->wpa, NULL);
  377. eapol_sm_deinit(wpa_s->eapol);
  378. wpa_s->eapol = NULL;
  379. rsn_preauth_deinit(wpa_s->wpa);
  380. #ifdef CONFIG_TDLS
  381. wpa_tdls_deinit(wpa_s->wpa);
  382. #endif /* CONFIG_TDLS */
  383. pmksa_candidate_free(wpa_s->wpa);
  384. wpa_sm_deinit(wpa_s->wpa);
  385. wpa_s->wpa = NULL;
  386. wpa_blacklist_clear(wpa_s);
  387. wpa_bss_deinit(wpa_s);
  388. wpa_supplicant_cancel_delayed_sched_scan(wpa_s);
  389. wpa_supplicant_cancel_scan(wpa_s);
  390. wpa_supplicant_cancel_auth_timeout(wpa_s);
  391. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
  392. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  393. eloop_cancel_timeout(wpa_supplicant_delayed_mic_error_report,
  394. wpa_s, NULL);
  395. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  396. wpas_wps_deinit(wpa_s);
  397. wpabuf_free(wpa_s->pending_eapol_rx);
  398. wpa_s->pending_eapol_rx = NULL;
  399. #ifdef CONFIG_IBSS_RSN
  400. ibss_rsn_deinit(wpa_s->ibss_rsn);
  401. wpa_s->ibss_rsn = NULL;
  402. #endif /* CONFIG_IBSS_RSN */
  403. sme_deinit(wpa_s);
  404. #ifdef CONFIG_AP
  405. wpa_supplicant_ap_deinit(wpa_s);
  406. #endif /* CONFIG_AP */
  407. wpas_p2p_deinit(wpa_s);
  408. #ifdef CONFIG_OFFCHANNEL
  409. offchannel_deinit(wpa_s);
  410. #endif /* CONFIG_OFFCHANNEL */
  411. wpa_supplicant_cancel_sched_scan(wpa_s);
  412. os_free(wpa_s->next_scan_freqs);
  413. wpa_s->next_scan_freqs = NULL;
  414. os_free(wpa_s->manual_scan_freqs);
  415. wpa_s->manual_scan_freqs = NULL;
  416. os_free(wpa_s->manual_sched_scan_freqs);
  417. wpa_s->manual_sched_scan_freqs = NULL;
  418. gas_query_deinit(wpa_s->gas);
  419. wpa_s->gas = NULL;
  420. free_hw_features(wpa_s);
  421. ieee802_1x_dealloc_kay_sm(wpa_s);
  422. os_free(wpa_s->bssid_filter);
  423. wpa_s->bssid_filter = NULL;
  424. os_free(wpa_s->disallow_aps_bssid);
  425. wpa_s->disallow_aps_bssid = NULL;
  426. os_free(wpa_s->disallow_aps_ssid);
  427. wpa_s->disallow_aps_ssid = NULL;
  428. wnm_bss_keep_alive_deinit(wpa_s);
  429. #ifdef CONFIG_WNM
  430. wnm_deallocate_memory(wpa_s);
  431. #endif /* CONFIG_WNM */
  432. ext_password_deinit(wpa_s->ext_pw);
  433. wpa_s->ext_pw = NULL;
  434. wpabuf_free(wpa_s->last_gas_resp);
  435. wpa_s->last_gas_resp = NULL;
  436. wpabuf_free(wpa_s->prev_gas_resp);
  437. wpa_s->prev_gas_resp = NULL;
  438. os_free(wpa_s->last_scan_res);
  439. wpa_s->last_scan_res = NULL;
  440. #ifdef CONFIG_HS20
  441. hs20_deinit(wpa_s);
  442. #endif /* CONFIG_HS20 */
  443. for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
  444. wpabuf_free(wpa_s->vendor_elem[i]);
  445. wpa_s->vendor_elem[i] = NULL;
  446. }
  447. wmm_ac_notify_disassoc(wpa_s);
  448. }
  449. /**
  450. * wpa_clear_keys - Clear keys configured for the driver
  451. * @wpa_s: Pointer to wpa_supplicant data
  452. * @addr: Previously used BSSID or %NULL if not available
  453. *
  454. * This function clears the encryption keys that has been previously configured
  455. * for the driver.
  456. */
  457. void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr)
  458. {
  459. int i, max;
  460. #ifdef CONFIG_IEEE80211W
  461. max = 6;
  462. #else /* CONFIG_IEEE80211W */
  463. max = 4;
  464. #endif /* CONFIG_IEEE80211W */
  465. /* MLME-DELETEKEYS.request */
  466. for (i = 0; i < max; i++) {
  467. if (wpa_s->keys_cleared & BIT(i))
  468. continue;
  469. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, i, 0, NULL, 0,
  470. NULL, 0);
  471. }
  472. if (!(wpa_s->keys_cleared & BIT(0)) && addr &&
  473. !is_zero_ether_addr(addr)) {
  474. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, addr, 0, 0, NULL, 0, NULL,
  475. 0);
  476. /* MLME-SETPROTECTION.request(None) */
  477. wpa_drv_mlme_setprotection(
  478. wpa_s, addr,
  479. MLME_SETPROTECTION_PROTECT_TYPE_NONE,
  480. MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
  481. }
  482. wpa_s->keys_cleared = (u32) -1;
  483. }
  484. /**
  485. * wpa_supplicant_state_txt - Get the connection state name as a text string
  486. * @state: State (wpa_state; WPA_*)
  487. * Returns: The state name as a printable text string
  488. */
  489. const char * wpa_supplicant_state_txt(enum wpa_states state)
  490. {
  491. switch (state) {
  492. case WPA_DISCONNECTED:
  493. return "DISCONNECTED";
  494. case WPA_INACTIVE:
  495. return "INACTIVE";
  496. case WPA_INTERFACE_DISABLED:
  497. return "INTERFACE_DISABLED";
  498. case WPA_SCANNING:
  499. return "SCANNING";
  500. case WPA_AUTHENTICATING:
  501. return "AUTHENTICATING";
  502. case WPA_ASSOCIATING:
  503. return "ASSOCIATING";
  504. case WPA_ASSOCIATED:
  505. return "ASSOCIATED";
  506. case WPA_4WAY_HANDSHAKE:
  507. return "4WAY_HANDSHAKE";
  508. case WPA_GROUP_HANDSHAKE:
  509. return "GROUP_HANDSHAKE";
  510. case WPA_COMPLETED:
  511. return "COMPLETED";
  512. default:
  513. return "UNKNOWN";
  514. }
  515. }
  516. #ifdef CONFIG_BGSCAN
  517. static void wpa_supplicant_start_bgscan(struct wpa_supplicant *wpa_s)
  518. {
  519. const char *name;
  520. if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan)
  521. name = wpa_s->current_ssid->bgscan;
  522. else
  523. name = wpa_s->conf->bgscan;
  524. if (name == NULL || name[0] == '\0')
  525. return;
  526. if (wpas_driver_bss_selection(wpa_s))
  527. return;
  528. if (wpa_s->current_ssid == wpa_s->bgscan_ssid)
  529. return;
  530. #ifdef CONFIG_P2P
  531. if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)
  532. return;
  533. #endif /* CONFIG_P2P */
  534. bgscan_deinit(wpa_s);
  535. if (wpa_s->current_ssid) {
  536. if (bgscan_init(wpa_s, wpa_s->current_ssid, name)) {
  537. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize "
  538. "bgscan");
  539. /*
  540. * Live without bgscan; it is only used as a roaming
  541. * optimization, so the initial connection is not
  542. * affected.
  543. */
  544. } else {
  545. struct wpa_scan_results *scan_res;
  546. wpa_s->bgscan_ssid = wpa_s->current_ssid;
  547. scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL,
  548. 0);
  549. if (scan_res) {
  550. bgscan_notify_scan(wpa_s, scan_res);
  551. wpa_scan_results_free(scan_res);
  552. }
  553. }
  554. } else
  555. wpa_s->bgscan_ssid = NULL;
  556. }
  557. static void wpa_supplicant_stop_bgscan(struct wpa_supplicant *wpa_s)
  558. {
  559. if (wpa_s->bgscan_ssid != NULL) {
  560. bgscan_deinit(wpa_s);
  561. wpa_s->bgscan_ssid = NULL;
  562. }
  563. }
  564. #endif /* CONFIG_BGSCAN */
  565. static void wpa_supplicant_start_autoscan(struct wpa_supplicant *wpa_s)
  566. {
  567. if (autoscan_init(wpa_s, 0))
  568. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize autoscan");
  569. }
  570. static void wpa_supplicant_stop_autoscan(struct wpa_supplicant *wpa_s)
  571. {
  572. autoscan_deinit(wpa_s);
  573. }
  574. void wpa_supplicant_reinit_autoscan(struct wpa_supplicant *wpa_s)
  575. {
  576. if (wpa_s->wpa_state == WPA_DISCONNECTED ||
  577. wpa_s->wpa_state == WPA_SCANNING) {
  578. autoscan_deinit(wpa_s);
  579. wpa_supplicant_start_autoscan(wpa_s);
  580. }
  581. }
  582. /**
  583. * wpa_supplicant_set_state - Set current connection state
  584. * @wpa_s: Pointer to wpa_supplicant data
  585. * @state: The new connection state
  586. *
  587. * This function is called whenever the connection state changes, e.g.,
  588. * association is completed for WPA/WPA2 4-Way Handshake is started.
  589. */
  590. void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s,
  591. enum wpa_states state)
  592. {
  593. enum wpa_states old_state = wpa_s->wpa_state;
  594. wpa_dbg(wpa_s, MSG_DEBUG, "State: %s -> %s",
  595. wpa_supplicant_state_txt(wpa_s->wpa_state),
  596. wpa_supplicant_state_txt(state));
  597. if (state == WPA_INTERFACE_DISABLED) {
  598. /* Assure normal scan when interface is restored */
  599. wpa_s->normal_scans = 0;
  600. }
  601. if (state == WPA_COMPLETED) {
  602. wpas_connect_work_done(wpa_s);
  603. /* Reinitialize normal_scan counter */
  604. wpa_s->normal_scans = 0;
  605. }
  606. if (state != WPA_SCANNING)
  607. wpa_supplicant_notify_scanning(wpa_s, 0);
  608. if (state == WPA_COMPLETED && wpa_s->new_connection) {
  609. struct wpa_ssid *ssid = wpa_s->current_ssid;
  610. #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
  611. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED "- Connection to "
  612. MACSTR " completed [id=%d id_str=%s]",
  613. MAC2STR(wpa_s->bssid),
  614. ssid ? ssid->id : -1,
  615. ssid && ssid->id_str ? ssid->id_str : "");
  616. #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
  617. wpas_clear_temp_disabled(wpa_s, ssid, 1);
  618. wpa_s->extra_blacklist_count = 0;
  619. wpa_s->new_connection = 0;
  620. wpa_drv_set_operstate(wpa_s, 1);
  621. #ifndef IEEE8021X_EAPOL
  622. wpa_drv_set_supp_port(wpa_s, 1);
  623. #endif /* IEEE8021X_EAPOL */
  624. wpa_s->after_wps = 0;
  625. wpa_s->known_wps_freq = 0;
  626. wpas_p2p_completed(wpa_s);
  627. sme_sched_obss_scan(wpa_s, 1);
  628. } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
  629. state == WPA_ASSOCIATED) {
  630. wpa_s->new_connection = 1;
  631. wpa_drv_set_operstate(wpa_s, 0);
  632. #ifndef IEEE8021X_EAPOL
  633. wpa_drv_set_supp_port(wpa_s, 0);
  634. #endif /* IEEE8021X_EAPOL */
  635. sme_sched_obss_scan(wpa_s, 0);
  636. }
  637. wpa_s->wpa_state = state;
  638. #ifdef CONFIG_BGSCAN
  639. if (state == WPA_COMPLETED)
  640. wpa_supplicant_start_bgscan(wpa_s);
  641. else if (state < WPA_ASSOCIATED)
  642. wpa_supplicant_stop_bgscan(wpa_s);
  643. #endif /* CONFIG_BGSCAN */
  644. if (state == WPA_AUTHENTICATING)
  645. wpa_supplicant_stop_autoscan(wpa_s);
  646. if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
  647. wpa_supplicant_start_autoscan(wpa_s);
  648. if (wpa_s->wpa_state != old_state) {
  649. wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
  650. /*
  651. * Notify the P2P Device interface about a state change in one
  652. * of the interfaces.
  653. */
  654. wpas_p2p_indicate_state_change(wpa_s);
  655. if (wpa_s->wpa_state == WPA_COMPLETED ||
  656. old_state == WPA_COMPLETED)
  657. wpas_notify_auth_changed(wpa_s);
  658. }
  659. }
  660. void wpa_supplicant_terminate_proc(struct wpa_global *global)
  661. {
  662. int pending = 0;
  663. #ifdef CONFIG_WPS
  664. struct wpa_supplicant *wpa_s = global->ifaces;
  665. while (wpa_s) {
  666. struct wpa_supplicant *next = wpa_s->next;
  667. if (wpas_wps_terminate_pending(wpa_s) == 1)
  668. pending = 1;
  669. #ifdef CONFIG_P2P
  670. if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE ||
  671. (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group))
  672. wpas_p2p_disconnect(wpa_s);
  673. #endif /* CONFIG_P2P */
  674. wpa_s = next;
  675. }
  676. #endif /* CONFIG_WPS */
  677. if (pending)
  678. return;
  679. eloop_terminate();
  680. }
  681. static void wpa_supplicant_terminate(int sig, void *signal_ctx)
  682. {
  683. struct wpa_global *global = signal_ctx;
  684. wpa_supplicant_terminate_proc(global);
  685. }
  686. void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s)
  687. {
  688. enum wpa_states old_state = wpa_s->wpa_state;
  689. wpa_s->pairwise_cipher = 0;
  690. wpa_s->group_cipher = 0;
  691. wpa_s->mgmt_group_cipher = 0;
  692. wpa_s->key_mgmt = 0;
  693. if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED)
  694. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  695. if (wpa_s->wpa_state != old_state)
  696. wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state);
  697. }
  698. /**
  699. * wpa_supplicant_reload_configuration - Reload configuration data
  700. * @wpa_s: Pointer to wpa_supplicant data
  701. * Returns: 0 on success or -1 if configuration parsing failed
  702. *
  703. * This function can be used to request that the configuration data is reloaded
  704. * (e.g., after configuration file change). This function is reloading
  705. * configuration only for one interface, so this may need to be called multiple
  706. * times if %wpa_supplicant is controlling multiple interfaces and all
  707. * interfaces need reconfiguration.
  708. */
  709. int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s)
  710. {
  711. struct wpa_config *conf;
  712. int reconf_ctrl;
  713. int old_ap_scan;
  714. if (wpa_s->confname == NULL)
  715. return -1;
  716. conf = wpa_config_read(wpa_s->confname, NULL);
  717. if (conf == NULL) {
  718. wpa_msg(wpa_s, MSG_ERROR, "Failed to parse the configuration "
  719. "file '%s' - exiting", wpa_s->confname);
  720. return -1;
  721. }
  722. wpa_config_read(wpa_s->confanother, conf);
  723. conf->changed_parameters = (unsigned int) -1;
  724. reconf_ctrl = !!conf->ctrl_interface != !!wpa_s->conf->ctrl_interface
  725. || (conf->ctrl_interface && wpa_s->conf->ctrl_interface &&
  726. os_strcmp(conf->ctrl_interface,
  727. wpa_s->conf->ctrl_interface) != 0);
  728. if (reconf_ctrl && wpa_s->ctrl_iface) {
  729. wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
  730. wpa_s->ctrl_iface = NULL;
  731. }
  732. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  733. if (wpa_s->current_ssid) {
  734. wpa_supplicant_deauthenticate(wpa_s,
  735. WLAN_REASON_DEAUTH_LEAVING);
  736. }
  737. /*
  738. * TODO: should notify EAPOL SM about changes in opensc_engine_path,
  739. * pkcs11_engine_path, pkcs11_module_path, openssl_ciphers.
  740. */
  741. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  742. /*
  743. * Clear forced success to clear EAP state for next
  744. * authentication.
  745. */
  746. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  747. }
  748. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  749. wpa_sm_set_config(wpa_s->wpa, NULL);
  750. wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
  751. wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth);
  752. rsn_preauth_deinit(wpa_s->wpa);
  753. old_ap_scan = wpa_s->conf->ap_scan;
  754. wpa_config_free(wpa_s->conf);
  755. wpa_s->conf = conf;
  756. if (old_ap_scan != wpa_s->conf->ap_scan)
  757. wpas_notify_ap_scan_changed(wpa_s);
  758. if (reconf_ctrl)
  759. wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s);
  760. wpa_supplicant_update_config(wpa_s);
  761. wpa_supplicant_clear_status(wpa_s);
  762. if (wpa_supplicant_enabled_networks(wpa_s)) {
  763. wpa_s->reassociate = 1;
  764. wpa_supplicant_req_scan(wpa_s, 0, 0);
  765. }
  766. wpa_dbg(wpa_s, MSG_DEBUG, "Reconfiguration completed");
  767. return 0;
  768. }
  769. static void wpa_supplicant_reconfig(int sig, void *signal_ctx)
  770. {
  771. struct wpa_global *global = signal_ctx;
  772. struct wpa_supplicant *wpa_s;
  773. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  774. wpa_dbg(wpa_s, MSG_DEBUG, "Signal %d received - reconfiguring",
  775. sig);
  776. if (wpa_supplicant_reload_configuration(wpa_s) < 0) {
  777. wpa_supplicant_terminate_proc(global);
  778. }
  779. }
  780. }
  781. static int wpa_supplicant_suites_from_ai(struct wpa_supplicant *wpa_s,
  782. struct wpa_ssid *ssid,
  783. struct wpa_ie_data *ie)
  784. {
  785. int ret = wpa_sm_parse_own_wpa_ie(wpa_s->wpa, ie);
  786. if (ret) {
  787. if (ret == -2) {
  788. wpa_msg(wpa_s, MSG_INFO, "WPA: Failed to parse WPA IE "
  789. "from association info");
  790. }
  791. return -1;
  792. }
  793. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Using WPA IE from AssocReq to set "
  794. "cipher suites");
  795. if (!(ie->group_cipher & ssid->group_cipher)) {
  796. wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled group "
  797. "cipher 0x%x (mask 0x%x) - reject",
  798. ie->group_cipher, ssid->group_cipher);
  799. return -1;
  800. }
  801. if (!(ie->pairwise_cipher & ssid->pairwise_cipher)) {
  802. wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled pairwise "
  803. "cipher 0x%x (mask 0x%x) - reject",
  804. ie->pairwise_cipher, ssid->pairwise_cipher);
  805. return -1;
  806. }
  807. if (!(ie->key_mgmt & ssid->key_mgmt)) {
  808. wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled key "
  809. "management 0x%x (mask 0x%x) - reject",
  810. ie->key_mgmt, ssid->key_mgmt);
  811. return -1;
  812. }
  813. #ifdef CONFIG_IEEE80211W
  814. if (!(ie->capabilities & WPA_CAPABILITY_MFPC) &&
  815. (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
  816. wpa_s->conf->pmf : ssid->ieee80211w) ==
  817. MGMT_FRAME_PROTECTION_REQUIRED) {
  818. wpa_msg(wpa_s, MSG_INFO, "WPA: Driver associated with an AP "
  819. "that does not support management frame protection - "
  820. "reject");
  821. return -1;
  822. }
  823. #endif /* CONFIG_IEEE80211W */
  824. return 0;
  825. }
  826. /**
  827. * wpa_supplicant_set_suites - Set authentication and encryption parameters
  828. * @wpa_s: Pointer to wpa_supplicant data
  829. * @bss: Scan results for the selected BSS, or %NULL if not available
  830. * @ssid: Configuration data for the selected network
  831. * @wpa_ie: Buffer for the WPA/RSN IE
  832. * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the
  833. * used buffer length in case the functions returns success.
  834. * Returns: 0 on success or -1 on failure
  835. *
  836. * This function is used to configure authentication and encryption parameters
  837. * based on the network configuration and scan result for the selected BSS (if
  838. * available).
  839. */
  840. int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
  841. struct wpa_bss *bss, struct wpa_ssid *ssid,
  842. u8 *wpa_ie, size_t *wpa_ie_len)
  843. {
  844. struct wpa_ie_data ie;
  845. int sel, proto;
  846. const u8 *bss_wpa, *bss_rsn, *bss_osen;
  847. if (bss) {
  848. bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  849. bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  850. bss_osen = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
  851. } else
  852. bss_wpa = bss_rsn = bss_osen = NULL;
  853. if (bss_rsn && (ssid->proto & WPA_PROTO_RSN) &&
  854. wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie) == 0 &&
  855. (ie.group_cipher & ssid->group_cipher) &&
  856. (ie.pairwise_cipher & ssid->pairwise_cipher) &&
  857. (ie.key_mgmt & ssid->key_mgmt)) {
  858. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using IEEE 802.11i/D9.0");
  859. proto = WPA_PROTO_RSN;
  860. } else if (bss_wpa && (ssid->proto & WPA_PROTO_WPA) &&
  861. wpa_parse_wpa_ie(bss_wpa, 2 + bss_wpa[1], &ie) == 0 &&
  862. (ie.group_cipher & ssid->group_cipher) &&
  863. (ie.pairwise_cipher & ssid->pairwise_cipher) &&
  864. (ie.key_mgmt & ssid->key_mgmt)) {
  865. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using IEEE 802.11i/D3.0");
  866. proto = WPA_PROTO_WPA;
  867. #ifdef CONFIG_HS20
  868. } else if (bss_osen && (ssid->proto & WPA_PROTO_OSEN)) {
  869. wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: using OSEN");
  870. /* TODO: parse OSEN element */
  871. os_memset(&ie, 0, sizeof(ie));
  872. ie.group_cipher = WPA_CIPHER_CCMP;
  873. ie.pairwise_cipher = WPA_CIPHER_CCMP;
  874. ie.key_mgmt = WPA_KEY_MGMT_OSEN;
  875. proto = WPA_PROTO_OSEN;
  876. #endif /* CONFIG_HS20 */
  877. } else if (bss) {
  878. wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select WPA/RSN");
  879. wpa_dbg(wpa_s, MSG_DEBUG,
  880. "WPA: ssid proto=0x%x pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
  881. ssid->proto, ssid->pairwise_cipher, ssid->group_cipher,
  882. ssid->key_mgmt);
  883. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: BSS " MACSTR " ssid='%s'%s%s%s",
  884. MAC2STR(bss->bssid),
  885. wpa_ssid_txt(bss->ssid, bss->ssid_len),
  886. bss_wpa ? " WPA" : "",
  887. bss_rsn ? " RSN" : "",
  888. bss_osen ? " OSEN" : "");
  889. if (bss_rsn) {
  890. wpa_hexdump(MSG_DEBUG, "RSN", bss_rsn, 2 + bss_rsn[1]);
  891. if (wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie)) {
  892. wpa_dbg(wpa_s, MSG_DEBUG,
  893. "Could not parse RSN element");
  894. } else {
  895. wpa_dbg(wpa_s, MSG_DEBUG,
  896. "RSN: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
  897. ie.pairwise_cipher, ie.group_cipher,
  898. ie.key_mgmt);
  899. }
  900. }
  901. if (bss_wpa) {
  902. wpa_hexdump(MSG_DEBUG, "WPA", bss_wpa, 2 + bss_wpa[1]);
  903. if (wpa_parse_wpa_ie(bss_wpa, 2 + bss_wpa[1], &ie)) {
  904. wpa_dbg(wpa_s, MSG_DEBUG,
  905. "Could not parse WPA element");
  906. } else {
  907. wpa_dbg(wpa_s, MSG_DEBUG,
  908. "WPA: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x",
  909. ie.pairwise_cipher, ie.group_cipher,
  910. ie.key_mgmt);
  911. }
  912. }
  913. return -1;
  914. } else {
  915. if (ssid->proto & WPA_PROTO_OSEN)
  916. proto = WPA_PROTO_OSEN;
  917. else if (ssid->proto & WPA_PROTO_RSN)
  918. proto = WPA_PROTO_RSN;
  919. else
  920. proto = WPA_PROTO_WPA;
  921. if (wpa_supplicant_suites_from_ai(wpa_s, ssid, &ie) < 0) {
  922. os_memset(&ie, 0, sizeof(ie));
  923. ie.group_cipher = ssid->group_cipher;
  924. ie.pairwise_cipher = ssid->pairwise_cipher;
  925. ie.key_mgmt = ssid->key_mgmt;
  926. #ifdef CONFIG_IEEE80211W
  927. ie.mgmt_group_cipher =
  928. ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION ?
  929. WPA_CIPHER_AES_128_CMAC : 0;
  930. #endif /* CONFIG_IEEE80211W */
  931. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Set cipher suites "
  932. "based on configuration");
  933. } else
  934. proto = ie.proto;
  935. }
  936. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected cipher suites: group %d "
  937. "pairwise %d key_mgmt %d proto %d",
  938. ie.group_cipher, ie.pairwise_cipher, ie.key_mgmt, proto);
  939. #ifdef CONFIG_IEEE80211W
  940. if (ssid->ieee80211w) {
  941. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected mgmt group cipher %d",
  942. ie.mgmt_group_cipher);
  943. }
  944. #endif /* CONFIG_IEEE80211W */
  945. wpa_s->wpa_proto = proto;
  946. wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, proto);
  947. wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED,
  948. !!(ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)));
  949. if (bss || !wpa_s->ap_ies_from_associnfo) {
  950. if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
  951. bss_wpa ? 2 + bss_wpa[1] : 0) ||
  952. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
  953. bss_rsn ? 2 + bss_rsn[1] : 0))
  954. return -1;
  955. }
  956. sel = ie.group_cipher & ssid->group_cipher;
  957. wpa_s->group_cipher = wpa_pick_group_cipher(sel);
  958. if (wpa_s->group_cipher < 0) {
  959. wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select group "
  960. "cipher");
  961. return -1;
  962. }
  963. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s",
  964. wpa_cipher_txt(wpa_s->group_cipher));
  965. sel = ie.pairwise_cipher & ssid->pairwise_cipher;
  966. wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(sel, 1);
  967. if (wpa_s->pairwise_cipher < 0) {
  968. wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select pairwise "
  969. "cipher");
  970. return -1;
  971. }
  972. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s",
  973. wpa_cipher_txt(wpa_s->pairwise_cipher));
  974. sel = ie.key_mgmt & ssid->key_mgmt;
  975. #ifdef CONFIG_SAE
  976. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE))
  977. sel &= ~(WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_FT_SAE);
  978. #endif /* CONFIG_SAE */
  979. if (0) {
  980. } else if (sel & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
  981. wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B;
  982. wpa_dbg(wpa_s, MSG_DEBUG,
  983. "WPA: using KEY_MGMT 802.1X with Suite B");
  984. #ifdef CONFIG_IEEE80211R
  985. } else if (sel & WPA_KEY_MGMT_FT_IEEE8021X) {
  986. wpa_s->key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X;
  987. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/802.1X");
  988. } else if (sel & WPA_KEY_MGMT_FT_PSK) {
  989. wpa_s->key_mgmt = WPA_KEY_MGMT_FT_PSK;
  990. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/PSK");
  991. #endif /* CONFIG_IEEE80211R */
  992. #ifdef CONFIG_SAE
  993. } else if (sel & WPA_KEY_MGMT_SAE) {
  994. wpa_s->key_mgmt = WPA_KEY_MGMT_SAE;
  995. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT SAE");
  996. } else if (sel & WPA_KEY_MGMT_FT_SAE) {
  997. wpa_s->key_mgmt = WPA_KEY_MGMT_FT_SAE;
  998. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT FT/SAE");
  999. #endif /* CONFIG_SAE */
  1000. #ifdef CONFIG_IEEE80211W
  1001. } else if (sel & WPA_KEY_MGMT_IEEE8021X_SHA256) {
  1002. wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA256;
  1003. wpa_dbg(wpa_s, MSG_DEBUG,
  1004. "WPA: using KEY_MGMT 802.1X with SHA256");
  1005. } else if (sel & WPA_KEY_MGMT_PSK_SHA256) {
  1006. wpa_s->key_mgmt = WPA_KEY_MGMT_PSK_SHA256;
  1007. wpa_dbg(wpa_s, MSG_DEBUG,
  1008. "WPA: using KEY_MGMT PSK with SHA256");
  1009. #endif /* CONFIG_IEEE80211W */
  1010. } else if (sel & WPA_KEY_MGMT_IEEE8021X) {
  1011. wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
  1012. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT 802.1X");
  1013. } else if (sel & WPA_KEY_MGMT_PSK) {
  1014. wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
  1015. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-PSK");
  1016. } else if (sel & WPA_KEY_MGMT_WPA_NONE) {
  1017. wpa_s->key_mgmt = WPA_KEY_MGMT_WPA_NONE;
  1018. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-NONE");
  1019. #ifdef CONFIG_HS20
  1020. } else if (sel & WPA_KEY_MGMT_OSEN) {
  1021. wpa_s->key_mgmt = WPA_KEY_MGMT_OSEN;
  1022. wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: using KEY_MGMT OSEN");
  1023. #endif /* CONFIG_HS20 */
  1024. } else {
  1025. wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select "
  1026. "authenticated key management type");
  1027. return -1;
  1028. }
  1029. wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt);
  1030. wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE,
  1031. wpa_s->pairwise_cipher);
  1032. wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
  1033. #ifdef CONFIG_IEEE80211W
  1034. sel = ie.mgmt_group_cipher;
  1035. if ((ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
  1036. wpa_s->conf->pmf : ssid->ieee80211w) == NO_MGMT_FRAME_PROTECTION ||
  1037. !(ie.capabilities & WPA_CAPABILITY_MFPC))
  1038. sel = 0;
  1039. if (sel & WPA_CIPHER_AES_128_CMAC) {
  1040. wpa_s->mgmt_group_cipher = WPA_CIPHER_AES_128_CMAC;
  1041. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher "
  1042. "AES-128-CMAC");
  1043. } else if (sel & WPA_CIPHER_BIP_GMAC_128) {
  1044. wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_GMAC_128;
  1045. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher "
  1046. "BIP-GMAC-128");
  1047. } else if (sel & WPA_CIPHER_BIP_GMAC_256) {
  1048. wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_GMAC_256;
  1049. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher "
  1050. "BIP-GMAC-256");
  1051. } else if (sel & WPA_CIPHER_BIP_CMAC_256) {
  1052. wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_CMAC_256;
  1053. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher "
  1054. "BIP-CMAC-256");
  1055. } else {
  1056. wpa_s->mgmt_group_cipher = 0;
  1057. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher");
  1058. }
  1059. wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP,
  1060. wpa_s->mgmt_group_cipher);
  1061. wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP,
  1062. (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
  1063. wpa_s->conf->pmf : ssid->ieee80211w));
  1064. #endif /* CONFIG_IEEE80211W */
  1065. if (wpa_sm_set_assoc_wpa_ie_default(wpa_s->wpa, wpa_ie, wpa_ie_len)) {
  1066. wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to generate WPA IE");
  1067. return -1;
  1068. }
  1069. if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) {
  1070. wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL);
  1071. #ifndef CONFIG_NO_PBKDF2
  1072. if (bss && ssid->bssid_set && ssid->ssid_len == 0 &&
  1073. ssid->passphrase) {
  1074. u8 psk[PMK_LEN];
  1075. pbkdf2_sha1(ssid->passphrase, bss->ssid, bss->ssid_len,
  1076. 4096, psk, PMK_LEN);
  1077. wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)",
  1078. psk, PMK_LEN);
  1079. wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL);
  1080. }
  1081. #endif /* CONFIG_NO_PBKDF2 */
  1082. #ifdef CONFIG_EXT_PASSWORD
  1083. if (ssid->ext_psk) {
  1084. struct wpabuf *pw = ext_password_get(wpa_s->ext_pw,
  1085. ssid->ext_psk);
  1086. char pw_str[64 + 1];
  1087. u8 psk[PMK_LEN];
  1088. if (pw == NULL) {
  1089. wpa_msg(wpa_s, MSG_INFO, "EXT PW: No PSK "
  1090. "found from external storage");
  1091. return -1;
  1092. }
  1093. if (wpabuf_len(pw) < 8 || wpabuf_len(pw) > 64) {
  1094. wpa_msg(wpa_s, MSG_INFO, "EXT PW: Unexpected "
  1095. "PSK length %d in external storage",
  1096. (int) wpabuf_len(pw));
  1097. ext_password_free(pw);
  1098. return -1;
  1099. }
  1100. os_memcpy(pw_str, wpabuf_head(pw), wpabuf_len(pw));
  1101. pw_str[wpabuf_len(pw)] = '\0';
  1102. #ifndef CONFIG_NO_PBKDF2
  1103. if (wpabuf_len(pw) >= 8 && wpabuf_len(pw) < 64 && bss)
  1104. {
  1105. pbkdf2_sha1(pw_str, bss->ssid, bss->ssid_len,
  1106. 4096, psk, PMK_LEN);
  1107. os_memset(pw_str, 0, sizeof(pw_str));
  1108. wpa_hexdump_key(MSG_MSGDUMP, "PSK (from "
  1109. "external passphrase)",
  1110. psk, PMK_LEN);
  1111. wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL);
  1112. } else
  1113. #endif /* CONFIG_NO_PBKDF2 */
  1114. if (wpabuf_len(pw) == 2 * PMK_LEN) {
  1115. if (hexstr2bin(pw_str, psk, PMK_LEN) < 0) {
  1116. wpa_msg(wpa_s, MSG_INFO, "EXT PW: "
  1117. "Invalid PSK hex string");
  1118. os_memset(pw_str, 0, sizeof(pw_str));
  1119. ext_password_free(pw);
  1120. return -1;
  1121. }
  1122. wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL);
  1123. } else {
  1124. wpa_msg(wpa_s, MSG_INFO, "EXT PW: No suitable "
  1125. "PSK available");
  1126. os_memset(pw_str, 0, sizeof(pw_str));
  1127. ext_password_free(pw);
  1128. return -1;
  1129. }
  1130. os_memset(pw_str, 0, sizeof(pw_str));
  1131. ext_password_free(pw);
  1132. }
  1133. #endif /* CONFIG_EXT_PASSWORD */
  1134. } else
  1135. wpa_sm_set_pmk_from_pmksa(wpa_s->wpa);
  1136. return 0;
  1137. }
  1138. static void wpas_ext_capab_byte(struct wpa_supplicant *wpa_s, u8 *pos, int idx)
  1139. {
  1140. *pos = 0x00;
  1141. switch (idx) {
  1142. case 0: /* Bits 0-7 */
  1143. break;
  1144. case 1: /* Bits 8-15 */
  1145. break;
  1146. case 2: /* Bits 16-23 */
  1147. #ifdef CONFIG_WNM
  1148. *pos |= 0x02; /* Bit 17 - WNM-Sleep Mode */
  1149. *pos |= 0x08; /* Bit 19 - BSS Transition */
  1150. #endif /* CONFIG_WNM */
  1151. break;
  1152. case 3: /* Bits 24-31 */
  1153. #ifdef CONFIG_WNM
  1154. *pos |= 0x02; /* Bit 25 - SSID List */
  1155. #endif /* CONFIG_WNM */
  1156. #ifdef CONFIG_INTERWORKING
  1157. if (wpa_s->conf->interworking)
  1158. *pos |= 0x80; /* Bit 31 - Interworking */
  1159. #endif /* CONFIG_INTERWORKING */
  1160. break;
  1161. case 4: /* Bits 32-39 */
  1162. #ifdef CONFIG_INTERWORKING
  1163. if (wpa_s->drv_flags / WPA_DRIVER_FLAGS_QOS_MAPPING)
  1164. *pos |= 0x01; /* Bit 32 - QoS Map */
  1165. #endif /* CONFIG_INTERWORKING */
  1166. break;
  1167. case 5: /* Bits 40-47 */
  1168. #ifdef CONFIG_HS20
  1169. if (wpa_s->conf->hs20)
  1170. *pos |= 0x40; /* Bit 46 - WNM-Notification */
  1171. #endif /* CONFIG_HS20 */
  1172. break;
  1173. case 6: /* Bits 48-55 */
  1174. break;
  1175. }
  1176. }
  1177. int wpas_build_ext_capab(struct wpa_supplicant *wpa_s, u8 *buf, size_t buflen)
  1178. {
  1179. u8 *pos = buf;
  1180. u8 len = 6, i;
  1181. if (len < wpa_s->extended_capa_len)
  1182. len = wpa_s->extended_capa_len;
  1183. if (buflen < (size_t) len + 2) {
  1184. wpa_printf(MSG_INFO,
  1185. "Not enough room for building extended capabilities element");
  1186. return -1;
  1187. }
  1188. *pos++ = WLAN_EID_EXT_CAPAB;
  1189. *pos++ = len;
  1190. for (i = 0; i < len; i++, pos++) {
  1191. wpas_ext_capab_byte(wpa_s, pos, i);
  1192. if (i < wpa_s->extended_capa_len) {
  1193. *pos &= ~wpa_s->extended_capa_mask[i];
  1194. *pos |= wpa_s->extended_capa[i];
  1195. }
  1196. }
  1197. while (len > 0 && buf[1 + len] == 0) {
  1198. len--;
  1199. buf[1] = len;
  1200. }
  1201. if (len == 0)
  1202. return 0;
  1203. return 2 + len;
  1204. }
  1205. static int wpas_valid_bss(struct wpa_supplicant *wpa_s,
  1206. struct wpa_bss *test_bss)
  1207. {
  1208. struct wpa_bss *bss;
  1209. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  1210. if (bss == test_bss)
  1211. return 1;
  1212. }
  1213. return 0;
  1214. }
  1215. static int wpas_valid_ssid(struct wpa_supplicant *wpa_s,
  1216. struct wpa_ssid *test_ssid)
  1217. {
  1218. struct wpa_ssid *ssid;
  1219. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  1220. if (ssid == test_ssid)
  1221. return 1;
  1222. }
  1223. return 0;
  1224. }
  1225. int wpas_valid_bss_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *test_bss,
  1226. struct wpa_ssid *test_ssid)
  1227. {
  1228. if (test_bss && !wpas_valid_bss(wpa_s, test_bss))
  1229. return 0;
  1230. return test_ssid == NULL || wpas_valid_ssid(wpa_s, test_ssid);
  1231. }
  1232. void wpas_connect_work_free(struct wpa_connect_work *cwork)
  1233. {
  1234. if (cwork == NULL)
  1235. return;
  1236. os_free(cwork);
  1237. }
  1238. void wpas_connect_work_done(struct wpa_supplicant *wpa_s)
  1239. {
  1240. struct wpa_connect_work *cwork;
  1241. struct wpa_radio_work *work = wpa_s->connect_work;
  1242. if (!work)
  1243. return;
  1244. wpa_s->connect_work = NULL;
  1245. cwork = work->ctx;
  1246. work->ctx = NULL;
  1247. wpas_connect_work_free(cwork);
  1248. radio_work_done(work);
  1249. }
  1250. int wpas_update_random_addr(struct wpa_supplicant *wpa_s, int style)
  1251. {
  1252. struct os_reltime now;
  1253. u8 addr[ETH_ALEN];
  1254. os_get_reltime(&now);
  1255. if (wpa_s->last_mac_addr_style == style &&
  1256. wpa_s->last_mac_addr_change.sec != 0 &&
  1257. !os_reltime_expired(&now, &wpa_s->last_mac_addr_change,
  1258. wpa_s->conf->rand_addr_lifetime)) {
  1259. wpa_msg(wpa_s, MSG_DEBUG,
  1260. "Previously selected random MAC address has not yet expired");
  1261. return 0;
  1262. }
  1263. switch (style) {
  1264. case 1:
  1265. if (random_mac_addr(addr) < 0)
  1266. return -1;
  1267. break;
  1268. case 2:
  1269. os_memcpy(addr, wpa_s->perm_addr, ETH_ALEN);
  1270. if (random_mac_addr_keep_oui(addr) < 0)
  1271. return -1;
  1272. break;
  1273. default:
  1274. return -1;
  1275. }
  1276. if (wpa_drv_set_mac_addr(wpa_s, addr) < 0) {
  1277. wpa_msg(wpa_s, MSG_INFO,
  1278. "Failed to set random MAC address");
  1279. return -1;
  1280. }
  1281. os_get_reltime(&wpa_s->last_mac_addr_change);
  1282. wpa_s->mac_addr_changed = 1;
  1283. wpa_s->last_mac_addr_style = style;
  1284. if (wpa_supplicant_update_mac_addr(wpa_s) < 0) {
  1285. wpa_msg(wpa_s, MSG_INFO,
  1286. "Could not update MAC address information");
  1287. return -1;
  1288. }
  1289. wpa_msg(wpa_s, MSG_DEBUG, "Using random MAC address " MACSTR,
  1290. MAC2STR(addr));
  1291. return 0;
  1292. }
  1293. int wpas_update_random_addr_disassoc(struct wpa_supplicant *wpa_s)
  1294. {
  1295. if (wpa_s->wpa_state >= WPA_AUTHENTICATING ||
  1296. !wpa_s->conf->preassoc_mac_addr)
  1297. return 0;
  1298. return wpas_update_random_addr(wpa_s, wpa_s->conf->preassoc_mac_addr);
  1299. }
  1300. static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit);
  1301. /**
  1302. * wpa_supplicant_associate - Request association
  1303. * @wpa_s: Pointer to wpa_supplicant data
  1304. * @bss: Scan results for the selected BSS, or %NULL if not available
  1305. * @ssid: Configuration data for the selected network
  1306. *
  1307. * This function is used to request %wpa_supplicant to associate with a BSS.
  1308. */
  1309. void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
  1310. struct wpa_bss *bss, struct wpa_ssid *ssid)
  1311. {
  1312. struct wpa_connect_work *cwork;
  1313. int rand_style;
  1314. if (ssid->mac_addr == -1)
  1315. rand_style = wpa_s->conf->mac_addr;
  1316. else
  1317. rand_style = ssid->mac_addr;
  1318. if (wpa_s->last_ssid == ssid) {
  1319. wpa_dbg(wpa_s, MSG_DEBUG, "Re-association to the same ESS");
  1320. } else if (rand_style > 0) {
  1321. if (wpas_update_random_addr(wpa_s, rand_style) < 0)
  1322. return;
  1323. wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
  1324. } else if (wpa_s->mac_addr_changed) {
  1325. if (wpa_drv_set_mac_addr(wpa_s, NULL) < 0) {
  1326. wpa_msg(wpa_s, MSG_INFO,
  1327. "Could not restore permanent MAC address");
  1328. return;
  1329. }
  1330. wpa_s->mac_addr_changed = 0;
  1331. if (wpa_supplicant_update_mac_addr(wpa_s) < 0) {
  1332. wpa_msg(wpa_s, MSG_INFO,
  1333. "Could not update MAC address information");
  1334. return;
  1335. }
  1336. wpa_msg(wpa_s, MSG_DEBUG, "Using permanent MAC address");
  1337. }
  1338. wpa_s->last_ssid = ssid;
  1339. #ifdef CONFIG_IBSS_RSN
  1340. ibss_rsn_deinit(wpa_s->ibss_rsn);
  1341. wpa_s->ibss_rsn = NULL;
  1342. #endif /* CONFIG_IBSS_RSN */
  1343. if (ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO ||
  1344. ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
  1345. #ifdef CONFIG_AP
  1346. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP)) {
  1347. wpa_msg(wpa_s, MSG_INFO, "Driver does not support AP "
  1348. "mode");
  1349. return;
  1350. }
  1351. if (wpa_supplicant_create_ap(wpa_s, ssid) < 0) {
  1352. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1353. if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
  1354. wpas_p2p_ap_setup_failed(wpa_s);
  1355. return;
  1356. }
  1357. wpa_s->current_bss = bss;
  1358. #else /* CONFIG_AP */
  1359. wpa_msg(wpa_s, MSG_ERROR, "AP mode support not included in "
  1360. "the build");
  1361. #endif /* CONFIG_AP */
  1362. return;
  1363. }
  1364. if (ssid->mode == WPAS_MODE_MESH) {
  1365. #ifdef CONFIG_MESH
  1366. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_MESH)) {
  1367. wpa_msg(wpa_s, MSG_INFO,
  1368. "Driver does not support mesh mode");
  1369. return;
  1370. }
  1371. if (bss)
  1372. ssid->frequency = bss->freq;
  1373. if (wpa_supplicant_join_mesh(wpa_s, ssid) < 0) {
  1374. wpa_msg(wpa_s, MSG_ERROR, "Could not join mesh");
  1375. return;
  1376. }
  1377. wpa_s->current_bss = bss;
  1378. wpa_msg_ctrl(wpa_s, MSG_INFO, MESH_GROUP_STARTED
  1379. "ssid=\"%s\" id=%d",
  1380. wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
  1381. ssid->id);
  1382. #else /* CONFIG_MESH */
  1383. wpa_msg(wpa_s, MSG_ERROR,
  1384. "mesh mode support not included in the build");
  1385. #endif /* CONFIG_MESH */
  1386. return;
  1387. }
  1388. #ifdef CONFIG_TDLS
  1389. if (bss)
  1390. wpa_tdls_ap_ies(wpa_s->wpa, (const u8 *) (bss + 1),
  1391. bss->ie_len);
  1392. #endif /* CONFIG_TDLS */
  1393. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
  1394. ssid->mode == IEEE80211_MODE_INFRA) {
  1395. sme_authenticate(wpa_s, bss, ssid);
  1396. return;
  1397. }
  1398. if (wpa_s->connect_work) {
  1399. wpa_dbg(wpa_s, MSG_DEBUG, "Reject wpa_supplicant_associate() call since connect_work exist");
  1400. return;
  1401. }
  1402. if (radio_work_pending(wpa_s, "connect")) {
  1403. wpa_dbg(wpa_s, MSG_DEBUG, "Reject wpa_supplicant_associate() call since pending work exist");
  1404. return;
  1405. }
  1406. cwork = os_zalloc(sizeof(*cwork));
  1407. if (cwork == NULL)
  1408. return;
  1409. cwork->bss = bss;
  1410. cwork->ssid = ssid;
  1411. if (radio_add_work(wpa_s, bss ? bss->freq : 0, "connect", 1,
  1412. wpas_start_assoc_cb, cwork) < 0) {
  1413. os_free(cwork);
  1414. }
  1415. }
  1416. static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit)
  1417. {
  1418. struct wpa_connect_work *cwork = work->ctx;
  1419. struct wpa_bss *bss = cwork->bss;
  1420. struct wpa_ssid *ssid = cwork->ssid;
  1421. struct wpa_supplicant *wpa_s = work->wpa_s;
  1422. u8 wpa_ie[200];
  1423. size_t wpa_ie_len;
  1424. int use_crypt, ret, i, bssid_changed;
  1425. int algs = WPA_AUTH_ALG_OPEN;
  1426. unsigned int cipher_pairwise, cipher_group;
  1427. struct wpa_driver_associate_params params;
  1428. int wep_keys_set = 0;
  1429. int assoc_failed = 0;
  1430. struct wpa_ssid *old_ssid;
  1431. #ifdef CONFIG_HT_OVERRIDES
  1432. struct ieee80211_ht_capabilities htcaps;
  1433. struct ieee80211_ht_capabilities htcaps_mask;
  1434. #endif /* CONFIG_HT_OVERRIDES */
  1435. #ifdef CONFIG_VHT_OVERRIDES
  1436. struct ieee80211_vht_capabilities vhtcaps;
  1437. struct ieee80211_vht_capabilities vhtcaps_mask;
  1438. #endif /* CONFIG_VHT_OVERRIDES */
  1439. if (deinit) {
  1440. if (work->started) {
  1441. wpa_s->connect_work = NULL;
  1442. /* cancel possible auth. timeout */
  1443. eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s,
  1444. NULL);
  1445. }
  1446. wpas_connect_work_free(cwork);
  1447. return;
  1448. }
  1449. wpa_s->connect_work = work;
  1450. if (cwork->bss_removed || !wpas_valid_bss_ssid(wpa_s, bss, ssid)) {
  1451. wpa_dbg(wpa_s, MSG_DEBUG, "BSS/SSID entry for association not valid anymore - drop connection attempt");
  1452. wpas_connect_work_done(wpa_s);
  1453. return;
  1454. }
  1455. os_memset(&params, 0, sizeof(params));
  1456. wpa_s->reassociate = 0;
  1457. wpa_s->eap_expected_failure = 0;
  1458. if (bss &&
  1459. (!wpas_driver_bss_selection(wpa_s) || wpas_wps_searching(wpa_s))) {
  1460. #ifdef CONFIG_IEEE80211R
  1461. const u8 *ie, *md = NULL;
  1462. #endif /* CONFIG_IEEE80211R */
  1463. wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR
  1464. " (SSID='%s' freq=%d MHz)", MAC2STR(bss->bssid),
  1465. wpa_ssid_txt(bss->ssid, bss->ssid_len), bss->freq);
  1466. bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
  1467. os_memset(wpa_s->bssid, 0, ETH_ALEN);
  1468. os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN);
  1469. if (bssid_changed)
  1470. wpas_notify_bssid_changed(wpa_s);
  1471. #ifdef CONFIG_IEEE80211R
  1472. ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
  1473. if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN)
  1474. md = ie + 2;
  1475. wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0);
  1476. if (md) {
  1477. /* Prepare for the next transition */
  1478. wpa_ft_prepare_auth_request(wpa_s->wpa, ie);
  1479. }
  1480. #endif /* CONFIG_IEEE80211R */
  1481. #ifdef CONFIG_WPS
  1482. } else if ((ssid->ssid == NULL || ssid->ssid_len == 0) &&
  1483. wpa_s->conf->ap_scan == 2 &&
  1484. (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
  1485. /* Use ap_scan==1 style network selection to find the network
  1486. */
  1487. wpas_connect_work_done(wpa_s);
  1488. wpa_s->scan_req = MANUAL_SCAN_REQ;
  1489. wpa_s->reassociate = 1;
  1490. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1491. return;
  1492. #endif /* CONFIG_WPS */
  1493. } else {
  1494. wpa_msg(wpa_s, MSG_INFO, "Trying to associate with SSID '%s'",
  1495. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  1496. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1497. }
  1498. wpa_supplicant_cancel_sched_scan(wpa_s);
  1499. wpa_supplicant_cancel_scan(wpa_s);
  1500. /* Starting new association, so clear the possibly used WPA IE from the
  1501. * previous association. */
  1502. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  1503. #ifdef IEEE8021X_EAPOL
  1504. if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  1505. if (ssid->leap) {
  1506. if (ssid->non_leap == 0)
  1507. algs = WPA_AUTH_ALG_LEAP;
  1508. else
  1509. algs |= WPA_AUTH_ALG_LEAP;
  1510. }
  1511. }
  1512. #endif /* IEEE8021X_EAPOL */
  1513. wpa_dbg(wpa_s, MSG_DEBUG, "Automatic auth_alg selection: 0x%x", algs);
  1514. if (ssid->auth_alg) {
  1515. algs = ssid->auth_alg;
  1516. wpa_dbg(wpa_s, MSG_DEBUG, "Overriding auth_alg selection: "
  1517. "0x%x", algs);
  1518. }
  1519. if (bss && (wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) ||
  1520. wpa_bss_get_ie(bss, WLAN_EID_RSN)) &&
  1521. wpa_key_mgmt_wpa(ssid->key_mgmt)) {
  1522. int try_opportunistic;
  1523. try_opportunistic = (ssid->proactive_key_caching < 0 ?
  1524. wpa_s->conf->okc :
  1525. ssid->proactive_key_caching) &&
  1526. (ssid->proto & WPA_PROTO_RSN);
  1527. if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid,
  1528. ssid, try_opportunistic) == 0)
  1529. eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
  1530. wpa_ie_len = sizeof(wpa_ie);
  1531. if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
  1532. wpa_ie, &wpa_ie_len)) {
  1533. wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA "
  1534. "key management and encryption suites");
  1535. wpas_connect_work_done(wpa_s);
  1536. return;
  1537. }
  1538. } else if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && bss &&
  1539. wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt)) {
  1540. /*
  1541. * Both WPA and non-WPA IEEE 802.1X enabled in configuration -
  1542. * use non-WPA since the scan results did not indicate that the
  1543. * AP is using WPA or WPA2.
  1544. */
  1545. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  1546. wpa_ie_len = 0;
  1547. wpa_s->wpa_proto = 0;
  1548. } else if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
  1549. wpa_ie_len = sizeof(wpa_ie);
  1550. if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
  1551. wpa_ie, &wpa_ie_len)) {
  1552. wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA "
  1553. "key management and encryption suites (no "
  1554. "scan results)");
  1555. wpas_connect_work_done(wpa_s);
  1556. return;
  1557. }
  1558. #ifdef CONFIG_WPS
  1559. } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
  1560. struct wpabuf *wps_ie;
  1561. wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid));
  1562. if (wps_ie && wpabuf_len(wps_ie) <= sizeof(wpa_ie)) {
  1563. wpa_ie_len = wpabuf_len(wps_ie);
  1564. os_memcpy(wpa_ie, wpabuf_head(wps_ie), wpa_ie_len);
  1565. } else
  1566. wpa_ie_len = 0;
  1567. wpabuf_free(wps_ie);
  1568. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  1569. if (!bss || (bss->caps & IEEE80211_CAP_PRIVACY))
  1570. params.wps = WPS_MODE_PRIVACY;
  1571. else
  1572. params.wps = WPS_MODE_OPEN;
  1573. wpa_s->wpa_proto = 0;
  1574. #endif /* CONFIG_WPS */
  1575. } else {
  1576. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  1577. wpa_ie_len = 0;
  1578. wpa_s->wpa_proto = 0;
  1579. }
  1580. #ifdef CONFIG_P2P
  1581. if (wpa_s->global->p2p) {
  1582. u8 *pos;
  1583. size_t len;
  1584. int res;
  1585. pos = wpa_ie + wpa_ie_len;
  1586. len = sizeof(wpa_ie) - wpa_ie_len;
  1587. res = wpas_p2p_assoc_req_ie(wpa_s, bss, pos, len,
  1588. ssid->p2p_group);
  1589. if (res >= 0)
  1590. wpa_ie_len += res;
  1591. }
  1592. wpa_s->cross_connect_disallowed = 0;
  1593. if (bss) {
  1594. struct wpabuf *p2p;
  1595. p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
  1596. if (p2p) {
  1597. wpa_s->cross_connect_disallowed =
  1598. p2p_get_cross_connect_disallowed(p2p);
  1599. wpabuf_free(p2p);
  1600. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: WLAN AP %s cross "
  1601. "connection",
  1602. wpa_s->cross_connect_disallowed ?
  1603. "disallows" : "allows");
  1604. }
  1605. }
  1606. os_memset(wpa_s->p2p_ip_addr_info, 0, sizeof(wpa_s->p2p_ip_addr_info));
  1607. #endif /* CONFIG_P2P */
  1608. #ifdef CONFIG_HS20
  1609. if (is_hs20_network(wpa_s, ssid, bss)) {
  1610. struct wpabuf *hs20;
  1611. hs20 = wpabuf_alloc(20);
  1612. if (hs20) {
  1613. int pps_mo_id = hs20_get_pps_mo_id(wpa_s, ssid);
  1614. size_t len;
  1615. wpas_hs20_add_indication(hs20, pps_mo_id);
  1616. len = sizeof(wpa_ie) - wpa_ie_len;
  1617. if (wpabuf_len(hs20) <= len) {
  1618. os_memcpy(wpa_ie + wpa_ie_len,
  1619. wpabuf_head(hs20), wpabuf_len(hs20));
  1620. wpa_ie_len += wpabuf_len(hs20);
  1621. }
  1622. wpabuf_free(hs20);
  1623. }
  1624. }
  1625. #endif /* CONFIG_HS20 */
  1626. /*
  1627. * Workaround: Add Extended Capabilities element only if the AP
  1628. * included this element in Beacon/Probe Response frames. Some older
  1629. * APs seem to have interoperability issues if this element is
  1630. * included, so while the standard may require us to include the
  1631. * element in all cases, it is justifiable to skip it to avoid
  1632. * interoperability issues.
  1633. */
  1634. if (!bss || wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB)) {
  1635. u8 ext_capab[18];
  1636. int ext_capab_len;
  1637. ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab,
  1638. sizeof(ext_capab));
  1639. if (ext_capab_len > 0) {
  1640. u8 *pos = wpa_ie;
  1641. if (wpa_ie_len > 0 && pos[0] == WLAN_EID_RSN)
  1642. pos += 2 + pos[1];
  1643. os_memmove(pos + ext_capab_len, pos,
  1644. wpa_ie_len - (pos - wpa_ie));
  1645. wpa_ie_len += ext_capab_len;
  1646. os_memcpy(pos, ext_capab, ext_capab_len);
  1647. }
  1648. }
  1649. wpa_clear_keys(wpa_s, bss ? bss->bssid : NULL);
  1650. use_crypt = 1;
  1651. cipher_pairwise = wpa_s->pairwise_cipher;
  1652. cipher_group = wpa_s->group_cipher;
  1653. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1654. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  1655. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE)
  1656. use_crypt = 0;
  1657. if (wpa_set_wep_keys(wpa_s, ssid)) {
  1658. use_crypt = 1;
  1659. wep_keys_set = 1;
  1660. }
  1661. }
  1662. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)
  1663. use_crypt = 0;
  1664. #ifdef IEEE8021X_EAPOL
  1665. if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  1666. if ((ssid->eapol_flags &
  1667. (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  1668. EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) == 0 &&
  1669. !wep_keys_set) {
  1670. use_crypt = 0;
  1671. } else {
  1672. /* Assume that dynamic WEP-104 keys will be used and
  1673. * set cipher suites in order for drivers to expect
  1674. * encryption. */
  1675. cipher_pairwise = cipher_group = WPA_CIPHER_WEP104;
  1676. }
  1677. }
  1678. #endif /* IEEE8021X_EAPOL */
  1679. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1680. /* Set the key before (and later after) association */
  1681. wpa_supplicant_set_wpa_none_key(wpa_s, ssid);
  1682. }
  1683. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING);
  1684. if (bss) {
  1685. params.ssid = bss->ssid;
  1686. params.ssid_len = bss->ssid_len;
  1687. if (!wpas_driver_bss_selection(wpa_s) || ssid->bssid_set) {
  1688. wpa_printf(MSG_DEBUG, "Limit connection to BSSID "
  1689. MACSTR " freq=%u MHz based on scan results "
  1690. "(bssid_set=%d)",
  1691. MAC2STR(bss->bssid), bss->freq,
  1692. ssid->bssid_set);
  1693. params.bssid = bss->bssid;
  1694. params.freq.freq = bss->freq;
  1695. }
  1696. params.bssid_hint = bss->bssid;
  1697. params.freq_hint = bss->freq;
  1698. } else {
  1699. params.ssid = ssid->ssid;
  1700. params.ssid_len = ssid->ssid_len;
  1701. }
  1702. if (ssid->mode == WPAS_MODE_IBSS && ssid->bssid_set &&
  1703. wpa_s->conf->ap_scan == 2) {
  1704. params.bssid = ssid->bssid;
  1705. params.fixed_bssid = 1;
  1706. }
  1707. /* Initial frequency for IBSS/mesh */
  1708. if ((ssid->mode == WPAS_MODE_IBSS || ssid->mode == WPAS_MODE_MESH) &&
  1709. ssid->frequency > 0 && params.freq.freq == 0) {
  1710. enum hostapd_hw_mode hw_mode;
  1711. u8 channel;
  1712. params.freq.freq = ssid->frequency;
  1713. hw_mode = ieee80211_freq_to_chan(ssid->frequency, &channel);
  1714. for (i = 0; wpa_s->hw.modes && i < wpa_s->hw.num_modes; i++) {
  1715. if (wpa_s->hw.modes[i].mode == hw_mode) {
  1716. struct hostapd_hw_modes *mode;
  1717. mode = &wpa_s->hw.modes[i];
  1718. params.freq.ht_enabled = ht_supported(mode);
  1719. break;
  1720. }
  1721. }
  1722. }
  1723. if (ssid->mode == WPAS_MODE_IBSS) {
  1724. if (ssid->beacon_int)
  1725. params.beacon_int = ssid->beacon_int;
  1726. else
  1727. params.beacon_int = wpa_s->conf->beacon_int;
  1728. }
  1729. params.wpa_ie = wpa_ie;
  1730. params.wpa_ie_len = wpa_ie_len;
  1731. params.pairwise_suite = cipher_pairwise;
  1732. params.group_suite = cipher_group;
  1733. params.key_mgmt_suite = wpa_s->key_mgmt;
  1734. params.wpa_proto = wpa_s->wpa_proto;
  1735. params.auth_alg = algs;
  1736. params.mode = ssid->mode;
  1737. params.bg_scan_period = ssid->bg_scan_period;
  1738. for (i = 0; i < NUM_WEP_KEYS; i++) {
  1739. if (ssid->wep_key_len[i])
  1740. params.wep_key[i] = ssid->wep_key[i];
  1741. params.wep_key_len[i] = ssid->wep_key_len[i];
  1742. }
  1743. params.wep_tx_keyidx = ssid->wep_tx_keyidx;
  1744. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1745. (params.key_mgmt_suite == WPA_KEY_MGMT_PSK ||
  1746. params.key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) {
  1747. params.passphrase = ssid->passphrase;
  1748. if (ssid->psk_set)
  1749. params.psk = ssid->psk;
  1750. }
  1751. if (wpa_s->conf->key_mgmt_offload) {
  1752. if (params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
  1753. params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
  1754. params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B)
  1755. params.req_key_mgmt_offload =
  1756. ssid->proactive_key_caching < 0 ?
  1757. wpa_s->conf->okc : ssid->proactive_key_caching;
  1758. else
  1759. params.req_key_mgmt_offload = 1;
  1760. if ((params.key_mgmt_suite == WPA_KEY_MGMT_PSK ||
  1761. params.key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
  1762. params.key_mgmt_suite == WPA_KEY_MGMT_FT_PSK) &&
  1763. ssid->psk_set)
  1764. params.psk = ssid->psk;
  1765. }
  1766. params.drop_unencrypted = use_crypt;
  1767. #ifdef CONFIG_IEEE80211W
  1768. params.mgmt_frame_protection =
  1769. ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ?
  1770. wpa_s->conf->pmf : ssid->ieee80211w;
  1771. if (params.mgmt_frame_protection != NO_MGMT_FRAME_PROTECTION && bss) {
  1772. const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  1773. struct wpa_ie_data ie;
  1774. if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ie) == 0 &&
  1775. ie.capabilities &
  1776. (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) {
  1777. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected AP supports "
  1778. "MFP: require MFP");
  1779. params.mgmt_frame_protection =
  1780. MGMT_FRAME_PROTECTION_REQUIRED;
  1781. }
  1782. }
  1783. #endif /* CONFIG_IEEE80211W */
  1784. params.p2p = ssid->p2p_group;
  1785. if (wpa_s->parent->set_sta_uapsd)
  1786. params.uapsd = wpa_s->parent->sta_uapsd;
  1787. else
  1788. params.uapsd = -1;
  1789. #ifdef CONFIG_HT_OVERRIDES
  1790. os_memset(&htcaps, 0, sizeof(htcaps));
  1791. os_memset(&htcaps_mask, 0, sizeof(htcaps_mask));
  1792. params.htcaps = (u8 *) &htcaps;
  1793. params.htcaps_mask = (u8 *) &htcaps_mask;
  1794. wpa_supplicant_apply_ht_overrides(wpa_s, ssid, &params);
  1795. #endif /* CONFIG_HT_OVERRIDES */
  1796. #ifdef CONFIG_VHT_OVERRIDES
  1797. os_memset(&vhtcaps, 0, sizeof(vhtcaps));
  1798. os_memset(&vhtcaps_mask, 0, sizeof(vhtcaps_mask));
  1799. params.vhtcaps = &vhtcaps;
  1800. params.vhtcaps_mask = &vhtcaps_mask;
  1801. wpa_supplicant_apply_vht_overrides(wpa_s, wpa_s->current_ssid, &params);
  1802. #endif /* CONFIG_VHT_OVERRIDES */
  1803. #ifdef CONFIG_P2P
  1804. /*
  1805. * If multi-channel concurrency is not supported, check for any
  1806. * frequency conflict. In case of any frequency conflict, remove the
  1807. * least prioritized connection.
  1808. */
  1809. if (wpa_s->num_multichan_concurrent < 2) {
  1810. int freq, num;
  1811. num = get_shared_radio_freqs(wpa_s, &freq, 1);
  1812. if (num > 0 && freq > 0 && freq != params.freq.freq) {
  1813. wpa_printf(MSG_DEBUG,
  1814. "Assoc conflicting freq found (%d != %d)",
  1815. freq, params.freq.freq);
  1816. if (wpas_p2p_handle_frequency_conflicts(
  1817. wpa_s, params.freq.freq, ssid) < 0) {
  1818. wpas_connect_work_done(wpa_s);
  1819. return;
  1820. }
  1821. }
  1822. }
  1823. #endif /* CONFIG_P2P */
  1824. ret = wpa_drv_associate(wpa_s, &params);
  1825. if (ret < 0) {
  1826. wpa_msg(wpa_s, MSG_INFO, "Association request to the driver "
  1827. "failed");
  1828. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SANE_ERROR_CODES) {
  1829. /*
  1830. * The driver is known to mean what is saying, so we
  1831. * can stop right here; the association will not
  1832. * succeed.
  1833. */
  1834. wpas_connection_failed(wpa_s, wpa_s->pending_bssid);
  1835. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1836. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1837. return;
  1838. }
  1839. /* try to continue anyway; new association will be tried again
  1840. * after timeout */
  1841. assoc_failed = 1;
  1842. }
  1843. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1844. /* Set the key after the association just in case association
  1845. * cleared the previously configured key. */
  1846. wpa_supplicant_set_wpa_none_key(wpa_s, ssid);
  1847. /* No need to timeout authentication since there is no key
  1848. * management. */
  1849. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1850. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1851. #ifdef CONFIG_IBSS_RSN
  1852. } else if (ssid->mode == WPAS_MODE_IBSS &&
  1853. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  1854. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) {
  1855. /*
  1856. * RSN IBSS authentication is per-STA and we can disable the
  1857. * per-BSSID authentication.
  1858. */
  1859. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1860. #endif /* CONFIG_IBSS_RSN */
  1861. } else {
  1862. /* Timeout for IEEE 802.11 authentication and association */
  1863. int timeout = 60;
  1864. if (assoc_failed) {
  1865. /* give IBSS a bit more time */
  1866. timeout = ssid->mode == WPAS_MODE_IBSS ? 10 : 5;
  1867. } else if (wpa_s->conf->ap_scan == 1) {
  1868. /* give IBSS a bit more time */
  1869. timeout = ssid->mode == WPAS_MODE_IBSS ? 20 : 10;
  1870. }
  1871. wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0);
  1872. }
  1873. if (wep_keys_set &&
  1874. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC)) {
  1875. /* Set static WEP keys again */
  1876. wpa_set_wep_keys(wpa_s, ssid);
  1877. }
  1878. if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) {
  1879. /*
  1880. * Do not allow EAP session resumption between different
  1881. * network configurations.
  1882. */
  1883. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1884. }
  1885. old_ssid = wpa_s->current_ssid;
  1886. wpa_s->current_ssid = ssid;
  1887. wpa_s->current_bss = bss;
  1888. wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
  1889. wpa_supplicant_initiate_eapol(wpa_s);
  1890. if (old_ssid != wpa_s->current_ssid)
  1891. wpas_notify_network_changed(wpa_s);
  1892. }
  1893. static void wpa_supplicant_clear_connection(struct wpa_supplicant *wpa_s,
  1894. const u8 *addr)
  1895. {
  1896. struct wpa_ssid *old_ssid;
  1897. wpas_connect_work_done(wpa_s);
  1898. wpa_clear_keys(wpa_s, addr);
  1899. old_ssid = wpa_s->current_ssid;
  1900. wpa_supplicant_mark_disassoc(wpa_s);
  1901. wpa_sm_set_config(wpa_s->wpa, NULL);
  1902. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  1903. if (old_ssid != wpa_s->current_ssid)
  1904. wpas_notify_network_changed(wpa_s);
  1905. eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
  1906. }
  1907. /**
  1908. * wpa_supplicant_deauthenticate - Deauthenticate the current connection
  1909. * @wpa_s: Pointer to wpa_supplicant data
  1910. * @reason_code: IEEE 802.11 reason code for the deauthenticate frame
  1911. *
  1912. * This function is used to request %wpa_supplicant to deauthenticate from the
  1913. * current AP.
  1914. */
  1915. void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
  1916. int reason_code)
  1917. {
  1918. u8 *addr = NULL;
  1919. union wpa_event_data event;
  1920. int zero_addr = 0;
  1921. wpa_dbg(wpa_s, MSG_DEBUG, "Request to deauthenticate - bssid=" MACSTR
  1922. " pending_bssid=" MACSTR " reason=%d state=%s",
  1923. MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
  1924. reason_code, wpa_supplicant_state_txt(wpa_s->wpa_state));
  1925. if (!is_zero_ether_addr(wpa_s->bssid))
  1926. addr = wpa_s->bssid;
  1927. else if (!is_zero_ether_addr(wpa_s->pending_bssid) &&
  1928. (wpa_s->wpa_state == WPA_AUTHENTICATING ||
  1929. wpa_s->wpa_state == WPA_ASSOCIATING))
  1930. addr = wpa_s->pending_bssid;
  1931. else if (wpa_s->wpa_state == WPA_ASSOCIATING) {
  1932. /*
  1933. * When using driver-based BSS selection, we may not know the
  1934. * BSSID with which we are currently trying to associate. We
  1935. * need to notify the driver of this disconnection even in such
  1936. * a case, so use the all zeros address here.
  1937. */
  1938. addr = wpa_s->bssid;
  1939. zero_addr = 1;
  1940. }
  1941. #ifdef CONFIG_TDLS
  1942. wpa_tdls_teardown_peers(wpa_s->wpa);
  1943. #endif /* CONFIG_TDLS */
  1944. #ifdef CONFIG_MESH
  1945. if (wpa_s->ifmsh) {
  1946. wpa_msg_ctrl(wpa_s, MSG_INFO, MESH_GROUP_REMOVED "%s",
  1947. wpa_s->ifname);
  1948. wpa_supplicant_leave_mesh(wpa_s);
  1949. }
  1950. #endif /* CONFIG_MESH */
  1951. if (addr) {
  1952. wpa_drv_deauthenticate(wpa_s, addr, reason_code);
  1953. os_memset(&event, 0, sizeof(event));
  1954. event.deauth_info.reason_code = (u16) reason_code;
  1955. event.deauth_info.locally_generated = 1;
  1956. wpa_supplicant_event(wpa_s, EVENT_DEAUTH, &event);
  1957. if (zero_addr)
  1958. addr = NULL;
  1959. }
  1960. wpa_supplicant_clear_connection(wpa_s, addr);
  1961. }
  1962. static void wpa_supplicant_enable_one_network(struct wpa_supplicant *wpa_s,
  1963. struct wpa_ssid *ssid)
  1964. {
  1965. if (!ssid || !ssid->disabled || ssid->disabled == 2)
  1966. return;
  1967. ssid->disabled = 0;
  1968. wpas_clear_temp_disabled(wpa_s, ssid, 1);
  1969. wpas_notify_network_enabled_changed(wpa_s, ssid);
  1970. /*
  1971. * Try to reassociate since there is no current configuration and a new
  1972. * network was made available.
  1973. */
  1974. if (!wpa_s->current_ssid && !wpa_s->disconnected)
  1975. wpa_s->reassociate = 1;
  1976. }
  1977. /**
  1978. * wpa_supplicant_enable_network - Mark a configured network as enabled
  1979. * @wpa_s: wpa_supplicant structure for a network interface
  1980. * @ssid: wpa_ssid structure for a configured network or %NULL
  1981. *
  1982. * Enables the specified network or all networks if no network specified.
  1983. */
  1984. void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s,
  1985. struct wpa_ssid *ssid)
  1986. {
  1987. if (ssid == NULL) {
  1988. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
  1989. wpa_supplicant_enable_one_network(wpa_s, ssid);
  1990. } else
  1991. wpa_supplicant_enable_one_network(wpa_s, ssid);
  1992. if (wpa_s->reassociate && !wpa_s->disconnected) {
  1993. if (wpa_s->sched_scanning) {
  1994. wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to add "
  1995. "new network to scan filters");
  1996. wpa_supplicant_cancel_sched_scan(wpa_s);
  1997. }
  1998. if (wpa_supplicant_fast_associate(wpa_s) != 1)
  1999. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2000. }
  2001. }
  2002. /**
  2003. * wpa_supplicant_disable_network - Mark a configured network as disabled
  2004. * @wpa_s: wpa_supplicant structure for a network interface
  2005. * @ssid: wpa_ssid structure for a configured network or %NULL
  2006. *
  2007. * Disables the specified network or all networks if no network specified.
  2008. */
  2009. void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s,
  2010. struct wpa_ssid *ssid)
  2011. {
  2012. struct wpa_ssid *other_ssid;
  2013. int was_disabled;
  2014. if (ssid == NULL) {
  2015. if (wpa_s->sched_scanning)
  2016. wpa_supplicant_cancel_sched_scan(wpa_s);
  2017. for (other_ssid = wpa_s->conf->ssid; other_ssid;
  2018. other_ssid = other_ssid->next) {
  2019. was_disabled = other_ssid->disabled;
  2020. if (was_disabled == 2)
  2021. continue; /* do not change persistent P2P group
  2022. * data */
  2023. other_ssid->disabled = 1;
  2024. if (was_disabled != other_ssid->disabled)
  2025. wpas_notify_network_enabled_changed(
  2026. wpa_s, other_ssid);
  2027. }
  2028. if (wpa_s->current_ssid)
  2029. wpa_supplicant_deauthenticate(
  2030. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  2031. } else if (ssid->disabled != 2) {
  2032. if (ssid == wpa_s->current_ssid)
  2033. wpa_supplicant_deauthenticate(
  2034. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  2035. was_disabled = ssid->disabled;
  2036. ssid->disabled = 1;
  2037. if (was_disabled != ssid->disabled) {
  2038. wpas_notify_network_enabled_changed(wpa_s, ssid);
  2039. if (wpa_s->sched_scanning) {
  2040. wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan "
  2041. "to remove network from filters");
  2042. wpa_supplicant_cancel_sched_scan(wpa_s);
  2043. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2044. }
  2045. }
  2046. }
  2047. }
  2048. /**
  2049. * wpa_supplicant_select_network - Attempt association with a network
  2050. * @wpa_s: wpa_supplicant structure for a network interface
  2051. * @ssid: wpa_ssid structure for a configured network or %NULL for any network
  2052. */
  2053. void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s,
  2054. struct wpa_ssid *ssid)
  2055. {
  2056. struct wpa_ssid *other_ssid;
  2057. int disconnected = 0;
  2058. if (ssid && ssid != wpa_s->current_ssid && wpa_s->current_ssid) {
  2059. wpa_supplicant_deauthenticate(
  2060. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  2061. disconnected = 1;
  2062. }
  2063. if (ssid)
  2064. wpas_clear_temp_disabled(wpa_s, ssid, 1);
  2065. /*
  2066. * Mark all other networks disabled or mark all networks enabled if no
  2067. * network specified.
  2068. */
  2069. for (other_ssid = wpa_s->conf->ssid; other_ssid;
  2070. other_ssid = other_ssid->next) {
  2071. int was_disabled = other_ssid->disabled;
  2072. if (was_disabled == 2)
  2073. continue; /* do not change persistent P2P group data */
  2074. other_ssid->disabled = ssid ? (ssid->id != other_ssid->id) : 0;
  2075. if (was_disabled && !other_ssid->disabled)
  2076. wpas_clear_temp_disabled(wpa_s, other_ssid, 0);
  2077. if (was_disabled != other_ssid->disabled)
  2078. wpas_notify_network_enabled_changed(wpa_s, other_ssid);
  2079. }
  2080. if (ssid && ssid == wpa_s->current_ssid && wpa_s->current_ssid) {
  2081. /* We are already associated with the selected network */
  2082. wpa_printf(MSG_DEBUG, "Already associated with the "
  2083. "selected network - do nothing");
  2084. return;
  2085. }
  2086. if (ssid) {
  2087. wpa_s->current_ssid = ssid;
  2088. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  2089. wpa_s->connect_without_scan =
  2090. (ssid->mode == WPAS_MODE_MESH) ? ssid : NULL;
  2091. } else {
  2092. wpa_s->connect_without_scan = NULL;
  2093. }
  2094. wpa_s->disconnected = 0;
  2095. wpa_s->reassociate = 1;
  2096. if (wpa_s->connect_without_scan ||
  2097. wpa_supplicant_fast_associate(wpa_s) != 1)
  2098. wpa_supplicant_req_scan(wpa_s, 0, disconnected ? 100000 : 0);
  2099. if (ssid)
  2100. wpas_notify_network_selected(wpa_s, ssid);
  2101. }
  2102. /**
  2103. * wpas_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path
  2104. * @wpa_s: wpa_supplicant structure for a network interface
  2105. * @pkcs11_engine_path: PKCS #11 engine path or NULL
  2106. * @pkcs11_module_path: PKCS #11 module path or NULL
  2107. * Returns: 0 on success; -1 on failure
  2108. *
  2109. * Sets the PKCS #11 engine and module path. Both have to be NULL or a valid
  2110. * path. If resetting the EAPOL state machine with the new PKCS #11 engine and
  2111. * module path fails the paths will be reset to the default value (NULL).
  2112. */
  2113. int wpas_set_pkcs11_engine_and_module_path(struct wpa_supplicant *wpa_s,
  2114. const char *pkcs11_engine_path,
  2115. const char *pkcs11_module_path)
  2116. {
  2117. char *pkcs11_engine_path_copy = NULL;
  2118. char *pkcs11_module_path_copy = NULL;
  2119. if (pkcs11_engine_path != NULL) {
  2120. pkcs11_engine_path_copy = os_strdup(pkcs11_engine_path);
  2121. if (pkcs11_engine_path_copy == NULL)
  2122. return -1;
  2123. }
  2124. if (pkcs11_module_path != NULL) {
  2125. pkcs11_module_path_copy = os_strdup(pkcs11_module_path);
  2126. if (pkcs11_module_path_copy == NULL) {
  2127. os_free(pkcs11_engine_path_copy);
  2128. return -1;
  2129. }
  2130. }
  2131. os_free(wpa_s->conf->pkcs11_engine_path);
  2132. os_free(wpa_s->conf->pkcs11_module_path);
  2133. wpa_s->conf->pkcs11_engine_path = pkcs11_engine_path_copy;
  2134. wpa_s->conf->pkcs11_module_path = pkcs11_module_path_copy;
  2135. wpa_sm_set_eapol(wpa_s->wpa, NULL);
  2136. eapol_sm_deinit(wpa_s->eapol);
  2137. wpa_s->eapol = NULL;
  2138. if (wpa_supplicant_init_eapol(wpa_s)) {
  2139. /* Error -> Reset paths to the default value (NULL) once. */
  2140. if (pkcs11_engine_path != NULL && pkcs11_module_path != NULL)
  2141. wpas_set_pkcs11_engine_and_module_path(wpa_s, NULL,
  2142. NULL);
  2143. return -1;
  2144. }
  2145. wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol);
  2146. return 0;
  2147. }
  2148. /**
  2149. * wpa_supplicant_set_ap_scan - Set AP scan mode for interface
  2150. * @wpa_s: wpa_supplicant structure for a network interface
  2151. * @ap_scan: AP scan mode
  2152. * Returns: 0 if succeed or -1 if ap_scan has an invalid value
  2153. *
  2154. */
  2155. int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s, int ap_scan)
  2156. {
  2157. int old_ap_scan;
  2158. if (ap_scan < 0 || ap_scan > 2)
  2159. return -1;
  2160. #ifdef ANDROID
  2161. if (ap_scan == 2 && ap_scan != wpa_s->conf->ap_scan &&
  2162. wpa_s->wpa_state >= WPA_ASSOCIATING &&
  2163. wpa_s->wpa_state < WPA_COMPLETED) {
  2164. wpa_printf(MSG_ERROR, "ap_scan = %d (%d) rejected while "
  2165. "associating", wpa_s->conf->ap_scan, ap_scan);
  2166. return 0;
  2167. }
  2168. #endif /* ANDROID */
  2169. old_ap_scan = wpa_s->conf->ap_scan;
  2170. wpa_s->conf->ap_scan = ap_scan;
  2171. if (old_ap_scan != wpa_s->conf->ap_scan)
  2172. wpas_notify_ap_scan_changed(wpa_s);
  2173. return 0;
  2174. }
  2175. /**
  2176. * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age
  2177. * @wpa_s: wpa_supplicant structure for a network interface
  2178. * @expire_age: Expiration age in seconds
  2179. * Returns: 0 if succeed or -1 if expire_age has an invalid value
  2180. *
  2181. */
  2182. int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant *wpa_s,
  2183. unsigned int bss_expire_age)
  2184. {
  2185. if (bss_expire_age < 10) {
  2186. wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration age %u",
  2187. bss_expire_age);
  2188. return -1;
  2189. }
  2190. wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration age: %d sec",
  2191. bss_expire_age);
  2192. wpa_s->conf->bss_expiration_age = bss_expire_age;
  2193. return 0;
  2194. }
  2195. /**
  2196. * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count
  2197. * @wpa_s: wpa_supplicant structure for a network interface
  2198. * @expire_count: number of scans after which an unseen BSS is reclaimed
  2199. * Returns: 0 if succeed or -1 if expire_count has an invalid value
  2200. *
  2201. */
  2202. int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant *wpa_s,
  2203. unsigned int bss_expire_count)
  2204. {
  2205. if (bss_expire_count < 1) {
  2206. wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration count %u",
  2207. bss_expire_count);
  2208. return -1;
  2209. }
  2210. wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration scan count: %u",
  2211. bss_expire_count);
  2212. wpa_s->conf->bss_expiration_scan_count = bss_expire_count;
  2213. return 0;
  2214. }
  2215. /**
  2216. * wpa_supplicant_set_scan_interval - Set scan interval
  2217. * @wpa_s: wpa_supplicant structure for a network interface
  2218. * @scan_interval: scan interval in seconds
  2219. * Returns: 0 if succeed or -1 if scan_interval has an invalid value
  2220. *
  2221. */
  2222. int wpa_supplicant_set_scan_interval(struct wpa_supplicant *wpa_s,
  2223. int scan_interval)
  2224. {
  2225. if (scan_interval < 0) {
  2226. wpa_msg(wpa_s, MSG_ERROR, "Invalid scan interval %d",
  2227. scan_interval);
  2228. return -1;
  2229. }
  2230. wpa_msg(wpa_s, MSG_DEBUG, "Setting scan interval: %d sec",
  2231. scan_interval);
  2232. wpa_supplicant_update_scan_int(wpa_s, scan_interval);
  2233. return 0;
  2234. }
  2235. /**
  2236. * wpa_supplicant_set_debug_params - Set global debug params
  2237. * @global: wpa_global structure
  2238. * @debug_level: debug level
  2239. * @debug_timestamp: determines if show timestamp in debug data
  2240. * @debug_show_keys: determines if show keys in debug data
  2241. * Returns: 0 if succeed or -1 if debug_level has wrong value
  2242. */
  2243. int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level,
  2244. int debug_timestamp, int debug_show_keys)
  2245. {
  2246. int old_level, old_timestamp, old_show_keys;
  2247. /* check for allowed debuglevels */
  2248. if (debug_level != MSG_EXCESSIVE &&
  2249. debug_level != MSG_MSGDUMP &&
  2250. debug_level != MSG_DEBUG &&
  2251. debug_level != MSG_INFO &&
  2252. debug_level != MSG_WARNING &&
  2253. debug_level != MSG_ERROR)
  2254. return -1;
  2255. old_level = wpa_debug_level;
  2256. old_timestamp = wpa_debug_timestamp;
  2257. old_show_keys = wpa_debug_show_keys;
  2258. wpa_debug_level = debug_level;
  2259. wpa_debug_timestamp = debug_timestamp ? 1 : 0;
  2260. wpa_debug_show_keys = debug_show_keys ? 1 : 0;
  2261. if (wpa_debug_level != old_level)
  2262. wpas_notify_debug_level_changed(global);
  2263. if (wpa_debug_timestamp != old_timestamp)
  2264. wpas_notify_debug_timestamp_changed(global);
  2265. if (wpa_debug_show_keys != old_show_keys)
  2266. wpas_notify_debug_show_keys_changed(global);
  2267. return 0;
  2268. }
  2269. /**
  2270. * wpa_supplicant_get_ssid - Get a pointer to the current network structure
  2271. * @wpa_s: Pointer to wpa_supplicant data
  2272. * Returns: A pointer to the current network structure or %NULL on failure
  2273. */
  2274. struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s)
  2275. {
  2276. struct wpa_ssid *entry;
  2277. u8 ssid[MAX_SSID_LEN];
  2278. int res;
  2279. size_t ssid_len;
  2280. u8 bssid[ETH_ALEN];
  2281. int wired;
  2282. res = wpa_drv_get_ssid(wpa_s, ssid);
  2283. if (res < 0) {
  2284. wpa_msg(wpa_s, MSG_WARNING, "Could not read SSID from "
  2285. "driver");
  2286. return NULL;
  2287. }
  2288. ssid_len = res;
  2289. if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
  2290. wpa_msg(wpa_s, MSG_WARNING, "Could not read BSSID from "
  2291. "driver");
  2292. return NULL;
  2293. }
  2294. wired = wpa_s->conf->ap_scan == 0 &&
  2295. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED);
  2296. entry = wpa_s->conf->ssid;
  2297. while (entry) {
  2298. if (!wpas_network_disabled(wpa_s, entry) &&
  2299. ((ssid_len == entry->ssid_len &&
  2300. os_memcmp(ssid, entry->ssid, ssid_len) == 0) || wired) &&
  2301. (!entry->bssid_set ||
  2302. os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0))
  2303. return entry;
  2304. #ifdef CONFIG_WPS
  2305. if (!wpas_network_disabled(wpa_s, entry) &&
  2306. (entry->key_mgmt & WPA_KEY_MGMT_WPS) &&
  2307. (entry->ssid == NULL || entry->ssid_len == 0) &&
  2308. (!entry->bssid_set ||
  2309. os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0))
  2310. return entry;
  2311. #endif /* CONFIG_WPS */
  2312. if (!wpas_network_disabled(wpa_s, entry) && entry->bssid_set &&
  2313. entry->ssid_len == 0 &&
  2314. os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0)
  2315. return entry;
  2316. entry = entry->next;
  2317. }
  2318. return NULL;
  2319. }
  2320. static int select_driver(struct wpa_supplicant *wpa_s, int i)
  2321. {
  2322. struct wpa_global *global = wpa_s->global;
  2323. if (wpa_drivers[i]->global_init && global->drv_priv[i] == NULL) {
  2324. global->drv_priv[i] = wpa_drivers[i]->global_init();
  2325. if (global->drv_priv[i] == NULL) {
  2326. wpa_printf(MSG_ERROR, "Failed to initialize driver "
  2327. "'%s'", wpa_drivers[i]->name);
  2328. return -1;
  2329. }
  2330. }
  2331. wpa_s->driver = wpa_drivers[i];
  2332. wpa_s->global_drv_priv = global->drv_priv[i];
  2333. return 0;
  2334. }
  2335. static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s,
  2336. const char *name)
  2337. {
  2338. int i;
  2339. size_t len;
  2340. const char *pos, *driver = name;
  2341. if (wpa_s == NULL)
  2342. return -1;
  2343. if (wpa_drivers[0] == NULL) {
  2344. wpa_msg(wpa_s, MSG_ERROR, "No driver interfaces build into "
  2345. "wpa_supplicant");
  2346. return -1;
  2347. }
  2348. if (name == NULL) {
  2349. /* default to first driver in the list */
  2350. return select_driver(wpa_s, 0);
  2351. }
  2352. do {
  2353. pos = os_strchr(driver, ',');
  2354. if (pos)
  2355. len = pos - driver;
  2356. else
  2357. len = os_strlen(driver);
  2358. for (i = 0; wpa_drivers[i]; i++) {
  2359. if (os_strlen(wpa_drivers[i]->name) == len &&
  2360. os_strncmp(driver, wpa_drivers[i]->name, len) ==
  2361. 0) {
  2362. /* First driver that succeeds wins */
  2363. if (select_driver(wpa_s, i) == 0)
  2364. return 0;
  2365. }
  2366. }
  2367. driver = pos + 1;
  2368. } while (pos);
  2369. wpa_msg(wpa_s, MSG_ERROR, "Unsupported driver '%s'", name);
  2370. return -1;
  2371. }
  2372. /**
  2373. * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant
  2374. * @ctx: Context pointer (wpa_s); this is the ctx variable registered
  2375. * with struct wpa_driver_ops::init()
  2376. * @src_addr: Source address of the EAPOL frame
  2377. * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header)
  2378. * @len: Length of the EAPOL data
  2379. *
  2380. * This function is called for each received EAPOL frame. Most driver
  2381. * interfaces rely on more generic OS mechanism for receiving frames through
  2382. * l2_packet, but if such a mechanism is not available, the driver wrapper may
  2383. * take care of received EAPOL frames and deliver them to the core supplicant
  2384. * code by calling this function.
  2385. */
  2386. void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
  2387. const u8 *buf, size_t len)
  2388. {
  2389. struct wpa_supplicant *wpa_s = ctx;
  2390. wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR, MAC2STR(src_addr));
  2391. wpa_hexdump(MSG_MSGDUMP, "RX EAPOL", buf, len);
  2392. #ifdef CONFIG_PEERKEY
  2393. if (wpa_s->wpa_state > WPA_ASSOCIATED && wpa_s->current_ssid &&
  2394. wpa_s->current_ssid->peerkey &&
  2395. !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  2396. wpa_sm_rx_eapol_peerkey(wpa_s->wpa, src_addr, buf, len) == 1) {
  2397. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: Processed PeerKey EAPOL-Key");
  2398. return;
  2399. }
  2400. #endif /* CONFIG_PEERKEY */
  2401. if (wpa_s->wpa_state < WPA_ASSOCIATED ||
  2402. (wpa_s->last_eapol_matches_bssid &&
  2403. #ifdef CONFIG_AP
  2404. !wpa_s->ap_iface &&
  2405. #endif /* CONFIG_AP */
  2406. os_memcmp(src_addr, wpa_s->bssid, ETH_ALEN) != 0)) {
  2407. /*
  2408. * There is possible race condition between receiving the
  2409. * association event and the EAPOL frame since they are coming
  2410. * through different paths from the driver. In order to avoid
  2411. * issues in trying to process the EAPOL frame before receiving
  2412. * association information, lets queue it for processing until
  2413. * the association event is received. This may also be needed in
  2414. * driver-based roaming case, so also use src_addr != BSSID as a
  2415. * trigger if we have previously confirmed that the
  2416. * Authenticator uses BSSID as the src_addr (which is not the
  2417. * case with wired IEEE 802.1X).
  2418. */
  2419. wpa_dbg(wpa_s, MSG_DEBUG, "Not associated - Delay processing "
  2420. "of received EAPOL frame (state=%s bssid=" MACSTR ")",
  2421. wpa_supplicant_state_txt(wpa_s->wpa_state),
  2422. MAC2STR(wpa_s->bssid));
  2423. wpabuf_free(wpa_s->pending_eapol_rx);
  2424. wpa_s->pending_eapol_rx = wpabuf_alloc_copy(buf, len);
  2425. if (wpa_s->pending_eapol_rx) {
  2426. os_get_reltime(&wpa_s->pending_eapol_rx_time);
  2427. os_memcpy(wpa_s->pending_eapol_rx_src, src_addr,
  2428. ETH_ALEN);
  2429. }
  2430. return;
  2431. }
  2432. wpa_s->last_eapol_matches_bssid =
  2433. os_memcmp(src_addr, wpa_s->bssid, ETH_ALEN) == 0;
  2434. #ifdef CONFIG_AP
  2435. if (wpa_s->ap_iface) {
  2436. wpa_supplicant_ap_rx_eapol(wpa_s, src_addr, buf, len);
  2437. return;
  2438. }
  2439. #endif /* CONFIG_AP */
  2440. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
  2441. wpa_dbg(wpa_s, MSG_DEBUG, "Ignored received EAPOL frame since "
  2442. "no key management is configured");
  2443. return;
  2444. }
  2445. if (wpa_s->eapol_received == 0 &&
  2446. (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) ||
  2447. !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
  2448. wpa_s->wpa_state != WPA_COMPLETED) &&
  2449. (wpa_s->current_ssid == NULL ||
  2450. wpa_s->current_ssid->mode != IEEE80211_MODE_IBSS)) {
  2451. /* Timeout for completing IEEE 802.1X and WPA authentication */
  2452. wpa_supplicant_req_auth_timeout(
  2453. wpa_s,
  2454. (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  2455. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA ||
  2456. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) ?
  2457. 70 : 10, 0);
  2458. }
  2459. wpa_s->eapol_received++;
  2460. if (wpa_s->countermeasures) {
  2461. wpa_msg(wpa_s, MSG_INFO, "WPA: Countermeasures - dropped "
  2462. "EAPOL packet");
  2463. return;
  2464. }
  2465. #ifdef CONFIG_IBSS_RSN
  2466. if (wpa_s->current_ssid &&
  2467. wpa_s->current_ssid->mode == WPAS_MODE_IBSS) {
  2468. ibss_rsn_rx_eapol(wpa_s->ibss_rsn, src_addr, buf, len);
  2469. return;
  2470. }
  2471. #endif /* CONFIG_IBSS_RSN */
  2472. /* Source address of the incoming EAPOL frame could be compared to the
  2473. * current BSSID. However, it is possible that a centralized
  2474. * Authenticator could be using another MAC address than the BSSID of
  2475. * an AP, so just allow any address to be used for now. The replies are
  2476. * still sent to the current BSSID (if available), though. */
  2477. os_memcpy(wpa_s->last_eapol_src, src_addr, ETH_ALEN);
  2478. if (!wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) &&
  2479. eapol_sm_rx_eapol(wpa_s->eapol, src_addr, buf, len) > 0)
  2480. return;
  2481. wpa_drv_poll(wpa_s);
  2482. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE))
  2483. wpa_sm_rx_eapol(wpa_s->wpa, src_addr, buf, len);
  2484. else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  2485. /*
  2486. * Set portValid = TRUE here since we are going to skip 4-way
  2487. * handshake processing which would normally set portValid. We
  2488. * need this to allow the EAPOL state machines to be completed
  2489. * without going through EAPOL-Key handshake.
  2490. */
  2491. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  2492. }
  2493. }
  2494. int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s)
  2495. {
  2496. if ((!wpa_s->p2p_mgmt ||
  2497. !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) &&
  2498. !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)) {
  2499. l2_packet_deinit(wpa_s->l2);
  2500. wpa_s->l2 = l2_packet_init(wpa_s->ifname,
  2501. wpa_drv_get_mac_addr(wpa_s),
  2502. ETH_P_EAPOL,
  2503. wpa_supplicant_rx_eapol, wpa_s, 0);
  2504. if (wpa_s->l2 == NULL)
  2505. return -1;
  2506. } else {
  2507. const u8 *addr = wpa_drv_get_mac_addr(wpa_s);
  2508. if (addr)
  2509. os_memcpy(wpa_s->own_addr, addr, ETH_ALEN);
  2510. }
  2511. if (wpa_s->l2 && l2_packet_get_own_addr(wpa_s->l2, wpa_s->own_addr)) {
  2512. wpa_msg(wpa_s, MSG_ERROR, "Failed to get own L2 address");
  2513. return -1;
  2514. }
  2515. wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr);
  2516. return 0;
  2517. }
  2518. static void wpa_supplicant_rx_eapol_bridge(void *ctx, const u8 *src_addr,
  2519. const u8 *buf, size_t len)
  2520. {
  2521. struct wpa_supplicant *wpa_s = ctx;
  2522. const struct l2_ethhdr *eth;
  2523. if (len < sizeof(*eth))
  2524. return;
  2525. eth = (const struct l2_ethhdr *) buf;
  2526. if (os_memcmp(eth->h_dest, wpa_s->own_addr, ETH_ALEN) != 0 &&
  2527. !(eth->h_dest[0] & 0x01)) {
  2528. wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR
  2529. " (bridge - not for this interface - ignore)",
  2530. MAC2STR(src_addr), MAC2STR(eth->h_dest));
  2531. return;
  2532. }
  2533. wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR
  2534. " (bridge)", MAC2STR(src_addr), MAC2STR(eth->h_dest));
  2535. wpa_supplicant_rx_eapol(wpa_s, src_addr, buf + sizeof(*eth),
  2536. len - sizeof(*eth));
  2537. }
  2538. /**
  2539. * wpa_supplicant_driver_init - Initialize driver interface parameters
  2540. * @wpa_s: Pointer to wpa_supplicant data
  2541. * Returns: 0 on success, -1 on failure
  2542. *
  2543. * This function is called to initialize driver interface parameters.
  2544. * wpa_drv_init() must have been called before this function to initialize the
  2545. * driver interface.
  2546. */
  2547. int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s)
  2548. {
  2549. static int interface_count = 0;
  2550. if (wpa_supplicant_update_mac_addr(wpa_s) < 0)
  2551. return -1;
  2552. wpa_dbg(wpa_s, MSG_DEBUG, "Own MAC address: " MACSTR,
  2553. MAC2STR(wpa_s->own_addr));
  2554. os_memcpy(wpa_s->perm_addr, wpa_s->own_addr, ETH_ALEN);
  2555. wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr);
  2556. if (wpa_s->bridge_ifname[0]) {
  2557. wpa_dbg(wpa_s, MSG_DEBUG, "Receiving packets from bridge "
  2558. "interface '%s'", wpa_s->bridge_ifname);
  2559. wpa_s->l2_br = l2_packet_init(wpa_s->bridge_ifname,
  2560. wpa_s->own_addr,
  2561. ETH_P_EAPOL,
  2562. wpa_supplicant_rx_eapol_bridge,
  2563. wpa_s, 1);
  2564. if (wpa_s->l2_br == NULL) {
  2565. wpa_msg(wpa_s, MSG_ERROR, "Failed to open l2_packet "
  2566. "connection for the bridge interface '%s'",
  2567. wpa_s->bridge_ifname);
  2568. return -1;
  2569. }
  2570. }
  2571. wpa_clear_keys(wpa_s, NULL);
  2572. /* Make sure that TKIP countermeasures are not left enabled (could
  2573. * happen if wpa_supplicant is killed during countermeasures. */
  2574. wpa_drv_set_countermeasures(wpa_s, 0);
  2575. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: flushing PMKID list in the driver");
  2576. wpa_drv_flush_pmkid(wpa_s);
  2577. wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN;
  2578. wpa_s->prev_scan_wildcard = 0;
  2579. if (wpa_supplicant_enabled_networks(wpa_s)) {
  2580. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  2581. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  2582. interface_count = 0;
  2583. }
  2584. #ifndef ANDROID
  2585. if (!wpa_s->p2p_mgmt &&
  2586. wpa_supplicant_delayed_sched_scan(wpa_s,
  2587. interface_count % 3,
  2588. 100000))
  2589. wpa_supplicant_req_scan(wpa_s, interface_count % 3,
  2590. 100000);
  2591. #endif /* ANDROID */
  2592. interface_count++;
  2593. } else
  2594. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  2595. return 0;
  2596. }
  2597. static int wpa_supplicant_daemon(const char *pid_file)
  2598. {
  2599. wpa_printf(MSG_DEBUG, "Daemonize..");
  2600. return os_daemonize(pid_file);
  2601. }
  2602. static struct wpa_supplicant * wpa_supplicant_alloc(void)
  2603. {
  2604. struct wpa_supplicant *wpa_s;
  2605. wpa_s = os_zalloc(sizeof(*wpa_s));
  2606. if (wpa_s == NULL)
  2607. return NULL;
  2608. wpa_s->scan_req = INITIAL_SCAN_REQ;
  2609. wpa_s->scan_interval = 5;
  2610. wpa_s->new_connection = 1;
  2611. wpa_s->parent = wpa_s;
  2612. wpa_s->sched_scanning = 0;
  2613. return wpa_s;
  2614. }
  2615. #ifdef CONFIG_HT_OVERRIDES
  2616. static int wpa_set_htcap_mcs(struct wpa_supplicant *wpa_s,
  2617. struct ieee80211_ht_capabilities *htcaps,
  2618. struct ieee80211_ht_capabilities *htcaps_mask,
  2619. const char *ht_mcs)
  2620. {
  2621. /* parse ht_mcs into hex array */
  2622. int i;
  2623. const char *tmp = ht_mcs;
  2624. char *end = NULL;
  2625. /* If ht_mcs is null, do not set anything */
  2626. if (!ht_mcs)
  2627. return 0;
  2628. /* This is what we are setting in the kernel */
  2629. os_memset(&htcaps->supported_mcs_set, 0, IEEE80211_HT_MCS_MASK_LEN);
  2630. wpa_msg(wpa_s, MSG_DEBUG, "set_htcap, ht_mcs -:%s:-", ht_mcs);
  2631. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
  2632. errno = 0;
  2633. long v = strtol(tmp, &end, 16);
  2634. if (errno == 0) {
  2635. wpa_msg(wpa_s, MSG_DEBUG,
  2636. "htcap value[%i]: %ld end: %p tmp: %p",
  2637. i, v, end, tmp);
  2638. if (end == tmp)
  2639. break;
  2640. htcaps->supported_mcs_set[i] = v;
  2641. tmp = end;
  2642. } else {
  2643. wpa_msg(wpa_s, MSG_ERROR,
  2644. "Failed to parse ht-mcs: %s, error: %s\n",
  2645. ht_mcs, strerror(errno));
  2646. return -1;
  2647. }
  2648. }
  2649. /*
  2650. * If we were able to parse any values, then set mask for the MCS set.
  2651. */
  2652. if (i) {
  2653. os_memset(&htcaps_mask->supported_mcs_set, 0xff,
  2654. IEEE80211_HT_MCS_MASK_LEN - 1);
  2655. /* skip the 3 reserved bits */
  2656. htcaps_mask->supported_mcs_set[IEEE80211_HT_MCS_MASK_LEN - 1] =
  2657. 0x1f;
  2658. }
  2659. return 0;
  2660. }
  2661. static int wpa_disable_max_amsdu(struct wpa_supplicant *wpa_s,
  2662. struct ieee80211_ht_capabilities *htcaps,
  2663. struct ieee80211_ht_capabilities *htcaps_mask,
  2664. int disabled)
  2665. {
  2666. le16 msk;
  2667. wpa_msg(wpa_s, MSG_DEBUG, "set_disable_max_amsdu: %d", disabled);
  2668. if (disabled == -1)
  2669. return 0;
  2670. msk = host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE);
  2671. htcaps_mask->ht_capabilities_info |= msk;
  2672. if (disabled)
  2673. htcaps->ht_capabilities_info &= msk;
  2674. else
  2675. htcaps->ht_capabilities_info |= msk;
  2676. return 0;
  2677. }
  2678. static int wpa_set_ampdu_factor(struct wpa_supplicant *wpa_s,
  2679. struct ieee80211_ht_capabilities *htcaps,
  2680. struct ieee80211_ht_capabilities *htcaps_mask,
  2681. int factor)
  2682. {
  2683. wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_factor: %d", factor);
  2684. if (factor == -1)
  2685. return 0;
  2686. if (factor < 0 || factor > 3) {
  2687. wpa_msg(wpa_s, MSG_ERROR, "ampdu_factor: %d out of range. "
  2688. "Must be 0-3 or -1", factor);
  2689. return -EINVAL;
  2690. }
  2691. htcaps_mask->a_mpdu_params |= 0x3; /* 2 bits for factor */
  2692. htcaps->a_mpdu_params &= ~0x3;
  2693. htcaps->a_mpdu_params |= factor & 0x3;
  2694. return 0;
  2695. }
  2696. static int wpa_set_ampdu_density(struct wpa_supplicant *wpa_s,
  2697. struct ieee80211_ht_capabilities *htcaps,
  2698. struct ieee80211_ht_capabilities *htcaps_mask,
  2699. int density)
  2700. {
  2701. wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_density: %d", density);
  2702. if (density == -1)
  2703. return 0;
  2704. if (density < 0 || density > 7) {
  2705. wpa_msg(wpa_s, MSG_ERROR,
  2706. "ampdu_density: %d out of range. Must be 0-7 or -1.",
  2707. density);
  2708. return -EINVAL;
  2709. }
  2710. htcaps_mask->a_mpdu_params |= 0x1C;
  2711. htcaps->a_mpdu_params &= ~(0x1C);
  2712. htcaps->a_mpdu_params |= (density << 2) & 0x1C;
  2713. return 0;
  2714. }
  2715. static int wpa_set_disable_ht40(struct wpa_supplicant *wpa_s,
  2716. struct ieee80211_ht_capabilities *htcaps,
  2717. struct ieee80211_ht_capabilities *htcaps_mask,
  2718. int disabled)
  2719. {
  2720. /* Masking these out disables HT40 */
  2721. le16 msk = host_to_le16(HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET |
  2722. HT_CAP_INFO_SHORT_GI40MHZ);
  2723. wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ht40: %d", disabled);
  2724. if (disabled)
  2725. htcaps->ht_capabilities_info &= ~msk;
  2726. else
  2727. htcaps->ht_capabilities_info |= msk;
  2728. htcaps_mask->ht_capabilities_info |= msk;
  2729. return 0;
  2730. }
  2731. static int wpa_set_disable_sgi(struct wpa_supplicant *wpa_s,
  2732. struct ieee80211_ht_capabilities *htcaps,
  2733. struct ieee80211_ht_capabilities *htcaps_mask,
  2734. int disabled)
  2735. {
  2736. /* Masking these out disables SGI */
  2737. le16 msk = host_to_le16(HT_CAP_INFO_SHORT_GI20MHZ |
  2738. HT_CAP_INFO_SHORT_GI40MHZ);
  2739. wpa_msg(wpa_s, MSG_DEBUG, "set_disable_sgi: %d", disabled);
  2740. if (disabled)
  2741. htcaps->ht_capabilities_info &= ~msk;
  2742. else
  2743. htcaps->ht_capabilities_info |= msk;
  2744. htcaps_mask->ht_capabilities_info |= msk;
  2745. return 0;
  2746. }
  2747. static int wpa_set_disable_ldpc(struct wpa_supplicant *wpa_s,
  2748. struct ieee80211_ht_capabilities *htcaps,
  2749. struct ieee80211_ht_capabilities *htcaps_mask,
  2750. int disabled)
  2751. {
  2752. /* Masking these out disables LDPC */
  2753. le16 msk = host_to_le16(HT_CAP_INFO_LDPC_CODING_CAP);
  2754. wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ldpc: %d", disabled);
  2755. if (disabled)
  2756. htcaps->ht_capabilities_info &= ~msk;
  2757. else
  2758. htcaps->ht_capabilities_info |= msk;
  2759. htcaps_mask->ht_capabilities_info |= msk;
  2760. return 0;
  2761. }
  2762. void wpa_supplicant_apply_ht_overrides(
  2763. struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
  2764. struct wpa_driver_associate_params *params)
  2765. {
  2766. struct ieee80211_ht_capabilities *htcaps;
  2767. struct ieee80211_ht_capabilities *htcaps_mask;
  2768. if (!ssid)
  2769. return;
  2770. params->disable_ht = ssid->disable_ht;
  2771. if (!params->htcaps || !params->htcaps_mask)
  2772. return;
  2773. htcaps = (struct ieee80211_ht_capabilities *) params->htcaps;
  2774. htcaps_mask = (struct ieee80211_ht_capabilities *) params->htcaps_mask;
  2775. wpa_set_htcap_mcs(wpa_s, htcaps, htcaps_mask, ssid->ht_mcs);
  2776. wpa_disable_max_amsdu(wpa_s, htcaps, htcaps_mask,
  2777. ssid->disable_max_amsdu);
  2778. wpa_set_ampdu_factor(wpa_s, htcaps, htcaps_mask, ssid->ampdu_factor);
  2779. wpa_set_ampdu_density(wpa_s, htcaps, htcaps_mask, ssid->ampdu_density);
  2780. wpa_set_disable_ht40(wpa_s, htcaps, htcaps_mask, ssid->disable_ht40);
  2781. wpa_set_disable_sgi(wpa_s, htcaps, htcaps_mask, ssid->disable_sgi);
  2782. wpa_set_disable_ldpc(wpa_s, htcaps, htcaps_mask, ssid->disable_ldpc);
  2783. if (ssid->ht40_intolerant) {
  2784. le16 bit = host_to_le16(HT_CAP_INFO_40MHZ_INTOLERANT);
  2785. htcaps->ht_capabilities_info |= bit;
  2786. htcaps_mask->ht_capabilities_info |= bit;
  2787. }
  2788. }
  2789. #endif /* CONFIG_HT_OVERRIDES */
  2790. #ifdef CONFIG_VHT_OVERRIDES
  2791. void wpa_supplicant_apply_vht_overrides(
  2792. struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
  2793. struct wpa_driver_associate_params *params)
  2794. {
  2795. struct ieee80211_vht_capabilities *vhtcaps;
  2796. struct ieee80211_vht_capabilities *vhtcaps_mask;
  2797. if (!ssid)
  2798. return;
  2799. params->disable_vht = ssid->disable_vht;
  2800. vhtcaps = (void *) params->vhtcaps;
  2801. vhtcaps_mask = (void *) params->vhtcaps_mask;
  2802. if (!vhtcaps || !vhtcaps_mask)
  2803. return;
  2804. vhtcaps->vht_capabilities_info = ssid->vht_capa;
  2805. vhtcaps_mask->vht_capabilities_info = ssid->vht_capa_mask;
  2806. #ifdef CONFIG_HT_OVERRIDES
  2807. /* if max ampdu is <= 3, we have to make the HT cap the same */
  2808. if (ssid->vht_capa_mask & VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX) {
  2809. int max_ampdu;
  2810. max_ampdu = (ssid->vht_capa &
  2811. VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX) >>
  2812. VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX_SHIFT;
  2813. max_ampdu = max_ampdu < 3 ? max_ampdu : 3;
  2814. wpa_set_ampdu_factor(wpa_s,
  2815. (void *) params->htcaps,
  2816. (void *) params->htcaps_mask,
  2817. max_ampdu);
  2818. }
  2819. #endif /* CONFIG_HT_OVERRIDES */
  2820. #define OVERRIDE_MCS(i) \
  2821. if (ssid->vht_tx_mcs_nss_ ##i >= 0) { \
  2822. vhtcaps_mask->vht_supported_mcs_set.tx_map |= \
  2823. 3 << 2 * (i - 1); \
  2824. vhtcaps->vht_supported_mcs_set.tx_map |= \
  2825. ssid->vht_tx_mcs_nss_ ##i << 2 * (i - 1); \
  2826. } \
  2827. if (ssid->vht_rx_mcs_nss_ ##i >= 0) { \
  2828. vhtcaps_mask->vht_supported_mcs_set.rx_map |= \
  2829. 3 << 2 * (i - 1); \
  2830. vhtcaps->vht_supported_mcs_set.rx_map |= \
  2831. ssid->vht_rx_mcs_nss_ ##i << 2 * (i - 1); \
  2832. }
  2833. OVERRIDE_MCS(1);
  2834. OVERRIDE_MCS(2);
  2835. OVERRIDE_MCS(3);
  2836. OVERRIDE_MCS(4);
  2837. OVERRIDE_MCS(5);
  2838. OVERRIDE_MCS(6);
  2839. OVERRIDE_MCS(7);
  2840. OVERRIDE_MCS(8);
  2841. }
  2842. #endif /* CONFIG_VHT_OVERRIDES */
  2843. static int pcsc_reader_init(struct wpa_supplicant *wpa_s)
  2844. {
  2845. #ifdef PCSC_FUNCS
  2846. size_t len;
  2847. if (!wpa_s->conf->pcsc_reader)
  2848. return 0;
  2849. wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
  2850. if (!wpa_s->scard)
  2851. return 1;
  2852. if (wpa_s->conf->pcsc_pin &&
  2853. scard_set_pin(wpa_s->scard, wpa_s->conf->pcsc_pin) < 0) {
  2854. scard_deinit(wpa_s->scard);
  2855. wpa_s->scard = NULL;
  2856. wpa_msg(wpa_s, MSG_ERROR, "PC/SC PIN validation failed");
  2857. return -1;
  2858. }
  2859. len = sizeof(wpa_s->imsi) - 1;
  2860. if (scard_get_imsi(wpa_s->scard, wpa_s->imsi, &len)) {
  2861. scard_deinit(wpa_s->scard);
  2862. wpa_s->scard = NULL;
  2863. wpa_msg(wpa_s, MSG_ERROR, "Could not read IMSI");
  2864. return -1;
  2865. }
  2866. wpa_s->imsi[len] = '\0';
  2867. wpa_s->mnc_len = scard_get_mnc_len(wpa_s->scard);
  2868. wpa_printf(MSG_DEBUG, "SCARD: IMSI %s (MNC length %d)",
  2869. wpa_s->imsi, wpa_s->mnc_len);
  2870. wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
  2871. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  2872. #endif /* PCSC_FUNCS */
  2873. return 0;
  2874. }
  2875. int wpas_init_ext_pw(struct wpa_supplicant *wpa_s)
  2876. {
  2877. char *val, *pos;
  2878. ext_password_deinit(wpa_s->ext_pw);
  2879. wpa_s->ext_pw = NULL;
  2880. eapol_sm_set_ext_pw_ctx(wpa_s->eapol, NULL);
  2881. if (!wpa_s->conf->ext_password_backend)
  2882. return 0;
  2883. val = os_strdup(wpa_s->conf->ext_password_backend);
  2884. if (val == NULL)
  2885. return -1;
  2886. pos = os_strchr(val, ':');
  2887. if (pos)
  2888. *pos++ = '\0';
  2889. wpa_printf(MSG_DEBUG, "EXT PW: Initialize backend '%s'", val);
  2890. wpa_s->ext_pw = ext_password_init(val, pos);
  2891. os_free(val);
  2892. if (wpa_s->ext_pw == NULL) {
  2893. wpa_printf(MSG_DEBUG, "EXT PW: Failed to initialize backend");
  2894. return -1;
  2895. }
  2896. eapol_sm_set_ext_pw_ctx(wpa_s->eapol, wpa_s->ext_pw);
  2897. return 0;
  2898. }
  2899. static int wpas_set_wowlan_triggers(struct wpa_supplicant *wpa_s,
  2900. const struct wpa_driver_capa *capa)
  2901. {
  2902. struct wowlan_triggers *triggers;
  2903. int ret = 0;
  2904. if (!wpa_s->conf->wowlan_triggers)
  2905. return 0;
  2906. triggers = wpa_get_wowlan_triggers(wpa_s->conf->wowlan_triggers, capa);
  2907. if (triggers) {
  2908. ret = wpa_drv_wowlan(wpa_s, triggers);
  2909. os_free(triggers);
  2910. }
  2911. return ret;
  2912. }
  2913. static struct wpa_radio * radio_add_interface(struct wpa_supplicant *wpa_s,
  2914. const char *rn)
  2915. {
  2916. struct wpa_supplicant *iface = wpa_s->global->ifaces;
  2917. struct wpa_radio *radio;
  2918. while (rn && iface) {
  2919. radio = iface->radio;
  2920. if (radio && os_strcmp(rn, radio->name) == 0) {
  2921. wpa_printf(MSG_DEBUG, "Add interface %s to existing radio %s",
  2922. wpa_s->ifname, rn);
  2923. dl_list_add(&radio->ifaces, &wpa_s->radio_list);
  2924. return radio;
  2925. }
  2926. iface = iface->next;
  2927. }
  2928. wpa_printf(MSG_DEBUG, "Add interface %s to a new radio %s",
  2929. wpa_s->ifname, rn ? rn : "N/A");
  2930. radio = os_zalloc(sizeof(*radio));
  2931. if (radio == NULL)
  2932. return NULL;
  2933. if (rn)
  2934. os_strlcpy(radio->name, rn, sizeof(radio->name));
  2935. dl_list_init(&radio->ifaces);
  2936. dl_list_init(&radio->work);
  2937. dl_list_add(&radio->ifaces, &wpa_s->radio_list);
  2938. return radio;
  2939. }
  2940. static void radio_work_free(struct wpa_radio_work *work)
  2941. {
  2942. if (work->wpa_s->scan_work == work) {
  2943. /* This should not really happen. */
  2944. wpa_dbg(work->wpa_s, MSG_INFO, "Freeing radio work '%s'@%p (started=%d) that is marked as scan_work",
  2945. work->type, work, work->started);
  2946. work->wpa_s->scan_work = NULL;
  2947. }
  2948. #ifdef CONFIG_P2P
  2949. if (work->wpa_s->p2p_scan_work == work) {
  2950. /* This should not really happen. */
  2951. wpa_dbg(work->wpa_s, MSG_INFO, "Freeing radio work '%s'@%p (started=%d) that is marked as p2p_scan_work",
  2952. work->type, work, work->started);
  2953. work->wpa_s->p2p_scan_work = NULL;
  2954. }
  2955. #endif /* CONFIG_P2P */
  2956. dl_list_del(&work->list);
  2957. os_free(work);
  2958. }
  2959. static void radio_start_next_work(void *eloop_ctx, void *timeout_ctx)
  2960. {
  2961. struct wpa_radio *radio = eloop_ctx;
  2962. struct wpa_radio_work *work;
  2963. struct os_reltime now, diff;
  2964. struct wpa_supplicant *wpa_s;
  2965. work = dl_list_first(&radio->work, struct wpa_radio_work, list);
  2966. if (work == NULL)
  2967. return;
  2968. if (work->started)
  2969. return; /* already started and still in progress */
  2970. wpa_s = dl_list_first(&radio->ifaces, struct wpa_supplicant,
  2971. radio_list);
  2972. if (wpa_s && wpa_s->external_scan_running) {
  2973. wpa_printf(MSG_DEBUG, "Delay radio work start until externally triggered scan completes");
  2974. return;
  2975. }
  2976. os_get_reltime(&now);
  2977. os_reltime_sub(&now, &work->time, &diff);
  2978. wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting radio work '%s'@%p after %ld.%06ld second wait",
  2979. work->type, work, diff.sec, diff.usec);
  2980. work->started = 1;
  2981. work->time = now;
  2982. work->cb(work, 0);
  2983. }
  2984. /*
  2985. * This function removes both started and pending radio works running on
  2986. * the provided interface's radio.
  2987. * Prior to the removal of the radio work, its callback (cb) is called with
  2988. * deinit set to be 1. Each work's callback is responsible for clearing its
  2989. * internal data and restoring to a correct state.
  2990. * @wpa_s: wpa_supplicant data
  2991. * @type: type of works to be removed
  2992. * @remove_all: 1 to remove all the works on this radio, 0 to remove only
  2993. * this interface's works.
  2994. */
  2995. void radio_remove_works(struct wpa_supplicant *wpa_s,
  2996. const char *type, int remove_all)
  2997. {
  2998. struct wpa_radio_work *work, *tmp;
  2999. struct wpa_radio *radio = wpa_s->radio;
  3000. dl_list_for_each_safe(work, tmp, &radio->work, struct wpa_radio_work,
  3001. list) {
  3002. if (type && os_strcmp(type, work->type) != 0)
  3003. continue;
  3004. /* skip other ifaces' works */
  3005. if (!remove_all && work->wpa_s != wpa_s)
  3006. continue;
  3007. wpa_dbg(wpa_s, MSG_DEBUG, "Remove radio work '%s'@%p%s",
  3008. work->type, work, work->started ? " (started)" : "");
  3009. work->cb(work, 1);
  3010. radio_work_free(work);
  3011. }
  3012. /* in case we removed the started work */
  3013. radio_work_check_next(wpa_s);
  3014. }
  3015. static void radio_remove_interface(struct wpa_supplicant *wpa_s)
  3016. {
  3017. struct wpa_radio *radio = wpa_s->radio;
  3018. if (!radio)
  3019. return;
  3020. wpa_printf(MSG_DEBUG, "Remove interface %s from radio %s",
  3021. wpa_s->ifname, radio->name);
  3022. dl_list_del(&wpa_s->radio_list);
  3023. radio_remove_works(wpa_s, NULL, 0);
  3024. wpa_s->radio = NULL;
  3025. if (!dl_list_empty(&radio->ifaces))
  3026. return; /* Interfaces remain for this radio */
  3027. wpa_printf(MSG_DEBUG, "Remove radio %s", radio->name);
  3028. eloop_cancel_timeout(radio_start_next_work, radio, NULL);
  3029. os_free(radio);
  3030. }
  3031. void radio_work_check_next(struct wpa_supplicant *wpa_s)
  3032. {
  3033. struct wpa_radio *radio = wpa_s->radio;
  3034. if (dl_list_empty(&radio->work))
  3035. return;
  3036. if (wpa_s->ext_work_in_progress) {
  3037. wpa_printf(MSG_DEBUG,
  3038. "External radio work in progress - delay start of pending item");
  3039. return;
  3040. }
  3041. eloop_cancel_timeout(radio_start_next_work, radio, NULL);
  3042. eloop_register_timeout(0, 0, radio_start_next_work, radio, NULL);
  3043. }
  3044. /**
  3045. * radio_add_work - Add a radio work item
  3046. * @wpa_s: Pointer to wpa_supplicant data
  3047. * @freq: Frequency of the offchannel operation in MHz or 0
  3048. * @type: Unique identifier for each type of work
  3049. * @next: Force as the next work to be executed
  3050. * @cb: Callback function for indicating when radio is available
  3051. * @ctx: Context pointer for the work (work->ctx in cb())
  3052. * Returns: 0 on success, -1 on failure
  3053. *
  3054. * This function is used to request time for an operation that requires
  3055. * exclusive radio control. Once the radio is available, the registered callback
  3056. * function will be called. radio_work_done() must be called once the exclusive
  3057. * radio operation has been completed, so that the radio is freed for other
  3058. * operations. The special case of deinit=1 is used to free the context data
  3059. * during interface removal. That does not allow the callback function to start
  3060. * the radio operation, i.e., it must free any resources allocated for the radio
  3061. * work and return.
  3062. *
  3063. * The @freq parameter can be used to indicate a single channel on which the
  3064. * offchannel operation will occur. This may allow multiple radio work
  3065. * operations to be performed in parallel if they apply for the same channel.
  3066. * Setting this to 0 indicates that the work item may use multiple channels or
  3067. * requires exclusive control of the radio.
  3068. */
  3069. int radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq,
  3070. const char *type, int next,
  3071. void (*cb)(struct wpa_radio_work *work, int deinit),
  3072. void *ctx)
  3073. {
  3074. struct wpa_radio_work *work;
  3075. int was_empty;
  3076. work = os_zalloc(sizeof(*work));
  3077. if (work == NULL)
  3078. return -1;
  3079. wpa_dbg(wpa_s, MSG_DEBUG, "Add radio work '%s'@%p", type, work);
  3080. os_get_reltime(&work->time);
  3081. work->freq = freq;
  3082. work->type = type;
  3083. work->wpa_s = wpa_s;
  3084. work->cb = cb;
  3085. work->ctx = ctx;
  3086. was_empty = dl_list_empty(&wpa_s->radio->work);
  3087. if (next)
  3088. dl_list_add(&wpa_s->radio->work, &work->list);
  3089. else
  3090. dl_list_add_tail(&wpa_s->radio->work, &work->list);
  3091. if (was_empty) {
  3092. wpa_dbg(wpa_s, MSG_DEBUG, "First radio work item in the queue - schedule start immediately");
  3093. radio_work_check_next(wpa_s);
  3094. }
  3095. return 0;
  3096. }
  3097. /**
  3098. * radio_work_done - Indicate that a radio work item has been completed
  3099. * @work: Completed work
  3100. *
  3101. * This function is called once the callback function registered with
  3102. * radio_add_work() has completed its work.
  3103. */
  3104. void radio_work_done(struct wpa_radio_work *work)
  3105. {
  3106. struct wpa_supplicant *wpa_s = work->wpa_s;
  3107. struct os_reltime now, diff;
  3108. unsigned int started = work->started;
  3109. os_get_reltime(&now);
  3110. os_reltime_sub(&now, &work->time, &diff);
  3111. wpa_dbg(wpa_s, MSG_DEBUG, "Radio work '%s'@%p %s in %ld.%06ld seconds",
  3112. work->type, work, started ? "done" : "canceled",
  3113. diff.sec, diff.usec);
  3114. radio_work_free(work);
  3115. if (started)
  3116. radio_work_check_next(wpa_s);
  3117. }
  3118. struct wpa_radio_work *
  3119. radio_work_pending(struct wpa_supplicant *wpa_s, const char *type)
  3120. {
  3121. struct wpa_radio_work *work;
  3122. struct wpa_radio *radio = wpa_s->radio;
  3123. dl_list_for_each(work, &radio->work, struct wpa_radio_work, list) {
  3124. if (work->wpa_s == wpa_s && os_strcmp(work->type, type) == 0)
  3125. return work;
  3126. }
  3127. return NULL;
  3128. }
  3129. static int wpas_init_driver(struct wpa_supplicant *wpa_s,
  3130. struct wpa_interface *iface)
  3131. {
  3132. const char *ifname, *driver, *rn;
  3133. driver = iface->driver;
  3134. next_driver:
  3135. if (wpa_supplicant_set_driver(wpa_s, driver) < 0)
  3136. return -1;
  3137. wpa_s->drv_priv = wpa_drv_init(wpa_s, wpa_s->ifname);
  3138. if (wpa_s->drv_priv == NULL) {
  3139. const char *pos;
  3140. pos = driver ? os_strchr(driver, ',') : NULL;
  3141. if (pos) {
  3142. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize "
  3143. "driver interface - try next driver wrapper");
  3144. driver = pos + 1;
  3145. goto next_driver;
  3146. }
  3147. wpa_msg(wpa_s, MSG_ERROR, "Failed to initialize driver "
  3148. "interface");
  3149. return -1;
  3150. }
  3151. if (wpa_drv_set_param(wpa_s, wpa_s->conf->driver_param) < 0) {
  3152. wpa_msg(wpa_s, MSG_ERROR, "Driver interface rejected "
  3153. "driver_param '%s'", wpa_s->conf->driver_param);
  3154. return -1;
  3155. }
  3156. ifname = wpa_drv_get_ifname(wpa_s);
  3157. if (ifname && os_strcmp(ifname, wpa_s->ifname) != 0) {
  3158. wpa_dbg(wpa_s, MSG_DEBUG, "Driver interface replaced "
  3159. "interface name with '%s'", ifname);
  3160. os_strlcpy(wpa_s->ifname, ifname, sizeof(wpa_s->ifname));
  3161. }
  3162. rn = wpa_driver_get_radio_name(wpa_s);
  3163. if (rn && rn[0] == '\0')
  3164. rn = NULL;
  3165. wpa_s->radio = radio_add_interface(wpa_s, rn);
  3166. if (wpa_s->radio == NULL)
  3167. return -1;
  3168. return 0;
  3169. }
  3170. static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
  3171. struct wpa_interface *iface)
  3172. {
  3173. struct wpa_driver_capa capa;
  3174. int capa_res;
  3175. wpa_printf(MSG_DEBUG, "Initializing interface '%s' conf '%s' driver "
  3176. "'%s' ctrl_interface '%s' bridge '%s'", iface->ifname,
  3177. iface->confname ? iface->confname : "N/A",
  3178. iface->driver ? iface->driver : "default",
  3179. iface->ctrl_interface ? iface->ctrl_interface : "N/A",
  3180. iface->bridge_ifname ? iface->bridge_ifname : "N/A");
  3181. if (iface->confname) {
  3182. #ifdef CONFIG_BACKEND_FILE
  3183. wpa_s->confname = os_rel2abs_path(iface->confname);
  3184. if (wpa_s->confname == NULL) {
  3185. wpa_printf(MSG_ERROR, "Failed to get absolute path "
  3186. "for configuration file '%s'.",
  3187. iface->confname);
  3188. return -1;
  3189. }
  3190. wpa_printf(MSG_DEBUG, "Configuration file '%s' -> '%s'",
  3191. iface->confname, wpa_s->confname);
  3192. #else /* CONFIG_BACKEND_FILE */
  3193. wpa_s->confname = os_strdup(iface->confname);
  3194. #endif /* CONFIG_BACKEND_FILE */
  3195. wpa_s->conf = wpa_config_read(wpa_s->confname, NULL);
  3196. if (wpa_s->conf == NULL) {
  3197. wpa_printf(MSG_ERROR, "Failed to read or parse "
  3198. "configuration '%s'.", wpa_s->confname);
  3199. return -1;
  3200. }
  3201. wpa_s->confanother = os_rel2abs_path(iface->confanother);
  3202. wpa_config_read(wpa_s->confanother, wpa_s->conf);
  3203. /*
  3204. * Override ctrl_interface and driver_param if set on command
  3205. * line.
  3206. */
  3207. if (iface->ctrl_interface) {
  3208. os_free(wpa_s->conf->ctrl_interface);
  3209. wpa_s->conf->ctrl_interface =
  3210. os_strdup(iface->ctrl_interface);
  3211. }
  3212. if (iface->driver_param) {
  3213. os_free(wpa_s->conf->driver_param);
  3214. wpa_s->conf->driver_param =
  3215. os_strdup(iface->driver_param);
  3216. }
  3217. if (iface->p2p_mgmt && !iface->ctrl_interface) {
  3218. os_free(wpa_s->conf->ctrl_interface);
  3219. wpa_s->conf->ctrl_interface = NULL;
  3220. }
  3221. } else
  3222. wpa_s->conf = wpa_config_alloc_empty(iface->ctrl_interface,
  3223. iface->driver_param);
  3224. if (wpa_s->conf == NULL) {
  3225. wpa_printf(MSG_ERROR, "\nNo configuration found.");
  3226. return -1;
  3227. }
  3228. if (iface->ifname == NULL) {
  3229. wpa_printf(MSG_ERROR, "\nInterface name is required.");
  3230. return -1;
  3231. }
  3232. if (os_strlen(iface->ifname) >= sizeof(wpa_s->ifname)) {
  3233. wpa_printf(MSG_ERROR, "\nToo long interface name '%s'.",
  3234. iface->ifname);
  3235. return -1;
  3236. }
  3237. os_strlcpy(wpa_s->ifname, iface->ifname, sizeof(wpa_s->ifname));
  3238. if (iface->bridge_ifname) {
  3239. if (os_strlen(iface->bridge_ifname) >=
  3240. sizeof(wpa_s->bridge_ifname)) {
  3241. wpa_printf(MSG_ERROR, "\nToo long bridge interface "
  3242. "name '%s'.", iface->bridge_ifname);
  3243. return -1;
  3244. }
  3245. os_strlcpy(wpa_s->bridge_ifname, iface->bridge_ifname,
  3246. sizeof(wpa_s->bridge_ifname));
  3247. }
  3248. /* RSNA Supplicant Key Management - INITIALIZE */
  3249. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  3250. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  3251. /* Initialize driver interface and register driver event handler before
  3252. * L2 receive handler so that association events are processed before
  3253. * EAPOL-Key packets if both become available for the same select()
  3254. * call. */
  3255. if (wpas_init_driver(wpa_s, iface) < 0)
  3256. return -1;
  3257. if (wpa_supplicant_init_wpa(wpa_s) < 0)
  3258. return -1;
  3259. wpa_sm_set_ifname(wpa_s->wpa, wpa_s->ifname,
  3260. wpa_s->bridge_ifname[0] ? wpa_s->bridge_ifname :
  3261. NULL);
  3262. wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth);
  3263. if (wpa_s->conf->dot11RSNAConfigPMKLifetime &&
  3264. wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
  3265. wpa_s->conf->dot11RSNAConfigPMKLifetime)) {
  3266. wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for "
  3267. "dot11RSNAConfigPMKLifetime");
  3268. return -1;
  3269. }
  3270. if (wpa_s->conf->dot11RSNAConfigPMKReauthThreshold &&
  3271. wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
  3272. wpa_s->conf->dot11RSNAConfigPMKReauthThreshold)) {
  3273. wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for "
  3274. "dot11RSNAConfigPMKReauthThreshold");
  3275. return -1;
  3276. }
  3277. if (wpa_s->conf->dot11RSNAConfigSATimeout &&
  3278. wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
  3279. wpa_s->conf->dot11RSNAConfigSATimeout)) {
  3280. wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for "
  3281. "dot11RSNAConfigSATimeout");
  3282. return -1;
  3283. }
  3284. wpa_s->hw.modes = wpa_drv_get_hw_feature_data(wpa_s,
  3285. &wpa_s->hw.num_modes,
  3286. &wpa_s->hw.flags);
  3287. capa_res = wpa_drv_get_capa(wpa_s, &capa);
  3288. if (capa_res == 0) {
  3289. wpa_s->drv_capa_known = 1;
  3290. wpa_s->drv_flags = capa.flags;
  3291. wpa_s->drv_enc = capa.enc;
  3292. wpa_s->drv_smps_modes = capa.smps_modes;
  3293. wpa_s->drv_rrm_flags = capa.rrm_flags;
  3294. wpa_s->probe_resp_offloads = capa.probe_resp_offloads;
  3295. wpa_s->max_scan_ssids = capa.max_scan_ssids;
  3296. wpa_s->max_sched_scan_ssids = capa.max_sched_scan_ssids;
  3297. wpa_s->sched_scan_supported = capa.sched_scan_supported;
  3298. wpa_s->max_match_sets = capa.max_match_sets;
  3299. wpa_s->max_remain_on_chan = capa.max_remain_on_chan;
  3300. wpa_s->max_stations = capa.max_stations;
  3301. wpa_s->extended_capa = capa.extended_capa;
  3302. wpa_s->extended_capa_mask = capa.extended_capa_mask;
  3303. wpa_s->extended_capa_len = capa.extended_capa_len;
  3304. wpa_s->num_multichan_concurrent =
  3305. capa.num_multichan_concurrent;
  3306. wpa_s->wmm_ac_supported = capa.wmm_ac_supported;
  3307. }
  3308. if (wpa_s->max_remain_on_chan == 0)
  3309. wpa_s->max_remain_on_chan = 1000;
  3310. /*
  3311. * Only take p2p_mgmt parameters when P2P Device is supported.
  3312. * Doing it here as it determines whether l2_packet_init() will be done
  3313. * during wpa_supplicant_driver_init().
  3314. */
  3315. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)
  3316. wpa_s->p2p_mgmt = iface->p2p_mgmt;
  3317. else
  3318. iface->p2p_mgmt = 1;
  3319. if (wpa_s->num_multichan_concurrent == 0)
  3320. wpa_s->num_multichan_concurrent = 1;
  3321. if (wpa_supplicant_driver_init(wpa_s) < 0)
  3322. return -1;
  3323. #ifdef CONFIG_TDLS
  3324. if ((!iface->p2p_mgmt ||
  3325. !(wpa_s->drv_flags &
  3326. WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) &&
  3327. wpa_tdls_init(wpa_s->wpa))
  3328. return -1;
  3329. #endif /* CONFIG_TDLS */
  3330. if (wpa_s->conf->country[0] && wpa_s->conf->country[1] &&
  3331. wpa_drv_set_country(wpa_s, wpa_s->conf->country)) {
  3332. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to set country");
  3333. return -1;
  3334. }
  3335. if (wpas_wps_init(wpa_s))
  3336. return -1;
  3337. if (wpa_supplicant_init_eapol(wpa_s) < 0)
  3338. return -1;
  3339. wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol);
  3340. wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s);
  3341. if (wpa_s->ctrl_iface == NULL) {
  3342. wpa_printf(MSG_ERROR,
  3343. "Failed to initialize control interface '%s'.\n"
  3344. "You may have another wpa_supplicant process "
  3345. "already running or the file was\n"
  3346. "left by an unclean termination of wpa_supplicant "
  3347. "in which case you will need\n"
  3348. "to manually remove this file before starting "
  3349. "wpa_supplicant again.\n",
  3350. wpa_s->conf->ctrl_interface);
  3351. return -1;
  3352. }
  3353. wpa_s->gas = gas_query_init(wpa_s);
  3354. if (wpa_s->gas == NULL) {
  3355. wpa_printf(MSG_ERROR, "Failed to initialize GAS query");
  3356. return -1;
  3357. }
  3358. if (iface->p2p_mgmt && wpas_p2p_init(wpa_s->global, wpa_s) < 0) {
  3359. wpa_msg(wpa_s, MSG_ERROR, "Failed to init P2P");
  3360. return -1;
  3361. }
  3362. if (wpa_bss_init(wpa_s) < 0)
  3363. return -1;
  3364. /*
  3365. * Set Wake-on-WLAN triggers, if configured.
  3366. * Note: We don't restore/remove the triggers on shutdown (it doesn't
  3367. * have effect anyway when the interface is down).
  3368. */
  3369. if (capa_res == 0 && wpas_set_wowlan_triggers(wpa_s, &capa) < 0)
  3370. return -1;
  3371. #ifdef CONFIG_EAP_PROXY
  3372. {
  3373. size_t len;
  3374. wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, wpa_s->imsi,
  3375. &len);
  3376. if (wpa_s->mnc_len > 0) {
  3377. wpa_s->imsi[len] = '\0';
  3378. wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)",
  3379. wpa_s->imsi, wpa_s->mnc_len);
  3380. } else {
  3381. wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available");
  3382. }
  3383. }
  3384. #endif /* CONFIG_EAP_PROXY */
  3385. if (pcsc_reader_init(wpa_s) < 0)
  3386. return -1;
  3387. if (wpas_init_ext_pw(wpa_s) < 0)
  3388. return -1;
  3389. wpas_rrm_reset(wpa_s);
  3390. return 0;
  3391. }
  3392. static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s,
  3393. int notify, int terminate)
  3394. {
  3395. struct wpa_global *global = wpa_s->global;
  3396. struct wpa_supplicant *iface, *prev;
  3397. if (wpa_s == wpa_s->parent)
  3398. wpas_p2p_group_remove(wpa_s, "*");
  3399. iface = global->ifaces;
  3400. while (iface) {
  3401. if (iface == wpa_s || iface->parent != wpa_s) {
  3402. iface = iface->next;
  3403. continue;
  3404. }
  3405. wpa_printf(MSG_DEBUG,
  3406. "Remove remaining child interface %s from parent %s",
  3407. iface->ifname, wpa_s->ifname);
  3408. prev = iface;
  3409. iface = iface->next;
  3410. wpa_supplicant_remove_iface(global, prev, terminate);
  3411. }
  3412. wpa_s->disconnected = 1;
  3413. if (wpa_s->drv_priv) {
  3414. wpa_supplicant_deauthenticate(wpa_s,
  3415. WLAN_REASON_DEAUTH_LEAVING);
  3416. wpa_drv_set_countermeasures(wpa_s, 0);
  3417. wpa_clear_keys(wpa_s, NULL);
  3418. }
  3419. wpa_supplicant_cleanup(wpa_s);
  3420. wpas_p2p_deinit_iface(wpa_s);
  3421. wpas_ctrl_radio_work_flush(wpa_s);
  3422. radio_remove_interface(wpa_s);
  3423. if (wpa_s->drv_priv)
  3424. wpa_drv_deinit(wpa_s);
  3425. if (notify)
  3426. wpas_notify_iface_removed(wpa_s);
  3427. if (terminate)
  3428. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING);
  3429. if (wpa_s->ctrl_iface) {
  3430. wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
  3431. wpa_s->ctrl_iface = NULL;
  3432. }
  3433. #ifdef CONFIG_MESH
  3434. if (wpa_s->ifmsh) {
  3435. wpa_supplicant_mesh_iface_deinit(wpa_s, wpa_s->ifmsh);
  3436. wpa_s->ifmsh = NULL;
  3437. }
  3438. #endif /* CONFIG_MESH */
  3439. if (wpa_s->conf != NULL) {
  3440. wpa_config_free(wpa_s->conf);
  3441. wpa_s->conf = NULL;
  3442. }
  3443. os_free(wpa_s);
  3444. }
  3445. /**
  3446. * wpa_supplicant_add_iface - Add a new network interface
  3447. * @global: Pointer to global data from wpa_supplicant_init()
  3448. * @iface: Interface configuration options
  3449. * Returns: Pointer to the created interface or %NULL on failure
  3450. *
  3451. * This function is used to add new network interfaces for %wpa_supplicant.
  3452. * This can be called before wpa_supplicant_run() to add interfaces before the
  3453. * main event loop has been started. In addition, new interfaces can be added
  3454. * dynamically while %wpa_supplicant is already running. This could happen,
  3455. * e.g., when a hotplug network adapter is inserted.
  3456. */
  3457. struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
  3458. struct wpa_interface *iface)
  3459. {
  3460. struct wpa_supplicant *wpa_s;
  3461. struct wpa_interface t_iface;
  3462. struct wpa_ssid *ssid;
  3463. if (global == NULL || iface == NULL)
  3464. return NULL;
  3465. wpa_s = wpa_supplicant_alloc();
  3466. if (wpa_s == NULL)
  3467. return NULL;
  3468. wpa_s->global = global;
  3469. t_iface = *iface;
  3470. if (global->params.override_driver) {
  3471. wpa_printf(MSG_DEBUG, "Override interface parameter: driver "
  3472. "('%s' -> '%s')",
  3473. iface->driver, global->params.override_driver);
  3474. t_iface.driver = global->params.override_driver;
  3475. }
  3476. if (global->params.override_ctrl_interface) {
  3477. wpa_printf(MSG_DEBUG, "Override interface parameter: "
  3478. "ctrl_interface ('%s' -> '%s')",
  3479. iface->ctrl_interface,
  3480. global->params.override_ctrl_interface);
  3481. t_iface.ctrl_interface =
  3482. global->params.override_ctrl_interface;
  3483. }
  3484. if (wpa_supplicant_init_iface(wpa_s, &t_iface)) {
  3485. wpa_printf(MSG_DEBUG, "Failed to add interface %s",
  3486. iface->ifname);
  3487. wpa_supplicant_deinit_iface(wpa_s, 0, 0);
  3488. return NULL;
  3489. }
  3490. if (iface->p2p_mgmt == 0) {
  3491. /* Notify the control interfaces about new iface */
  3492. if (wpas_notify_iface_added(wpa_s)) {
  3493. wpa_supplicant_deinit_iface(wpa_s, 1, 0);
  3494. return NULL;
  3495. }
  3496. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
  3497. wpas_notify_network_added(wpa_s, ssid);
  3498. }
  3499. wpa_s->next = global->ifaces;
  3500. global->ifaces = wpa_s;
  3501. wpa_dbg(wpa_s, MSG_DEBUG, "Added interface %s", wpa_s->ifname);
  3502. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  3503. #ifdef CONFIG_P2P
  3504. if (wpa_s->global->p2p == NULL &&
  3505. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
  3506. wpas_p2p_add_p2pdev_interface(wpa_s, iface->conf_p2p_dev) < 0) {
  3507. wpa_printf(MSG_INFO,
  3508. "P2P: Failed to enable P2P Device interface");
  3509. /* Try to continue without. P2P will be disabled. */
  3510. }
  3511. #endif /* CONFIG_P2P */
  3512. return wpa_s;
  3513. }
  3514. /**
  3515. * wpa_supplicant_remove_iface - Remove a network interface
  3516. * @global: Pointer to global data from wpa_supplicant_init()
  3517. * @wpa_s: Pointer to the network interface to be removed
  3518. * Returns: 0 if interface was removed, -1 if interface was not found
  3519. *
  3520. * This function can be used to dynamically remove network interfaces from
  3521. * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
  3522. * addition, this function is used to remove all remaining interfaces when
  3523. * %wpa_supplicant is terminated.
  3524. */
  3525. int wpa_supplicant_remove_iface(struct wpa_global *global,
  3526. struct wpa_supplicant *wpa_s,
  3527. int terminate)
  3528. {
  3529. struct wpa_supplicant *prev;
  3530. #ifdef CONFIG_MESH
  3531. unsigned int mesh_if_created = wpa_s->mesh_if_created;
  3532. char *ifname = NULL;
  3533. #endif /* CONFIG_MESH */
  3534. /* Remove interface from the global list of interfaces */
  3535. prev = global->ifaces;
  3536. if (prev == wpa_s) {
  3537. global->ifaces = wpa_s->next;
  3538. } else {
  3539. while (prev && prev->next != wpa_s)
  3540. prev = prev->next;
  3541. if (prev == NULL)
  3542. return -1;
  3543. prev->next = wpa_s->next;
  3544. }
  3545. wpa_dbg(wpa_s, MSG_DEBUG, "Removing interface %s", wpa_s->ifname);
  3546. #ifdef CONFIG_MESH
  3547. if (mesh_if_created) {
  3548. ifname = os_strdup(wpa_s->ifname);
  3549. if (ifname == NULL) {
  3550. wpa_dbg(wpa_s, MSG_ERROR,
  3551. "mesh: Failed to malloc ifname");
  3552. return -1;
  3553. }
  3554. }
  3555. #endif /* CONFIG_MESH */
  3556. if (global->p2p_group_formation == wpa_s)
  3557. global->p2p_group_formation = NULL;
  3558. if (global->p2p_invite_group == wpa_s)
  3559. global->p2p_invite_group = NULL;
  3560. wpa_supplicant_deinit_iface(wpa_s, 1, terminate);
  3561. #ifdef CONFIG_MESH
  3562. if (mesh_if_created) {
  3563. wpa_drv_if_remove(global->ifaces, WPA_IF_MESH, ifname);
  3564. os_free(ifname);
  3565. }
  3566. #endif /* CONFIG_MESH */
  3567. return 0;
  3568. }
  3569. /**
  3570. * wpa_supplicant_get_eap_mode - Get the current EAP mode
  3571. * @wpa_s: Pointer to the network interface
  3572. * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found
  3573. */
  3574. const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant *wpa_s)
  3575. {
  3576. const char *eapol_method;
  3577. if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) == 0 &&
  3578. wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  3579. return "NO-EAP";
  3580. }
  3581. eapol_method = eapol_sm_get_method_name(wpa_s->eapol);
  3582. if (eapol_method == NULL)
  3583. return "UNKNOWN-EAP";
  3584. return eapol_method;
  3585. }
  3586. /**
  3587. * wpa_supplicant_get_iface - Get a new network interface
  3588. * @global: Pointer to global data from wpa_supplicant_init()
  3589. * @ifname: Interface name
  3590. * Returns: Pointer to the interface or %NULL if not found
  3591. */
  3592. struct wpa_supplicant * wpa_supplicant_get_iface(struct wpa_global *global,
  3593. const char *ifname)
  3594. {
  3595. struct wpa_supplicant *wpa_s;
  3596. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  3597. if (os_strcmp(wpa_s->ifname, ifname) == 0)
  3598. return wpa_s;
  3599. }
  3600. return NULL;
  3601. }
  3602. #ifndef CONFIG_NO_WPA_MSG
  3603. static const char * wpa_supplicant_msg_ifname_cb(void *ctx)
  3604. {
  3605. struct wpa_supplicant *wpa_s = ctx;
  3606. if (wpa_s == NULL)
  3607. return NULL;
  3608. return wpa_s->ifname;
  3609. }
  3610. #endif /* CONFIG_NO_WPA_MSG */
  3611. /**
  3612. * wpa_supplicant_init - Initialize %wpa_supplicant
  3613. * @params: Parameters for %wpa_supplicant
  3614. * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure
  3615. *
  3616. * This function is used to initialize %wpa_supplicant. After successful
  3617. * initialization, the returned data pointer can be used to add and remove
  3618. * network interfaces, and eventually, to deinitialize %wpa_supplicant.
  3619. */
  3620. struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
  3621. {
  3622. struct wpa_global *global;
  3623. int ret, i;
  3624. if (params == NULL)
  3625. return NULL;
  3626. #ifdef CONFIG_DRIVER_NDIS
  3627. {
  3628. void driver_ndis_init_ops(void);
  3629. driver_ndis_init_ops();
  3630. }
  3631. #endif /* CONFIG_DRIVER_NDIS */
  3632. #ifndef CONFIG_NO_WPA_MSG
  3633. wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb);
  3634. #endif /* CONFIG_NO_WPA_MSG */
  3635. wpa_debug_open_file(params->wpa_debug_file_path);
  3636. if (params->wpa_debug_syslog)
  3637. wpa_debug_open_syslog();
  3638. if (params->wpa_debug_tracing) {
  3639. ret = wpa_debug_open_linux_tracing();
  3640. if (ret) {
  3641. wpa_printf(MSG_ERROR,
  3642. "Failed to enable trace logging");
  3643. return NULL;
  3644. }
  3645. }
  3646. ret = eap_register_methods();
  3647. if (ret) {
  3648. wpa_printf(MSG_ERROR, "Failed to register EAP methods");
  3649. if (ret == -2)
  3650. wpa_printf(MSG_ERROR, "Two or more EAP methods used "
  3651. "the same EAP type.");
  3652. return NULL;
  3653. }
  3654. global = os_zalloc(sizeof(*global));
  3655. if (global == NULL)
  3656. return NULL;
  3657. dl_list_init(&global->p2p_srv_bonjour);
  3658. dl_list_init(&global->p2p_srv_upnp);
  3659. global->params.daemonize = params->daemonize;
  3660. global->params.wait_for_monitor = params->wait_for_monitor;
  3661. global->params.dbus_ctrl_interface = params->dbus_ctrl_interface;
  3662. if (params->pid_file)
  3663. global->params.pid_file = os_strdup(params->pid_file);
  3664. if (params->ctrl_interface)
  3665. global->params.ctrl_interface =
  3666. os_strdup(params->ctrl_interface);
  3667. if (params->ctrl_interface_group)
  3668. global->params.ctrl_interface_group =
  3669. os_strdup(params->ctrl_interface_group);
  3670. if (params->override_driver)
  3671. global->params.override_driver =
  3672. os_strdup(params->override_driver);
  3673. if (params->override_ctrl_interface)
  3674. global->params.override_ctrl_interface =
  3675. os_strdup(params->override_ctrl_interface);
  3676. wpa_debug_level = global->params.wpa_debug_level =
  3677. params->wpa_debug_level;
  3678. wpa_debug_show_keys = global->params.wpa_debug_show_keys =
  3679. params->wpa_debug_show_keys;
  3680. wpa_debug_timestamp = global->params.wpa_debug_timestamp =
  3681. params->wpa_debug_timestamp;
  3682. wpa_printf(MSG_DEBUG, "wpa_supplicant v" VERSION_STR);
  3683. if (eloop_init()) {
  3684. wpa_printf(MSG_ERROR, "Failed to initialize event loop");
  3685. wpa_supplicant_deinit(global);
  3686. return NULL;
  3687. }
  3688. random_init(params->entropy_file);
  3689. global->ctrl_iface = wpa_supplicant_global_ctrl_iface_init(global);
  3690. if (global->ctrl_iface == NULL) {
  3691. wpa_supplicant_deinit(global);
  3692. return NULL;
  3693. }
  3694. if (wpas_notify_supplicant_initialized(global)) {
  3695. wpa_supplicant_deinit(global);
  3696. return NULL;
  3697. }
  3698. for (i = 0; wpa_drivers[i]; i++)
  3699. global->drv_count++;
  3700. if (global->drv_count == 0) {
  3701. wpa_printf(MSG_ERROR, "No drivers enabled");
  3702. wpa_supplicant_deinit(global);
  3703. return NULL;
  3704. }
  3705. global->drv_priv = os_calloc(global->drv_count, sizeof(void *));
  3706. if (global->drv_priv == NULL) {
  3707. wpa_supplicant_deinit(global);
  3708. return NULL;
  3709. }
  3710. #ifdef CONFIG_WIFI_DISPLAY
  3711. if (wifi_display_init(global) < 0) {
  3712. wpa_printf(MSG_ERROR, "Failed to initialize Wi-Fi Display");
  3713. wpa_supplicant_deinit(global);
  3714. return NULL;
  3715. }
  3716. #endif /* CONFIG_WIFI_DISPLAY */
  3717. return global;
  3718. }
  3719. /**
  3720. * wpa_supplicant_run - Run the %wpa_supplicant main event loop
  3721. * @global: Pointer to global data from wpa_supplicant_init()
  3722. * Returns: 0 after successful event loop run, -1 on failure
  3723. *
  3724. * This function starts the main event loop and continues running as long as
  3725. * there are any remaining events. In most cases, this function is running as
  3726. * long as the %wpa_supplicant process in still in use.
  3727. */
  3728. int wpa_supplicant_run(struct wpa_global *global)
  3729. {
  3730. struct wpa_supplicant *wpa_s;
  3731. if (global->params.daemonize &&
  3732. wpa_supplicant_daemon(global->params.pid_file))
  3733. return -1;
  3734. if (global->params.wait_for_monitor) {
  3735. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
  3736. if (wpa_s->ctrl_iface)
  3737. wpa_supplicant_ctrl_iface_wait(
  3738. wpa_s->ctrl_iface);
  3739. }
  3740. eloop_register_signal_terminate(wpa_supplicant_terminate, global);
  3741. eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
  3742. eloop_run();
  3743. return 0;
  3744. }
  3745. /**
  3746. * wpa_supplicant_deinit - Deinitialize %wpa_supplicant
  3747. * @global: Pointer to global data from wpa_supplicant_init()
  3748. *
  3749. * This function is called to deinitialize %wpa_supplicant and to free all
  3750. * allocated resources. Remaining network interfaces will also be removed.
  3751. */
  3752. void wpa_supplicant_deinit(struct wpa_global *global)
  3753. {
  3754. int i;
  3755. if (global == NULL)
  3756. return;
  3757. #ifdef CONFIG_WIFI_DISPLAY
  3758. wifi_display_deinit(global);
  3759. #endif /* CONFIG_WIFI_DISPLAY */
  3760. while (global->ifaces)
  3761. wpa_supplicant_remove_iface(global, global->ifaces, 1);
  3762. if (global->ctrl_iface)
  3763. wpa_supplicant_global_ctrl_iface_deinit(global->ctrl_iface);
  3764. wpas_notify_supplicant_deinitialized(global);
  3765. eap_peer_unregister_methods();
  3766. #ifdef CONFIG_AP
  3767. eap_server_unregister_methods();
  3768. #endif /* CONFIG_AP */
  3769. for (i = 0; wpa_drivers[i] && global->drv_priv; i++) {
  3770. if (!global->drv_priv[i])
  3771. continue;
  3772. wpa_drivers[i]->global_deinit(global->drv_priv[i]);
  3773. }
  3774. os_free(global->drv_priv);
  3775. random_deinit();
  3776. eloop_destroy();
  3777. if (global->params.pid_file) {
  3778. os_daemonize_terminate(global->params.pid_file);
  3779. os_free(global->params.pid_file);
  3780. }
  3781. os_free(global->params.ctrl_interface);
  3782. os_free(global->params.ctrl_interface_group);
  3783. os_free(global->params.override_driver);
  3784. os_free(global->params.override_ctrl_interface);
  3785. os_free(global->p2p_disallow_freq.range);
  3786. os_free(global->p2p_go_avoid_freq.range);
  3787. os_free(global->add_psk);
  3788. os_free(global);
  3789. wpa_debug_close_syslog();
  3790. wpa_debug_close_file();
  3791. wpa_debug_close_linux_tracing();
  3792. }
  3793. void wpa_supplicant_update_config(struct wpa_supplicant *wpa_s)
  3794. {
  3795. if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) &&
  3796. wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
  3797. char country[3];
  3798. country[0] = wpa_s->conf->country[0];
  3799. country[1] = wpa_s->conf->country[1];
  3800. country[2] = '\0';
  3801. if (wpa_drv_set_country(wpa_s, country) < 0) {
  3802. wpa_printf(MSG_ERROR, "Failed to set country code "
  3803. "'%s'", country);
  3804. }
  3805. }
  3806. if (wpa_s->conf->changed_parameters & CFG_CHANGED_EXT_PW_BACKEND)
  3807. wpas_init_ext_pw(wpa_s);
  3808. #ifdef CONFIG_WPS
  3809. wpas_wps_update_config(wpa_s);
  3810. #endif /* CONFIG_WPS */
  3811. wpas_p2p_update_config(wpa_s);
  3812. wpa_s->conf->changed_parameters = 0;
  3813. }
  3814. void add_freq(int *freqs, int *num_freqs, int freq)
  3815. {
  3816. int i;
  3817. for (i = 0; i < *num_freqs; i++) {
  3818. if (freqs[i] == freq)
  3819. return;
  3820. }
  3821. freqs[*num_freqs] = freq;
  3822. (*num_freqs)++;
  3823. }
  3824. static int * get_bss_freqs_in_ess(struct wpa_supplicant *wpa_s)
  3825. {
  3826. struct wpa_bss *bss, *cbss;
  3827. const int max_freqs = 10;
  3828. int *freqs;
  3829. int num_freqs = 0;
  3830. freqs = os_calloc(max_freqs + 1, sizeof(int));
  3831. if (freqs == NULL)
  3832. return NULL;
  3833. cbss = wpa_s->current_bss;
  3834. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  3835. if (bss == cbss)
  3836. continue;
  3837. if (bss->ssid_len == cbss->ssid_len &&
  3838. os_memcmp(bss->ssid, cbss->ssid, bss->ssid_len) == 0 &&
  3839. wpa_blacklist_get(wpa_s, bss->bssid) == NULL) {
  3840. add_freq(freqs, &num_freqs, bss->freq);
  3841. if (num_freqs == max_freqs)
  3842. break;
  3843. }
  3844. }
  3845. if (num_freqs == 0) {
  3846. os_free(freqs);
  3847. freqs = NULL;
  3848. }
  3849. return freqs;
  3850. }
  3851. void wpas_connection_failed(struct wpa_supplicant *wpa_s, const u8 *bssid)
  3852. {
  3853. int timeout;
  3854. int count;
  3855. int *freqs = NULL;
  3856. wpas_connect_work_done(wpa_s);
  3857. /*
  3858. * Remove possible authentication timeout since the connection failed.
  3859. */
  3860. eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL);
  3861. if (wpa_s->disconnected) {
  3862. /*
  3863. * There is no point in blacklisting the AP if this event is
  3864. * generated based on local request to disconnect.
  3865. */
  3866. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore connection failure "
  3867. "indication since interface has been put into "
  3868. "disconnected state");
  3869. return;
  3870. }
  3871. /*
  3872. * Add the failed BSSID into the blacklist and speed up next scan
  3873. * attempt if there could be other APs that could accept association.
  3874. * The current blacklist count indicates how many times we have tried
  3875. * connecting to this AP and multiple attempts mean that other APs are
  3876. * either not available or has already been tried, so that we can start
  3877. * increasing the delay here to avoid constant scanning.
  3878. */
  3879. count = wpa_blacklist_add(wpa_s, bssid);
  3880. if (count == 1 && wpa_s->current_bss) {
  3881. /*
  3882. * This BSS was not in the blacklist before. If there is
  3883. * another BSS available for the same ESS, we should try that
  3884. * next. Otherwise, we may as well try this one once more
  3885. * before allowing other, likely worse, ESSes to be considered.
  3886. */
  3887. freqs = get_bss_freqs_in_ess(wpa_s);
  3888. if (freqs) {
  3889. wpa_dbg(wpa_s, MSG_DEBUG, "Another BSS in this ESS "
  3890. "has been seen; try it next");
  3891. wpa_blacklist_add(wpa_s, bssid);
  3892. /*
  3893. * On the next scan, go through only the known channels
  3894. * used in this ESS based on previous scans to speed up
  3895. * common load balancing use case.
  3896. */
  3897. os_free(wpa_s->next_scan_freqs);
  3898. wpa_s->next_scan_freqs = freqs;
  3899. }
  3900. }
  3901. /*
  3902. * Add previous failure count in case the temporary blacklist was
  3903. * cleared due to no other BSSes being available.
  3904. */
  3905. count += wpa_s->extra_blacklist_count;
  3906. if (count > 3 && wpa_s->current_ssid) {
  3907. wpa_printf(MSG_DEBUG, "Continuous association failures - "
  3908. "consider temporary network disabling");
  3909. wpas_auth_failed(wpa_s, "CONN_FAILED");
  3910. }
  3911. switch (count) {
  3912. case 1:
  3913. timeout = 100;
  3914. break;
  3915. case 2:
  3916. timeout = 500;
  3917. break;
  3918. case 3:
  3919. timeout = 1000;
  3920. break;
  3921. case 4:
  3922. timeout = 5000;
  3923. break;
  3924. default:
  3925. timeout = 10000;
  3926. break;
  3927. }
  3928. wpa_dbg(wpa_s, MSG_DEBUG, "Blacklist count %d --> request scan in %d "
  3929. "ms", count, timeout);
  3930. /*
  3931. * TODO: if more than one possible AP is available in scan results,
  3932. * could try the other ones before requesting a new scan.
  3933. */
  3934. wpa_supplicant_req_scan(wpa_s, timeout / 1000,
  3935. 1000 * (timeout % 1000));
  3936. }
  3937. int wpas_driver_bss_selection(struct wpa_supplicant *wpa_s)
  3938. {
  3939. return wpa_s->conf->ap_scan == 2 ||
  3940. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION);
  3941. }
  3942. #if defined(CONFIG_CTRL_IFACE) || defined(CONFIG_CTRL_IFACE_DBUS_NEW)
  3943. int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant *wpa_s,
  3944. struct wpa_ssid *ssid,
  3945. const char *field,
  3946. const char *value)
  3947. {
  3948. #ifdef IEEE8021X_EAPOL
  3949. struct eap_peer_config *eap = &ssid->eap;
  3950. wpa_printf(MSG_DEBUG, "CTRL_IFACE: response handle field=%s", field);
  3951. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: response value",
  3952. (const u8 *) value, os_strlen(value));
  3953. switch (wpa_supplicant_ctrl_req_from_string(field)) {
  3954. case WPA_CTRL_REQ_EAP_IDENTITY:
  3955. os_free(eap->identity);
  3956. eap->identity = (u8 *) os_strdup(value);
  3957. eap->identity_len = os_strlen(value);
  3958. eap->pending_req_identity = 0;
  3959. if (ssid == wpa_s->current_ssid)
  3960. wpa_s->reassociate = 1;
  3961. break;
  3962. case WPA_CTRL_REQ_EAP_PASSWORD:
  3963. bin_clear_free(eap->password, eap->password_len);
  3964. eap->password = (u8 *) os_strdup(value);
  3965. eap->password_len = os_strlen(value);
  3966. eap->pending_req_password = 0;
  3967. if (ssid == wpa_s->current_ssid)
  3968. wpa_s->reassociate = 1;
  3969. break;
  3970. case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
  3971. bin_clear_free(eap->new_password, eap->new_password_len);
  3972. eap->new_password = (u8 *) os_strdup(value);
  3973. eap->new_password_len = os_strlen(value);
  3974. eap->pending_req_new_password = 0;
  3975. if (ssid == wpa_s->current_ssid)
  3976. wpa_s->reassociate = 1;
  3977. break;
  3978. case WPA_CTRL_REQ_EAP_PIN:
  3979. str_clear_free(eap->pin);
  3980. eap->pin = os_strdup(value);
  3981. eap->pending_req_pin = 0;
  3982. if (ssid == wpa_s->current_ssid)
  3983. wpa_s->reassociate = 1;
  3984. break;
  3985. case WPA_CTRL_REQ_EAP_OTP:
  3986. bin_clear_free(eap->otp, eap->otp_len);
  3987. eap->otp = (u8 *) os_strdup(value);
  3988. eap->otp_len = os_strlen(value);
  3989. os_free(eap->pending_req_otp);
  3990. eap->pending_req_otp = NULL;
  3991. eap->pending_req_otp_len = 0;
  3992. break;
  3993. case WPA_CTRL_REQ_EAP_PASSPHRASE:
  3994. str_clear_free(eap->private_key_passwd);
  3995. eap->private_key_passwd = os_strdup(value);
  3996. eap->pending_req_passphrase = 0;
  3997. if (ssid == wpa_s->current_ssid)
  3998. wpa_s->reassociate = 1;
  3999. break;
  4000. case WPA_CTRL_REQ_SIM:
  4001. str_clear_free(eap->external_sim_resp);
  4002. eap->external_sim_resp = os_strdup(value);
  4003. break;
  4004. default:
  4005. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", field);
  4006. return -1;
  4007. }
  4008. return 0;
  4009. #else /* IEEE8021X_EAPOL */
  4010. wpa_printf(MSG_DEBUG, "CTRL_IFACE: IEEE 802.1X not included");
  4011. return -1;
  4012. #endif /* IEEE8021X_EAPOL */
  4013. }
  4014. #endif /* CONFIG_CTRL_IFACE || CONFIG_CTRL_IFACE_DBUS_NEW */
  4015. int wpas_network_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
  4016. {
  4017. int i;
  4018. unsigned int drv_enc;
  4019. if (ssid == NULL)
  4020. return 1;
  4021. if (ssid->disabled)
  4022. return 1;
  4023. if (wpa_s && wpa_s->drv_capa_known)
  4024. drv_enc = wpa_s->drv_enc;
  4025. else
  4026. drv_enc = (unsigned int) -1;
  4027. for (i = 0; i < NUM_WEP_KEYS; i++) {
  4028. size_t len = ssid->wep_key_len[i];
  4029. if (len == 0)
  4030. continue;
  4031. if (len == 5 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP40))
  4032. continue;
  4033. if (len == 13 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP104))
  4034. continue;
  4035. if (len == 16 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP128))
  4036. continue;
  4037. return 1; /* invalid WEP key */
  4038. }
  4039. if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && !ssid->psk_set &&
  4040. (!ssid->passphrase || ssid->ssid_len != 0) && !ssid->ext_psk)
  4041. return 1;
  4042. return 0;
  4043. }
  4044. int wpas_is_p2p_prioritized(struct wpa_supplicant *wpa_s)
  4045. {
  4046. if (wpa_s->global->conc_pref == WPA_CONC_PREF_P2P)
  4047. return 1;
  4048. if (wpa_s->global->conc_pref == WPA_CONC_PREF_STA)
  4049. return 0;
  4050. return -1;
  4051. }
  4052. void wpas_auth_failed(struct wpa_supplicant *wpa_s, char *reason)
  4053. {
  4054. struct wpa_ssid *ssid = wpa_s->current_ssid;
  4055. int dur;
  4056. struct os_reltime now;
  4057. if (ssid == NULL) {
  4058. wpa_printf(MSG_DEBUG, "Authentication failure but no known "
  4059. "SSID block");
  4060. return;
  4061. }
  4062. if (ssid->key_mgmt == WPA_KEY_MGMT_WPS)
  4063. return;
  4064. ssid->auth_failures++;
  4065. #ifdef CONFIG_P2P
  4066. if (ssid->p2p_group &&
  4067. (wpa_s->p2p_in_provisioning || wpa_s->show_group_started)) {
  4068. /*
  4069. * Skip the wait time since there is a short timeout on the
  4070. * connection to a P2P group.
  4071. */
  4072. return;
  4073. }
  4074. #endif /* CONFIG_P2P */
  4075. if (ssid->auth_failures > 50)
  4076. dur = 300;
  4077. else if (ssid->auth_failures > 10)
  4078. dur = 120;
  4079. else if (ssid->auth_failures > 5)
  4080. dur = 90;
  4081. else if (ssid->auth_failures > 3)
  4082. dur = 60;
  4083. else if (ssid->auth_failures > 2)
  4084. dur = 30;
  4085. else if (ssid->auth_failures > 1)
  4086. dur = 20;
  4087. else
  4088. dur = 10;
  4089. if (ssid->auth_failures > 1 &&
  4090. wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt))
  4091. dur += os_random() % (ssid->auth_failures * 10);
  4092. os_get_reltime(&now);
  4093. if (now.sec + dur <= ssid->disabled_until.sec)
  4094. return;
  4095. ssid->disabled_until.sec = now.sec + dur;
  4096. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TEMP_DISABLED
  4097. "id=%d ssid=\"%s\" auth_failures=%u duration=%d reason=%s",
  4098. ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
  4099. ssid->auth_failures, dur, reason);
  4100. }
  4101. void wpas_clear_temp_disabled(struct wpa_supplicant *wpa_s,
  4102. struct wpa_ssid *ssid, int clear_failures)
  4103. {
  4104. if (ssid == NULL)
  4105. return;
  4106. if (ssid->disabled_until.sec) {
  4107. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REENABLED
  4108. "id=%d ssid=\"%s\"",
  4109. ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  4110. }
  4111. ssid->disabled_until.sec = 0;
  4112. ssid->disabled_until.usec = 0;
  4113. if (clear_failures)
  4114. ssid->auth_failures = 0;
  4115. }
  4116. int disallowed_bssid(struct wpa_supplicant *wpa_s, const u8 *bssid)
  4117. {
  4118. size_t i;
  4119. if (wpa_s->disallow_aps_bssid == NULL)
  4120. return 0;
  4121. for (i = 0; i < wpa_s->disallow_aps_bssid_count; i++) {
  4122. if (os_memcmp(wpa_s->disallow_aps_bssid + i * ETH_ALEN,
  4123. bssid, ETH_ALEN) == 0)
  4124. return 1;
  4125. }
  4126. return 0;
  4127. }
  4128. int disallowed_ssid(struct wpa_supplicant *wpa_s, const u8 *ssid,
  4129. size_t ssid_len)
  4130. {
  4131. size_t i;
  4132. if (wpa_s->disallow_aps_ssid == NULL || ssid == NULL)
  4133. return 0;
  4134. for (i = 0; i < wpa_s->disallow_aps_ssid_count; i++) {
  4135. struct wpa_ssid_value *s = &wpa_s->disallow_aps_ssid[i];
  4136. if (ssid_len == s->ssid_len &&
  4137. os_memcmp(ssid, s->ssid, ssid_len) == 0)
  4138. return 1;
  4139. }
  4140. return 0;
  4141. }
  4142. /**
  4143. * wpas_request_connection - Request a new connection
  4144. * @wpa_s: Pointer to the network interface
  4145. *
  4146. * This function is used to request a new connection to be found. It will mark
  4147. * the interface to allow reassociation and request a new scan to find a
  4148. * suitable network to connect to.
  4149. */
  4150. void wpas_request_connection(struct wpa_supplicant *wpa_s)
  4151. {
  4152. wpa_s->normal_scans = 0;
  4153. wpa_s->scan_req = NORMAL_SCAN_REQ;
  4154. wpa_supplicant_reinit_autoscan(wpa_s);
  4155. wpa_s->extra_blacklist_count = 0;
  4156. wpa_s->disconnected = 0;
  4157. wpa_s->reassociate = 1;
  4158. if (wpa_supplicant_fast_associate(wpa_s) != 1)
  4159. wpa_supplicant_req_scan(wpa_s, 0, 0);
  4160. }
  4161. void dump_freq_data(struct wpa_supplicant *wpa_s, const char *title,
  4162. struct wpa_used_freq_data *freqs_data,
  4163. unsigned int len)
  4164. {
  4165. unsigned int i;
  4166. wpa_dbg(wpa_s, MSG_DEBUG, "Shared frequencies (len=%u): %s",
  4167. len, title);
  4168. for (i = 0; i < len; i++) {
  4169. struct wpa_used_freq_data *cur = &freqs_data[i];
  4170. wpa_dbg(wpa_s, MSG_DEBUG, "freq[%u]: %d, flags=0x%X",
  4171. i, cur->freq, cur->flags);
  4172. }
  4173. }
  4174. /*
  4175. * Find the operating frequencies of any of the virtual interfaces that
  4176. * are using the same radio as the current interface, and in addition, get
  4177. * information about the interface types that are using the frequency.
  4178. */
  4179. int get_shared_radio_freqs_data(struct wpa_supplicant *wpa_s,
  4180. struct wpa_used_freq_data *freqs_data,
  4181. unsigned int len)
  4182. {
  4183. struct wpa_supplicant *ifs;
  4184. u8 bssid[ETH_ALEN];
  4185. int freq;
  4186. unsigned int idx = 0, i;
  4187. wpa_dbg(wpa_s, MSG_DEBUG,
  4188. "Determining shared radio frequencies (max len %u)", len);
  4189. os_memset(freqs_data, 0, sizeof(struct wpa_used_freq_data) * len);
  4190. dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
  4191. radio_list) {
  4192. if (idx == len)
  4193. break;
  4194. if (ifs->current_ssid == NULL || ifs->assoc_freq == 0)
  4195. continue;
  4196. if (ifs->current_ssid->mode == WPAS_MODE_AP ||
  4197. ifs->current_ssid->mode == WPAS_MODE_P2P_GO)
  4198. freq = ifs->current_ssid->frequency;
  4199. else if (wpa_drv_get_bssid(ifs, bssid) == 0)
  4200. freq = ifs->assoc_freq;
  4201. else
  4202. continue;
  4203. /* Hold only distinct freqs */
  4204. for (i = 0; i < idx; i++)
  4205. if (freqs_data[i].freq == freq)
  4206. break;
  4207. if (i == idx)
  4208. freqs_data[idx++].freq = freq;
  4209. if (ifs->current_ssid->mode == WPAS_MODE_INFRA) {
  4210. freqs_data[i].flags = ifs->current_ssid->p2p_group ?
  4211. WPA_FREQ_USED_BY_P2P_CLIENT :
  4212. WPA_FREQ_USED_BY_INFRA_STATION;
  4213. }
  4214. }
  4215. dump_freq_data(wpa_s, "completed iteration", freqs_data, idx);
  4216. return idx;
  4217. }
  4218. /*
  4219. * Find the operating frequencies of any of the virtual interfaces that
  4220. * are using the same radio as the current interface.
  4221. */
  4222. int get_shared_radio_freqs(struct wpa_supplicant *wpa_s,
  4223. int *freq_array, unsigned int len)
  4224. {
  4225. struct wpa_used_freq_data *freqs_data;
  4226. int num, i;
  4227. os_memset(freq_array, 0, sizeof(int) * len);
  4228. freqs_data = os_calloc(len, sizeof(struct wpa_used_freq_data));
  4229. if (!freqs_data)
  4230. return -1;
  4231. num = get_shared_radio_freqs_data(wpa_s, freqs_data, len);
  4232. for (i = 0; i < num; i++)
  4233. freq_array[i] = freqs_data[i].freq;
  4234. os_free(freqs_data);
  4235. return num;
  4236. }
  4237. static void wpas_rrm_neighbor_rep_timeout_handler(void *data, void *user_ctx)
  4238. {
  4239. struct rrm_data *rrm = data;
  4240. if (!rrm->notify_neighbor_rep) {
  4241. wpa_printf(MSG_ERROR,
  4242. "RRM: Unexpected neighbor report timeout");
  4243. return;
  4244. }
  4245. wpa_printf(MSG_DEBUG, "RRM: Notifying neighbor report - NONE");
  4246. rrm->notify_neighbor_rep(rrm->neighbor_rep_cb_ctx, NULL);
  4247. rrm->notify_neighbor_rep = NULL;
  4248. rrm->neighbor_rep_cb_ctx = NULL;
  4249. }
  4250. /*
  4251. * wpas_rrm_reset - Clear and reset all RRM data in wpa_supplicant
  4252. * @wpa_s: Pointer to wpa_supplicant
  4253. */
  4254. void wpas_rrm_reset(struct wpa_supplicant *wpa_s)
  4255. {
  4256. wpa_s->rrm.rrm_used = 0;
  4257. eloop_cancel_timeout(wpas_rrm_neighbor_rep_timeout_handler, &wpa_s->rrm,
  4258. NULL);
  4259. if (wpa_s->rrm.notify_neighbor_rep)
  4260. wpas_rrm_neighbor_rep_timeout_handler(&wpa_s->rrm, NULL);
  4261. wpa_s->rrm.next_neighbor_rep_token = 1;
  4262. }
  4263. /*
  4264. * wpas_rrm_process_neighbor_rep - Handle incoming neighbor report
  4265. * @wpa_s: Pointer to wpa_supplicant
  4266. * @report: Neighbor report buffer, prefixed by a 1-byte dialog token
  4267. * @report_len: Length of neighbor report buffer
  4268. */
  4269. void wpas_rrm_process_neighbor_rep(struct wpa_supplicant *wpa_s,
  4270. const u8 *report, size_t report_len)
  4271. {
  4272. struct wpabuf *neighbor_rep;
  4273. wpa_hexdump(MSG_DEBUG, "RRM: New Neighbor Report", report, report_len);
  4274. if (report_len < 1)
  4275. return;
  4276. if (report[0] != wpa_s->rrm.next_neighbor_rep_token - 1) {
  4277. wpa_printf(MSG_DEBUG,
  4278. "RRM: Discarding neighbor report with token %d (expected %d)",
  4279. report[0], wpa_s->rrm.next_neighbor_rep_token - 1);
  4280. return;
  4281. }
  4282. eloop_cancel_timeout(wpas_rrm_neighbor_rep_timeout_handler, &wpa_s->rrm,
  4283. NULL);
  4284. if (!wpa_s->rrm.notify_neighbor_rep) {
  4285. wpa_printf(MSG_ERROR, "RRM: Unexpected neighbor report");
  4286. return;
  4287. }
  4288. /* skipping the first byte, which is only an id (dialog token) */
  4289. neighbor_rep = wpabuf_alloc(report_len - 1);
  4290. if (neighbor_rep == NULL)
  4291. return;
  4292. wpabuf_put_data(neighbor_rep, report + 1, report_len - 1);
  4293. wpa_printf(MSG_DEBUG, "RRM: Notifying neighbor report (token = %d)",
  4294. report[0]);
  4295. wpa_s->rrm.notify_neighbor_rep(wpa_s->rrm.neighbor_rep_cb_ctx,
  4296. neighbor_rep);
  4297. wpa_s->rrm.notify_neighbor_rep = NULL;
  4298. wpa_s->rrm.neighbor_rep_cb_ctx = NULL;
  4299. }
  4300. /**
  4301. * wpas_rrm_send_neighbor_rep_request - Request a neighbor report from our AP
  4302. * @wpa_s: Pointer to wpa_supplicant
  4303. * @ssid: if not null, this is sent in the request. Otherwise, no SSID IE
  4304. * is sent in the request.
  4305. * @cb: Callback function to be called once the requested report arrives, or
  4306. * timed out after RRM_NEIGHBOR_REPORT_TIMEOUT seconds.
  4307. * In the former case, 'neighbor_rep' is a newly allocated wpabuf, and it's
  4308. * the requester's responsibility to free it.
  4309. * In the latter case NULL will be sent in 'neighbor_rep'.
  4310. * @cb_ctx: Context value to send the callback function
  4311. * Returns: 0 in case of success, negative error code otherwise
  4312. *
  4313. * In case there is a previous request which has not been answered yet, the
  4314. * new request fails. The caller may retry after RRM_NEIGHBOR_REPORT_TIMEOUT.
  4315. * Request must contain a callback function.
  4316. */
  4317. int wpas_rrm_send_neighbor_rep_request(struct wpa_supplicant *wpa_s,
  4318. const struct wpa_ssid *ssid,
  4319. void (*cb)(void *ctx,
  4320. struct wpabuf *neighbor_rep),
  4321. void *cb_ctx)
  4322. {
  4323. struct wpabuf *buf;
  4324. const u8 *rrm_ie;
  4325. if (wpa_s->wpa_state != WPA_COMPLETED || wpa_s->current_ssid == NULL) {
  4326. wpa_printf(MSG_DEBUG, "RRM: No connection, no RRM.");
  4327. return -ENOTCONN;
  4328. }
  4329. if (!wpa_s->rrm.rrm_used) {
  4330. wpa_printf(MSG_DEBUG, "RRM: No RRM in current connection.");
  4331. return -EOPNOTSUPP;
  4332. }
  4333. rrm_ie = wpa_bss_get_ie(wpa_s->current_bss,
  4334. WLAN_EID_RRM_ENABLED_CAPABILITIES);
  4335. if (!rrm_ie || !(wpa_s->current_bss->caps & IEEE80211_CAP_RRM) ||
  4336. !(rrm_ie[2] & WLAN_RRM_CAPS_NEIGHBOR_REPORT)) {
  4337. wpa_printf(MSG_DEBUG,
  4338. "RRM: No network support for Neighbor Report.");
  4339. return -EOPNOTSUPP;
  4340. }
  4341. if (!cb) {
  4342. wpa_printf(MSG_DEBUG,
  4343. "RRM: Neighbor Report request must provide a callback.");
  4344. return -EINVAL;
  4345. }
  4346. /* Refuse if there's a live request */
  4347. if (wpa_s->rrm.notify_neighbor_rep) {
  4348. wpa_printf(MSG_DEBUG,
  4349. "RRM: Currently handling previous Neighbor Report.");
  4350. return -EBUSY;
  4351. }
  4352. /* 3 = action category + action code + dialog token */
  4353. buf = wpabuf_alloc(3 + (ssid ? 2 + ssid->ssid_len : 0));
  4354. if (buf == NULL) {
  4355. wpa_printf(MSG_DEBUG,
  4356. "RRM: Failed to allocate Neighbor Report Request");
  4357. return -ENOMEM;
  4358. }
  4359. wpa_printf(MSG_DEBUG, "RRM: Neighbor report request (for %s), token=%d",
  4360. (ssid ? wpa_ssid_txt(ssid->ssid, ssid->ssid_len) : ""),
  4361. wpa_s->rrm.next_neighbor_rep_token);
  4362. wpabuf_put_u8(buf, WLAN_ACTION_RADIO_MEASUREMENT);
  4363. wpabuf_put_u8(buf, WLAN_RRM_NEIGHBOR_REPORT_REQUEST);
  4364. wpabuf_put_u8(buf, wpa_s->rrm.next_neighbor_rep_token);
  4365. if (ssid) {
  4366. wpabuf_put_u8(buf, WLAN_EID_SSID);
  4367. wpabuf_put_u8(buf, ssid->ssid_len);
  4368. wpabuf_put_data(buf, ssid->ssid, ssid->ssid_len);
  4369. }
  4370. wpa_s->rrm.next_neighbor_rep_token++;
  4371. if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
  4372. wpa_s->own_addr, wpa_s->bssid,
  4373. wpabuf_head(buf), wpabuf_len(buf), 0) < 0) {
  4374. wpa_printf(MSG_DEBUG,
  4375. "RRM: Failed to send Neighbor Report Request");
  4376. wpabuf_free(buf);
  4377. return -ECANCELED;
  4378. }
  4379. wpa_s->rrm.neighbor_rep_cb_ctx = cb_ctx;
  4380. wpa_s->rrm.notify_neighbor_rep = cb;
  4381. eloop_register_timeout(RRM_NEIGHBOR_REPORT_TIMEOUT, 0,
  4382. wpas_rrm_neighbor_rep_timeout_handler,
  4383. &wpa_s->rrm, NULL);
  4384. wpabuf_free(buf);
  4385. return 0;
  4386. }
  4387. void wpas_rrm_handle_link_measurement_request(struct wpa_supplicant *wpa_s,
  4388. const u8 *src,
  4389. const u8 *frame, size_t len,
  4390. int rssi)
  4391. {
  4392. struct wpabuf *buf;
  4393. const struct rrm_link_measurement_request *req;
  4394. struct rrm_link_measurement_report report;
  4395. if (wpa_s->wpa_state != WPA_COMPLETED) {
  4396. wpa_printf(MSG_INFO,
  4397. "RRM: Ignoring link measurement request. Not associated");
  4398. return;
  4399. }
  4400. if (!wpa_s->rrm.rrm_used) {
  4401. wpa_printf(MSG_INFO,
  4402. "RRM: Ignoring link measurement request. Not RRM network");
  4403. return;
  4404. }
  4405. if (!(wpa_s->drv_rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION)) {
  4406. wpa_printf(MSG_INFO,
  4407. "RRM: Measurement report failed. TX power insertion not supported");
  4408. return;
  4409. }
  4410. req = (const struct rrm_link_measurement_request *) frame;
  4411. if (len < sizeof(*req)) {
  4412. wpa_printf(MSG_INFO,
  4413. "RRM: Link measurement report failed. Request too short");
  4414. return;
  4415. }
  4416. os_memset(&report, 0, sizeof(report));
  4417. report.tpc.eid = WLAN_EID_TPC_REPORT;
  4418. report.tpc.len = 2;
  4419. report.rsni = 255; /* 255 indicates that RSNI is not available */
  4420. report.dialog_token = req->dialog_token;
  4421. /*
  4422. * It's possible to estimate RCPI based on RSSI in dBm. This
  4423. * calculation will not reflect the correct value for high rates,
  4424. * but it's good enough for Action frames which are transmitted
  4425. * with up to 24 Mbps rates.
  4426. */
  4427. if (!rssi)
  4428. report.rcpi = 255; /* not available */
  4429. else if (rssi < -110)
  4430. report.rcpi = 0;
  4431. else if (rssi > 0)
  4432. report.rcpi = 220;
  4433. else
  4434. report.rcpi = (rssi + 110) * 2;
  4435. /* action_category + action_code */
  4436. buf = wpabuf_alloc(2 + sizeof(report));
  4437. if (buf == NULL) {
  4438. wpa_printf(MSG_ERROR,
  4439. "RRM: Link measurement report failed. Buffer allocation failed");
  4440. return;
  4441. }
  4442. wpabuf_put_u8(buf, WLAN_ACTION_RADIO_MEASUREMENT);
  4443. wpabuf_put_u8(buf, WLAN_RRM_LINK_MEASUREMENT_REPORT);
  4444. wpabuf_put_data(buf, &report, sizeof(report));
  4445. wpa_hexdump(MSG_DEBUG, "RRM: Link measurement report:",
  4446. wpabuf_head(buf), wpabuf_len(buf));
  4447. if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, src,
  4448. wpa_s->own_addr, wpa_s->bssid,
  4449. wpabuf_head(buf), wpabuf_len(buf), 0)) {
  4450. wpa_printf(MSG_ERROR,
  4451. "RRM: Link measurement report failed. Send action failed");
  4452. }
  4453. wpabuf_free(buf);
  4454. }