]> git.ipfire.org Git - thirdparty/hostap.git/blob - wpa_supplicant/ctrl_iface.c
P2P: Allow p2p_invite-persistent to specify channel for GO
[thirdparty/hostap.git] / wpa_supplicant / ctrl_iface.c
1 /*
2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "utils/includes.h"
10
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/version.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/ieee802_11_common.h"
16 #include "common/wpa_ctrl.h"
17 #include "eap_peer/eap.h"
18 #include "eapol_supp/eapol_supp_sm.h"
19 #include "rsn_supp/wpa.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "l2_packet/l2_packet.h"
23 #include "wps/wps.h"
24 #include "config.h"
25 #include "wpa_supplicant_i.h"
26 #include "driver_i.h"
27 #include "wps_supplicant.h"
28 #include "ibss_rsn.h"
29 #include "ap.h"
30 #include "p2p_supplicant.h"
31 #include "p2p/p2p.h"
32 #include "hs20_supplicant.h"
33 #include "wifi_display.h"
34 #include "notify.h"
35 #include "bss.h"
36 #include "scan.h"
37 #include "ctrl_iface.h"
38 #include "interworking.h"
39 #include "blacklist.h"
40 #include "wpas_glue.h"
41 #include "autoscan.h"
42
43 extern struct wpa_driver_ops *wpa_drivers[];
44
45 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
46 char *buf, int len);
47 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
48 char *buf, int len);
49
50
51 static int pno_start(struct wpa_supplicant *wpa_s)
52 {
53 int ret;
54 size_t i, num_ssid;
55 struct wpa_ssid *ssid;
56 struct wpa_driver_scan_params params;
57
58 if (wpa_s->pno)
59 return 0;
60
61 os_memset(&params, 0, sizeof(params));
62
63 num_ssid = 0;
64 ssid = wpa_s->conf->ssid;
65 while (ssid) {
66 if (!wpas_network_disabled(wpa_s, ssid))
67 num_ssid++;
68 ssid = ssid->next;
69 }
70 if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
71 wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
72 "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
73 num_ssid = WPAS_MAX_SCAN_SSIDS;
74 }
75
76 if (num_ssid == 0) {
77 wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
78 return -1;
79 }
80
81 params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
82 num_ssid);
83 if (params.filter_ssids == NULL)
84 return -1;
85 i = 0;
86 ssid = wpa_s->conf->ssid;
87 while (ssid) {
88 if (!wpas_network_disabled(wpa_s, ssid)) {
89 params.ssids[i].ssid = ssid->ssid;
90 params.ssids[i].ssid_len = ssid->ssid_len;
91 params.num_ssids++;
92 os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
93 ssid->ssid_len);
94 params.filter_ssids[i].ssid_len = ssid->ssid_len;
95 params.num_filter_ssids++;
96 i++;
97 if (i == num_ssid)
98 break;
99 }
100 ssid = ssid->next;
101 }
102
103 if (wpa_s->conf->filter_rssi)
104 params.filter_rssi = wpa_s->conf->filter_rssi;
105
106 ret = wpa_drv_sched_scan(wpa_s, &params, 10 * 1000);
107 os_free(params.filter_ssids);
108 if (ret == 0)
109 wpa_s->pno = 1;
110 return ret;
111 }
112
113
114 static int pno_stop(struct wpa_supplicant *wpa_s)
115 {
116 if (wpa_s->pno) {
117 wpa_s->pno = 0;
118 return wpa_drv_stop_sched_scan(wpa_s);
119 }
120 return 0;
121 }
122
123
124 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
125 {
126 char *pos;
127 u8 addr[ETH_ALEN], *filter = NULL, *n;
128 size_t count = 0;
129
130 pos = val;
131 while (pos) {
132 if (*pos == '\0')
133 break;
134 if (hwaddr_aton(pos, addr)) {
135 os_free(filter);
136 return -1;
137 }
138 n = os_realloc_array(filter, count + 1, ETH_ALEN);
139 if (n == NULL) {
140 os_free(filter);
141 return -1;
142 }
143 filter = n;
144 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
145 count++;
146
147 pos = os_strchr(pos, ' ');
148 if (pos)
149 pos++;
150 }
151
152 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
153 os_free(wpa_s->bssid_filter);
154 wpa_s->bssid_filter = filter;
155 wpa_s->bssid_filter_count = count;
156
157 return 0;
158 }
159
160
161 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
162 char *cmd)
163 {
164 char *value;
165 int ret = 0;
166
167 value = os_strchr(cmd, ' ');
168 if (value == NULL)
169 return -1;
170 *value++ = '\0';
171
172 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
173 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
174 eapol_sm_configure(wpa_s->eapol,
175 atoi(value), -1, -1, -1);
176 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
177 eapol_sm_configure(wpa_s->eapol,
178 -1, atoi(value), -1, -1);
179 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
180 eapol_sm_configure(wpa_s->eapol,
181 -1, -1, atoi(value), -1);
182 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
183 eapol_sm_configure(wpa_s->eapol,
184 -1, -1, -1, atoi(value));
185 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
186 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
187 atoi(value)))
188 ret = -1;
189 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
190 0) {
191 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
192 atoi(value)))
193 ret = -1;
194 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
195 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
196 ret = -1;
197 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
198 wpa_s->wps_fragment_size = atoi(value);
199 #ifdef CONFIG_WPS_TESTING
200 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
201 long int val;
202 val = strtol(value, NULL, 0);
203 if (val < 0 || val > 0xff) {
204 ret = -1;
205 wpa_printf(MSG_DEBUG, "WPS: Invalid "
206 "wps_version_number %ld", val);
207 } else {
208 wps_version_number = val;
209 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
210 "version %u.%u",
211 (wps_version_number & 0xf0) >> 4,
212 wps_version_number & 0x0f);
213 }
214 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
215 wps_testing_dummy_cred = atoi(value);
216 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
217 wps_testing_dummy_cred);
218 #endif /* CONFIG_WPS_TESTING */
219 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
220 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
221 ret = -1;
222 #ifdef CONFIG_TDLS_TESTING
223 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
224 extern unsigned int tdls_testing;
225 tdls_testing = strtol(value, NULL, 0);
226 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
227 #endif /* CONFIG_TDLS_TESTING */
228 #ifdef CONFIG_TDLS
229 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
230 int disabled = atoi(value);
231 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
232 if (disabled) {
233 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
234 ret = -1;
235 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
236 ret = -1;
237 wpa_tdls_enable(wpa_s->wpa, !disabled);
238 #endif /* CONFIG_TDLS */
239 } else if (os_strcasecmp(cmd, "pno") == 0) {
240 if (atoi(value))
241 ret = pno_start(wpa_s);
242 else
243 ret = pno_stop(wpa_s);
244 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
245 int disabled = atoi(value);
246 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
247 ret = -1;
248 else if (disabled)
249 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
250 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
251 if (os_strcmp(value, "disable") == 0)
252 wpa_s->set_sta_uapsd = 0;
253 else {
254 int be, bk, vi, vo;
255 char *pos;
256 /* format: BE,BK,VI,VO;max SP Length */
257 be = atoi(value);
258 pos = os_strchr(value, ',');
259 if (pos == NULL)
260 return -1;
261 pos++;
262 bk = atoi(pos);
263 pos = os_strchr(pos, ',');
264 if (pos == NULL)
265 return -1;
266 pos++;
267 vi = atoi(pos);
268 pos = os_strchr(pos, ',');
269 if (pos == NULL)
270 return -1;
271 pos++;
272 vo = atoi(pos);
273 /* ignore max SP Length for now */
274
275 wpa_s->set_sta_uapsd = 1;
276 wpa_s->sta_uapsd = 0;
277 if (be)
278 wpa_s->sta_uapsd |= BIT(0);
279 if (bk)
280 wpa_s->sta_uapsd |= BIT(1);
281 if (vi)
282 wpa_s->sta_uapsd |= BIT(2);
283 if (vo)
284 wpa_s->sta_uapsd |= BIT(3);
285 }
286 } else if (os_strcasecmp(cmd, "ps") == 0) {
287 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
288 #ifdef CONFIG_WIFI_DISPLAY
289 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
290 wifi_display_enable(wpa_s->global, !!atoi(value));
291 #endif /* CONFIG_WIFI_DISPLAY */
292 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
293 ret = set_bssid_filter(wpa_s, value);
294 } else {
295 value[-1] = '=';
296 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
297 if (ret == 0)
298 wpa_supplicant_update_config(wpa_s);
299 }
300
301 return ret;
302 }
303
304
305 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
306 char *cmd, char *buf, size_t buflen)
307 {
308 int res = -1;
309
310 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
311
312 if (os_strcmp(cmd, "version") == 0) {
313 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
314 } else if (os_strcasecmp(cmd, "country") == 0) {
315 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
316 res = os_snprintf(buf, buflen, "%c%c",
317 wpa_s->conf->country[0],
318 wpa_s->conf->country[1]);
319 #ifdef CONFIG_WIFI_DISPLAY
320 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
321 res = os_snprintf(buf, buflen, "%d",
322 wpa_s->global->wifi_display);
323 if (res < 0 || (unsigned int) res >= buflen)
324 return -1;
325 return res;
326 #endif /* CONFIG_WIFI_DISPLAY */
327 }
328
329 if (res < 0 || (unsigned int) res >= buflen)
330 return -1;
331 return res;
332 }
333
334
335 #ifdef IEEE8021X_EAPOL
336 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
337 char *addr)
338 {
339 u8 bssid[ETH_ALEN];
340 struct wpa_ssid *ssid = wpa_s->current_ssid;
341
342 if (hwaddr_aton(addr, bssid)) {
343 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
344 "'%s'", addr);
345 return -1;
346 }
347
348 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
349 rsn_preauth_deinit(wpa_s->wpa);
350 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
351 return -1;
352
353 return 0;
354 }
355 #endif /* IEEE8021X_EAPOL */
356
357
358 #ifdef CONFIG_PEERKEY
359 /* MLME-STKSTART.request(peer) */
360 static int wpa_supplicant_ctrl_iface_stkstart(
361 struct wpa_supplicant *wpa_s, char *addr)
362 {
363 u8 peer[ETH_ALEN];
364
365 if (hwaddr_aton(addr, peer)) {
366 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
367 "address '%s'", addr);
368 return -1;
369 }
370
371 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
372 MAC2STR(peer));
373
374 return wpa_sm_stkstart(wpa_s->wpa, peer);
375 }
376 #endif /* CONFIG_PEERKEY */
377
378
379 #ifdef CONFIG_TDLS
380
381 static int wpa_supplicant_ctrl_iface_tdls_discover(
382 struct wpa_supplicant *wpa_s, char *addr)
383 {
384 u8 peer[ETH_ALEN];
385 int ret;
386
387 if (hwaddr_aton(addr, peer)) {
388 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
389 "address '%s'", addr);
390 return -1;
391 }
392
393 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
394 MAC2STR(peer));
395
396 if (wpa_tdls_is_external_setup(wpa_s->wpa))
397 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
398 else
399 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
400
401 return ret;
402 }
403
404
405 static int wpa_supplicant_ctrl_iface_tdls_setup(
406 struct wpa_supplicant *wpa_s, char *addr)
407 {
408 u8 peer[ETH_ALEN];
409 int ret;
410
411 if (hwaddr_aton(addr, peer)) {
412 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
413 "address '%s'", addr);
414 return -1;
415 }
416
417 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
418 MAC2STR(peer));
419
420 ret = wpa_tdls_reneg(wpa_s->wpa, peer);
421 if (ret) {
422 if (wpa_tdls_is_external_setup(wpa_s->wpa))
423 ret = wpa_tdls_start(wpa_s->wpa, peer);
424 else
425 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
426 }
427
428 return ret;
429 }
430
431
432 static int wpa_supplicant_ctrl_iface_tdls_teardown(
433 struct wpa_supplicant *wpa_s, char *addr)
434 {
435 u8 peer[ETH_ALEN];
436
437 if (hwaddr_aton(addr, peer)) {
438 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
439 "address '%s'", addr);
440 return -1;
441 }
442
443 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
444 MAC2STR(peer));
445
446 return wpa_tdls_teardown_link(wpa_s->wpa, peer,
447 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
448 }
449
450 #endif /* CONFIG_TDLS */
451
452
453 #ifdef CONFIG_IEEE80211R
454 static int wpa_supplicant_ctrl_iface_ft_ds(
455 struct wpa_supplicant *wpa_s, char *addr)
456 {
457 u8 target_ap[ETH_ALEN];
458 struct wpa_bss *bss;
459 const u8 *mdie;
460
461 if (hwaddr_aton(addr, target_ap)) {
462 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
463 "address '%s'", addr);
464 return -1;
465 }
466
467 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
468
469 bss = wpa_bss_get_bssid(wpa_s, target_ap);
470 if (bss)
471 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
472 else
473 mdie = NULL;
474
475 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
476 }
477 #endif /* CONFIG_IEEE80211R */
478
479
480 #ifdef CONFIG_WPS
481 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
482 char *cmd)
483 {
484 u8 bssid[ETH_ALEN], *_bssid = bssid;
485 #ifdef CONFIG_P2P
486 u8 p2p_dev_addr[ETH_ALEN];
487 #endif /* CONFIG_P2P */
488 #ifdef CONFIG_AP
489 u8 *_p2p_dev_addr = NULL;
490 #endif /* CONFIG_AP */
491
492 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
493 _bssid = NULL;
494 #ifdef CONFIG_P2P
495 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
496 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
497 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
498 "P2P Device Address '%s'",
499 cmd + 13);
500 return -1;
501 }
502 _p2p_dev_addr = p2p_dev_addr;
503 #endif /* CONFIG_P2P */
504 } else if (hwaddr_aton(cmd, bssid)) {
505 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
506 cmd);
507 return -1;
508 }
509
510 #ifdef CONFIG_AP
511 if (wpa_s->ap_iface)
512 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
513 #endif /* CONFIG_AP */
514
515 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
516 }
517
518
519 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
520 char *cmd, char *buf,
521 size_t buflen)
522 {
523 u8 bssid[ETH_ALEN], *_bssid = bssid;
524 char *pin;
525 int ret;
526
527 pin = os_strchr(cmd, ' ');
528 if (pin)
529 *pin++ = '\0';
530
531 if (os_strcmp(cmd, "any") == 0)
532 _bssid = NULL;
533 else if (os_strcmp(cmd, "get") == 0) {
534 ret = wps_generate_pin();
535 goto done;
536 } else if (hwaddr_aton(cmd, bssid)) {
537 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
538 cmd);
539 return -1;
540 }
541
542 #ifdef CONFIG_AP
543 if (wpa_s->ap_iface)
544 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
545 buf, buflen);
546 #endif /* CONFIG_AP */
547
548 if (pin) {
549 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
550 DEV_PW_DEFAULT);
551 if (ret < 0)
552 return -1;
553 ret = os_snprintf(buf, buflen, "%s", pin);
554 if (ret < 0 || (size_t) ret >= buflen)
555 return -1;
556 return ret;
557 }
558
559 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
560 if (ret < 0)
561 return -1;
562
563 done:
564 /* Return the generated PIN */
565 ret = os_snprintf(buf, buflen, "%08d", ret);
566 if (ret < 0 || (size_t) ret >= buflen)
567 return -1;
568 return ret;
569 }
570
571
572 static int wpa_supplicant_ctrl_iface_wps_check_pin(
573 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
574 {
575 char pin[9];
576 size_t len;
577 char *pos;
578 int ret;
579
580 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
581 (u8 *) cmd, os_strlen(cmd));
582 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
583 if (*pos < '0' || *pos > '9')
584 continue;
585 pin[len++] = *pos;
586 if (len == 9) {
587 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
588 return -1;
589 }
590 }
591 if (len != 4 && len != 8) {
592 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
593 return -1;
594 }
595 pin[len] = '\0';
596
597 if (len == 8) {
598 unsigned int pin_val;
599 pin_val = atoi(pin);
600 if (!wps_pin_valid(pin_val)) {
601 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
602 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
603 if (ret < 0 || (size_t) ret >= buflen)
604 return -1;
605 return ret;
606 }
607 }
608
609 ret = os_snprintf(buf, buflen, "%s", pin);
610 if (ret < 0 || (size_t) ret >= buflen)
611 return -1;
612
613 return ret;
614 }
615
616
617 #ifdef CONFIG_WPS_OOB
618 static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s,
619 char *cmd)
620 {
621 char *path, *method, *name;
622
623 path = os_strchr(cmd, ' ');
624 if (path == NULL)
625 return -1;
626 *path++ = '\0';
627
628 method = os_strchr(path, ' ');
629 if (method == NULL)
630 return -1;
631 *method++ = '\0';
632
633 name = os_strchr(method, ' ');
634 if (name != NULL)
635 *name++ = '\0';
636
637 return wpas_wps_start_oob(wpa_s, cmd, path, method, name);
638 }
639 #endif /* CONFIG_WPS_OOB */
640
641
642 #ifdef CONFIG_WPS_NFC
643
644 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
645 char *cmd)
646 {
647 u8 bssid[ETH_ALEN], *_bssid = bssid;
648
649 if (cmd == NULL || cmd[0] == '\0')
650 _bssid = NULL;
651 else if (hwaddr_aton(cmd, bssid))
652 return -1;
653
654 return wpas_wps_start_nfc(wpa_s, _bssid);
655 }
656
657
658 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
659 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
660 {
661 int ndef;
662 struct wpabuf *buf;
663 int res;
664
665 if (os_strcmp(cmd, "WPS") == 0)
666 ndef = 0;
667 else if (os_strcmp(cmd, "NDEF") == 0)
668 ndef = 1;
669 else
670 return -1;
671
672 buf = wpas_wps_nfc_token(wpa_s, ndef);
673 if (buf == NULL)
674 return -1;
675
676 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
677 wpabuf_len(buf));
678 reply[res++] = '\n';
679 reply[res] = '\0';
680
681 wpabuf_free(buf);
682
683 return res;
684 }
685
686
687 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
688 struct wpa_supplicant *wpa_s, char *pos)
689 {
690 size_t len;
691 struct wpabuf *buf;
692 int ret;
693
694 len = os_strlen(pos);
695 if (len & 0x01)
696 return -1;
697 len /= 2;
698
699 buf = wpabuf_alloc(len);
700 if (buf == NULL)
701 return -1;
702 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
703 wpabuf_free(buf);
704 return -1;
705 }
706
707 ret = wpas_wps_nfc_tag_read(wpa_s, buf);
708 wpabuf_free(buf);
709
710 return ret;
711 }
712
713 #endif /* CONFIG_WPS_NFC */
714
715
716 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
717 char *cmd)
718 {
719 u8 bssid[ETH_ALEN];
720 char *pin;
721 char *new_ssid;
722 char *new_auth;
723 char *new_encr;
724 char *new_key;
725 struct wps_new_ap_settings ap;
726
727 pin = os_strchr(cmd, ' ');
728 if (pin == NULL)
729 return -1;
730 *pin++ = '\0';
731
732 if (hwaddr_aton(cmd, bssid)) {
733 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
734 cmd);
735 return -1;
736 }
737
738 new_ssid = os_strchr(pin, ' ');
739 if (new_ssid == NULL)
740 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
741 *new_ssid++ = '\0';
742
743 new_auth = os_strchr(new_ssid, ' ');
744 if (new_auth == NULL)
745 return -1;
746 *new_auth++ = '\0';
747
748 new_encr = os_strchr(new_auth, ' ');
749 if (new_encr == NULL)
750 return -1;
751 *new_encr++ = '\0';
752
753 new_key = os_strchr(new_encr, ' ');
754 if (new_key == NULL)
755 return -1;
756 *new_key++ = '\0';
757
758 os_memset(&ap, 0, sizeof(ap));
759 ap.ssid_hex = new_ssid;
760 ap.auth = new_auth;
761 ap.encr = new_encr;
762 ap.key_hex = new_key;
763 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
764 }
765
766
767 #ifdef CONFIG_AP
768 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
769 char *cmd, char *buf,
770 size_t buflen)
771 {
772 int timeout = 300;
773 char *pos;
774 const char *pin_txt;
775
776 if (!wpa_s->ap_iface)
777 return -1;
778
779 pos = os_strchr(cmd, ' ');
780 if (pos)
781 *pos++ = '\0';
782
783 if (os_strcmp(cmd, "disable") == 0) {
784 wpas_wps_ap_pin_disable(wpa_s);
785 return os_snprintf(buf, buflen, "OK\n");
786 }
787
788 if (os_strcmp(cmd, "random") == 0) {
789 if (pos)
790 timeout = atoi(pos);
791 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
792 if (pin_txt == NULL)
793 return -1;
794 return os_snprintf(buf, buflen, "%s", pin_txt);
795 }
796
797 if (os_strcmp(cmd, "get") == 0) {
798 pin_txt = wpas_wps_ap_pin_get(wpa_s);
799 if (pin_txt == NULL)
800 return -1;
801 return os_snprintf(buf, buflen, "%s", pin_txt);
802 }
803
804 if (os_strcmp(cmd, "set") == 0) {
805 char *pin;
806 if (pos == NULL)
807 return -1;
808 pin = pos;
809 pos = os_strchr(pos, ' ');
810 if (pos) {
811 *pos++ = '\0';
812 timeout = atoi(pos);
813 }
814 if (os_strlen(pin) > buflen)
815 return -1;
816 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
817 return -1;
818 return os_snprintf(buf, buflen, "%s", pin);
819 }
820
821 return -1;
822 }
823 #endif /* CONFIG_AP */
824
825
826 #ifdef CONFIG_WPS_ER
827 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
828 char *cmd)
829 {
830 char *uuid = cmd, *pin, *pos;
831 u8 addr_buf[ETH_ALEN], *addr = NULL;
832 pin = os_strchr(uuid, ' ');
833 if (pin == NULL)
834 return -1;
835 *pin++ = '\0';
836 pos = os_strchr(pin, ' ');
837 if (pos) {
838 *pos++ = '\0';
839 if (hwaddr_aton(pos, addr_buf) == 0)
840 addr = addr_buf;
841 }
842 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
843 }
844
845
846 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
847 char *cmd)
848 {
849 char *uuid = cmd, *pin;
850 pin = os_strchr(uuid, ' ');
851 if (pin == NULL)
852 return -1;
853 *pin++ = '\0';
854 return wpas_wps_er_learn(wpa_s, uuid, pin);
855 }
856
857
858 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
859 struct wpa_supplicant *wpa_s, char *cmd)
860 {
861 char *uuid = cmd, *id;
862 id = os_strchr(uuid, ' ');
863 if (id == NULL)
864 return -1;
865 *id++ = '\0';
866 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
867 }
868
869
870 static int wpa_supplicant_ctrl_iface_wps_er_config(
871 struct wpa_supplicant *wpa_s, char *cmd)
872 {
873 char *pin;
874 char *new_ssid;
875 char *new_auth;
876 char *new_encr;
877 char *new_key;
878 struct wps_new_ap_settings ap;
879
880 pin = os_strchr(cmd, ' ');
881 if (pin == NULL)
882 return -1;
883 *pin++ = '\0';
884
885 new_ssid = os_strchr(pin, ' ');
886 if (new_ssid == NULL)
887 return -1;
888 *new_ssid++ = '\0';
889
890 new_auth = os_strchr(new_ssid, ' ');
891 if (new_auth == NULL)
892 return -1;
893 *new_auth++ = '\0';
894
895 new_encr = os_strchr(new_auth, ' ');
896 if (new_encr == NULL)
897 return -1;
898 *new_encr++ = '\0';
899
900 new_key = os_strchr(new_encr, ' ');
901 if (new_key == NULL)
902 return -1;
903 *new_key++ = '\0';
904
905 os_memset(&ap, 0, sizeof(ap));
906 ap.ssid_hex = new_ssid;
907 ap.auth = new_auth;
908 ap.encr = new_encr;
909 ap.key_hex = new_key;
910 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
911 }
912
913
914 #ifdef CONFIG_WPS_NFC
915 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
916 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
917 {
918 int ndef;
919 struct wpabuf *buf;
920 int res;
921 char *uuid;
922
923 uuid = os_strchr(cmd, ' ');
924 if (uuid == NULL)
925 return -1;
926 *uuid++ = '\0';
927
928 if (os_strcmp(cmd, "WPS") == 0)
929 ndef = 0;
930 else if (os_strcmp(cmd, "NDEF") == 0)
931 ndef = 1;
932 else
933 return -1;
934
935 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
936 if (buf == NULL)
937 return -1;
938
939 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
940 wpabuf_len(buf));
941 reply[res++] = '\n';
942 reply[res] = '\0';
943
944 wpabuf_free(buf);
945
946 return res;
947 }
948 #endif /* CONFIG_WPS_NFC */
949 #endif /* CONFIG_WPS_ER */
950
951 #endif /* CONFIG_WPS */
952
953
954 #ifdef CONFIG_IBSS_RSN
955 static int wpa_supplicant_ctrl_iface_ibss_rsn(
956 struct wpa_supplicant *wpa_s, char *addr)
957 {
958 u8 peer[ETH_ALEN];
959
960 if (hwaddr_aton(addr, peer)) {
961 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
962 "address '%s'", addr);
963 return -1;
964 }
965
966 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
967 MAC2STR(peer));
968
969 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
970 }
971 #endif /* CONFIG_IBSS_RSN */
972
973
974 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
975 char *rsp)
976 {
977 #ifdef IEEE8021X_EAPOL
978 char *pos, *id_pos;
979 int id;
980 struct wpa_ssid *ssid;
981
982 pos = os_strchr(rsp, '-');
983 if (pos == NULL)
984 return -1;
985 *pos++ = '\0';
986 id_pos = pos;
987 pos = os_strchr(pos, ':');
988 if (pos == NULL)
989 return -1;
990 *pos++ = '\0';
991 id = atoi(id_pos);
992 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
993 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
994 (u8 *) pos, os_strlen(pos));
995
996 ssid = wpa_config_get_network(wpa_s->conf, id);
997 if (ssid == NULL) {
998 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
999 "to update", id);
1000 return -1;
1001 }
1002
1003 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1004 pos);
1005 #else /* IEEE8021X_EAPOL */
1006 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1007 return -1;
1008 #endif /* IEEE8021X_EAPOL */
1009 }
1010
1011
1012 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1013 const char *params,
1014 char *buf, size_t buflen)
1015 {
1016 char *pos, *end, tmp[30];
1017 int res, verbose, wps, ret;
1018
1019 verbose = os_strcmp(params, "-VERBOSE") == 0;
1020 wps = os_strcmp(params, "-WPS") == 0;
1021 pos = buf;
1022 end = buf + buflen;
1023 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1024 struct wpa_ssid *ssid = wpa_s->current_ssid;
1025 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1026 MAC2STR(wpa_s->bssid));
1027 if (ret < 0 || ret >= end - pos)
1028 return pos - buf;
1029 pos += ret;
1030 if (ssid) {
1031 u8 *_ssid = ssid->ssid;
1032 size_t ssid_len = ssid->ssid_len;
1033 u8 ssid_buf[MAX_SSID_LEN];
1034 if (ssid_len == 0) {
1035 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1036 if (_res < 0)
1037 ssid_len = 0;
1038 else
1039 ssid_len = _res;
1040 _ssid = ssid_buf;
1041 }
1042 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1043 wpa_ssid_txt(_ssid, ssid_len),
1044 ssid->id);
1045 if (ret < 0 || ret >= end - pos)
1046 return pos - buf;
1047 pos += ret;
1048
1049 if (wps && ssid->passphrase &&
1050 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1051 (ssid->mode == WPAS_MODE_AP ||
1052 ssid->mode == WPAS_MODE_P2P_GO)) {
1053 ret = os_snprintf(pos, end - pos,
1054 "passphrase=%s\n",
1055 ssid->passphrase);
1056 if (ret < 0 || ret >= end - pos)
1057 return pos - buf;
1058 pos += ret;
1059 }
1060 if (ssid->id_str) {
1061 ret = os_snprintf(pos, end - pos,
1062 "id_str=%s\n",
1063 ssid->id_str);
1064 if (ret < 0 || ret >= end - pos)
1065 return pos - buf;
1066 pos += ret;
1067 }
1068
1069 switch (ssid->mode) {
1070 case WPAS_MODE_INFRA:
1071 ret = os_snprintf(pos, end - pos,
1072 "mode=station\n");
1073 break;
1074 case WPAS_MODE_IBSS:
1075 ret = os_snprintf(pos, end - pos,
1076 "mode=IBSS\n");
1077 break;
1078 case WPAS_MODE_AP:
1079 ret = os_snprintf(pos, end - pos,
1080 "mode=AP\n");
1081 break;
1082 case WPAS_MODE_P2P_GO:
1083 ret = os_snprintf(pos, end - pos,
1084 "mode=P2P GO\n");
1085 break;
1086 case WPAS_MODE_P2P_GROUP_FORMATION:
1087 ret = os_snprintf(pos, end - pos,
1088 "mode=P2P GO - group "
1089 "formation\n");
1090 break;
1091 default:
1092 ret = 0;
1093 break;
1094 }
1095 if (ret < 0 || ret >= end - pos)
1096 return pos - buf;
1097 pos += ret;
1098 }
1099
1100 #ifdef CONFIG_AP
1101 if (wpa_s->ap_iface) {
1102 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1103 end - pos,
1104 verbose);
1105 } else
1106 #endif /* CONFIG_AP */
1107 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1108 }
1109 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1110 wpa_supplicant_state_txt(wpa_s->wpa_state));
1111 if (ret < 0 || ret >= end - pos)
1112 return pos - buf;
1113 pos += ret;
1114
1115 if (wpa_s->l2 &&
1116 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1117 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1118 if (ret < 0 || ret >= end - pos)
1119 return pos - buf;
1120 pos += ret;
1121 }
1122
1123 #ifdef CONFIG_P2P
1124 if (wpa_s->global->p2p) {
1125 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1126 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1127 if (ret < 0 || ret >= end - pos)
1128 return pos - buf;
1129 pos += ret;
1130 }
1131 #endif /* CONFIG_P2P */
1132
1133 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1134 MAC2STR(wpa_s->own_addr));
1135 if (ret < 0 || ret >= end - pos)
1136 return pos - buf;
1137 pos += ret;
1138
1139 #ifdef CONFIG_HS20
1140 if (wpa_s->current_bss &&
1141 wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE) &&
1142 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1143 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1144 ret = os_snprintf(pos, end - pos, "hs20=1\n");
1145 if (ret < 0 || ret >= end - pos)
1146 return pos - buf;
1147 pos += ret;
1148 }
1149 #endif /* CONFIG_HS20 */
1150
1151 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1152 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1153 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1154 verbose);
1155 if (res >= 0)
1156 pos += res;
1157 }
1158
1159 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1160 if (res >= 0)
1161 pos += res;
1162
1163 return pos - buf;
1164 }
1165
1166
1167 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1168 char *cmd)
1169 {
1170 char *pos;
1171 int id;
1172 struct wpa_ssid *ssid;
1173 u8 bssid[ETH_ALEN];
1174
1175 /* cmd: "<network id> <BSSID>" */
1176 pos = os_strchr(cmd, ' ');
1177 if (pos == NULL)
1178 return -1;
1179 *pos++ = '\0';
1180 id = atoi(cmd);
1181 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1182 if (hwaddr_aton(pos, bssid)) {
1183 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1184 return -1;
1185 }
1186
1187 ssid = wpa_config_get_network(wpa_s->conf, id);
1188 if (ssid == NULL) {
1189 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1190 "to update", id);
1191 return -1;
1192 }
1193
1194 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1195 ssid->bssid_set = !is_zero_ether_addr(bssid);
1196
1197 return 0;
1198 }
1199
1200
1201 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1202 char *cmd, char *buf,
1203 size_t buflen)
1204 {
1205 u8 bssid[ETH_ALEN];
1206 struct wpa_blacklist *e;
1207 char *pos, *end;
1208 int ret;
1209
1210 /* cmd: "BLACKLIST [<BSSID>]" */
1211 if (*cmd == '\0') {
1212 pos = buf;
1213 end = buf + buflen;
1214 e = wpa_s->blacklist;
1215 while (e) {
1216 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1217 MAC2STR(e->bssid));
1218 if (ret < 0 || ret >= end - pos)
1219 return pos - buf;
1220 pos += ret;
1221 e = e->next;
1222 }
1223 return pos - buf;
1224 }
1225
1226 cmd++;
1227 if (os_strncmp(cmd, "clear", 5) == 0) {
1228 wpa_blacklist_clear(wpa_s);
1229 os_memcpy(buf, "OK\n", 3);
1230 return 3;
1231 }
1232
1233 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1234 if (hwaddr_aton(cmd, bssid)) {
1235 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1236 return -1;
1237 }
1238
1239 /*
1240 * Add the BSSID twice, so its count will be 2, causing it to be
1241 * skipped when processing scan results.
1242 */
1243 ret = wpa_blacklist_add(wpa_s, bssid);
1244 if (ret != 0)
1245 return -1;
1246 ret = wpa_blacklist_add(wpa_s, bssid);
1247 if (ret != 0)
1248 return -1;
1249 os_memcpy(buf, "OK\n", 3);
1250 return 3;
1251 }
1252
1253
1254 extern int wpa_debug_level;
1255 extern int wpa_debug_timestamp;
1256
1257 static const char * debug_level_str(int level)
1258 {
1259 switch (level) {
1260 case MSG_EXCESSIVE:
1261 return "EXCESSIVE";
1262 case MSG_MSGDUMP:
1263 return "MSGDUMP";
1264 case MSG_DEBUG:
1265 return "DEBUG";
1266 case MSG_INFO:
1267 return "INFO";
1268 case MSG_WARNING:
1269 return "WARNING";
1270 case MSG_ERROR:
1271 return "ERROR";
1272 default:
1273 return "?";
1274 }
1275 }
1276
1277
1278 static int str_to_debug_level(const char *s)
1279 {
1280 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1281 return MSG_EXCESSIVE;
1282 if (os_strcasecmp(s, "MSGDUMP") == 0)
1283 return MSG_MSGDUMP;
1284 if (os_strcasecmp(s, "DEBUG") == 0)
1285 return MSG_DEBUG;
1286 if (os_strcasecmp(s, "INFO") == 0)
1287 return MSG_INFO;
1288 if (os_strcasecmp(s, "WARNING") == 0)
1289 return MSG_WARNING;
1290 if (os_strcasecmp(s, "ERROR") == 0)
1291 return MSG_ERROR;
1292 return -1;
1293 }
1294
1295
1296 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1297 char *cmd, char *buf,
1298 size_t buflen)
1299 {
1300 char *pos, *end, *stamp;
1301 int ret;
1302
1303 if (cmd == NULL) {
1304 return -1;
1305 }
1306
1307 /* cmd: "LOG_LEVEL [<level>]" */
1308 if (*cmd == '\0') {
1309 pos = buf;
1310 end = buf + buflen;
1311 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1312 "Timestamp: %d\n",
1313 debug_level_str(wpa_debug_level),
1314 wpa_debug_timestamp);
1315 if (ret < 0 || ret >= end - pos)
1316 ret = 0;
1317
1318 return ret;
1319 }
1320
1321 while (*cmd == ' ')
1322 cmd++;
1323
1324 stamp = os_strchr(cmd, ' ');
1325 if (stamp) {
1326 *stamp++ = '\0';
1327 while (*stamp == ' ') {
1328 stamp++;
1329 }
1330 }
1331
1332 if (cmd && os_strlen(cmd)) {
1333 int level = str_to_debug_level(cmd);
1334 if (level < 0)
1335 return -1;
1336 wpa_debug_level = level;
1337 }
1338
1339 if (stamp && os_strlen(stamp))
1340 wpa_debug_timestamp = atoi(stamp);
1341
1342 os_memcpy(buf, "OK\n", 3);
1343 return 3;
1344 }
1345
1346
1347 static int wpa_supplicant_ctrl_iface_list_networks(
1348 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1349 {
1350 char *pos, *end;
1351 struct wpa_ssid *ssid;
1352 int ret;
1353
1354 pos = buf;
1355 end = buf + buflen;
1356 ret = os_snprintf(pos, end - pos,
1357 "network id / ssid / bssid / flags\n");
1358 if (ret < 0 || ret >= end - pos)
1359 return pos - buf;
1360 pos += ret;
1361
1362 ssid = wpa_s->conf->ssid;
1363 while (ssid) {
1364 ret = os_snprintf(pos, end - pos, "%d\t%s",
1365 ssid->id,
1366 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1367 if (ret < 0 || ret >= end - pos)
1368 return pos - buf;
1369 pos += ret;
1370 if (ssid->bssid_set) {
1371 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
1372 MAC2STR(ssid->bssid));
1373 } else {
1374 ret = os_snprintf(pos, end - pos, "\tany");
1375 }
1376 if (ret < 0 || ret >= end - pos)
1377 return pos - buf;
1378 pos += ret;
1379 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
1380 ssid == wpa_s->current_ssid ?
1381 "[CURRENT]" : "",
1382 ssid->disabled ? "[DISABLED]" : "",
1383 ssid->disabled_until.sec ?
1384 "[TEMP-DISABLED]" : "",
1385 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
1386 "");
1387 if (ret < 0 || ret >= end - pos)
1388 return pos - buf;
1389 pos += ret;
1390 ret = os_snprintf(pos, end - pos, "\n");
1391 if (ret < 0 || ret >= end - pos)
1392 return pos - buf;
1393 pos += ret;
1394
1395 ssid = ssid->next;
1396 }
1397
1398 return pos - buf;
1399 }
1400
1401
1402 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
1403 {
1404 int first = 1, ret;
1405 ret = os_snprintf(pos, end - pos, "-");
1406 if (ret < 0 || ret >= end - pos)
1407 return pos;
1408 pos += ret;
1409 if (cipher & WPA_CIPHER_NONE) {
1410 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
1411 if (ret < 0 || ret >= end - pos)
1412 return pos;
1413 pos += ret;
1414 first = 0;
1415 }
1416 if (cipher & WPA_CIPHER_WEP40) {
1417 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
1418 if (ret < 0 || ret >= end - pos)
1419 return pos;
1420 pos += ret;
1421 first = 0;
1422 }
1423 if (cipher & WPA_CIPHER_WEP104) {
1424 ret = os_snprintf(pos, end - pos, "%sWEP104",
1425 first ? "" : "+");
1426 if (ret < 0 || ret >= end - pos)
1427 return pos;
1428 pos += ret;
1429 first = 0;
1430 }
1431 if (cipher & WPA_CIPHER_TKIP) {
1432 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
1433 if (ret < 0 || ret >= end - pos)
1434 return pos;
1435 pos += ret;
1436 first = 0;
1437 }
1438 if (cipher & WPA_CIPHER_CCMP) {
1439 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
1440 if (ret < 0 || ret >= end - pos)
1441 return pos;
1442 pos += ret;
1443 first = 0;
1444 }
1445 if (cipher & WPA_CIPHER_GCMP) {
1446 ret = os_snprintf(pos, end - pos, "%sGCMP", first ? "" : "+");
1447 if (ret < 0 || ret >= end - pos)
1448 return pos;
1449 pos += ret;
1450 first = 0;
1451 }
1452 return pos;
1453 }
1454
1455
1456 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
1457 const u8 *ie, size_t ie_len)
1458 {
1459 struct wpa_ie_data data;
1460 int first, ret;
1461
1462 ret = os_snprintf(pos, end - pos, "[%s-", proto);
1463 if (ret < 0 || ret >= end - pos)
1464 return pos;
1465 pos += ret;
1466
1467 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
1468 ret = os_snprintf(pos, end - pos, "?]");
1469 if (ret < 0 || ret >= end - pos)
1470 return pos;
1471 pos += ret;
1472 return pos;
1473 }
1474
1475 first = 1;
1476 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
1477 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
1478 if (ret < 0 || ret >= end - pos)
1479 return pos;
1480 pos += ret;
1481 first = 0;
1482 }
1483 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
1484 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
1485 if (ret < 0 || ret >= end - pos)
1486 return pos;
1487 pos += ret;
1488 first = 0;
1489 }
1490 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
1491 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
1492 if (ret < 0 || ret >= end - pos)
1493 return pos;
1494 pos += ret;
1495 first = 0;
1496 }
1497 #ifdef CONFIG_IEEE80211R
1498 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
1499 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
1500 first ? "" : "+");
1501 if (ret < 0 || ret >= end - pos)
1502 return pos;
1503 pos += ret;
1504 first = 0;
1505 }
1506 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
1507 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
1508 first ? "" : "+");
1509 if (ret < 0 || ret >= end - pos)
1510 return pos;
1511 pos += ret;
1512 first = 0;
1513 }
1514 #endif /* CONFIG_IEEE80211R */
1515 #ifdef CONFIG_IEEE80211W
1516 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1517 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
1518 first ? "" : "+");
1519 if (ret < 0 || ret >= end - pos)
1520 return pos;
1521 pos += ret;
1522 first = 0;
1523 }
1524 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
1525 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
1526 first ? "" : "+");
1527 if (ret < 0 || ret >= end - pos)
1528 return pos;
1529 pos += ret;
1530 first = 0;
1531 }
1532 #endif /* CONFIG_IEEE80211W */
1533
1534 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
1535
1536 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
1537 ret = os_snprintf(pos, end - pos, "-preauth");
1538 if (ret < 0 || ret >= end - pos)
1539 return pos;
1540 pos += ret;
1541 }
1542
1543 ret = os_snprintf(pos, end - pos, "]");
1544 if (ret < 0 || ret >= end - pos)
1545 return pos;
1546 pos += ret;
1547
1548 return pos;
1549 }
1550
1551
1552 #ifdef CONFIG_WPS
1553 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
1554 char *pos, char *end,
1555 struct wpabuf *wps_ie)
1556 {
1557 int ret;
1558 const char *txt;
1559
1560 if (wps_ie == NULL)
1561 return pos;
1562 if (wps_is_selected_pbc_registrar(wps_ie))
1563 txt = "[WPS-PBC]";
1564 #ifdef CONFIG_WPS2
1565 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
1566 txt = "[WPS-AUTH]";
1567 #endif /* CONFIG_WPS2 */
1568 else if (wps_is_selected_pin_registrar(wps_ie))
1569 txt = "[WPS-PIN]";
1570 else
1571 txt = "[WPS]";
1572
1573 ret = os_snprintf(pos, end - pos, "%s", txt);
1574 if (ret >= 0 && ret < end - pos)
1575 pos += ret;
1576 wpabuf_free(wps_ie);
1577 return pos;
1578 }
1579 #endif /* CONFIG_WPS */
1580
1581
1582 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
1583 char *pos, char *end,
1584 const struct wpa_bss *bss)
1585 {
1586 #ifdef CONFIG_WPS
1587 struct wpabuf *wps_ie;
1588 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1589 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
1590 #else /* CONFIG_WPS */
1591 return pos;
1592 #endif /* CONFIG_WPS */
1593 }
1594
1595
1596 /* Format one result on one text line into a buffer. */
1597 static int wpa_supplicant_ctrl_iface_scan_result(
1598 struct wpa_supplicant *wpa_s,
1599 const struct wpa_bss *bss, char *buf, size_t buflen)
1600 {
1601 char *pos, *end;
1602 int ret;
1603 const u8 *ie, *ie2, *p2p;
1604
1605 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1606 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
1607 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
1608 0)
1609 return 0; /* Do not show P2P listen discovery results here */
1610
1611 pos = buf;
1612 end = buf + buflen;
1613
1614 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
1615 MAC2STR(bss->bssid), bss->freq, bss->level);
1616 if (ret < 0 || ret >= end - pos)
1617 return -1;
1618 pos += ret;
1619 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1620 if (ie)
1621 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
1622 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1623 if (ie2)
1624 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
1625 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
1626 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
1627 ret = os_snprintf(pos, end - pos, "[WEP]");
1628 if (ret < 0 || ret >= end - pos)
1629 return -1;
1630 pos += ret;
1631 }
1632 if (bss->caps & IEEE80211_CAP_IBSS) {
1633 ret = os_snprintf(pos, end - pos, "[IBSS]");
1634 if (ret < 0 || ret >= end - pos)
1635 return -1;
1636 pos += ret;
1637 }
1638 if (bss->caps & IEEE80211_CAP_ESS) {
1639 ret = os_snprintf(pos, end - pos, "[ESS]");
1640 if (ret < 0 || ret >= end - pos)
1641 return -1;
1642 pos += ret;
1643 }
1644 if (p2p) {
1645 ret = os_snprintf(pos, end - pos, "[P2P]");
1646 if (ret < 0 || ret >= end - pos)
1647 return -1;
1648 pos += ret;
1649 }
1650 #ifdef CONFIG_HS20
1651 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
1652 ret = os_snprintf(pos, end - pos, "[HS20]");
1653 if (ret < 0 || ret >= end - pos)
1654 return -1;
1655 pos += ret;
1656 }
1657 #endif /* CONFIG_HS20 */
1658
1659 ret = os_snprintf(pos, end - pos, "\t%s",
1660 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1661 if (ret < 0 || ret >= end - pos)
1662 return -1;
1663 pos += ret;
1664
1665 ret = os_snprintf(pos, end - pos, "\n");
1666 if (ret < 0 || ret >= end - pos)
1667 return -1;
1668 pos += ret;
1669
1670 return pos - buf;
1671 }
1672
1673
1674 static int wpa_supplicant_ctrl_iface_scan_results(
1675 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1676 {
1677 char *pos, *end;
1678 struct wpa_bss *bss;
1679 int ret;
1680
1681 pos = buf;
1682 end = buf + buflen;
1683 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
1684 "flags / ssid\n");
1685 if (ret < 0 || ret >= end - pos)
1686 return pos - buf;
1687 pos += ret;
1688
1689 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
1690 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
1691 end - pos);
1692 if (ret < 0 || ret >= end - pos)
1693 return pos - buf;
1694 pos += ret;
1695 }
1696
1697 return pos - buf;
1698 }
1699
1700
1701 static int wpa_supplicant_ctrl_iface_select_network(
1702 struct wpa_supplicant *wpa_s, char *cmd)
1703 {
1704 int id;
1705 struct wpa_ssid *ssid;
1706
1707 /* cmd: "<network id>" or "any" */
1708 if (os_strcmp(cmd, "any") == 0) {
1709 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
1710 ssid = NULL;
1711 } else {
1712 id = atoi(cmd);
1713 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
1714
1715 ssid = wpa_config_get_network(wpa_s->conf, id);
1716 if (ssid == NULL) {
1717 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
1718 "network id=%d", id);
1719 return -1;
1720 }
1721 if (ssid->disabled == 2) {
1722 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
1723 "SELECT_NETWORK with persistent P2P group");
1724 return -1;
1725 }
1726 }
1727
1728 wpa_supplicant_select_network(wpa_s, ssid);
1729
1730 return 0;
1731 }
1732
1733
1734 static int wpa_supplicant_ctrl_iface_enable_network(
1735 struct wpa_supplicant *wpa_s, char *cmd)
1736 {
1737 int id;
1738 struct wpa_ssid *ssid;
1739
1740 /* cmd: "<network id>" or "all" */
1741 if (os_strcmp(cmd, "all") == 0) {
1742 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
1743 ssid = NULL;
1744 } else {
1745 id = atoi(cmd);
1746 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
1747
1748 ssid = wpa_config_get_network(wpa_s->conf, id);
1749 if (ssid == NULL) {
1750 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
1751 "network id=%d", id);
1752 return -1;
1753 }
1754 if (ssid->disabled == 2) {
1755 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
1756 "ENABLE_NETWORK with persistent P2P group");
1757 return -1;
1758 }
1759
1760 if (os_strstr(cmd, " no-connect")) {
1761 ssid->disabled = 0;
1762 return 0;
1763 }
1764 }
1765 wpa_supplicant_enable_network(wpa_s, ssid);
1766
1767 return 0;
1768 }
1769
1770
1771 static int wpa_supplicant_ctrl_iface_disable_network(
1772 struct wpa_supplicant *wpa_s, char *cmd)
1773 {
1774 int id;
1775 struct wpa_ssid *ssid;
1776
1777 /* cmd: "<network id>" or "all" */
1778 if (os_strcmp(cmd, "all") == 0) {
1779 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
1780 ssid = NULL;
1781 } else {
1782 id = atoi(cmd);
1783 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
1784
1785 ssid = wpa_config_get_network(wpa_s->conf, id);
1786 if (ssid == NULL) {
1787 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
1788 "network id=%d", id);
1789 return -1;
1790 }
1791 if (ssid->disabled == 2) {
1792 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
1793 "DISABLE_NETWORK with persistent P2P "
1794 "group");
1795 return -1;
1796 }
1797 }
1798 wpa_supplicant_disable_network(wpa_s, ssid);
1799
1800 return 0;
1801 }
1802
1803
1804 static int wpa_supplicant_ctrl_iface_add_network(
1805 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1806 {
1807 struct wpa_ssid *ssid;
1808 int ret;
1809
1810 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
1811
1812 ssid = wpa_config_add_network(wpa_s->conf);
1813 if (ssid == NULL)
1814 return -1;
1815
1816 wpas_notify_network_added(wpa_s, ssid);
1817
1818 ssid->disabled = 1;
1819 wpa_config_set_network_defaults(ssid);
1820
1821 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
1822 if (ret < 0 || (size_t) ret >= buflen)
1823 return -1;
1824 return ret;
1825 }
1826
1827
1828 static int wpa_supplicant_ctrl_iface_remove_network(
1829 struct wpa_supplicant *wpa_s, char *cmd)
1830 {
1831 int id;
1832 struct wpa_ssid *ssid;
1833
1834 /* cmd: "<network id>" or "all" */
1835 if (os_strcmp(cmd, "all") == 0) {
1836 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
1837 ssid = wpa_s->conf->ssid;
1838 while (ssid) {
1839 struct wpa_ssid *remove_ssid = ssid;
1840 id = ssid->id;
1841 ssid = ssid->next;
1842 wpas_notify_network_removed(wpa_s, remove_ssid);
1843 wpa_config_remove_network(wpa_s->conf, id);
1844 }
1845 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1846 if (wpa_s->current_ssid) {
1847 #ifdef CONFIG_SME
1848 wpa_s->sme.prev_bssid_set = 0;
1849 #endif /* CONFIG_SME */
1850 wpa_sm_set_config(wpa_s->wpa, NULL);
1851 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
1852 wpa_supplicant_disassociate(wpa_s,
1853 WLAN_REASON_DEAUTH_LEAVING);
1854 }
1855 return 0;
1856 }
1857
1858 id = atoi(cmd);
1859 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
1860
1861 ssid = wpa_config_get_network(wpa_s->conf, id);
1862 if (ssid)
1863 wpas_notify_network_removed(wpa_s, ssid);
1864 if (ssid == NULL ||
1865 wpa_config_remove_network(wpa_s->conf, id) < 0) {
1866 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1867 "id=%d", id);
1868 return -1;
1869 }
1870
1871 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
1872 #ifdef CONFIG_SME
1873 wpa_s->sme.prev_bssid_set = 0;
1874 #endif /* CONFIG_SME */
1875 /*
1876 * Invalidate the EAP session cache if the current or
1877 * previously used network is removed.
1878 */
1879 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1880 }
1881
1882 if (ssid == wpa_s->current_ssid) {
1883 wpa_sm_set_config(wpa_s->wpa, NULL);
1884 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
1885
1886 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1887 }
1888
1889 return 0;
1890 }
1891
1892
1893 static int wpa_supplicant_ctrl_iface_set_network(
1894 struct wpa_supplicant *wpa_s, char *cmd)
1895 {
1896 int id;
1897 struct wpa_ssid *ssid;
1898 char *name, *value;
1899
1900 /* cmd: "<network id> <variable name> <value>" */
1901 name = os_strchr(cmd, ' ');
1902 if (name == NULL)
1903 return -1;
1904 *name++ = '\0';
1905
1906 value = os_strchr(name, ' ');
1907 if (value == NULL)
1908 return -1;
1909 *value++ = '\0';
1910
1911 id = atoi(cmd);
1912 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
1913 id, name);
1914 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1915 (u8 *) value, os_strlen(value));
1916
1917 ssid = wpa_config_get_network(wpa_s->conf, id);
1918 if (ssid == NULL) {
1919 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1920 "id=%d", id);
1921 return -1;
1922 }
1923
1924 if (wpa_config_set(ssid, name, value, 0) < 0) {
1925 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
1926 "variable '%s'", name);
1927 return -1;
1928 }
1929
1930 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
1931
1932 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
1933 /*
1934 * Invalidate the EAP session cache if anything in the current
1935 * or previously used configuration changes.
1936 */
1937 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1938 }
1939
1940 if ((os_strcmp(name, "psk") == 0 &&
1941 value[0] == '"' && ssid->ssid_len) ||
1942 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
1943 wpa_config_update_psk(ssid);
1944 else if (os_strcmp(name, "priority") == 0)
1945 wpa_config_update_prio_list(wpa_s->conf);
1946
1947 return 0;
1948 }
1949
1950
1951 static int wpa_supplicant_ctrl_iface_get_network(
1952 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1953 {
1954 int id;
1955 size_t res;
1956 struct wpa_ssid *ssid;
1957 char *name, *value;
1958
1959 /* cmd: "<network id> <variable name>" */
1960 name = os_strchr(cmd, ' ');
1961 if (name == NULL || buflen == 0)
1962 return -1;
1963 *name++ = '\0';
1964
1965 id = atoi(cmd);
1966 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
1967 id, name);
1968
1969 ssid = wpa_config_get_network(wpa_s->conf, id);
1970 if (ssid == NULL) {
1971 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1972 "id=%d", id);
1973 return -1;
1974 }
1975
1976 value = wpa_config_get_no_key(ssid, name);
1977 if (value == NULL) {
1978 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
1979 "variable '%s'", name);
1980 return -1;
1981 }
1982
1983 res = os_strlcpy(buf, value, buflen);
1984 if (res >= buflen) {
1985 os_free(value);
1986 return -1;
1987 }
1988
1989 os_free(value);
1990
1991 return res;
1992 }
1993
1994
1995 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
1996 char *buf, size_t buflen)
1997 {
1998 char *pos, *end;
1999 struct wpa_cred *cred;
2000 int ret;
2001
2002 pos = buf;
2003 end = buf + buflen;
2004 ret = os_snprintf(pos, end - pos,
2005 "cred id / realm / username / domain / imsi\n");
2006 if (ret < 0 || ret >= end - pos)
2007 return pos - buf;
2008 pos += ret;
2009
2010 cred = wpa_s->conf->cred;
2011 while (cred) {
2012 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2013 cred->id, cred->realm ? cred->realm : "",
2014 cred->username ? cred->username : "",
2015 cred->domain ? cred->domain : "",
2016 cred->imsi ? cred->imsi : "");
2017 if (ret < 0 || ret >= end - pos)
2018 return pos - buf;
2019 pos += ret;
2020
2021 cred = cred->next;
2022 }
2023
2024 return pos - buf;
2025 }
2026
2027
2028 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2029 char *buf, size_t buflen)
2030 {
2031 struct wpa_cred *cred;
2032 int ret;
2033
2034 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2035
2036 cred = wpa_config_add_cred(wpa_s->conf);
2037 if (cred == NULL)
2038 return -1;
2039
2040 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2041 if (ret < 0 || (size_t) ret >= buflen)
2042 return -1;
2043 return ret;
2044 }
2045
2046
2047 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2048 char *cmd)
2049 {
2050 int id;
2051 struct wpa_cred *cred;
2052
2053 /* cmd: "<cred id>" or "all" */
2054 if (os_strcmp(cmd, "all") == 0) {
2055 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2056 cred = wpa_s->conf->cred;
2057 while (cred) {
2058 id = cred->id;
2059 cred = cred->next;
2060 wpa_config_remove_cred(wpa_s->conf, id);
2061 }
2062 return 0;
2063 }
2064
2065 id = atoi(cmd);
2066 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2067
2068 cred = wpa_config_get_cred(wpa_s->conf, id);
2069 if (cred == NULL ||
2070 wpa_config_remove_cred(wpa_s->conf, id) < 0) {
2071 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2072 id);
2073 return -1;
2074 }
2075
2076 return 0;
2077 }
2078
2079
2080 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2081 char *cmd)
2082 {
2083 int id;
2084 struct wpa_cred *cred;
2085 char *name, *value;
2086
2087 /* cmd: "<cred id> <variable name> <value>" */
2088 name = os_strchr(cmd, ' ');
2089 if (name == NULL)
2090 return -1;
2091 *name++ = '\0';
2092
2093 value = os_strchr(name, ' ');
2094 if (value == NULL)
2095 return -1;
2096 *value++ = '\0';
2097
2098 id = atoi(cmd);
2099 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2100 id, name);
2101 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2102 (u8 *) value, os_strlen(value));
2103
2104 cred = wpa_config_get_cred(wpa_s->conf, id);
2105 if (cred == NULL) {
2106 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2107 id);
2108 return -1;
2109 }
2110
2111 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2112 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2113 "variable '%s'", name);
2114 return -1;
2115 }
2116
2117 return 0;
2118 }
2119
2120
2121 #ifndef CONFIG_NO_CONFIG_WRITE
2122 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2123 {
2124 int ret;
2125
2126 if (!wpa_s->conf->update_config) {
2127 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2128 "to update configuration (update_config=0)");
2129 return -1;
2130 }
2131
2132 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2133 if (ret) {
2134 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2135 "update configuration");
2136 } else {
2137 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2138 " updated");
2139 }
2140
2141 return ret;
2142 }
2143 #endif /* CONFIG_NO_CONFIG_WRITE */
2144
2145
2146 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2147 struct wpa_driver_capa *capa,
2148 char *buf, size_t buflen)
2149 {
2150 int ret, first = 1;
2151 char *pos, *end;
2152 size_t len;
2153
2154 pos = buf;
2155 end = pos + buflen;
2156
2157 if (res < 0) {
2158 if (strict)
2159 return 0;
2160 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2161 if (len >= buflen)
2162 return -1;
2163 return len;
2164 }
2165
2166 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
2167 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
2168 if (ret < 0 || ret >= end - pos)
2169 return pos - buf;
2170 pos += ret;
2171 first = 0;
2172 }
2173
2174 if (capa->enc & WPA_DRIVER_CAPA_ENC_GCMP) {
2175 ret = os_snprintf(pos, end - pos, "%sGCMP", first ? "" : " ");
2176 if (ret < 0 || ret >= end - pos)
2177 return pos - buf;
2178 pos += ret;
2179 first = 0;
2180 }
2181
2182 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
2183 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
2184 if (ret < 0 || ret >= end - pos)
2185 return pos - buf;
2186 pos += ret;
2187 first = 0;
2188 }
2189
2190 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2191 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " ");
2192 if (ret < 0 || ret >= end - pos)
2193 return pos - buf;
2194 pos += ret;
2195 first = 0;
2196 }
2197
2198 return pos - buf;
2199 }
2200
2201
2202 static int ctrl_iface_get_capability_group(int res, char *strict,
2203 struct wpa_driver_capa *capa,
2204 char *buf, size_t buflen)
2205 {
2206 int ret, first = 1;
2207 char *pos, *end;
2208 size_t len;
2209
2210 pos = buf;
2211 end = pos + buflen;
2212
2213 if (res < 0) {
2214 if (strict)
2215 return 0;
2216 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2217 if (len >= buflen)
2218 return -1;
2219 return len;
2220 }
2221
2222 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
2223 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
2224 if (ret < 0 || ret >= end - pos)
2225 return pos - buf;
2226 pos += ret;
2227 first = 0;
2228 }
2229
2230 if (capa->enc & WPA_DRIVER_CAPA_ENC_GCMP) {
2231 ret = os_snprintf(pos, end - pos, "%sGCMP", first ? "" : " ");
2232 if (ret < 0 || ret >= end - pos)
2233 return pos - buf;
2234 pos += ret;
2235 first = 0;
2236 }
2237
2238 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
2239 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
2240 if (ret < 0 || ret >= end - pos)
2241 return pos - buf;
2242 pos += ret;
2243 first = 0;
2244 }
2245
2246 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) {
2247 ret = os_snprintf(pos, end - pos, "%sWEP104",
2248 first ? "" : " ");
2249 if (ret < 0 || ret >= end - pos)
2250 return pos - buf;
2251 pos += ret;
2252 first = 0;
2253 }
2254
2255 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) {
2256 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " ");
2257 if (ret < 0 || ret >= end - pos)
2258 return pos - buf;
2259 pos += ret;
2260 first = 0;
2261 }
2262
2263 return pos - buf;
2264 }
2265
2266
2267 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2268 struct wpa_driver_capa *capa,
2269 char *buf, size_t buflen)
2270 {
2271 int ret;
2272 char *pos, *end;
2273 size_t len;
2274
2275 pos = buf;
2276 end = pos + buflen;
2277
2278 if (res < 0) {
2279 if (strict)
2280 return 0;
2281 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2282 "NONE", buflen);
2283 if (len >= buflen)
2284 return -1;
2285 return len;
2286 }
2287
2288 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2289 if (ret < 0 || ret >= end - pos)
2290 return pos - buf;
2291 pos += ret;
2292
2293 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2294 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2295 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2296 if (ret < 0 || ret >= end - pos)
2297 return pos - buf;
2298 pos += ret;
2299 }
2300
2301 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2302 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2303 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2304 if (ret < 0 || ret >= end - pos)
2305 return pos - buf;
2306 pos += ret;
2307 }
2308
2309 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2310 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2311 if (ret < 0 || ret >= end - pos)
2312 return pos - buf;
2313 pos += ret;
2314 }
2315
2316 return pos - buf;
2317 }
2318
2319
2320 static int ctrl_iface_get_capability_proto(int res, char *strict,
2321 struct wpa_driver_capa *capa,
2322 char *buf, size_t buflen)
2323 {
2324 int ret, first = 1;
2325 char *pos, *end;
2326 size_t len;
2327
2328 pos = buf;
2329 end = pos + buflen;
2330
2331 if (res < 0) {
2332 if (strict)
2333 return 0;
2334 len = os_strlcpy(buf, "RSN WPA", buflen);
2335 if (len >= buflen)
2336 return -1;
2337 return len;
2338 }
2339
2340 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2341 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2342 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
2343 if (ret < 0 || ret >= end - pos)
2344 return pos - buf;
2345 pos += ret;
2346 first = 0;
2347 }
2348
2349 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2350 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
2351 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
2352 if (ret < 0 || ret >= end - pos)
2353 return pos - buf;
2354 pos += ret;
2355 first = 0;
2356 }
2357
2358 return pos - buf;
2359 }
2360
2361
2362 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
2363 struct wpa_driver_capa *capa,
2364 char *buf, size_t buflen)
2365 {
2366 int ret, first = 1;
2367 char *pos, *end;
2368 size_t len;
2369
2370 pos = buf;
2371 end = pos + buflen;
2372
2373 if (res < 0) {
2374 if (strict)
2375 return 0;
2376 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
2377 if (len >= buflen)
2378 return -1;
2379 return len;
2380 }
2381
2382 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
2383 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
2384 if (ret < 0 || ret >= end - pos)
2385 return pos - buf;
2386 pos += ret;
2387 first = 0;
2388 }
2389
2390 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
2391 ret = os_snprintf(pos, end - pos, "%sSHARED",
2392 first ? "" : " ");
2393 if (ret < 0 || ret >= end - pos)
2394 return pos - buf;
2395 pos += ret;
2396 first = 0;
2397 }
2398
2399 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
2400 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
2401 if (ret < 0 || ret >= end - pos)
2402 return pos - buf;
2403 pos += ret;
2404 first = 0;
2405 }
2406
2407 return pos - buf;
2408 }
2409
2410
2411 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
2412 char *buf, size_t buflen)
2413 {
2414 struct hostapd_channel_data *chnl;
2415 int ret, i, j;
2416 char *pos, *end, *hmode;
2417
2418 pos = buf;
2419 end = pos + buflen;
2420
2421 for (j = 0; j < wpa_s->hw.num_modes; j++) {
2422 switch (wpa_s->hw.modes[j].mode) {
2423 case HOSTAPD_MODE_IEEE80211B:
2424 hmode = "B";
2425 break;
2426 case HOSTAPD_MODE_IEEE80211G:
2427 hmode = "G";
2428 break;
2429 case HOSTAPD_MODE_IEEE80211A:
2430 hmode = "A";
2431 break;
2432 default:
2433 continue;
2434 }
2435 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
2436 if (ret < 0 || ret >= end - pos)
2437 return pos - buf;
2438 pos += ret;
2439 chnl = wpa_s->hw.modes[j].channels;
2440 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
2441 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
2442 continue;
2443 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
2444 if (ret < 0 || ret >= end - pos)
2445 return pos - buf;
2446 pos += ret;
2447 }
2448 ret = os_snprintf(pos, end - pos, "\n");
2449 if (ret < 0 || ret >= end - pos)
2450 return pos - buf;
2451 pos += ret;
2452 }
2453
2454 return pos - buf;
2455 }
2456
2457
2458 static int wpa_supplicant_ctrl_iface_get_capability(
2459 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
2460 size_t buflen)
2461 {
2462 struct wpa_driver_capa capa;
2463 int res;
2464 char *strict;
2465 char field[30];
2466 size_t len;
2467
2468 /* Determine whether or not strict checking was requested */
2469 len = os_strlcpy(field, _field, sizeof(field));
2470 if (len >= sizeof(field))
2471 return -1;
2472 strict = os_strchr(field, ' ');
2473 if (strict != NULL) {
2474 *strict++ = '\0';
2475 if (os_strcmp(strict, "strict") != 0)
2476 return -1;
2477 }
2478
2479 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
2480 field, strict ? strict : "");
2481
2482 if (os_strcmp(field, "eap") == 0) {
2483 return eap_get_names(buf, buflen);
2484 }
2485
2486 res = wpa_drv_get_capa(wpa_s, &capa);
2487
2488 if (os_strcmp(field, "pairwise") == 0)
2489 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
2490 buf, buflen);
2491
2492 if (os_strcmp(field, "group") == 0)
2493 return ctrl_iface_get_capability_group(res, strict, &capa,
2494 buf, buflen);
2495
2496 if (os_strcmp(field, "key_mgmt") == 0)
2497 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
2498 buf, buflen);
2499
2500 if (os_strcmp(field, "proto") == 0)
2501 return ctrl_iface_get_capability_proto(res, strict, &capa,
2502 buf, buflen);
2503
2504 if (os_strcmp(field, "auth_alg") == 0)
2505 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
2506 buf, buflen);
2507
2508 if (os_strcmp(field, "channels") == 0)
2509 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
2510
2511 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
2512 field);
2513
2514 return -1;
2515 }
2516
2517
2518 #ifdef CONFIG_INTERWORKING
2519 static char * anqp_add_hex(char *pos, char *end, const char *title,
2520 struct wpabuf *data)
2521 {
2522 char *start = pos;
2523 size_t i;
2524 int ret;
2525 const u8 *d;
2526
2527 if (data == NULL)
2528 return start;
2529
2530 ret = os_snprintf(pos, end - pos, "%s=", title);
2531 if (ret < 0 || ret >= end - pos)
2532 return start;
2533 pos += ret;
2534
2535 d = wpabuf_head_u8(data);
2536 for (i = 0; i < wpabuf_len(data); i++) {
2537 ret = os_snprintf(pos, end - pos, "%02x", *d++);
2538 if (ret < 0 || ret >= end - pos)
2539 return start;
2540 pos += ret;
2541 }
2542
2543 ret = os_snprintf(pos, end - pos, "\n");
2544 if (ret < 0 || ret >= end - pos)
2545 return start;
2546 pos += ret;
2547
2548 return pos;
2549 }
2550 #endif /* CONFIG_INTERWORKING */
2551
2552
2553 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
2554 unsigned long mask, char *buf, size_t buflen)
2555 {
2556 size_t i;
2557 int ret;
2558 char *pos, *end;
2559 const u8 *ie, *ie2;
2560
2561 pos = buf;
2562 end = buf + buflen;
2563
2564 if (mask & WPA_BSS_MASK_ID) {
2565 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
2566 if (ret < 0 || ret >= end - pos)
2567 return 0;
2568 pos += ret;
2569 }
2570
2571 if (mask & WPA_BSS_MASK_BSSID) {
2572 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2573 MAC2STR(bss->bssid));
2574 if (ret < 0 || ret >= end - pos)
2575 return 0;
2576 pos += ret;
2577 }
2578
2579 if (mask & WPA_BSS_MASK_FREQ) {
2580 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
2581 if (ret < 0 || ret >= end - pos)
2582 return 0;
2583 pos += ret;
2584 }
2585
2586 if (mask & WPA_BSS_MASK_BEACON_INT) {
2587 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
2588 bss->beacon_int);
2589 if (ret < 0 || ret >= end - pos)
2590 return 0;
2591 pos += ret;
2592 }
2593
2594 if (mask & WPA_BSS_MASK_CAPABILITIES) {
2595 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
2596 bss->caps);
2597 if (ret < 0 || ret >= end - pos)
2598 return 0;
2599 pos += ret;
2600 }
2601
2602 if (mask & WPA_BSS_MASK_QUAL) {
2603 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
2604 if (ret < 0 || ret >= end - pos)
2605 return 0;
2606 pos += ret;
2607 }
2608
2609 if (mask & WPA_BSS_MASK_NOISE) {
2610 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
2611 if (ret < 0 || ret >= end - pos)
2612 return 0;
2613 pos += ret;
2614 }
2615
2616 if (mask & WPA_BSS_MASK_LEVEL) {
2617 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
2618 if (ret < 0 || ret >= end - pos)
2619 return 0;
2620 pos += ret;
2621 }
2622
2623 if (mask & WPA_BSS_MASK_TSF) {
2624 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
2625 (unsigned long long) bss->tsf);
2626 if (ret < 0 || ret >= end - pos)
2627 return 0;
2628 pos += ret;
2629 }
2630
2631 if (mask & WPA_BSS_MASK_AGE) {
2632 struct os_time now;
2633
2634 os_get_time(&now);
2635 ret = os_snprintf(pos, end - pos, "age=%d\n",
2636 (int) (now.sec - bss->last_update.sec));
2637 if (ret < 0 || ret >= end - pos)
2638 return 0;
2639 pos += ret;
2640 }
2641
2642 if (mask & WPA_BSS_MASK_IE) {
2643 ret = os_snprintf(pos, end - pos, "ie=");
2644 if (ret < 0 || ret >= end - pos)
2645 return 0;
2646 pos += ret;
2647
2648 ie = (const u8 *) (bss + 1);
2649 for (i = 0; i < bss->ie_len; i++) {
2650 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
2651 if (ret < 0 || ret >= end - pos)
2652 return 0;
2653 pos += ret;
2654 }
2655
2656 ret = os_snprintf(pos, end - pos, "\n");
2657 if (ret < 0 || ret >= end - pos)
2658 return 0;
2659 pos += ret;
2660 }
2661
2662 if (mask & WPA_BSS_MASK_FLAGS) {
2663 ret = os_snprintf(pos, end - pos, "flags=");
2664 if (ret < 0 || ret >= end - pos)
2665 return 0;
2666 pos += ret;
2667
2668 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2669 if (ie)
2670 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
2671 2 + ie[1]);
2672 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2673 if (ie2)
2674 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
2675 2 + ie2[1]);
2676 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2677 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2678 ret = os_snprintf(pos, end - pos, "[WEP]");
2679 if (ret < 0 || ret >= end - pos)
2680 return 0;
2681 pos += ret;
2682 }
2683 if (bss->caps & IEEE80211_CAP_IBSS) {
2684 ret = os_snprintf(pos, end - pos, "[IBSS]");
2685 if (ret < 0 || ret >= end - pos)
2686 return 0;
2687 pos += ret;
2688 }
2689 if (bss->caps & IEEE80211_CAP_ESS) {
2690 ret = os_snprintf(pos, end - pos, "[ESS]");
2691 if (ret < 0 || ret >= end - pos)
2692 return 0;
2693 pos += ret;
2694 }
2695 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) {
2696 ret = os_snprintf(pos, end - pos, "[P2P]");
2697 if (ret < 0 || ret >= end - pos)
2698 return 0;
2699 pos += ret;
2700 }
2701 #ifdef CONFIG_HS20
2702 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
2703 ret = os_snprintf(pos, end - pos, "[HS20]");
2704 if (ret < 0 || ret >= end - pos)
2705 return -1;
2706 pos += ret;
2707 }
2708 #endif /* CONFIG_HS20 */
2709
2710 ret = os_snprintf(pos, end - pos, "\n");
2711 if (ret < 0 || ret >= end - pos)
2712 return 0;
2713 pos += ret;
2714 }
2715
2716 if (mask & WPA_BSS_MASK_SSID) {
2717 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
2718 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2719 if (ret < 0 || ret >= end - pos)
2720 return 0;
2721 pos += ret;
2722 }
2723
2724 #ifdef CONFIG_WPS
2725 if (mask & WPA_BSS_MASK_WPS_SCAN) {
2726 ie = (const u8 *) (bss + 1);
2727 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
2728 if (ret < 0 || ret >= end - pos)
2729 return 0;
2730 pos += ret;
2731 }
2732 #endif /* CONFIG_WPS */
2733
2734 #ifdef CONFIG_P2P
2735 if (mask & WPA_BSS_MASK_P2P_SCAN) {
2736 ie = (const u8 *) (bss + 1);
2737 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
2738 if (ret < 0 || ret >= end - pos)
2739 return 0;
2740 pos += ret;
2741 }
2742 #endif /* CONFIG_P2P */
2743
2744 #ifdef CONFIG_WIFI_DISPLAY
2745 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
2746 struct wpabuf *wfd;
2747 ie = (const u8 *) (bss + 1);
2748 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
2749 WFD_IE_VENDOR_TYPE);
2750 if (wfd) {
2751 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
2752 if (ret < 0 || ret >= end - pos)
2753 return pos - buf;
2754 pos += ret;
2755
2756 pos += wpa_snprintf_hex(pos, end - pos,
2757 wpabuf_head(wfd),
2758 wpabuf_len(wfd));
2759 wpabuf_free(wfd);
2760
2761 ret = os_snprintf(pos, end - pos, "\n");
2762 if (ret < 0 || ret >= end - pos)
2763 return pos - buf;
2764 pos += ret;
2765 }
2766 }
2767 #endif /* CONFIG_WIFI_DISPLAY */
2768
2769 #ifdef CONFIG_INTERWORKING
2770 if (mask & WPA_BSS_MASK_INTERNETW) {
2771 pos = anqp_add_hex(pos, end, "anqp_venue_name",
2772 bss->anqp_venue_name);
2773 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
2774 bss->anqp_network_auth_type);
2775 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
2776 bss->anqp_roaming_consortium);
2777 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
2778 bss->anqp_ip_addr_type_availability);
2779 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
2780 bss->anqp_nai_realm);
2781 pos = anqp_add_hex(pos, end, "anqp_3gpp", bss->anqp_3gpp);
2782 pos = anqp_add_hex(pos, end, "anqp_domain_name",
2783 bss->anqp_domain_name);
2784 #ifdef CONFIG_HS20
2785 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
2786 bss->hs20_operator_friendly_name);
2787 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
2788 bss->hs20_wan_metrics);
2789 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
2790 bss->hs20_connection_capability);
2791 #endif /* CONFIG_HS20 */
2792 }
2793 #endif /* CONFIG_INTERWORKING */
2794
2795 return pos - buf;
2796 }
2797
2798
2799 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
2800 const char *cmd, char *buf,
2801 size_t buflen)
2802 {
2803 u8 bssid[ETH_ALEN];
2804 size_t i;
2805 struct wpa_bss *bss;
2806 struct wpa_bss *bsslast = NULL;
2807 struct dl_list *next;
2808 int ret = 0;
2809 int len;
2810 char *ctmp;
2811 unsigned long mask = WPA_BSS_MASK_ALL;
2812
2813 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
2814 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
2815 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
2816 list_id);
2817 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
2818 list_id);
2819 } else { /* N1-N2 */
2820 unsigned int id1, id2;
2821
2822 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
2823 wpa_printf(MSG_INFO, "Wrong BSS range "
2824 "format");
2825 return 0;
2826 }
2827
2828 id1 = atoi(cmd + 6);
2829 bss = wpa_bss_get_id(wpa_s, id1);
2830 id2 = atoi(ctmp + 1);
2831 if (id2 == 0)
2832 bsslast = dl_list_last(&wpa_s->bss_id,
2833 struct wpa_bss,
2834 list_id);
2835 else {
2836 bsslast = wpa_bss_get_id(wpa_s, id2);
2837 if (bsslast == NULL && bss && id2 > id1) {
2838 struct wpa_bss *tmp = bss;
2839 for (;;) {
2840 next = tmp->list_id.next;
2841 if (next == &wpa_s->bss_id)
2842 break;
2843 tmp = dl_list_entry(
2844 next, struct wpa_bss,
2845 list_id);
2846 if (tmp->id > id2)
2847 break;
2848 bsslast = tmp;
2849 }
2850 }
2851 }
2852 }
2853 } else if (os_strcmp(cmd, "FIRST") == 0)
2854 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
2855 else if (os_strncmp(cmd, "ID-", 3) == 0) {
2856 i = atoi(cmd + 3);
2857 bss = wpa_bss_get_id(wpa_s, i);
2858 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
2859 i = atoi(cmd + 5);
2860 bss = wpa_bss_get_id(wpa_s, i);
2861 if (bss) {
2862 next = bss->list_id.next;
2863 if (next == &wpa_s->bss_id)
2864 bss = NULL;
2865 else
2866 bss = dl_list_entry(next, struct wpa_bss,
2867 list_id);
2868 }
2869 #ifdef CONFIG_P2P
2870 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
2871 if (hwaddr_aton(cmd + 13, bssid) == 0)
2872 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
2873 else
2874 bss = NULL;
2875 #endif /* CONFIG_P2P */
2876 } else if (hwaddr_aton(cmd, bssid) == 0)
2877 bss = wpa_bss_get_bssid(wpa_s, bssid);
2878 else {
2879 struct wpa_bss *tmp;
2880 i = atoi(cmd);
2881 bss = NULL;
2882 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
2883 {
2884 if (i-- == 0) {
2885 bss = tmp;
2886 break;
2887 }
2888 }
2889 }
2890
2891 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
2892 mask = strtoul(ctmp + 5, NULL, 0x10);
2893 if (mask == 0)
2894 mask = WPA_BSS_MASK_ALL;
2895 }
2896
2897 if (bss == NULL)
2898 return 0;
2899
2900 if (bsslast == NULL)
2901 bsslast = bss;
2902 do {
2903 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
2904 ret += len;
2905 buf += len;
2906 buflen -= len;
2907 if (bss == bsslast)
2908 break;
2909 next = bss->list_id.next;
2910 if (next == &wpa_s->bss_id)
2911 break;
2912 bss = dl_list_entry(next, struct wpa_bss, list_id);
2913 } while (bss && len);
2914
2915 return ret;
2916 }
2917
2918
2919 static int wpa_supplicant_ctrl_iface_ap_scan(
2920 struct wpa_supplicant *wpa_s, char *cmd)
2921 {
2922 int ap_scan = atoi(cmd);
2923 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
2924 }
2925
2926
2927 static int wpa_supplicant_ctrl_iface_scan_interval(
2928 struct wpa_supplicant *wpa_s, char *cmd)
2929 {
2930 int scan_int = atoi(cmd);
2931 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
2932 }
2933
2934
2935 static int wpa_supplicant_ctrl_iface_bss_expire_age(
2936 struct wpa_supplicant *wpa_s, char *cmd)
2937 {
2938 int expire_age = atoi(cmd);
2939 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
2940 }
2941
2942
2943 static int wpa_supplicant_ctrl_iface_bss_expire_count(
2944 struct wpa_supplicant *wpa_s, char *cmd)
2945 {
2946 int expire_count = atoi(cmd);
2947 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
2948 }
2949
2950
2951 static int wpa_supplicant_ctrl_iface_bss_flush(
2952 struct wpa_supplicant *wpa_s, char *cmd)
2953 {
2954 int flush_age = atoi(cmd);
2955
2956 if (flush_age == 0)
2957 wpa_bss_flush(wpa_s);
2958 else
2959 wpa_bss_flush_by_age(wpa_s, flush_age);
2960 return 0;
2961 }
2962
2963
2964 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
2965 {
2966 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
2967 /* MLME-DELETEKEYS.request */
2968 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
2969 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
2970 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
2971 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
2972 #ifdef CONFIG_IEEE80211W
2973 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
2974 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
2975 #endif /* CONFIG_IEEE80211W */
2976
2977 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
2978 0);
2979 /* MLME-SETPROTECTION.request(None) */
2980 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
2981 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
2982 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
2983 wpa_sm_drop_sa(wpa_s->wpa);
2984 }
2985
2986
2987 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
2988 char *addr)
2989 {
2990 #ifdef CONFIG_NO_SCAN_PROCESSING
2991 return -1;
2992 #else /* CONFIG_NO_SCAN_PROCESSING */
2993 u8 bssid[ETH_ALEN];
2994 struct wpa_bss *bss;
2995 struct wpa_ssid *ssid = wpa_s->current_ssid;
2996
2997 if (hwaddr_aton(addr, bssid)) {
2998 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
2999 "address '%s'", addr);
3000 return -1;
3001 }
3002
3003 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3004
3005 bss = wpa_bss_get_bssid(wpa_s, bssid);
3006 if (!bss) {
3007 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3008 "from BSS table");
3009 return -1;
3010 }
3011
3012 /*
3013 * TODO: Find best network configuration block from configuration to
3014 * allow roaming to other networks
3015 */
3016
3017 if (!ssid) {
3018 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3019 "configuration known for the target AP");
3020 return -1;
3021 }
3022
3023 wpa_s->reassociate = 1;
3024 wpa_supplicant_connect(wpa_s, bss, ssid);
3025
3026 return 0;
3027 #endif /* CONFIG_NO_SCAN_PROCESSING */
3028 }
3029
3030
3031 #ifdef CONFIG_P2P
3032 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3033 {
3034 unsigned int timeout = atoi(cmd);
3035 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
3036 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3037 char *pos;
3038 unsigned int search_delay;
3039
3040 if (os_strstr(cmd, "type=social"))
3041 type = P2P_FIND_ONLY_SOCIAL;
3042 else if (os_strstr(cmd, "type=progressive"))
3043 type = P2P_FIND_PROGRESSIVE;
3044
3045 pos = os_strstr(cmd, "dev_id=");
3046 if (pos) {
3047 pos += 7;
3048 if (hwaddr_aton(pos, dev_id))
3049 return -1;
3050 _dev_id = dev_id;
3051 }
3052
3053 pos = os_strstr(cmd, "delay=");
3054 if (pos) {
3055 pos += 6;
3056 search_delay = atoi(pos);
3057 } else
3058 search_delay = wpas_p2p_search_delay(wpa_s);
3059
3060 return wpas_p2p_find(wpa_s, timeout, type, 0, NULL, _dev_id,
3061 search_delay);
3062 }
3063
3064
3065 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3066 char *buf, size_t buflen)
3067 {
3068 u8 addr[ETH_ALEN];
3069 char *pos, *pos2;
3070 char *pin = NULL;
3071 enum p2p_wps_method wps_method;
3072 int new_pin;
3073 int ret;
3074 int persistent_group, persistent_id = -1;
3075 int join;
3076 int auth;
3077 int automatic;
3078 int go_intent = -1;
3079 int freq = 0;
3080 int pd;
3081 int ht40;
3082
3083 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3084 * [persistent|persistent=<network id>]
3085 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3086 * [ht40] */
3087
3088 if (hwaddr_aton(cmd, addr))
3089 return -1;
3090
3091 pos = cmd + 17;
3092 if (*pos != ' ')
3093 return -1;
3094 pos++;
3095
3096 persistent_group = os_strstr(pos, " persistent") != NULL;
3097 pos2 = os_strstr(pos, " persistent=");
3098 if (pos2) {
3099 struct wpa_ssid *ssid;
3100 persistent_id = atoi(pos2 + 12);
3101 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3102 if (ssid == NULL || ssid->disabled != 2 ||
3103 ssid->mode != WPAS_MODE_P2P_GO) {
3104 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3105 "SSID id=%d for persistent P2P group (GO)",
3106 persistent_id);
3107 return -1;
3108 }
3109 }
3110 join = os_strstr(pos, " join") != NULL;
3111 auth = os_strstr(pos, " auth") != NULL;
3112 automatic = os_strstr(pos, " auto") != NULL;
3113 pd = os_strstr(pos, " provdisc") != NULL;
3114 ht40 = os_strstr(pos, " ht40") != NULL;
3115
3116 pos2 = os_strstr(pos, " go_intent=");
3117 if (pos2) {
3118 pos2 += 11;
3119 go_intent = atoi(pos2);
3120 if (go_intent < 0 || go_intent > 15)
3121 return -1;
3122 }
3123
3124 pos2 = os_strstr(pos, " freq=");
3125 if (pos2) {
3126 pos2 += 6;
3127 freq = atoi(pos2);
3128 if (freq <= 0)
3129 return -1;
3130 }
3131
3132 if (os_strncmp(pos, "pin", 3) == 0) {
3133 /* Request random PIN (to be displayed) and enable the PIN */
3134 wps_method = WPS_PIN_DISPLAY;
3135 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3136 wps_method = WPS_PBC;
3137 } else {
3138 pin = pos;
3139 pos = os_strchr(pin, ' ');
3140 wps_method = WPS_PIN_KEYPAD;
3141 if (pos) {
3142 *pos++ = '\0';
3143 if (os_strncmp(pos, "display", 7) == 0)
3144 wps_method = WPS_PIN_DISPLAY;
3145 }
3146 if (!wps_pin_str_valid(pin)) {
3147 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3148 return 17;
3149 }
3150 }
3151
3152 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
3153 persistent_group, automatic, join,
3154 auth, go_intent, freq, persistent_id, pd,
3155 ht40);
3156 if (new_pin == -2) {
3157 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3158 return 25;
3159 }
3160 if (new_pin == -3) {
3161 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3162 return 25;
3163 }
3164 if (new_pin < 0)
3165 return -1;
3166 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3167 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3168 if (ret < 0 || (size_t) ret >= buflen)
3169 return -1;
3170 return ret;
3171 }
3172
3173 os_memcpy(buf, "OK\n", 3);
3174 return 3;
3175 }
3176
3177
3178 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3179 {
3180 unsigned int timeout = atoi(cmd);
3181 return wpas_p2p_listen(wpa_s, timeout);
3182 }
3183
3184
3185 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
3186 {
3187 u8 addr[ETH_ALEN];
3188 char *pos;
3189 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
3190
3191 /* <addr> <config method> [join|auto] */
3192
3193 if (hwaddr_aton(cmd, addr))
3194 return -1;
3195
3196 pos = cmd + 17;
3197 if (*pos != ' ')
3198 return -1;
3199 pos++;
3200
3201 if (os_strstr(pos, " join") != NULL)
3202 use = WPAS_P2P_PD_FOR_JOIN;
3203 else if (os_strstr(pos, " auto") != NULL)
3204 use = WPAS_P2P_PD_AUTO;
3205
3206 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
3207 }
3208
3209
3210 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
3211 size_t buflen)
3212 {
3213 struct wpa_ssid *ssid = wpa_s->current_ssid;
3214
3215 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
3216 ssid->passphrase == NULL)
3217 return -1;
3218
3219 os_strlcpy(buf, ssid->passphrase, buflen);
3220 return os_strlen(buf);
3221 }
3222
3223
3224 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
3225 char *buf, size_t buflen)
3226 {
3227 u64 ref;
3228 int res;
3229 u8 dst_buf[ETH_ALEN], *dst;
3230 struct wpabuf *tlvs;
3231 char *pos;
3232 size_t len;
3233
3234 if (hwaddr_aton(cmd, dst_buf))
3235 return -1;
3236 dst = dst_buf;
3237 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
3238 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
3239 dst = NULL;
3240 pos = cmd + 17;
3241 if (*pos != ' ')
3242 return -1;
3243 pos++;
3244
3245 if (os_strncmp(pos, "upnp ", 5) == 0) {
3246 u8 version;
3247 pos += 5;
3248 if (hexstr2bin(pos, &version, 1) < 0)
3249 return -1;
3250 pos += 2;
3251 if (*pos != ' ')
3252 return -1;
3253 pos++;
3254 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
3255 #ifdef CONFIG_WIFI_DISPLAY
3256 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
3257 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
3258 #endif /* CONFIG_WIFI_DISPLAY */
3259 } else {
3260 len = os_strlen(pos);
3261 if (len & 1)
3262 return -1;
3263 len /= 2;
3264 tlvs = wpabuf_alloc(len);
3265 if (tlvs == NULL)
3266 return -1;
3267 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
3268 wpabuf_free(tlvs);
3269 return -1;
3270 }
3271
3272 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
3273 wpabuf_free(tlvs);
3274 }
3275 if (ref == 0)
3276 return -1;
3277 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
3278 if (res < 0 || (unsigned) res >= buflen)
3279 return -1;
3280 return res;
3281 }
3282
3283
3284 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
3285 char *cmd)
3286 {
3287 long long unsigned val;
3288 u64 req;
3289 if (sscanf(cmd, "%llx", &val) != 1)
3290 return -1;
3291 req = val;
3292 return wpas_p2p_sd_cancel_request(wpa_s, req);
3293 }
3294
3295
3296 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
3297 {
3298 int freq;
3299 u8 dst[ETH_ALEN];
3300 u8 dialog_token;
3301 struct wpabuf *resp_tlvs;
3302 char *pos, *pos2;
3303 size_t len;
3304
3305 pos = os_strchr(cmd, ' ');
3306 if (pos == NULL)
3307 return -1;
3308 *pos++ = '\0';
3309 freq = atoi(cmd);
3310 if (freq == 0)
3311 return -1;
3312
3313 if (hwaddr_aton(pos, dst))
3314 return -1;
3315 pos += 17;
3316 if (*pos != ' ')
3317 return -1;
3318 pos++;
3319
3320 pos2 = os_strchr(pos, ' ');
3321 if (pos2 == NULL)
3322 return -1;
3323 *pos2++ = '\0';
3324 dialog_token = atoi(pos);
3325
3326 len = os_strlen(pos2);
3327 if (len & 1)
3328 return -1;
3329 len /= 2;
3330 resp_tlvs = wpabuf_alloc(len);
3331 if (resp_tlvs == NULL)
3332 return -1;
3333 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
3334 wpabuf_free(resp_tlvs);
3335 return -1;
3336 }
3337
3338 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
3339 wpabuf_free(resp_tlvs);
3340 return 0;
3341 }
3342
3343
3344 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
3345 char *cmd)
3346 {
3347 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
3348 return -1;
3349 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
3350 return 0;
3351 }
3352
3353
3354 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
3355 char *cmd)
3356 {
3357 char *pos;
3358 size_t len;
3359 struct wpabuf *query, *resp;
3360
3361 pos = os_strchr(cmd, ' ');
3362 if (pos == NULL)
3363 return -1;
3364 *pos++ = '\0';
3365
3366 len = os_strlen(cmd);
3367 if (len & 1)
3368 return -1;
3369 len /= 2;
3370 query = wpabuf_alloc(len);
3371 if (query == NULL)
3372 return -1;
3373 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
3374 wpabuf_free(query);
3375 return -1;
3376 }
3377
3378 len = os_strlen(pos);
3379 if (len & 1) {
3380 wpabuf_free(query);
3381 return -1;
3382 }
3383 len /= 2;
3384 resp = wpabuf_alloc(len);
3385 if (resp == NULL) {
3386 wpabuf_free(query);
3387 return -1;
3388 }
3389 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
3390 wpabuf_free(query);
3391 wpabuf_free(resp);
3392 return -1;
3393 }
3394
3395 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
3396 wpabuf_free(query);
3397 wpabuf_free(resp);
3398 return -1;
3399 }
3400 return 0;
3401 }
3402
3403
3404 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
3405 {
3406 char *pos;
3407 u8 version;
3408
3409 pos = os_strchr(cmd, ' ');
3410 if (pos == NULL)
3411 return -1;
3412 *pos++ = '\0';
3413
3414 if (hexstr2bin(cmd, &version, 1) < 0)
3415 return -1;
3416
3417 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
3418 }
3419
3420
3421 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
3422 {
3423 char *pos;
3424
3425 pos = os_strchr(cmd, ' ');
3426 if (pos == NULL)
3427 return -1;
3428 *pos++ = '\0';
3429
3430 if (os_strcmp(cmd, "bonjour") == 0)
3431 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
3432 if (os_strcmp(cmd, "upnp") == 0)
3433 return p2p_ctrl_service_add_upnp(wpa_s, pos);
3434 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
3435 return -1;
3436 }
3437
3438
3439 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
3440 char *cmd)
3441 {
3442 size_t len;
3443 struct wpabuf *query;
3444 int ret;
3445
3446 len = os_strlen(cmd);
3447 if (len & 1)
3448 return -1;
3449 len /= 2;
3450 query = wpabuf_alloc(len);
3451 if (query == NULL)
3452 return -1;
3453 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
3454 wpabuf_free(query);
3455 return -1;
3456 }
3457
3458 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
3459 wpabuf_free(query);
3460 return ret;
3461 }
3462
3463
3464 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
3465 {
3466 char *pos;
3467 u8 version;
3468
3469 pos = os_strchr(cmd, ' ');
3470 if (pos == NULL)
3471 return -1;
3472 *pos++ = '\0';
3473
3474 if (hexstr2bin(cmd, &version, 1) < 0)
3475 return -1;
3476
3477 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
3478 }
3479
3480
3481 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
3482 {
3483 char *pos;
3484
3485 pos = os_strchr(cmd, ' ');
3486 if (pos == NULL)
3487 return -1;
3488 *pos++ = '\0';
3489
3490 if (os_strcmp(cmd, "bonjour") == 0)
3491 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
3492 if (os_strcmp(cmd, "upnp") == 0)
3493 return p2p_ctrl_service_del_upnp(wpa_s, pos);
3494 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
3495 return -1;
3496 }
3497
3498
3499 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
3500 {
3501 u8 addr[ETH_ALEN];
3502
3503 /* <addr> */
3504
3505 if (hwaddr_aton(cmd, addr))
3506 return -1;
3507
3508 return wpas_p2p_reject(wpa_s, addr);
3509 }
3510
3511
3512 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
3513 {
3514 char *pos;
3515 int id;
3516 struct wpa_ssid *ssid;
3517 u8 peer[ETH_ALEN];
3518 int freq = 0;
3519 int ht40;
3520
3521 id = atoi(cmd);
3522 pos = os_strstr(cmd, " peer=");
3523 if (pos) {
3524 pos += 6;
3525 if (hwaddr_aton(pos, peer))
3526 return -1;
3527 }
3528 ssid = wpa_config_get_network(wpa_s->conf, id);
3529 if (ssid == NULL || ssid->disabled != 2) {
3530 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
3531 "for persistent P2P group",
3532 id);
3533 return -1;
3534 }
3535
3536 pos = os_strstr(cmd, " freq=");
3537 if (pos) {
3538 pos += 6;
3539 freq = atoi(pos);
3540 if (freq <= 0)
3541 return -1;
3542 }
3543
3544 ht40 = os_strstr(cmd, " ht40") != NULL;
3545
3546 return wpas_p2p_invite(wpa_s, pos ? peer : NULL, ssid, NULL, freq,
3547 ht40);
3548 }
3549
3550
3551 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
3552 {
3553 char *pos;
3554 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
3555
3556 pos = os_strstr(cmd, " peer=");
3557 if (!pos)
3558 return -1;
3559
3560 *pos = '\0';
3561 pos += 6;
3562 if (hwaddr_aton(pos, peer)) {
3563 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
3564 return -1;
3565 }
3566
3567 pos = os_strstr(pos, " go_dev_addr=");
3568 if (pos) {
3569 pos += 13;
3570 if (hwaddr_aton(pos, go_dev_addr)) {
3571 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
3572 pos);
3573 return -1;
3574 }
3575 go_dev = go_dev_addr;
3576 }
3577
3578 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
3579 }
3580
3581
3582 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
3583 {
3584 if (os_strncmp(cmd, "persistent=", 11) == 0)
3585 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
3586 if (os_strncmp(cmd, "group=", 6) == 0)
3587 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
3588
3589 return -1;
3590 }
3591
3592
3593 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
3594 char *cmd, int freq, int ht40)
3595 {
3596 int id;
3597 struct wpa_ssid *ssid;
3598
3599 id = atoi(cmd);
3600 ssid = wpa_config_get_network(wpa_s->conf, id);
3601 if (ssid == NULL || ssid->disabled != 2) {
3602 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
3603 "for persistent P2P group",
3604 id);
3605 return -1;
3606 }
3607
3608 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, ht40);
3609 }
3610
3611
3612 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
3613 {
3614 int freq = 0, ht40;
3615 char *pos;
3616
3617 pos = os_strstr(cmd, "freq=");
3618 if (pos)
3619 freq = atoi(pos + 5);
3620
3621 ht40 = os_strstr(cmd, "ht40") != NULL;
3622
3623 if (os_strncmp(cmd, "persistent=", 11) == 0)
3624 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
3625 ht40);
3626 if (os_strcmp(cmd, "persistent") == 0 ||
3627 os_strncmp(cmd, "persistent ", 11) == 0)
3628 return wpas_p2p_group_add(wpa_s, 1, freq, ht40);
3629 if (os_strncmp(cmd, "freq=", 5) == 0)
3630 return wpas_p2p_group_add(wpa_s, 0, freq, ht40);
3631 if (ht40)
3632 return wpas_p2p_group_add(wpa_s, 0, freq, ht40);
3633
3634 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
3635 cmd);
3636 return -1;
3637 }
3638
3639
3640 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
3641 char *buf, size_t buflen)
3642 {
3643 u8 addr[ETH_ALEN], *addr_ptr;
3644 int next, res;
3645 const struct p2p_peer_info *info;
3646 char *pos, *end;
3647 char devtype[WPS_DEV_TYPE_BUFSIZE];
3648 struct wpa_ssid *ssid;
3649
3650 if (!wpa_s->global->p2p)
3651 return -1;
3652
3653 if (os_strcmp(cmd, "FIRST") == 0) {
3654 addr_ptr = NULL;
3655 next = 0;
3656 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3657 if (hwaddr_aton(cmd + 5, addr) < 0)
3658 return -1;
3659 addr_ptr = addr;
3660 next = 1;
3661 } else {
3662 if (hwaddr_aton(cmd, addr) < 0)
3663 return -1;
3664 addr_ptr = addr;
3665 next = 0;
3666 }
3667
3668 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
3669 if (info == NULL)
3670 return -1;
3671
3672 pos = buf;
3673 end = buf + buflen;
3674
3675 res = os_snprintf(pos, end - pos, MACSTR "\n"
3676 "pri_dev_type=%s\n"
3677 "device_name=%s\n"
3678 "manufacturer=%s\n"
3679 "model_name=%s\n"
3680 "model_number=%s\n"
3681 "serial_number=%s\n"
3682 "config_methods=0x%x\n"
3683 "dev_capab=0x%x\n"
3684 "group_capab=0x%x\n"
3685 "level=%d\n",
3686 MAC2STR(info->p2p_device_addr),
3687 wps_dev_type_bin2str(info->pri_dev_type,
3688 devtype, sizeof(devtype)),
3689 info->device_name,
3690 info->manufacturer,
3691 info->model_name,
3692 info->model_number,
3693 info->serial_number,
3694 info->config_methods,
3695 info->dev_capab,
3696 info->group_capab,
3697 info->level);
3698 if (res < 0 || res >= end - pos)
3699 return pos - buf;
3700 pos += res;
3701
3702 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
3703 if (ssid) {
3704 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
3705 if (res < 0 || res >= end - pos)
3706 return pos - buf;
3707 pos += res;
3708 }
3709
3710 res = p2p_get_peer_info_txt(info, pos, end - pos);
3711 if (res < 0)
3712 return pos - buf;
3713 pos += res;
3714
3715 return pos - buf;
3716 }
3717
3718
3719 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
3720 const char *param)
3721 {
3722 struct wpa_freq_range *freq = NULL, *n;
3723 unsigned int count = 0, i;
3724 const char *pos, *pos2, *pos3;
3725
3726 if (wpa_s->global->p2p == NULL)
3727 return -1;
3728
3729 /*
3730 * param includes comma separated frequency range.
3731 * For example: 2412-2432,2462,5000-6000
3732 */
3733 pos = param;
3734 while (pos && pos[0]) {
3735 n = os_realloc_array(freq, count + 1,
3736 sizeof(struct wpa_freq_range));
3737 if (n == NULL) {
3738 os_free(freq);
3739 return -1;
3740 }
3741 freq = n;
3742 freq[count].min = atoi(pos);
3743 pos2 = os_strchr(pos, '-');
3744 pos3 = os_strchr(pos, ',');
3745 if (pos2 && (!pos3 || pos2 < pos3)) {
3746 pos2++;
3747 freq[count].max = atoi(pos2);
3748 } else
3749 freq[count].max = freq[count].min;
3750 pos = pos3;
3751 if (pos)
3752 pos++;
3753 count++;
3754 }
3755
3756 for (i = 0; i < count; i++) {
3757 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
3758 freq[i].min, freq[i].max);
3759 }
3760
3761 os_free(wpa_s->global->p2p_disallow_freq);
3762 wpa_s->global->p2p_disallow_freq = freq;
3763 wpa_s->global->num_p2p_disallow_freq = count;
3764 wpas_p2p_update_channel_list(wpa_s);
3765 return 0;
3766 }
3767
3768
3769 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
3770 {
3771 char *param;
3772
3773 if (wpa_s->global->p2p == NULL)
3774 return -1;
3775
3776 param = os_strchr(cmd, ' ');
3777 if (param == NULL)
3778 return -1;
3779 *param++ = '\0';
3780
3781 if (os_strcmp(cmd, "discoverability") == 0) {
3782 p2p_set_client_discoverability(wpa_s->global->p2p,
3783 atoi(param));
3784 return 0;
3785 }
3786
3787 if (os_strcmp(cmd, "managed") == 0) {
3788 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
3789 return 0;
3790 }
3791
3792 if (os_strcmp(cmd, "listen_channel") == 0) {
3793 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
3794 atoi(param));
3795 }
3796
3797 if (os_strcmp(cmd, "ssid_postfix") == 0) {
3798 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
3799 os_strlen(param));
3800 }
3801
3802 if (os_strcmp(cmd, "noa") == 0) {
3803 char *pos;
3804 int count, start, duration;
3805 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
3806 count = atoi(param);
3807 pos = os_strchr(param, ',');
3808 if (pos == NULL)
3809 return -1;
3810 pos++;
3811 start = atoi(pos);
3812 pos = os_strchr(pos, ',');
3813 if (pos == NULL)
3814 return -1;
3815 pos++;
3816 duration = atoi(pos);
3817 if (count < 0 || count > 255 || start < 0 || duration < 0)
3818 return -1;
3819 if (count == 0 && duration > 0)
3820 return -1;
3821 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
3822 "start=%d duration=%d", count, start, duration);
3823 return wpas_p2p_set_noa(wpa_s, count, start, duration);
3824 }
3825
3826 if (os_strcmp(cmd, "ps") == 0)
3827 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
3828
3829 if (os_strcmp(cmd, "oppps") == 0)
3830 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
3831
3832 if (os_strcmp(cmd, "ctwindow") == 0)
3833 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
3834
3835 if (os_strcmp(cmd, "disabled") == 0) {
3836 wpa_s->global->p2p_disabled = atoi(param);
3837 wpa_printf(MSG_DEBUG, "P2P functionality %s",
3838 wpa_s->global->p2p_disabled ?
3839 "disabled" : "enabled");
3840 if (wpa_s->global->p2p_disabled) {
3841 wpas_p2p_stop_find(wpa_s);
3842 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
3843 p2p_flush(wpa_s->global->p2p);
3844 }
3845 return 0;
3846 }
3847
3848 if (os_strcmp(cmd, "conc_pref") == 0) {
3849 if (os_strcmp(param, "sta") == 0)
3850 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
3851 else if (os_strcmp(param, "p2p") == 0)
3852 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
3853 else {
3854 wpa_printf(MSG_INFO, "Invalid conc_pref value");
3855 return -1;
3856 }
3857 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
3858 "%s", param);
3859 return 0;
3860 }
3861
3862 if (os_strcmp(cmd, "force_long_sd") == 0) {
3863 wpa_s->force_long_sd = atoi(param);
3864 return 0;
3865 }
3866
3867 if (os_strcmp(cmd, "peer_filter") == 0) {
3868 u8 addr[ETH_ALEN];
3869 if (hwaddr_aton(param, addr))
3870 return -1;
3871 p2p_set_peer_filter(wpa_s->global->p2p, addr);
3872 return 0;
3873 }
3874
3875 if (os_strcmp(cmd, "cross_connect") == 0)
3876 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
3877
3878 if (os_strcmp(cmd, "go_apsd") == 0) {
3879 if (os_strcmp(param, "disable") == 0)
3880 wpa_s->set_ap_uapsd = 0;
3881 else {
3882 wpa_s->set_ap_uapsd = 1;
3883 wpa_s->ap_uapsd = atoi(param);
3884 }
3885 return 0;
3886 }
3887
3888 if (os_strcmp(cmd, "client_apsd") == 0) {
3889 if (os_strcmp(param, "disable") == 0)
3890 wpa_s->set_sta_uapsd = 0;
3891 else {
3892 int be, bk, vi, vo;
3893 char *pos;
3894 /* format: BE,BK,VI,VO;max SP Length */
3895 be = atoi(param);
3896 pos = os_strchr(param, ',');
3897 if (pos == NULL)
3898 return -1;
3899 pos++;
3900 bk = atoi(pos);
3901 pos = os_strchr(pos, ',');
3902 if (pos == NULL)
3903 return -1;
3904 pos++;
3905 vi = atoi(pos);
3906 pos = os_strchr(pos, ',');
3907 if (pos == NULL)
3908 return -1;
3909 pos++;
3910 vo = atoi(pos);
3911 /* ignore max SP Length for now */
3912
3913 wpa_s->set_sta_uapsd = 1;
3914 wpa_s->sta_uapsd = 0;
3915 if (be)
3916 wpa_s->sta_uapsd |= BIT(0);
3917 if (bk)
3918 wpa_s->sta_uapsd |= BIT(1);
3919 if (vi)
3920 wpa_s->sta_uapsd |= BIT(2);
3921 if (vo)
3922 wpa_s->sta_uapsd |= BIT(3);
3923 }
3924 return 0;
3925 }
3926
3927 if (os_strcmp(cmd, "disallow_freq") == 0)
3928 return p2p_ctrl_disallow_freq(wpa_s, param);
3929
3930 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
3931 cmd);
3932
3933 return -1;
3934 }
3935
3936
3937 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
3938 {
3939 char *pos, *pos2;
3940 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
3941
3942 if (cmd[0]) {
3943 pos = os_strchr(cmd, ' ');
3944 if (pos == NULL)
3945 return -1;
3946 *pos++ = '\0';
3947 dur1 = atoi(cmd);
3948
3949 pos2 = os_strchr(pos, ' ');
3950 if (pos2)
3951 *pos2++ = '\0';
3952 int1 = atoi(pos);
3953 } else
3954 pos2 = NULL;
3955
3956 if (pos2) {
3957 pos = os_strchr(pos2, ' ');
3958 if (pos == NULL)
3959 return -1;
3960 *pos++ = '\0';
3961 dur2 = atoi(pos2);
3962 int2 = atoi(pos);
3963 }
3964
3965 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
3966 }
3967
3968
3969 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
3970 {
3971 char *pos;
3972 unsigned int period = 0, interval = 0;
3973
3974 if (cmd[0]) {
3975 pos = os_strchr(cmd, ' ');
3976 if (pos == NULL)
3977 return -1;
3978 *pos++ = '\0';
3979 period = atoi(cmd);
3980 interval = atoi(pos);
3981 }
3982
3983 return wpas_p2p_ext_listen(wpa_s, period, interval);
3984 }
3985
3986 #endif /* CONFIG_P2P */
3987
3988
3989 #ifdef CONFIG_INTERWORKING
3990 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
3991 {
3992 u8 bssid[ETH_ALEN];
3993 struct wpa_bss *bss;
3994
3995 if (hwaddr_aton(dst, bssid)) {
3996 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
3997 return -1;
3998 }
3999
4000 bss = wpa_bss_get_bssid(wpa_s, bssid);
4001 if (bss == NULL) {
4002 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4003 MAC2STR(bssid));
4004 return -1;
4005 }
4006
4007 return interworking_connect(wpa_s, bss);
4008 }
4009
4010
4011 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4012 {
4013 u8 dst_addr[ETH_ALEN];
4014 int used;
4015 char *pos;
4016 #define MAX_ANQP_INFO_ID 100
4017 u16 id[MAX_ANQP_INFO_ID];
4018 size_t num_id = 0;
4019
4020 used = hwaddr_aton2(dst, dst_addr);
4021 if (used < 0)
4022 return -1;
4023 pos = dst + used;
4024 while (num_id < MAX_ANQP_INFO_ID) {
4025 id[num_id] = atoi(pos);
4026 if (id[num_id])
4027 num_id++;
4028 pos = os_strchr(pos + 1, ',');
4029 if (pos == NULL)
4030 break;
4031 pos++;
4032 }
4033
4034 if (num_id == 0)
4035 return -1;
4036
4037 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4038 }
4039
4040
4041 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4042 {
4043 u8 dst_addr[ETH_ALEN];
4044 struct wpabuf *advproto, *query = NULL;
4045 int used, ret = -1;
4046 char *pos, *end;
4047 size_t len;
4048
4049 used = hwaddr_aton2(cmd, dst_addr);
4050 if (used < 0)
4051 return -1;
4052
4053 pos = cmd + used;
4054 while (*pos == ' ')
4055 pos++;
4056
4057 /* Advertisement Protocol ID */
4058 end = os_strchr(pos, ' ');
4059 if (end)
4060 len = end - pos;
4061 else
4062 len = os_strlen(pos);
4063 if (len & 0x01)
4064 return -1;
4065 len /= 2;
4066 if (len == 0)
4067 return -1;
4068 advproto = wpabuf_alloc(len);
4069 if (advproto == NULL)
4070 return -1;
4071 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
4072 goto fail;
4073
4074 if (end) {
4075 /* Optional Query Request */
4076 pos = end + 1;
4077 while (*pos == ' ')
4078 pos++;
4079
4080 len = os_strlen(pos);
4081 if (len) {
4082 if (len & 0x01)
4083 goto fail;
4084 len /= 2;
4085 if (len == 0)
4086 goto fail;
4087 query = wpabuf_alloc(len);
4088 if (query == NULL)
4089 goto fail;
4090 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
4091 goto fail;
4092 }
4093 }
4094
4095 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
4096
4097 fail:
4098 wpabuf_free(advproto);
4099 wpabuf_free(query);
4100
4101 return ret;
4102 }
4103
4104
4105 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
4106 size_t buflen)
4107 {
4108 u8 addr[ETH_ALEN];
4109 int dialog_token;
4110 int used;
4111 char *pos;
4112 size_t resp_len, start, requested_len;
4113
4114 if (!wpa_s->last_gas_resp)
4115 return -1;
4116
4117 used = hwaddr_aton2(cmd, addr);
4118 if (used < 0)
4119 return -1;
4120
4121 pos = cmd + used;
4122 while (*pos == ' ')
4123 pos++;
4124 dialog_token = atoi(pos);
4125
4126 if (os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) != 0 ||
4127 dialog_token != wpa_s->last_gas_dialog_token)
4128 return -1;
4129
4130 resp_len = wpabuf_len(wpa_s->last_gas_resp);
4131 start = 0;
4132 requested_len = resp_len;
4133
4134 pos = os_strchr(pos, ' ');
4135 if (pos) {
4136 start = atoi(pos);
4137 if (start > resp_len)
4138 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4139 pos = os_strchr(pos, ',');
4140 if (pos == NULL)
4141 return -1;
4142 pos++;
4143 requested_len = atoi(pos);
4144 if (start + requested_len > resp_len)
4145 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4146 }
4147
4148 if (requested_len * 2 + 1 > buflen)
4149 return os_snprintf(buf, buflen, "FAIL-Too long response");
4150
4151 return wpa_snprintf_hex(buf, buflen,
4152 wpabuf_head_u8(wpa_s->last_gas_resp) + start,
4153 requested_len);
4154 }
4155 #endif /* CONFIG_INTERWORKING */
4156
4157
4158 #ifdef CONFIG_HS20
4159
4160 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
4161 {
4162 u8 dst_addr[ETH_ALEN];
4163 int used;
4164 char *pos;
4165 u32 subtypes = 0;
4166
4167 used = hwaddr_aton2(dst, dst_addr);
4168 if (used < 0)
4169 return -1;
4170 pos = dst + used;
4171 for (;;) {
4172 int num = atoi(pos);
4173 if (num <= 0 || num > 31)
4174 return -1;
4175 subtypes |= BIT(num);
4176 pos = os_strchr(pos + 1, ',');
4177 if (pos == NULL)
4178 break;
4179 pos++;
4180 }
4181
4182 if (subtypes == 0)
4183 return -1;
4184
4185 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
4186 }
4187
4188
4189 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4190 const u8 *addr, const char *realm)
4191 {
4192 u8 *buf;
4193 size_t rlen, len;
4194 int ret;
4195
4196 rlen = os_strlen(realm);
4197 len = 3 + rlen;
4198 buf = os_malloc(len);
4199 if (buf == NULL)
4200 return -1;
4201 buf[0] = 1; /* NAI Home Realm Count */
4202 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
4203 buf[2] = rlen;
4204 os_memcpy(buf + 3, realm, rlen);
4205
4206 ret = hs20_anqp_send_req(wpa_s, addr,
4207 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
4208 buf, len);
4209
4210 os_free(buf);
4211
4212 return ret;
4213 }
4214
4215
4216 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4217 char *dst)
4218 {
4219 struct wpa_cred *cred = wpa_s->conf->cred;
4220 u8 dst_addr[ETH_ALEN];
4221 int used;
4222 u8 *buf;
4223 size_t len;
4224 int ret;
4225
4226 used = hwaddr_aton2(dst, dst_addr);
4227 if (used < 0)
4228 return -1;
4229
4230 while (dst[used] == ' ')
4231 used++;
4232 if (os_strncmp(dst + used, "realm=", 6) == 0)
4233 return hs20_nai_home_realm_list(wpa_s, dst_addr,
4234 dst + used + 6);
4235
4236 len = os_strlen(dst + used);
4237
4238 if (len == 0 && cred && cred->realm)
4239 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
4240
4241 if (len % 1)
4242 return -1;
4243 len /= 2;
4244 buf = os_malloc(len);
4245 if (buf == NULL)
4246 return -1;
4247 if (hexstr2bin(dst + used, buf, len) < 0) {
4248 os_free(buf);
4249 return -1;
4250 }
4251
4252 ret = hs20_anqp_send_req(wpa_s, dst_addr,
4253 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
4254 buf, len);
4255 os_free(buf);
4256
4257 return ret;
4258 }
4259
4260 #endif /* CONFIG_HS20 */
4261
4262
4263 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
4264 struct wpa_supplicant *wpa_s, char *cmd)
4265 {
4266 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
4267 return 0;
4268 }
4269
4270
4271 #ifdef CONFIG_AUTOSCAN
4272
4273 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
4274 char *cmd)
4275 {
4276 enum wpa_states state = wpa_s->wpa_state;
4277 char *new_params = NULL;
4278
4279 if (os_strlen(cmd) > 0) {
4280 new_params = os_strdup(cmd);
4281 if (new_params == NULL)
4282 return -1;
4283 }
4284
4285 os_free(wpa_s->conf->autoscan);
4286 wpa_s->conf->autoscan = new_params;
4287
4288 if (wpa_s->conf->autoscan == NULL)
4289 autoscan_deinit(wpa_s);
4290 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
4291 autoscan_init(wpa_s, 1);
4292 else if (state == WPA_SCANNING)
4293 wpa_supplicant_reinit_autoscan(wpa_s);
4294
4295 return 0;
4296 }
4297
4298 #endif /* CONFIG_AUTOSCAN */
4299
4300
4301 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
4302 size_t buflen)
4303 {
4304 struct wpa_signal_info si;
4305 int ret;
4306
4307 ret = wpa_drv_signal_poll(wpa_s, &si);
4308 if (ret)
4309 return -1;
4310
4311 ret = os_snprintf(buf, buflen, "RSSI=%d\nLINKSPEED=%d\n"
4312 "NOISE=%d\nFREQUENCY=%u\n",
4313 si.current_signal, si.current_txrate / 1000,
4314 si.current_noise, si.frequency);
4315 if (ret < 0 || (unsigned int) ret > buflen)
4316 return -1;
4317 return ret;
4318 }
4319
4320
4321 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
4322 char *buf, size_t *resp_len)
4323 {
4324 char *reply;
4325 const int reply_size = 4096;
4326 int ctrl_rsp = 0;
4327 int reply_len;
4328
4329 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
4330 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
4331 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
4332 (const u8 *) buf, os_strlen(buf));
4333 } else {
4334 int level = MSG_DEBUG;
4335 if (os_strcmp(buf, "PING") == 0)
4336 level = MSG_EXCESSIVE;
4337 wpa_hexdump_ascii(level, "RX ctrl_iface",
4338 (const u8 *) buf, os_strlen(buf));
4339 }
4340
4341 reply = os_malloc(reply_size);
4342 if (reply == NULL) {
4343 *resp_len = 1;
4344 return NULL;
4345 }
4346
4347 os_memcpy(reply, "OK\n", 3);
4348 reply_len = 3;
4349
4350 if (os_strcmp(buf, "PING") == 0) {
4351 os_memcpy(reply, "PONG\n", 5);
4352 reply_len = 5;
4353 } else if (os_strcmp(buf, "IFNAME") == 0) {
4354 reply_len = os_strlen(wpa_s->ifname);
4355 os_memcpy(reply, wpa_s->ifname, reply_len);
4356 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
4357 if (wpa_debug_reopen_file() < 0)
4358 reply_len = -1;
4359 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
4360 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
4361 } else if (os_strcmp(buf, "MIB") == 0) {
4362 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
4363 if (reply_len >= 0) {
4364 int res;
4365 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
4366 reply_size - reply_len);
4367 if (res < 0)
4368 reply_len = -1;
4369 else
4370 reply_len += res;
4371 }
4372 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
4373 reply_len = wpa_supplicant_ctrl_iface_status(
4374 wpa_s, buf + 6, reply, reply_size);
4375 } else if (os_strcmp(buf, "PMKSA") == 0) {
4376 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
4377 reply_size);
4378 } else if (os_strncmp(buf, "SET ", 4) == 0) {
4379 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
4380 reply_len = -1;
4381 } else if (os_strncmp(buf, "GET ", 4) == 0) {
4382 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
4383 reply, reply_size);
4384 } else if (os_strcmp(buf, "LOGON") == 0) {
4385 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
4386 } else if (os_strcmp(buf, "LOGOFF") == 0) {
4387 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
4388 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
4389 wpa_s->normal_scans = 0;
4390 wpa_supplicant_reinit_autoscan(wpa_s);
4391 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4392 reply_len = -1;
4393 else {
4394 wpa_s->disconnected = 0;
4395 wpa_s->reassociate = 1;
4396 wpa_supplicant_req_scan(wpa_s, 0, 0);
4397 }
4398 } else if (os_strcmp(buf, "RECONNECT") == 0) {
4399 wpa_s->normal_scans = 0;
4400 wpa_supplicant_reinit_autoscan(wpa_s);
4401 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4402 reply_len = -1;
4403 else if (wpa_s->disconnected) {
4404 wpa_s->disconnected = 0;
4405 wpa_s->reassociate = 1;
4406 wpa_supplicant_req_scan(wpa_s, 0, 0);
4407 }
4408 #ifdef IEEE8021X_EAPOL
4409 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
4410 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
4411 reply_len = -1;
4412 #endif /* IEEE8021X_EAPOL */
4413 #ifdef CONFIG_PEERKEY
4414 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
4415 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
4416 reply_len = -1;
4417 #endif /* CONFIG_PEERKEY */
4418 #ifdef CONFIG_IEEE80211R
4419 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
4420 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
4421 reply_len = -1;
4422 #endif /* CONFIG_IEEE80211R */
4423 #ifdef CONFIG_WPS
4424 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
4425 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
4426 if (res == -2) {
4427 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
4428 reply_len = 17;
4429 } else if (res)
4430 reply_len = -1;
4431 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
4432 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
4433 if (res == -2) {
4434 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
4435 reply_len = 17;
4436 } else if (res)
4437 reply_len = -1;
4438 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
4439 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
4440 reply,
4441 reply_size);
4442 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
4443 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
4444 wpa_s, buf + 14, reply, reply_size);
4445 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
4446 if (wpas_wps_cancel(wpa_s))
4447 reply_len = -1;
4448 #ifdef CONFIG_WPS_OOB
4449 } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
4450 if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8))
4451 reply_len = -1;
4452 #endif /* CONFIG_WPS_OOB */
4453 #ifdef CONFIG_WPS_NFC
4454 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
4455 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
4456 reply_len = -1;
4457 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
4458 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
4459 reply_len = -1;
4460 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
4461 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
4462 wpa_s, buf + 14, reply, reply_size);
4463 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
4464 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
4465 buf + 17))
4466 reply_len = -1;
4467 #endif /* CONFIG_WPS_NFC */
4468 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
4469 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
4470 reply_len = -1;
4471 #ifdef CONFIG_AP
4472 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
4473 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
4474 wpa_s, buf + 11, reply, reply_size);
4475 #endif /* CONFIG_AP */
4476 #ifdef CONFIG_WPS_ER
4477 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
4478 if (wpas_wps_er_start(wpa_s, NULL))
4479 reply_len = -1;
4480 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
4481 if (wpas_wps_er_start(wpa_s, buf + 13))
4482 reply_len = -1;
4483 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
4484 if (wpas_wps_er_stop(wpa_s))
4485 reply_len = -1;
4486 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
4487 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
4488 reply_len = -1;
4489 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
4490 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
4491 if (ret == -2) {
4492 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
4493 reply_len = 17;
4494 } else if (ret == -3) {
4495 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
4496 reply_len = 18;
4497 } else if (ret == -4) {
4498 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
4499 reply_len = 20;
4500 } else if (ret)
4501 reply_len = -1;
4502 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
4503 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
4504 reply_len = -1;
4505 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
4506 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
4507 buf + 18))
4508 reply_len = -1;
4509 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
4510 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
4511 reply_len = -1;
4512 #ifdef CONFIG_WPS_NFC
4513 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
4514 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
4515 wpa_s, buf + 24, reply, reply_size);
4516 #endif /* CONFIG_WPS_NFC */
4517 #endif /* CONFIG_WPS_ER */
4518 #endif /* CONFIG_WPS */
4519 #ifdef CONFIG_IBSS_RSN
4520 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
4521 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
4522 reply_len = -1;
4523 #endif /* CONFIG_IBSS_RSN */
4524 #ifdef CONFIG_P2P
4525 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
4526 if (p2p_ctrl_find(wpa_s, buf + 9))
4527 reply_len = -1;
4528 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
4529 if (p2p_ctrl_find(wpa_s, ""))
4530 reply_len = -1;
4531 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
4532 wpas_p2p_stop_find(wpa_s);
4533 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
4534 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
4535 reply_size);
4536 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
4537 if (p2p_ctrl_listen(wpa_s, buf + 11))
4538 reply_len = -1;
4539 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
4540 if (p2p_ctrl_listen(wpa_s, ""))
4541 reply_len = -1;
4542 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
4543 if (wpas_p2p_group_remove(wpa_s, buf + 17))
4544 reply_len = -1;
4545 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
4546 if (wpas_p2p_group_add(wpa_s, 0, 0, 0))
4547 reply_len = -1;
4548 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
4549 if (p2p_ctrl_group_add(wpa_s, buf + 14))
4550 reply_len = -1;
4551 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
4552 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
4553 reply_len = -1;
4554 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
4555 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
4556 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
4557 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
4558 reply_size);
4559 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
4560 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
4561 reply_len = -1;
4562 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
4563 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
4564 reply_len = -1;
4565 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
4566 wpas_p2p_sd_service_update(wpa_s);
4567 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
4568 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
4569 reply_len = -1;
4570 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
4571 wpas_p2p_service_flush(wpa_s);
4572 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
4573 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
4574 reply_len = -1;
4575 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
4576 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
4577 reply_len = -1;
4578 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
4579 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
4580 reply_len = -1;
4581 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
4582 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
4583 reply_len = -1;
4584 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
4585 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
4586 reply_size);
4587 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
4588 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
4589 reply_len = -1;
4590 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
4591 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4592 wpa_s->force_long_sd = 0;
4593 if (wpa_s->global->p2p)
4594 p2p_flush(wpa_s->global->p2p);
4595 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
4596 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
4597 reply_len = -1;
4598 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
4599 if (wpas_p2p_cancel(wpa_s))
4600 reply_len = -1;
4601 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
4602 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
4603 reply_len = -1;
4604 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
4605 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
4606 reply_len = -1;
4607 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
4608 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
4609 reply_len = -1;
4610 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
4611 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
4612 reply_len = -1;
4613 #endif /* CONFIG_P2P */
4614 #ifdef CONFIG_WIFI_DISPLAY
4615 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
4616 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
4617 reply_len = -1;
4618 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
4619 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
4620 reply, reply_size);
4621 #endif /* CONFIG_WIFI_DISPLAY */
4622 #ifdef CONFIG_INTERWORKING
4623 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
4624 if (interworking_fetch_anqp(wpa_s) < 0)
4625 reply_len = -1;
4626 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
4627 interworking_stop_fetch_anqp(wpa_s);
4628 } else if (os_strncmp(buf, "INTERWORKING_SELECT", 19) == 0) {
4629 if (interworking_select(wpa_s, os_strstr(buf + 19, "auto") !=
4630 NULL) < 0)
4631 reply_len = -1;
4632 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
4633 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
4634 reply_len = -1;
4635 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
4636 if (get_anqp(wpa_s, buf + 9) < 0)
4637 reply_len = -1;
4638 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
4639 if (gas_request(wpa_s, buf + 12) < 0)
4640 reply_len = -1;
4641 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
4642 reply_len = gas_response_get(wpa_s, buf + 17, reply,
4643 reply_size);
4644 #endif /* CONFIG_INTERWORKING */
4645 #ifdef CONFIG_HS20
4646 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
4647 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
4648 reply_len = -1;
4649 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
4650 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
4651 reply_len = -1;
4652 #endif /* CONFIG_HS20 */
4653 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
4654 {
4655 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
4656 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
4657 reply_len = -1;
4658 else
4659 ctrl_rsp = 1;
4660 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
4661 if (wpa_supplicant_reload_configuration(wpa_s))
4662 reply_len = -1;
4663 } else if (os_strcmp(buf, "TERMINATE") == 0) {
4664 wpa_supplicant_terminate_proc(wpa_s->global);
4665 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
4666 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
4667 reply_len = -1;
4668 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
4669 reply_len = wpa_supplicant_ctrl_iface_blacklist(
4670 wpa_s, buf + 9, reply, reply_size);
4671 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
4672 reply_len = wpa_supplicant_ctrl_iface_log_level(
4673 wpa_s, buf + 9, reply, reply_size);
4674 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
4675 reply_len = wpa_supplicant_ctrl_iface_list_networks(
4676 wpa_s, reply, reply_size);
4677 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
4678 #ifdef CONFIG_SME
4679 wpa_s->sme.prev_bssid_set = 0;
4680 #endif /* CONFIG_SME */
4681 wpa_s->reassociate = 0;
4682 wpa_s->disconnected = 1;
4683 wpa_supplicant_cancel_sched_scan(wpa_s);
4684 wpa_supplicant_cancel_scan(wpa_s);
4685 wpa_supplicant_deauthenticate(wpa_s,
4686 WLAN_REASON_DEAUTH_LEAVING);
4687 } else if (os_strcmp(buf, "SCAN") == 0) {
4688 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4689 reply_len = -1;
4690 else {
4691 if (!wpa_s->scanning &&
4692 ((wpa_s->wpa_state <= WPA_SCANNING) ||
4693 (wpa_s->wpa_state == WPA_COMPLETED))) {
4694 wpa_s->normal_scans = 0;
4695 wpa_s->scan_req = 2;
4696 wpa_supplicant_req_scan(wpa_s, 0, 0);
4697 } else if (wpa_s->sched_scanning) {
4698 wpa_printf(MSG_DEBUG, "Stop ongoing "
4699 "sched_scan to allow requested "
4700 "full scan to proceed");
4701 wpa_supplicant_cancel_sched_scan(wpa_s);
4702 wpa_s->scan_req = 2;
4703 wpa_supplicant_req_scan(wpa_s, 0, 0);
4704 } else {
4705 wpa_printf(MSG_DEBUG, "Ongoing scan action - "
4706 "reject new request");
4707 reply_len = os_snprintf(reply, reply_size,
4708 "FAIL-BUSY\n");
4709 }
4710 }
4711 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
4712 reply_len = wpa_supplicant_ctrl_iface_scan_results(
4713 wpa_s, reply, reply_size);
4714 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
4715 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
4716 reply_len = -1;
4717 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
4718 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
4719 reply_len = -1;
4720 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
4721 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
4722 reply_len = -1;
4723 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
4724 reply_len = wpa_supplicant_ctrl_iface_add_network(
4725 wpa_s, reply, reply_size);
4726 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
4727 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
4728 reply_len = -1;
4729 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
4730 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
4731 reply_len = -1;
4732 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
4733 reply_len = wpa_supplicant_ctrl_iface_get_network(
4734 wpa_s, buf + 12, reply, reply_size);
4735 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
4736 reply_len = wpa_supplicant_ctrl_iface_list_creds(
4737 wpa_s, reply, reply_size);
4738 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
4739 reply_len = wpa_supplicant_ctrl_iface_add_cred(
4740 wpa_s, reply, reply_size);
4741 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
4742 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
4743 reply_len = -1;
4744 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
4745 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
4746 reply_len = -1;
4747 #ifndef CONFIG_NO_CONFIG_WRITE
4748 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
4749 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
4750 reply_len = -1;
4751 #endif /* CONFIG_NO_CONFIG_WRITE */
4752 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
4753 reply_len = wpa_supplicant_ctrl_iface_get_capability(
4754 wpa_s, buf + 15, reply, reply_size);
4755 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
4756 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
4757 reply_len = -1;
4758 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
4759 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
4760 reply_len = -1;
4761 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
4762 reply_len = wpa_supplicant_global_iface_list(
4763 wpa_s->global, reply, reply_size);
4764 } else if (os_strcmp(buf, "INTERFACES") == 0) {
4765 reply_len = wpa_supplicant_global_iface_interfaces(
4766 wpa_s->global, reply, reply_size);
4767 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
4768 reply_len = wpa_supplicant_ctrl_iface_bss(
4769 wpa_s, buf + 4, reply, reply_size);
4770 #ifdef CONFIG_AP
4771 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
4772 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
4773 } else if (os_strncmp(buf, "STA ", 4) == 0) {
4774 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
4775 reply_size);
4776 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
4777 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
4778 reply_size);
4779 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
4780 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
4781 reply_len = -1;
4782 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
4783 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
4784 reply_len = -1;
4785 #endif /* CONFIG_AP */
4786 } else if (os_strcmp(buf, "SUSPEND") == 0) {
4787 wpas_notify_suspend(wpa_s->global);
4788 } else if (os_strcmp(buf, "RESUME") == 0) {
4789 wpas_notify_resume(wpa_s->global);
4790 } else if (os_strcmp(buf, "DROP_SA") == 0) {
4791 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
4792 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
4793 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
4794 reply_len = -1;
4795 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
4796 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
4797 reply_len = -1;
4798 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
4799 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
4800 reply_len = -1;
4801 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
4802 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
4803 buf + 17))
4804 reply_len = -1;
4805 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
4806 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
4807 reply_len = -1;
4808 #ifdef CONFIG_TDLS
4809 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
4810 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
4811 reply_len = -1;
4812 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
4813 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
4814 reply_len = -1;
4815 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
4816 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
4817 reply_len = -1;
4818 #endif /* CONFIG_TDLS */
4819 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
4820 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
4821 reply_size);
4822 #ifdef CONFIG_AUTOSCAN
4823 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
4824 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
4825 reply_len = -1;
4826 #endif /* CONFIG_AUTOSCAN */
4827 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
4828 eapol_sm_request_reauth(wpa_s->eapol);
4829 } else {
4830 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
4831 reply_len = 16;
4832 }
4833
4834 if (reply_len < 0) {
4835 os_memcpy(reply, "FAIL\n", 5);
4836 reply_len = 5;
4837 }
4838
4839 if (ctrl_rsp)
4840 eapol_sm_notify_ctrl_response(wpa_s->eapol);
4841
4842 *resp_len = reply_len;
4843 return reply;
4844 }
4845
4846
4847 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
4848 char *cmd)
4849 {
4850 struct wpa_interface iface;
4851 char *pos;
4852
4853 /*
4854 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
4855 * TAB<bridge_ifname>
4856 */
4857 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
4858
4859 os_memset(&iface, 0, sizeof(iface));
4860
4861 do {
4862 iface.ifname = pos = cmd;
4863 pos = os_strchr(pos, '\t');
4864 if (pos)
4865 *pos++ = '\0';
4866 if (iface.ifname[0] == '\0')
4867 return -1;
4868 if (pos == NULL)
4869 break;
4870
4871 iface.confname = pos;
4872 pos = os_strchr(pos, '\t');
4873 if (pos)
4874 *pos++ = '\0';
4875 if (iface.confname[0] == '\0')
4876 iface.confname = NULL;
4877 if (pos == NULL)
4878 break;
4879
4880 iface.driver = pos;
4881 pos = os_strchr(pos, '\t');
4882 if (pos)
4883 *pos++ = '\0';
4884 if (iface.driver[0] == '\0')
4885 iface.driver = NULL;
4886 if (pos == NULL)
4887 break;
4888
4889 iface.ctrl_interface = pos;
4890 pos = os_strchr(pos, '\t');
4891 if (pos)
4892 *pos++ = '\0';
4893 if (iface.ctrl_interface[0] == '\0')
4894 iface.ctrl_interface = NULL;
4895 if (pos == NULL)
4896 break;
4897
4898 iface.driver_param = pos;
4899 pos = os_strchr(pos, '\t');
4900 if (pos)
4901 *pos++ = '\0';
4902 if (iface.driver_param[0] == '\0')
4903 iface.driver_param = NULL;
4904 if (pos == NULL)
4905 break;
4906
4907 iface.bridge_ifname = pos;
4908 pos = os_strchr(pos, '\t');
4909 if (pos)
4910 *pos++ = '\0';
4911 if (iface.bridge_ifname[0] == '\0')
4912 iface.bridge_ifname = NULL;
4913 if (pos == NULL)
4914 break;
4915 } while (0);
4916
4917 if (wpa_supplicant_get_iface(global, iface.ifname))
4918 return -1;
4919
4920 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
4921 }
4922
4923
4924 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
4925 char *cmd)
4926 {
4927 struct wpa_supplicant *wpa_s;
4928
4929 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
4930
4931 wpa_s = wpa_supplicant_get_iface(global, cmd);
4932 if (wpa_s == NULL)
4933 return -1;
4934 return wpa_supplicant_remove_iface(global, wpa_s, 0);
4935 }
4936
4937
4938 static void wpa_free_iface_info(struct wpa_interface_info *iface)
4939 {
4940 struct wpa_interface_info *prev;
4941
4942 while (iface) {
4943 prev = iface;
4944 iface = iface->next;
4945
4946 os_free(prev->ifname);
4947 os_free(prev->desc);
4948 os_free(prev);
4949 }
4950 }
4951
4952
4953 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
4954 char *buf, int len)
4955 {
4956 int i, res;
4957 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
4958 char *pos, *end;
4959
4960 for (i = 0; wpa_drivers[i]; i++) {
4961 struct wpa_driver_ops *drv = wpa_drivers[i];
4962 if (drv->get_interfaces == NULL)
4963 continue;
4964 tmp = drv->get_interfaces(global->drv_priv[i]);
4965 if (tmp == NULL)
4966 continue;
4967
4968 if (last == NULL)
4969 iface = last = tmp;
4970 else
4971 last->next = tmp;
4972 while (last->next)
4973 last = last->next;
4974 }
4975
4976 pos = buf;
4977 end = buf + len;
4978 for (tmp = iface; tmp; tmp = tmp->next) {
4979 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
4980 tmp->drv_name, tmp->ifname,
4981 tmp->desc ? tmp->desc : "");
4982 if (res < 0 || res >= end - pos) {
4983 *pos = '\0';
4984 break;
4985 }
4986 pos += res;
4987 }
4988
4989 wpa_free_iface_info(iface);
4990
4991 return pos - buf;
4992 }
4993
4994
4995 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
4996 char *buf, int len)
4997 {
4998 int res;
4999 char *pos, *end;
5000 struct wpa_supplicant *wpa_s;
5001
5002 wpa_s = global->ifaces;
5003 pos = buf;
5004 end = buf + len;
5005
5006 while (wpa_s) {
5007 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
5008 if (res < 0 || res >= end - pos) {
5009 *pos = '\0';
5010 break;
5011 }
5012 pos += res;
5013 wpa_s = wpa_s->next;
5014 }
5015 return pos - buf;
5016 }
5017
5018
5019 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
5020 char *buf, size_t *resp_len)
5021 {
5022 char *reply;
5023 const int reply_size = 2048;
5024 int reply_len;
5025 int level = MSG_DEBUG;
5026
5027 if (os_strcmp(buf, "PING") == 0)
5028 level = MSG_EXCESSIVE;
5029 wpa_hexdump_ascii(level, "RX global ctrl_iface",
5030 (const u8 *) buf, os_strlen(buf));
5031
5032 reply = os_malloc(reply_size);
5033 if (reply == NULL) {
5034 *resp_len = 1;
5035 return NULL;
5036 }
5037
5038 os_memcpy(reply, "OK\n", 3);
5039 reply_len = 3;
5040
5041 if (os_strcmp(buf, "PING") == 0) {
5042 os_memcpy(reply, "PONG\n", 5);
5043 reply_len = 5;
5044 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
5045 if (wpa_supplicant_global_iface_add(global, buf + 14))
5046 reply_len = -1;
5047 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
5048 if (wpa_supplicant_global_iface_remove(global, buf + 17))
5049 reply_len = -1;
5050 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
5051 reply_len = wpa_supplicant_global_iface_list(
5052 global, reply, reply_size);
5053 } else if (os_strcmp(buf, "INTERFACES") == 0) {
5054 reply_len = wpa_supplicant_global_iface_interfaces(
5055 global, reply, reply_size);
5056 } else if (os_strcmp(buf, "TERMINATE") == 0) {
5057 wpa_supplicant_terminate_proc(global);
5058 } else if (os_strcmp(buf, "SUSPEND") == 0) {
5059 wpas_notify_suspend(global);
5060 } else if (os_strcmp(buf, "RESUME") == 0) {
5061 wpas_notify_resume(global);
5062 } else {
5063 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
5064 reply_len = 16;
5065 }
5066
5067 if (reply_len < 0) {
5068 os_memcpy(reply, "FAIL\n", 5);
5069 reply_len = 5;
5070 }
5071
5072 *resp_len = reply_len;
5073 return reply;
5074 }