ctrl_iface.c 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597
  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, "conc_pref") == 0) {
  3028. if (os_strcmp(param, "sta") == 0)
  3029. wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
  3030. else if (os_strcmp(param, "p2p") == 0)
  3031. wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
  3032. else {
  3033. wpa_printf(MSG_INFO, "Invalid conc_pref value");
  3034. return -1;
  3035. }
  3036. wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
  3037. "%s", param);
  3038. return 0;
  3039. }
  3040. if (os_strcmp(cmd, "force_long_sd") == 0) {
  3041. wpa_s->force_long_sd = atoi(param);
  3042. return 0;
  3043. }
  3044. if (os_strcmp(cmd, "peer_filter") == 0) {
  3045. u8 addr[ETH_ALEN];
  3046. if (hwaddr_aton(param, addr))
  3047. return -1;
  3048. p2p_set_peer_filter(wpa_s->global->p2p, addr);
  3049. return 0;
  3050. }
  3051. if (os_strcmp(cmd, "cross_connect") == 0)
  3052. return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
  3053. if (os_strcmp(cmd, "go_apsd") == 0) {
  3054. if (os_strcmp(param, "disable") == 0)
  3055. wpa_s->set_ap_uapsd = 0;
  3056. else {
  3057. wpa_s->set_ap_uapsd = 1;
  3058. wpa_s->ap_uapsd = atoi(param);
  3059. }
  3060. return 0;
  3061. }
  3062. if (os_strcmp(cmd, "client_apsd") == 0) {
  3063. if (os_strcmp(param, "disable") == 0)
  3064. wpa_s->set_sta_uapsd = 0;
  3065. else {
  3066. int be, bk, vi, vo;
  3067. char *pos;
  3068. /* format: BE,BK,VI,VO;max SP Length */
  3069. be = atoi(param);
  3070. pos = os_strchr(param, ',');
  3071. if (pos == NULL)
  3072. return -1;
  3073. pos++;
  3074. bk = atoi(pos);
  3075. pos = os_strchr(pos, ',');
  3076. if (pos == NULL)
  3077. return -1;
  3078. pos++;
  3079. vi = atoi(pos);
  3080. pos = os_strchr(pos, ',');
  3081. if (pos == NULL)
  3082. return -1;
  3083. pos++;
  3084. vo = atoi(pos);
  3085. /* ignore max SP Length for now */
  3086. wpa_s->set_sta_uapsd = 1;
  3087. wpa_s->sta_uapsd = 0;
  3088. if (be)
  3089. wpa_s->sta_uapsd |= BIT(0);
  3090. if (bk)
  3091. wpa_s->sta_uapsd |= BIT(1);
  3092. if (vi)
  3093. wpa_s->sta_uapsd |= BIT(2);
  3094. if (vo)
  3095. wpa_s->sta_uapsd |= BIT(3);
  3096. }
  3097. return 0;
  3098. }
  3099. if (os_strcmp(cmd, "disallow_freq") == 0)
  3100. return p2p_ctrl_disallow_freq(wpa_s, param);
  3101. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
  3102. cmd);
  3103. return -1;
  3104. }
  3105. static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
  3106. {
  3107. char *pos, *pos2;
  3108. unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
  3109. if (cmd[0]) {
  3110. pos = os_strchr(cmd, ' ');
  3111. if (pos == NULL)
  3112. return -1;
  3113. *pos++ = '\0';
  3114. dur1 = atoi(cmd);
  3115. pos2 = os_strchr(pos, ' ');
  3116. if (pos2)
  3117. *pos2++ = '\0';
  3118. int1 = atoi(pos);
  3119. } else
  3120. pos2 = NULL;
  3121. if (pos2) {
  3122. pos = os_strchr(pos2, ' ');
  3123. if (pos == NULL)
  3124. return -1;
  3125. *pos++ = '\0';
  3126. dur2 = atoi(pos2);
  3127. int2 = atoi(pos);
  3128. }
  3129. return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
  3130. }
  3131. static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
  3132. {
  3133. char *pos;
  3134. unsigned int period = 0, interval = 0;
  3135. if (cmd[0]) {
  3136. pos = os_strchr(cmd, ' ');
  3137. if (pos == NULL)
  3138. return -1;
  3139. *pos++ = '\0';
  3140. period = atoi(cmd);
  3141. interval = atoi(pos);
  3142. }
  3143. return wpas_p2p_ext_listen(wpa_s, period, interval);
  3144. }
  3145. #endif /* CONFIG_P2P */
  3146. #ifdef CONFIG_INTERWORKING
  3147. static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
  3148. {
  3149. u8 bssid[ETH_ALEN];
  3150. struct wpa_bss *bss;
  3151. if (hwaddr_aton(dst, bssid)) {
  3152. wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
  3153. return -1;
  3154. }
  3155. bss = wpa_bss_get_bssid(wpa_s, bssid);
  3156. if (bss == NULL) {
  3157. wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
  3158. MAC2STR(bssid));
  3159. return -1;
  3160. }
  3161. return interworking_connect(wpa_s, bss);
  3162. }
  3163. static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
  3164. {
  3165. u8 dst_addr[ETH_ALEN];
  3166. int used;
  3167. char *pos;
  3168. #define MAX_ANQP_INFO_ID 100
  3169. u16 id[MAX_ANQP_INFO_ID];
  3170. size_t num_id = 0;
  3171. used = hwaddr_aton2(dst, dst_addr);
  3172. if (used < 0)
  3173. return -1;
  3174. pos = dst + used;
  3175. while (num_id < MAX_ANQP_INFO_ID) {
  3176. id[num_id] = atoi(pos);
  3177. if (id[num_id])
  3178. num_id++;
  3179. pos = os_strchr(pos + 1, ',');
  3180. if (pos == NULL)
  3181. break;
  3182. pos++;
  3183. }
  3184. if (num_id == 0)
  3185. return -1;
  3186. return anqp_send_req(wpa_s, dst_addr, id, num_id);
  3187. }
  3188. #endif /* CONFIG_INTERWORKING */
  3189. #ifdef CONFIG_HS20
  3190. static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
  3191. {
  3192. u8 dst_addr[ETH_ALEN];
  3193. int used;
  3194. char *pos;
  3195. u32 subtypes = 0;
  3196. used = hwaddr_aton2(dst, dst_addr);
  3197. if (used < 0)
  3198. return -1;
  3199. pos = dst + used;
  3200. for (;;) {
  3201. int num = atoi(pos);
  3202. if (num <= 0 || num > 31)
  3203. return -1;
  3204. subtypes |= BIT(num);
  3205. pos = os_strchr(pos + 1, ',');
  3206. if (pos == NULL)
  3207. break;
  3208. pos++;
  3209. }
  3210. if (subtypes == 0)
  3211. return -1;
  3212. return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
  3213. }
  3214. static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
  3215. const u8 *addr, const char *realm)
  3216. {
  3217. u8 *buf;
  3218. size_t rlen, len;
  3219. int ret;
  3220. rlen = os_strlen(realm);
  3221. len = 3 + rlen;
  3222. buf = os_malloc(len);
  3223. if (buf == NULL)
  3224. return -1;
  3225. buf[0] = 1; /* NAI Home Realm Count */
  3226. buf[1] = 0; /* Formatted in accordance with RFC 4282 */
  3227. buf[2] = rlen;
  3228. os_memcpy(buf + 3, realm, rlen);
  3229. ret = hs20_anqp_send_req(wpa_s, addr,
  3230. BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
  3231. buf, len);
  3232. os_free(buf);
  3233. return ret;
  3234. }
  3235. static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
  3236. char *dst)
  3237. {
  3238. struct wpa_cred *cred = wpa_s->conf->cred;
  3239. u8 dst_addr[ETH_ALEN];
  3240. int used;
  3241. u8 *buf;
  3242. size_t len;
  3243. int ret;
  3244. used = hwaddr_aton2(dst, dst_addr);
  3245. if (used < 0)
  3246. return -1;
  3247. while (dst[used] == ' ')
  3248. used++;
  3249. if (os_strncmp(dst + used, "realm=", 6) == 0)
  3250. return hs20_nai_home_realm_list(wpa_s, dst_addr,
  3251. dst + used + 6);
  3252. len = os_strlen(dst + used);
  3253. if (len == 0 && cred && cred->realm)
  3254. return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
  3255. if (len % 1)
  3256. return -1;
  3257. len /= 2;
  3258. buf = os_malloc(len);
  3259. if (buf == NULL)
  3260. return -1;
  3261. if (hexstr2bin(dst + used, buf, len) < 0) {
  3262. os_free(buf);
  3263. return -1;
  3264. }
  3265. ret = hs20_anqp_send_req(wpa_s, dst_addr,
  3266. BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
  3267. buf, len);
  3268. os_free(buf);
  3269. return ret;
  3270. }
  3271. #endif /* CONFIG_HS20 */
  3272. static int wpa_supplicant_ctrl_iface_sta_autoconnect(
  3273. struct wpa_supplicant *wpa_s, char *cmd)
  3274. {
  3275. wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
  3276. return 0;
  3277. }
  3278. static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
  3279. size_t buflen)
  3280. {
  3281. struct wpa_signal_info si;
  3282. int ret;
  3283. ret = wpa_drv_signal_poll(wpa_s, &si);
  3284. if (ret)
  3285. return -1;
  3286. ret = os_snprintf(buf, buflen, "RSSI=%d\nLINKSPEED=%d\n"
  3287. "NOISE=%d\nFREQUENCY=%u\n",
  3288. si.current_signal, si.current_txrate / 1000,
  3289. si.current_noise, si.frequency);
  3290. if (ret < 0 || (unsigned int) ret > buflen)
  3291. return -1;
  3292. return ret;
  3293. }
  3294. char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
  3295. char *buf, size_t *resp_len)
  3296. {
  3297. char *reply;
  3298. const int reply_size = 4096;
  3299. int ctrl_rsp = 0;
  3300. int reply_len;
  3301. if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
  3302. os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  3303. wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
  3304. (const u8 *) buf, os_strlen(buf));
  3305. } else {
  3306. int level = MSG_DEBUG;
  3307. if (os_strcmp(buf, "PING") == 0)
  3308. level = MSG_EXCESSIVE;
  3309. wpa_hexdump_ascii(level, "RX ctrl_iface",
  3310. (const u8 *) buf, os_strlen(buf));
  3311. }
  3312. reply = os_malloc(reply_size);
  3313. if (reply == NULL) {
  3314. *resp_len = 1;
  3315. return NULL;
  3316. }
  3317. os_memcpy(reply, "OK\n", 3);
  3318. reply_len = 3;
  3319. if (os_strcmp(buf, "PING") == 0) {
  3320. os_memcpy(reply, "PONG\n", 5);
  3321. reply_len = 5;
  3322. } else if (os_strncmp(buf, "RELOG", 5) == 0) {
  3323. if (wpa_debug_reopen_file() < 0)
  3324. reply_len = -1;
  3325. } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
  3326. wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
  3327. } else if (os_strcmp(buf, "MIB") == 0) {
  3328. reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
  3329. if (reply_len >= 0) {
  3330. int res;
  3331. res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
  3332. reply_size - reply_len);
  3333. if (res < 0)
  3334. reply_len = -1;
  3335. else
  3336. reply_len += res;
  3337. }
  3338. } else if (os_strncmp(buf, "STATUS", 6) == 0) {
  3339. reply_len = wpa_supplicant_ctrl_iface_status(
  3340. wpa_s, buf + 6, reply, reply_size);
  3341. } else if (os_strcmp(buf, "PMKSA") == 0) {
  3342. reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
  3343. reply_size);
  3344. } else if (os_strncmp(buf, "SET ", 4) == 0) {
  3345. if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
  3346. reply_len = -1;
  3347. } else if (os_strncmp(buf, "GET ", 4) == 0) {
  3348. reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
  3349. reply, reply_size);
  3350. } else if (os_strcmp(buf, "LOGON") == 0) {
  3351. eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
  3352. } else if (os_strcmp(buf, "LOGOFF") == 0) {
  3353. eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
  3354. } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
  3355. wpa_s->normal_scans = 0;
  3356. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3357. reply_len = -1;
  3358. else {
  3359. wpa_s->disconnected = 0;
  3360. wpa_s->reassociate = 1;
  3361. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3362. }
  3363. } else if (os_strcmp(buf, "RECONNECT") == 0) {
  3364. wpa_s->normal_scans = 0;
  3365. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3366. reply_len = -1;
  3367. else if (wpa_s->disconnected) {
  3368. wpa_s->disconnected = 0;
  3369. wpa_s->reassociate = 1;
  3370. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3371. }
  3372. #ifdef IEEE8021X_EAPOL
  3373. } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
  3374. if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
  3375. reply_len = -1;
  3376. #endif /* IEEE8021X_EAPOL */
  3377. #ifdef CONFIG_PEERKEY
  3378. } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
  3379. if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
  3380. reply_len = -1;
  3381. #endif /* CONFIG_PEERKEY */
  3382. #ifdef CONFIG_IEEE80211R
  3383. } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
  3384. if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
  3385. reply_len = -1;
  3386. #endif /* CONFIG_IEEE80211R */
  3387. #ifdef CONFIG_WPS
  3388. } else if (os_strcmp(buf, "WPS_PBC") == 0) {
  3389. int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
  3390. if (res == -2) {
  3391. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  3392. reply_len = 17;
  3393. } else if (res)
  3394. reply_len = -1;
  3395. } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
  3396. int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
  3397. if (res == -2) {
  3398. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  3399. reply_len = 17;
  3400. } else if (res)
  3401. reply_len = -1;
  3402. } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
  3403. reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
  3404. reply,
  3405. reply_size);
  3406. } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
  3407. reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
  3408. wpa_s, buf + 14, reply, reply_size);
  3409. } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
  3410. if (wpas_wps_cancel(wpa_s))
  3411. reply_len = -1;
  3412. #ifdef CONFIG_WPS_OOB
  3413. } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
  3414. if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8))
  3415. reply_len = -1;
  3416. #endif /* CONFIG_WPS_OOB */
  3417. } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
  3418. if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
  3419. reply_len = -1;
  3420. #ifdef CONFIG_AP
  3421. } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
  3422. reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
  3423. wpa_s, buf + 11, reply, reply_size);
  3424. #endif /* CONFIG_AP */
  3425. #ifdef CONFIG_WPS_ER
  3426. } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
  3427. if (wpas_wps_er_start(wpa_s, NULL))
  3428. reply_len = -1;
  3429. } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
  3430. if (wpas_wps_er_start(wpa_s, buf + 13))
  3431. reply_len = -1;
  3432. } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
  3433. if (wpas_wps_er_stop(wpa_s))
  3434. reply_len = -1;
  3435. } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
  3436. if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
  3437. reply_len = -1;
  3438. } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
  3439. int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
  3440. if (ret == -2) {
  3441. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  3442. reply_len = 17;
  3443. } else if (ret == -3) {
  3444. os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
  3445. reply_len = 18;
  3446. } else if (ret == -4) {
  3447. os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
  3448. reply_len = 20;
  3449. } else if (ret)
  3450. reply_len = -1;
  3451. } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
  3452. if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
  3453. reply_len = -1;
  3454. } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
  3455. if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
  3456. buf + 18))
  3457. reply_len = -1;
  3458. } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
  3459. if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
  3460. reply_len = -1;
  3461. #endif /* CONFIG_WPS_ER */
  3462. #endif /* CONFIG_WPS */
  3463. #ifdef CONFIG_IBSS_RSN
  3464. } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
  3465. if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
  3466. reply_len = -1;
  3467. #endif /* CONFIG_IBSS_RSN */
  3468. #ifdef CONFIG_P2P
  3469. } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
  3470. if (p2p_ctrl_find(wpa_s, buf + 9))
  3471. reply_len = -1;
  3472. } else if (os_strcmp(buf, "P2P_FIND") == 0) {
  3473. if (p2p_ctrl_find(wpa_s, ""))
  3474. reply_len = -1;
  3475. } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
  3476. wpas_p2p_stop_find(wpa_s);
  3477. } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
  3478. reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
  3479. reply_size);
  3480. } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
  3481. if (p2p_ctrl_listen(wpa_s, buf + 11))
  3482. reply_len = -1;
  3483. } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
  3484. if (p2p_ctrl_listen(wpa_s, ""))
  3485. reply_len = -1;
  3486. } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
  3487. if (wpas_p2p_group_remove(wpa_s, buf + 17))
  3488. reply_len = -1;
  3489. } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
  3490. if (wpas_p2p_group_add(wpa_s, 0, 0))
  3491. reply_len = -1;
  3492. } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
  3493. if (p2p_ctrl_group_add(wpa_s, buf + 14))
  3494. reply_len = -1;
  3495. } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
  3496. if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
  3497. reply_len = -1;
  3498. } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
  3499. reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
  3500. } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
  3501. reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
  3502. reply_size);
  3503. } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
  3504. if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
  3505. reply_len = -1;
  3506. } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
  3507. if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
  3508. reply_len = -1;
  3509. } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
  3510. wpas_p2p_sd_service_update(wpa_s);
  3511. } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
  3512. if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
  3513. reply_len = -1;
  3514. } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
  3515. wpas_p2p_service_flush(wpa_s);
  3516. } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
  3517. if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
  3518. reply_len = -1;
  3519. } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
  3520. if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
  3521. reply_len = -1;
  3522. } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
  3523. if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
  3524. reply_len = -1;
  3525. } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
  3526. if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
  3527. reply_len = -1;
  3528. } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
  3529. reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
  3530. reply_size);
  3531. } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
  3532. if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
  3533. reply_len = -1;
  3534. } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
  3535. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  3536. wpa_s->force_long_sd = 0;
  3537. if (wpa_s->global->p2p)
  3538. p2p_flush(wpa_s->global->p2p);
  3539. } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
  3540. if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
  3541. reply_len = -1;
  3542. } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
  3543. if (wpas_p2p_cancel(wpa_s))
  3544. reply_len = -1;
  3545. } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
  3546. if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
  3547. reply_len = -1;
  3548. } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
  3549. if (p2p_ctrl_presence_req(wpa_s, "") < 0)
  3550. reply_len = -1;
  3551. } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
  3552. if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
  3553. reply_len = -1;
  3554. } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
  3555. if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
  3556. reply_len = -1;
  3557. #endif /* CONFIG_P2P */
  3558. #ifdef CONFIG_INTERWORKING
  3559. } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
  3560. if (interworking_fetch_anqp(wpa_s) < 0)
  3561. reply_len = -1;
  3562. } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
  3563. interworking_stop_fetch_anqp(wpa_s);
  3564. } else if (os_strncmp(buf, "INTERWORKING_SELECT", 19) == 0) {
  3565. if (interworking_select(wpa_s, os_strstr(buf + 19, "auto") !=
  3566. NULL) < 0)
  3567. reply_len = -1;
  3568. } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
  3569. if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
  3570. reply_len = -1;
  3571. } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
  3572. if (get_anqp(wpa_s, buf + 9) < 0)
  3573. reply_len = -1;
  3574. #endif /* CONFIG_INTERWORKING */
  3575. #ifdef CONFIG_HS20
  3576. } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
  3577. if (get_hs20_anqp(wpa_s, buf + 14) < 0)
  3578. reply_len = -1;
  3579. } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
  3580. if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
  3581. reply_len = -1;
  3582. #endif /* CONFIG_HS20 */
  3583. } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
  3584. {
  3585. if (wpa_supplicant_ctrl_iface_ctrl_rsp(
  3586. wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
  3587. reply_len = -1;
  3588. else
  3589. ctrl_rsp = 1;
  3590. } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
  3591. if (wpa_supplicant_reload_configuration(wpa_s))
  3592. reply_len = -1;
  3593. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  3594. wpa_supplicant_terminate_proc(wpa_s->global);
  3595. } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
  3596. if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
  3597. reply_len = -1;
  3598. } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
  3599. reply_len = wpa_supplicant_ctrl_iface_blacklist(
  3600. wpa_s, buf + 9, reply, reply_size);
  3601. } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
  3602. reply_len = wpa_supplicant_ctrl_iface_log_level(
  3603. wpa_s, buf + 9, reply, reply_size);
  3604. } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
  3605. reply_len = wpa_supplicant_ctrl_iface_list_networks(
  3606. wpa_s, reply, reply_size);
  3607. } else if (os_strcmp(buf, "DISCONNECT") == 0) {
  3608. #ifdef CONFIG_SME
  3609. wpa_s->sme.prev_bssid_set = 0;
  3610. #endif /* CONFIG_SME */
  3611. wpa_s->reassociate = 0;
  3612. wpa_s->disconnected = 1;
  3613. wpa_supplicant_cancel_sched_scan(wpa_s);
  3614. wpa_supplicant_deauthenticate(wpa_s,
  3615. WLAN_REASON_DEAUTH_LEAVING);
  3616. } else if (os_strcmp(buf, "SCAN") == 0) {
  3617. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3618. reply_len = -1;
  3619. else {
  3620. if (!wpa_s->scanning &&
  3621. ((wpa_s->wpa_state <= WPA_SCANNING) ||
  3622. (wpa_s->wpa_state == WPA_COMPLETED))) {
  3623. wpa_s->normal_scans = 0;
  3624. wpa_s->scan_req = 2;
  3625. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3626. } else if (wpa_s->sched_scanning) {
  3627. wpa_printf(MSG_DEBUG, "Stop ongoing "
  3628. "sched_scan to allow requested "
  3629. "full scan to proceed");
  3630. wpa_supplicant_cancel_sched_scan(wpa_s);
  3631. wpa_s->scan_req = 2;
  3632. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3633. } else {
  3634. wpa_printf(MSG_DEBUG, "Ongoing scan action - "
  3635. "reject new request");
  3636. reply_len = os_snprintf(reply, reply_size,
  3637. "FAIL-BUSY\n");
  3638. }
  3639. }
  3640. } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
  3641. reply_len = wpa_supplicant_ctrl_iface_scan_results(
  3642. wpa_s, reply, reply_size);
  3643. } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
  3644. if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
  3645. reply_len = -1;
  3646. } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
  3647. if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
  3648. reply_len = -1;
  3649. } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
  3650. if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
  3651. reply_len = -1;
  3652. } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
  3653. reply_len = wpa_supplicant_ctrl_iface_add_network(
  3654. wpa_s, reply, reply_size);
  3655. } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
  3656. if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
  3657. reply_len = -1;
  3658. } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  3659. if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
  3660. reply_len = -1;
  3661. } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
  3662. reply_len = wpa_supplicant_ctrl_iface_get_network(
  3663. wpa_s, buf + 12, reply, reply_size);
  3664. } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
  3665. reply_len = wpa_supplicant_ctrl_iface_list_creds(
  3666. wpa_s, reply, reply_size);
  3667. } else if (os_strcmp(buf, "ADD_CRED") == 0) {
  3668. reply_len = wpa_supplicant_ctrl_iface_add_cred(
  3669. wpa_s, reply, reply_size);
  3670. } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
  3671. if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
  3672. reply_len = -1;
  3673. } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
  3674. if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
  3675. reply_len = -1;
  3676. #ifndef CONFIG_NO_CONFIG_WRITE
  3677. } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
  3678. if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
  3679. reply_len = -1;
  3680. #endif /* CONFIG_NO_CONFIG_WRITE */
  3681. } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
  3682. reply_len = wpa_supplicant_ctrl_iface_get_capability(
  3683. wpa_s, buf + 15, reply, reply_size);
  3684. } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
  3685. if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
  3686. reply_len = -1;
  3687. } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
  3688. if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
  3689. reply_len = -1;
  3690. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  3691. reply_len = wpa_supplicant_global_iface_list(
  3692. wpa_s->global, reply, reply_size);
  3693. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  3694. reply_len = wpa_supplicant_global_iface_interfaces(
  3695. wpa_s->global, reply, reply_size);
  3696. } else if (os_strncmp(buf, "BSS ", 4) == 0) {
  3697. reply_len = wpa_supplicant_ctrl_iface_bss(
  3698. wpa_s, buf + 4, reply, reply_size);
  3699. #ifdef CONFIG_AP
  3700. } else if (os_strcmp(buf, "STA-FIRST") == 0) {
  3701. reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
  3702. } else if (os_strncmp(buf, "STA ", 4) == 0) {
  3703. reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
  3704. reply_size);
  3705. } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
  3706. reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
  3707. reply_size);
  3708. } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
  3709. if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
  3710. reply_len = -1;
  3711. } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
  3712. if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
  3713. reply_len = -1;
  3714. #endif /* CONFIG_AP */
  3715. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  3716. wpas_notify_suspend(wpa_s->global);
  3717. } else if (os_strcmp(buf, "RESUME") == 0) {
  3718. wpas_notify_resume(wpa_s->global);
  3719. } else if (os_strcmp(buf, "DROP_SA") == 0) {
  3720. wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
  3721. } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
  3722. if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
  3723. reply_len = -1;
  3724. } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
  3725. if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
  3726. reply_len = -1;
  3727. } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
  3728. if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
  3729. reply_len = -1;
  3730. } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
  3731. if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
  3732. buf + 17))
  3733. reply_len = -1;
  3734. #ifdef CONFIG_TDLS
  3735. } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
  3736. if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
  3737. reply_len = -1;
  3738. } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
  3739. if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
  3740. reply_len = -1;
  3741. } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
  3742. if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
  3743. reply_len = -1;
  3744. #endif /* CONFIG_TDLS */
  3745. } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
  3746. reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
  3747. reply_size);
  3748. } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
  3749. eapol_sm_request_reauth(wpa_s->eapol);
  3750. } else {
  3751. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  3752. reply_len = 16;
  3753. }
  3754. if (reply_len < 0) {
  3755. os_memcpy(reply, "FAIL\n", 5);
  3756. reply_len = 5;
  3757. }
  3758. if (ctrl_rsp)
  3759. eapol_sm_notify_ctrl_response(wpa_s->eapol);
  3760. *resp_len = reply_len;
  3761. return reply;
  3762. }
  3763. static int wpa_supplicant_global_iface_add(struct wpa_global *global,
  3764. char *cmd)
  3765. {
  3766. struct wpa_interface iface;
  3767. char *pos;
  3768. /*
  3769. * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
  3770. * TAB<bridge_ifname>
  3771. */
  3772. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
  3773. os_memset(&iface, 0, sizeof(iface));
  3774. do {
  3775. iface.ifname = pos = cmd;
  3776. pos = os_strchr(pos, '\t');
  3777. if (pos)
  3778. *pos++ = '\0';
  3779. if (iface.ifname[0] == '\0')
  3780. return -1;
  3781. if (pos == NULL)
  3782. break;
  3783. iface.confname = pos;
  3784. pos = os_strchr(pos, '\t');
  3785. if (pos)
  3786. *pos++ = '\0';
  3787. if (iface.confname[0] == '\0')
  3788. iface.confname = NULL;
  3789. if (pos == NULL)
  3790. break;
  3791. iface.driver = pos;
  3792. pos = os_strchr(pos, '\t');
  3793. if (pos)
  3794. *pos++ = '\0';
  3795. if (iface.driver[0] == '\0')
  3796. iface.driver = NULL;
  3797. if (pos == NULL)
  3798. break;
  3799. iface.ctrl_interface = pos;
  3800. pos = os_strchr(pos, '\t');
  3801. if (pos)
  3802. *pos++ = '\0';
  3803. if (iface.ctrl_interface[0] == '\0')
  3804. iface.ctrl_interface = NULL;
  3805. if (pos == NULL)
  3806. break;
  3807. iface.driver_param = pos;
  3808. pos = os_strchr(pos, '\t');
  3809. if (pos)
  3810. *pos++ = '\0';
  3811. if (iface.driver_param[0] == '\0')
  3812. iface.driver_param = NULL;
  3813. if (pos == NULL)
  3814. break;
  3815. iface.bridge_ifname = pos;
  3816. pos = os_strchr(pos, '\t');
  3817. if (pos)
  3818. *pos++ = '\0';
  3819. if (iface.bridge_ifname[0] == '\0')
  3820. iface.bridge_ifname = NULL;
  3821. if (pos == NULL)
  3822. break;
  3823. } while (0);
  3824. if (wpa_supplicant_get_iface(global, iface.ifname))
  3825. return -1;
  3826. return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
  3827. }
  3828. static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
  3829. char *cmd)
  3830. {
  3831. struct wpa_supplicant *wpa_s;
  3832. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
  3833. wpa_s = wpa_supplicant_get_iface(global, cmd);
  3834. if (wpa_s == NULL)
  3835. return -1;
  3836. return wpa_supplicant_remove_iface(global, wpa_s, 0);
  3837. }
  3838. static void wpa_free_iface_info(struct wpa_interface_info *iface)
  3839. {
  3840. struct wpa_interface_info *prev;
  3841. while (iface) {
  3842. prev = iface;
  3843. iface = iface->next;
  3844. os_free(prev->ifname);
  3845. os_free(prev->desc);
  3846. os_free(prev);
  3847. }
  3848. }
  3849. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  3850. char *buf, int len)
  3851. {
  3852. int i, res;
  3853. struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
  3854. char *pos, *end;
  3855. for (i = 0; wpa_drivers[i]; i++) {
  3856. struct wpa_driver_ops *drv = wpa_drivers[i];
  3857. if (drv->get_interfaces == NULL)
  3858. continue;
  3859. tmp = drv->get_interfaces(global->drv_priv[i]);
  3860. if (tmp == NULL)
  3861. continue;
  3862. if (last == NULL)
  3863. iface = last = tmp;
  3864. else
  3865. last->next = tmp;
  3866. while (last->next)
  3867. last = last->next;
  3868. }
  3869. pos = buf;
  3870. end = buf + len;
  3871. for (tmp = iface; tmp; tmp = tmp->next) {
  3872. res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
  3873. tmp->drv_name, tmp->ifname,
  3874. tmp->desc ? tmp->desc : "");
  3875. if (res < 0 || res >= end - pos) {
  3876. *pos = '\0';
  3877. break;
  3878. }
  3879. pos += res;
  3880. }
  3881. wpa_free_iface_info(iface);
  3882. return pos - buf;
  3883. }
  3884. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  3885. char *buf, int len)
  3886. {
  3887. int res;
  3888. char *pos, *end;
  3889. struct wpa_supplicant *wpa_s;
  3890. wpa_s = global->ifaces;
  3891. pos = buf;
  3892. end = buf + len;
  3893. while (wpa_s) {
  3894. res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
  3895. if (res < 0 || res >= end - pos) {
  3896. *pos = '\0';
  3897. break;
  3898. }
  3899. pos += res;
  3900. wpa_s = wpa_s->next;
  3901. }
  3902. return pos - buf;
  3903. }
  3904. char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
  3905. char *buf, size_t *resp_len)
  3906. {
  3907. char *reply;
  3908. const int reply_size = 2048;
  3909. int reply_len;
  3910. int level = MSG_DEBUG;
  3911. if (os_strcmp(buf, "PING") == 0)
  3912. level = MSG_EXCESSIVE;
  3913. wpa_hexdump_ascii(level, "RX global ctrl_iface",
  3914. (const u8 *) buf, os_strlen(buf));
  3915. reply = os_malloc(reply_size);
  3916. if (reply == NULL) {
  3917. *resp_len = 1;
  3918. return NULL;
  3919. }
  3920. os_memcpy(reply, "OK\n", 3);
  3921. reply_len = 3;
  3922. if (os_strcmp(buf, "PING") == 0) {
  3923. os_memcpy(reply, "PONG\n", 5);
  3924. reply_len = 5;
  3925. } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
  3926. if (wpa_supplicant_global_iface_add(global, buf + 14))
  3927. reply_len = -1;
  3928. } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
  3929. if (wpa_supplicant_global_iface_remove(global, buf + 17))
  3930. reply_len = -1;
  3931. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  3932. reply_len = wpa_supplicant_global_iface_list(
  3933. global, reply, reply_size);
  3934. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  3935. reply_len = wpa_supplicant_global_iface_interfaces(
  3936. global, reply, reply_size);
  3937. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  3938. wpa_supplicant_terminate_proc(global);
  3939. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  3940. wpas_notify_suspend(global);
  3941. } else if (os_strcmp(buf, "RESUME") == 0) {
  3942. wpas_notify_resume(global);
  3943. } else {
  3944. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  3945. reply_len = 16;
  3946. }
  3947. if (reply_len < 0) {
  3948. os_memcpy(reply, "FAIL\n", 5);
  3949. reply_len = 5;
  3950. }
  3951. *resp_len = reply_len;
  3952. return reply;
  3953. }