ctrl_iface.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780
  1. /*
  2. * WPA Supplicant / Control interface (shared code for all backends)
  3. * Copyright (c) 2004-2008, 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 "includes.h"
  15. #include "common.h"
  16. #include "eloop.h"
  17. #include "wpa.h"
  18. #include "config.h"
  19. #include "eapol_supp/eapol_supp_sm.h"
  20. #include "wpa_supplicant_i.h"
  21. #include "ctrl_iface.h"
  22. #include "l2_packet/l2_packet.h"
  23. #include "preauth.h"
  24. #include "pmksa_cache.h"
  25. #include "wpa_ctrl.h"
  26. #include "eap_peer/eap.h"
  27. #include "ieee802_11_defs.h"
  28. #include "wps_supplicant.h"
  29. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  30. char *buf, int len);
  31. static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
  32. char *cmd)
  33. {
  34. char *value;
  35. int ret = 0;
  36. value = os_strchr(cmd, ' ');
  37. if (value == NULL)
  38. return -1;
  39. *value++ = '\0';
  40. wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
  41. if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
  42. eapol_sm_configure(wpa_s->eapol,
  43. atoi(value), -1, -1, -1);
  44. } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
  45. eapol_sm_configure(wpa_s->eapol,
  46. -1, atoi(value), -1, -1);
  47. } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
  48. eapol_sm_configure(wpa_s->eapol,
  49. -1, -1, atoi(value), -1);
  50. } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
  51. eapol_sm_configure(wpa_s->eapol,
  52. -1, -1, -1, atoi(value));
  53. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
  54. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
  55. atoi(value)))
  56. ret = -1;
  57. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
  58. 0) {
  59. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
  60. atoi(value)))
  61. ret = -1;
  62. } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
  63. if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
  64. ret = -1;
  65. } else
  66. ret = -1;
  67. return ret;
  68. }
  69. #ifdef IEEE8021X_EAPOL
  70. static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
  71. char *addr)
  72. {
  73. u8 bssid[ETH_ALEN];
  74. struct wpa_ssid *ssid = wpa_s->current_ssid;
  75. if (hwaddr_aton(addr, bssid)) {
  76. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
  77. "'%s'", addr);
  78. return -1;
  79. }
  80. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
  81. rsn_preauth_deinit(wpa_s->wpa);
  82. if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
  83. return -1;
  84. return 0;
  85. }
  86. #endif /* IEEE8021X_EAPOL */
  87. #ifdef CONFIG_PEERKEY
  88. /* MLME-STKSTART.request(peer) */
  89. static int wpa_supplicant_ctrl_iface_stkstart(
  90. struct wpa_supplicant *wpa_s, char *addr)
  91. {
  92. u8 peer[ETH_ALEN];
  93. if (hwaddr_aton(addr, peer)) {
  94. wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
  95. "address '%s'", peer);
  96. return -1;
  97. }
  98. wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
  99. MAC2STR(peer));
  100. return wpa_sm_stkstart(wpa_s->wpa, peer);
  101. }
  102. #endif /* CONFIG_PEERKEY */
  103. #ifdef CONFIG_IEEE80211R
  104. static int wpa_supplicant_ctrl_iface_ft_ds(
  105. struct wpa_supplicant *wpa_s, char *addr)
  106. {
  107. u8 target_ap[ETH_ALEN];
  108. if (hwaddr_aton(addr, target_ap)) {
  109. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
  110. "address '%s'", target_ap);
  111. return -1;
  112. }
  113. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
  114. return wpa_ft_start_over_ds(wpa_s->wpa, target_ap);
  115. }
  116. #endif /* CONFIG_IEEE80211R */
  117. #ifdef CONFIG_WPS
  118. static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
  119. char *cmd)
  120. {
  121. u8 bssid[ETH_ALEN];
  122. if (cmd == NULL || os_strcmp(cmd, "any") == 0)
  123. return wpas_wps_start_pbc(wpa_s, NULL);
  124. if (hwaddr_aton(cmd, bssid)) {
  125. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
  126. cmd);
  127. return -1;
  128. }
  129. return wpas_wps_start_pbc(wpa_s, bssid);
  130. }
  131. static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
  132. char *cmd, char *buf,
  133. size_t buflen)
  134. {
  135. u8 bssid[ETH_ALEN], *_bssid = bssid;
  136. char *pin;
  137. int ret;
  138. pin = os_strchr(cmd, ' ');
  139. if (pin)
  140. *pin++ = '\0';
  141. if (os_strcmp(cmd, "any") == 0)
  142. _bssid = NULL;
  143. else if (hwaddr_aton(cmd, bssid)) {
  144. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
  145. cmd);
  146. return -1;
  147. }
  148. if (pin) {
  149. ret = wpas_wps_start_pin(wpa_s, _bssid, pin);
  150. if (ret < 0)
  151. return -1;
  152. ret = os_snprintf(buf, buflen, "%s", pin);
  153. if (ret < 0 || (size_t) ret >= buflen)
  154. return -1;
  155. return ret;
  156. }
  157. ret = wpas_wps_start_pin(wpa_s, _bssid, NULL);
  158. if (ret < 0)
  159. return -1;
  160. /* Return the generated PIN */
  161. ret = os_snprintf(buf, buflen, "%08d", ret);
  162. if (ret < 0 || (size_t) ret >= buflen)
  163. return -1;
  164. return ret;
  165. }
  166. static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
  167. char *cmd)
  168. {
  169. u8 bssid[ETH_ALEN], *_bssid = bssid;
  170. char *pin;
  171. pin = os_strchr(cmd, ' ');
  172. if (pin == NULL)
  173. return -1;
  174. *pin++ = '\0';
  175. if (os_strcmp(cmd, "any") == 0)
  176. _bssid = NULL;
  177. else if (hwaddr_aton(cmd, bssid)) {
  178. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
  179. cmd);
  180. return -1;
  181. }
  182. return wpas_wps_start_reg(wpa_s, _bssid, pin);
  183. }
  184. #endif /* CONFIG_WPS */
  185. static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
  186. char *rsp)
  187. {
  188. #ifdef IEEE8021X_EAPOL
  189. char *pos, *id_pos;
  190. int id;
  191. struct wpa_ssid *ssid;
  192. struct eap_peer_config *eap;
  193. pos = os_strchr(rsp, '-');
  194. if (pos == NULL)
  195. return -1;
  196. *pos++ = '\0';
  197. id_pos = pos;
  198. pos = os_strchr(pos, ':');
  199. if (pos == NULL)
  200. return -1;
  201. *pos++ = '\0';
  202. id = atoi(id_pos);
  203. wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
  204. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  205. (u8 *) pos, os_strlen(pos));
  206. ssid = wpa_config_get_network(wpa_s->conf, id);
  207. if (ssid == NULL) {
  208. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  209. "to update", id);
  210. return -1;
  211. }
  212. eap = &ssid->eap;
  213. if (os_strcmp(rsp, "IDENTITY") == 0) {
  214. os_free(eap->identity);
  215. eap->identity = (u8 *) os_strdup(pos);
  216. eap->identity_len = os_strlen(pos);
  217. eap->pending_req_identity = 0;
  218. if (ssid == wpa_s->current_ssid)
  219. wpa_s->reassociate = 1;
  220. } else if (os_strcmp(rsp, "PASSWORD") == 0) {
  221. os_free(eap->password);
  222. eap->password = (u8 *) os_strdup(pos);
  223. eap->password_len = os_strlen(pos);
  224. eap->pending_req_password = 0;
  225. if (ssid == wpa_s->current_ssid)
  226. wpa_s->reassociate = 1;
  227. } else if (os_strcmp(rsp, "NEW_PASSWORD") == 0) {
  228. os_free(eap->new_password);
  229. eap->new_password = (u8 *) os_strdup(pos);
  230. eap->new_password_len = os_strlen(pos);
  231. eap->pending_req_new_password = 0;
  232. if (ssid == wpa_s->current_ssid)
  233. wpa_s->reassociate = 1;
  234. } else if (os_strcmp(rsp, "PIN") == 0) {
  235. os_free(eap->pin);
  236. eap->pin = os_strdup(pos);
  237. eap->pending_req_pin = 0;
  238. if (ssid == wpa_s->current_ssid)
  239. wpa_s->reassociate = 1;
  240. } else if (os_strcmp(rsp, "OTP") == 0) {
  241. os_free(eap->otp);
  242. eap->otp = (u8 *) os_strdup(pos);
  243. eap->otp_len = os_strlen(pos);
  244. os_free(eap->pending_req_otp);
  245. eap->pending_req_otp = NULL;
  246. eap->pending_req_otp_len = 0;
  247. } else if (os_strcmp(rsp, "PASSPHRASE") == 0) {
  248. os_free(eap->private_key_passwd);
  249. eap->private_key_passwd = (u8 *) os_strdup(pos);
  250. eap->pending_req_passphrase = 0;
  251. if (ssid == wpa_s->current_ssid)
  252. wpa_s->reassociate = 1;
  253. } else {
  254. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", rsp);
  255. return -1;
  256. }
  257. return 0;
  258. #else /* IEEE8021X_EAPOL */
  259. wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
  260. return -1;
  261. #endif /* IEEE8021X_EAPOL */
  262. }
  263. static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
  264. const char *params,
  265. char *buf, size_t buflen)
  266. {
  267. char *pos, *end, tmp[30];
  268. int res, verbose, ret;
  269. verbose = os_strcmp(params, "-VERBOSE") == 0;
  270. pos = buf;
  271. end = buf + buflen;
  272. if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
  273. struct wpa_ssid *ssid = wpa_s->current_ssid;
  274. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
  275. MAC2STR(wpa_s->bssid));
  276. if (ret < 0 || ret >= end - pos)
  277. return pos - buf;
  278. pos += ret;
  279. if (ssid) {
  280. u8 *_ssid = ssid->ssid;
  281. size_t ssid_len = ssid->ssid_len;
  282. u8 ssid_buf[MAX_SSID_LEN];
  283. if (ssid_len == 0) {
  284. int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
  285. if (_res < 0)
  286. ssid_len = 0;
  287. else
  288. ssid_len = _res;
  289. _ssid = ssid_buf;
  290. }
  291. ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
  292. wpa_ssid_txt(_ssid, ssid_len),
  293. ssid->id);
  294. if (ret < 0 || ret >= end - pos)
  295. return pos - buf;
  296. pos += ret;
  297. if (ssid->id_str) {
  298. ret = os_snprintf(pos, end - pos,
  299. "id_str=%s\n",
  300. ssid->id_str);
  301. if (ret < 0 || ret >= end - pos)
  302. return pos - buf;
  303. pos += ret;
  304. }
  305. }
  306. pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
  307. }
  308. ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
  309. wpa_supplicant_state_txt(wpa_s->wpa_state));
  310. if (ret < 0 || ret >= end - pos)
  311. return pos - buf;
  312. pos += ret;
  313. if (wpa_s->l2 &&
  314. l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
  315. ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
  316. if (ret < 0 || ret >= end - pos)
  317. return pos - buf;
  318. pos += ret;
  319. }
  320. if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  321. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  322. res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
  323. verbose);
  324. if (res >= 0)
  325. pos += res;
  326. }
  327. res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
  328. if (res >= 0)
  329. pos += res;
  330. return pos - buf;
  331. }
  332. static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
  333. char *cmd)
  334. {
  335. char *pos;
  336. int id;
  337. struct wpa_ssid *ssid;
  338. u8 bssid[ETH_ALEN];
  339. /* cmd: "<network id> <BSSID>" */
  340. pos = os_strchr(cmd, ' ');
  341. if (pos == NULL)
  342. return -1;
  343. *pos++ = '\0';
  344. id = atoi(cmd);
  345. wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
  346. if (hwaddr_aton(pos, bssid)) {
  347. wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
  348. return -1;
  349. }
  350. ssid = wpa_config_get_network(wpa_s->conf, id);
  351. if (ssid == NULL) {
  352. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  353. "to update", id);
  354. return -1;
  355. }
  356. os_memcpy(ssid->bssid, bssid, ETH_ALEN);
  357. ssid->bssid_set = !is_zero_ether_addr(bssid);
  358. return 0;
  359. }
  360. static int wpa_supplicant_ctrl_iface_list_networks(
  361. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  362. {
  363. char *pos, *end;
  364. struct wpa_ssid *ssid;
  365. int ret;
  366. pos = buf;
  367. end = buf + buflen;
  368. ret = os_snprintf(pos, end - pos,
  369. "network id / ssid / bssid / flags\n");
  370. if (ret < 0 || ret >= end - pos)
  371. return pos - buf;
  372. pos += ret;
  373. ssid = wpa_s->conf->ssid;
  374. while (ssid) {
  375. ret = os_snprintf(pos, end - pos, "%d\t%s",
  376. ssid->id,
  377. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  378. if (ret < 0 || ret >= end - pos)
  379. return pos - buf;
  380. pos += ret;
  381. if (ssid->bssid_set) {
  382. ret = os_snprintf(pos, end - pos, "\t" MACSTR,
  383. MAC2STR(ssid->bssid));
  384. } else {
  385. ret = os_snprintf(pos, end - pos, "\tany");
  386. }
  387. if (ret < 0 || ret >= end - pos)
  388. return pos - buf;
  389. pos += ret;
  390. ret = os_snprintf(pos, end - pos, "\t%s%s",
  391. ssid == wpa_s->current_ssid ?
  392. "[CURRENT]" : "",
  393. ssid->disabled ? "[DISABLED]" : "");
  394. if (ret < 0 || ret >= end - pos)
  395. return pos - buf;
  396. pos += ret;
  397. ret = os_snprintf(pos, end - pos, "\n");
  398. if (ret < 0 || ret >= end - pos)
  399. return pos - buf;
  400. pos += ret;
  401. ssid = ssid->next;
  402. }
  403. return pos - buf;
  404. }
  405. static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
  406. {
  407. int first = 1, ret;
  408. ret = os_snprintf(pos, end - pos, "-");
  409. if (ret < 0 || ret >= end - pos)
  410. return pos;
  411. pos += ret;
  412. if (cipher & WPA_CIPHER_NONE) {
  413. ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
  414. if (ret < 0 || ret >= end - pos)
  415. return pos;
  416. pos += ret;
  417. first = 0;
  418. }
  419. if (cipher & WPA_CIPHER_WEP40) {
  420. ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
  421. if (ret < 0 || ret >= end - pos)
  422. return pos;
  423. pos += ret;
  424. first = 0;
  425. }
  426. if (cipher & WPA_CIPHER_WEP104) {
  427. ret = os_snprintf(pos, end - pos, "%sWEP104",
  428. first ? "" : "+");
  429. if (ret < 0 || ret >= end - pos)
  430. return pos;
  431. pos += ret;
  432. first = 0;
  433. }
  434. if (cipher & WPA_CIPHER_TKIP) {
  435. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
  436. if (ret < 0 || ret >= end - pos)
  437. return pos;
  438. pos += ret;
  439. first = 0;
  440. }
  441. if (cipher & WPA_CIPHER_CCMP) {
  442. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
  443. if (ret < 0 || ret >= end - pos)
  444. return pos;
  445. pos += ret;
  446. first = 0;
  447. }
  448. return pos;
  449. }
  450. static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
  451. const u8 *ie, size_t ie_len)
  452. {
  453. struct wpa_ie_data data;
  454. int first, ret;
  455. ret = os_snprintf(pos, end - pos, "[%s-", proto);
  456. if (ret < 0 || ret >= end - pos)
  457. return pos;
  458. pos += ret;
  459. if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
  460. ret = os_snprintf(pos, end - pos, "?]");
  461. if (ret < 0 || ret >= end - pos)
  462. return pos;
  463. pos += ret;
  464. return pos;
  465. }
  466. first = 1;
  467. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  468. ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
  469. if (ret < 0 || ret >= end - pos)
  470. return pos;
  471. pos += ret;
  472. first = 0;
  473. }
  474. if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
  475. ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
  476. if (ret < 0 || ret >= end - pos)
  477. return pos;
  478. pos += ret;
  479. first = 0;
  480. }
  481. if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
  482. ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
  483. if (ret < 0 || ret >= end - pos)
  484. return pos;
  485. pos += ret;
  486. first = 0;
  487. }
  488. #ifdef CONFIG_IEEE80211R
  489. if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
  490. ret = os_snprintf(pos, end - pos, "%sFT/EAP",
  491. first ? "" : "+");
  492. if (ret < 0 || ret >= end - pos)
  493. return pos;
  494. pos += ret;
  495. first = 0;
  496. }
  497. if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
  498. ret = os_snprintf(pos, end - pos, "%sFT/PSK",
  499. first ? "" : "+");
  500. if (ret < 0 || ret >= end - pos)
  501. return pos;
  502. pos += ret;
  503. first = 0;
  504. }
  505. #endif /* CONFIG_IEEE80211R */
  506. #ifdef CONFIG_IEEE80211W
  507. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
  508. ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
  509. first ? "" : "+");
  510. if (ret < 0 || ret >= end - pos)
  511. return pos;
  512. pos += ret;
  513. first = 0;
  514. }
  515. if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
  516. ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
  517. first ? "" : "+");
  518. if (ret < 0 || ret >= end - pos)
  519. return pos;
  520. pos += ret;
  521. first = 0;
  522. }
  523. #endif /* CONFIG_IEEE80211W */
  524. pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
  525. if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
  526. ret = os_snprintf(pos, end - pos, "-preauth");
  527. if (ret < 0 || ret >= end - pos)
  528. return pos;
  529. pos += ret;
  530. }
  531. ret = os_snprintf(pos, end - pos, "]");
  532. if (ret < 0 || ret >= end - pos)
  533. return pos;
  534. pos += ret;
  535. return pos;
  536. }
  537. /* Format one result on one text line into a buffer. */
  538. static int wpa_supplicant_ctrl_iface_scan_result(
  539. const struct wpa_scan_res *res, char *buf, size_t buflen)
  540. {
  541. char *pos, *end;
  542. int ret;
  543. const u8 *ie, *ie2;
  544. pos = buf;
  545. end = buf + buflen;
  546. ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
  547. MAC2STR(res->bssid), res->freq, res->level);
  548. if (ret < 0 || ret >= end - pos)
  549. return pos - buf;
  550. pos += ret;
  551. ie = wpa_scan_get_vendor_ie(res, WPA_IE_VENDOR_TYPE);
  552. if (ie)
  553. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
  554. ie2 = wpa_scan_get_ie(res, WLAN_EID_RSN);
  555. if (ie2)
  556. pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
  557. if (!ie && !ie2 && res->caps & IEEE80211_CAP_PRIVACY) {
  558. ret = os_snprintf(pos, end - pos, "[WEP]");
  559. if (ret < 0 || ret >= end - pos)
  560. return pos - buf;
  561. pos += ret;
  562. }
  563. if (res->caps & IEEE80211_CAP_IBSS) {
  564. ret = os_snprintf(pos, end - pos, "[IBSS]");
  565. if (ret < 0 || ret >= end - pos)
  566. return pos - buf;
  567. pos += ret;
  568. }
  569. ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
  570. ret = os_snprintf(pos, end - pos, "\t%s",
  571. ie ? wpa_ssid_txt(ie + 2, ie[1]) : "");
  572. if (ret < 0 || ret >= end - pos)
  573. return pos - buf;
  574. pos += ret;
  575. ret = os_snprintf(pos, end - pos, "\n");
  576. if (ret < 0 || ret >= end - pos)
  577. return pos - buf;
  578. pos += ret;
  579. return pos - buf;
  580. }
  581. static int wpa_supplicant_ctrl_iface_scan_results(
  582. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  583. {
  584. char *pos, *end;
  585. struct wpa_scan_res *res;
  586. int ret;
  587. size_t i;
  588. if (wpa_s->scan_res == NULL &&
  589. wpa_supplicant_get_scan_results(wpa_s) < 0)
  590. return 0;
  591. pos = buf;
  592. end = buf + buflen;
  593. ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
  594. "flags / ssid\n");
  595. if (ret < 0 || ret >= end - pos)
  596. return pos - buf;
  597. pos += ret;
  598. for (i = 0; i < wpa_s->scan_res->num; i++) {
  599. res = wpa_s->scan_res->res[i];
  600. ret = wpa_supplicant_ctrl_iface_scan_result(res, pos,
  601. end - pos);
  602. if (ret < 0 || ret >= end - pos)
  603. return pos - buf;
  604. pos += ret;
  605. }
  606. return pos - buf;
  607. }
  608. static int wpa_supplicant_ctrl_iface_select_network(
  609. struct wpa_supplicant *wpa_s, char *cmd)
  610. {
  611. int id;
  612. struct wpa_ssid *ssid;
  613. /* cmd: "<network id>" or "any" */
  614. if (os_strcmp(cmd, "any") == 0) {
  615. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
  616. ssid = wpa_s->conf->ssid;
  617. while (ssid) {
  618. ssid->disabled = 0;
  619. ssid = ssid->next;
  620. }
  621. wpa_s->reassociate = 1;
  622. wpa_supplicant_req_scan(wpa_s, 0, 0);
  623. return 0;
  624. }
  625. id = atoi(cmd);
  626. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
  627. ssid = wpa_config_get_network(wpa_s->conf, id);
  628. if (ssid == NULL) {
  629. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  630. "id=%d", id);
  631. return -1;
  632. }
  633. if (ssid != wpa_s->current_ssid && wpa_s->current_ssid)
  634. wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  635. /* Mark all other networks disabled and trigger reassociation */
  636. ssid = wpa_s->conf->ssid;
  637. while (ssid) {
  638. ssid->disabled = id != ssid->id;
  639. ssid = ssid->next;
  640. }
  641. wpa_s->reassociate = 1;
  642. wpa_supplicant_req_scan(wpa_s, 0, 0);
  643. return 0;
  644. }
  645. static int wpa_supplicant_ctrl_iface_enable_network(
  646. struct wpa_supplicant *wpa_s, char *cmd)
  647. {
  648. int id;
  649. struct wpa_ssid *ssid;
  650. /* cmd: "<network id>" or "all" */
  651. if (os_strcmp(cmd, "all") == 0) {
  652. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
  653. ssid = wpa_s->conf->ssid;
  654. while (ssid) {
  655. if (ssid == wpa_s->current_ssid && ssid->disabled)
  656. wpa_s->reassociate = 1;
  657. ssid->disabled = 0;
  658. ssid = ssid->next;
  659. }
  660. if (wpa_s->reassociate)
  661. wpa_supplicant_req_scan(wpa_s, 0, 0);
  662. return 0;
  663. }
  664. id = atoi(cmd);
  665. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
  666. ssid = wpa_config_get_network(wpa_s->conf, id);
  667. if (ssid == NULL) {
  668. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  669. "id=%d", id);
  670. return -1;
  671. }
  672. if (wpa_s->current_ssid == NULL && ssid->disabled) {
  673. /*
  674. * Try to reassociate since there is no current configuration
  675. * and a new network was made available. */
  676. wpa_s->reassociate = 1;
  677. wpa_supplicant_req_scan(wpa_s, 0, 0);
  678. }
  679. ssid->disabled = 0;
  680. return 0;
  681. }
  682. static int wpa_supplicant_ctrl_iface_disable_network(
  683. struct wpa_supplicant *wpa_s, char *cmd)
  684. {
  685. int id;
  686. struct wpa_ssid *ssid;
  687. /* cmd: "<network id>" or "all" */
  688. if (os_strcmp(cmd, "all") == 0) {
  689. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
  690. ssid = wpa_s->conf->ssid;
  691. while (ssid) {
  692. ssid->disabled = 1;
  693. ssid = ssid->next;
  694. }
  695. if (wpa_s->current_ssid)
  696. wpa_supplicant_disassociate(wpa_s,
  697. WLAN_REASON_DEAUTH_LEAVING);
  698. return 0;
  699. }
  700. id = atoi(cmd);
  701. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
  702. ssid = wpa_config_get_network(wpa_s->conf, id);
  703. if (ssid == NULL) {
  704. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  705. "id=%d", id);
  706. return -1;
  707. }
  708. if (ssid == wpa_s->current_ssid)
  709. wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  710. ssid->disabled = 1;
  711. return 0;
  712. }
  713. static int wpa_supplicant_ctrl_iface_add_network(
  714. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  715. {
  716. struct wpa_ssid *ssid;
  717. int ret;
  718. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
  719. ssid = wpa_config_add_network(wpa_s->conf);
  720. if (ssid == NULL)
  721. return -1;
  722. ssid->disabled = 1;
  723. wpa_config_set_network_defaults(ssid);
  724. ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
  725. if (ret < 0 || (size_t) ret >= buflen)
  726. return -1;
  727. return ret;
  728. }
  729. static int wpa_supplicant_ctrl_iface_remove_network(
  730. struct wpa_supplicant *wpa_s, char *cmd)
  731. {
  732. int id;
  733. struct wpa_ssid *ssid;
  734. /* cmd: "<network id>" or "all" */
  735. if (os_strcmp(cmd, "all") == 0) {
  736. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
  737. ssid = wpa_s->conf->ssid;
  738. while (ssid) {
  739. id = ssid->id;
  740. ssid = ssid->next;
  741. wpa_config_remove_network(wpa_s->conf, id);
  742. }
  743. if (wpa_s->current_ssid) {
  744. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  745. wpa_supplicant_disassociate(wpa_s,
  746. WLAN_REASON_DEAUTH_LEAVING);
  747. }
  748. return 0;
  749. }
  750. id = atoi(cmd);
  751. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
  752. ssid = wpa_config_get_network(wpa_s->conf, id);
  753. if (ssid == NULL ||
  754. wpa_config_remove_network(wpa_s->conf, id) < 0) {
  755. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  756. "id=%d", id);
  757. return -1;
  758. }
  759. if (ssid == wpa_s->current_ssid) {
  760. /*
  761. * Invalidate the EAP session cache if the current network is
  762. * removed.
  763. */
  764. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  765. wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  766. }
  767. return 0;
  768. }
  769. static int wpa_supplicant_ctrl_iface_set_network(
  770. struct wpa_supplicant *wpa_s, char *cmd)
  771. {
  772. int id;
  773. struct wpa_ssid *ssid;
  774. char *name, *value;
  775. /* cmd: "<network id> <variable name> <value>" */
  776. name = os_strchr(cmd, ' ');
  777. if (name == NULL)
  778. return -1;
  779. *name++ = '\0';
  780. value = os_strchr(name, ' ');
  781. if (value == NULL)
  782. return -1;
  783. *value++ = '\0';
  784. id = atoi(cmd);
  785. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
  786. id, name);
  787. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  788. (u8 *) value, os_strlen(value));
  789. ssid = wpa_config_get_network(wpa_s->conf, id);
  790. if (ssid == NULL) {
  791. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  792. "id=%d", id);
  793. return -1;
  794. }
  795. if (wpa_config_set(ssid, name, value, 0) < 0) {
  796. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
  797. "variable '%s'", name);
  798. return -1;
  799. }
  800. if (wpa_s->current_ssid == ssid) {
  801. /*
  802. * Invalidate the EAP session cache if anything in the current
  803. * configuration changes.
  804. */
  805. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  806. }
  807. if ((os_strcmp(name, "psk") == 0 &&
  808. value[0] == '"' && ssid->ssid_len) ||
  809. (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
  810. wpa_config_update_psk(ssid);
  811. return 0;
  812. }
  813. static int wpa_supplicant_ctrl_iface_get_network(
  814. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  815. {
  816. int id;
  817. size_t res;
  818. struct wpa_ssid *ssid;
  819. char *name, *value;
  820. /* cmd: "<network id> <variable name>" */
  821. name = os_strchr(cmd, ' ');
  822. if (name == NULL || buflen == 0)
  823. return -1;
  824. *name++ = '\0';
  825. id = atoi(cmd);
  826. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
  827. id, name);
  828. ssid = wpa_config_get_network(wpa_s->conf, id);
  829. if (ssid == NULL) {
  830. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  831. "id=%d", id);
  832. return -1;
  833. }
  834. value = wpa_config_get_no_key(ssid, name);
  835. if (value == NULL) {
  836. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
  837. "variable '%s'", name);
  838. return -1;
  839. }
  840. res = os_strlcpy(buf, value, buflen);
  841. if (res >= buflen) {
  842. os_free(value);
  843. return -1;
  844. }
  845. os_free(value);
  846. return res;
  847. }
  848. #ifndef CONFIG_NO_CONFIG_WRITE
  849. static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
  850. {
  851. int ret;
  852. if (!wpa_s->conf->update_config) {
  853. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
  854. "to update configuration (update_config=0)");
  855. return -1;
  856. }
  857. ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
  858. if (ret) {
  859. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
  860. "update configuration");
  861. } else {
  862. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
  863. " updated");
  864. }
  865. return ret;
  866. }
  867. #endif /* CONFIG_NO_CONFIG_WRITE */
  868. static int ctrl_iface_get_capability_pairwise(int res, char *strict,
  869. struct wpa_driver_capa *capa,
  870. char *buf, size_t buflen)
  871. {
  872. int ret, first = 1;
  873. char *pos, *end;
  874. size_t len;
  875. pos = buf;
  876. end = pos + buflen;
  877. if (res < 0) {
  878. if (strict)
  879. return 0;
  880. len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
  881. if (len >= buflen)
  882. return -1;
  883. return len;
  884. }
  885. if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  886. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
  887. if (ret < 0 || ret >= end - pos)
  888. return pos - buf;
  889. pos += ret;
  890. first = 0;
  891. }
  892. if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  893. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
  894. if (ret < 0 || ret >= end - pos)
  895. return pos - buf;
  896. pos += ret;
  897. first = 0;
  898. }
  899. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  900. ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " ");
  901. if (ret < 0 || ret >= end - pos)
  902. return pos - buf;
  903. pos += ret;
  904. first = 0;
  905. }
  906. return pos - buf;
  907. }
  908. static int ctrl_iface_get_capability_group(int res, char *strict,
  909. struct wpa_driver_capa *capa,
  910. char *buf, size_t buflen)
  911. {
  912. int ret, first = 1;
  913. char *pos, *end;
  914. size_t len;
  915. pos = buf;
  916. end = pos + buflen;
  917. if (res < 0) {
  918. if (strict)
  919. return 0;
  920. len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
  921. if (len >= buflen)
  922. return -1;
  923. return len;
  924. }
  925. if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  926. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
  927. if (ret < 0 || ret >= end - pos)
  928. return pos - buf;
  929. pos += ret;
  930. first = 0;
  931. }
  932. if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  933. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
  934. if (ret < 0 || ret >= end - pos)
  935. return pos - buf;
  936. pos += ret;
  937. first = 0;
  938. }
  939. if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) {
  940. ret = os_snprintf(pos, end - pos, "%sWEP104",
  941. first ? "" : " ");
  942. if (ret < 0 || ret >= end - pos)
  943. return pos - buf;
  944. pos += ret;
  945. first = 0;
  946. }
  947. if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) {
  948. ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " ");
  949. if (ret < 0 || ret >= end - pos)
  950. return pos - buf;
  951. pos += ret;
  952. first = 0;
  953. }
  954. return pos - buf;
  955. }
  956. static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
  957. struct wpa_driver_capa *capa,
  958. char *buf, size_t buflen)
  959. {
  960. int ret;
  961. char *pos, *end;
  962. size_t len;
  963. pos = buf;
  964. end = pos + buflen;
  965. if (res < 0) {
  966. if (strict)
  967. return 0;
  968. len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
  969. "NONE", buflen);
  970. if (len >= buflen)
  971. return -1;
  972. return len;
  973. }
  974. ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
  975. if (ret < 0 || ret >= end - pos)
  976. return pos - buf;
  977. pos += ret;
  978. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  979. WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
  980. ret = os_snprintf(pos, end - pos, " WPA-EAP");
  981. if (ret < 0 || ret >= end - pos)
  982. return pos - buf;
  983. pos += ret;
  984. }
  985. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
  986. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  987. ret = os_snprintf(pos, end - pos, " WPA-PSK");
  988. if (ret < 0 || ret >= end - pos)
  989. return pos - buf;
  990. pos += ret;
  991. }
  992. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  993. ret = os_snprintf(pos, end - pos, " WPA-NONE");
  994. if (ret < 0 || ret >= end - pos)
  995. return pos - buf;
  996. pos += ret;
  997. }
  998. return pos - buf;
  999. }
  1000. static int ctrl_iface_get_capability_proto(int res, char *strict,
  1001. struct wpa_driver_capa *capa,
  1002. char *buf, size_t buflen)
  1003. {
  1004. int ret, first = 1;
  1005. char *pos, *end;
  1006. size_t len;
  1007. pos = buf;
  1008. end = pos + buflen;
  1009. if (res < 0) {
  1010. if (strict)
  1011. return 0;
  1012. len = os_strlcpy(buf, "RSN WPA", buflen);
  1013. if (len >= buflen)
  1014. return -1;
  1015. return len;
  1016. }
  1017. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
  1018. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1019. ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
  1020. if (ret < 0 || ret >= end - pos)
  1021. return pos - buf;
  1022. pos += ret;
  1023. first = 0;
  1024. }
  1025. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1026. WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
  1027. ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
  1028. if (ret < 0 || ret >= end - pos)
  1029. return pos - buf;
  1030. pos += ret;
  1031. first = 0;
  1032. }
  1033. return pos - buf;
  1034. }
  1035. static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
  1036. struct wpa_driver_capa *capa,
  1037. char *buf, size_t buflen)
  1038. {
  1039. int ret, first = 1;
  1040. char *pos, *end;
  1041. size_t len;
  1042. pos = buf;
  1043. end = pos + buflen;
  1044. if (res < 0) {
  1045. if (strict)
  1046. return 0;
  1047. len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
  1048. if (len >= buflen)
  1049. return -1;
  1050. return len;
  1051. }
  1052. if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
  1053. ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
  1054. if (ret < 0 || ret >= end - pos)
  1055. return pos - buf;
  1056. pos += ret;
  1057. first = 0;
  1058. }
  1059. if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
  1060. ret = os_snprintf(pos, end - pos, "%sSHARED",
  1061. first ? "" : " ");
  1062. if (ret < 0 || ret >= end - pos)
  1063. return pos - buf;
  1064. pos += ret;
  1065. first = 0;
  1066. }
  1067. if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
  1068. ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
  1069. if (ret < 0 || ret >= end - pos)
  1070. return pos - buf;
  1071. pos += ret;
  1072. first = 0;
  1073. }
  1074. return pos - buf;
  1075. }
  1076. static int wpa_supplicant_ctrl_iface_get_capability(
  1077. struct wpa_supplicant *wpa_s, const char *_field, char *buf,
  1078. size_t buflen)
  1079. {
  1080. struct wpa_driver_capa capa;
  1081. int res;
  1082. char *strict;
  1083. char field[30];
  1084. size_t len;
  1085. /* Determine whether or not strict checking was requested */
  1086. len = os_strlcpy(field, _field, sizeof(field));
  1087. if (len >= sizeof(field))
  1088. return -1;
  1089. strict = os_strchr(field, ' ');
  1090. if (strict != NULL) {
  1091. *strict++ = '\0';
  1092. if (os_strcmp(strict, "strict") != 0)
  1093. return -1;
  1094. }
  1095. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
  1096. field, strict ? strict : "");
  1097. if (os_strcmp(field, "eap") == 0) {
  1098. return eap_get_names(buf, buflen);
  1099. }
  1100. res = wpa_drv_get_capa(wpa_s, &capa);
  1101. if (os_strcmp(field, "pairwise") == 0)
  1102. return ctrl_iface_get_capability_pairwise(res, strict, &capa,
  1103. buf, buflen);
  1104. if (os_strcmp(field, "group") == 0)
  1105. return ctrl_iface_get_capability_group(res, strict, &capa,
  1106. buf, buflen);
  1107. if (os_strcmp(field, "key_mgmt") == 0)
  1108. return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
  1109. buf, buflen);
  1110. if (os_strcmp(field, "proto") == 0)
  1111. return ctrl_iface_get_capability_proto(res, strict, &capa,
  1112. buf, buflen);
  1113. if (os_strcmp(field, "auth_alg") == 0)
  1114. return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
  1115. buf, buflen);
  1116. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
  1117. field);
  1118. return -1;
  1119. }
  1120. static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
  1121. const char *cmd, char *buf,
  1122. size_t buflen)
  1123. {
  1124. u8 bssid[ETH_ALEN];
  1125. size_t i;
  1126. struct wpa_scan_results *results;
  1127. struct wpa_scan_res *bss;
  1128. int ret;
  1129. char *pos, *end;
  1130. const u8 *ie, *ie2;
  1131. if (wpa_s->scan_res == NULL &&
  1132. wpa_supplicant_get_scan_results(wpa_s) < 0)
  1133. return 0;
  1134. results = wpa_s->scan_res;
  1135. if (results == NULL)
  1136. return 0;
  1137. if (hwaddr_aton(cmd, bssid) == 0) {
  1138. for (i = 0; i < results->num; i++) {
  1139. if (os_memcmp(bssid, results->res[i]->bssid, ETH_ALEN)
  1140. == 0)
  1141. break;
  1142. }
  1143. } else
  1144. i = atoi(cmd);
  1145. if (i >= results->num || results->res[i] == NULL)
  1146. return 0; /* no match found */
  1147. bss = results->res[i];
  1148. pos = buf;
  1149. end = buf + buflen;
  1150. ret = os_snprintf(pos, end - pos,
  1151. "bssid=" MACSTR "\n"
  1152. "freq=%d\n"
  1153. "beacon_int=%d\n"
  1154. "capabilities=0x%04x\n"
  1155. "qual=%d\n"
  1156. "noise=%d\n"
  1157. "level=%d\n"
  1158. "tsf=%016llu\n"
  1159. "ie=",
  1160. MAC2STR(bss->bssid), bss->freq, bss->beacon_int,
  1161. bss->caps, bss->qual, bss->noise, bss->level,
  1162. (unsigned long long) bss->tsf);
  1163. if (ret < 0 || ret >= end - pos)
  1164. return pos - buf;
  1165. pos += ret;
  1166. ie = (const u8 *) (bss + 1);
  1167. for (i = 0; i < bss->ie_len; i++) {
  1168. ret = os_snprintf(pos, end - pos, "%02x", *ie++);
  1169. if (ret < 0 || ret >= end - pos)
  1170. return pos - buf;
  1171. pos += ret;
  1172. }
  1173. ret = os_snprintf(pos, end - pos, "\n");
  1174. if (ret < 0 || ret >= end - pos)
  1175. return pos - buf;
  1176. pos += ret;
  1177. ret = os_snprintf(pos, end - pos, "flags=");
  1178. if (ret < 0 || ret >= end - pos)
  1179. return pos - buf;
  1180. pos += ret;
  1181. ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  1182. if (ie)
  1183. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
  1184. ie2 = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  1185. if (ie2)
  1186. pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
  1187. if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
  1188. ret = os_snprintf(pos, end - pos, "[WEP]");
  1189. if (ret < 0 || ret >= end - pos)
  1190. return pos - buf;
  1191. pos += ret;
  1192. }
  1193. if (bss->caps & IEEE80211_CAP_IBSS) {
  1194. ret = os_snprintf(pos, end - pos, "[IBSS]");
  1195. if (ret < 0 || ret >= end - pos)
  1196. return pos - buf;
  1197. pos += ret;
  1198. }
  1199. ret = os_snprintf(pos, end - pos, "\n");
  1200. if (ret < 0 || ret >= end - pos)
  1201. return pos - buf;
  1202. pos += ret;
  1203. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  1204. ret = os_snprintf(pos, end - pos, "ssid=%s\n",
  1205. ie ? wpa_ssid_txt(ie + 2, ie[1]) : "");
  1206. if (ret < 0 || ret >= end - pos)
  1207. return pos - buf;
  1208. pos += ret;
  1209. return pos - buf;
  1210. }
  1211. static int wpa_supplicant_ctrl_iface_ap_scan(
  1212. struct wpa_supplicant *wpa_s, char *cmd)
  1213. {
  1214. int ap_scan = atoi(cmd);
  1215. if (ap_scan < 0 || ap_scan > 2)
  1216. return -1;
  1217. wpa_s->conf->ap_scan = ap_scan;
  1218. return 0;
  1219. }
  1220. char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
  1221. char *buf, size_t *resp_len)
  1222. {
  1223. char *reply;
  1224. const int reply_size = 2048;
  1225. int ctrl_rsp = 0;
  1226. int reply_len;
  1227. if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
  1228. os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  1229. wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
  1230. (const u8 *) buf, os_strlen(buf));
  1231. } else {
  1232. wpa_hexdump_ascii(MSG_DEBUG, "RX ctrl_iface",
  1233. (const u8 *) buf, os_strlen(buf));
  1234. }
  1235. reply = os_malloc(reply_size);
  1236. if (reply == NULL) {
  1237. *resp_len = 1;
  1238. return NULL;
  1239. }
  1240. os_memcpy(reply, "OK\n", 3);
  1241. reply_len = 3;
  1242. if (os_strcmp(buf, "PING") == 0) {
  1243. os_memcpy(reply, "PONG\n", 5);
  1244. reply_len = 5;
  1245. } else if (os_strcmp(buf, "MIB") == 0) {
  1246. reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
  1247. if (reply_len >= 0) {
  1248. int res;
  1249. res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
  1250. reply_size - reply_len);
  1251. if (res < 0)
  1252. reply_len = -1;
  1253. else
  1254. reply_len += res;
  1255. }
  1256. } else if (os_strncmp(buf, "STATUS", 6) == 0) {
  1257. reply_len = wpa_supplicant_ctrl_iface_status(
  1258. wpa_s, buf + 6, reply, reply_size);
  1259. } else if (os_strcmp(buf, "PMKSA") == 0) {
  1260. reply_len = pmksa_cache_list(wpa_s->wpa, reply, reply_size);
  1261. } else if (os_strncmp(buf, "SET ", 4) == 0) {
  1262. if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
  1263. reply_len = -1;
  1264. } else if (os_strcmp(buf, "LOGON") == 0) {
  1265. eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
  1266. } else if (os_strcmp(buf, "LOGOFF") == 0) {
  1267. eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
  1268. } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
  1269. wpa_s->disconnected = 0;
  1270. wpa_s->reassociate = 1;
  1271. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1272. } else if (os_strcmp(buf, "RECONNECT") == 0) {
  1273. if (wpa_s->disconnected) {
  1274. wpa_s->disconnected = 0;
  1275. wpa_s->reassociate = 1;
  1276. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1277. }
  1278. #ifdef IEEE8021X_EAPOL
  1279. } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
  1280. if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
  1281. reply_len = -1;
  1282. #endif /* IEEE8021X_EAPOL */
  1283. #ifdef CONFIG_PEERKEY
  1284. } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
  1285. if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
  1286. reply_len = -1;
  1287. #endif /* CONFIG_PEERKEY */
  1288. #ifdef CONFIG_IEEE80211R
  1289. } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
  1290. if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
  1291. reply_len = -1;
  1292. #endif /* CONFIG_IEEE80211R */
  1293. #ifdef CONFIG_WPS
  1294. } else if (os_strcmp(buf, "WPS_PBC") == 0) {
  1295. if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL))
  1296. reply_len = -1;
  1297. } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
  1298. if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8))
  1299. reply_len = -1;
  1300. } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
  1301. reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
  1302. reply,
  1303. reply_size);
  1304. } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
  1305. if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
  1306. reply_len = -1;
  1307. #endif /* CONFIG_WPS */
  1308. } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
  1309. {
  1310. if (wpa_supplicant_ctrl_iface_ctrl_rsp(
  1311. wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
  1312. reply_len = -1;
  1313. else
  1314. ctrl_rsp = 1;
  1315. } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
  1316. if (wpa_supplicant_reload_configuration(wpa_s))
  1317. reply_len = -1;
  1318. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  1319. eloop_terminate();
  1320. } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
  1321. if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
  1322. reply_len = -1;
  1323. } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
  1324. reply_len = wpa_supplicant_ctrl_iface_list_networks(
  1325. wpa_s, reply, reply_size);
  1326. } else if (os_strcmp(buf, "DISCONNECT") == 0) {
  1327. wpa_s->reassociate = 0;
  1328. wpa_s->disconnected = 1;
  1329. wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1330. } else if (os_strcmp(buf, "SCAN") == 0) {
  1331. wpa_s->scan_req = 2;
  1332. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1333. } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
  1334. reply_len = wpa_supplicant_ctrl_iface_scan_results(
  1335. wpa_s, reply, reply_size);
  1336. } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
  1337. if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
  1338. reply_len = -1;
  1339. } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
  1340. if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
  1341. reply_len = -1;
  1342. } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
  1343. if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
  1344. reply_len = -1;
  1345. } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
  1346. reply_len = wpa_supplicant_ctrl_iface_add_network(
  1347. wpa_s, reply, reply_size);
  1348. } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
  1349. if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
  1350. reply_len = -1;
  1351. } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  1352. if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
  1353. reply_len = -1;
  1354. } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
  1355. reply_len = wpa_supplicant_ctrl_iface_get_network(
  1356. wpa_s, buf + 12, reply, reply_size);
  1357. #ifndef CONFIG_NO_CONFIG_WRITE
  1358. } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
  1359. if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
  1360. reply_len = -1;
  1361. #endif /* CONFIG_NO_CONFIG_WRITE */
  1362. } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
  1363. reply_len = wpa_supplicant_ctrl_iface_get_capability(
  1364. wpa_s, buf + 15, reply, reply_size);
  1365. } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
  1366. if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
  1367. reply_len = -1;
  1368. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  1369. reply_len = wpa_supplicant_global_iface_interfaces(
  1370. wpa_s->global, reply, reply_size);
  1371. } else if (os_strncmp(buf, "BSS ", 4) == 0) {
  1372. reply_len = wpa_supplicant_ctrl_iface_bss(
  1373. wpa_s, buf + 4, reply, reply_size);
  1374. } else {
  1375. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  1376. reply_len = 16;
  1377. }
  1378. if (reply_len < 0) {
  1379. os_memcpy(reply, "FAIL\n", 5);
  1380. reply_len = 5;
  1381. }
  1382. if (ctrl_rsp)
  1383. eapol_sm_notify_ctrl_response(wpa_s->eapol);
  1384. *resp_len = reply_len;
  1385. return reply;
  1386. }
  1387. static int wpa_supplicant_global_iface_add(struct wpa_global *global,
  1388. char *cmd)
  1389. {
  1390. struct wpa_interface iface;
  1391. char *pos;
  1392. /*
  1393. * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
  1394. * TAB<bridge_ifname>
  1395. */
  1396. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
  1397. os_memset(&iface, 0, sizeof(iface));
  1398. do {
  1399. iface.ifname = pos = cmd;
  1400. pos = os_strchr(pos, '\t');
  1401. if (pos)
  1402. *pos++ = '\0';
  1403. if (iface.ifname[0] == '\0')
  1404. return -1;
  1405. if (pos == NULL)
  1406. break;
  1407. iface.confname = pos;
  1408. pos = os_strchr(pos, '\t');
  1409. if (pos)
  1410. *pos++ = '\0';
  1411. if (iface.confname[0] == '\0')
  1412. iface.confname = NULL;
  1413. if (pos == NULL)
  1414. break;
  1415. iface.driver = pos;
  1416. pos = os_strchr(pos, '\t');
  1417. if (pos)
  1418. *pos++ = '\0';
  1419. if (iface.driver[0] == '\0')
  1420. iface.driver = NULL;
  1421. if (pos == NULL)
  1422. break;
  1423. iface.ctrl_interface = pos;
  1424. pos = os_strchr(pos, '\t');
  1425. if (pos)
  1426. *pos++ = '\0';
  1427. if (iface.ctrl_interface[0] == '\0')
  1428. iface.ctrl_interface = NULL;
  1429. if (pos == NULL)
  1430. break;
  1431. iface.driver_param = pos;
  1432. pos = os_strchr(pos, '\t');
  1433. if (pos)
  1434. *pos++ = '\0';
  1435. if (iface.driver_param[0] == '\0')
  1436. iface.driver_param = NULL;
  1437. if (pos == NULL)
  1438. break;
  1439. iface.bridge_ifname = pos;
  1440. pos = os_strchr(pos, '\t');
  1441. if (pos)
  1442. *pos++ = '\0';
  1443. if (iface.bridge_ifname[0] == '\0')
  1444. iface.bridge_ifname = NULL;
  1445. if (pos == NULL)
  1446. break;
  1447. } while (0);
  1448. if (wpa_supplicant_get_iface(global, iface.ifname))
  1449. return -1;
  1450. return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
  1451. }
  1452. static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
  1453. char *cmd)
  1454. {
  1455. struct wpa_supplicant *wpa_s;
  1456. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
  1457. wpa_s = wpa_supplicant_get_iface(global, cmd);
  1458. if (wpa_s == NULL)
  1459. return -1;
  1460. return wpa_supplicant_remove_iface(global, wpa_s);
  1461. }
  1462. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  1463. char *buf, int len)
  1464. {
  1465. int res;
  1466. char *pos, *end;
  1467. struct wpa_supplicant *wpa_s;
  1468. wpa_s = global->ifaces;
  1469. pos = buf;
  1470. end = buf + len;
  1471. while (wpa_s) {
  1472. res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
  1473. if (res < 0 || res >= end - pos) {
  1474. *pos = '\0';
  1475. break;
  1476. }
  1477. pos += res;
  1478. wpa_s = wpa_s->next;
  1479. }
  1480. return pos - buf;
  1481. }
  1482. char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
  1483. char *buf, size_t *resp_len)
  1484. {
  1485. char *reply;
  1486. const int reply_size = 2048;
  1487. int reply_len;
  1488. wpa_hexdump_ascii(MSG_DEBUG, "RX global ctrl_iface",
  1489. (const u8 *) buf, os_strlen(buf));
  1490. reply = os_malloc(reply_size);
  1491. if (reply == NULL) {
  1492. *resp_len = 1;
  1493. return NULL;
  1494. }
  1495. os_memcpy(reply, "OK\n", 3);
  1496. reply_len = 3;
  1497. if (os_strcmp(buf, "PING") == 0) {
  1498. os_memcpy(reply, "PONG\n", 5);
  1499. reply_len = 5;
  1500. } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
  1501. if (wpa_supplicant_global_iface_add(global, buf + 14))
  1502. reply_len = -1;
  1503. } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
  1504. if (wpa_supplicant_global_iface_remove(global, buf + 17))
  1505. reply_len = -1;
  1506. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  1507. reply_len = wpa_supplicant_global_iface_interfaces(
  1508. global, reply, reply_size);
  1509. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  1510. eloop_terminate();
  1511. } else {
  1512. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  1513. reply_len = 16;
  1514. }
  1515. if (reply_len < 0) {
  1516. os_memcpy(reply, "FAIL\n", 5);
  1517. reply_len = 5;
  1518. }
  1519. *resp_len = reply_len;
  1520. return reply;
  1521. }