ctrl_iface.c 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583
  1. /*
  2. * WPA Supplicant / Control interface (shared code for all backends)
  3. * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "utils/eloop.h"
  11. #include "common/version.h"
  12. #include "common/ieee802_11_defs.h"
  13. #include "common/wpa_ctrl.h"
  14. #include "eap_peer/eap.h"
  15. #include "eapol_supp/eapol_supp_sm.h"
  16. #include "rsn_supp/wpa.h"
  17. #include "rsn_supp/preauth.h"
  18. #include "rsn_supp/pmksa_cache.h"
  19. #include "l2_packet/l2_packet.h"
  20. #include "wps/wps.h"
  21. #include "config.h"
  22. #include "wpa_supplicant_i.h"
  23. #include "driver_i.h"
  24. #include "wps_supplicant.h"
  25. #include "ibss_rsn.h"
  26. #include "ap.h"
  27. #include "p2p_supplicant.h"
  28. #include "p2p/p2p.h"
  29. #include "hs20_supplicant.h"
  30. #include "notify.h"
  31. #include "bss.h"
  32. #include "scan.h"
  33. #include "ctrl_iface.h"
  34. #include "interworking.h"
  35. #include "blacklist.h"
  36. #include "wpas_glue.h"
  37. extern struct wpa_driver_ops *wpa_drivers[];
  38. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  39. char *buf, int len);
  40. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  41. char *buf, int len);
  42. static int pno_start(struct wpa_supplicant *wpa_s)
  43. {
  44. int ret;
  45. size_t i, num_ssid;
  46. struct wpa_ssid *ssid;
  47. struct wpa_driver_scan_params params;
  48. if (wpa_s->pno)
  49. return 0;
  50. os_memset(&params, 0, sizeof(params));
  51. num_ssid = 0;
  52. ssid = wpa_s->conf->ssid;
  53. while (ssid) {
  54. if (!wpas_network_disabled(wpa_s, ssid))
  55. num_ssid++;
  56. ssid = ssid->next;
  57. }
  58. if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
  59. wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
  60. "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
  61. num_ssid = WPAS_MAX_SCAN_SSIDS;
  62. }
  63. if (num_ssid == 0) {
  64. wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
  65. return -1;
  66. }
  67. params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
  68. num_ssid);
  69. if (params.filter_ssids == NULL)
  70. return -1;
  71. i = 0;
  72. ssid = wpa_s->conf->ssid;
  73. while (ssid) {
  74. if (!wpas_network_disabled(wpa_s, ssid)) {
  75. params.ssids[i].ssid = ssid->ssid;
  76. params.ssids[i].ssid_len = ssid->ssid_len;
  77. params.num_ssids++;
  78. os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
  79. ssid->ssid_len);
  80. params.filter_ssids[i].ssid_len = ssid->ssid_len;
  81. params.num_filter_ssids++;
  82. i++;
  83. if (i == num_ssid)
  84. break;
  85. }
  86. ssid = ssid->next;
  87. }
  88. ret = wpa_drv_sched_scan(wpa_s, &params, 10 * 1000);
  89. os_free(params.filter_ssids);
  90. if (ret == 0)
  91. wpa_s->pno = 1;
  92. return ret;
  93. }
  94. static int pno_stop(struct wpa_supplicant *wpa_s)
  95. {
  96. if (wpa_s->pno) {
  97. wpa_s->pno = 0;
  98. return wpa_drv_stop_sched_scan(wpa_s);
  99. }
  100. return 0;
  101. }
  102. static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
  103. {
  104. char *pos;
  105. u8 addr[ETH_ALEN], *filter = NULL, *n;
  106. size_t count = 0;
  107. pos = val;
  108. while (pos) {
  109. if (*pos == '\0')
  110. break;
  111. if (hwaddr_aton(pos, addr)) {
  112. os_free(filter);
  113. return -1;
  114. }
  115. n = os_realloc(filter, (count + 1) * ETH_ALEN);
  116. if (n == NULL) {
  117. os_free(filter);
  118. return -1;
  119. }
  120. filter = n;
  121. os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
  122. count++;
  123. pos = os_strchr(pos, ' ');
  124. if (pos)
  125. pos++;
  126. }
  127. wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
  128. os_free(wpa_s->bssid_filter);
  129. wpa_s->bssid_filter = filter;
  130. wpa_s->bssid_filter_count = count;
  131. return 0;
  132. }
  133. static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
  134. char *cmd)
  135. {
  136. char *value;
  137. int ret = 0;
  138. value = os_strchr(cmd, ' ');
  139. if (value == NULL)
  140. return -1;
  141. *value++ = '\0';
  142. wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
  143. if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
  144. eapol_sm_configure(wpa_s->eapol,
  145. atoi(value), -1, -1, -1);
  146. } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
  147. eapol_sm_configure(wpa_s->eapol,
  148. -1, atoi(value), -1, -1);
  149. } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
  150. eapol_sm_configure(wpa_s->eapol,
  151. -1, -1, atoi(value), -1);
  152. } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
  153. eapol_sm_configure(wpa_s->eapol,
  154. -1, -1, -1, atoi(value));
  155. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
  156. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
  157. atoi(value)))
  158. ret = -1;
  159. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
  160. 0) {
  161. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
  162. atoi(value)))
  163. ret = -1;
  164. } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
  165. if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
  166. ret = -1;
  167. } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
  168. wpa_s->wps_fragment_size = atoi(value);
  169. #ifdef CONFIG_WPS_TESTING
  170. } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
  171. long int val;
  172. val = strtol(value, NULL, 0);
  173. if (val < 0 || val > 0xff) {
  174. ret = -1;
  175. wpa_printf(MSG_DEBUG, "WPS: Invalid "
  176. "wps_version_number %ld", val);
  177. } else {
  178. wps_version_number = val;
  179. wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
  180. "version %u.%u",
  181. (wps_version_number & 0xf0) >> 4,
  182. wps_version_number & 0x0f);
  183. }
  184. } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
  185. wps_testing_dummy_cred = atoi(value);
  186. wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
  187. wps_testing_dummy_cred);
  188. #endif /* CONFIG_WPS_TESTING */
  189. } else if (os_strcasecmp(cmd, "ampdu") == 0) {
  190. if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
  191. ret = -1;
  192. #ifdef CONFIG_TDLS_TESTING
  193. } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
  194. extern unsigned int tdls_testing;
  195. tdls_testing = strtol(value, NULL, 0);
  196. wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
  197. #endif /* CONFIG_TDLS_TESTING */
  198. #ifdef CONFIG_TDLS
  199. } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
  200. int disabled = atoi(value);
  201. wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
  202. if (disabled) {
  203. if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
  204. ret = -1;
  205. } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
  206. ret = -1;
  207. wpa_tdls_enable(wpa_s->wpa, !disabled);
  208. #endif /* CONFIG_TDLS */
  209. } else if (os_strcasecmp(cmd, "pno") == 0) {
  210. if (atoi(value))
  211. ret = pno_start(wpa_s);
  212. else
  213. ret = pno_stop(wpa_s);
  214. } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
  215. int disabled = atoi(value);
  216. if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
  217. ret = -1;
  218. else if (disabled)
  219. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  220. } else if (os_strcasecmp(cmd, "uapsd") == 0) {
  221. if (os_strcmp(value, "disable") == 0)
  222. wpa_s->set_sta_uapsd = 0;
  223. else {
  224. int be, bk, vi, vo;
  225. char *pos;
  226. /* format: BE,BK,VI,VO;max SP Length */
  227. be = atoi(value);
  228. pos = os_strchr(value, ',');
  229. if (pos == NULL)
  230. return -1;
  231. pos++;
  232. bk = atoi(pos);
  233. pos = os_strchr(pos, ',');
  234. if (pos == NULL)
  235. return -1;
  236. pos++;
  237. vi = atoi(pos);
  238. pos = os_strchr(pos, ',');
  239. if (pos == NULL)
  240. return -1;
  241. pos++;
  242. vo = atoi(pos);
  243. /* ignore max SP Length for now */
  244. wpa_s->set_sta_uapsd = 1;
  245. wpa_s->sta_uapsd = 0;
  246. if (be)
  247. wpa_s->sta_uapsd |= BIT(0);
  248. if (bk)
  249. wpa_s->sta_uapsd |= BIT(1);
  250. if (vi)
  251. wpa_s->sta_uapsd |= BIT(2);
  252. if (vo)
  253. wpa_s->sta_uapsd |= BIT(3);
  254. }
  255. } else if (os_strcasecmp(cmd, "ps") == 0) {
  256. ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
  257. } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
  258. ret = set_bssid_filter(wpa_s, value);
  259. } else {
  260. value[-1] = '=';
  261. ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
  262. if (ret == 0)
  263. wpa_supplicant_update_config(wpa_s);
  264. }
  265. return ret;
  266. }
  267. static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
  268. char *cmd, char *buf, size_t buflen)
  269. {
  270. int res = -1;
  271. wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
  272. if (os_strcmp(cmd, "version") == 0) {
  273. res = os_snprintf(buf, buflen, "%s", VERSION_STR);
  274. } else if (os_strcasecmp(cmd, "country") == 0) {
  275. if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
  276. res = os_snprintf(buf, buflen, "%c%c",
  277. wpa_s->conf->country[0],
  278. wpa_s->conf->country[1]);
  279. }
  280. if (res < 0 || (unsigned int) res >= buflen)
  281. return -1;
  282. return res;
  283. }
  284. #ifdef IEEE8021X_EAPOL
  285. static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
  286. char *addr)
  287. {
  288. u8 bssid[ETH_ALEN];
  289. struct wpa_ssid *ssid = wpa_s->current_ssid;
  290. if (hwaddr_aton(addr, bssid)) {
  291. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
  292. "'%s'", addr);
  293. return -1;
  294. }
  295. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
  296. rsn_preauth_deinit(wpa_s->wpa);
  297. if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
  298. return -1;
  299. return 0;
  300. }
  301. #endif /* IEEE8021X_EAPOL */
  302. #ifdef CONFIG_PEERKEY
  303. /* MLME-STKSTART.request(peer) */
  304. static int wpa_supplicant_ctrl_iface_stkstart(
  305. struct wpa_supplicant *wpa_s, char *addr)
  306. {
  307. u8 peer[ETH_ALEN];
  308. if (hwaddr_aton(addr, peer)) {
  309. wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
  310. "address '%s'", addr);
  311. return -1;
  312. }
  313. wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
  314. MAC2STR(peer));
  315. return wpa_sm_stkstart(wpa_s->wpa, peer);
  316. }
  317. #endif /* CONFIG_PEERKEY */
  318. #ifdef CONFIG_TDLS
  319. static int wpa_supplicant_ctrl_iface_tdls_discover(
  320. struct wpa_supplicant *wpa_s, char *addr)
  321. {
  322. u8 peer[ETH_ALEN];
  323. int ret;
  324. if (hwaddr_aton(addr, peer)) {
  325. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
  326. "address '%s'", addr);
  327. return -1;
  328. }
  329. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
  330. MAC2STR(peer));
  331. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  332. ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
  333. else
  334. ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
  335. return ret;
  336. }
  337. static int wpa_supplicant_ctrl_iface_tdls_setup(
  338. struct wpa_supplicant *wpa_s, char *addr)
  339. {
  340. u8 peer[ETH_ALEN];
  341. int ret;
  342. if (hwaddr_aton(addr, peer)) {
  343. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
  344. "address '%s'", addr);
  345. return -1;
  346. }
  347. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
  348. MAC2STR(peer));
  349. ret = wpa_tdls_reneg(wpa_s->wpa, peer);
  350. if (ret) {
  351. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  352. ret = wpa_tdls_start(wpa_s->wpa, peer);
  353. else
  354. ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
  355. }
  356. return ret;
  357. }
  358. static int wpa_supplicant_ctrl_iface_tdls_teardown(
  359. struct wpa_supplicant *wpa_s, char *addr)
  360. {
  361. u8 peer[ETH_ALEN];
  362. if (hwaddr_aton(addr, peer)) {
  363. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
  364. "address '%s'", addr);
  365. return -1;
  366. }
  367. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
  368. MAC2STR(peer));
  369. return wpa_tdls_teardown_link(wpa_s->wpa, peer,
  370. WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
  371. }
  372. #endif /* CONFIG_TDLS */
  373. #ifdef CONFIG_IEEE80211R
  374. static int wpa_supplicant_ctrl_iface_ft_ds(
  375. struct wpa_supplicant *wpa_s, char *addr)
  376. {
  377. u8 target_ap[ETH_ALEN];
  378. struct wpa_bss *bss;
  379. const u8 *mdie;
  380. if (hwaddr_aton(addr, target_ap)) {
  381. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
  382. "address '%s'", addr);
  383. return -1;
  384. }
  385. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
  386. bss = wpa_bss_get_bssid(wpa_s, target_ap);
  387. if (bss)
  388. mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
  389. else
  390. mdie = NULL;
  391. return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
  392. }
  393. #endif /* CONFIG_IEEE80211R */
  394. #ifdef CONFIG_WPS
  395. static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
  396. char *cmd)
  397. {
  398. u8 bssid[ETH_ALEN], *_bssid = bssid;
  399. #ifdef CONFIG_P2P
  400. u8 p2p_dev_addr[ETH_ALEN];
  401. #endif /* CONFIG_P2P */
  402. #ifdef CONFIG_AP
  403. u8 *_p2p_dev_addr = NULL;
  404. #endif /* CONFIG_AP */
  405. if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
  406. _bssid = NULL;
  407. #ifdef CONFIG_P2P
  408. } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
  409. if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
  410. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
  411. "P2P Device Address '%s'",
  412. cmd + 13);
  413. return -1;
  414. }
  415. _p2p_dev_addr = p2p_dev_addr;
  416. #endif /* CONFIG_P2P */
  417. } else if (hwaddr_aton(cmd, bssid)) {
  418. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
  419. cmd);
  420. return -1;
  421. }
  422. #ifdef CONFIG_AP
  423. if (wpa_s->ap_iface)
  424. return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
  425. #endif /* CONFIG_AP */
  426. return wpas_wps_start_pbc(wpa_s, _bssid, 0);
  427. }
  428. static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
  429. char *cmd, char *buf,
  430. size_t buflen)
  431. {
  432. u8 bssid[ETH_ALEN], *_bssid = bssid;
  433. char *pin;
  434. int ret;
  435. pin = os_strchr(cmd, ' ');
  436. if (pin)
  437. *pin++ = '\0';
  438. if (os_strcmp(cmd, "any") == 0)
  439. _bssid = NULL;
  440. else if (os_strcmp(cmd, "get") == 0) {
  441. ret = wps_generate_pin();
  442. goto done;
  443. } else if (hwaddr_aton(cmd, bssid)) {
  444. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
  445. cmd);
  446. return -1;
  447. }
  448. #ifdef CONFIG_AP
  449. if (wpa_s->ap_iface)
  450. return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
  451. buf, buflen);
  452. #endif /* CONFIG_AP */
  453. if (pin) {
  454. ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
  455. DEV_PW_DEFAULT);
  456. if (ret < 0)
  457. return -1;
  458. ret = os_snprintf(buf, buflen, "%s", pin);
  459. if (ret < 0 || (size_t) ret >= buflen)
  460. return -1;
  461. return ret;
  462. }
  463. ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
  464. if (ret < 0)
  465. return -1;
  466. done:
  467. /* Return the generated PIN */
  468. ret = os_snprintf(buf, buflen, "%08d", ret);
  469. if (ret < 0 || (size_t) ret >= buflen)
  470. return -1;
  471. return ret;
  472. }
  473. static int wpa_supplicant_ctrl_iface_wps_check_pin(
  474. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  475. {
  476. char pin[9];
  477. size_t len;
  478. char *pos;
  479. int ret;
  480. wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
  481. (u8 *) cmd, os_strlen(cmd));
  482. for (pos = cmd, len = 0; *pos != '\0'; pos++) {
  483. if (*pos < '0' || *pos > '9')
  484. continue;
  485. pin[len++] = *pos;
  486. if (len == 9) {
  487. wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
  488. return -1;
  489. }
  490. }
  491. if (len != 4 && len != 8) {
  492. wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
  493. return -1;
  494. }
  495. pin[len] = '\0';
  496. if (len == 8) {
  497. unsigned int pin_val;
  498. pin_val = atoi(pin);
  499. if (!wps_pin_valid(pin_val)) {
  500. wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
  501. ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
  502. if (ret < 0 || (size_t) ret >= buflen)
  503. return -1;
  504. return ret;
  505. }
  506. }
  507. ret = os_snprintf(buf, buflen, "%s", pin);
  508. if (ret < 0 || (size_t) ret >= buflen)
  509. return -1;
  510. return ret;
  511. }
  512. #ifdef CONFIG_WPS_OOB
  513. static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s,
  514. char *cmd)
  515. {
  516. char *path, *method, *name;
  517. path = os_strchr(cmd, ' ');
  518. if (path == NULL)
  519. return -1;
  520. *path++ = '\0';
  521. method = os_strchr(path, ' ');
  522. if (method == NULL)
  523. return -1;
  524. *method++ = '\0';
  525. name = os_strchr(method, ' ');
  526. if (name != NULL)
  527. *name++ = '\0';
  528. return wpas_wps_start_oob(wpa_s, cmd, path, method, name);
  529. }
  530. #endif /* CONFIG_WPS_OOB */
  531. static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
  532. char *cmd)
  533. {
  534. u8 bssid[ETH_ALEN];
  535. char *pin;
  536. char *new_ssid;
  537. char *new_auth;
  538. char *new_encr;
  539. char *new_key;
  540. struct wps_new_ap_settings ap;
  541. pin = os_strchr(cmd, ' ');
  542. if (pin == NULL)
  543. return -1;
  544. *pin++ = '\0';
  545. if (hwaddr_aton(cmd, bssid)) {
  546. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
  547. cmd);
  548. return -1;
  549. }
  550. new_ssid = os_strchr(pin, ' ');
  551. if (new_ssid == NULL)
  552. return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
  553. *new_ssid++ = '\0';
  554. new_auth = os_strchr(new_ssid, ' ');
  555. if (new_auth == NULL)
  556. return -1;
  557. *new_auth++ = '\0';
  558. new_encr = os_strchr(new_auth, ' ');
  559. if (new_encr == NULL)
  560. return -1;
  561. *new_encr++ = '\0';
  562. new_key = os_strchr(new_encr, ' ');
  563. if (new_key == NULL)
  564. return -1;
  565. *new_key++ = '\0';
  566. os_memset(&ap, 0, sizeof(ap));
  567. ap.ssid_hex = new_ssid;
  568. ap.auth = new_auth;
  569. ap.encr = new_encr;
  570. ap.key_hex = new_key;
  571. return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
  572. }
  573. #ifdef CONFIG_AP
  574. static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
  575. char *cmd, char *buf,
  576. size_t buflen)
  577. {
  578. int timeout = 300;
  579. char *pos;
  580. const char *pin_txt;
  581. if (!wpa_s->ap_iface)
  582. return -1;
  583. pos = os_strchr(cmd, ' ');
  584. if (pos)
  585. *pos++ = '\0';
  586. if (os_strcmp(cmd, "disable") == 0) {
  587. wpas_wps_ap_pin_disable(wpa_s);
  588. return os_snprintf(buf, buflen, "OK\n");
  589. }
  590. if (os_strcmp(cmd, "random") == 0) {
  591. if (pos)
  592. timeout = atoi(pos);
  593. pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
  594. if (pin_txt == NULL)
  595. return -1;
  596. return os_snprintf(buf, buflen, "%s", pin_txt);
  597. }
  598. if (os_strcmp(cmd, "get") == 0) {
  599. pin_txt = wpas_wps_ap_pin_get(wpa_s);
  600. if (pin_txt == NULL)
  601. return -1;
  602. return os_snprintf(buf, buflen, "%s", pin_txt);
  603. }
  604. if (os_strcmp(cmd, "set") == 0) {
  605. char *pin;
  606. if (pos == NULL)
  607. return -1;
  608. pin = pos;
  609. pos = os_strchr(pos, ' ');
  610. if (pos) {
  611. *pos++ = '\0';
  612. timeout = atoi(pos);
  613. }
  614. if (os_strlen(pin) > buflen)
  615. return -1;
  616. if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
  617. return -1;
  618. return os_snprintf(buf, buflen, "%s", pin);
  619. }
  620. return -1;
  621. }
  622. #endif /* CONFIG_AP */
  623. #ifdef CONFIG_WPS_ER
  624. static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
  625. char *cmd)
  626. {
  627. char *uuid = cmd, *pin, *pos;
  628. u8 addr_buf[ETH_ALEN], *addr = NULL;
  629. pin = os_strchr(uuid, ' ');
  630. if (pin == NULL)
  631. return -1;
  632. *pin++ = '\0';
  633. pos = os_strchr(pin, ' ');
  634. if (pos) {
  635. *pos++ = '\0';
  636. if (hwaddr_aton(pos, addr_buf) == 0)
  637. addr = addr_buf;
  638. }
  639. return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
  640. }
  641. static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
  642. char *cmd)
  643. {
  644. char *uuid = cmd, *pin;
  645. pin = os_strchr(uuid, ' ');
  646. if (pin == NULL)
  647. return -1;
  648. *pin++ = '\0';
  649. return wpas_wps_er_learn(wpa_s, uuid, pin);
  650. }
  651. static int wpa_supplicant_ctrl_iface_wps_er_set_config(
  652. struct wpa_supplicant *wpa_s, char *cmd)
  653. {
  654. char *uuid = cmd, *id;
  655. id = os_strchr(uuid, ' ');
  656. if (id == NULL)
  657. return -1;
  658. *id++ = '\0';
  659. return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
  660. }
  661. static int wpa_supplicant_ctrl_iface_wps_er_config(
  662. struct wpa_supplicant *wpa_s, char *cmd)
  663. {
  664. char *pin;
  665. char *new_ssid;
  666. char *new_auth;
  667. char *new_encr;
  668. char *new_key;
  669. struct wps_new_ap_settings ap;
  670. pin = os_strchr(cmd, ' ');
  671. if (pin == NULL)
  672. return -1;
  673. *pin++ = '\0';
  674. new_ssid = os_strchr(pin, ' ');
  675. if (new_ssid == NULL)
  676. return -1;
  677. *new_ssid++ = '\0';
  678. new_auth = os_strchr(new_ssid, ' ');
  679. if (new_auth == NULL)
  680. return -1;
  681. *new_auth++ = '\0';
  682. new_encr = os_strchr(new_auth, ' ');
  683. if (new_encr == NULL)
  684. return -1;
  685. *new_encr++ = '\0';
  686. new_key = os_strchr(new_encr, ' ');
  687. if (new_key == NULL)
  688. return -1;
  689. *new_key++ = '\0';
  690. os_memset(&ap, 0, sizeof(ap));
  691. ap.ssid_hex = new_ssid;
  692. ap.auth = new_auth;
  693. ap.encr = new_encr;
  694. ap.key_hex = new_key;
  695. return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
  696. }
  697. #endif /* CONFIG_WPS_ER */
  698. #endif /* CONFIG_WPS */
  699. #ifdef CONFIG_IBSS_RSN
  700. static int wpa_supplicant_ctrl_iface_ibss_rsn(
  701. struct wpa_supplicant *wpa_s, char *addr)
  702. {
  703. u8 peer[ETH_ALEN];
  704. if (hwaddr_aton(addr, peer)) {
  705. wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
  706. "address '%s'", addr);
  707. return -1;
  708. }
  709. wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
  710. MAC2STR(peer));
  711. return ibss_rsn_start(wpa_s->ibss_rsn, peer);
  712. }
  713. #endif /* CONFIG_IBSS_RSN */
  714. static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
  715. char *rsp)
  716. {
  717. #ifdef IEEE8021X_EAPOL
  718. char *pos, *id_pos;
  719. int id;
  720. struct wpa_ssid *ssid;
  721. pos = os_strchr(rsp, '-');
  722. if (pos == NULL)
  723. return -1;
  724. *pos++ = '\0';
  725. id_pos = pos;
  726. pos = os_strchr(pos, ':');
  727. if (pos == NULL)
  728. return -1;
  729. *pos++ = '\0';
  730. id = atoi(id_pos);
  731. wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
  732. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  733. (u8 *) pos, os_strlen(pos));
  734. ssid = wpa_config_get_network(wpa_s->conf, id);
  735. if (ssid == NULL) {
  736. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  737. "to update", id);
  738. return -1;
  739. }
  740. return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
  741. pos);
  742. #else /* IEEE8021X_EAPOL */
  743. wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
  744. return -1;
  745. #endif /* IEEE8021X_EAPOL */
  746. }
  747. static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
  748. const char *params,
  749. char *buf, size_t buflen)
  750. {
  751. char *pos, *end, tmp[30];
  752. int res, verbose, wps, ret;
  753. verbose = os_strcmp(params, "-VERBOSE") == 0;
  754. wps = os_strcmp(params, "-WPS") == 0;
  755. pos = buf;
  756. end = buf + buflen;
  757. if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
  758. struct wpa_ssid *ssid = wpa_s->current_ssid;
  759. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
  760. MAC2STR(wpa_s->bssid));
  761. if (ret < 0 || ret >= end - pos)
  762. return pos - buf;
  763. pos += ret;
  764. if (ssid) {
  765. u8 *_ssid = ssid->ssid;
  766. size_t ssid_len = ssid->ssid_len;
  767. u8 ssid_buf[MAX_SSID_LEN];
  768. if (ssid_len == 0) {
  769. int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
  770. if (_res < 0)
  771. ssid_len = 0;
  772. else
  773. ssid_len = _res;
  774. _ssid = ssid_buf;
  775. }
  776. ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
  777. wpa_ssid_txt(_ssid, ssid_len),
  778. ssid->id);
  779. if (ret < 0 || ret >= end - pos)
  780. return pos - buf;
  781. pos += ret;
  782. if (wps && ssid->passphrase &&
  783. wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
  784. (ssid->mode == WPAS_MODE_AP ||
  785. ssid->mode == WPAS_MODE_P2P_GO)) {
  786. ret = os_snprintf(pos, end - pos,
  787. "passphrase=%s\n",
  788. ssid->passphrase);
  789. if (ret < 0 || ret >= end - pos)
  790. return pos - buf;
  791. pos += ret;
  792. }
  793. if (ssid->id_str) {
  794. ret = os_snprintf(pos, end - pos,
  795. "id_str=%s\n",
  796. ssid->id_str);
  797. if (ret < 0 || ret >= end - pos)
  798. return pos - buf;
  799. pos += ret;
  800. }
  801. switch (ssid->mode) {
  802. case WPAS_MODE_INFRA:
  803. ret = os_snprintf(pos, end - pos,
  804. "mode=station\n");
  805. break;
  806. case WPAS_MODE_IBSS:
  807. ret = os_snprintf(pos, end - pos,
  808. "mode=IBSS\n");
  809. break;
  810. case WPAS_MODE_AP:
  811. ret = os_snprintf(pos, end - pos,
  812. "mode=AP\n");
  813. break;
  814. case WPAS_MODE_P2P_GO:
  815. ret = os_snprintf(pos, end - pos,
  816. "mode=P2P GO\n");
  817. break;
  818. case WPAS_MODE_P2P_GROUP_FORMATION:
  819. ret = os_snprintf(pos, end - pos,
  820. "mode=P2P GO - group "
  821. "formation\n");
  822. break;
  823. default:
  824. ret = 0;
  825. break;
  826. }
  827. if (ret < 0 || ret >= end - pos)
  828. return pos - buf;
  829. pos += ret;
  830. }
  831. #ifdef CONFIG_AP
  832. if (wpa_s->ap_iface) {
  833. pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
  834. end - pos,
  835. verbose);
  836. } else
  837. #endif /* CONFIG_AP */
  838. pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
  839. }
  840. ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
  841. wpa_supplicant_state_txt(wpa_s->wpa_state));
  842. if (ret < 0 || ret >= end - pos)
  843. return pos - buf;
  844. pos += ret;
  845. if (wpa_s->l2 &&
  846. l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
  847. ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
  848. if (ret < 0 || ret >= end - pos)
  849. return pos - buf;
  850. pos += ret;
  851. }
  852. #ifdef CONFIG_P2P
  853. if (wpa_s->global->p2p) {
  854. ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
  855. "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
  856. if (ret < 0 || ret >= end - pos)
  857. return pos - buf;
  858. pos += ret;
  859. }
  860. #endif /* CONFIG_P2P */
  861. ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
  862. MAC2STR(wpa_s->own_addr));
  863. if (ret < 0 || ret >= end - pos)
  864. return pos - buf;
  865. pos += ret;
  866. #ifdef CONFIG_HS20
  867. if (wpa_s->current_bss &&
  868. wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE)) {
  869. ret = os_snprintf(pos, end - pos, "hs20=1\n");
  870. if (ret < 0 || ret >= end - pos)
  871. return pos - buf;
  872. pos += ret;
  873. }
  874. #endif /* CONFIG_HS20 */
  875. if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  876. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  877. res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
  878. verbose);
  879. if (res >= 0)
  880. pos += res;
  881. }
  882. res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
  883. if (res >= 0)
  884. pos += res;
  885. return pos - buf;
  886. }
  887. static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
  888. char *cmd)
  889. {
  890. char *pos;
  891. int id;
  892. struct wpa_ssid *ssid;
  893. u8 bssid[ETH_ALEN];
  894. /* cmd: "<network id> <BSSID>" */
  895. pos = os_strchr(cmd, ' ');
  896. if (pos == NULL)
  897. return -1;
  898. *pos++ = '\0';
  899. id = atoi(cmd);
  900. wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
  901. if (hwaddr_aton(pos, bssid)) {
  902. wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
  903. return -1;
  904. }
  905. ssid = wpa_config_get_network(wpa_s->conf, id);
  906. if (ssid == NULL) {
  907. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  908. "to update", id);
  909. return -1;
  910. }
  911. os_memcpy(ssid->bssid, bssid, ETH_ALEN);
  912. ssid->bssid_set = !is_zero_ether_addr(bssid);
  913. return 0;
  914. }
  915. static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
  916. char *cmd, char *buf,
  917. size_t buflen)
  918. {
  919. u8 bssid[ETH_ALEN];
  920. struct wpa_blacklist *e;
  921. char *pos, *end;
  922. int ret;
  923. /* cmd: "BLACKLIST [<BSSID>]" */
  924. if (*cmd == '\0') {
  925. pos = buf;
  926. end = buf + buflen;
  927. e = wpa_s->blacklist;
  928. while (e) {
  929. ret = os_snprintf(pos, end - pos, MACSTR "\n",
  930. MAC2STR(e->bssid));
  931. if (ret < 0 || ret >= end - pos)
  932. return pos - buf;
  933. pos += ret;
  934. e = e->next;
  935. }
  936. return pos - buf;
  937. }
  938. cmd++;
  939. if (os_strncmp(cmd, "clear", 5) == 0) {
  940. wpa_blacklist_clear(wpa_s);
  941. os_memcpy(buf, "OK\n", 3);
  942. return 3;
  943. }
  944. wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
  945. if (hwaddr_aton(cmd, bssid)) {
  946. wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
  947. return -1;
  948. }
  949. /*
  950. * Add the BSSID twice, so its count will be 2, causing it to be
  951. * skipped when processing scan results.
  952. */
  953. ret = wpa_blacklist_add(wpa_s, bssid);
  954. if (ret != 0)
  955. return -1;
  956. ret = wpa_blacklist_add(wpa_s, bssid);
  957. if (ret != 0)
  958. return -1;
  959. os_memcpy(buf, "OK\n", 3);
  960. return 3;
  961. }
  962. extern int wpa_debug_level;
  963. extern int wpa_debug_timestamp;
  964. static const char * debug_level_str(int level)
  965. {
  966. switch (level) {
  967. case MSG_EXCESSIVE:
  968. return "EXCESSIVE";
  969. case MSG_MSGDUMP:
  970. return "MSGDUMP";
  971. case MSG_DEBUG:
  972. return "DEBUG";
  973. case MSG_INFO:
  974. return "INFO";
  975. case MSG_WARNING:
  976. return "WARNING";
  977. case MSG_ERROR:
  978. return "ERROR";
  979. default:
  980. return "?";
  981. }
  982. }
  983. static int str_to_debug_level(const char *s)
  984. {
  985. if (os_strcasecmp(s, "EXCESSIVE") == 0)
  986. return MSG_EXCESSIVE;
  987. if (os_strcasecmp(s, "MSGDUMP") == 0)
  988. return MSG_MSGDUMP;
  989. if (os_strcasecmp(s, "DEBUG") == 0)
  990. return MSG_DEBUG;
  991. if (os_strcasecmp(s, "INFO") == 0)
  992. return MSG_INFO;
  993. if (os_strcasecmp(s, "WARNING") == 0)
  994. return MSG_WARNING;
  995. if (os_strcasecmp(s, "ERROR") == 0)
  996. return MSG_ERROR;
  997. return -1;
  998. }
  999. static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
  1000. char *cmd, char *buf,
  1001. size_t buflen)
  1002. {
  1003. char *pos, *end, *stamp;
  1004. int ret;
  1005. if (cmd == NULL) {
  1006. return -1;
  1007. }
  1008. /* cmd: "LOG_LEVEL [<level>]" */
  1009. if (*cmd == '\0') {
  1010. pos = buf;
  1011. end = buf + buflen;
  1012. ret = os_snprintf(pos, end - pos, "Current level: %s\n"
  1013. "Timestamp: %d\n",
  1014. debug_level_str(wpa_debug_level),
  1015. wpa_debug_timestamp);
  1016. if (ret < 0 || ret >= end - pos)
  1017. ret = 0;
  1018. return ret;
  1019. }
  1020. while (*cmd == ' ')
  1021. cmd++;
  1022. stamp = os_strchr(cmd, ' ');
  1023. if (stamp) {
  1024. *stamp++ = '\0';
  1025. while (*stamp == ' ') {
  1026. stamp++;
  1027. }
  1028. }
  1029. if (cmd && os_strlen(cmd)) {
  1030. int level = str_to_debug_level(cmd);
  1031. if (level < 0)
  1032. return -1;
  1033. wpa_debug_level = level;
  1034. }
  1035. if (stamp && os_strlen(stamp))
  1036. wpa_debug_timestamp = atoi(stamp);
  1037. os_memcpy(buf, "OK\n", 3);
  1038. return 3;
  1039. }
  1040. static int wpa_supplicant_ctrl_iface_list_networks(
  1041. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  1042. {
  1043. char *pos, *end;
  1044. struct wpa_ssid *ssid;
  1045. int ret;
  1046. pos = buf;
  1047. end = buf + buflen;
  1048. ret = os_snprintf(pos, end - pos,
  1049. "network id / ssid / bssid / flags\n");
  1050. if (ret < 0 || ret >= end - pos)
  1051. return pos - buf;
  1052. pos += ret;
  1053. ssid = wpa_s->conf->ssid;
  1054. while (ssid) {
  1055. ret = os_snprintf(pos, end - pos, "%d\t%s",
  1056. ssid->id,
  1057. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  1058. if (ret < 0 || ret >= end - pos)
  1059. return pos - buf;
  1060. pos += ret;
  1061. if (ssid->bssid_set) {
  1062. ret = os_snprintf(pos, end - pos, "\t" MACSTR,
  1063. MAC2STR(ssid->bssid));
  1064. } else {
  1065. ret = os_snprintf(pos, end - pos, "\tany");
  1066. }
  1067. if (ret < 0 || ret >= end - pos)
  1068. return pos - buf;
  1069. pos += ret;
  1070. ret = os_snprintf(pos, end - pos, "\t%s%s%s",
  1071. ssid == wpa_s->current_ssid ?
  1072. "[CURRENT]" : "",
  1073. ssid->disabled ? "[DISABLED]" : "",
  1074. ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
  1075. "");
  1076. if (ret < 0 || ret >= end - pos)
  1077. return pos - buf;
  1078. pos += ret;
  1079. ret = os_snprintf(pos, end - pos, "\n");
  1080. if (ret < 0 || ret >= end - pos)
  1081. return pos - buf;
  1082. pos += ret;
  1083. ssid = ssid->next;
  1084. }
  1085. return pos - buf;
  1086. }
  1087. static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
  1088. {
  1089. int first = 1, ret;
  1090. ret = os_snprintf(pos, end - pos, "-");
  1091. if (ret < 0 || ret >= end - pos)
  1092. return pos;
  1093. pos += ret;
  1094. if (cipher & WPA_CIPHER_NONE) {
  1095. ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
  1096. if (ret < 0 || ret >= end - pos)
  1097. return pos;
  1098. pos += ret;
  1099. first = 0;
  1100. }
  1101. if (cipher & WPA_CIPHER_WEP40) {
  1102. ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
  1103. if (ret < 0 || ret >= end - pos)
  1104. return pos;
  1105. pos += ret;
  1106. first = 0;
  1107. }
  1108. if (cipher & WPA_CIPHER_WEP104) {
  1109. ret = os_snprintf(pos, end - pos, "%sWEP104",
  1110. first ? "" : "+");
  1111. if (ret < 0 || ret >= end - pos)
  1112. return pos;
  1113. pos += ret;
  1114. first = 0;
  1115. }
  1116. if (cipher & WPA_CIPHER_TKIP) {
  1117. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
  1118. if (ret < 0 || ret >= end - pos)
  1119. return pos;
  1120. pos += ret;
  1121. first = 0;
  1122. }
  1123. if (cipher & WPA_CIPHER_CCMP) {
  1124. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
  1125. if (ret < 0 || ret >= end - pos)
  1126. return pos;
  1127. pos += ret;
  1128. first = 0;
  1129. }
  1130. return pos;
  1131. }
  1132. static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
  1133. const u8 *ie, size_t ie_len)
  1134. {
  1135. struct wpa_ie_data data;
  1136. int first, ret;
  1137. ret = os_snprintf(pos, end - pos, "[%s-", proto);
  1138. if (ret < 0 || ret >= end - pos)
  1139. return pos;
  1140. pos += ret;
  1141. if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
  1142. ret = os_snprintf(pos, end - pos, "?]");
  1143. if (ret < 0 || ret >= end - pos)
  1144. return pos;
  1145. pos += ret;
  1146. return pos;
  1147. }
  1148. first = 1;
  1149. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  1150. ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
  1151. if (ret < 0 || ret >= end - pos)
  1152. return pos;
  1153. pos += ret;
  1154. first = 0;
  1155. }
  1156. if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
  1157. ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
  1158. if (ret < 0 || ret >= end - pos)
  1159. return pos;
  1160. pos += ret;
  1161. first = 0;
  1162. }
  1163. if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
  1164. ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
  1165. if (ret < 0 || ret >= end - pos)
  1166. return pos;
  1167. pos += ret;
  1168. first = 0;
  1169. }
  1170. #ifdef CONFIG_IEEE80211R
  1171. if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
  1172. ret = os_snprintf(pos, end - pos, "%sFT/EAP",
  1173. first ? "" : "+");
  1174. if (ret < 0 || ret >= end - pos)
  1175. return pos;
  1176. pos += ret;
  1177. first = 0;
  1178. }
  1179. if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
  1180. ret = os_snprintf(pos, end - pos, "%sFT/PSK",
  1181. first ? "" : "+");
  1182. if (ret < 0 || ret >= end - pos)
  1183. return pos;
  1184. pos += ret;
  1185. first = 0;
  1186. }
  1187. #endif /* CONFIG_IEEE80211R */
  1188. #ifdef CONFIG_IEEE80211W
  1189. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
  1190. ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
  1191. first ? "" : "+");
  1192. if (ret < 0 || ret >= end - pos)
  1193. return pos;
  1194. pos += ret;
  1195. first = 0;
  1196. }
  1197. if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
  1198. ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
  1199. first ? "" : "+");
  1200. if (ret < 0 || ret >= end - pos)
  1201. return pos;
  1202. pos += ret;
  1203. first = 0;
  1204. }
  1205. #endif /* CONFIG_IEEE80211W */
  1206. pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
  1207. if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
  1208. ret = os_snprintf(pos, end - pos, "-preauth");
  1209. if (ret < 0 || ret >= end - pos)
  1210. return pos;
  1211. pos += ret;
  1212. }
  1213. ret = os_snprintf(pos, end - pos, "]");
  1214. if (ret < 0 || ret >= end - pos)
  1215. return pos;
  1216. pos += ret;
  1217. return pos;
  1218. }
  1219. #ifdef CONFIG_WPS
  1220. static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
  1221. char *pos, char *end,
  1222. struct wpabuf *wps_ie)
  1223. {
  1224. int ret;
  1225. const char *txt;
  1226. if (wps_ie == NULL)
  1227. return pos;
  1228. if (wps_is_selected_pbc_registrar(wps_ie))
  1229. txt = "[WPS-PBC]";
  1230. #ifdef CONFIG_WPS2
  1231. else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
  1232. txt = "[WPS-AUTH]";
  1233. #endif /* CONFIG_WPS2 */
  1234. else if (wps_is_selected_pin_registrar(wps_ie))
  1235. txt = "[WPS-PIN]";
  1236. else
  1237. txt = "[WPS]";
  1238. ret = os_snprintf(pos, end - pos, "%s", txt);
  1239. if (ret >= 0 && ret < end - pos)
  1240. pos += ret;
  1241. wpabuf_free(wps_ie);
  1242. return pos;
  1243. }
  1244. #endif /* CONFIG_WPS */
  1245. static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
  1246. char *pos, char *end,
  1247. const struct wpa_bss *bss)
  1248. {
  1249. #ifdef CONFIG_WPS
  1250. struct wpabuf *wps_ie;
  1251. wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  1252. return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
  1253. #else /* CONFIG_WPS */
  1254. return pos;
  1255. #endif /* CONFIG_WPS */
  1256. }
  1257. /* Format one result on one text line into a buffer. */
  1258. static int wpa_supplicant_ctrl_iface_scan_result(
  1259. struct wpa_supplicant *wpa_s,
  1260. const struct wpa_bss *bss, char *buf, size_t buflen)
  1261. {
  1262. char *pos, *end;
  1263. int ret;
  1264. const u8 *ie, *ie2, *p2p;
  1265. p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
  1266. if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
  1267. os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
  1268. 0)
  1269. return 0; /* Do not show P2P listen discovery results here */
  1270. pos = buf;
  1271. end = buf + buflen;
  1272. ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
  1273. MAC2STR(bss->bssid), bss->freq, bss->level);
  1274. if (ret < 0 || ret >= end - pos)
  1275. return -1;
  1276. pos += ret;
  1277. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  1278. if (ie)
  1279. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
  1280. ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  1281. if (ie2)
  1282. pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
  1283. pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
  1284. if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
  1285. ret = os_snprintf(pos, end - pos, "[WEP]");
  1286. if (ret < 0 || ret >= end - pos)
  1287. return -1;
  1288. pos += ret;
  1289. }
  1290. if (bss->caps & IEEE80211_CAP_IBSS) {
  1291. ret = os_snprintf(pos, end - pos, "[IBSS]");
  1292. if (ret < 0 || ret >= end - pos)
  1293. return -1;
  1294. pos += ret;
  1295. }
  1296. if (bss->caps & IEEE80211_CAP_ESS) {
  1297. ret = os_snprintf(pos, end - pos, "[ESS]");
  1298. if (ret < 0 || ret >= end - pos)
  1299. return -1;
  1300. pos += ret;
  1301. }
  1302. if (p2p) {
  1303. ret = os_snprintf(pos, end - pos, "[P2P]");
  1304. if (ret < 0 || ret >= end - pos)
  1305. return -1;
  1306. pos += ret;
  1307. }
  1308. #ifdef CONFIG_HS20
  1309. if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
  1310. ret = os_snprintf(pos, end - pos, "[HS20]");
  1311. if (ret < 0 || ret >= end - pos)
  1312. return -1;
  1313. pos += ret;
  1314. }
  1315. #endif /* CONFIG_HS20 */
  1316. ret = os_snprintf(pos, end - pos, "\t%s",
  1317. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  1318. if (ret < 0 || ret >= end - pos)
  1319. return -1;
  1320. pos += ret;
  1321. ret = os_snprintf(pos, end - pos, "\n");
  1322. if (ret < 0 || ret >= end - pos)
  1323. return -1;
  1324. pos += ret;
  1325. return pos - buf;
  1326. }
  1327. static int wpa_supplicant_ctrl_iface_scan_results(
  1328. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  1329. {
  1330. char *pos, *end;
  1331. struct wpa_bss *bss;
  1332. int ret;
  1333. pos = buf;
  1334. end = buf + buflen;
  1335. ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
  1336. "flags / ssid\n");
  1337. if (ret < 0 || ret >= end - pos)
  1338. return pos - buf;
  1339. pos += ret;
  1340. dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
  1341. ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
  1342. end - pos);
  1343. if (ret < 0 || ret >= end - pos)
  1344. return pos - buf;
  1345. pos += ret;
  1346. }
  1347. return pos - buf;
  1348. }
  1349. static int wpa_supplicant_ctrl_iface_select_network(
  1350. struct wpa_supplicant *wpa_s, char *cmd)
  1351. {
  1352. int id;
  1353. struct wpa_ssid *ssid;
  1354. /* cmd: "<network id>" or "any" */
  1355. if (os_strcmp(cmd, "any") == 0) {
  1356. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
  1357. ssid = NULL;
  1358. } else {
  1359. id = atoi(cmd);
  1360. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
  1361. ssid = wpa_config_get_network(wpa_s->conf, id);
  1362. if (ssid == NULL) {
  1363. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  1364. "network id=%d", id);
  1365. return -1;
  1366. }
  1367. if (ssid->disabled == 2) {
  1368. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  1369. "SELECT_NETWORK with persistent P2P group");
  1370. return -1;
  1371. }
  1372. }
  1373. wpa_supplicant_select_network(wpa_s, ssid);
  1374. return 0;
  1375. }
  1376. static int wpa_supplicant_ctrl_iface_enable_network(
  1377. struct wpa_supplicant *wpa_s, char *cmd)
  1378. {
  1379. int id;
  1380. struct wpa_ssid *ssid;
  1381. /* cmd: "<network id>" or "all" */
  1382. if (os_strcmp(cmd, "all") == 0) {
  1383. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
  1384. ssid = NULL;
  1385. } else {
  1386. id = atoi(cmd);
  1387. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
  1388. ssid = wpa_config_get_network(wpa_s->conf, id);
  1389. if (ssid == NULL) {
  1390. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  1391. "network id=%d", id);
  1392. return -1;
  1393. }
  1394. if (ssid->disabled == 2) {
  1395. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  1396. "ENABLE_NETWORK with persistent P2P group");
  1397. return -1;
  1398. }
  1399. if (os_strstr(cmd, " no-connect")) {
  1400. ssid->disabled = 0;
  1401. return 0;
  1402. }
  1403. }
  1404. wpa_supplicant_enable_network(wpa_s, ssid);
  1405. return 0;
  1406. }
  1407. static int wpa_supplicant_ctrl_iface_disable_network(
  1408. struct wpa_supplicant *wpa_s, char *cmd)
  1409. {
  1410. int id;
  1411. struct wpa_ssid *ssid;
  1412. /* cmd: "<network id>" or "all" */
  1413. if (os_strcmp(cmd, "all") == 0) {
  1414. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
  1415. ssid = NULL;
  1416. } else {
  1417. id = atoi(cmd);
  1418. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
  1419. ssid = wpa_config_get_network(wpa_s->conf, id);
  1420. if (ssid == NULL) {
  1421. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  1422. "network id=%d", id);
  1423. return -1;
  1424. }
  1425. if (ssid->disabled == 2) {
  1426. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  1427. "DISABLE_NETWORK with persistent P2P "
  1428. "group");
  1429. return -1;
  1430. }
  1431. }
  1432. wpa_supplicant_disable_network(wpa_s, ssid);
  1433. return 0;
  1434. }
  1435. static int wpa_supplicant_ctrl_iface_add_network(
  1436. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  1437. {
  1438. struct wpa_ssid *ssid;
  1439. int ret;
  1440. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
  1441. ssid = wpa_config_add_network(wpa_s->conf);
  1442. if (ssid == NULL)
  1443. return -1;
  1444. wpas_notify_network_added(wpa_s, ssid);
  1445. ssid->disabled = 1;
  1446. wpa_config_set_network_defaults(ssid);
  1447. ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
  1448. if (ret < 0 || (size_t) ret >= buflen)
  1449. return -1;
  1450. return ret;
  1451. }
  1452. static int wpa_supplicant_ctrl_iface_remove_network(
  1453. struct wpa_supplicant *wpa_s, char *cmd)
  1454. {
  1455. int id;
  1456. struct wpa_ssid *ssid;
  1457. /* cmd: "<network id>" or "all" */
  1458. if (os_strcmp(cmd, "all") == 0) {
  1459. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
  1460. ssid = wpa_s->conf->ssid;
  1461. while (ssid) {
  1462. struct wpa_ssid *remove_ssid = ssid;
  1463. id = ssid->id;
  1464. ssid = ssid->next;
  1465. wpas_notify_network_removed(wpa_s, remove_ssid);
  1466. wpa_config_remove_network(wpa_s->conf, id);
  1467. }
  1468. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1469. if (wpa_s->current_ssid) {
  1470. #ifdef CONFIG_SME
  1471. wpa_s->sme.prev_bssid_set = 0;
  1472. #endif /* CONFIG_SME */
  1473. wpa_sm_set_config(wpa_s->wpa, NULL);
  1474. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  1475. wpa_supplicant_disassociate(wpa_s,
  1476. WLAN_REASON_DEAUTH_LEAVING);
  1477. }
  1478. return 0;
  1479. }
  1480. id = atoi(cmd);
  1481. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
  1482. ssid = wpa_config_get_network(wpa_s->conf, id);
  1483. if (ssid)
  1484. wpas_notify_network_removed(wpa_s, ssid);
  1485. if (ssid == NULL ||
  1486. wpa_config_remove_network(wpa_s->conf, id) < 0) {
  1487. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  1488. "id=%d", id);
  1489. return -1;
  1490. }
  1491. if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
  1492. #ifdef CONFIG_SME
  1493. wpa_s->sme.prev_bssid_set = 0;
  1494. #endif /* CONFIG_SME */
  1495. /*
  1496. * Invalidate the EAP session cache if the current or
  1497. * previously used network is removed.
  1498. */
  1499. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1500. }
  1501. if (ssid == wpa_s->current_ssid) {
  1502. wpa_sm_set_config(wpa_s->wpa, NULL);
  1503. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  1504. wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1505. }
  1506. return 0;
  1507. }
  1508. static int wpa_supplicant_ctrl_iface_set_network(
  1509. struct wpa_supplicant *wpa_s, char *cmd)
  1510. {
  1511. int id;
  1512. struct wpa_ssid *ssid;
  1513. char *name, *value;
  1514. /* cmd: "<network id> <variable name> <value>" */
  1515. name = os_strchr(cmd, ' ');
  1516. if (name == NULL)
  1517. return -1;
  1518. *name++ = '\0';
  1519. value = os_strchr(name, ' ');
  1520. if (value == NULL)
  1521. return -1;
  1522. *value++ = '\0';
  1523. id = atoi(cmd);
  1524. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
  1525. id, name);
  1526. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  1527. (u8 *) value, os_strlen(value));
  1528. ssid = wpa_config_get_network(wpa_s->conf, id);
  1529. if (ssid == NULL) {
  1530. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  1531. "id=%d", id);
  1532. return -1;
  1533. }
  1534. if (wpa_config_set(ssid, name, value, 0) < 0) {
  1535. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
  1536. "variable '%s'", name);
  1537. return -1;
  1538. }
  1539. wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
  1540. if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
  1541. /*
  1542. * Invalidate the EAP session cache if anything in the current
  1543. * or previously used configuration changes.
  1544. */
  1545. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1546. }
  1547. if ((os_strcmp(name, "psk") == 0 &&
  1548. value[0] == '"' && ssid->ssid_len) ||
  1549. (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
  1550. wpa_config_update_psk(ssid);
  1551. else if (os_strcmp(name, "priority") == 0)
  1552. wpa_config_update_prio_list(wpa_s->conf);
  1553. return 0;
  1554. }
  1555. static int wpa_supplicant_ctrl_iface_get_network(
  1556. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  1557. {
  1558. int id;
  1559. size_t res;
  1560. struct wpa_ssid *ssid;
  1561. char *name, *value;
  1562. /* cmd: "<network id> <variable name>" */
  1563. name = os_strchr(cmd, ' ');
  1564. if (name == NULL || buflen == 0)
  1565. return -1;
  1566. *name++ = '\0';
  1567. id = atoi(cmd);
  1568. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
  1569. id, name);
  1570. ssid = wpa_config_get_network(wpa_s->conf, id);
  1571. if (ssid == NULL) {
  1572. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  1573. "id=%d", id);
  1574. return -1;
  1575. }
  1576. value = wpa_config_get_no_key(ssid, name);
  1577. if (value == NULL) {
  1578. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
  1579. "variable '%s'", name);
  1580. return -1;
  1581. }
  1582. res = os_strlcpy(buf, value, buflen);
  1583. if (res >= buflen) {
  1584. os_free(value);
  1585. return -1;
  1586. }
  1587. os_free(value);
  1588. return res;
  1589. }
  1590. static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
  1591. char *buf, size_t buflen)
  1592. {
  1593. char *pos, *end;
  1594. struct wpa_cred *cred;
  1595. int ret;
  1596. pos = buf;
  1597. end = buf + buflen;
  1598. ret = os_snprintf(pos, end - pos,
  1599. "cred id / realm / username / domain / imsi\n");
  1600. if (ret < 0 || ret >= end - pos)
  1601. return pos - buf;
  1602. pos += ret;
  1603. cred = wpa_s->conf->cred;
  1604. while (cred) {
  1605. ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
  1606. cred->id, cred->realm ? cred->realm : "",
  1607. cred->username ? cred->username : "",
  1608. cred->domain ? cred->domain : "",
  1609. cred->imsi ? cred->imsi : "");
  1610. if (ret < 0 || ret >= end - pos)
  1611. return pos - buf;
  1612. pos += ret;
  1613. cred = cred->next;
  1614. }
  1615. return pos - buf;
  1616. }
  1617. static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
  1618. char *buf, size_t buflen)
  1619. {
  1620. struct wpa_cred *cred;
  1621. int ret;
  1622. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
  1623. cred = wpa_config_add_cred(wpa_s->conf);
  1624. if (cred == NULL)
  1625. return -1;
  1626. ret = os_snprintf(buf, buflen, "%d\n", cred->id);
  1627. if (ret < 0 || (size_t) ret >= buflen)
  1628. return -1;
  1629. return ret;
  1630. }
  1631. static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
  1632. char *cmd)
  1633. {
  1634. int id;
  1635. struct wpa_cred *cred;
  1636. /* cmd: "<cred id>" or "all" */
  1637. if (os_strcmp(cmd, "all") == 0) {
  1638. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
  1639. cred = wpa_s->conf->cred;
  1640. while (cred) {
  1641. id = cred->id;
  1642. cred = cred->next;
  1643. wpa_config_remove_cred(wpa_s->conf, id);
  1644. }
  1645. return 0;
  1646. }
  1647. id = atoi(cmd);
  1648. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
  1649. cred = wpa_config_get_cred(wpa_s->conf, id);
  1650. if (cred == NULL ||
  1651. wpa_config_remove_cred(wpa_s->conf, id) < 0) {
  1652. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
  1653. id);
  1654. return -1;
  1655. }
  1656. return 0;
  1657. }
  1658. static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
  1659. char *cmd)
  1660. {
  1661. int id;
  1662. struct wpa_cred *cred;
  1663. char *name, *value;
  1664. /* cmd: "<cred id> <variable name> <value>" */
  1665. name = os_strchr(cmd, ' ');
  1666. if (name == NULL)
  1667. return -1;
  1668. *name++ = '\0';
  1669. value = os_strchr(name, ' ');
  1670. if (value == NULL)
  1671. return -1;
  1672. *value++ = '\0';
  1673. id = atoi(cmd);
  1674. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
  1675. id, name);
  1676. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  1677. (u8 *) value, os_strlen(value));
  1678. cred = wpa_config_get_cred(wpa_s->conf, id);
  1679. if (cred == NULL) {
  1680. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
  1681. id);
  1682. return -1;
  1683. }
  1684. if (wpa_config_set_cred(cred, name, value, 0) < 0) {
  1685. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
  1686. "variable '%s'", name);
  1687. return -1;
  1688. }
  1689. return 0;
  1690. }
  1691. #ifndef CONFIG_NO_CONFIG_WRITE
  1692. static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
  1693. {
  1694. int ret;
  1695. if (!wpa_s->conf->update_config) {
  1696. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
  1697. "to update configuration (update_config=0)");
  1698. return -1;
  1699. }
  1700. ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
  1701. if (ret) {
  1702. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
  1703. "update configuration");
  1704. } else {
  1705. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
  1706. " updated");
  1707. }
  1708. return ret;
  1709. }
  1710. #endif /* CONFIG_NO_CONFIG_WRITE */
  1711. static int ctrl_iface_get_capability_pairwise(int res, char *strict,
  1712. struct wpa_driver_capa *capa,
  1713. char *buf, size_t buflen)
  1714. {
  1715. int ret, first = 1;
  1716. char *pos, *end;
  1717. size_t len;
  1718. pos = buf;
  1719. end = pos + buflen;
  1720. if (res < 0) {
  1721. if (strict)
  1722. return 0;
  1723. len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
  1724. if (len >= buflen)
  1725. return -1;
  1726. return len;
  1727. }
  1728. if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1729. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
  1730. if (ret < 0 || ret >= end - pos)
  1731. return pos - buf;
  1732. pos += ret;
  1733. first = 0;
  1734. }
  1735. if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1736. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
  1737. if (ret < 0 || ret >= end - pos)
  1738. return pos - buf;
  1739. pos += ret;
  1740. first = 0;
  1741. }
  1742. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1743. ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " ");
  1744. if (ret < 0 || ret >= end - pos)
  1745. return pos - buf;
  1746. pos += ret;
  1747. first = 0;
  1748. }
  1749. return pos - buf;
  1750. }
  1751. static int ctrl_iface_get_capability_group(int res, char *strict,
  1752. struct wpa_driver_capa *capa,
  1753. char *buf, size_t buflen)
  1754. {
  1755. int ret, first = 1;
  1756. char *pos, *end;
  1757. size_t len;
  1758. pos = buf;
  1759. end = pos + buflen;
  1760. if (res < 0) {
  1761. if (strict)
  1762. return 0;
  1763. len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
  1764. if (len >= buflen)
  1765. return -1;
  1766. return len;
  1767. }
  1768. if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1769. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
  1770. if (ret < 0 || ret >= end - pos)
  1771. return pos - buf;
  1772. pos += ret;
  1773. first = 0;
  1774. }
  1775. if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1776. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
  1777. if (ret < 0 || ret >= end - pos)
  1778. return pos - buf;
  1779. pos += ret;
  1780. first = 0;
  1781. }
  1782. if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) {
  1783. ret = os_snprintf(pos, end - pos, "%sWEP104",
  1784. first ? "" : " ");
  1785. if (ret < 0 || ret >= end - pos)
  1786. return pos - buf;
  1787. pos += ret;
  1788. first = 0;
  1789. }
  1790. if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) {
  1791. ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " ");
  1792. if (ret < 0 || ret >= end - pos)
  1793. return pos - buf;
  1794. pos += ret;
  1795. first = 0;
  1796. }
  1797. return pos - buf;
  1798. }
  1799. static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
  1800. struct wpa_driver_capa *capa,
  1801. char *buf, size_t buflen)
  1802. {
  1803. int ret;
  1804. char *pos, *end;
  1805. size_t len;
  1806. pos = buf;
  1807. end = pos + buflen;
  1808. if (res < 0) {
  1809. if (strict)
  1810. return 0;
  1811. len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
  1812. "NONE", buflen);
  1813. if (len >= buflen)
  1814. return -1;
  1815. return len;
  1816. }
  1817. ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
  1818. if (ret < 0 || ret >= end - pos)
  1819. return pos - buf;
  1820. pos += ret;
  1821. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1822. WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
  1823. ret = os_snprintf(pos, end - pos, " WPA-EAP");
  1824. if (ret < 0 || ret >= end - pos)
  1825. return pos - buf;
  1826. pos += ret;
  1827. }
  1828. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
  1829. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1830. ret = os_snprintf(pos, end - pos, " WPA-PSK");
  1831. if (ret < 0 || ret >= end - pos)
  1832. return pos - buf;
  1833. pos += ret;
  1834. }
  1835. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1836. ret = os_snprintf(pos, end - pos, " WPA-NONE");
  1837. if (ret < 0 || ret >= end - pos)
  1838. return pos - buf;
  1839. pos += ret;
  1840. }
  1841. return pos - buf;
  1842. }
  1843. static int ctrl_iface_get_capability_proto(int res, char *strict,
  1844. struct wpa_driver_capa *capa,
  1845. char *buf, size_t buflen)
  1846. {
  1847. int ret, first = 1;
  1848. char *pos, *end;
  1849. size_t len;
  1850. pos = buf;
  1851. end = pos + buflen;
  1852. if (res < 0) {
  1853. if (strict)
  1854. return 0;
  1855. len = os_strlcpy(buf, "RSN WPA", buflen);
  1856. if (len >= buflen)
  1857. return -1;
  1858. return len;
  1859. }
  1860. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
  1861. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1862. ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
  1863. if (ret < 0 || ret >= end - pos)
  1864. return pos - buf;
  1865. pos += ret;
  1866. first = 0;
  1867. }
  1868. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1869. WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
  1870. ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
  1871. if (ret < 0 || ret >= end - pos)
  1872. return pos - buf;
  1873. pos += ret;
  1874. first = 0;
  1875. }
  1876. return pos - buf;
  1877. }
  1878. static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
  1879. struct wpa_driver_capa *capa,
  1880. char *buf, size_t buflen)
  1881. {
  1882. int ret, first = 1;
  1883. char *pos, *end;
  1884. size_t len;
  1885. pos = buf;
  1886. end = pos + buflen;
  1887. if (res < 0) {
  1888. if (strict)
  1889. return 0;
  1890. len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
  1891. if (len >= buflen)
  1892. return -1;
  1893. return len;
  1894. }
  1895. if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
  1896. ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
  1897. if (ret < 0 || ret >= end - pos)
  1898. return pos - buf;
  1899. pos += ret;
  1900. first = 0;
  1901. }
  1902. if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
  1903. ret = os_snprintf(pos, end - pos, "%sSHARED",
  1904. first ? "" : " ");
  1905. if (ret < 0 || ret >= end - pos)
  1906. return pos - buf;
  1907. pos += ret;
  1908. first = 0;
  1909. }
  1910. if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
  1911. ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
  1912. if (ret < 0 || ret >= end - pos)
  1913. return pos - buf;
  1914. pos += ret;
  1915. first = 0;
  1916. }
  1917. return pos - buf;
  1918. }
  1919. static int wpa_supplicant_ctrl_iface_get_capability(
  1920. struct wpa_supplicant *wpa_s, const char *_field, char *buf,
  1921. size_t buflen)
  1922. {
  1923. struct wpa_driver_capa capa;
  1924. int res;
  1925. char *strict;
  1926. char field[30];
  1927. size_t len;
  1928. /* Determine whether or not strict checking was requested */
  1929. len = os_strlcpy(field, _field, sizeof(field));
  1930. if (len >= sizeof(field))
  1931. return -1;
  1932. strict = os_strchr(field, ' ');
  1933. if (strict != NULL) {
  1934. *strict++ = '\0';
  1935. if (os_strcmp(strict, "strict") != 0)
  1936. return -1;
  1937. }
  1938. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
  1939. field, strict ? strict : "");
  1940. if (os_strcmp(field, "eap") == 0) {
  1941. return eap_get_names(buf, buflen);
  1942. }
  1943. res = wpa_drv_get_capa(wpa_s, &capa);
  1944. if (os_strcmp(field, "pairwise") == 0)
  1945. return ctrl_iface_get_capability_pairwise(res, strict, &capa,
  1946. buf, buflen);
  1947. if (os_strcmp(field, "group") == 0)
  1948. return ctrl_iface_get_capability_group(res, strict, &capa,
  1949. buf, buflen);
  1950. if (os_strcmp(field, "key_mgmt") == 0)
  1951. return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
  1952. buf, buflen);
  1953. if (os_strcmp(field, "proto") == 0)
  1954. return ctrl_iface_get_capability_proto(res, strict, &capa,
  1955. buf, buflen);
  1956. if (os_strcmp(field, "auth_alg") == 0)
  1957. return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
  1958. buf, buflen);
  1959. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
  1960. field);
  1961. return -1;
  1962. }
  1963. #ifdef CONFIG_INTERWORKING
  1964. static char * anqp_add_hex(char *pos, char *end, const char *title,
  1965. struct wpabuf *data)
  1966. {
  1967. char *start = pos;
  1968. size_t i;
  1969. int ret;
  1970. const u8 *d;
  1971. if (data == NULL)
  1972. return start;
  1973. ret = os_snprintf(pos, end - pos, "%s=", title);
  1974. if (ret < 0 || ret >= end - pos)
  1975. return start;
  1976. pos += ret;
  1977. d = wpabuf_head_u8(data);
  1978. for (i = 0; i < wpabuf_len(data); i++) {
  1979. ret = os_snprintf(pos, end - pos, "%02x", *d++);
  1980. if (ret < 0 || ret >= end - pos)
  1981. return start;
  1982. pos += ret;
  1983. }
  1984. ret = os_snprintf(pos, end - pos, "\n");
  1985. if (ret < 0 || ret >= end - pos)
  1986. return start;
  1987. pos += ret;
  1988. return pos;
  1989. }
  1990. #endif /* CONFIG_INTERWORKING */
  1991. static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
  1992. unsigned long mask, char *buf, size_t buflen)
  1993. {
  1994. size_t i;
  1995. int ret;
  1996. char *pos, *end;
  1997. const u8 *ie, *ie2;
  1998. pos = buf;
  1999. end = buf + buflen;
  2000. if (mask & WPA_BSS_MASK_ID) {
  2001. ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
  2002. if (ret < 0 || ret >= end - pos)
  2003. return 0;
  2004. pos += ret;
  2005. }
  2006. if (mask & WPA_BSS_MASK_BSSID) {
  2007. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
  2008. MAC2STR(bss->bssid));
  2009. if (ret < 0 || ret >= end - pos)
  2010. return 0;
  2011. pos += ret;
  2012. }
  2013. if (mask & WPA_BSS_MASK_FREQ) {
  2014. ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
  2015. if (ret < 0 || ret >= end - pos)
  2016. return 0;
  2017. pos += ret;
  2018. }
  2019. if (mask & WPA_BSS_MASK_BEACON_INT) {
  2020. ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
  2021. bss->beacon_int);
  2022. if (ret < 0 || ret >= end - pos)
  2023. return 0;
  2024. pos += ret;
  2025. }
  2026. if (mask & WPA_BSS_MASK_CAPABILITIES) {
  2027. ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
  2028. bss->caps);
  2029. if (ret < 0 || ret >= end - pos)
  2030. return 0;
  2031. pos += ret;
  2032. }
  2033. if (mask & WPA_BSS_MASK_QUAL) {
  2034. ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
  2035. if (ret < 0 || ret >= end - pos)
  2036. return 0;
  2037. pos += ret;
  2038. }
  2039. if (mask & WPA_BSS_MASK_NOISE) {
  2040. ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
  2041. if (ret < 0 || ret >= end - pos)
  2042. return 0;
  2043. pos += ret;
  2044. }
  2045. if (mask & WPA_BSS_MASK_LEVEL) {
  2046. ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
  2047. if (ret < 0 || ret >= end - pos)
  2048. return 0;
  2049. pos += ret;
  2050. }
  2051. if (mask & WPA_BSS_MASK_TSF) {
  2052. ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
  2053. (unsigned long long) bss->tsf);
  2054. if (ret < 0 || ret >= end - pos)
  2055. return 0;
  2056. pos += ret;
  2057. }
  2058. if (mask & WPA_BSS_MASK_AGE) {
  2059. struct os_time now;
  2060. os_get_time(&now);
  2061. ret = os_snprintf(pos, end - pos, "age=%d\n",
  2062. (int) (now.sec - bss->last_update.sec));
  2063. if (ret < 0 || ret >= end - pos)
  2064. return 0;
  2065. pos += ret;
  2066. }
  2067. if (mask & WPA_BSS_MASK_IE) {
  2068. ret = os_snprintf(pos, end - pos, "ie=");
  2069. if (ret < 0 || ret >= end - pos)
  2070. return 0;
  2071. pos += ret;
  2072. ie = (const u8 *) (bss + 1);
  2073. for (i = 0; i < bss->ie_len; i++) {
  2074. ret = os_snprintf(pos, end - pos, "%02x", *ie++);
  2075. if (ret < 0 || ret >= end - pos)
  2076. return 0;
  2077. pos += ret;
  2078. }
  2079. ret = os_snprintf(pos, end - pos, "\n");
  2080. if (ret < 0 || ret >= end - pos)
  2081. return 0;
  2082. pos += ret;
  2083. }
  2084. if (mask & WPA_BSS_MASK_FLAGS) {
  2085. ret = os_snprintf(pos, end - pos, "flags=");
  2086. if (ret < 0 || ret >= end - pos)
  2087. return 0;
  2088. pos += ret;
  2089. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  2090. if (ie)
  2091. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
  2092. 2 + ie[1]);
  2093. ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  2094. if (ie2)
  2095. pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
  2096. 2 + ie2[1]);
  2097. pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
  2098. if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
  2099. ret = os_snprintf(pos, end - pos, "[WEP]");
  2100. if (ret < 0 || ret >= end - pos)
  2101. return 0;
  2102. pos += ret;
  2103. }
  2104. if (bss->caps & IEEE80211_CAP_IBSS) {
  2105. ret = os_snprintf(pos, end - pos, "[IBSS]");
  2106. if (ret < 0 || ret >= end - pos)
  2107. return 0;
  2108. pos += ret;
  2109. }
  2110. if (bss->caps & IEEE80211_CAP_ESS) {
  2111. ret = os_snprintf(pos, end - pos, "[ESS]");
  2112. if (ret < 0 || ret >= end - pos)
  2113. return 0;
  2114. pos += ret;
  2115. }
  2116. if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) {
  2117. ret = os_snprintf(pos, end - pos, "[P2P]");
  2118. if (ret < 0 || ret >= end - pos)
  2119. return 0;
  2120. pos += ret;
  2121. }
  2122. #ifdef CONFIG_HS20
  2123. if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
  2124. ret = os_snprintf(pos, end - pos, "[HS20]");
  2125. if (ret < 0 || ret >= end - pos)
  2126. return -1;
  2127. pos += ret;
  2128. }
  2129. #endif /* CONFIG_HS20 */
  2130. ret = os_snprintf(pos, end - pos, "\n");
  2131. if (ret < 0 || ret >= end - pos)
  2132. return 0;
  2133. pos += ret;
  2134. }
  2135. if (mask & WPA_BSS_MASK_SSID) {
  2136. ret = os_snprintf(pos, end - pos, "ssid=%s\n",
  2137. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  2138. if (ret < 0 || ret >= end - pos)
  2139. return 0;
  2140. pos += ret;
  2141. }
  2142. #ifdef CONFIG_WPS
  2143. if (mask & WPA_BSS_MASK_WPS_SCAN) {
  2144. ie = (const u8 *) (bss + 1);
  2145. ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
  2146. if (ret < 0 || ret >= end - pos)
  2147. return 0;
  2148. pos += ret;
  2149. }
  2150. #endif /* CONFIG_WPS */
  2151. #ifdef CONFIG_P2P
  2152. if (mask & WPA_BSS_MASK_P2P_SCAN) {
  2153. ie = (const u8 *) (bss + 1);
  2154. ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
  2155. if (ret < 0 || ret >= end - pos)
  2156. return 0;
  2157. pos += ret;
  2158. }
  2159. #endif /* CONFIG_P2P */
  2160. #ifdef CONFIG_INTERWORKING
  2161. if (mask & WPA_BSS_MASK_INTERNETW) {
  2162. pos = anqp_add_hex(pos, end, "anqp_venue_name",
  2163. bss->anqp_venue_name);
  2164. pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
  2165. bss->anqp_network_auth_type);
  2166. pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
  2167. bss->anqp_roaming_consortium);
  2168. pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
  2169. bss->anqp_ip_addr_type_availability);
  2170. pos = anqp_add_hex(pos, end, "anqp_nai_realm",
  2171. bss->anqp_nai_realm);
  2172. pos = anqp_add_hex(pos, end, "anqp_3gpp", bss->anqp_3gpp);
  2173. pos = anqp_add_hex(pos, end, "anqp_domain_name",
  2174. bss->anqp_domain_name);
  2175. #ifdef CONFIG_HS20
  2176. pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
  2177. bss->hs20_operator_friendly_name);
  2178. pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
  2179. bss->hs20_wan_metrics);
  2180. pos = anqp_add_hex(pos, end, "hs20_connection_capability",
  2181. bss->hs20_connection_capability);
  2182. #endif /* CONFIG_HS20 */
  2183. }
  2184. #endif /* CONFIG_INTERWORKING */
  2185. return pos - buf;
  2186. }
  2187. static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
  2188. const char *cmd, char *buf,
  2189. size_t buflen)
  2190. {
  2191. u8 bssid[ETH_ALEN];
  2192. size_t i;
  2193. struct wpa_bss *bss;
  2194. struct wpa_bss *bsslast = NULL;
  2195. struct dl_list *next;
  2196. int ret = 0;
  2197. int len;
  2198. char *ctmp;
  2199. unsigned long mask = WPA_BSS_MASK_ALL;
  2200. if (os_strncmp(cmd, "RANGE=", 6) == 0) {
  2201. if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
  2202. bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
  2203. list_id);
  2204. bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
  2205. list_id);
  2206. } else { /* N1-N2 */
  2207. unsigned int id1, id2;
  2208. if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
  2209. wpa_printf(MSG_INFO, "Wrong BSS range "
  2210. "format");
  2211. return 0;
  2212. }
  2213. id1 = atoi(cmd + 6);
  2214. bss = wpa_bss_get_id(wpa_s, id1);
  2215. id2 = atoi(ctmp + 1);
  2216. if (id2 == 0)
  2217. bsslast = dl_list_last(&wpa_s->bss_id,
  2218. struct wpa_bss,
  2219. list_id);
  2220. else {
  2221. bsslast = wpa_bss_get_id(wpa_s, id2);
  2222. if (bsslast == NULL && bss && id2 > id1) {
  2223. struct wpa_bss *tmp = bss;
  2224. for (;;) {
  2225. next = tmp->list_id.next;
  2226. if (next == &wpa_s->bss_id)
  2227. break;
  2228. tmp = dl_list_entry(
  2229. next, struct wpa_bss,
  2230. list_id);
  2231. if (tmp->id > id2)
  2232. break;
  2233. bsslast = tmp;
  2234. }
  2235. }
  2236. }
  2237. }
  2238. } else if (os_strcmp(cmd, "FIRST") == 0)
  2239. bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
  2240. else if (os_strncmp(cmd, "ID-", 3) == 0) {
  2241. i = atoi(cmd + 3);
  2242. bss = wpa_bss_get_id(wpa_s, i);
  2243. } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
  2244. i = atoi(cmd + 5);
  2245. bss = wpa_bss_get_id(wpa_s, i);
  2246. if (bss) {
  2247. next = bss->list_id.next;
  2248. if (next == &wpa_s->bss_id)
  2249. bss = NULL;
  2250. else
  2251. bss = dl_list_entry(next, struct wpa_bss,
  2252. list_id);
  2253. }
  2254. #ifdef CONFIG_P2P
  2255. } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
  2256. if (hwaddr_aton(cmd + 13, bssid) == 0)
  2257. bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
  2258. else
  2259. bss = NULL;
  2260. #endif /* CONFIG_P2P */
  2261. } else if (hwaddr_aton(cmd, bssid) == 0)
  2262. bss = wpa_bss_get_bssid(wpa_s, bssid);
  2263. else {
  2264. struct wpa_bss *tmp;
  2265. i = atoi(cmd);
  2266. bss = NULL;
  2267. dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
  2268. {
  2269. if (i-- == 0) {
  2270. bss = tmp;
  2271. break;
  2272. }
  2273. }
  2274. }
  2275. if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
  2276. mask = strtoul(ctmp + 5, NULL, 0x10);
  2277. if (mask == 0)
  2278. mask = WPA_BSS_MASK_ALL;
  2279. }
  2280. if (bss == NULL)
  2281. return 0;
  2282. if (bsslast == NULL)
  2283. bsslast = bss;
  2284. do {
  2285. len = print_bss_info(wpa_s, bss, mask, buf, buflen);
  2286. ret += len;
  2287. buf += len;
  2288. buflen -= len;
  2289. if (bss == bsslast)
  2290. break;
  2291. next = bss->list_id.next;
  2292. if (next == &wpa_s->bss_id)
  2293. break;
  2294. bss = dl_list_entry(next, struct wpa_bss, list_id);
  2295. } while (bss && len);
  2296. return ret;
  2297. }
  2298. static int wpa_supplicant_ctrl_iface_ap_scan(
  2299. struct wpa_supplicant *wpa_s, char *cmd)
  2300. {
  2301. int ap_scan = atoi(cmd);
  2302. return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
  2303. }
  2304. static int wpa_supplicant_ctrl_iface_scan_interval(
  2305. struct wpa_supplicant *wpa_s, char *cmd)
  2306. {
  2307. int scan_int = atoi(cmd);
  2308. return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
  2309. }
  2310. static int wpa_supplicant_ctrl_iface_bss_expire_age(
  2311. struct wpa_supplicant *wpa_s, char *cmd)
  2312. {
  2313. int expire_age = atoi(cmd);
  2314. return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
  2315. }
  2316. static int wpa_supplicant_ctrl_iface_bss_expire_count(
  2317. struct wpa_supplicant *wpa_s, char *cmd)
  2318. {
  2319. int expire_count = atoi(cmd);
  2320. return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
  2321. }
  2322. static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
  2323. {
  2324. wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
  2325. /* MLME-DELETEKEYS.request */
  2326. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
  2327. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
  2328. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
  2329. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
  2330. #ifdef CONFIG_IEEE80211W
  2331. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
  2332. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
  2333. #endif /* CONFIG_IEEE80211W */
  2334. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
  2335. 0);
  2336. /* MLME-SETPROTECTION.request(None) */
  2337. wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
  2338. MLME_SETPROTECTION_PROTECT_TYPE_NONE,
  2339. MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
  2340. wpa_sm_drop_sa(wpa_s->wpa);
  2341. }
  2342. static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
  2343. char *addr)
  2344. {
  2345. #ifdef CONFIG_NO_SCAN_PROCESSING
  2346. return -1;
  2347. #else /* CONFIG_NO_SCAN_PROCESSING */
  2348. u8 bssid[ETH_ALEN];
  2349. struct wpa_bss *bss;
  2350. struct wpa_ssid *ssid = wpa_s->current_ssid;
  2351. if (hwaddr_aton(addr, bssid)) {
  2352. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
  2353. "address '%s'", addr);
  2354. return -1;
  2355. }
  2356. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
  2357. bss = wpa_bss_get_bssid(wpa_s, bssid);
  2358. if (!bss) {
  2359. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
  2360. "from BSS table");
  2361. return -1;
  2362. }
  2363. /*
  2364. * TODO: Find best network configuration block from configuration to
  2365. * allow roaming to other networks
  2366. */
  2367. if (!ssid) {
  2368. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
  2369. "configuration known for the target AP");
  2370. return -1;
  2371. }
  2372. wpa_s->reassociate = 1;
  2373. wpa_supplicant_connect(wpa_s, bss, ssid);
  2374. return 0;
  2375. #endif /* CONFIG_NO_SCAN_PROCESSING */
  2376. }
  2377. #ifdef CONFIG_P2P
  2378. static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
  2379. {
  2380. unsigned int timeout = atoi(cmd);
  2381. enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
  2382. u8 dev_id[ETH_ALEN], *_dev_id = NULL;
  2383. char *pos;
  2384. if (os_strstr(cmd, "type=social"))
  2385. type = P2P_FIND_ONLY_SOCIAL;
  2386. else if (os_strstr(cmd, "type=progressive"))
  2387. type = P2P_FIND_PROGRESSIVE;
  2388. pos = os_strstr(cmd, "dev_id=");
  2389. if (pos) {
  2390. pos += 7;
  2391. if (hwaddr_aton(pos, dev_id))
  2392. return -1;
  2393. _dev_id = dev_id;
  2394. }
  2395. return wpas_p2p_find(wpa_s, timeout, type, 0, NULL, _dev_id);
  2396. }
  2397. static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
  2398. char *buf, size_t buflen)
  2399. {
  2400. u8 addr[ETH_ALEN];
  2401. char *pos, *pos2;
  2402. char *pin = NULL;
  2403. enum p2p_wps_method wps_method;
  2404. int new_pin;
  2405. int ret;
  2406. int persistent_group, persistent_id = -1;
  2407. int join;
  2408. int auth;
  2409. int automatic;
  2410. int go_intent = -1;
  2411. int freq = 0;
  2412. int pd;
  2413. /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
  2414. * [persistent|persistent=<network id>]
  2415. * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] */
  2416. if (hwaddr_aton(cmd, addr))
  2417. return -1;
  2418. pos = cmd + 17;
  2419. if (*pos != ' ')
  2420. return -1;
  2421. pos++;
  2422. persistent_group = os_strstr(pos, " persistent") != NULL;
  2423. pos2 = os_strstr(pos, " persistent=");
  2424. if (pos2) {
  2425. struct wpa_ssid *ssid;
  2426. persistent_id = atoi(pos2 + 12);
  2427. ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
  2428. if (ssid == NULL || ssid->disabled != 2 ||
  2429. ssid->mode != WPAS_MODE_P2P_GO) {
  2430. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2431. "SSID id=%d for persistent P2P group (GO)",
  2432. persistent_id);
  2433. return -1;
  2434. }
  2435. }
  2436. join = os_strstr(pos, " join") != NULL;
  2437. auth = os_strstr(pos, " auth") != NULL;
  2438. automatic = os_strstr(pos, " auto") != NULL;
  2439. pd = os_strstr(pos, " provdisc") != NULL;
  2440. pos2 = os_strstr(pos, " go_intent=");
  2441. if (pos2) {
  2442. pos2 += 11;
  2443. go_intent = atoi(pos2);
  2444. if (go_intent < 0 || go_intent > 15)
  2445. return -1;
  2446. }
  2447. pos2 = os_strstr(pos, " freq=");
  2448. if (pos2) {
  2449. pos2 += 6;
  2450. freq = atoi(pos2);
  2451. if (freq <= 0)
  2452. return -1;
  2453. }
  2454. if (os_strncmp(pos, "pin", 3) == 0) {
  2455. /* Request random PIN (to be displayed) and enable the PIN */
  2456. wps_method = WPS_PIN_DISPLAY;
  2457. } else if (os_strncmp(pos, "pbc", 3) == 0) {
  2458. wps_method = WPS_PBC;
  2459. } else {
  2460. pin = pos;
  2461. pos = os_strchr(pin, ' ');
  2462. wps_method = WPS_PIN_KEYPAD;
  2463. if (pos) {
  2464. *pos++ = '\0';
  2465. if (os_strncmp(pos, "display", 7) == 0)
  2466. wps_method = WPS_PIN_DISPLAY;
  2467. }
  2468. }
  2469. new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
  2470. persistent_group, automatic, join,
  2471. auth, go_intent, freq, persistent_id, pd);
  2472. if (new_pin == -2) {
  2473. os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
  2474. return 25;
  2475. }
  2476. if (new_pin == -3) {
  2477. os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
  2478. return 25;
  2479. }
  2480. if (new_pin < 0)
  2481. return -1;
  2482. if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
  2483. ret = os_snprintf(buf, buflen, "%08d", new_pin);
  2484. if (ret < 0 || (size_t) ret >= buflen)
  2485. return -1;
  2486. return ret;
  2487. }
  2488. os_memcpy(buf, "OK\n", 3);
  2489. return 3;
  2490. }
  2491. static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
  2492. {
  2493. unsigned int timeout = atoi(cmd);
  2494. return wpas_p2p_listen(wpa_s, timeout);
  2495. }
  2496. static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
  2497. {
  2498. u8 addr[ETH_ALEN];
  2499. char *pos;
  2500. enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
  2501. /* <addr> <config method> [join|auto] */
  2502. if (hwaddr_aton(cmd, addr))
  2503. return -1;
  2504. pos = cmd + 17;
  2505. if (*pos != ' ')
  2506. return -1;
  2507. pos++;
  2508. if (os_strstr(pos, " join") != NULL)
  2509. use = WPAS_P2P_PD_FOR_JOIN;
  2510. else if (os_strstr(pos, " auto") != NULL)
  2511. use = WPAS_P2P_PD_AUTO;
  2512. return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
  2513. }
  2514. static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
  2515. size_t buflen)
  2516. {
  2517. struct wpa_ssid *ssid = wpa_s->current_ssid;
  2518. if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
  2519. ssid->passphrase == NULL)
  2520. return -1;
  2521. os_strlcpy(buf, ssid->passphrase, buflen);
  2522. return os_strlen(buf);
  2523. }
  2524. static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
  2525. char *buf, size_t buflen)
  2526. {
  2527. u64 ref;
  2528. int res;
  2529. u8 dst_buf[ETH_ALEN], *dst;
  2530. struct wpabuf *tlvs;
  2531. char *pos;
  2532. size_t len;
  2533. if (hwaddr_aton(cmd, dst_buf))
  2534. return -1;
  2535. dst = dst_buf;
  2536. if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
  2537. dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
  2538. dst = NULL;
  2539. pos = cmd + 17;
  2540. if (*pos != ' ')
  2541. return -1;
  2542. pos++;
  2543. if (os_strncmp(pos, "upnp ", 5) == 0) {
  2544. u8 version;
  2545. pos += 5;
  2546. if (hexstr2bin(pos, &version, 1) < 0)
  2547. return -1;
  2548. pos += 2;
  2549. if (*pos != ' ')
  2550. return -1;
  2551. pos++;
  2552. ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
  2553. } else {
  2554. len = os_strlen(pos);
  2555. if (len & 1)
  2556. return -1;
  2557. len /= 2;
  2558. tlvs = wpabuf_alloc(len);
  2559. if (tlvs == NULL)
  2560. return -1;
  2561. if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
  2562. wpabuf_free(tlvs);
  2563. return -1;
  2564. }
  2565. ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
  2566. wpabuf_free(tlvs);
  2567. }
  2568. if (ref == 0)
  2569. return -1;
  2570. res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
  2571. if (res < 0 || (unsigned) res >= buflen)
  2572. return -1;
  2573. return res;
  2574. }
  2575. static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
  2576. char *cmd)
  2577. {
  2578. long long unsigned val;
  2579. u64 req;
  2580. if (sscanf(cmd, "%llx", &val) != 1)
  2581. return -1;
  2582. req = val;
  2583. return wpas_p2p_sd_cancel_request(wpa_s, req);
  2584. }
  2585. static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
  2586. {
  2587. int freq;
  2588. u8 dst[ETH_ALEN];
  2589. u8 dialog_token;
  2590. struct wpabuf *resp_tlvs;
  2591. char *pos, *pos2;
  2592. size_t len;
  2593. pos = os_strchr(cmd, ' ');
  2594. if (pos == NULL)
  2595. return -1;
  2596. *pos++ = '\0';
  2597. freq = atoi(cmd);
  2598. if (freq == 0)
  2599. return -1;
  2600. if (hwaddr_aton(pos, dst))
  2601. return -1;
  2602. pos += 17;
  2603. if (*pos != ' ')
  2604. return -1;
  2605. pos++;
  2606. pos2 = os_strchr(pos, ' ');
  2607. if (pos2 == NULL)
  2608. return -1;
  2609. *pos2++ = '\0';
  2610. dialog_token = atoi(pos);
  2611. len = os_strlen(pos2);
  2612. if (len & 1)
  2613. return -1;
  2614. len /= 2;
  2615. resp_tlvs = wpabuf_alloc(len);
  2616. if (resp_tlvs == NULL)
  2617. return -1;
  2618. if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
  2619. wpabuf_free(resp_tlvs);
  2620. return -1;
  2621. }
  2622. wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
  2623. wpabuf_free(resp_tlvs);
  2624. return 0;
  2625. }
  2626. static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
  2627. char *cmd)
  2628. {
  2629. if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
  2630. return -1;
  2631. wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
  2632. return 0;
  2633. }
  2634. static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
  2635. char *cmd)
  2636. {
  2637. char *pos;
  2638. size_t len;
  2639. struct wpabuf *query, *resp;
  2640. pos = os_strchr(cmd, ' ');
  2641. if (pos == NULL)
  2642. return -1;
  2643. *pos++ = '\0';
  2644. len = os_strlen(cmd);
  2645. if (len & 1)
  2646. return -1;
  2647. len /= 2;
  2648. query = wpabuf_alloc(len);
  2649. if (query == NULL)
  2650. return -1;
  2651. if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
  2652. wpabuf_free(query);
  2653. return -1;
  2654. }
  2655. len = os_strlen(pos);
  2656. if (len & 1) {
  2657. wpabuf_free(query);
  2658. return -1;
  2659. }
  2660. len /= 2;
  2661. resp = wpabuf_alloc(len);
  2662. if (resp == NULL) {
  2663. wpabuf_free(query);
  2664. return -1;
  2665. }
  2666. if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
  2667. wpabuf_free(query);
  2668. wpabuf_free(resp);
  2669. return -1;
  2670. }
  2671. if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
  2672. wpabuf_free(query);
  2673. wpabuf_free(resp);
  2674. return -1;
  2675. }
  2676. return 0;
  2677. }
  2678. static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
  2679. {
  2680. char *pos;
  2681. u8 version;
  2682. pos = os_strchr(cmd, ' ');
  2683. if (pos == NULL)
  2684. return -1;
  2685. *pos++ = '\0';
  2686. if (hexstr2bin(cmd, &version, 1) < 0)
  2687. return -1;
  2688. return wpas_p2p_service_add_upnp(wpa_s, version, pos);
  2689. }
  2690. static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
  2691. {
  2692. char *pos;
  2693. pos = os_strchr(cmd, ' ');
  2694. if (pos == NULL)
  2695. return -1;
  2696. *pos++ = '\0';
  2697. if (os_strcmp(cmd, "bonjour") == 0)
  2698. return p2p_ctrl_service_add_bonjour(wpa_s, pos);
  2699. if (os_strcmp(cmd, "upnp") == 0)
  2700. return p2p_ctrl_service_add_upnp(wpa_s, pos);
  2701. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  2702. return -1;
  2703. }
  2704. static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
  2705. char *cmd)
  2706. {
  2707. size_t len;
  2708. struct wpabuf *query;
  2709. int ret;
  2710. len = os_strlen(cmd);
  2711. if (len & 1)
  2712. return -1;
  2713. len /= 2;
  2714. query = wpabuf_alloc(len);
  2715. if (query == NULL)
  2716. return -1;
  2717. if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
  2718. wpabuf_free(query);
  2719. return -1;
  2720. }
  2721. ret = wpas_p2p_service_del_bonjour(wpa_s, query);
  2722. wpabuf_free(query);
  2723. return ret;
  2724. }
  2725. static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
  2726. {
  2727. char *pos;
  2728. u8 version;
  2729. pos = os_strchr(cmd, ' ');
  2730. if (pos == NULL)
  2731. return -1;
  2732. *pos++ = '\0';
  2733. if (hexstr2bin(cmd, &version, 1) < 0)
  2734. return -1;
  2735. return wpas_p2p_service_del_upnp(wpa_s, version, pos);
  2736. }
  2737. static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
  2738. {
  2739. char *pos;
  2740. pos = os_strchr(cmd, ' ');
  2741. if (pos == NULL)
  2742. return -1;
  2743. *pos++ = '\0';
  2744. if (os_strcmp(cmd, "bonjour") == 0)
  2745. return p2p_ctrl_service_del_bonjour(wpa_s, pos);
  2746. if (os_strcmp(cmd, "upnp") == 0)
  2747. return p2p_ctrl_service_del_upnp(wpa_s, pos);
  2748. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  2749. return -1;
  2750. }
  2751. static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
  2752. {
  2753. u8 addr[ETH_ALEN];
  2754. /* <addr> */
  2755. if (hwaddr_aton(cmd, addr))
  2756. return -1;
  2757. return wpas_p2p_reject(wpa_s, addr);
  2758. }
  2759. static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
  2760. {
  2761. char *pos;
  2762. int id;
  2763. struct wpa_ssid *ssid;
  2764. u8 peer[ETH_ALEN];
  2765. id = atoi(cmd);
  2766. pos = os_strstr(cmd, " peer=");
  2767. if (pos) {
  2768. pos += 6;
  2769. if (hwaddr_aton(pos, peer))
  2770. return -1;
  2771. }
  2772. ssid = wpa_config_get_network(wpa_s->conf, id);
  2773. if (ssid == NULL || ssid->disabled != 2) {
  2774. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  2775. "for persistent P2P group",
  2776. id);
  2777. return -1;
  2778. }
  2779. return wpas_p2p_invite(wpa_s, pos ? peer : NULL, ssid, NULL);
  2780. }
  2781. static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
  2782. {
  2783. char *pos;
  2784. u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
  2785. pos = os_strstr(cmd, " peer=");
  2786. if (!pos)
  2787. return -1;
  2788. *pos = '\0';
  2789. pos += 6;
  2790. if (hwaddr_aton(pos, peer)) {
  2791. wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
  2792. return -1;
  2793. }
  2794. pos = os_strstr(pos, " go_dev_addr=");
  2795. if (pos) {
  2796. pos += 13;
  2797. if (hwaddr_aton(pos, go_dev_addr)) {
  2798. wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
  2799. pos);
  2800. return -1;
  2801. }
  2802. go_dev = go_dev_addr;
  2803. }
  2804. return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
  2805. }
  2806. static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
  2807. {
  2808. if (os_strncmp(cmd, "persistent=", 11) == 0)
  2809. return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
  2810. if (os_strncmp(cmd, "group=", 6) == 0)
  2811. return p2p_ctrl_invite_group(wpa_s, cmd + 6);
  2812. return -1;
  2813. }
  2814. static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
  2815. char *cmd, int freq)
  2816. {
  2817. int id;
  2818. struct wpa_ssid *ssid;
  2819. id = atoi(cmd);
  2820. ssid = wpa_config_get_network(wpa_s->conf, id);
  2821. if (ssid == NULL || ssid->disabled != 2) {
  2822. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  2823. "for persistent P2P group",
  2824. id);
  2825. return -1;
  2826. }
  2827. return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq);
  2828. }
  2829. static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
  2830. {
  2831. int freq = 0;
  2832. char *pos;
  2833. pos = os_strstr(cmd, "freq=");
  2834. if (pos)
  2835. freq = atoi(pos + 5);
  2836. if (os_strncmp(cmd, "persistent=", 11) == 0)
  2837. return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq);
  2838. if (os_strcmp(cmd, "persistent") == 0 ||
  2839. os_strncmp(cmd, "persistent ", 11) == 0)
  2840. return wpas_p2p_group_add(wpa_s, 1, freq);
  2841. if (os_strncmp(cmd, "freq=", 5) == 0)
  2842. return wpas_p2p_group_add(wpa_s, 0, freq);
  2843. wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
  2844. cmd);
  2845. return -1;
  2846. }
  2847. static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
  2848. char *buf, size_t buflen)
  2849. {
  2850. u8 addr[ETH_ALEN], *addr_ptr;
  2851. int next, res;
  2852. const struct p2p_peer_info *info;
  2853. char *pos, *end;
  2854. char devtype[WPS_DEV_TYPE_BUFSIZE];
  2855. struct wpa_ssid *ssid;
  2856. if (!wpa_s->global->p2p)
  2857. return -1;
  2858. if (os_strcmp(cmd, "FIRST") == 0) {
  2859. addr_ptr = NULL;
  2860. next = 0;
  2861. } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
  2862. if (hwaddr_aton(cmd + 5, addr) < 0)
  2863. return -1;
  2864. addr_ptr = addr;
  2865. next = 1;
  2866. } else {
  2867. if (hwaddr_aton(cmd, addr) < 0)
  2868. return -1;
  2869. addr_ptr = addr;
  2870. next = 0;
  2871. }
  2872. info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
  2873. if (info == NULL)
  2874. return -1;
  2875. pos = buf;
  2876. end = buf + buflen;
  2877. res = os_snprintf(pos, end - pos, MACSTR "\n"
  2878. "pri_dev_type=%s\n"
  2879. "device_name=%s\n"
  2880. "manufacturer=%s\n"
  2881. "model_name=%s\n"
  2882. "model_number=%s\n"
  2883. "serial_number=%s\n"
  2884. "config_methods=0x%x\n"
  2885. "dev_capab=0x%x\n"
  2886. "group_capab=0x%x\n"
  2887. "level=%d\n",
  2888. MAC2STR(info->p2p_device_addr),
  2889. wps_dev_type_bin2str(info->pri_dev_type,
  2890. devtype, sizeof(devtype)),
  2891. info->device_name,
  2892. info->manufacturer,
  2893. info->model_name,
  2894. info->model_number,
  2895. info->serial_number,
  2896. info->config_methods,
  2897. info->dev_capab,
  2898. info->group_capab,
  2899. info->level);
  2900. if (res < 0 || res >= end - pos)
  2901. return pos - buf;
  2902. pos += res;
  2903. ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
  2904. if (ssid) {
  2905. res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
  2906. if (res < 0 || res >= end - pos)
  2907. return pos - buf;
  2908. pos += res;
  2909. }
  2910. res = p2p_get_peer_info_txt(info, pos, end - pos);
  2911. if (res < 0)
  2912. return pos - buf;
  2913. pos += res;
  2914. return pos - buf;
  2915. }
  2916. static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
  2917. const char *param)
  2918. {
  2919. struct wpa_freq_range *freq = NULL, *n;
  2920. unsigned int count = 0, i;
  2921. const char *pos, *pos2, *pos3;
  2922. if (wpa_s->global->p2p == NULL)
  2923. return -1;
  2924. /*
  2925. * param includes comma separated frequency range.
  2926. * For example: 2412-2432,2462,5000-6000
  2927. */
  2928. pos = param;
  2929. while (pos && pos[0]) {
  2930. n = os_realloc(freq,
  2931. (count + 1) * sizeof(struct wpa_freq_range));
  2932. if (n == NULL) {
  2933. os_free(freq);
  2934. return -1;
  2935. }
  2936. freq = n;
  2937. freq[count].min = atoi(pos);
  2938. pos2 = os_strchr(pos, '-');
  2939. pos3 = os_strchr(pos, ',');
  2940. if (pos2 && (!pos3 || pos2 < pos3)) {
  2941. pos2++;
  2942. freq[count].max = atoi(pos2);
  2943. } else
  2944. freq[count].max = freq[count].min;
  2945. pos = pos3;
  2946. if (pos)
  2947. pos++;
  2948. count++;
  2949. }
  2950. for (i = 0; i < count; i++) {
  2951. wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
  2952. freq[i].min, freq[i].max);
  2953. }
  2954. os_free(wpa_s->global->p2p_disallow_freq);
  2955. wpa_s->global->p2p_disallow_freq = freq;
  2956. wpa_s->global->num_p2p_disallow_freq = count;
  2957. wpas_p2p_update_channel_list(wpa_s);
  2958. return 0;
  2959. }
  2960. static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
  2961. {
  2962. char *param;
  2963. if (wpa_s->global->p2p == NULL)
  2964. return -1;
  2965. param = os_strchr(cmd, ' ');
  2966. if (param == NULL)
  2967. return -1;
  2968. *param++ = '\0';
  2969. if (os_strcmp(cmd, "discoverability") == 0) {
  2970. p2p_set_client_discoverability(wpa_s->global->p2p,
  2971. atoi(param));
  2972. return 0;
  2973. }
  2974. if (os_strcmp(cmd, "managed") == 0) {
  2975. p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
  2976. return 0;
  2977. }
  2978. if (os_strcmp(cmd, "listen_channel") == 0) {
  2979. return p2p_set_listen_channel(wpa_s->global->p2p, 81,
  2980. atoi(param));
  2981. }
  2982. if (os_strcmp(cmd, "ssid_postfix") == 0) {
  2983. return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
  2984. os_strlen(param));
  2985. }
  2986. if (os_strcmp(cmd, "noa") == 0) {
  2987. char *pos;
  2988. int count, start, duration;
  2989. /* GO NoA parameters: count,start_offset(ms),duration(ms) */
  2990. count = atoi(param);
  2991. pos = os_strchr(param, ',');
  2992. if (pos == NULL)
  2993. return -1;
  2994. pos++;
  2995. start = atoi(pos);
  2996. pos = os_strchr(pos, ',');
  2997. if (pos == NULL)
  2998. return -1;
  2999. pos++;
  3000. duration = atoi(pos);
  3001. if (count < 0 || count > 255 || start < 0 || duration < 0)
  3002. return -1;
  3003. if (count == 0 && duration > 0)
  3004. return -1;
  3005. wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
  3006. "start=%d duration=%d", count, start, duration);
  3007. return wpas_p2p_set_noa(wpa_s, count, start, duration);
  3008. }
  3009. if (os_strcmp(cmd, "ps") == 0)
  3010. return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
  3011. if (os_strcmp(cmd, "oppps") == 0)
  3012. return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
  3013. if (os_strcmp(cmd, "ctwindow") == 0)
  3014. return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
  3015. if (os_strcmp(cmd, "disabled") == 0) {
  3016. wpa_s->global->p2p_disabled = atoi(param);
  3017. wpa_printf(MSG_DEBUG, "P2P functionality %s",
  3018. wpa_s->global->p2p_disabled ?
  3019. "disabled" : "enabled");
  3020. if (wpa_s->global->p2p_disabled) {
  3021. wpas_p2p_stop_find(wpa_s);
  3022. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  3023. p2p_flush(wpa_s->global->p2p);
  3024. }
  3025. return 0;
  3026. }
  3027. if (os_strcmp(cmd, "force_long_sd") == 0) {
  3028. wpa_s->force_long_sd = atoi(param);
  3029. return 0;
  3030. }
  3031. if (os_strcmp(cmd, "peer_filter") == 0) {
  3032. u8 addr[ETH_ALEN];
  3033. if (hwaddr_aton(param, addr))
  3034. return -1;
  3035. p2p_set_peer_filter(wpa_s->global->p2p, addr);
  3036. return 0;
  3037. }
  3038. if (os_strcmp(cmd, "cross_connect") == 0)
  3039. return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
  3040. if (os_strcmp(cmd, "go_apsd") == 0) {
  3041. if (os_strcmp(param, "disable") == 0)
  3042. wpa_s->set_ap_uapsd = 0;
  3043. else {
  3044. wpa_s->set_ap_uapsd = 1;
  3045. wpa_s->ap_uapsd = atoi(param);
  3046. }
  3047. return 0;
  3048. }
  3049. if (os_strcmp(cmd, "client_apsd") == 0) {
  3050. if (os_strcmp(param, "disable") == 0)
  3051. wpa_s->set_sta_uapsd = 0;
  3052. else {
  3053. int be, bk, vi, vo;
  3054. char *pos;
  3055. /* format: BE,BK,VI,VO;max SP Length */
  3056. be = atoi(param);
  3057. pos = os_strchr(param, ',');
  3058. if (pos == NULL)
  3059. return -1;
  3060. pos++;
  3061. bk = atoi(pos);
  3062. pos = os_strchr(pos, ',');
  3063. if (pos == NULL)
  3064. return -1;
  3065. pos++;
  3066. vi = atoi(pos);
  3067. pos = os_strchr(pos, ',');
  3068. if (pos == NULL)
  3069. return -1;
  3070. pos++;
  3071. vo = atoi(pos);
  3072. /* ignore max SP Length for now */
  3073. wpa_s->set_sta_uapsd = 1;
  3074. wpa_s->sta_uapsd = 0;
  3075. if (be)
  3076. wpa_s->sta_uapsd |= BIT(0);
  3077. if (bk)
  3078. wpa_s->sta_uapsd |= BIT(1);
  3079. if (vi)
  3080. wpa_s->sta_uapsd |= BIT(2);
  3081. if (vo)
  3082. wpa_s->sta_uapsd |= BIT(3);
  3083. }
  3084. return 0;
  3085. }
  3086. if (os_strcmp(cmd, "disallow_freq") == 0)
  3087. return p2p_ctrl_disallow_freq(wpa_s, param);
  3088. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
  3089. cmd);
  3090. return -1;
  3091. }
  3092. static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
  3093. {
  3094. char *pos, *pos2;
  3095. unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
  3096. if (cmd[0]) {
  3097. pos = os_strchr(cmd, ' ');
  3098. if (pos == NULL)
  3099. return -1;
  3100. *pos++ = '\0';
  3101. dur1 = atoi(cmd);
  3102. pos2 = os_strchr(pos, ' ');
  3103. if (pos2)
  3104. *pos2++ = '\0';
  3105. int1 = atoi(pos);
  3106. } else
  3107. pos2 = NULL;
  3108. if (pos2) {
  3109. pos = os_strchr(pos2, ' ');
  3110. if (pos == NULL)
  3111. return -1;
  3112. *pos++ = '\0';
  3113. dur2 = atoi(pos2);
  3114. int2 = atoi(pos);
  3115. }
  3116. return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
  3117. }
  3118. static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
  3119. {
  3120. char *pos;
  3121. unsigned int period = 0, interval = 0;
  3122. if (cmd[0]) {
  3123. pos = os_strchr(cmd, ' ');
  3124. if (pos == NULL)
  3125. return -1;
  3126. *pos++ = '\0';
  3127. period = atoi(cmd);
  3128. interval = atoi(pos);
  3129. }
  3130. return wpas_p2p_ext_listen(wpa_s, period, interval);
  3131. }
  3132. #endif /* CONFIG_P2P */
  3133. #ifdef CONFIG_INTERWORKING
  3134. static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
  3135. {
  3136. u8 bssid[ETH_ALEN];
  3137. struct wpa_bss *bss;
  3138. if (hwaddr_aton(dst, bssid)) {
  3139. wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
  3140. return -1;
  3141. }
  3142. bss = wpa_bss_get_bssid(wpa_s, bssid);
  3143. if (bss == NULL) {
  3144. wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
  3145. MAC2STR(bssid));
  3146. return -1;
  3147. }
  3148. return interworking_connect(wpa_s, bss);
  3149. }
  3150. static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
  3151. {
  3152. u8 dst_addr[ETH_ALEN];
  3153. int used;
  3154. char *pos;
  3155. #define MAX_ANQP_INFO_ID 100
  3156. u16 id[MAX_ANQP_INFO_ID];
  3157. size_t num_id = 0;
  3158. used = hwaddr_aton2(dst, dst_addr);
  3159. if (used < 0)
  3160. return -1;
  3161. pos = dst + used;
  3162. while (num_id < MAX_ANQP_INFO_ID) {
  3163. id[num_id] = atoi(pos);
  3164. if (id[num_id])
  3165. num_id++;
  3166. pos = os_strchr(pos + 1, ',');
  3167. if (pos == NULL)
  3168. break;
  3169. pos++;
  3170. }
  3171. if (num_id == 0)
  3172. return -1;
  3173. return anqp_send_req(wpa_s, dst_addr, id, num_id);
  3174. }
  3175. #endif /* CONFIG_INTERWORKING */
  3176. #ifdef CONFIG_HS20
  3177. static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
  3178. {
  3179. u8 dst_addr[ETH_ALEN];
  3180. int used;
  3181. char *pos;
  3182. u32 subtypes = 0;
  3183. used = hwaddr_aton2(dst, dst_addr);
  3184. if (used < 0)
  3185. return -1;
  3186. pos = dst + used;
  3187. for (;;) {
  3188. int num = atoi(pos);
  3189. if (num <= 0 || num > 31)
  3190. return -1;
  3191. subtypes |= BIT(num);
  3192. pos = os_strchr(pos + 1, ',');
  3193. if (pos == NULL)
  3194. break;
  3195. pos++;
  3196. }
  3197. if (subtypes == 0)
  3198. return -1;
  3199. return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
  3200. }
  3201. static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
  3202. const u8 *addr, const char *realm)
  3203. {
  3204. u8 *buf;
  3205. size_t rlen, len;
  3206. int ret;
  3207. rlen = os_strlen(realm);
  3208. len = 3 + rlen;
  3209. buf = os_malloc(len);
  3210. if (buf == NULL)
  3211. return -1;
  3212. buf[0] = 1; /* NAI Home Realm Count */
  3213. buf[1] = 0; /* Formatted in accordance with RFC 4282 */
  3214. buf[2] = rlen;
  3215. os_memcpy(buf + 3, realm, rlen);
  3216. ret = hs20_anqp_send_req(wpa_s, addr,
  3217. BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
  3218. buf, len);
  3219. os_free(buf);
  3220. return ret;
  3221. }
  3222. static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
  3223. char *dst)
  3224. {
  3225. struct wpa_cred *cred = wpa_s->conf->cred;
  3226. u8 dst_addr[ETH_ALEN];
  3227. int used;
  3228. u8 *buf;
  3229. size_t len;
  3230. int ret;
  3231. used = hwaddr_aton2(dst, dst_addr);
  3232. if (used < 0)
  3233. return -1;
  3234. while (dst[used] == ' ')
  3235. used++;
  3236. if (os_strncmp(dst + used, "realm=", 6) == 0)
  3237. return hs20_nai_home_realm_list(wpa_s, dst_addr,
  3238. dst + used + 6);
  3239. len = os_strlen(dst + used);
  3240. if (len == 0 && cred && cred->realm)
  3241. return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
  3242. if (len % 1)
  3243. return -1;
  3244. len /= 2;
  3245. buf = os_malloc(len);
  3246. if (buf == NULL)
  3247. return -1;
  3248. if (hexstr2bin(dst + used, buf, len) < 0) {
  3249. os_free(buf);
  3250. return -1;
  3251. }
  3252. ret = hs20_anqp_send_req(wpa_s, dst_addr,
  3253. BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
  3254. buf, len);
  3255. os_free(buf);
  3256. return ret;
  3257. }
  3258. #endif /* CONFIG_HS20 */
  3259. static int wpa_supplicant_ctrl_iface_sta_autoconnect(
  3260. struct wpa_supplicant *wpa_s, char *cmd)
  3261. {
  3262. wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
  3263. return 0;
  3264. }
  3265. static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
  3266. size_t buflen)
  3267. {
  3268. struct wpa_signal_info si;
  3269. int ret;
  3270. ret = wpa_drv_signal_poll(wpa_s, &si);
  3271. if (ret)
  3272. return -1;
  3273. ret = os_snprintf(buf, buflen, "RSSI=%d\nLINKSPEED=%d\n"
  3274. "NOISE=%d\nFREQUENCY=%u\n",
  3275. si.current_signal, si.current_txrate / 1000,
  3276. si.current_noise, si.frequency);
  3277. if (ret < 0 || (unsigned int) ret > buflen)
  3278. return -1;
  3279. return ret;
  3280. }
  3281. char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
  3282. char *buf, size_t *resp_len)
  3283. {
  3284. char *reply;
  3285. const int reply_size = 4096;
  3286. int ctrl_rsp = 0;
  3287. int reply_len;
  3288. if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
  3289. os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  3290. wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
  3291. (const u8 *) buf, os_strlen(buf));
  3292. } else {
  3293. int level = MSG_DEBUG;
  3294. if (os_strcmp(buf, "PING") == 0)
  3295. level = MSG_EXCESSIVE;
  3296. wpa_hexdump_ascii(level, "RX ctrl_iface",
  3297. (const u8 *) buf, os_strlen(buf));
  3298. }
  3299. reply = os_malloc(reply_size);
  3300. if (reply == NULL) {
  3301. *resp_len = 1;
  3302. return NULL;
  3303. }
  3304. os_memcpy(reply, "OK\n", 3);
  3305. reply_len = 3;
  3306. if (os_strcmp(buf, "PING") == 0) {
  3307. os_memcpy(reply, "PONG\n", 5);
  3308. reply_len = 5;
  3309. } else if (os_strncmp(buf, "RELOG", 5) == 0) {
  3310. if (wpa_debug_reopen_file() < 0)
  3311. reply_len = -1;
  3312. } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
  3313. wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
  3314. } else if (os_strcmp(buf, "MIB") == 0) {
  3315. reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
  3316. if (reply_len >= 0) {
  3317. int res;
  3318. res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
  3319. reply_size - reply_len);
  3320. if (res < 0)
  3321. reply_len = -1;
  3322. else
  3323. reply_len += res;
  3324. }
  3325. } else if (os_strncmp(buf, "STATUS", 6) == 0) {
  3326. reply_len = wpa_supplicant_ctrl_iface_status(
  3327. wpa_s, buf + 6, reply, reply_size);
  3328. } else if (os_strcmp(buf, "PMKSA") == 0) {
  3329. reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
  3330. reply_size);
  3331. } else if (os_strncmp(buf, "SET ", 4) == 0) {
  3332. if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
  3333. reply_len = -1;
  3334. } else if (os_strncmp(buf, "GET ", 4) == 0) {
  3335. reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
  3336. reply, reply_size);
  3337. } else if (os_strcmp(buf, "LOGON") == 0) {
  3338. eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
  3339. } else if (os_strcmp(buf, "LOGOFF") == 0) {
  3340. eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
  3341. } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
  3342. wpa_s->normal_scans = 0;
  3343. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3344. reply_len = -1;
  3345. else {
  3346. wpa_s->disconnected = 0;
  3347. wpa_s->reassociate = 1;
  3348. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3349. }
  3350. } else if (os_strcmp(buf, "RECONNECT") == 0) {
  3351. wpa_s->normal_scans = 0;
  3352. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3353. reply_len = -1;
  3354. else if (wpa_s->disconnected) {
  3355. wpa_s->disconnected = 0;
  3356. wpa_s->reassociate = 1;
  3357. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3358. }
  3359. #ifdef IEEE8021X_EAPOL
  3360. } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
  3361. if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
  3362. reply_len = -1;
  3363. #endif /* IEEE8021X_EAPOL */
  3364. #ifdef CONFIG_PEERKEY
  3365. } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
  3366. if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
  3367. reply_len = -1;
  3368. #endif /* CONFIG_PEERKEY */
  3369. #ifdef CONFIG_IEEE80211R
  3370. } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
  3371. if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
  3372. reply_len = -1;
  3373. #endif /* CONFIG_IEEE80211R */
  3374. #ifdef CONFIG_WPS
  3375. } else if (os_strcmp(buf, "WPS_PBC") == 0) {
  3376. int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
  3377. if (res == -2) {
  3378. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  3379. reply_len = 17;
  3380. } else if (res)
  3381. reply_len = -1;
  3382. } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
  3383. int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
  3384. if (res == -2) {
  3385. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  3386. reply_len = 17;
  3387. } else if (res)
  3388. reply_len = -1;
  3389. } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
  3390. reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
  3391. reply,
  3392. reply_size);
  3393. } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
  3394. reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
  3395. wpa_s, buf + 14, reply, reply_size);
  3396. } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
  3397. if (wpas_wps_cancel(wpa_s))
  3398. reply_len = -1;
  3399. #ifdef CONFIG_WPS_OOB
  3400. } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
  3401. if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8))
  3402. reply_len = -1;
  3403. #endif /* CONFIG_WPS_OOB */
  3404. } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
  3405. if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
  3406. reply_len = -1;
  3407. #ifdef CONFIG_AP
  3408. } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
  3409. reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
  3410. wpa_s, buf + 11, reply, reply_size);
  3411. #endif /* CONFIG_AP */
  3412. #ifdef CONFIG_WPS_ER
  3413. } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
  3414. if (wpas_wps_er_start(wpa_s, NULL))
  3415. reply_len = -1;
  3416. } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
  3417. if (wpas_wps_er_start(wpa_s, buf + 13))
  3418. reply_len = -1;
  3419. } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
  3420. if (wpas_wps_er_stop(wpa_s))
  3421. reply_len = -1;
  3422. } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
  3423. if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
  3424. reply_len = -1;
  3425. } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
  3426. int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
  3427. if (ret == -2) {
  3428. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  3429. reply_len = 17;
  3430. } else if (ret == -3) {
  3431. os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
  3432. reply_len = 18;
  3433. } else if (ret == -4) {
  3434. os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
  3435. reply_len = 20;
  3436. } else if (ret)
  3437. reply_len = -1;
  3438. } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
  3439. if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
  3440. reply_len = -1;
  3441. } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
  3442. if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
  3443. buf + 18))
  3444. reply_len = -1;
  3445. } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
  3446. if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
  3447. reply_len = -1;
  3448. #endif /* CONFIG_WPS_ER */
  3449. #endif /* CONFIG_WPS */
  3450. #ifdef CONFIG_IBSS_RSN
  3451. } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
  3452. if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
  3453. reply_len = -1;
  3454. #endif /* CONFIG_IBSS_RSN */
  3455. #ifdef CONFIG_P2P
  3456. } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
  3457. if (p2p_ctrl_find(wpa_s, buf + 9))
  3458. reply_len = -1;
  3459. } else if (os_strcmp(buf, "P2P_FIND") == 0) {
  3460. if (p2p_ctrl_find(wpa_s, ""))
  3461. reply_len = -1;
  3462. } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
  3463. wpas_p2p_stop_find(wpa_s);
  3464. } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
  3465. reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
  3466. reply_size);
  3467. } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
  3468. if (p2p_ctrl_listen(wpa_s, buf + 11))
  3469. reply_len = -1;
  3470. } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
  3471. if (p2p_ctrl_listen(wpa_s, ""))
  3472. reply_len = -1;
  3473. } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
  3474. if (wpas_p2p_group_remove(wpa_s, buf + 17))
  3475. reply_len = -1;
  3476. } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
  3477. if (wpas_p2p_group_add(wpa_s, 0, 0))
  3478. reply_len = -1;
  3479. } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
  3480. if (p2p_ctrl_group_add(wpa_s, buf + 14))
  3481. reply_len = -1;
  3482. } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
  3483. if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
  3484. reply_len = -1;
  3485. } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
  3486. reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
  3487. } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
  3488. reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
  3489. reply_size);
  3490. } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
  3491. if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
  3492. reply_len = -1;
  3493. } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
  3494. if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
  3495. reply_len = -1;
  3496. } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
  3497. wpas_p2p_sd_service_update(wpa_s);
  3498. } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
  3499. if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
  3500. reply_len = -1;
  3501. } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
  3502. wpas_p2p_service_flush(wpa_s);
  3503. } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
  3504. if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
  3505. reply_len = -1;
  3506. } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
  3507. if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
  3508. reply_len = -1;
  3509. } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
  3510. if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
  3511. reply_len = -1;
  3512. } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
  3513. if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
  3514. reply_len = -1;
  3515. } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
  3516. reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
  3517. reply_size);
  3518. } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
  3519. if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
  3520. reply_len = -1;
  3521. } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
  3522. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  3523. wpa_s->force_long_sd = 0;
  3524. if (wpa_s->global->p2p)
  3525. p2p_flush(wpa_s->global->p2p);
  3526. } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
  3527. if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
  3528. reply_len = -1;
  3529. } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
  3530. if (wpas_p2p_cancel(wpa_s))
  3531. reply_len = -1;
  3532. } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
  3533. if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
  3534. reply_len = -1;
  3535. } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
  3536. if (p2p_ctrl_presence_req(wpa_s, "") < 0)
  3537. reply_len = -1;
  3538. } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
  3539. if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
  3540. reply_len = -1;
  3541. } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
  3542. if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
  3543. reply_len = -1;
  3544. #endif /* CONFIG_P2P */
  3545. #ifdef CONFIG_INTERWORKING
  3546. } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
  3547. if (interworking_fetch_anqp(wpa_s) < 0)
  3548. reply_len = -1;
  3549. } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
  3550. interworking_stop_fetch_anqp(wpa_s);
  3551. } else if (os_strncmp(buf, "INTERWORKING_SELECT", 19) == 0) {
  3552. if (interworking_select(wpa_s, os_strstr(buf + 19, "auto") !=
  3553. NULL) < 0)
  3554. reply_len = -1;
  3555. } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
  3556. if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
  3557. reply_len = -1;
  3558. } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
  3559. if (get_anqp(wpa_s, buf + 9) < 0)
  3560. reply_len = -1;
  3561. #endif /* CONFIG_INTERWORKING */
  3562. #ifdef CONFIG_HS20
  3563. } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
  3564. if (get_hs20_anqp(wpa_s, buf + 14) < 0)
  3565. reply_len = -1;
  3566. } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
  3567. if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
  3568. reply_len = -1;
  3569. #endif /* CONFIG_HS20 */
  3570. } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
  3571. {
  3572. if (wpa_supplicant_ctrl_iface_ctrl_rsp(
  3573. wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
  3574. reply_len = -1;
  3575. else
  3576. ctrl_rsp = 1;
  3577. } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
  3578. if (wpa_supplicant_reload_configuration(wpa_s))
  3579. reply_len = -1;
  3580. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  3581. wpa_supplicant_terminate_proc(wpa_s->global);
  3582. } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
  3583. if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
  3584. reply_len = -1;
  3585. } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
  3586. reply_len = wpa_supplicant_ctrl_iface_blacklist(
  3587. wpa_s, buf + 9, reply, reply_size);
  3588. } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
  3589. reply_len = wpa_supplicant_ctrl_iface_log_level(
  3590. wpa_s, buf + 9, reply, reply_size);
  3591. } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
  3592. reply_len = wpa_supplicant_ctrl_iface_list_networks(
  3593. wpa_s, reply, reply_size);
  3594. } else if (os_strcmp(buf, "DISCONNECT") == 0) {
  3595. #ifdef CONFIG_SME
  3596. wpa_s->sme.prev_bssid_set = 0;
  3597. #endif /* CONFIG_SME */
  3598. wpa_s->reassociate = 0;
  3599. wpa_s->disconnected = 1;
  3600. wpa_supplicant_cancel_sched_scan(wpa_s);
  3601. wpa_supplicant_deauthenticate(wpa_s,
  3602. WLAN_REASON_DEAUTH_LEAVING);
  3603. } else if (os_strcmp(buf, "SCAN") == 0) {
  3604. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3605. reply_len = -1;
  3606. else {
  3607. if (!wpa_s->scanning &&
  3608. ((wpa_s->wpa_state <= WPA_SCANNING) ||
  3609. (wpa_s->wpa_state == WPA_COMPLETED))) {
  3610. wpa_s->normal_scans = 0;
  3611. wpa_s->scan_req = 2;
  3612. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3613. } else if (wpa_s->sched_scanning) {
  3614. wpa_printf(MSG_DEBUG, "Stop ongoing "
  3615. "sched_scan to allow requested "
  3616. "full scan to proceed");
  3617. wpa_supplicant_cancel_sched_scan(wpa_s);
  3618. wpa_s->scan_req = 2;
  3619. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3620. } else {
  3621. wpa_printf(MSG_DEBUG, "Ongoing scan action - "
  3622. "reject new request");
  3623. reply_len = os_snprintf(reply, reply_size,
  3624. "FAIL-BUSY\n");
  3625. }
  3626. }
  3627. } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
  3628. reply_len = wpa_supplicant_ctrl_iface_scan_results(
  3629. wpa_s, reply, reply_size);
  3630. } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
  3631. if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
  3632. reply_len = -1;
  3633. } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
  3634. if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
  3635. reply_len = -1;
  3636. } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
  3637. if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
  3638. reply_len = -1;
  3639. } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
  3640. reply_len = wpa_supplicant_ctrl_iface_add_network(
  3641. wpa_s, reply, reply_size);
  3642. } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
  3643. if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
  3644. reply_len = -1;
  3645. } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  3646. if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
  3647. reply_len = -1;
  3648. } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
  3649. reply_len = wpa_supplicant_ctrl_iface_get_network(
  3650. wpa_s, buf + 12, reply, reply_size);
  3651. } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
  3652. reply_len = wpa_supplicant_ctrl_iface_list_creds(
  3653. wpa_s, reply, reply_size);
  3654. } else if (os_strcmp(buf, "ADD_CRED") == 0) {
  3655. reply_len = wpa_supplicant_ctrl_iface_add_cred(
  3656. wpa_s, reply, reply_size);
  3657. } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
  3658. if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
  3659. reply_len = -1;
  3660. } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
  3661. if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
  3662. reply_len = -1;
  3663. #ifndef CONFIG_NO_CONFIG_WRITE
  3664. } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
  3665. if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
  3666. reply_len = -1;
  3667. #endif /* CONFIG_NO_CONFIG_WRITE */
  3668. } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
  3669. reply_len = wpa_supplicant_ctrl_iface_get_capability(
  3670. wpa_s, buf + 15, reply, reply_size);
  3671. } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
  3672. if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
  3673. reply_len = -1;
  3674. } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
  3675. if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
  3676. reply_len = -1;
  3677. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  3678. reply_len = wpa_supplicant_global_iface_list(
  3679. wpa_s->global, reply, reply_size);
  3680. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  3681. reply_len = wpa_supplicant_global_iface_interfaces(
  3682. wpa_s->global, reply, reply_size);
  3683. } else if (os_strncmp(buf, "BSS ", 4) == 0) {
  3684. reply_len = wpa_supplicant_ctrl_iface_bss(
  3685. wpa_s, buf + 4, reply, reply_size);
  3686. #ifdef CONFIG_AP
  3687. } else if (os_strcmp(buf, "STA-FIRST") == 0) {
  3688. reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
  3689. } else if (os_strncmp(buf, "STA ", 4) == 0) {
  3690. reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
  3691. reply_size);
  3692. } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
  3693. reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
  3694. reply_size);
  3695. } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
  3696. if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
  3697. reply_len = -1;
  3698. } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
  3699. if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
  3700. reply_len = -1;
  3701. #endif /* CONFIG_AP */
  3702. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  3703. wpas_notify_suspend(wpa_s->global);
  3704. } else if (os_strcmp(buf, "RESUME") == 0) {
  3705. wpas_notify_resume(wpa_s->global);
  3706. } else if (os_strcmp(buf, "DROP_SA") == 0) {
  3707. wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
  3708. } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
  3709. if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
  3710. reply_len = -1;
  3711. } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
  3712. if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
  3713. reply_len = -1;
  3714. } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
  3715. if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
  3716. reply_len = -1;
  3717. } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
  3718. if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
  3719. buf + 17))
  3720. reply_len = -1;
  3721. #ifdef CONFIG_TDLS
  3722. } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
  3723. if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
  3724. reply_len = -1;
  3725. } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
  3726. if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
  3727. reply_len = -1;
  3728. } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
  3729. if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
  3730. reply_len = -1;
  3731. #endif /* CONFIG_TDLS */
  3732. } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
  3733. reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
  3734. reply_size);
  3735. } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
  3736. eapol_sm_request_reauth(wpa_s->eapol);
  3737. } else {
  3738. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  3739. reply_len = 16;
  3740. }
  3741. if (reply_len < 0) {
  3742. os_memcpy(reply, "FAIL\n", 5);
  3743. reply_len = 5;
  3744. }
  3745. if (ctrl_rsp)
  3746. eapol_sm_notify_ctrl_response(wpa_s->eapol);
  3747. *resp_len = reply_len;
  3748. return reply;
  3749. }
  3750. static int wpa_supplicant_global_iface_add(struct wpa_global *global,
  3751. char *cmd)
  3752. {
  3753. struct wpa_interface iface;
  3754. char *pos;
  3755. /*
  3756. * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
  3757. * TAB<bridge_ifname>
  3758. */
  3759. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
  3760. os_memset(&iface, 0, sizeof(iface));
  3761. do {
  3762. iface.ifname = pos = cmd;
  3763. pos = os_strchr(pos, '\t');
  3764. if (pos)
  3765. *pos++ = '\0';
  3766. if (iface.ifname[0] == '\0')
  3767. return -1;
  3768. if (pos == NULL)
  3769. break;
  3770. iface.confname = pos;
  3771. pos = os_strchr(pos, '\t');
  3772. if (pos)
  3773. *pos++ = '\0';
  3774. if (iface.confname[0] == '\0')
  3775. iface.confname = NULL;
  3776. if (pos == NULL)
  3777. break;
  3778. iface.driver = pos;
  3779. pos = os_strchr(pos, '\t');
  3780. if (pos)
  3781. *pos++ = '\0';
  3782. if (iface.driver[0] == '\0')
  3783. iface.driver = NULL;
  3784. if (pos == NULL)
  3785. break;
  3786. iface.ctrl_interface = pos;
  3787. pos = os_strchr(pos, '\t');
  3788. if (pos)
  3789. *pos++ = '\0';
  3790. if (iface.ctrl_interface[0] == '\0')
  3791. iface.ctrl_interface = NULL;
  3792. if (pos == NULL)
  3793. break;
  3794. iface.driver_param = pos;
  3795. pos = os_strchr(pos, '\t');
  3796. if (pos)
  3797. *pos++ = '\0';
  3798. if (iface.driver_param[0] == '\0')
  3799. iface.driver_param = NULL;
  3800. if (pos == NULL)
  3801. break;
  3802. iface.bridge_ifname = pos;
  3803. pos = os_strchr(pos, '\t');
  3804. if (pos)
  3805. *pos++ = '\0';
  3806. if (iface.bridge_ifname[0] == '\0')
  3807. iface.bridge_ifname = NULL;
  3808. if (pos == NULL)
  3809. break;
  3810. } while (0);
  3811. if (wpa_supplicant_get_iface(global, iface.ifname))
  3812. return -1;
  3813. return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
  3814. }
  3815. static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
  3816. char *cmd)
  3817. {
  3818. struct wpa_supplicant *wpa_s;
  3819. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
  3820. wpa_s = wpa_supplicant_get_iface(global, cmd);
  3821. if (wpa_s == NULL)
  3822. return -1;
  3823. return wpa_supplicant_remove_iface(global, wpa_s, 0);
  3824. }
  3825. static void wpa_free_iface_info(struct wpa_interface_info *iface)
  3826. {
  3827. struct wpa_interface_info *prev;
  3828. while (iface) {
  3829. prev = iface;
  3830. iface = iface->next;
  3831. os_free(prev->ifname);
  3832. os_free(prev->desc);
  3833. os_free(prev);
  3834. }
  3835. }
  3836. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  3837. char *buf, int len)
  3838. {
  3839. int i, res;
  3840. struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
  3841. char *pos, *end;
  3842. for (i = 0; wpa_drivers[i]; i++) {
  3843. struct wpa_driver_ops *drv = wpa_drivers[i];
  3844. if (drv->get_interfaces == NULL)
  3845. continue;
  3846. tmp = drv->get_interfaces(global->drv_priv[i]);
  3847. if (tmp == NULL)
  3848. continue;
  3849. if (last == NULL)
  3850. iface = last = tmp;
  3851. else
  3852. last->next = tmp;
  3853. while (last->next)
  3854. last = last->next;
  3855. }
  3856. pos = buf;
  3857. end = buf + len;
  3858. for (tmp = iface; tmp; tmp = tmp->next) {
  3859. res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
  3860. tmp->drv_name, tmp->ifname,
  3861. tmp->desc ? tmp->desc : "");
  3862. if (res < 0 || res >= end - pos) {
  3863. *pos = '\0';
  3864. break;
  3865. }
  3866. pos += res;
  3867. }
  3868. wpa_free_iface_info(iface);
  3869. return pos - buf;
  3870. }
  3871. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  3872. char *buf, int len)
  3873. {
  3874. int res;
  3875. char *pos, *end;
  3876. struct wpa_supplicant *wpa_s;
  3877. wpa_s = global->ifaces;
  3878. pos = buf;
  3879. end = buf + len;
  3880. while (wpa_s) {
  3881. res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
  3882. if (res < 0 || res >= end - pos) {
  3883. *pos = '\0';
  3884. break;
  3885. }
  3886. pos += res;
  3887. wpa_s = wpa_s->next;
  3888. }
  3889. return pos - buf;
  3890. }
  3891. char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
  3892. char *buf, size_t *resp_len)
  3893. {
  3894. char *reply;
  3895. const int reply_size = 2048;
  3896. int reply_len;
  3897. int level = MSG_DEBUG;
  3898. if (os_strcmp(buf, "PING") == 0)
  3899. level = MSG_EXCESSIVE;
  3900. wpa_hexdump_ascii(level, "RX global ctrl_iface",
  3901. (const u8 *) buf, os_strlen(buf));
  3902. reply = os_malloc(reply_size);
  3903. if (reply == NULL) {
  3904. *resp_len = 1;
  3905. return NULL;
  3906. }
  3907. os_memcpy(reply, "OK\n", 3);
  3908. reply_len = 3;
  3909. if (os_strcmp(buf, "PING") == 0) {
  3910. os_memcpy(reply, "PONG\n", 5);
  3911. reply_len = 5;
  3912. } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
  3913. if (wpa_supplicant_global_iface_add(global, buf + 14))
  3914. reply_len = -1;
  3915. } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
  3916. if (wpa_supplicant_global_iface_remove(global, buf + 17))
  3917. reply_len = -1;
  3918. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  3919. reply_len = wpa_supplicant_global_iface_list(
  3920. global, reply, reply_size);
  3921. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  3922. reply_len = wpa_supplicant_global_iface_interfaces(
  3923. global, reply, reply_size);
  3924. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  3925. wpa_supplicant_terminate_proc(global);
  3926. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  3927. wpas_notify_suspend(global);
  3928. } else if (os_strcmp(buf, "RESUME") == 0) {
  3929. wpas_notify_resume(global);
  3930. } else {
  3931. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  3932. reply_len = 16;
  3933. }
  3934. if (reply_len < 0) {
  3935. os_memcpy(reply, "FAIL\n", 5);
  3936. reply_len = 5;
  3937. }
  3938. *resp_len = reply_len;
  3939. return reply;
  3940. }