Standardize on a single definition of auth_alg bitfield values
[hostap-gosc2009.git] / wpa_supplicant / ctrl_iface.c
blob7242e5ca4f1843768d27c6cbc13c05af5ad2babd
1 /*
2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
17 #include "utils/common.h"
18 #include "utils/eloop.h"
19 #include "common/ieee802_11_defs.h"
20 #include "common/wpa_ctrl.h"
21 #include "eap_peer/eap.h"
22 #include "eapol_supp/eapol_supp_sm.h"
23 #include "rsn_supp/wpa.h"
24 #include "rsn_supp/preauth.h"
25 #include "rsn_supp/pmksa_cache.h"
26 #include "l2_packet/l2_packet.h"
27 #include "wps/wps.h"
28 #include "config.h"
29 #include "wpa_supplicant_i.h"
30 #include "driver_i.h"
31 #include "wps_supplicant.h"
32 #include "ibss_rsn.h"
33 #include "ap.h"
34 #include "notify.h"
35 #include "bss.h"
36 #include "scan.h"
37 #include "ctrl_iface.h"
39 extern struct wpa_driver_ops *wpa_drivers[];
41 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
42 char *buf, int len);
43 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
44 char *buf, int len);
47 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
48 char *cmd)
50 char *value;
51 int ret = 0;
53 value = os_strchr(cmd, ' ');
54 if (value == NULL)
55 return -1;
56 *value++ = '\0';
58 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
59 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
60 eapol_sm_configure(wpa_s->eapol,
61 atoi(value), -1, -1, -1);
62 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
63 eapol_sm_configure(wpa_s->eapol,
64 -1, atoi(value), -1, -1);
65 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
66 eapol_sm_configure(wpa_s->eapol,
67 -1, -1, atoi(value), -1);
68 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
69 eapol_sm_configure(wpa_s->eapol,
70 -1, -1, -1, atoi(value));
71 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
72 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
73 atoi(value)))
74 ret = -1;
75 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
76 0) {
77 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
78 atoi(value)))
79 ret = -1;
80 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
81 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
82 ret = -1;
83 } else
84 ret = -1;
86 return ret;
90 #ifdef IEEE8021X_EAPOL
91 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
92 char *addr)
94 u8 bssid[ETH_ALEN];
95 struct wpa_ssid *ssid = wpa_s->current_ssid;
97 if (hwaddr_aton(addr, bssid)) {
98 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
99 "'%s'", addr);
100 return -1;
103 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
104 rsn_preauth_deinit(wpa_s->wpa);
105 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
106 return -1;
108 return 0;
110 #endif /* IEEE8021X_EAPOL */
113 #ifdef CONFIG_PEERKEY
114 /* MLME-STKSTART.request(peer) */
115 static int wpa_supplicant_ctrl_iface_stkstart(
116 struct wpa_supplicant *wpa_s, char *addr)
118 u8 peer[ETH_ALEN];
120 if (hwaddr_aton(addr, peer)) {
121 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
122 "address '%s'", peer);
123 return -1;
126 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
127 MAC2STR(peer));
129 return wpa_sm_stkstart(wpa_s->wpa, peer);
131 #endif /* CONFIG_PEERKEY */
134 #ifdef CONFIG_IEEE80211R
135 static int wpa_supplicant_ctrl_iface_ft_ds(
136 struct wpa_supplicant *wpa_s, char *addr)
138 u8 target_ap[ETH_ALEN];
140 if (hwaddr_aton(addr, target_ap)) {
141 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
142 "address '%s'", target_ap);
143 return -1;
146 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
148 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap);
150 #endif /* CONFIG_IEEE80211R */
153 #ifdef CONFIG_WPS
154 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
155 char *cmd)
157 u8 bssid[ETH_ALEN], *_bssid = bssid;
159 if (cmd == NULL || os_strcmp(cmd, "any") == 0)
160 _bssid = NULL;
161 else if (hwaddr_aton(cmd, bssid)) {
162 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
163 cmd);
164 return -1;
167 #ifdef CONFIG_AP
168 if (wpa_s->ap_iface)
169 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid);
170 #endif /* CONFIG_AP */
172 return wpas_wps_start_pbc(wpa_s, _bssid);
176 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
177 char *cmd, char *buf,
178 size_t buflen)
180 u8 bssid[ETH_ALEN], *_bssid = bssid;
181 char *pin;
182 int ret;
184 pin = os_strchr(cmd, ' ');
185 if (pin)
186 *pin++ = '\0';
188 if (os_strcmp(cmd, "any") == 0)
189 _bssid = NULL;
190 else if (hwaddr_aton(cmd, bssid)) {
191 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
192 cmd);
193 return -1;
196 #ifdef CONFIG_AP
197 if (wpa_s->ap_iface)
198 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
199 buf, buflen);
200 #endif /* CONFIG_AP */
202 if (pin) {
203 ret = wpas_wps_start_pin(wpa_s, _bssid, pin);
204 if (ret < 0)
205 return -1;
206 ret = os_snprintf(buf, buflen, "%s", pin);
207 if (ret < 0 || (size_t) ret >= buflen)
208 return -1;
209 return ret;
212 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL);
213 if (ret < 0)
214 return -1;
216 /* Return the generated PIN */
217 ret = os_snprintf(buf, buflen, "%08d", ret);
218 if (ret < 0 || (size_t) ret >= buflen)
219 return -1;
220 return ret;
224 #ifdef CONFIG_WPS_OOB
225 static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s,
226 char *cmd)
228 char *path, *method, *name;
230 path = os_strchr(cmd, ' ');
231 if (path == NULL)
232 return -1;
233 *path++ = '\0';
235 method = os_strchr(path, ' ');
236 if (method == NULL)
237 return -1;
238 *method++ = '\0';
240 name = os_strchr(method, ' ');
241 if (name != NULL)
242 *name++ = '\0';
244 return wpas_wps_start_oob(wpa_s, cmd, path, method, name);
246 #endif /* CONFIG_WPS_OOB */
249 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
250 char *cmd)
252 u8 bssid[ETH_ALEN], *_bssid = bssid;
253 char *pin;
254 char *new_ssid;
255 char *new_auth;
256 char *new_encr;
257 char *new_key;
258 struct wps_new_ap_settings ap;
260 pin = os_strchr(cmd, ' ');
261 if (pin == NULL)
262 return -1;
263 *pin++ = '\0';
265 if (os_strcmp(cmd, "any") == 0)
266 _bssid = NULL;
267 else if (hwaddr_aton(cmd, bssid)) {
268 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
269 cmd);
270 return -1;
273 new_ssid = os_strchr(pin, ' ');
274 if (new_ssid == NULL)
275 return wpas_wps_start_reg(wpa_s, _bssid, pin, NULL);
276 *new_ssid++ = '\0';
278 new_auth = os_strchr(new_ssid, ' ');
279 if (new_auth == NULL)
280 return -1;
281 *new_auth++ = '\0';
283 new_encr = os_strchr(new_auth, ' ');
284 if (new_encr == NULL)
285 return -1;
286 *new_encr++ = '\0';
288 new_key = os_strchr(new_encr, ' ');
289 if (new_key == NULL)
290 return -1;
291 *new_key++ = '\0';
293 os_memset(&ap, 0, sizeof(ap));
294 ap.ssid_hex = new_ssid;
295 ap.auth = new_auth;
296 ap.encr = new_encr;
297 ap.key_hex = new_key;
298 return wpas_wps_start_reg(wpa_s, _bssid, pin, &ap);
302 #ifdef CONFIG_WPS_ER
303 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
304 char *cmd)
306 char *uuid = cmd, *pin;
307 pin = os_strchr(uuid, ' ');
308 if (pin == NULL)
309 return -1;
310 *pin++ = '\0';
311 return wpas_wps_er_add_pin(wpa_s, uuid, pin);
315 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
316 char *cmd)
318 char *uuid = cmd, *pin;
319 pin = os_strchr(uuid, ' ');
320 if (pin == NULL)
321 return -1;
322 *pin++ = '\0';
323 return wpas_wps_er_learn(wpa_s, uuid, pin);
325 #endif /* CONFIG_WPS_ER */
327 #endif /* CONFIG_WPS */
330 #ifdef CONFIG_IBSS_RSN
331 static int wpa_supplicant_ctrl_iface_ibss_rsn(
332 struct wpa_supplicant *wpa_s, char *addr)
334 u8 peer[ETH_ALEN];
336 if (hwaddr_aton(addr, peer)) {
337 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
338 "address '%s'", peer);
339 return -1;
342 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
343 MAC2STR(peer));
345 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
347 #endif /* CONFIG_IBSS_RSN */
350 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
351 char *rsp)
353 #ifdef IEEE8021X_EAPOL
354 char *pos, *id_pos;
355 int id;
356 struct wpa_ssid *ssid;
357 struct eap_peer_config *eap;
359 pos = os_strchr(rsp, '-');
360 if (pos == NULL)
361 return -1;
362 *pos++ = '\0';
363 id_pos = pos;
364 pos = os_strchr(pos, ':');
365 if (pos == NULL)
366 return -1;
367 *pos++ = '\0';
368 id = atoi(id_pos);
369 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
370 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
371 (u8 *) pos, os_strlen(pos));
373 ssid = wpa_config_get_network(wpa_s->conf, id);
374 if (ssid == NULL) {
375 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
376 "to update", id);
377 return -1;
379 eap = &ssid->eap;
381 if (os_strcmp(rsp, "IDENTITY") == 0) {
382 os_free(eap->identity);
383 eap->identity = (u8 *) os_strdup(pos);
384 eap->identity_len = os_strlen(pos);
385 eap->pending_req_identity = 0;
386 if (ssid == wpa_s->current_ssid)
387 wpa_s->reassociate = 1;
388 } else if (os_strcmp(rsp, "PASSWORD") == 0) {
389 os_free(eap->password);
390 eap->password = (u8 *) os_strdup(pos);
391 eap->password_len = os_strlen(pos);
392 eap->pending_req_password = 0;
393 if (ssid == wpa_s->current_ssid)
394 wpa_s->reassociate = 1;
395 } else if (os_strcmp(rsp, "NEW_PASSWORD") == 0) {
396 os_free(eap->new_password);
397 eap->new_password = (u8 *) os_strdup(pos);
398 eap->new_password_len = os_strlen(pos);
399 eap->pending_req_new_password = 0;
400 if (ssid == wpa_s->current_ssid)
401 wpa_s->reassociate = 1;
402 } else if (os_strcmp(rsp, "PIN") == 0) {
403 os_free(eap->pin);
404 eap->pin = os_strdup(pos);
405 eap->pending_req_pin = 0;
406 if (ssid == wpa_s->current_ssid)
407 wpa_s->reassociate = 1;
408 } else if (os_strcmp(rsp, "OTP") == 0) {
409 os_free(eap->otp);
410 eap->otp = (u8 *) os_strdup(pos);
411 eap->otp_len = os_strlen(pos);
412 os_free(eap->pending_req_otp);
413 eap->pending_req_otp = NULL;
414 eap->pending_req_otp_len = 0;
415 } else if (os_strcmp(rsp, "PASSPHRASE") == 0) {
416 os_free(eap->private_key_passwd);
417 eap->private_key_passwd = (u8 *) os_strdup(pos);
418 eap->pending_req_passphrase = 0;
419 if (ssid == wpa_s->current_ssid)
420 wpa_s->reassociate = 1;
421 } else {
422 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", rsp);
423 return -1;
426 return 0;
427 #else /* IEEE8021X_EAPOL */
428 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
429 return -1;
430 #endif /* IEEE8021X_EAPOL */
434 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
435 const char *params,
436 char *buf, size_t buflen)
438 char *pos, *end, tmp[30];
439 int res, verbose, ret;
441 verbose = os_strcmp(params, "-VERBOSE") == 0;
442 pos = buf;
443 end = buf + buflen;
444 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
445 struct wpa_ssid *ssid = wpa_s->current_ssid;
446 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
447 MAC2STR(wpa_s->bssid));
448 if (ret < 0 || ret >= end - pos)
449 return pos - buf;
450 pos += ret;
451 if (ssid) {
452 u8 *_ssid = ssid->ssid;
453 size_t ssid_len = ssid->ssid_len;
454 u8 ssid_buf[MAX_SSID_LEN];
455 if (ssid_len == 0) {
456 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
457 if (_res < 0)
458 ssid_len = 0;
459 else
460 ssid_len = _res;
461 _ssid = ssid_buf;
463 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
464 wpa_ssid_txt(_ssid, ssid_len),
465 ssid->id);
466 if (ret < 0 || ret >= end - pos)
467 return pos - buf;
468 pos += ret;
470 if (ssid->id_str) {
471 ret = os_snprintf(pos, end - pos,
472 "id_str=%s\n",
473 ssid->id_str);
474 if (ret < 0 || ret >= end - pos)
475 return pos - buf;
476 pos += ret;
479 switch (ssid->mode) {
480 case WPAS_MODE_INFRA:
481 ret = os_snprintf(pos, end - pos,
482 "mode=station\n");
483 break;
484 case WPAS_MODE_IBSS:
485 ret = os_snprintf(pos, end - pos,
486 "mode=IBSS\n");
487 break;
488 case WPAS_MODE_AP:
489 ret = os_snprintf(pos, end - pos,
490 "mode=AP\n");
491 break;
492 default:
493 ret = 0;
494 break;
496 if (ret < 0 || ret >= end - pos)
497 return pos - buf;
498 pos += ret;
501 #ifdef CONFIG_AP
502 if (wpa_s->ap_iface) {
503 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
504 end - pos,
505 verbose);
506 } else
507 #endif /* CONFIG_AP */
508 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
510 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
511 wpa_supplicant_state_txt(wpa_s->wpa_state));
512 if (ret < 0 || ret >= end - pos)
513 return pos - buf;
514 pos += ret;
516 if (wpa_s->l2 &&
517 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
518 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
519 if (ret < 0 || ret >= end - pos)
520 return pos - buf;
521 pos += ret;
524 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
525 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
526 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
527 verbose);
528 if (res >= 0)
529 pos += res;
532 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
533 if (res >= 0)
534 pos += res;
536 return pos - buf;
540 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
541 char *cmd)
543 char *pos;
544 int id;
545 struct wpa_ssid *ssid;
546 u8 bssid[ETH_ALEN];
548 /* cmd: "<network id> <BSSID>" */
549 pos = os_strchr(cmd, ' ');
550 if (pos == NULL)
551 return -1;
552 *pos++ = '\0';
553 id = atoi(cmd);
554 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
555 if (hwaddr_aton(pos, bssid)) {
556 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
557 return -1;
560 ssid = wpa_config_get_network(wpa_s->conf, id);
561 if (ssid == NULL) {
562 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
563 "to update", id);
564 return -1;
567 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
568 ssid->bssid_set = !is_zero_ether_addr(bssid);
570 return 0;
574 static int wpa_supplicant_ctrl_iface_list_networks(
575 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
577 char *pos, *end;
578 struct wpa_ssid *ssid;
579 int ret;
581 pos = buf;
582 end = buf + buflen;
583 ret = os_snprintf(pos, end - pos,
584 "network id / ssid / bssid / flags\n");
585 if (ret < 0 || ret >= end - pos)
586 return pos - buf;
587 pos += ret;
589 ssid = wpa_s->conf->ssid;
590 while (ssid) {
591 ret = os_snprintf(pos, end - pos, "%d\t%s",
592 ssid->id,
593 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
594 if (ret < 0 || ret >= end - pos)
595 return pos - buf;
596 pos += ret;
597 if (ssid->bssid_set) {
598 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
599 MAC2STR(ssid->bssid));
600 } else {
601 ret = os_snprintf(pos, end - pos, "\tany");
603 if (ret < 0 || ret >= end - pos)
604 return pos - buf;
605 pos += ret;
606 ret = os_snprintf(pos, end - pos, "\t%s%s",
607 ssid == wpa_s->current_ssid ?
608 "[CURRENT]" : "",
609 ssid->disabled ? "[DISABLED]" : "");
610 if (ret < 0 || ret >= end - pos)
611 return pos - buf;
612 pos += ret;
613 ret = os_snprintf(pos, end - pos, "\n");
614 if (ret < 0 || ret >= end - pos)
615 return pos - buf;
616 pos += ret;
618 ssid = ssid->next;
621 return pos - buf;
625 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
627 int first = 1, ret;
628 ret = os_snprintf(pos, end - pos, "-");
629 if (ret < 0 || ret >= end - pos)
630 return pos;
631 pos += ret;
632 if (cipher & WPA_CIPHER_NONE) {
633 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
634 if (ret < 0 || ret >= end - pos)
635 return pos;
636 pos += ret;
637 first = 0;
639 if (cipher & WPA_CIPHER_WEP40) {
640 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
641 if (ret < 0 || ret >= end - pos)
642 return pos;
643 pos += ret;
644 first = 0;
646 if (cipher & WPA_CIPHER_WEP104) {
647 ret = os_snprintf(pos, end - pos, "%sWEP104",
648 first ? "" : "+");
649 if (ret < 0 || ret >= end - pos)
650 return pos;
651 pos += ret;
652 first = 0;
654 if (cipher & WPA_CIPHER_TKIP) {
655 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
656 if (ret < 0 || ret >= end - pos)
657 return pos;
658 pos += ret;
659 first = 0;
661 if (cipher & WPA_CIPHER_CCMP) {
662 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
663 if (ret < 0 || ret >= end - pos)
664 return pos;
665 pos += ret;
666 first = 0;
668 return pos;
672 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
673 const u8 *ie, size_t ie_len)
675 struct wpa_ie_data data;
676 int first, ret;
678 ret = os_snprintf(pos, end - pos, "[%s-", proto);
679 if (ret < 0 || ret >= end - pos)
680 return pos;
681 pos += ret;
683 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
684 ret = os_snprintf(pos, end - pos, "?]");
685 if (ret < 0 || ret >= end - pos)
686 return pos;
687 pos += ret;
688 return pos;
691 first = 1;
692 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
693 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
694 if (ret < 0 || ret >= end - pos)
695 return pos;
696 pos += ret;
697 first = 0;
699 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
700 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
701 if (ret < 0 || ret >= end - pos)
702 return pos;
703 pos += ret;
704 first = 0;
706 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
707 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
708 if (ret < 0 || ret >= end - pos)
709 return pos;
710 pos += ret;
711 first = 0;
713 #ifdef CONFIG_IEEE80211R
714 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
715 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
716 first ? "" : "+");
717 if (ret < 0 || ret >= end - pos)
718 return pos;
719 pos += ret;
720 first = 0;
722 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
723 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
724 first ? "" : "+");
725 if (ret < 0 || ret >= end - pos)
726 return pos;
727 pos += ret;
728 first = 0;
730 #endif /* CONFIG_IEEE80211R */
731 #ifdef CONFIG_IEEE80211W
732 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
733 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
734 first ? "" : "+");
735 if (ret < 0 || ret >= end - pos)
736 return pos;
737 pos += ret;
738 first = 0;
740 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
741 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
742 first ? "" : "+");
743 if (ret < 0 || ret >= end - pos)
744 return pos;
745 pos += ret;
746 first = 0;
748 #endif /* CONFIG_IEEE80211W */
750 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
752 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
753 ret = os_snprintf(pos, end - pos, "-preauth");
754 if (ret < 0 || ret >= end - pos)
755 return pos;
756 pos += ret;
759 ret = os_snprintf(pos, end - pos, "]");
760 if (ret < 0 || ret >= end - pos)
761 return pos;
762 pos += ret;
764 return pos;
768 #ifdef CONFIG_WPS
769 static char * wpa_supplicant_wps_ie_txt_buf(char *pos, char *end,
770 struct wpabuf *wps_ie)
772 int ret;
773 const char *txt;
775 if (wps_ie == NULL)
776 return pos;
777 if (wps_is_selected_pbc_registrar(wps_ie))
778 txt = "[WPS-PBC]";
779 else if (wps_is_selected_pin_registrar(wps_ie))
780 txt = "[WPS-PIN]";
781 else
782 txt = "[WPS]";
784 ret = os_snprintf(pos, end - pos, "%s", txt);
785 if (ret >= 0 && ret < end - pos)
786 pos += ret;
787 wpabuf_free(wps_ie);
788 return pos;
790 #endif /* CONFIG_WPS */
793 static char * wpa_supplicant_wps_ie_txt(char *pos, char *end,
794 const struct wpa_bss *bss)
796 #ifdef CONFIG_WPS
797 struct wpabuf *wps_ie;
798 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
799 return wpa_supplicant_wps_ie_txt_buf(pos, end, wps_ie);
800 #else /* CONFIG_WPS */
801 return pos;
802 #endif /* CONFIG_WPS */
806 /* Format one result on one text line into a buffer. */
807 static int wpa_supplicant_ctrl_iface_scan_result(
808 const struct wpa_bss *bss, char *buf, size_t buflen)
810 char *pos, *end;
811 int ret;
812 const u8 *ie, *ie2;
814 pos = buf;
815 end = buf + buflen;
817 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
818 MAC2STR(bss->bssid), bss->freq, bss->level);
819 if (ret < 0 || ret >= end - pos)
820 return pos - buf;
821 pos += ret;
822 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
823 if (ie)
824 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
825 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
826 if (ie2)
827 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
828 pos = wpa_supplicant_wps_ie_txt(pos, end, bss);
829 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
830 ret = os_snprintf(pos, end - pos, "[WEP]");
831 if (ret < 0 || ret >= end - pos)
832 return pos - buf;
833 pos += ret;
835 if (bss->caps & IEEE80211_CAP_IBSS) {
836 ret = os_snprintf(pos, end - pos, "[IBSS]");
837 if (ret < 0 || ret >= end - pos)
838 return pos - buf;
839 pos += ret;
841 if (bss->caps & IEEE80211_CAP_ESS) {
842 ret = os_snprintf(pos, end - pos, "[ESS]");
843 if (ret < 0 || ret >= end - pos)
844 return pos - buf;
845 pos += ret;
848 ret = os_snprintf(pos, end - pos, "\t%s",
849 wpa_ssid_txt(bss->ssid, bss->ssid_len));
850 if (ret < 0 || ret >= end - pos)
851 return pos - buf;
852 pos += ret;
854 ret = os_snprintf(pos, end - pos, "\n");
855 if (ret < 0 || ret >= end - pos)
856 return pos - buf;
857 pos += ret;
859 return pos - buf;
863 static int wpa_supplicant_ctrl_iface_scan_results(
864 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
866 char *pos, *end;
867 struct wpa_bss *bss;
868 int ret;
870 pos = buf;
871 end = buf + buflen;
872 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
873 "flags / ssid\n");
874 if (ret < 0 || ret >= end - pos)
875 return pos - buf;
876 pos += ret;
878 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
879 ret = wpa_supplicant_ctrl_iface_scan_result(bss, pos,
880 end - pos);
881 if (ret < 0 || ret >= end - pos)
882 return pos - buf;
883 pos += ret;
886 return pos - buf;
890 static int wpa_supplicant_ctrl_iface_select_network(
891 struct wpa_supplicant *wpa_s, char *cmd)
893 int id;
894 struct wpa_ssid *ssid;
896 /* cmd: "<network id>" or "any" */
897 if (os_strcmp(cmd, "any") == 0) {
898 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
899 ssid = NULL;
900 } else {
901 id = atoi(cmd);
902 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
904 ssid = wpa_config_get_network(wpa_s->conf, id);
905 if (ssid == NULL) {
906 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
907 "network id=%d", id);
908 return -1;
912 wpa_supplicant_select_network(wpa_s, ssid);
914 return 0;
918 static int wpa_supplicant_ctrl_iface_enable_network(
919 struct wpa_supplicant *wpa_s, char *cmd)
921 int id;
922 struct wpa_ssid *ssid;
924 /* cmd: "<network id>" or "all" */
925 if (os_strcmp(cmd, "all") == 0) {
926 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
927 ssid = NULL;
928 } else {
929 id = atoi(cmd);
930 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
932 ssid = wpa_config_get_network(wpa_s->conf, id);
933 if (ssid == NULL) {
934 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
935 "network id=%d", id);
936 return -1;
939 wpa_supplicant_enable_network(wpa_s, ssid);
941 return 0;
945 static int wpa_supplicant_ctrl_iface_disable_network(
946 struct wpa_supplicant *wpa_s, char *cmd)
948 int id;
949 struct wpa_ssid *ssid;
951 /* cmd: "<network id>" or "all" */
952 if (os_strcmp(cmd, "all") == 0) {
953 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
954 ssid = NULL;
955 } else {
956 id = atoi(cmd);
957 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
959 ssid = wpa_config_get_network(wpa_s->conf, id);
960 if (ssid == NULL) {
961 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
962 "network id=%d", id);
963 return -1;
966 wpa_supplicant_disable_network(wpa_s, ssid);
968 return 0;
972 static int wpa_supplicant_ctrl_iface_add_network(
973 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
975 struct wpa_ssid *ssid;
976 int ret;
978 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
980 ssid = wpa_config_add_network(wpa_s->conf);
981 if (ssid == NULL)
982 return -1;
984 wpas_notify_network_added(wpa_s, ssid);
986 ssid->disabled = 1;
987 wpa_config_set_network_defaults(ssid);
989 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
990 if (ret < 0 || (size_t) ret >= buflen)
991 return -1;
992 return ret;
996 static int wpa_supplicant_ctrl_iface_remove_network(
997 struct wpa_supplicant *wpa_s, char *cmd)
999 int id;
1000 struct wpa_ssid *ssid;
1002 /* cmd: "<network id>" or "all" */
1003 if (os_strcmp(cmd, "all") == 0) {
1004 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
1005 ssid = wpa_s->conf->ssid;
1006 while (ssid) {
1007 struct wpa_ssid *remove_ssid = ssid;
1008 id = ssid->id;
1009 ssid = ssid->next;
1010 wpas_notify_network_removed(wpa_s, remove_ssid);
1011 wpa_config_remove_network(wpa_s->conf, id);
1013 if (wpa_s->current_ssid) {
1014 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1015 wpa_supplicant_disassociate(wpa_s,
1016 WLAN_REASON_DEAUTH_LEAVING);
1018 return 0;
1021 id = atoi(cmd);
1022 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
1024 ssid = wpa_config_get_network(wpa_s->conf, id);
1025 if (ssid == NULL ||
1026 wpa_config_remove_network(wpa_s->conf, id) < 0) {
1027 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1028 "id=%d", id);
1029 return -1;
1032 if (ssid == wpa_s->current_ssid) {
1034 * Invalidate the EAP session cache if the current network is
1035 * removed.
1037 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1039 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1042 return 0;
1046 static int wpa_supplicant_ctrl_iface_set_network(
1047 struct wpa_supplicant *wpa_s, char *cmd)
1049 int id;
1050 struct wpa_ssid *ssid;
1051 char *name, *value;
1053 /* cmd: "<network id> <variable name> <value>" */
1054 name = os_strchr(cmd, ' ');
1055 if (name == NULL)
1056 return -1;
1057 *name++ = '\0';
1059 value = os_strchr(name, ' ');
1060 if (value == NULL)
1061 return -1;
1062 *value++ = '\0';
1064 id = atoi(cmd);
1065 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
1066 id, name);
1067 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1068 (u8 *) value, os_strlen(value));
1070 ssid = wpa_config_get_network(wpa_s->conf, id);
1071 if (ssid == NULL) {
1072 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1073 "id=%d", id);
1074 return -1;
1077 if (wpa_config_set(ssid, name, value, 0) < 0) {
1078 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
1079 "variable '%s'", name);
1080 return -1;
1083 if (wpa_s->current_ssid == ssid) {
1085 * Invalidate the EAP session cache if anything in the current
1086 * configuration changes.
1088 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1091 if ((os_strcmp(name, "psk") == 0 &&
1092 value[0] == '"' && ssid->ssid_len) ||
1093 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
1094 wpa_config_update_psk(ssid);
1096 return 0;
1100 static int wpa_supplicant_ctrl_iface_get_network(
1101 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1103 int id;
1104 size_t res;
1105 struct wpa_ssid *ssid;
1106 char *name, *value;
1108 /* cmd: "<network id> <variable name>" */
1109 name = os_strchr(cmd, ' ');
1110 if (name == NULL || buflen == 0)
1111 return -1;
1112 *name++ = '\0';
1114 id = atoi(cmd);
1115 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
1116 id, name);
1118 ssid = wpa_config_get_network(wpa_s->conf, id);
1119 if (ssid == NULL) {
1120 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1121 "id=%d", id);
1122 return -1;
1125 value = wpa_config_get_no_key(ssid, name);
1126 if (value == NULL) {
1127 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
1128 "variable '%s'", name);
1129 return -1;
1132 res = os_strlcpy(buf, value, buflen);
1133 if (res >= buflen) {
1134 os_free(value);
1135 return -1;
1138 os_free(value);
1140 return res;
1144 #ifndef CONFIG_NO_CONFIG_WRITE
1145 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
1147 int ret;
1149 if (!wpa_s->conf->update_config) {
1150 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
1151 "to update configuration (update_config=0)");
1152 return -1;
1155 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
1156 if (ret) {
1157 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
1158 "update configuration");
1159 } else {
1160 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
1161 " updated");
1164 return ret;
1166 #endif /* CONFIG_NO_CONFIG_WRITE */
1169 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
1170 struct wpa_driver_capa *capa,
1171 char *buf, size_t buflen)
1173 int ret, first = 1;
1174 char *pos, *end;
1175 size_t len;
1177 pos = buf;
1178 end = pos + buflen;
1180 if (res < 0) {
1181 if (strict)
1182 return 0;
1183 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
1184 if (len >= buflen)
1185 return -1;
1186 return len;
1189 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
1190 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
1191 if (ret < 0 || ret >= end - pos)
1192 return pos - buf;
1193 pos += ret;
1194 first = 0;
1197 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
1198 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
1199 if (ret < 0 || ret >= end - pos)
1200 return pos - buf;
1201 pos += ret;
1202 first = 0;
1205 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1206 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " ");
1207 if (ret < 0 || ret >= end - pos)
1208 return pos - buf;
1209 pos += ret;
1210 first = 0;
1213 return pos - buf;
1217 static int ctrl_iface_get_capability_group(int res, char *strict,
1218 struct wpa_driver_capa *capa,
1219 char *buf, size_t buflen)
1221 int ret, first = 1;
1222 char *pos, *end;
1223 size_t len;
1225 pos = buf;
1226 end = pos + buflen;
1228 if (res < 0) {
1229 if (strict)
1230 return 0;
1231 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
1232 if (len >= buflen)
1233 return -1;
1234 return len;
1237 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
1238 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
1239 if (ret < 0 || ret >= end - pos)
1240 return pos - buf;
1241 pos += ret;
1242 first = 0;
1245 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
1246 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
1247 if (ret < 0 || ret >= end - pos)
1248 return pos - buf;
1249 pos += ret;
1250 first = 0;
1253 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) {
1254 ret = os_snprintf(pos, end - pos, "%sWEP104",
1255 first ? "" : " ");
1256 if (ret < 0 || ret >= end - pos)
1257 return pos - buf;
1258 pos += ret;
1259 first = 0;
1262 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) {
1263 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " ");
1264 if (ret < 0 || ret >= end - pos)
1265 return pos - buf;
1266 pos += ret;
1267 first = 0;
1270 return pos - buf;
1274 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
1275 struct wpa_driver_capa *capa,
1276 char *buf, size_t buflen)
1278 int ret;
1279 char *pos, *end;
1280 size_t len;
1282 pos = buf;
1283 end = pos + buflen;
1285 if (res < 0) {
1286 if (strict)
1287 return 0;
1288 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
1289 "NONE", buflen);
1290 if (len >= buflen)
1291 return -1;
1292 return len;
1295 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
1296 if (ret < 0 || ret >= end - pos)
1297 return pos - buf;
1298 pos += ret;
1300 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1301 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
1302 ret = os_snprintf(pos, end - pos, " WPA-EAP");
1303 if (ret < 0 || ret >= end - pos)
1304 return pos - buf;
1305 pos += ret;
1308 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1309 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
1310 ret = os_snprintf(pos, end - pos, " WPA-PSK");
1311 if (ret < 0 || ret >= end - pos)
1312 return pos - buf;
1313 pos += ret;
1316 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1317 ret = os_snprintf(pos, end - pos, " WPA-NONE");
1318 if (ret < 0 || ret >= end - pos)
1319 return pos - buf;
1320 pos += ret;
1323 return pos - buf;
1327 static int ctrl_iface_get_capability_proto(int res, char *strict,
1328 struct wpa_driver_capa *capa,
1329 char *buf, size_t buflen)
1331 int ret, first = 1;
1332 char *pos, *end;
1333 size_t len;
1335 pos = buf;
1336 end = pos + buflen;
1338 if (res < 0) {
1339 if (strict)
1340 return 0;
1341 len = os_strlcpy(buf, "RSN WPA", buflen);
1342 if (len >= buflen)
1343 return -1;
1344 return len;
1347 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1348 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
1349 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
1350 if (ret < 0 || ret >= end - pos)
1351 return pos - buf;
1352 pos += ret;
1353 first = 0;
1356 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1357 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
1358 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
1359 if (ret < 0 || ret >= end - pos)
1360 return pos - buf;
1361 pos += ret;
1362 first = 0;
1365 return pos - buf;
1369 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
1370 struct wpa_driver_capa *capa,
1371 char *buf, size_t buflen)
1373 int ret, first = 1;
1374 char *pos, *end;
1375 size_t len;
1377 pos = buf;
1378 end = pos + buflen;
1380 if (res < 0) {
1381 if (strict)
1382 return 0;
1383 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
1384 if (len >= buflen)
1385 return -1;
1386 return len;
1389 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
1390 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
1391 if (ret < 0 || ret >= end - pos)
1392 return pos - buf;
1393 pos += ret;
1394 first = 0;
1397 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
1398 ret = os_snprintf(pos, end - pos, "%sSHARED",
1399 first ? "" : " ");
1400 if (ret < 0 || ret >= end - pos)
1401 return pos - buf;
1402 pos += ret;
1403 first = 0;
1406 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
1407 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
1408 if (ret < 0 || ret >= end - pos)
1409 return pos - buf;
1410 pos += ret;
1411 first = 0;
1414 return pos - buf;
1418 static int wpa_supplicant_ctrl_iface_get_capability(
1419 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
1420 size_t buflen)
1422 struct wpa_driver_capa capa;
1423 int res;
1424 char *strict;
1425 char field[30];
1426 size_t len;
1428 /* Determine whether or not strict checking was requested */
1429 len = os_strlcpy(field, _field, sizeof(field));
1430 if (len >= sizeof(field))
1431 return -1;
1432 strict = os_strchr(field, ' ');
1433 if (strict != NULL) {
1434 *strict++ = '\0';
1435 if (os_strcmp(strict, "strict") != 0)
1436 return -1;
1439 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
1440 field, strict ? strict : "");
1442 if (os_strcmp(field, "eap") == 0) {
1443 return eap_get_names(buf, buflen);
1446 res = wpa_drv_get_capa(wpa_s, &capa);
1448 if (os_strcmp(field, "pairwise") == 0)
1449 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
1450 buf, buflen);
1452 if (os_strcmp(field, "group") == 0)
1453 return ctrl_iface_get_capability_group(res, strict, &capa,
1454 buf, buflen);
1456 if (os_strcmp(field, "key_mgmt") == 0)
1457 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
1458 buf, buflen);
1460 if (os_strcmp(field, "proto") == 0)
1461 return ctrl_iface_get_capability_proto(res, strict, &capa,
1462 buf, buflen);
1464 if (os_strcmp(field, "auth_alg") == 0)
1465 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
1466 buf, buflen);
1468 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
1469 field);
1471 return -1;
1475 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
1476 const char *cmd, char *buf,
1477 size_t buflen)
1479 u8 bssid[ETH_ALEN];
1480 size_t i;
1481 struct wpa_bss *bss;
1482 int ret;
1483 char *pos, *end;
1484 const u8 *ie, *ie2;
1486 if (os_strcmp(cmd, "FIRST") == 0)
1487 bss = dl_list_first(&wpa_s->bss, struct wpa_bss, list);
1488 else if (os_strncmp(cmd, "ID-", 3) == 0) {
1489 i = atoi(cmd + 3);
1490 bss = wpa_bss_get_id(wpa_s, i);
1491 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
1492 i = atoi(cmd + 5);
1493 bss = wpa_bss_get_id(wpa_s, i);
1494 if (bss) {
1495 struct dl_list *next = bss->list_id.next;
1496 if (next == &wpa_s->bss_id)
1497 bss = NULL;
1498 else
1499 bss = dl_list_entry(next, struct wpa_bss,
1500 list_id);
1502 } else if (hwaddr_aton(cmd, bssid) == 0)
1503 bss = wpa_bss_get_bssid(wpa_s, bssid);
1504 else {
1505 struct wpa_bss *tmp;
1506 i = atoi(cmd);
1507 bss = NULL;
1508 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
1510 if (i-- == 0) {
1511 bss = tmp;
1512 break;
1517 if (bss == NULL)
1518 return 0;
1520 pos = buf;
1521 end = buf + buflen;
1522 ret = os_snprintf(pos, end - pos,
1523 "id=%u\n"
1524 "bssid=" MACSTR "\n"
1525 "freq=%d\n"
1526 "beacon_int=%d\n"
1527 "capabilities=0x%04x\n"
1528 "qual=%d\n"
1529 "noise=%d\n"
1530 "level=%d\n"
1531 "tsf=%016llu\n"
1532 "ie=",
1533 bss->id,
1534 MAC2STR(bss->bssid), bss->freq, bss->beacon_int,
1535 bss->caps, bss->qual, bss->noise, bss->level,
1536 (unsigned long long) bss->tsf);
1537 if (ret < 0 || ret >= end - pos)
1538 return pos - buf;
1539 pos += ret;
1541 ie = (const u8 *) (bss + 1);
1542 for (i = 0; i < bss->ie_len; i++) {
1543 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
1544 if (ret < 0 || ret >= end - pos)
1545 return pos - buf;
1546 pos += ret;
1549 ret = os_snprintf(pos, end - pos, "\n");
1550 if (ret < 0 || ret >= end - pos)
1551 return pos - buf;
1552 pos += ret;
1554 ret = os_snprintf(pos, end - pos, "flags=");
1555 if (ret < 0 || ret >= end - pos)
1556 return pos - buf;
1557 pos += ret;
1559 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1560 if (ie)
1561 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
1562 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1563 if (ie2)
1564 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
1565 pos = wpa_supplicant_wps_ie_txt(pos, end, bss);
1566 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
1567 ret = os_snprintf(pos, end - pos, "[WEP]");
1568 if (ret < 0 || ret >= end - pos)
1569 return pos - buf;
1570 pos += ret;
1572 if (bss->caps & IEEE80211_CAP_IBSS) {
1573 ret = os_snprintf(pos, end - pos, "[IBSS]");
1574 if (ret < 0 || ret >= end - pos)
1575 return pos - buf;
1576 pos += ret;
1578 if (bss->caps & IEEE80211_CAP_ESS) {
1579 ret = os_snprintf(pos, end - pos, "[ESS]");
1580 if (ret < 0 || ret >= end - pos)
1581 return pos - buf;
1582 pos += ret;
1585 ret = os_snprintf(pos, end - pos, "\n");
1586 if (ret < 0 || ret >= end - pos)
1587 return pos - buf;
1588 pos += ret;
1590 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
1591 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1592 if (ret < 0 || ret >= end - pos)
1593 return pos - buf;
1594 pos += ret;
1596 #ifdef CONFIG_WPS
1597 ie = (const u8 *) (bss + 1);
1598 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
1599 if (ret < 0 || ret >= end - pos)
1600 return pos - buf;
1601 pos += ret;
1602 #endif /* CONFIG_WPS */
1604 return pos - buf;
1608 static int wpa_supplicant_ctrl_iface_ap_scan(
1609 struct wpa_supplicant *wpa_s, char *cmd)
1611 int ap_scan = atoi(cmd);
1612 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
1616 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
1617 char *buf, size_t *resp_len)
1619 char *reply;
1620 const int reply_size = 2048;
1621 int ctrl_rsp = 0;
1622 int reply_len;
1624 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
1625 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
1626 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
1627 (const u8 *) buf, os_strlen(buf));
1628 } else {
1629 wpa_hexdump_ascii(MSG_DEBUG, "RX ctrl_iface",
1630 (const u8 *) buf, os_strlen(buf));
1633 reply = os_malloc(reply_size);
1634 if (reply == NULL) {
1635 *resp_len = 1;
1636 return NULL;
1639 os_memcpy(reply, "OK\n", 3);
1640 reply_len = 3;
1642 if (os_strcmp(buf, "PING") == 0) {
1643 os_memcpy(reply, "PONG\n", 5);
1644 reply_len = 5;
1645 } else if (os_strcmp(buf, "MIB") == 0) {
1646 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
1647 if (reply_len >= 0) {
1648 int res;
1649 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
1650 reply_size - reply_len);
1651 if (res < 0)
1652 reply_len = -1;
1653 else
1654 reply_len += res;
1656 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
1657 reply_len = wpa_supplicant_ctrl_iface_status(
1658 wpa_s, buf + 6, reply, reply_size);
1659 } else if (os_strcmp(buf, "PMKSA") == 0) {
1660 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
1661 reply_size);
1662 } else if (os_strncmp(buf, "SET ", 4) == 0) {
1663 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
1664 reply_len = -1;
1665 } else if (os_strcmp(buf, "LOGON") == 0) {
1666 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
1667 } else if (os_strcmp(buf, "LOGOFF") == 0) {
1668 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
1669 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
1670 wpa_s->disconnected = 0;
1671 wpa_s->reassociate = 1;
1672 wpa_supplicant_req_scan(wpa_s, 0, 0);
1673 } else if (os_strcmp(buf, "RECONNECT") == 0) {
1674 if (wpa_s->disconnected) {
1675 wpa_s->disconnected = 0;
1676 wpa_s->reassociate = 1;
1677 wpa_supplicant_req_scan(wpa_s, 0, 0);
1679 #ifdef IEEE8021X_EAPOL
1680 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
1681 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
1682 reply_len = -1;
1683 #endif /* IEEE8021X_EAPOL */
1684 #ifdef CONFIG_PEERKEY
1685 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
1686 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
1687 reply_len = -1;
1688 #endif /* CONFIG_PEERKEY */
1689 #ifdef CONFIG_IEEE80211R
1690 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
1691 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
1692 reply_len = -1;
1693 #endif /* CONFIG_IEEE80211R */
1694 #ifdef CONFIG_WPS
1695 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
1696 if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL))
1697 reply_len = -1;
1698 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
1699 if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8))
1700 reply_len = -1;
1701 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
1702 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
1703 reply,
1704 reply_size);
1705 #ifdef CONFIG_WPS_OOB
1706 } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
1707 if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8))
1708 reply_len = -1;
1709 #endif /* CONFIG_WPS_OOB */
1710 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
1711 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
1712 reply_len = -1;
1713 #ifdef CONFIG_WPS_ER
1714 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
1715 if (wpas_wps_er_start(wpa_s))
1716 reply_len = -1;
1717 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
1718 if (wpas_wps_er_stop(wpa_s))
1719 reply_len = -1;
1720 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
1721 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
1722 reply_len = -1;
1723 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
1724 if (wpas_wps_er_pbc(wpa_s, buf + 11))
1725 reply_len = -1;
1726 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
1727 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
1728 reply_len = -1;
1729 #endif /* CONFIG_WPS_ER */
1730 #endif /* CONFIG_WPS */
1731 #ifdef CONFIG_IBSS_RSN
1732 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
1733 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
1734 reply_len = -1;
1735 #endif /* CONFIG_IBSS_RSN */
1736 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
1738 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
1739 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
1740 reply_len = -1;
1741 else
1742 ctrl_rsp = 1;
1743 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
1744 if (wpa_supplicant_reload_configuration(wpa_s))
1745 reply_len = -1;
1746 } else if (os_strcmp(buf, "TERMINATE") == 0) {
1747 wpa_supplicant_terminate_proc(wpa_s->global);
1748 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
1749 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
1750 reply_len = -1;
1751 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
1752 reply_len = wpa_supplicant_ctrl_iface_list_networks(
1753 wpa_s, reply, reply_size);
1754 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
1755 wpa_s->reassociate = 0;
1756 wpa_s->disconnected = 1;
1757 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1758 } else if (os_strcmp(buf, "SCAN") == 0) {
1759 wpa_s->scan_req = 2;
1760 wpa_supplicant_req_scan(wpa_s, 0, 0);
1761 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
1762 reply_len = wpa_supplicant_ctrl_iface_scan_results(
1763 wpa_s, reply, reply_size);
1764 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
1765 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
1766 reply_len = -1;
1767 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
1768 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
1769 reply_len = -1;
1770 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
1771 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
1772 reply_len = -1;
1773 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
1774 reply_len = wpa_supplicant_ctrl_iface_add_network(
1775 wpa_s, reply, reply_size);
1776 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
1777 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
1778 reply_len = -1;
1779 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
1780 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
1781 reply_len = -1;
1782 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
1783 reply_len = wpa_supplicant_ctrl_iface_get_network(
1784 wpa_s, buf + 12, reply, reply_size);
1785 #ifndef CONFIG_NO_CONFIG_WRITE
1786 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
1787 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
1788 reply_len = -1;
1789 #endif /* CONFIG_NO_CONFIG_WRITE */
1790 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
1791 reply_len = wpa_supplicant_ctrl_iface_get_capability(
1792 wpa_s, buf + 15, reply, reply_size);
1793 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
1794 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
1795 reply_len = -1;
1796 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
1797 reply_len = wpa_supplicant_global_iface_list(
1798 wpa_s->global, reply, reply_size);
1799 } else if (os_strcmp(buf, "INTERFACES") == 0) {
1800 reply_len = wpa_supplicant_global_iface_interfaces(
1801 wpa_s->global, reply, reply_size);
1802 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
1803 reply_len = wpa_supplicant_ctrl_iface_bss(
1804 wpa_s, buf + 4, reply, reply_size);
1805 #ifdef CONFIG_AP
1806 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
1807 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
1808 } else if (os_strncmp(buf, "STA ", 4) == 0) {
1809 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
1810 reply_size);
1811 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
1812 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
1813 reply_size);
1814 #endif /* CONFIG_AP */
1815 } else {
1816 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
1817 reply_len = 16;
1820 if (reply_len < 0) {
1821 os_memcpy(reply, "FAIL\n", 5);
1822 reply_len = 5;
1825 if (ctrl_rsp)
1826 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1828 *resp_len = reply_len;
1829 return reply;
1833 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
1834 char *cmd)
1836 struct wpa_interface iface;
1837 char *pos;
1840 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
1841 * TAB<bridge_ifname>
1843 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
1845 os_memset(&iface, 0, sizeof(iface));
1847 do {
1848 iface.ifname = pos = cmd;
1849 pos = os_strchr(pos, '\t');
1850 if (pos)
1851 *pos++ = '\0';
1852 if (iface.ifname[0] == '\0')
1853 return -1;
1854 if (pos == NULL)
1855 break;
1857 iface.confname = pos;
1858 pos = os_strchr(pos, '\t');
1859 if (pos)
1860 *pos++ = '\0';
1861 if (iface.confname[0] == '\0')
1862 iface.confname = NULL;
1863 if (pos == NULL)
1864 break;
1866 iface.driver = pos;
1867 pos = os_strchr(pos, '\t');
1868 if (pos)
1869 *pos++ = '\0';
1870 if (iface.driver[0] == '\0')
1871 iface.driver = NULL;
1872 if (pos == NULL)
1873 break;
1875 iface.ctrl_interface = pos;
1876 pos = os_strchr(pos, '\t');
1877 if (pos)
1878 *pos++ = '\0';
1879 if (iface.ctrl_interface[0] == '\0')
1880 iface.ctrl_interface = NULL;
1881 if (pos == NULL)
1882 break;
1884 iface.driver_param = pos;
1885 pos = os_strchr(pos, '\t');
1886 if (pos)
1887 *pos++ = '\0';
1888 if (iface.driver_param[0] == '\0')
1889 iface.driver_param = NULL;
1890 if (pos == NULL)
1891 break;
1893 iface.bridge_ifname = pos;
1894 pos = os_strchr(pos, '\t');
1895 if (pos)
1896 *pos++ = '\0';
1897 if (iface.bridge_ifname[0] == '\0')
1898 iface.bridge_ifname = NULL;
1899 if (pos == NULL)
1900 break;
1901 } while (0);
1903 if (wpa_supplicant_get_iface(global, iface.ifname))
1904 return -1;
1906 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
1910 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
1911 char *cmd)
1913 struct wpa_supplicant *wpa_s;
1915 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
1917 wpa_s = wpa_supplicant_get_iface(global, cmd);
1918 if (wpa_s == NULL)
1919 return -1;
1920 return wpa_supplicant_remove_iface(global, wpa_s);
1924 static void wpa_free_iface_info(struct wpa_interface_info *iface)
1926 struct wpa_interface_info *prev;
1928 while (iface) {
1929 prev = iface;
1930 iface = iface->next;
1932 os_free(prev->ifname);
1933 os_free(prev->desc);
1934 os_free(prev);
1939 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
1940 char *buf, int len)
1942 int i, res;
1943 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
1944 char *pos, *end;
1946 for (i = 0; wpa_drivers[i]; i++) {
1947 struct wpa_driver_ops *drv = wpa_drivers[i];
1948 if (drv->get_interfaces == NULL)
1949 continue;
1950 tmp = drv->get_interfaces(global->drv_priv);
1951 if (tmp == NULL)
1952 continue;
1954 if (last == NULL)
1955 iface = last = tmp;
1956 else
1957 last->next = tmp;
1958 while (last->next)
1959 last = last->next;
1962 pos = buf;
1963 end = buf + len;
1964 for (tmp = iface; tmp; tmp = tmp->next) {
1965 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
1966 tmp->drv_name, tmp->ifname,
1967 tmp->desc ? tmp->desc : "");
1968 if (res < 0 || res >= end - pos) {
1969 *pos = '\0';
1970 break;
1972 pos += res;
1975 wpa_free_iface_info(iface);
1977 return pos - buf;
1981 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
1982 char *buf, int len)
1984 int res;
1985 char *pos, *end;
1986 struct wpa_supplicant *wpa_s;
1988 wpa_s = global->ifaces;
1989 pos = buf;
1990 end = buf + len;
1992 while (wpa_s) {
1993 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
1994 if (res < 0 || res >= end - pos) {
1995 *pos = '\0';
1996 break;
1998 pos += res;
1999 wpa_s = wpa_s->next;
2001 return pos - buf;
2005 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
2006 char *buf, size_t *resp_len)
2008 char *reply;
2009 const int reply_size = 2048;
2010 int reply_len;
2012 wpa_hexdump_ascii(MSG_DEBUG, "RX global ctrl_iface",
2013 (const u8 *) buf, os_strlen(buf));
2015 reply = os_malloc(reply_size);
2016 if (reply == NULL) {
2017 *resp_len = 1;
2018 return NULL;
2021 os_memcpy(reply, "OK\n", 3);
2022 reply_len = 3;
2024 if (os_strcmp(buf, "PING") == 0) {
2025 os_memcpy(reply, "PONG\n", 5);
2026 reply_len = 5;
2027 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
2028 if (wpa_supplicant_global_iface_add(global, buf + 14))
2029 reply_len = -1;
2030 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
2031 if (wpa_supplicant_global_iface_remove(global, buf + 17))
2032 reply_len = -1;
2033 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
2034 reply_len = wpa_supplicant_global_iface_list(
2035 global, reply, reply_size);
2036 } else if (os_strcmp(buf, "INTERFACES") == 0) {
2037 reply_len = wpa_supplicant_global_iface_interfaces(
2038 global, reply, reply_size);
2039 } else if (os_strcmp(buf, "TERMINATE") == 0) {
2040 wpa_supplicant_terminate_proc(global);
2041 } else {
2042 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
2043 reply_len = 16;
2046 if (reply_len < 0) {
2047 os_memcpy(reply, "FAIL\n", 5);
2048 reply_len = 5;
2051 *resp_len = reply_len;
2052 return reply;