wpa_supplicant.c 116 KB

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