ctrl_iface.c 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438
  1. /*
  2. * WPA Supplicant / Control interface (shared code for all backends)
  3. * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "utils/includes.h"
  15. #include "utils/common.h"
  16. #include "utils/eloop.h"
  17. #include "common/version.h"
  18. #include "common/ieee802_11_defs.h"
  19. #include "common/wpa_ctrl.h"
  20. #include "eap_peer/eap.h"
  21. #include "eapol_supp/eapol_supp_sm.h"
  22. #include "rsn_supp/wpa.h"
  23. #include "rsn_supp/preauth.h"
  24. #include "rsn_supp/pmksa_cache.h"
  25. #include "l2_packet/l2_packet.h"
  26. #include "wps/wps.h"
  27. #include "config.h"
  28. #include "wpa_supplicant_i.h"
  29. #include "driver_i.h"
  30. #include "wps_supplicant.h"
  31. #include "ibss_rsn.h"
  32. #include "ap.h"
  33. #include "p2p_supplicant.h"
  34. #include "p2p/p2p.h"
  35. #include "notify.h"
  36. #include "bss.h"
  37. #include "scan.h"
  38. #include "ctrl_iface.h"
  39. extern struct wpa_driver_ops *wpa_drivers[];
  40. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  41. char *buf, int len);
  42. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  43. char *buf, int len);
  44. static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
  45. char *cmd)
  46. {
  47. char *value;
  48. int ret = 0;
  49. value = os_strchr(cmd, ' ');
  50. if (value == NULL)
  51. return -1;
  52. *value++ = '\0';
  53. wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
  54. if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
  55. eapol_sm_configure(wpa_s->eapol,
  56. atoi(value), -1, -1, -1);
  57. } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
  58. eapol_sm_configure(wpa_s->eapol,
  59. -1, atoi(value), -1, -1);
  60. } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
  61. eapol_sm_configure(wpa_s->eapol,
  62. -1, -1, atoi(value), -1);
  63. } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
  64. eapol_sm_configure(wpa_s->eapol,
  65. -1, -1, -1, atoi(value));
  66. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
  67. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
  68. atoi(value)))
  69. ret = -1;
  70. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
  71. 0) {
  72. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
  73. atoi(value)))
  74. ret = -1;
  75. } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
  76. if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
  77. ret = -1;
  78. } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
  79. wpa_s->wps_fragment_size = atoi(value);
  80. #ifdef CONFIG_WPS_TESTING
  81. } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
  82. long int val;
  83. val = strtol(value, NULL, 0);
  84. if (val < 0 || val > 0xff) {
  85. ret = -1;
  86. wpa_printf(MSG_DEBUG, "WPS: Invalid "
  87. "wps_version_number %ld", val);
  88. } else {
  89. wps_version_number = val;
  90. wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
  91. "version %u.%u",
  92. (wps_version_number & 0xf0) >> 4,
  93. wps_version_number & 0x0f);
  94. }
  95. } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
  96. wps_testing_dummy_cred = atoi(value);
  97. wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
  98. wps_testing_dummy_cred);
  99. #endif /* CONFIG_WPS_TESTING */
  100. } else if (os_strcasecmp(cmd, "ampdu") == 0) {
  101. if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
  102. ret = -1;
  103. #ifdef CONFIG_TDLS_TESTING
  104. } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
  105. extern unsigned int tdls_testing;
  106. tdls_testing = strtol(value, NULL, 0);
  107. wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
  108. #endif /* CONFIG_TDLS_TESTING */
  109. } else {
  110. value[-1] = '=';
  111. ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
  112. if (ret == 0)
  113. wpa_supplicant_update_config(wpa_s);
  114. }
  115. return ret;
  116. }
  117. static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
  118. char *cmd, char *buf, size_t buflen)
  119. {
  120. int res;
  121. wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
  122. if (os_strcmp(cmd, "version") == 0) {
  123. res = os_snprintf(buf, buflen, "%s", VERSION_STR);
  124. if (res < 0 || (unsigned int) res >= buflen)
  125. return -1;
  126. return res;
  127. }
  128. return -1;
  129. }
  130. #ifdef IEEE8021X_EAPOL
  131. static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
  132. char *addr)
  133. {
  134. u8 bssid[ETH_ALEN];
  135. struct wpa_ssid *ssid = wpa_s->current_ssid;
  136. if (hwaddr_aton(addr, bssid)) {
  137. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
  138. "'%s'", addr);
  139. return -1;
  140. }
  141. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
  142. rsn_preauth_deinit(wpa_s->wpa);
  143. if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
  144. return -1;
  145. return 0;
  146. }
  147. #endif /* IEEE8021X_EAPOL */
  148. #ifdef CONFIG_PEERKEY
  149. /* MLME-STKSTART.request(peer) */
  150. static int wpa_supplicant_ctrl_iface_stkstart(
  151. struct wpa_supplicant *wpa_s, char *addr)
  152. {
  153. u8 peer[ETH_ALEN];
  154. if (hwaddr_aton(addr, peer)) {
  155. wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
  156. "address '%s'", addr);
  157. return -1;
  158. }
  159. wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
  160. MAC2STR(peer));
  161. return wpa_sm_stkstart(wpa_s->wpa, peer);
  162. }
  163. #endif /* CONFIG_PEERKEY */
  164. #ifdef CONFIG_TDLS
  165. static int wpa_supplicant_ctrl_iface_tdls_discover(
  166. struct wpa_supplicant *wpa_s, char *addr)
  167. {
  168. u8 peer[ETH_ALEN];
  169. if (hwaddr_aton(addr, peer)) {
  170. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
  171. "address '%s'", addr);
  172. return -1;
  173. }
  174. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
  175. MAC2STR(peer));
  176. return wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
  177. }
  178. static int wpa_supplicant_ctrl_iface_tdls_setup(
  179. struct wpa_supplicant *wpa_s, char *addr)
  180. {
  181. u8 peer[ETH_ALEN];
  182. if (hwaddr_aton(addr, peer)) {
  183. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
  184. "address '%s'", addr);
  185. return -1;
  186. }
  187. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
  188. MAC2STR(peer));
  189. return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
  190. }
  191. static int wpa_supplicant_ctrl_iface_tdls_teardown(
  192. struct wpa_supplicant *wpa_s, char *addr)
  193. {
  194. u8 peer[ETH_ALEN];
  195. if (hwaddr_aton(addr, peer)) {
  196. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
  197. "address '%s'", addr);
  198. return -1;
  199. }
  200. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
  201. MAC2STR(peer));
  202. return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
  203. }
  204. #endif /* CONFIG_TDLS */
  205. #ifdef CONFIG_IEEE80211R
  206. static int wpa_supplicant_ctrl_iface_ft_ds(
  207. struct wpa_supplicant *wpa_s, char *addr)
  208. {
  209. u8 target_ap[ETH_ALEN];
  210. struct wpa_bss *bss;
  211. const u8 *mdie;
  212. if (hwaddr_aton(addr, target_ap)) {
  213. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
  214. "address '%s'", addr);
  215. return -1;
  216. }
  217. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
  218. bss = wpa_bss_get_bssid(wpa_s, target_ap);
  219. if (bss)
  220. mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
  221. else
  222. mdie = NULL;
  223. return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
  224. }
  225. #endif /* CONFIG_IEEE80211R */
  226. #ifdef CONFIG_WPS
  227. static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
  228. char *cmd)
  229. {
  230. u8 bssid[ETH_ALEN], *_bssid = bssid;
  231. u8 p2p_dev_addr[ETH_ALEN], *_p2p_dev_addr = NULL;
  232. if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
  233. _bssid = NULL;
  234. #ifdef CONFIG_P2P
  235. } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
  236. if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
  237. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
  238. "P2P Device Address '%s'",
  239. cmd + 13);
  240. return -1;
  241. }
  242. _p2p_dev_addr = p2p_dev_addr;
  243. #endif /* CONFIG_P2P */
  244. } else if (hwaddr_aton(cmd, bssid)) {
  245. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
  246. cmd);
  247. return -1;
  248. }
  249. #ifdef CONFIG_AP
  250. if (wpa_s->ap_iface)
  251. return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
  252. #endif /* CONFIG_AP */
  253. return wpas_wps_start_pbc(wpa_s, _bssid, 0);
  254. }
  255. static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
  256. char *cmd, char *buf,
  257. size_t buflen)
  258. {
  259. u8 bssid[ETH_ALEN], *_bssid = bssid;
  260. char *pin;
  261. int ret;
  262. pin = os_strchr(cmd, ' ');
  263. if (pin)
  264. *pin++ = '\0';
  265. if (os_strcmp(cmd, "any") == 0)
  266. _bssid = NULL;
  267. else if (hwaddr_aton(cmd, bssid)) {
  268. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
  269. cmd);
  270. return -1;
  271. }
  272. #ifdef CONFIG_AP
  273. if (wpa_s->ap_iface)
  274. return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
  275. buf, buflen);
  276. #endif /* CONFIG_AP */
  277. if (pin) {
  278. ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
  279. DEV_PW_DEFAULT);
  280. if (ret < 0)
  281. return -1;
  282. ret = os_snprintf(buf, buflen, "%s", pin);
  283. if (ret < 0 || (size_t) ret >= buflen)
  284. return -1;
  285. return ret;
  286. }
  287. ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
  288. if (ret < 0)
  289. return -1;
  290. /* Return the generated PIN */
  291. ret = os_snprintf(buf, buflen, "%08d", ret);
  292. if (ret < 0 || (size_t) ret >= buflen)
  293. return -1;
  294. return ret;
  295. }
  296. static int wpa_supplicant_ctrl_iface_wps_check_pin(
  297. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  298. {
  299. char pin[9];
  300. size_t len;
  301. char *pos;
  302. int ret;
  303. wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
  304. (u8 *) cmd, os_strlen(cmd));
  305. for (pos = cmd, len = 0; *pos != '\0'; pos++) {
  306. if (*pos < '0' || *pos > '9')
  307. continue;
  308. pin[len++] = *pos;
  309. if (len == 9) {
  310. wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
  311. return -1;
  312. }
  313. }
  314. if (len != 4 && len != 8) {
  315. wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
  316. return -1;
  317. }
  318. pin[len] = '\0';
  319. if (len == 8) {
  320. unsigned int pin_val;
  321. pin_val = atoi(pin);
  322. if (!wps_pin_valid(pin_val)) {
  323. wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
  324. ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
  325. if (ret < 0 || (size_t) ret >= buflen)
  326. return -1;
  327. return ret;
  328. }
  329. }
  330. ret = os_snprintf(buf, buflen, "%s", pin);
  331. if (ret < 0 || (size_t) ret >= buflen)
  332. return -1;
  333. return ret;
  334. }
  335. #ifdef CONFIG_WPS_OOB
  336. static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s,
  337. char *cmd)
  338. {
  339. char *path, *method, *name;
  340. path = os_strchr(cmd, ' ');
  341. if (path == NULL)
  342. return -1;
  343. *path++ = '\0';
  344. method = os_strchr(path, ' ');
  345. if (method == NULL)
  346. return -1;
  347. *method++ = '\0';
  348. name = os_strchr(method, ' ');
  349. if (name != NULL)
  350. *name++ = '\0';
  351. return wpas_wps_start_oob(wpa_s, cmd, path, method, name);
  352. }
  353. #endif /* CONFIG_WPS_OOB */
  354. static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
  355. char *cmd)
  356. {
  357. u8 bssid[ETH_ALEN];
  358. char *pin;
  359. char *new_ssid;
  360. char *new_auth;
  361. char *new_encr;
  362. char *new_key;
  363. struct wps_new_ap_settings ap;
  364. pin = os_strchr(cmd, ' ');
  365. if (pin == NULL)
  366. return -1;
  367. *pin++ = '\0';
  368. if (hwaddr_aton(cmd, bssid)) {
  369. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
  370. cmd);
  371. return -1;
  372. }
  373. new_ssid = os_strchr(pin, ' ');
  374. if (new_ssid == NULL)
  375. return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
  376. *new_ssid++ = '\0';
  377. new_auth = os_strchr(new_ssid, ' ');
  378. if (new_auth == NULL)
  379. return -1;
  380. *new_auth++ = '\0';
  381. new_encr = os_strchr(new_auth, ' ');
  382. if (new_encr == NULL)
  383. return -1;
  384. *new_encr++ = '\0';
  385. new_key = os_strchr(new_encr, ' ');
  386. if (new_key == NULL)
  387. return -1;
  388. *new_key++ = '\0';
  389. os_memset(&ap, 0, sizeof(ap));
  390. ap.ssid_hex = new_ssid;
  391. ap.auth = new_auth;
  392. ap.encr = new_encr;
  393. ap.key_hex = new_key;
  394. return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
  395. }
  396. #ifdef CONFIG_AP
  397. static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
  398. char *cmd, char *buf,
  399. size_t buflen)
  400. {
  401. int timeout = 300;
  402. char *pos;
  403. const char *pin_txt;
  404. if (!wpa_s->ap_iface)
  405. return -1;
  406. pos = os_strchr(cmd, ' ');
  407. if (pos)
  408. *pos++ = '\0';
  409. if (os_strcmp(cmd, "disable") == 0) {
  410. wpas_wps_ap_pin_disable(wpa_s);
  411. return os_snprintf(buf, buflen, "OK\n");
  412. }
  413. if (os_strcmp(cmd, "random") == 0) {
  414. if (pos)
  415. timeout = atoi(pos);
  416. pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
  417. if (pin_txt == NULL)
  418. return -1;
  419. return os_snprintf(buf, buflen, "%s", pin_txt);
  420. }
  421. if (os_strcmp(cmd, "get") == 0) {
  422. pin_txt = wpas_wps_ap_pin_get(wpa_s);
  423. if (pin_txt == NULL)
  424. return -1;
  425. return os_snprintf(buf, buflen, "%s", pin_txt);
  426. }
  427. if (os_strcmp(cmd, "set") == 0) {
  428. char *pin;
  429. if (pos == NULL)
  430. return -1;
  431. pin = pos;
  432. pos = os_strchr(pos, ' ');
  433. if (pos) {
  434. *pos++ = '\0';
  435. timeout = atoi(pos);
  436. }
  437. if (os_strlen(pin) > buflen)
  438. return -1;
  439. if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
  440. return -1;
  441. return os_snprintf(buf, buflen, "%s", pin);
  442. }
  443. return -1;
  444. }
  445. #endif /* CONFIG_AP */
  446. #ifdef CONFIG_WPS_ER
  447. static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
  448. char *cmd)
  449. {
  450. char *uuid = cmd, *pin, *pos;
  451. u8 addr_buf[ETH_ALEN], *addr = NULL;
  452. pin = os_strchr(uuid, ' ');
  453. if (pin == NULL)
  454. return -1;
  455. *pin++ = '\0';
  456. pos = os_strchr(pin, ' ');
  457. if (pos) {
  458. *pos++ = '\0';
  459. if (hwaddr_aton(pos, addr_buf) == 0)
  460. addr = addr_buf;
  461. }
  462. return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
  463. }
  464. static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
  465. char *cmd)
  466. {
  467. char *uuid = cmd, *pin;
  468. pin = os_strchr(uuid, ' ');
  469. if (pin == NULL)
  470. return -1;
  471. *pin++ = '\0';
  472. return wpas_wps_er_learn(wpa_s, uuid, pin);
  473. }
  474. static int wpa_supplicant_ctrl_iface_wps_er_set_config(
  475. struct wpa_supplicant *wpa_s, char *cmd)
  476. {
  477. char *uuid = cmd, *id;
  478. id = os_strchr(uuid, ' ');
  479. if (id == NULL)
  480. return -1;
  481. *id++ = '\0';
  482. return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
  483. }
  484. static int wpa_supplicant_ctrl_iface_wps_er_config(
  485. struct wpa_supplicant *wpa_s, char *cmd)
  486. {
  487. char *pin;
  488. char *new_ssid;
  489. char *new_auth;
  490. char *new_encr;
  491. char *new_key;
  492. struct wps_new_ap_settings ap;
  493. pin = os_strchr(cmd, ' ');
  494. if (pin == NULL)
  495. return -1;
  496. *pin++ = '\0';
  497. new_ssid = os_strchr(pin, ' ');
  498. if (new_ssid == NULL)
  499. return -1;
  500. *new_ssid++ = '\0';
  501. new_auth = os_strchr(new_ssid, ' ');
  502. if (new_auth == NULL)
  503. return -1;
  504. *new_auth++ = '\0';
  505. new_encr = os_strchr(new_auth, ' ');
  506. if (new_encr == NULL)
  507. return -1;
  508. *new_encr++ = '\0';
  509. new_key = os_strchr(new_encr, ' ');
  510. if (new_key == NULL)
  511. return -1;
  512. *new_key++ = '\0';
  513. os_memset(&ap, 0, sizeof(ap));
  514. ap.ssid_hex = new_ssid;
  515. ap.auth = new_auth;
  516. ap.encr = new_encr;
  517. ap.key_hex = new_key;
  518. return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
  519. }
  520. #endif /* CONFIG_WPS_ER */
  521. #endif /* CONFIG_WPS */
  522. #ifdef CONFIG_IBSS_RSN
  523. static int wpa_supplicant_ctrl_iface_ibss_rsn(
  524. struct wpa_supplicant *wpa_s, char *addr)
  525. {
  526. u8 peer[ETH_ALEN];
  527. if (hwaddr_aton(addr, peer)) {
  528. wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
  529. "address '%s'", addr);
  530. return -1;
  531. }
  532. wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
  533. MAC2STR(peer));
  534. return ibss_rsn_start(wpa_s->ibss_rsn, peer);
  535. }
  536. #endif /* CONFIG_IBSS_RSN */
  537. static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
  538. char *rsp)
  539. {
  540. #ifdef IEEE8021X_EAPOL
  541. char *pos, *id_pos;
  542. int id;
  543. struct wpa_ssid *ssid;
  544. struct eap_peer_config *eap;
  545. pos = os_strchr(rsp, '-');
  546. if (pos == NULL)
  547. return -1;
  548. *pos++ = '\0';
  549. id_pos = pos;
  550. pos = os_strchr(pos, ':');
  551. if (pos == NULL)
  552. return -1;
  553. *pos++ = '\0';
  554. id = atoi(id_pos);
  555. wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
  556. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  557. (u8 *) pos, os_strlen(pos));
  558. ssid = wpa_config_get_network(wpa_s->conf, id);
  559. if (ssid == NULL) {
  560. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  561. "to update", id);
  562. return -1;
  563. }
  564. eap = &ssid->eap;
  565. if (os_strcmp(rsp, "IDENTITY") == 0) {
  566. os_free(eap->identity);
  567. eap->identity = (u8 *) os_strdup(pos);
  568. eap->identity_len = os_strlen(pos);
  569. eap->pending_req_identity = 0;
  570. if (ssid == wpa_s->current_ssid)
  571. wpa_s->reassociate = 1;
  572. } else if (os_strcmp(rsp, "PASSWORD") == 0) {
  573. os_free(eap->password);
  574. eap->password = (u8 *) os_strdup(pos);
  575. eap->password_len = os_strlen(pos);
  576. eap->pending_req_password = 0;
  577. if (ssid == wpa_s->current_ssid)
  578. wpa_s->reassociate = 1;
  579. } else if (os_strcmp(rsp, "NEW_PASSWORD") == 0) {
  580. os_free(eap->new_password);
  581. eap->new_password = (u8 *) os_strdup(pos);
  582. eap->new_password_len = os_strlen(pos);
  583. eap->pending_req_new_password = 0;
  584. if (ssid == wpa_s->current_ssid)
  585. wpa_s->reassociate = 1;
  586. } else if (os_strcmp(rsp, "PIN") == 0) {
  587. os_free(eap->pin);
  588. eap->pin = os_strdup(pos);
  589. eap->pending_req_pin = 0;
  590. if (ssid == wpa_s->current_ssid)
  591. wpa_s->reassociate = 1;
  592. } else if (os_strcmp(rsp, "OTP") == 0) {
  593. os_free(eap->otp);
  594. eap->otp = (u8 *) os_strdup(pos);
  595. eap->otp_len = os_strlen(pos);
  596. os_free(eap->pending_req_otp);
  597. eap->pending_req_otp = NULL;
  598. eap->pending_req_otp_len = 0;
  599. } else if (os_strcmp(rsp, "PASSPHRASE") == 0) {
  600. os_free(eap->private_key_passwd);
  601. eap->private_key_passwd = (u8 *) os_strdup(pos);
  602. eap->pending_req_passphrase = 0;
  603. if (ssid == wpa_s->current_ssid)
  604. wpa_s->reassociate = 1;
  605. } else {
  606. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", rsp);
  607. return -1;
  608. }
  609. return 0;
  610. #else /* IEEE8021X_EAPOL */
  611. wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
  612. return -1;
  613. #endif /* IEEE8021X_EAPOL */
  614. }
  615. static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
  616. const char *params,
  617. char *buf, size_t buflen)
  618. {
  619. char *pos, *end, tmp[30];
  620. int res, verbose, ret;
  621. verbose = os_strcmp(params, "-VERBOSE") == 0;
  622. pos = buf;
  623. end = buf + buflen;
  624. if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
  625. struct wpa_ssid *ssid = wpa_s->current_ssid;
  626. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
  627. MAC2STR(wpa_s->bssid));
  628. if (ret < 0 || ret >= end - pos)
  629. return pos - buf;
  630. pos += ret;
  631. if (ssid) {
  632. u8 *_ssid = ssid->ssid;
  633. size_t ssid_len = ssid->ssid_len;
  634. u8 ssid_buf[MAX_SSID_LEN];
  635. if (ssid_len == 0) {
  636. int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
  637. if (_res < 0)
  638. ssid_len = 0;
  639. else
  640. ssid_len = _res;
  641. _ssid = ssid_buf;
  642. }
  643. ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
  644. wpa_ssid_txt(_ssid, ssid_len),
  645. ssid->id);
  646. if (ret < 0 || ret >= end - pos)
  647. return pos - buf;
  648. pos += ret;
  649. if (ssid->id_str) {
  650. ret = os_snprintf(pos, end - pos,
  651. "id_str=%s\n",
  652. ssid->id_str);
  653. if (ret < 0 || ret >= end - pos)
  654. return pos - buf;
  655. pos += ret;
  656. }
  657. switch (ssid->mode) {
  658. case WPAS_MODE_INFRA:
  659. ret = os_snprintf(pos, end - pos,
  660. "mode=station\n");
  661. break;
  662. case WPAS_MODE_IBSS:
  663. ret = os_snprintf(pos, end - pos,
  664. "mode=IBSS\n");
  665. break;
  666. case WPAS_MODE_AP:
  667. ret = os_snprintf(pos, end - pos,
  668. "mode=AP\n");
  669. break;
  670. case WPAS_MODE_P2P_GO:
  671. ret = os_snprintf(pos, end - pos,
  672. "mode=P2P GO\n");
  673. break;
  674. case WPAS_MODE_P2P_GROUP_FORMATION:
  675. ret = os_snprintf(pos, end - pos,
  676. "mode=P2P GO - group "
  677. "formation\n");
  678. break;
  679. default:
  680. ret = 0;
  681. break;
  682. }
  683. if (ret < 0 || ret >= end - pos)
  684. return pos - buf;
  685. pos += ret;
  686. }
  687. #ifdef CONFIG_AP
  688. if (wpa_s->ap_iface) {
  689. pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
  690. end - pos,
  691. verbose);
  692. } else
  693. #endif /* CONFIG_AP */
  694. pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
  695. }
  696. ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
  697. wpa_supplicant_state_txt(wpa_s->wpa_state));
  698. if (ret < 0 || ret >= end - pos)
  699. return pos - buf;
  700. pos += ret;
  701. if (wpa_s->l2 &&
  702. l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
  703. ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
  704. if (ret < 0 || ret >= end - pos)
  705. return pos - buf;
  706. pos += ret;
  707. }
  708. #ifdef CONFIG_P2P
  709. if (wpa_s->global->p2p) {
  710. ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
  711. "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
  712. if (ret < 0 || ret >= end - pos)
  713. return pos - buf;
  714. pos += ret;
  715. }
  716. #endif /* CONFIG_P2P */
  717. ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
  718. MAC2STR(wpa_s->own_addr));
  719. if (ret < 0 || ret >= end - pos)
  720. return pos - buf;
  721. pos += ret;
  722. if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  723. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  724. res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
  725. verbose);
  726. if (res >= 0)
  727. pos += res;
  728. }
  729. res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
  730. if (res >= 0)
  731. pos += res;
  732. return pos - buf;
  733. }
  734. static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
  735. char *cmd)
  736. {
  737. char *pos;
  738. int id;
  739. struct wpa_ssid *ssid;
  740. u8 bssid[ETH_ALEN];
  741. /* cmd: "<network id> <BSSID>" */
  742. pos = os_strchr(cmd, ' ');
  743. if (pos == NULL)
  744. return -1;
  745. *pos++ = '\0';
  746. id = atoi(cmd);
  747. wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
  748. if (hwaddr_aton(pos, bssid)) {
  749. wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
  750. return -1;
  751. }
  752. ssid = wpa_config_get_network(wpa_s->conf, id);
  753. if (ssid == NULL) {
  754. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  755. "to update", id);
  756. return -1;
  757. }
  758. os_memcpy(ssid->bssid, bssid, ETH_ALEN);
  759. ssid->bssid_set = !is_zero_ether_addr(bssid);
  760. return 0;
  761. }
  762. static int wpa_supplicant_ctrl_iface_list_networks(
  763. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  764. {
  765. char *pos, *end;
  766. struct wpa_ssid *ssid;
  767. int ret;
  768. pos = buf;
  769. end = buf + buflen;
  770. ret = os_snprintf(pos, end - pos,
  771. "network id / ssid / bssid / flags\n");
  772. if (ret < 0 || ret >= end - pos)
  773. return pos - buf;
  774. pos += ret;
  775. ssid = wpa_s->conf->ssid;
  776. while (ssid) {
  777. ret = os_snprintf(pos, end - pos, "%d\t%s",
  778. ssid->id,
  779. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  780. if (ret < 0 || ret >= end - pos)
  781. return pos - buf;
  782. pos += ret;
  783. if (ssid->bssid_set) {
  784. ret = os_snprintf(pos, end - pos, "\t" MACSTR,
  785. MAC2STR(ssid->bssid));
  786. } else {
  787. ret = os_snprintf(pos, end - pos, "\tany");
  788. }
  789. if (ret < 0 || ret >= end - pos)
  790. return pos - buf;
  791. pos += ret;
  792. ret = os_snprintf(pos, end - pos, "\t%s%s%s",
  793. ssid == wpa_s->current_ssid ?
  794. "[CURRENT]" : "",
  795. ssid->disabled ? "[DISABLED]" : "",
  796. ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
  797. "");
  798. if (ret < 0 || ret >= end - pos)
  799. return pos - buf;
  800. pos += ret;
  801. ret = os_snprintf(pos, end - pos, "\n");
  802. if (ret < 0 || ret >= end - pos)
  803. return pos - buf;
  804. pos += ret;
  805. ssid = ssid->next;
  806. }
  807. return pos - buf;
  808. }
  809. static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
  810. {
  811. int first = 1, ret;
  812. ret = os_snprintf(pos, end - pos, "-");
  813. if (ret < 0 || ret >= end - pos)
  814. return pos;
  815. pos += ret;
  816. if (cipher & WPA_CIPHER_NONE) {
  817. ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
  818. if (ret < 0 || ret >= end - pos)
  819. return pos;
  820. pos += ret;
  821. first = 0;
  822. }
  823. if (cipher & WPA_CIPHER_WEP40) {
  824. ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
  825. if (ret < 0 || ret >= end - pos)
  826. return pos;
  827. pos += ret;
  828. first = 0;
  829. }
  830. if (cipher & WPA_CIPHER_WEP104) {
  831. ret = os_snprintf(pos, end - pos, "%sWEP104",
  832. first ? "" : "+");
  833. if (ret < 0 || ret >= end - pos)
  834. return pos;
  835. pos += ret;
  836. first = 0;
  837. }
  838. if (cipher & WPA_CIPHER_TKIP) {
  839. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
  840. if (ret < 0 || ret >= end - pos)
  841. return pos;
  842. pos += ret;
  843. first = 0;
  844. }
  845. if (cipher & WPA_CIPHER_CCMP) {
  846. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
  847. if (ret < 0 || ret >= end - pos)
  848. return pos;
  849. pos += ret;
  850. first = 0;
  851. }
  852. return pos;
  853. }
  854. static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
  855. const u8 *ie, size_t ie_len)
  856. {
  857. struct wpa_ie_data data;
  858. int first, ret;
  859. ret = os_snprintf(pos, end - pos, "[%s-", proto);
  860. if (ret < 0 || ret >= end - pos)
  861. return pos;
  862. pos += ret;
  863. if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
  864. ret = os_snprintf(pos, end - pos, "?]");
  865. if (ret < 0 || ret >= end - pos)
  866. return pos;
  867. pos += ret;
  868. return pos;
  869. }
  870. first = 1;
  871. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  872. ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
  873. if (ret < 0 || ret >= end - pos)
  874. return pos;
  875. pos += ret;
  876. first = 0;
  877. }
  878. if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
  879. ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
  880. if (ret < 0 || ret >= end - pos)
  881. return pos;
  882. pos += ret;
  883. first = 0;
  884. }
  885. if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
  886. ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
  887. if (ret < 0 || ret >= end - pos)
  888. return pos;
  889. pos += ret;
  890. first = 0;
  891. }
  892. #ifdef CONFIG_IEEE80211R
  893. if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
  894. ret = os_snprintf(pos, end - pos, "%sFT/EAP",
  895. first ? "" : "+");
  896. if (ret < 0 || ret >= end - pos)
  897. return pos;
  898. pos += ret;
  899. first = 0;
  900. }
  901. if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
  902. ret = os_snprintf(pos, end - pos, "%sFT/PSK",
  903. first ? "" : "+");
  904. if (ret < 0 || ret >= end - pos)
  905. return pos;
  906. pos += ret;
  907. first = 0;
  908. }
  909. #endif /* CONFIG_IEEE80211R */
  910. #ifdef CONFIG_IEEE80211W
  911. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
  912. ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
  913. first ? "" : "+");
  914. if (ret < 0 || ret >= end - pos)
  915. return pos;
  916. pos += ret;
  917. first = 0;
  918. }
  919. if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
  920. ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
  921. first ? "" : "+");
  922. if (ret < 0 || ret >= end - pos)
  923. return pos;
  924. pos += ret;
  925. first = 0;
  926. }
  927. #endif /* CONFIG_IEEE80211W */
  928. pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
  929. if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
  930. ret = os_snprintf(pos, end - pos, "-preauth");
  931. if (ret < 0 || ret >= end - pos)
  932. return pos;
  933. pos += ret;
  934. }
  935. ret = os_snprintf(pos, end - pos, "]");
  936. if (ret < 0 || ret >= end - pos)
  937. return pos;
  938. pos += ret;
  939. return pos;
  940. }
  941. #ifdef CONFIG_WPS
  942. static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
  943. char *pos, char *end,
  944. struct wpabuf *wps_ie)
  945. {
  946. int ret;
  947. const char *txt;
  948. if (wps_ie == NULL)
  949. return pos;
  950. if (wps_is_selected_pbc_registrar(wps_ie))
  951. txt = "[WPS-PBC]";
  952. #ifdef CONFIG_WPS2
  953. else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
  954. txt = "[WPS-AUTH]";
  955. #endif /* CONFIG_WPS2 */
  956. else if (wps_is_selected_pin_registrar(wps_ie))
  957. txt = "[WPS-PIN]";
  958. else
  959. txt = "[WPS]";
  960. ret = os_snprintf(pos, end - pos, "%s", txt);
  961. if (ret >= 0 && ret < end - pos)
  962. pos += ret;
  963. wpabuf_free(wps_ie);
  964. return pos;
  965. }
  966. #endif /* CONFIG_WPS */
  967. static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
  968. char *pos, char *end,
  969. const struct wpa_bss *bss)
  970. {
  971. #ifdef CONFIG_WPS
  972. struct wpabuf *wps_ie;
  973. wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  974. return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
  975. #else /* CONFIG_WPS */
  976. return pos;
  977. #endif /* CONFIG_WPS */
  978. }
  979. /* Format one result on one text line into a buffer. */
  980. static int wpa_supplicant_ctrl_iface_scan_result(
  981. struct wpa_supplicant *wpa_s,
  982. const struct wpa_bss *bss, char *buf, size_t buflen)
  983. {
  984. char *pos, *end;
  985. int ret;
  986. const u8 *ie, *ie2, *p2p;
  987. p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
  988. if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
  989. os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
  990. 0)
  991. return 0; /* Do not show P2P listen discovery results here */
  992. pos = buf;
  993. end = buf + buflen;
  994. ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
  995. MAC2STR(bss->bssid), bss->freq, bss->level);
  996. if (ret < 0 || ret >= end - pos)
  997. return -1;
  998. pos += ret;
  999. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  1000. if (ie)
  1001. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
  1002. ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  1003. if (ie2)
  1004. pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
  1005. pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
  1006. if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
  1007. ret = os_snprintf(pos, end - pos, "[WEP]");
  1008. if (ret < 0 || ret >= end - pos)
  1009. return -1;
  1010. pos += ret;
  1011. }
  1012. if (bss->caps & IEEE80211_CAP_IBSS) {
  1013. ret = os_snprintf(pos, end - pos, "[IBSS]");
  1014. if (ret < 0 || ret >= end - pos)
  1015. return -1;
  1016. pos += ret;
  1017. }
  1018. if (bss->caps & IEEE80211_CAP_ESS) {
  1019. ret = os_snprintf(pos, end - pos, "[ESS]");
  1020. if (ret < 0 || ret >= end - pos)
  1021. return -1;
  1022. pos += ret;
  1023. }
  1024. if (p2p) {
  1025. ret = os_snprintf(pos, end - pos, "[P2P]");
  1026. if (ret < 0 || ret >= end - pos)
  1027. return -1;
  1028. pos += ret;
  1029. }
  1030. ret = os_snprintf(pos, end - pos, "\t%s",
  1031. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  1032. if (ret < 0 || ret >= end - pos)
  1033. return -1;
  1034. pos += ret;
  1035. ret = os_snprintf(pos, end - pos, "\n");
  1036. if (ret < 0 || ret >= end - pos)
  1037. return -1;
  1038. pos += ret;
  1039. return pos - buf;
  1040. }
  1041. static int wpa_supplicant_ctrl_iface_scan_results(
  1042. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  1043. {
  1044. char *pos, *end;
  1045. struct wpa_bss *bss;
  1046. int ret;
  1047. pos = buf;
  1048. end = buf + buflen;
  1049. ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
  1050. "flags / ssid\n");
  1051. if (ret < 0 || ret >= end - pos)
  1052. return pos - buf;
  1053. pos += ret;
  1054. dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
  1055. ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
  1056. end - pos);
  1057. if (ret < 0 || ret >= end - pos)
  1058. return pos - buf;
  1059. pos += ret;
  1060. }
  1061. return pos - buf;
  1062. }
  1063. static int wpa_supplicant_ctrl_iface_select_network(
  1064. struct wpa_supplicant *wpa_s, char *cmd)
  1065. {
  1066. int id;
  1067. struct wpa_ssid *ssid;
  1068. /* cmd: "<network id>" or "any" */
  1069. if (os_strcmp(cmd, "any") == 0) {
  1070. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
  1071. ssid = NULL;
  1072. } else {
  1073. id = atoi(cmd);
  1074. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
  1075. ssid = wpa_config_get_network(wpa_s->conf, id);
  1076. if (ssid == NULL) {
  1077. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  1078. "network id=%d", id);
  1079. return -1;
  1080. }
  1081. if (ssid->disabled == 2) {
  1082. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  1083. "SELECT_NETWORK with persistent P2P group");
  1084. return -1;
  1085. }
  1086. }
  1087. wpa_supplicant_select_network(wpa_s, ssid);
  1088. return 0;
  1089. }
  1090. static int wpa_supplicant_ctrl_iface_enable_network(
  1091. struct wpa_supplicant *wpa_s, char *cmd)
  1092. {
  1093. int id;
  1094. struct wpa_ssid *ssid;
  1095. /* cmd: "<network id>" or "all" */
  1096. if (os_strcmp(cmd, "all") == 0) {
  1097. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
  1098. ssid = NULL;
  1099. } else {
  1100. id = atoi(cmd);
  1101. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
  1102. ssid = wpa_config_get_network(wpa_s->conf, id);
  1103. if (ssid == NULL) {
  1104. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  1105. "network id=%d", id);
  1106. return -1;
  1107. }
  1108. if (ssid->disabled == 2) {
  1109. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  1110. "ENABLE_NETWORK with persistent P2P group");
  1111. return -1;
  1112. }
  1113. }
  1114. wpa_supplicant_enable_network(wpa_s, ssid);
  1115. return 0;
  1116. }
  1117. static int wpa_supplicant_ctrl_iface_disable_network(
  1118. struct wpa_supplicant *wpa_s, char *cmd)
  1119. {
  1120. int id;
  1121. struct wpa_ssid *ssid;
  1122. /* cmd: "<network id>" or "all" */
  1123. if (os_strcmp(cmd, "all") == 0) {
  1124. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
  1125. ssid = NULL;
  1126. } else {
  1127. id = atoi(cmd);
  1128. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
  1129. ssid = wpa_config_get_network(wpa_s->conf, id);
  1130. if (ssid == NULL) {
  1131. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  1132. "network id=%d", id);
  1133. return -1;
  1134. }
  1135. if (ssid->disabled == 2) {
  1136. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  1137. "DISABLE_NETWORK with persistent P2P "
  1138. "group");
  1139. return -1;
  1140. }
  1141. }
  1142. wpa_supplicant_disable_network(wpa_s, ssid);
  1143. return 0;
  1144. }
  1145. static int wpa_supplicant_ctrl_iface_add_network(
  1146. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  1147. {
  1148. struct wpa_ssid *ssid;
  1149. int ret;
  1150. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
  1151. ssid = wpa_config_add_network(wpa_s->conf);
  1152. if (ssid == NULL)
  1153. return -1;
  1154. wpas_notify_network_added(wpa_s, ssid);
  1155. ssid->disabled = 1;
  1156. wpa_config_set_network_defaults(ssid);
  1157. ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
  1158. if (ret < 0 || (size_t) ret >= buflen)
  1159. return -1;
  1160. return ret;
  1161. }
  1162. static int wpa_supplicant_ctrl_iface_remove_network(
  1163. struct wpa_supplicant *wpa_s, char *cmd)
  1164. {
  1165. int id;
  1166. struct wpa_ssid *ssid;
  1167. /* cmd: "<network id>" or "all" */
  1168. if (os_strcmp(cmd, "all") == 0) {
  1169. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
  1170. ssid = wpa_s->conf->ssid;
  1171. while (ssid) {
  1172. struct wpa_ssid *remove_ssid = ssid;
  1173. id = ssid->id;
  1174. ssid = ssid->next;
  1175. wpas_notify_network_removed(wpa_s, remove_ssid);
  1176. wpa_config_remove_network(wpa_s->conf, id);
  1177. }
  1178. if (wpa_s->current_ssid) {
  1179. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1180. wpa_supplicant_disassociate(wpa_s,
  1181. WLAN_REASON_DEAUTH_LEAVING);
  1182. }
  1183. return 0;
  1184. }
  1185. id = atoi(cmd);
  1186. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
  1187. ssid = wpa_config_get_network(wpa_s->conf, id);
  1188. if (ssid == NULL ||
  1189. wpa_config_remove_network(wpa_s->conf, id) < 0) {
  1190. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  1191. "id=%d", id);
  1192. return -1;
  1193. }
  1194. if (ssid == wpa_s->current_ssid) {
  1195. /*
  1196. * Invalidate the EAP session cache if the current network is
  1197. * removed.
  1198. */
  1199. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1200. wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1201. }
  1202. return 0;
  1203. }
  1204. static int wpa_supplicant_ctrl_iface_set_network(
  1205. struct wpa_supplicant *wpa_s, char *cmd)
  1206. {
  1207. int id;
  1208. struct wpa_ssid *ssid;
  1209. char *name, *value;
  1210. /* cmd: "<network id> <variable name> <value>" */
  1211. name = os_strchr(cmd, ' ');
  1212. if (name == NULL)
  1213. return -1;
  1214. *name++ = '\0';
  1215. value = os_strchr(name, ' ');
  1216. if (value == NULL)
  1217. return -1;
  1218. *value++ = '\0';
  1219. id = atoi(cmd);
  1220. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
  1221. id, name);
  1222. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  1223. (u8 *) value, os_strlen(value));
  1224. ssid = wpa_config_get_network(wpa_s->conf, id);
  1225. if (ssid == NULL) {
  1226. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  1227. "id=%d", id);
  1228. return -1;
  1229. }
  1230. if (wpa_config_set(ssid, name, value, 0) < 0) {
  1231. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
  1232. "variable '%s'", name);
  1233. return -1;
  1234. }
  1235. if (wpa_s->current_ssid == ssid) {
  1236. /*
  1237. * Invalidate the EAP session cache if anything in the current
  1238. * configuration changes.
  1239. */
  1240. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1241. }
  1242. if ((os_strcmp(name, "psk") == 0 &&
  1243. value[0] == '"' && ssid->ssid_len) ||
  1244. (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
  1245. wpa_config_update_psk(ssid);
  1246. else if (os_strcmp(name, "priority") == 0)
  1247. wpa_config_update_prio_list(wpa_s->conf);
  1248. return 0;
  1249. }
  1250. static int wpa_supplicant_ctrl_iface_get_network(
  1251. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  1252. {
  1253. int id;
  1254. size_t res;
  1255. struct wpa_ssid *ssid;
  1256. char *name, *value;
  1257. /* cmd: "<network id> <variable name>" */
  1258. name = os_strchr(cmd, ' ');
  1259. if (name == NULL || buflen == 0)
  1260. return -1;
  1261. *name++ = '\0';
  1262. id = atoi(cmd);
  1263. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
  1264. id, name);
  1265. ssid = wpa_config_get_network(wpa_s->conf, id);
  1266. if (ssid == NULL) {
  1267. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  1268. "id=%d", id);
  1269. return -1;
  1270. }
  1271. value = wpa_config_get_no_key(ssid, name);
  1272. if (value == NULL) {
  1273. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
  1274. "variable '%s'", name);
  1275. return -1;
  1276. }
  1277. res = os_strlcpy(buf, value, buflen);
  1278. if (res >= buflen) {
  1279. os_free(value);
  1280. return -1;
  1281. }
  1282. os_free(value);
  1283. return res;
  1284. }
  1285. #ifndef CONFIG_NO_CONFIG_WRITE
  1286. static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
  1287. {
  1288. int ret;
  1289. if (!wpa_s->conf->update_config) {
  1290. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
  1291. "to update configuration (update_config=0)");
  1292. return -1;
  1293. }
  1294. ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
  1295. if (ret) {
  1296. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
  1297. "update configuration");
  1298. } else {
  1299. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
  1300. " updated");
  1301. }
  1302. return ret;
  1303. }
  1304. #endif /* CONFIG_NO_CONFIG_WRITE */
  1305. static int ctrl_iface_get_capability_pairwise(int res, char *strict,
  1306. struct wpa_driver_capa *capa,
  1307. char *buf, size_t buflen)
  1308. {
  1309. int ret, first = 1;
  1310. char *pos, *end;
  1311. size_t len;
  1312. pos = buf;
  1313. end = pos + buflen;
  1314. if (res < 0) {
  1315. if (strict)
  1316. return 0;
  1317. len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
  1318. if (len >= buflen)
  1319. return -1;
  1320. return len;
  1321. }
  1322. if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1323. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
  1324. if (ret < 0 || ret >= end - pos)
  1325. return pos - buf;
  1326. pos += ret;
  1327. first = 0;
  1328. }
  1329. if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1330. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
  1331. if (ret < 0 || ret >= end - pos)
  1332. return pos - buf;
  1333. pos += ret;
  1334. first = 0;
  1335. }
  1336. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1337. ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " ");
  1338. if (ret < 0 || ret >= end - pos)
  1339. return pos - buf;
  1340. pos += ret;
  1341. first = 0;
  1342. }
  1343. return pos - buf;
  1344. }
  1345. static int ctrl_iface_get_capability_group(int res, char *strict,
  1346. struct wpa_driver_capa *capa,
  1347. char *buf, size_t buflen)
  1348. {
  1349. int ret, first = 1;
  1350. char *pos, *end;
  1351. size_t len;
  1352. pos = buf;
  1353. end = pos + buflen;
  1354. if (res < 0) {
  1355. if (strict)
  1356. return 0;
  1357. len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
  1358. if (len >= buflen)
  1359. return -1;
  1360. return len;
  1361. }
  1362. if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1363. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
  1364. if (ret < 0 || ret >= end - pos)
  1365. return pos - buf;
  1366. pos += ret;
  1367. first = 0;
  1368. }
  1369. if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1370. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
  1371. if (ret < 0 || ret >= end - pos)
  1372. return pos - buf;
  1373. pos += ret;
  1374. first = 0;
  1375. }
  1376. if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) {
  1377. ret = os_snprintf(pos, end - pos, "%sWEP104",
  1378. first ? "" : " ");
  1379. if (ret < 0 || ret >= end - pos)
  1380. return pos - buf;
  1381. pos += ret;
  1382. first = 0;
  1383. }
  1384. if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) {
  1385. ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " ");
  1386. if (ret < 0 || ret >= end - pos)
  1387. return pos - buf;
  1388. pos += ret;
  1389. first = 0;
  1390. }
  1391. return pos - buf;
  1392. }
  1393. static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
  1394. struct wpa_driver_capa *capa,
  1395. char *buf, size_t buflen)
  1396. {
  1397. int ret;
  1398. char *pos, *end;
  1399. size_t len;
  1400. pos = buf;
  1401. end = pos + buflen;
  1402. if (res < 0) {
  1403. if (strict)
  1404. return 0;
  1405. len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
  1406. "NONE", buflen);
  1407. if (len >= buflen)
  1408. return -1;
  1409. return len;
  1410. }
  1411. ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
  1412. if (ret < 0 || ret >= end - pos)
  1413. return pos - buf;
  1414. pos += ret;
  1415. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1416. WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
  1417. ret = os_snprintf(pos, end - pos, " WPA-EAP");
  1418. if (ret < 0 || ret >= end - pos)
  1419. return pos - buf;
  1420. pos += ret;
  1421. }
  1422. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
  1423. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1424. ret = os_snprintf(pos, end - pos, " WPA-PSK");
  1425. if (ret < 0 || ret >= end - pos)
  1426. return pos - buf;
  1427. pos += ret;
  1428. }
  1429. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1430. ret = os_snprintf(pos, end - pos, " WPA-NONE");
  1431. if (ret < 0 || ret >= end - pos)
  1432. return pos - buf;
  1433. pos += ret;
  1434. }
  1435. return pos - buf;
  1436. }
  1437. static int ctrl_iface_get_capability_proto(int res, char *strict,
  1438. struct wpa_driver_capa *capa,
  1439. char *buf, size_t buflen)
  1440. {
  1441. int ret, first = 1;
  1442. char *pos, *end;
  1443. size_t len;
  1444. pos = buf;
  1445. end = pos + buflen;
  1446. if (res < 0) {
  1447. if (strict)
  1448. return 0;
  1449. len = os_strlcpy(buf, "RSN WPA", buflen);
  1450. if (len >= buflen)
  1451. return -1;
  1452. return len;
  1453. }
  1454. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
  1455. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1456. ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
  1457. if (ret < 0 || ret >= end - pos)
  1458. return pos - buf;
  1459. pos += ret;
  1460. first = 0;
  1461. }
  1462. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1463. WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
  1464. ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
  1465. if (ret < 0 || ret >= end - pos)
  1466. return pos - buf;
  1467. pos += ret;
  1468. first = 0;
  1469. }
  1470. return pos - buf;
  1471. }
  1472. static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
  1473. struct wpa_driver_capa *capa,
  1474. char *buf, size_t buflen)
  1475. {
  1476. int ret, first = 1;
  1477. char *pos, *end;
  1478. size_t len;
  1479. pos = buf;
  1480. end = pos + buflen;
  1481. if (res < 0) {
  1482. if (strict)
  1483. return 0;
  1484. len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
  1485. if (len >= buflen)
  1486. return -1;
  1487. return len;
  1488. }
  1489. if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
  1490. ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
  1491. if (ret < 0 || ret >= end - pos)
  1492. return pos - buf;
  1493. pos += ret;
  1494. first = 0;
  1495. }
  1496. if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
  1497. ret = os_snprintf(pos, end - pos, "%sSHARED",
  1498. first ? "" : " ");
  1499. if (ret < 0 || ret >= end - pos)
  1500. return pos - buf;
  1501. pos += ret;
  1502. first = 0;
  1503. }
  1504. if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
  1505. ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
  1506. if (ret < 0 || ret >= end - pos)
  1507. return pos - buf;
  1508. pos += ret;
  1509. first = 0;
  1510. }
  1511. return pos - buf;
  1512. }
  1513. static int wpa_supplicant_ctrl_iface_get_capability(
  1514. struct wpa_supplicant *wpa_s, const char *_field, char *buf,
  1515. size_t buflen)
  1516. {
  1517. struct wpa_driver_capa capa;
  1518. int res;
  1519. char *strict;
  1520. char field[30];
  1521. size_t len;
  1522. /* Determine whether or not strict checking was requested */
  1523. len = os_strlcpy(field, _field, sizeof(field));
  1524. if (len >= sizeof(field))
  1525. return -1;
  1526. strict = os_strchr(field, ' ');
  1527. if (strict != NULL) {
  1528. *strict++ = '\0';
  1529. if (os_strcmp(strict, "strict") != 0)
  1530. return -1;
  1531. }
  1532. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
  1533. field, strict ? strict : "");
  1534. if (os_strcmp(field, "eap") == 0) {
  1535. return eap_get_names(buf, buflen);
  1536. }
  1537. res = wpa_drv_get_capa(wpa_s, &capa);
  1538. if (os_strcmp(field, "pairwise") == 0)
  1539. return ctrl_iface_get_capability_pairwise(res, strict, &capa,
  1540. buf, buflen);
  1541. if (os_strcmp(field, "group") == 0)
  1542. return ctrl_iface_get_capability_group(res, strict, &capa,
  1543. buf, buflen);
  1544. if (os_strcmp(field, "key_mgmt") == 0)
  1545. return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
  1546. buf, buflen);
  1547. if (os_strcmp(field, "proto") == 0)
  1548. return ctrl_iface_get_capability_proto(res, strict, &capa,
  1549. buf, buflen);
  1550. if (os_strcmp(field, "auth_alg") == 0)
  1551. return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
  1552. buf, buflen);
  1553. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
  1554. field);
  1555. return -1;
  1556. }
  1557. static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
  1558. const char *cmd, char *buf,
  1559. size_t buflen)
  1560. {
  1561. u8 bssid[ETH_ALEN];
  1562. size_t i;
  1563. struct wpa_bss *bss;
  1564. int ret;
  1565. char *pos, *end;
  1566. const u8 *ie, *ie2;
  1567. if (os_strcmp(cmd, "FIRST") == 0)
  1568. bss = dl_list_first(&wpa_s->bss, struct wpa_bss, list);
  1569. else if (os_strncmp(cmd, "ID-", 3) == 0) {
  1570. i = atoi(cmd + 3);
  1571. bss = wpa_bss_get_id(wpa_s, i);
  1572. } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
  1573. i = atoi(cmd + 5);
  1574. bss = wpa_bss_get_id(wpa_s, i);
  1575. if (bss) {
  1576. struct dl_list *next = bss->list_id.next;
  1577. if (next == &wpa_s->bss_id)
  1578. bss = NULL;
  1579. else
  1580. bss = dl_list_entry(next, struct wpa_bss,
  1581. list_id);
  1582. }
  1583. } else if (hwaddr_aton(cmd, bssid) == 0)
  1584. bss = wpa_bss_get_bssid(wpa_s, bssid);
  1585. else {
  1586. struct wpa_bss *tmp;
  1587. i = atoi(cmd);
  1588. bss = NULL;
  1589. dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
  1590. {
  1591. if (i-- == 0) {
  1592. bss = tmp;
  1593. break;
  1594. }
  1595. }
  1596. }
  1597. if (bss == NULL)
  1598. return 0;
  1599. pos = buf;
  1600. end = buf + buflen;
  1601. ret = os_snprintf(pos, end - pos,
  1602. "id=%u\n"
  1603. "bssid=" MACSTR "\n"
  1604. "freq=%d\n"
  1605. "beacon_int=%d\n"
  1606. "capabilities=0x%04x\n"
  1607. "qual=%d\n"
  1608. "noise=%d\n"
  1609. "level=%d\n"
  1610. "tsf=%016llu\n"
  1611. "ie=",
  1612. bss->id,
  1613. MAC2STR(bss->bssid), bss->freq, bss->beacon_int,
  1614. bss->caps, bss->qual, bss->noise, bss->level,
  1615. (unsigned long long) bss->tsf);
  1616. if (ret < 0 || ret >= end - pos)
  1617. return pos - buf;
  1618. pos += ret;
  1619. ie = (const u8 *) (bss + 1);
  1620. for (i = 0; i < bss->ie_len; i++) {
  1621. ret = os_snprintf(pos, end - pos, "%02x", *ie++);
  1622. if (ret < 0 || ret >= end - pos)
  1623. return pos - buf;
  1624. pos += ret;
  1625. }
  1626. if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) {
  1627. ret = os_snprintf(pos, end - pos, "[P2P]");
  1628. if (ret < 0 || ret >= end - pos)
  1629. return pos - buf;
  1630. pos += ret;
  1631. }
  1632. ret = os_snprintf(pos, end - pos, "\n");
  1633. if (ret < 0 || ret >= end - pos)
  1634. return pos - buf;
  1635. pos += ret;
  1636. ret = os_snprintf(pos, end - pos, "flags=");
  1637. if (ret < 0 || ret >= end - pos)
  1638. return pos - buf;
  1639. pos += ret;
  1640. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  1641. if (ie)
  1642. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
  1643. ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  1644. if (ie2)
  1645. pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
  1646. pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
  1647. if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
  1648. ret = os_snprintf(pos, end - pos, "[WEP]");
  1649. if (ret < 0 || ret >= end - pos)
  1650. return pos - buf;
  1651. pos += ret;
  1652. }
  1653. if (bss->caps & IEEE80211_CAP_IBSS) {
  1654. ret = os_snprintf(pos, end - pos, "[IBSS]");
  1655. if (ret < 0 || ret >= end - pos)
  1656. return pos - buf;
  1657. pos += ret;
  1658. }
  1659. if (bss->caps & IEEE80211_CAP_ESS) {
  1660. ret = os_snprintf(pos, end - pos, "[ESS]");
  1661. if (ret < 0 || ret >= end - pos)
  1662. return pos - buf;
  1663. pos += ret;
  1664. }
  1665. ret = os_snprintf(pos, end - pos, "\n");
  1666. if (ret < 0 || ret >= end - pos)
  1667. return pos - buf;
  1668. pos += ret;
  1669. ret = os_snprintf(pos, end - pos, "ssid=%s\n",
  1670. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  1671. if (ret < 0 || ret >= end - pos)
  1672. return pos - buf;
  1673. pos += ret;
  1674. #ifdef CONFIG_WPS
  1675. ie = (const u8 *) (bss + 1);
  1676. ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
  1677. if (ret < 0 || ret >= end - pos)
  1678. return pos - buf;
  1679. pos += ret;
  1680. #endif /* CONFIG_WPS */
  1681. #ifdef CONFIG_P2P
  1682. ie = (const u8 *) (bss + 1);
  1683. ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
  1684. if (ret < 0 || ret >= end - pos)
  1685. return pos - buf;
  1686. pos += ret;
  1687. #endif /* CONFIG_P2P */
  1688. return pos - buf;
  1689. }
  1690. static int wpa_supplicant_ctrl_iface_ap_scan(
  1691. struct wpa_supplicant *wpa_s, char *cmd)
  1692. {
  1693. int ap_scan = atoi(cmd);
  1694. return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
  1695. }
  1696. static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
  1697. {
  1698. wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
  1699. /* MLME-DELETEKEYS.request */
  1700. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
  1701. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
  1702. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
  1703. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
  1704. #ifdef CONFIG_IEEE80211W
  1705. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
  1706. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
  1707. #endif /* CONFIG_IEEE80211W */
  1708. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
  1709. 0);
  1710. /* MLME-SETPROTECTION.request(None) */
  1711. wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
  1712. MLME_SETPROTECTION_PROTECT_TYPE_NONE,
  1713. MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
  1714. wpa_sm_drop_sa(wpa_s->wpa);
  1715. }
  1716. static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
  1717. char *addr)
  1718. {
  1719. u8 bssid[ETH_ALEN];
  1720. struct wpa_bss *bss;
  1721. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1722. if (hwaddr_aton(addr, bssid)) {
  1723. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
  1724. "address '%s'", addr);
  1725. return -1;
  1726. }
  1727. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
  1728. bss = wpa_bss_get_bssid(wpa_s, bssid);
  1729. if (!bss) {
  1730. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
  1731. "from BSS table");
  1732. return -1;
  1733. }
  1734. /*
  1735. * TODO: Find best network configuration block from configuration to
  1736. * allow roaming to other networks
  1737. */
  1738. if (!ssid) {
  1739. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
  1740. "configuration known for the target AP");
  1741. return -1;
  1742. }
  1743. wpa_s->reassociate = 1;
  1744. wpa_supplicant_connect(wpa_s, bss, ssid);
  1745. return 0;
  1746. }
  1747. #ifdef CONFIG_P2P
  1748. static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
  1749. {
  1750. unsigned int timeout = atoi(cmd);
  1751. enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
  1752. if (os_strstr(cmd, "type=social"))
  1753. type = P2P_FIND_ONLY_SOCIAL;
  1754. else if (os_strstr(cmd, "type=progressive"))
  1755. type = P2P_FIND_PROGRESSIVE;
  1756. return wpas_p2p_find(wpa_s, timeout, type);
  1757. }
  1758. static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
  1759. char *buf, size_t buflen)
  1760. {
  1761. u8 addr[ETH_ALEN];
  1762. char *pos, *pos2;
  1763. char *pin = NULL;
  1764. enum p2p_wps_method wps_method;
  1765. int new_pin;
  1766. int ret;
  1767. int persistent_group;
  1768. int join;
  1769. int auth;
  1770. int go_intent = -1;
  1771. int freq = 0;
  1772. /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad] [persistent]
  1773. * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] */
  1774. if (hwaddr_aton(cmd, addr))
  1775. return -1;
  1776. pos = cmd + 17;
  1777. if (*pos != ' ')
  1778. return -1;
  1779. pos++;
  1780. persistent_group = os_strstr(pos, " persistent") != NULL;
  1781. join = os_strstr(pos, " join") != NULL;
  1782. auth = os_strstr(pos, " auth") != NULL;
  1783. pos2 = os_strstr(pos, " go_intent=");
  1784. if (pos2) {
  1785. pos2 += 11;
  1786. go_intent = atoi(pos2);
  1787. if (go_intent < 0 || go_intent > 15)
  1788. return -1;
  1789. }
  1790. pos2 = os_strstr(pos, " freq=");
  1791. if (pos2) {
  1792. pos2 += 6;
  1793. freq = atoi(pos2);
  1794. if (freq <= 0)
  1795. return -1;
  1796. }
  1797. if (os_strncmp(pos, "pin", 3) == 0) {
  1798. /* Request random PIN (to be displayed) and enable the PIN */
  1799. wps_method = WPS_PIN_DISPLAY;
  1800. } else if (os_strncmp(pos, "pbc", 3) == 0) {
  1801. wps_method = WPS_PBC;
  1802. } else {
  1803. pin = pos;
  1804. pos = os_strchr(pin, ' ');
  1805. wps_method = WPS_PIN_KEYPAD;
  1806. if (pos) {
  1807. *pos++ = '\0';
  1808. if (os_strncmp(pos, "label", 5) == 0)
  1809. wps_method = WPS_PIN_LABEL;
  1810. else if (os_strncmp(pos, "display", 7) == 0)
  1811. wps_method = WPS_PIN_DISPLAY;
  1812. }
  1813. }
  1814. new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
  1815. persistent_group, join, auth, go_intent,
  1816. freq);
  1817. if (new_pin == -2) {
  1818. os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
  1819. return 25;
  1820. }
  1821. if (new_pin == -3) {
  1822. os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
  1823. return 25;
  1824. }
  1825. if (new_pin < 0)
  1826. return -1;
  1827. if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
  1828. ret = os_snprintf(buf, buflen, "%08d", new_pin);
  1829. if (ret < 0 || (size_t) ret >= buflen)
  1830. return -1;
  1831. return ret;
  1832. }
  1833. os_memcpy(buf, "OK\n", 3);
  1834. return 3;
  1835. }
  1836. static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
  1837. {
  1838. unsigned int timeout = atoi(cmd);
  1839. return wpas_p2p_listen(wpa_s, timeout);
  1840. }
  1841. static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
  1842. {
  1843. u8 addr[ETH_ALEN];
  1844. char *pos;
  1845. /* <addr> <config method> */
  1846. if (hwaddr_aton(cmd, addr))
  1847. return -1;
  1848. pos = cmd + 17;
  1849. if (*pos != ' ')
  1850. return -1;
  1851. pos++;
  1852. return wpas_p2p_prov_disc(wpa_s, addr, pos);
  1853. }
  1854. static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
  1855. size_t buflen)
  1856. {
  1857. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1858. if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
  1859. ssid->passphrase == NULL)
  1860. return -1;
  1861. os_strlcpy(buf, ssid->passphrase, buflen);
  1862. return os_strlen(buf);
  1863. }
  1864. static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
  1865. char *buf, size_t buflen)
  1866. {
  1867. u64 ref;
  1868. int res;
  1869. u8 dst_buf[ETH_ALEN], *dst;
  1870. struct wpabuf *tlvs;
  1871. char *pos;
  1872. size_t len;
  1873. if (hwaddr_aton(cmd, dst_buf))
  1874. return -1;
  1875. dst = dst_buf;
  1876. if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
  1877. dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
  1878. dst = NULL;
  1879. pos = cmd + 17;
  1880. if (*pos != ' ')
  1881. return -1;
  1882. pos++;
  1883. if (os_strncmp(pos, "upnp ", 5) == 0) {
  1884. u8 version;
  1885. pos += 5;
  1886. if (hexstr2bin(pos, &version, 1) < 0)
  1887. return -1;
  1888. pos += 2;
  1889. if (*pos != ' ')
  1890. return -1;
  1891. pos++;
  1892. ref = (unsigned long) wpas_p2p_sd_request_upnp(wpa_s, dst,
  1893. version, pos);
  1894. } else {
  1895. len = os_strlen(pos);
  1896. if (len & 1)
  1897. return -1;
  1898. len /= 2;
  1899. tlvs = wpabuf_alloc(len);
  1900. if (tlvs == NULL)
  1901. return -1;
  1902. if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
  1903. wpabuf_free(tlvs);
  1904. return -1;
  1905. }
  1906. ref = (unsigned long) wpas_p2p_sd_request(wpa_s, dst, tlvs);
  1907. wpabuf_free(tlvs);
  1908. }
  1909. res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
  1910. if (res < 0 || (unsigned) res >= buflen)
  1911. return -1;
  1912. return res;
  1913. }
  1914. static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
  1915. char *cmd)
  1916. {
  1917. long long unsigned val;
  1918. u64 req;
  1919. if (sscanf(cmd, "%llx", &val) != 1)
  1920. return -1;
  1921. req = val;
  1922. return wpas_p2p_sd_cancel_request(wpa_s, (void *) (unsigned long) req);
  1923. }
  1924. static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
  1925. {
  1926. int freq;
  1927. u8 dst[ETH_ALEN];
  1928. u8 dialog_token;
  1929. struct wpabuf *resp_tlvs;
  1930. char *pos, *pos2;
  1931. size_t len;
  1932. pos = os_strchr(cmd, ' ');
  1933. if (pos == NULL)
  1934. return -1;
  1935. *pos++ = '\0';
  1936. freq = atoi(cmd);
  1937. if (freq == 0)
  1938. return -1;
  1939. if (hwaddr_aton(pos, dst))
  1940. return -1;
  1941. pos += 17;
  1942. if (*pos != ' ')
  1943. return -1;
  1944. pos++;
  1945. pos2 = os_strchr(pos, ' ');
  1946. if (pos2 == NULL)
  1947. return -1;
  1948. *pos2++ = '\0';
  1949. dialog_token = atoi(pos);
  1950. len = os_strlen(pos2);
  1951. if (len & 1)
  1952. return -1;
  1953. len /= 2;
  1954. resp_tlvs = wpabuf_alloc(len);
  1955. if (resp_tlvs == NULL)
  1956. return -1;
  1957. if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
  1958. wpabuf_free(resp_tlvs);
  1959. return -1;
  1960. }
  1961. wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
  1962. wpabuf_free(resp_tlvs);
  1963. return 0;
  1964. }
  1965. static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
  1966. char *cmd)
  1967. {
  1968. wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
  1969. return 0;
  1970. }
  1971. static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
  1972. char *cmd)
  1973. {
  1974. char *pos;
  1975. size_t len;
  1976. struct wpabuf *query, *resp;
  1977. pos = os_strchr(cmd, ' ');
  1978. if (pos == NULL)
  1979. return -1;
  1980. *pos++ = '\0';
  1981. len = os_strlen(cmd);
  1982. if (len & 1)
  1983. return -1;
  1984. len /= 2;
  1985. query = wpabuf_alloc(len);
  1986. if (query == NULL)
  1987. return -1;
  1988. if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
  1989. wpabuf_free(query);
  1990. return -1;
  1991. }
  1992. len = os_strlen(pos);
  1993. if (len & 1) {
  1994. wpabuf_free(query);
  1995. return -1;
  1996. }
  1997. len /= 2;
  1998. resp = wpabuf_alloc(len);
  1999. if (resp == NULL) {
  2000. wpabuf_free(query);
  2001. return -1;
  2002. }
  2003. if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
  2004. wpabuf_free(query);
  2005. wpabuf_free(resp);
  2006. return -1;
  2007. }
  2008. if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
  2009. wpabuf_free(query);
  2010. wpabuf_free(resp);
  2011. return -1;
  2012. }
  2013. return 0;
  2014. }
  2015. static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
  2016. {
  2017. char *pos;
  2018. u8 version;
  2019. pos = os_strchr(cmd, ' ');
  2020. if (pos == NULL)
  2021. return -1;
  2022. *pos++ = '\0';
  2023. if (hexstr2bin(cmd, &version, 1) < 0)
  2024. return -1;
  2025. return wpas_p2p_service_add_upnp(wpa_s, version, pos);
  2026. }
  2027. static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
  2028. {
  2029. char *pos;
  2030. pos = os_strchr(cmd, ' ');
  2031. if (pos == NULL)
  2032. return -1;
  2033. *pos++ = '\0';
  2034. if (os_strcmp(cmd, "bonjour") == 0)
  2035. return p2p_ctrl_service_add_bonjour(wpa_s, pos);
  2036. if (os_strcmp(cmd, "upnp") == 0)
  2037. return p2p_ctrl_service_add_upnp(wpa_s, pos);
  2038. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  2039. return -1;
  2040. }
  2041. static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
  2042. char *cmd)
  2043. {
  2044. size_t len;
  2045. struct wpabuf *query;
  2046. int ret;
  2047. len = os_strlen(cmd);
  2048. if (len & 1)
  2049. return -1;
  2050. len /= 2;
  2051. query = wpabuf_alloc(len);
  2052. if (query == NULL)
  2053. return -1;
  2054. if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
  2055. wpabuf_free(query);
  2056. return -1;
  2057. }
  2058. ret = wpas_p2p_service_del_bonjour(wpa_s, query);
  2059. wpabuf_free(query);
  2060. return ret;
  2061. }
  2062. static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
  2063. {
  2064. char *pos;
  2065. u8 version;
  2066. pos = os_strchr(cmd, ' ');
  2067. if (pos == NULL)
  2068. return -1;
  2069. *pos++ = '\0';
  2070. if (hexstr2bin(cmd, &version, 1) < 0)
  2071. return -1;
  2072. return wpas_p2p_service_del_upnp(wpa_s, version, pos);
  2073. }
  2074. static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
  2075. {
  2076. char *pos;
  2077. pos = os_strchr(cmd, ' ');
  2078. if (pos == NULL)
  2079. return -1;
  2080. *pos++ = '\0';
  2081. if (os_strcmp(cmd, "bonjour") == 0)
  2082. return p2p_ctrl_service_del_bonjour(wpa_s, pos);
  2083. if (os_strcmp(cmd, "upnp") == 0)
  2084. return p2p_ctrl_service_del_upnp(wpa_s, pos);
  2085. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  2086. return -1;
  2087. }
  2088. static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
  2089. {
  2090. u8 addr[ETH_ALEN];
  2091. /* <addr> */
  2092. if (hwaddr_aton(cmd, addr))
  2093. return -1;
  2094. return wpas_p2p_reject(wpa_s, addr);
  2095. }
  2096. static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
  2097. {
  2098. char *pos;
  2099. int id;
  2100. struct wpa_ssid *ssid;
  2101. u8 peer[ETH_ALEN];
  2102. id = atoi(cmd);
  2103. pos = os_strstr(cmd, " peer=");
  2104. if (pos) {
  2105. pos += 6;
  2106. if (hwaddr_aton(pos, peer))
  2107. return -1;
  2108. }
  2109. ssid = wpa_config_get_network(wpa_s->conf, id);
  2110. if (ssid == NULL || ssid->disabled != 2) {
  2111. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  2112. "for persistent P2P group",
  2113. id);
  2114. return -1;
  2115. }
  2116. return wpas_p2p_invite(wpa_s, pos ? peer : NULL, ssid, NULL);
  2117. }
  2118. static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
  2119. {
  2120. char *pos;
  2121. u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
  2122. pos = os_strstr(cmd, " peer=");
  2123. if (!pos)
  2124. return -1;
  2125. *pos = '\0';
  2126. pos += 6;
  2127. if (hwaddr_aton(pos, peer)) {
  2128. wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
  2129. return -1;
  2130. }
  2131. pos = os_strstr(pos, " go_dev_addr=");
  2132. if (pos) {
  2133. pos += 13;
  2134. if (hwaddr_aton(pos, go_dev_addr)) {
  2135. wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
  2136. pos);
  2137. return -1;
  2138. }
  2139. go_dev = go_dev_addr;
  2140. }
  2141. return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
  2142. }
  2143. static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
  2144. {
  2145. if (os_strncmp(cmd, "persistent=", 11) == 0)
  2146. return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
  2147. if (os_strncmp(cmd, "group=", 6) == 0)
  2148. return p2p_ctrl_invite_group(wpa_s, cmd + 6);
  2149. return -1;
  2150. }
  2151. static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
  2152. char *cmd, int freq)
  2153. {
  2154. int id;
  2155. struct wpa_ssid *ssid;
  2156. id = atoi(cmd);
  2157. ssid = wpa_config_get_network(wpa_s->conf, id);
  2158. if (ssid == NULL || ssid->disabled != 2) {
  2159. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  2160. "for persistent P2P group",
  2161. id);
  2162. return -1;
  2163. }
  2164. return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq);
  2165. }
  2166. static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
  2167. {
  2168. int freq = 0;
  2169. char *pos;
  2170. pos = os_strstr(cmd, "freq=");
  2171. if (pos)
  2172. freq = atoi(pos + 5);
  2173. if (os_strncmp(cmd, "persistent=", 11) == 0)
  2174. return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq);
  2175. if (os_strcmp(cmd, "persistent") == 0 ||
  2176. os_strncmp(cmd, "persistent ", 11) == 0)
  2177. return wpas_p2p_group_add(wpa_s, 1, freq);
  2178. if (os_strncmp(cmd, "freq=", 5) == 0)
  2179. return wpas_p2p_group_add(wpa_s, 0, freq);
  2180. wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
  2181. cmd);
  2182. return -1;
  2183. }
  2184. static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
  2185. char *buf, size_t buflen)
  2186. {
  2187. u8 addr[ETH_ALEN], *addr_ptr;
  2188. int next;
  2189. if (!wpa_s->global->p2p)
  2190. return -1;
  2191. if (os_strcmp(cmd, "FIRST") == 0) {
  2192. addr_ptr = NULL;
  2193. next = 0;
  2194. } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
  2195. if (hwaddr_aton(cmd + 5, addr) < 0)
  2196. return -1;
  2197. addr_ptr = addr;
  2198. next = 1;
  2199. } else {
  2200. if (hwaddr_aton(cmd, addr) < 0)
  2201. return -1;
  2202. addr_ptr = addr;
  2203. next = 0;
  2204. }
  2205. return p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next,
  2206. buf, buflen);
  2207. }
  2208. static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
  2209. {
  2210. char *param;
  2211. if (wpa_s->global->p2p == NULL)
  2212. return -1;
  2213. param = os_strchr(cmd, ' ');
  2214. if (param == NULL)
  2215. return -1;
  2216. *param++ = '\0';
  2217. if (os_strcmp(cmd, "discoverability") == 0) {
  2218. p2p_set_client_discoverability(wpa_s->global->p2p,
  2219. atoi(param));
  2220. return 0;
  2221. }
  2222. if (os_strcmp(cmd, "managed") == 0) {
  2223. p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
  2224. return 0;
  2225. }
  2226. if (os_strcmp(cmd, "listen_channel") == 0) {
  2227. return p2p_set_listen_channel(wpa_s->global->p2p, 81,
  2228. atoi(param));
  2229. }
  2230. if (os_strcmp(cmd, "ssid_postfix") == 0) {
  2231. return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
  2232. os_strlen(param));
  2233. }
  2234. if (os_strcmp(cmd, "noa") == 0) {
  2235. char *pos;
  2236. int count, start, duration;
  2237. /* GO NoA parameters: count,start_offset(ms),duration(ms) */
  2238. count = atoi(param);
  2239. pos = os_strchr(param, ',');
  2240. if (pos == NULL)
  2241. return -1;
  2242. pos++;
  2243. start = atoi(pos);
  2244. pos = os_strchr(pos, ',');
  2245. if (pos == NULL)
  2246. return -1;
  2247. pos++;
  2248. duration = atoi(pos);
  2249. if (count < 0 || count > 255 || start < 0 || duration < 0)
  2250. return -1;
  2251. if (count == 0 && duration > 0)
  2252. return -1;
  2253. wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
  2254. "start=%d duration=%d", count, start, duration);
  2255. return wpas_p2p_set_noa(wpa_s, count, start, duration);
  2256. }
  2257. if (os_strcmp(cmd, "ps") == 0)
  2258. return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
  2259. if (os_strcmp(cmd, "oppps") == 0)
  2260. return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
  2261. if (os_strcmp(cmd, "ctwindow") == 0)
  2262. return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
  2263. if (os_strcmp(cmd, "disabled") == 0) {
  2264. wpa_s->global->p2p_disabled = atoi(param);
  2265. wpa_printf(MSG_DEBUG, "P2P functionality %s",
  2266. wpa_s->global->p2p_disabled ?
  2267. "disabled" : "enabled");
  2268. if (wpa_s->global->p2p_disabled) {
  2269. wpas_p2p_stop_find(wpa_s);
  2270. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  2271. p2p_flush(wpa_s->global->p2p);
  2272. }
  2273. return 0;
  2274. }
  2275. if (os_strcmp(cmd, "force_long_sd") == 0) {
  2276. wpa_s->force_long_sd = atoi(param);
  2277. return 0;
  2278. }
  2279. if (os_strcmp(cmd, "peer_filter") == 0) {
  2280. u8 addr[ETH_ALEN];
  2281. if (hwaddr_aton(param, addr))
  2282. return -1;
  2283. p2p_set_peer_filter(wpa_s->global->p2p, addr);
  2284. return 0;
  2285. }
  2286. if (os_strcmp(cmd, "cross_connect") == 0)
  2287. return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
  2288. if (os_strcmp(cmd, "go_apsd") == 0) {
  2289. if (os_strcmp(param, "disable") == 0)
  2290. wpa_s->set_ap_uapsd = 0;
  2291. else {
  2292. wpa_s->set_ap_uapsd = 1;
  2293. wpa_s->ap_uapsd = atoi(param);
  2294. }
  2295. return 0;
  2296. }
  2297. if (os_strcmp(cmd, "client_apsd") == 0) {
  2298. if (os_strcmp(param, "disable") == 0)
  2299. wpa_s->set_sta_uapsd = 0;
  2300. else {
  2301. int be, bk, vi, vo;
  2302. char *pos;
  2303. /* format: BE,BK,VI,VO;max SP Length */
  2304. be = atoi(param);
  2305. pos = os_strchr(param, ',');
  2306. if (pos == NULL)
  2307. return -1;
  2308. pos++;
  2309. bk = atoi(pos);
  2310. pos = os_strchr(pos, ',');
  2311. if (pos == NULL)
  2312. return -1;
  2313. pos++;
  2314. vi = atoi(pos);
  2315. pos = os_strchr(pos, ',');
  2316. if (pos == NULL)
  2317. return -1;
  2318. pos++;
  2319. vo = atoi(pos);
  2320. /* ignore max SP Length for now */
  2321. wpa_s->set_sta_uapsd = 1;
  2322. wpa_s->sta_uapsd = 0;
  2323. if (be)
  2324. wpa_s->sta_uapsd |= BIT(0);
  2325. if (bk)
  2326. wpa_s->sta_uapsd |= BIT(1);
  2327. if (vi)
  2328. wpa_s->sta_uapsd |= BIT(2);
  2329. if (vo)
  2330. wpa_s->sta_uapsd |= BIT(3);
  2331. }
  2332. return 0;
  2333. }
  2334. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
  2335. cmd);
  2336. return -1;
  2337. }
  2338. static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
  2339. {
  2340. char *pos, *pos2;
  2341. unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
  2342. if (cmd[0]) {
  2343. pos = os_strchr(cmd, ' ');
  2344. if (pos == NULL)
  2345. return -1;
  2346. *pos++ = '\0';
  2347. dur1 = atoi(cmd);
  2348. pos2 = os_strchr(pos, ' ');
  2349. if (pos2)
  2350. *pos2++ = '\0';
  2351. int1 = atoi(pos);
  2352. } else
  2353. pos2 = NULL;
  2354. if (pos2) {
  2355. pos = os_strchr(pos2, ' ');
  2356. if (pos == NULL)
  2357. return -1;
  2358. *pos++ = '\0';
  2359. dur2 = atoi(pos2);
  2360. int2 = atoi(pos);
  2361. }
  2362. return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
  2363. }
  2364. static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
  2365. {
  2366. char *pos;
  2367. unsigned int period = 0, interval = 0;
  2368. if (cmd[0]) {
  2369. pos = os_strchr(cmd, ' ');
  2370. if (pos == NULL)
  2371. return -1;
  2372. *pos++ = '\0';
  2373. period = atoi(cmd);
  2374. interval = atoi(pos);
  2375. }
  2376. return wpas_p2p_ext_listen(wpa_s, period, interval);
  2377. }
  2378. #endif /* CONFIG_P2P */
  2379. static int wpa_supplicant_ctrl_iface_sta_autoconnect(
  2380. struct wpa_supplicant *wpa_s, char *cmd)
  2381. {
  2382. wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
  2383. return 0;
  2384. }
  2385. char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
  2386. char *buf, size_t *resp_len)
  2387. {
  2388. char *reply;
  2389. const int reply_size = 4096;
  2390. int ctrl_rsp = 0;
  2391. int reply_len;
  2392. if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
  2393. os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  2394. wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
  2395. (const u8 *) buf, os_strlen(buf));
  2396. } else {
  2397. int level = MSG_DEBUG;
  2398. if (os_strcmp(buf, "PING") == 0)
  2399. level = MSG_EXCESSIVE;
  2400. wpa_hexdump_ascii(level, "RX ctrl_iface",
  2401. (const u8 *) buf, os_strlen(buf));
  2402. }
  2403. reply = os_malloc(reply_size);
  2404. if (reply == NULL) {
  2405. *resp_len = 1;
  2406. return NULL;
  2407. }
  2408. os_memcpy(reply, "OK\n", 3);
  2409. reply_len = 3;
  2410. if (os_strcmp(buf, "PING") == 0) {
  2411. os_memcpy(reply, "PONG\n", 5);
  2412. reply_len = 5;
  2413. } else if (os_strncmp(buf, "RELOG", 5) == 0) {
  2414. if (wpa_debug_reopen_file() < 0)
  2415. reply_len = -1;
  2416. } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
  2417. wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
  2418. } else if (os_strcmp(buf, "MIB") == 0) {
  2419. reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
  2420. if (reply_len >= 0) {
  2421. int res;
  2422. res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
  2423. reply_size - reply_len);
  2424. if (res < 0)
  2425. reply_len = -1;
  2426. else
  2427. reply_len += res;
  2428. }
  2429. } else if (os_strncmp(buf, "STATUS", 6) == 0) {
  2430. reply_len = wpa_supplicant_ctrl_iface_status(
  2431. wpa_s, buf + 6, reply, reply_size);
  2432. } else if (os_strcmp(buf, "PMKSA") == 0) {
  2433. reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
  2434. reply_size);
  2435. } else if (os_strncmp(buf, "SET ", 4) == 0) {
  2436. if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
  2437. reply_len = -1;
  2438. } else if (os_strncmp(buf, "GET ", 4) == 0) {
  2439. reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
  2440. reply, reply_size);
  2441. } else if (os_strcmp(buf, "LOGON") == 0) {
  2442. eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
  2443. } else if (os_strcmp(buf, "LOGOFF") == 0) {
  2444. eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
  2445. } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
  2446. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  2447. reply_len = -1;
  2448. else {
  2449. wpa_s->disconnected = 0;
  2450. wpa_s->reassociate = 1;
  2451. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2452. }
  2453. } else if (os_strcmp(buf, "RECONNECT") == 0) {
  2454. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  2455. reply_len = -1;
  2456. else if (wpa_s->disconnected) {
  2457. wpa_s->disconnected = 0;
  2458. wpa_s->reassociate = 1;
  2459. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2460. }
  2461. #ifdef IEEE8021X_EAPOL
  2462. } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
  2463. if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
  2464. reply_len = -1;
  2465. #endif /* IEEE8021X_EAPOL */
  2466. #ifdef CONFIG_PEERKEY
  2467. } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
  2468. if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
  2469. reply_len = -1;
  2470. #endif /* CONFIG_PEERKEY */
  2471. #ifdef CONFIG_IEEE80211R
  2472. } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
  2473. if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
  2474. reply_len = -1;
  2475. #endif /* CONFIG_IEEE80211R */
  2476. #ifdef CONFIG_WPS
  2477. } else if (os_strcmp(buf, "WPS_PBC") == 0) {
  2478. if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL))
  2479. reply_len = -1;
  2480. } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
  2481. if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8))
  2482. reply_len = -1;
  2483. } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
  2484. reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
  2485. reply,
  2486. reply_size);
  2487. } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
  2488. reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
  2489. wpa_s, buf + 14, reply, reply_size);
  2490. } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
  2491. if (wpas_wps_cancel(wpa_s))
  2492. reply_len = -1;
  2493. #ifdef CONFIG_WPS_OOB
  2494. } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
  2495. if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8))
  2496. reply_len = -1;
  2497. #endif /* CONFIG_WPS_OOB */
  2498. } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
  2499. if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
  2500. reply_len = -1;
  2501. #ifdef CONFIG_AP
  2502. } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
  2503. reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
  2504. wpa_s, buf + 11, reply, reply_size);
  2505. #endif /* CONFIG_AP */
  2506. #ifdef CONFIG_WPS_ER
  2507. } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
  2508. if (wpas_wps_er_start(wpa_s, NULL))
  2509. reply_len = -1;
  2510. } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
  2511. if (wpas_wps_er_start(wpa_s, buf + 13))
  2512. reply_len = -1;
  2513. } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
  2514. if (wpas_wps_er_stop(wpa_s))
  2515. reply_len = -1;
  2516. } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
  2517. if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
  2518. reply_len = -1;
  2519. } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
  2520. int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
  2521. if (ret == -2) {
  2522. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  2523. reply_len = 17;
  2524. } else if (ret == -3) {
  2525. os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
  2526. reply_len = 18;
  2527. } else if (ret == -4) {
  2528. os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
  2529. reply_len = 20;
  2530. } else if (ret)
  2531. reply_len = -1;
  2532. } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
  2533. if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
  2534. reply_len = -1;
  2535. } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
  2536. if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
  2537. buf + 18))
  2538. reply_len = -1;
  2539. } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
  2540. if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
  2541. reply_len = -1;
  2542. #endif /* CONFIG_WPS_ER */
  2543. #endif /* CONFIG_WPS */
  2544. #ifdef CONFIG_IBSS_RSN
  2545. } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
  2546. if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
  2547. reply_len = -1;
  2548. #endif /* CONFIG_IBSS_RSN */
  2549. #ifdef CONFIG_P2P
  2550. } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
  2551. if (p2p_ctrl_find(wpa_s, buf + 9))
  2552. reply_len = -1;
  2553. } else if (os_strcmp(buf, "P2P_FIND") == 0) {
  2554. if (p2p_ctrl_find(wpa_s, ""))
  2555. reply_len = -1;
  2556. } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
  2557. wpas_p2p_stop_find(wpa_s);
  2558. } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
  2559. reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
  2560. reply_size);
  2561. } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
  2562. if (p2p_ctrl_listen(wpa_s, buf + 11))
  2563. reply_len = -1;
  2564. } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
  2565. if (p2p_ctrl_listen(wpa_s, ""))
  2566. reply_len = -1;
  2567. } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
  2568. if (wpas_p2p_group_remove(wpa_s, buf + 17))
  2569. reply_len = -1;
  2570. } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
  2571. if (wpas_p2p_group_add(wpa_s, 0, 0))
  2572. reply_len = -1;
  2573. } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
  2574. if (p2p_ctrl_group_add(wpa_s, buf + 14))
  2575. reply_len = -1;
  2576. } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
  2577. if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
  2578. reply_len = -1;
  2579. } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
  2580. reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
  2581. } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
  2582. reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
  2583. reply_size);
  2584. } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
  2585. if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
  2586. reply_len = -1;
  2587. } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
  2588. if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
  2589. reply_len = -1;
  2590. } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
  2591. wpas_p2p_sd_service_update(wpa_s);
  2592. } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
  2593. if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
  2594. reply_len = -1;
  2595. } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
  2596. wpas_p2p_service_flush(wpa_s);
  2597. } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
  2598. if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
  2599. reply_len = -1;
  2600. } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
  2601. if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
  2602. reply_len = -1;
  2603. } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
  2604. if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
  2605. reply_len = -1;
  2606. } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
  2607. if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
  2608. reply_len = -1;
  2609. } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
  2610. reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
  2611. reply_size);
  2612. } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
  2613. if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
  2614. reply_len = -1;
  2615. } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
  2616. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  2617. wpa_s->force_long_sd = 0;
  2618. if (wpa_s->global->p2p)
  2619. p2p_flush(wpa_s->global->p2p);
  2620. } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
  2621. if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
  2622. reply_len = -1;
  2623. } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
  2624. if (wpas_p2p_cancel(wpa_s))
  2625. reply_len = -1;
  2626. } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
  2627. if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
  2628. reply_len = -1;
  2629. } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
  2630. if (p2p_ctrl_presence_req(wpa_s, "") < 0)
  2631. reply_len = -1;
  2632. } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
  2633. if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
  2634. reply_len = -1;
  2635. } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
  2636. if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
  2637. reply_len = -1;
  2638. #endif /* CONFIG_P2P */
  2639. } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
  2640. {
  2641. if (wpa_supplicant_ctrl_iface_ctrl_rsp(
  2642. wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
  2643. reply_len = -1;
  2644. else
  2645. ctrl_rsp = 1;
  2646. } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
  2647. if (wpa_supplicant_reload_configuration(wpa_s))
  2648. reply_len = -1;
  2649. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  2650. wpa_supplicant_terminate_proc(wpa_s->global);
  2651. } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
  2652. if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
  2653. reply_len = -1;
  2654. } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
  2655. reply_len = wpa_supplicant_ctrl_iface_list_networks(
  2656. wpa_s, reply, reply_size);
  2657. } else if (os_strcmp(buf, "DISCONNECT") == 0) {
  2658. wpa_s->reassociate = 0;
  2659. wpa_s->disconnected = 1;
  2660. wpa_supplicant_deauthenticate(wpa_s,
  2661. WLAN_REASON_DEAUTH_LEAVING);
  2662. } else if (os_strcmp(buf, "SCAN") == 0) {
  2663. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  2664. reply_len = -1;
  2665. else {
  2666. wpa_s->scan_req = 2;
  2667. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2668. }
  2669. } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
  2670. reply_len = wpa_supplicant_ctrl_iface_scan_results(
  2671. wpa_s, reply, reply_size);
  2672. } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
  2673. if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
  2674. reply_len = -1;
  2675. } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
  2676. if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
  2677. reply_len = -1;
  2678. } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
  2679. if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
  2680. reply_len = -1;
  2681. } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
  2682. reply_len = wpa_supplicant_ctrl_iface_add_network(
  2683. wpa_s, reply, reply_size);
  2684. } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
  2685. if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
  2686. reply_len = -1;
  2687. } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  2688. if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
  2689. reply_len = -1;
  2690. } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
  2691. reply_len = wpa_supplicant_ctrl_iface_get_network(
  2692. wpa_s, buf + 12, reply, reply_size);
  2693. #ifndef CONFIG_NO_CONFIG_WRITE
  2694. } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
  2695. if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
  2696. reply_len = -1;
  2697. #endif /* CONFIG_NO_CONFIG_WRITE */
  2698. } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
  2699. reply_len = wpa_supplicant_ctrl_iface_get_capability(
  2700. wpa_s, buf + 15, reply, reply_size);
  2701. } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
  2702. if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
  2703. reply_len = -1;
  2704. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  2705. reply_len = wpa_supplicant_global_iface_list(
  2706. wpa_s->global, reply, reply_size);
  2707. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  2708. reply_len = wpa_supplicant_global_iface_interfaces(
  2709. wpa_s->global, reply, reply_size);
  2710. } else if (os_strncmp(buf, "BSS ", 4) == 0) {
  2711. reply_len = wpa_supplicant_ctrl_iface_bss(
  2712. wpa_s, buf + 4, reply, reply_size);
  2713. #ifdef CONFIG_AP
  2714. } else if (os_strcmp(buf, "STA-FIRST") == 0) {
  2715. reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
  2716. } else if (os_strncmp(buf, "STA ", 4) == 0) {
  2717. reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
  2718. reply_size);
  2719. } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
  2720. reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
  2721. reply_size);
  2722. #endif /* CONFIG_AP */
  2723. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  2724. wpas_notify_suspend(wpa_s->global);
  2725. } else if (os_strcmp(buf, "RESUME") == 0) {
  2726. wpas_notify_resume(wpa_s->global);
  2727. } else if (os_strcmp(buf, "DROP_SA") == 0) {
  2728. wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
  2729. } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
  2730. if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
  2731. reply_len = -1;
  2732. } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
  2733. if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
  2734. reply_len = -1;
  2735. #ifdef CONFIG_TDLS
  2736. } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
  2737. if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
  2738. reply_len = -1;
  2739. } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
  2740. if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
  2741. reply_len = -1;
  2742. } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
  2743. if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
  2744. reply_len = -1;
  2745. #endif /* CONFIG_TDLS */
  2746. } else {
  2747. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  2748. reply_len = 16;
  2749. }
  2750. if (reply_len < 0) {
  2751. os_memcpy(reply, "FAIL\n", 5);
  2752. reply_len = 5;
  2753. }
  2754. if (ctrl_rsp)
  2755. eapol_sm_notify_ctrl_response(wpa_s->eapol);
  2756. *resp_len = reply_len;
  2757. return reply;
  2758. }
  2759. static int wpa_supplicant_global_iface_add(struct wpa_global *global,
  2760. char *cmd)
  2761. {
  2762. struct wpa_interface iface;
  2763. char *pos;
  2764. /*
  2765. * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
  2766. * TAB<bridge_ifname>
  2767. */
  2768. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
  2769. os_memset(&iface, 0, sizeof(iface));
  2770. do {
  2771. iface.ifname = pos = cmd;
  2772. pos = os_strchr(pos, '\t');
  2773. if (pos)
  2774. *pos++ = '\0';
  2775. if (iface.ifname[0] == '\0')
  2776. return -1;
  2777. if (pos == NULL)
  2778. break;
  2779. iface.confname = pos;
  2780. pos = os_strchr(pos, '\t');
  2781. if (pos)
  2782. *pos++ = '\0';
  2783. if (iface.confname[0] == '\0')
  2784. iface.confname = NULL;
  2785. if (pos == NULL)
  2786. break;
  2787. iface.driver = pos;
  2788. pos = os_strchr(pos, '\t');
  2789. if (pos)
  2790. *pos++ = '\0';
  2791. if (iface.driver[0] == '\0')
  2792. iface.driver = NULL;
  2793. if (pos == NULL)
  2794. break;
  2795. iface.ctrl_interface = pos;
  2796. pos = os_strchr(pos, '\t');
  2797. if (pos)
  2798. *pos++ = '\0';
  2799. if (iface.ctrl_interface[0] == '\0')
  2800. iface.ctrl_interface = NULL;
  2801. if (pos == NULL)
  2802. break;
  2803. iface.driver_param = pos;
  2804. pos = os_strchr(pos, '\t');
  2805. if (pos)
  2806. *pos++ = '\0';
  2807. if (iface.driver_param[0] == '\0')
  2808. iface.driver_param = NULL;
  2809. if (pos == NULL)
  2810. break;
  2811. iface.bridge_ifname = pos;
  2812. pos = os_strchr(pos, '\t');
  2813. if (pos)
  2814. *pos++ = '\0';
  2815. if (iface.bridge_ifname[0] == '\0')
  2816. iface.bridge_ifname = NULL;
  2817. if (pos == NULL)
  2818. break;
  2819. } while (0);
  2820. if (wpa_supplicant_get_iface(global, iface.ifname))
  2821. return -1;
  2822. return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
  2823. }
  2824. static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
  2825. char *cmd)
  2826. {
  2827. struct wpa_supplicant *wpa_s;
  2828. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
  2829. wpa_s = wpa_supplicant_get_iface(global, cmd);
  2830. if (wpa_s == NULL)
  2831. return -1;
  2832. return wpa_supplicant_remove_iface(global, wpa_s);
  2833. }
  2834. static void wpa_free_iface_info(struct wpa_interface_info *iface)
  2835. {
  2836. struct wpa_interface_info *prev;
  2837. while (iface) {
  2838. prev = iface;
  2839. iface = iface->next;
  2840. os_free(prev->ifname);
  2841. os_free(prev->desc);
  2842. os_free(prev);
  2843. }
  2844. }
  2845. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  2846. char *buf, int len)
  2847. {
  2848. int i, res;
  2849. struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
  2850. char *pos, *end;
  2851. for (i = 0; wpa_drivers[i]; i++) {
  2852. struct wpa_driver_ops *drv = wpa_drivers[i];
  2853. if (drv->get_interfaces == NULL)
  2854. continue;
  2855. tmp = drv->get_interfaces(global->drv_priv[i]);
  2856. if (tmp == NULL)
  2857. continue;
  2858. if (last == NULL)
  2859. iface = last = tmp;
  2860. else
  2861. last->next = tmp;
  2862. while (last->next)
  2863. last = last->next;
  2864. }
  2865. pos = buf;
  2866. end = buf + len;
  2867. for (tmp = iface; tmp; tmp = tmp->next) {
  2868. res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
  2869. tmp->drv_name, tmp->ifname,
  2870. tmp->desc ? tmp->desc : "");
  2871. if (res < 0 || res >= end - pos) {
  2872. *pos = '\0';
  2873. break;
  2874. }
  2875. pos += res;
  2876. }
  2877. wpa_free_iface_info(iface);
  2878. return pos - buf;
  2879. }
  2880. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  2881. char *buf, int len)
  2882. {
  2883. int res;
  2884. char *pos, *end;
  2885. struct wpa_supplicant *wpa_s;
  2886. wpa_s = global->ifaces;
  2887. pos = buf;
  2888. end = buf + len;
  2889. while (wpa_s) {
  2890. res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
  2891. if (res < 0 || res >= end - pos) {
  2892. *pos = '\0';
  2893. break;
  2894. }
  2895. pos += res;
  2896. wpa_s = wpa_s->next;
  2897. }
  2898. return pos - buf;
  2899. }
  2900. char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
  2901. char *buf, size_t *resp_len)
  2902. {
  2903. char *reply;
  2904. const int reply_size = 2048;
  2905. int reply_len;
  2906. wpa_hexdump_ascii(MSG_DEBUG, "RX global ctrl_iface",
  2907. (const u8 *) buf, os_strlen(buf));
  2908. reply = os_malloc(reply_size);
  2909. if (reply == NULL) {
  2910. *resp_len = 1;
  2911. return NULL;
  2912. }
  2913. os_memcpy(reply, "OK\n", 3);
  2914. reply_len = 3;
  2915. if (os_strcmp(buf, "PING") == 0) {
  2916. os_memcpy(reply, "PONG\n", 5);
  2917. reply_len = 5;
  2918. } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
  2919. if (wpa_supplicant_global_iface_add(global, buf + 14))
  2920. reply_len = -1;
  2921. } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
  2922. if (wpa_supplicant_global_iface_remove(global, buf + 17))
  2923. reply_len = -1;
  2924. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  2925. reply_len = wpa_supplicant_global_iface_list(
  2926. global, reply, reply_size);
  2927. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  2928. reply_len = wpa_supplicant_global_iface_interfaces(
  2929. global, reply, reply_size);
  2930. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  2931. wpa_supplicant_terminate_proc(global);
  2932. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  2933. wpas_notify_suspend(global);
  2934. } else if (os_strcmp(buf, "RESUME") == 0) {
  2935. wpas_notify_resume(global);
  2936. } else {
  2937. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  2938. reply_len = 16;
  2939. }
  2940. if (reply_len < 0) {
  2941. os_memcpy(reply, "FAIL\n", 5);
  2942. reply_len = 5;
  2943. }
  2944. *resp_len = reply_len;
  2945. return reply;
  2946. }