ctrl_iface.c 82 KB

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