1 /*
2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2024, 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 #ifdef CONFIG_TESTING_OPTIONS
11 #include <netinet/ip.h>
12 #endif /* CONFIG_TESTING_OPTIONS */
13
14 #include "utils/common.h"
15 #include "utils/eloop.h"
16 #include "utils/uuid.h"
17 #include "utils/module_tests.h"
18 #include "common/version.h"
19 #include "common/ieee802_11_defs.h"
20 #include "common/ieee802_11_common.h"
21 #include "common/wpa_ctrl.h"
22 #ifdef CONFIG_DPP
23 #include "common/dpp.h"
24 #endif /* CONFIG_DPP */
25 #include "common/nan_de.h"
26 #include "common/ptksa_cache.h"
27 #include "crypto/tls.h"
28 #include "ap/hostapd.h"
29 #include "eap_peer/eap.h"
30 #include "eapol_supp/eapol_supp_sm.h"
31 #include "rsn_supp/wpa.h"
32 #include "rsn_supp/preauth.h"
33 #include "rsn_supp/pmksa_cache.h"
34 #include "l2_packet/l2_packet.h"
35 #include "wps/wps.h"
36 #include "fst/fst.h"
37 #include "fst/fst_ctrl_iface.h"
38 #include "config.h"
39 #include "wpa_supplicant_i.h"
40 #include "driver_i.h"
41 #include "wps_supplicant.h"
42 #include "ibss_rsn.h"
43 #include "wpas_glue.h"
44 #include "ap.h"
45 #include "p2p_supplicant.h"
46 #include "p2p/p2p.h"
47 #include "hs20_supplicant.h"
48 #include "wifi_display.h"
49 #include "notify.h"
50 #include "bss.h"
51 #include "scan.h"
52 #include "ctrl_iface.h"
53 #include "interworking.h"
54 #include "bssid_ignore.h"
55 #include "autoscan.h"
56 #include "wnm_sta.h"
57 #include "offchannel.h"
58 #include "drivers/driver.h"
59 #include "mesh.h"
60 #include "dpp_supplicant.h"
61 #include "sme.h"
62 #include "nan_usd.h"
63 #ifdef CONFIG_MAGICLINK
64 #include "wpa_magiclink.h"
65 #endif
66 #ifdef CONFIG_VENDOR_EXT
67 #include "vendor_ext.h"
68 #endif
69 #ifdef CONFIG_WAPI
70 #include "wapi_asue_i.h"
71 #endif
72 #ifdef CONFIG_WIFI_RPT
73 #include "p2p/p2p_i.h"
74 #include "wifi_rpt.h"
75 #endif
76
77 #ifdef CONFIG_DRIVER_NL80211_HISI
78 #include "driver_nl80211.h"
79 #endif
80
81 #ifdef CONFIG_OPEN_HARMONY_PATCH
82 #include "p2p/p2p_i.h"
83 #ifdef OPEN_HARMONY_MIRACAST_SINK_OPT
84 #include "hm_miracast_sink.h"
85 #endif
86 #endif
87 #ifdef OPEN_HARMONY_P2P_ONEHOP_FIND
88 #include "p2p_onehop_scan_opt.h"
89 #endif
90
91 #ifdef __NetBSD__
92 #include <net/if_ether.h>
93 #elif !defined(__CYGWIN__) && !defined(CONFIG_NATIVE_WINDOWS)
94 #include <net/ethernet.h>
95 #endif
96
97 #if defined(CONFIG_OPEN_HARMONY_PATCH) && defined(CONFIG_HILINK_OKC_STA)
98 #include "securec.h"
99 #include "hilink_okc.h"
100 #endif
101 #define P2P_160M_MASK 0x08000000
102 #define DISCOVER_TIMEOUT_S 120
103 #define DISCOVER_CHANNELID 20000
104 #define KBPS_OF_MBPS 1000
105
106 #ifdef CONFIG_WIFI_RPT
107 #define DEDAULT_RPT_ID -3
108 #endif
109
110 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
111 char *buf, int len);
112 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
113 const char *input,
114 char *buf, int len);
115 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
116 char *val);
117
118
set_bssid_filter(struct wpa_supplicant * wpa_s,char * val)119 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
120 {
121 char *pos;
122 u8 addr[ETH_ALEN], *filter = NULL, *n;
123 size_t count = 0;
124
125 pos = val;
126 while (pos) {
127 if (*pos == '\0')
128 break;
129 if (hwaddr_aton(pos, addr)) {
130 os_free(filter);
131 return -1;
132 }
133 n = os_realloc_array(filter, count + 1, ETH_ALEN);
134 if (n == NULL) {
135 os_free(filter);
136 return -1;
137 }
138 filter = n;
139 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
140 count++;
141
142 pos = os_strchr(pos, ' ');
143 if (pos)
144 pos++;
145 }
146
147 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
148 os_free(wpa_s->bssid_filter);
149 wpa_s->bssid_filter = filter;
150 wpa_s->bssid_filter_count = count;
151
152 return 0;
153 }
154
155
set_disallow_aps(struct wpa_supplicant * wpa_s,char * val)156 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
157 {
158 char *pos;
159 u8 addr[ETH_ALEN], *bssid = NULL, *n;
160 struct wpa_ssid_value *ssid = NULL, *ns;
161 size_t count = 0, ssid_count = 0;
162 struct wpa_ssid *c;
163
164 /*
165 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
166 * SSID_SPEC ::= ssid <SSID_HEX>
167 * BSSID_SPEC ::= bssid <BSSID_HEX>
168 */
169
170 pos = val;
171 while (pos) {
172 if (*pos == '\0')
173 break;
174 if (os_strncmp(pos, "bssid ", 6) == 0) {
175 int res;
176 pos += 6;
177 res = hwaddr_aton2(pos, addr);
178 if (res < 0) {
179 os_free(ssid);
180 os_free(bssid);
181 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
182 "BSSID value '%s'", pos);
183 return -1;
184 }
185 pos += res;
186 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
187 if (n == NULL) {
188 os_free(ssid);
189 os_free(bssid);
190 return -1;
191 }
192 bssid = n;
193 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
194 count++;
195 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
196 char *end;
197 pos += 5;
198
199 end = pos;
200 while (*end) {
201 if (*end == '\0' || *end == ' ')
202 break;
203 end++;
204 }
205
206 ns = os_realloc_array(ssid, ssid_count + 1,
207 sizeof(struct wpa_ssid_value));
208 if (ns == NULL) {
209 os_free(ssid);
210 os_free(bssid);
211 return -1;
212 }
213 ssid = ns;
214
215 if ((end - pos) & 0x01 ||
216 end - pos > 2 * SSID_MAX_LEN ||
217 hexstr2bin(pos, ssid[ssid_count].ssid,
218 (end - pos) / 2) < 0) {
219 os_free(ssid);
220 os_free(bssid);
221 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
222 "SSID value '%s'", pos);
223 return -1;
224 }
225 ssid[ssid_count].ssid_len = (end - pos) / 2;
226 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
227 ssid[ssid_count].ssid,
228 ssid[ssid_count].ssid_len);
229 ssid_count++;
230 pos = end;
231 } else {
232 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
233 "'%s'", pos);
234 os_free(ssid);
235 os_free(bssid);
236 return -1;
237 }
238
239 pos = os_strchr(pos, ' ');
240 if (pos)
241 pos++;
242 }
243
244 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
245 os_free(wpa_s->disallow_aps_bssid);
246 wpa_s->disallow_aps_bssid = bssid;
247 wpa_s->disallow_aps_bssid_count = count;
248
249 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
250 os_free(wpa_s->disallow_aps_ssid);
251 wpa_s->disallow_aps_ssid = ssid;
252 wpa_s->disallow_aps_ssid_count = ssid_count;
253
254 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
255 return 0;
256
257 c = wpa_s->current_ssid;
258 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
259 return 0;
260
261 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
262 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
263 return 0;
264
265 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
266 "because current AP was marked disallowed");
267
268 #ifdef CONFIG_SME
269 wpa_s->sme.prev_bssid_set = 0;
270 #endif /* CONFIG_SME */
271 wpa_s->reassociate = 1;
272 wpa_s->own_disconnect_req = 1;
273 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
274 wpa_supplicant_req_scan(wpa_s, 0, 0);
275
276 return 0;
277 }
278
279
280 #ifndef CONFIG_NO_CONFIG_BLOBS
wpas_ctrl_set_blob(struct wpa_supplicant * wpa_s,char * pos)281 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
282 {
283 char *name = pos;
284 struct wpa_config_blob *blob;
285 size_t len;
286
287 pos = os_strchr(pos, ' ');
288 if (pos == NULL)
289 return -1;
290 *pos++ = '\0';
291 len = os_strlen(pos);
292 if (len & 1)
293 return -1;
294
295 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
296 blob = os_zalloc(sizeof(*blob));
297 if (blob == NULL)
298 return -1;
299 blob->name = os_strdup(name);
300 blob->data = os_malloc(len / 2);
301 if (blob->name == NULL || blob->data == NULL) {
302 wpa_config_free_blob(blob);
303 return -1;
304 }
305
306 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
307 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
308 wpa_config_free_blob(blob);
309 return -1;
310 }
311 blob->len = len / 2;
312
313 wpa_config_set_blob(wpa_s->conf, blob);
314
315 return 0;
316 }
317 #endif /* CONFIG_NO_CONFIG_BLOBS */
318
319
wpas_ctrl_pno(struct wpa_supplicant * wpa_s,char * cmd)320 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
321 {
322 char *params;
323 char *pos;
324 int *freqs = NULL;
325 int ret;
326 wpa_printf(MSG_INFO, "%s: %s", __func__, cmd);
327 if (atoi(cmd)) {
328 params = os_strchr(cmd, ' ');
329 os_free(wpa_s->manual_sched_scan_freqs);
330 if (params) {
331 params++;
332 pos = os_strstr(params, "freq=");
333 if (pos)
334 freqs = freq_range_to_channel_list(wpa_s,
335 pos + 5);
336 }
337 wpa_s->manual_sched_scan_freqs = freqs;
338 ret = wpas_start_pno(wpa_s);
339 } else {
340 ret = wpas_stop_pno(wpa_s);
341 }
342 return ret;
343 }
344
345
wpas_ctrl_set_band(struct wpa_supplicant * wpa_s,char * bands)346 static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *bands)
347 {
348 union wpa_event_data event;
349 u32 setband_mask = WPA_SETBAND_AUTO;
350
351 /*
352 * For example:
353 * SET setband 2G,6G
354 * SET setband 5G
355 * SET setband AUTO
356 */
357 if (!os_strstr(bands, "AUTO")) {
358 if (os_strstr(bands, "5G"))
359 setband_mask |= WPA_SETBAND_5G;
360 if (os_strstr(bands, "6G"))
361 setband_mask |= WPA_SETBAND_6G;
362 if (os_strstr(bands, "2G"))
363 setband_mask |= WPA_SETBAND_2G;
364 if (setband_mask == WPA_SETBAND_AUTO)
365 return -1;
366 }
367
368 wpa_s->setband_mask = setband_mask;
369 if (wpa_drv_setband(wpa_s, wpa_s->setband_mask) == 0) {
370 os_memset(&event, 0, sizeof(event));
371 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
372 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
373 wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
374 }
375
376 return 0;
377 }
378
379
wpas_ctrl_iface_set_lci(struct wpa_supplicant * wpa_s,const char * cmd)380 static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s,
381 const char *cmd)
382 {
383 struct wpabuf *lci;
384
385 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
386 wpabuf_free(wpa_s->lci);
387 wpa_s->lci = NULL;
388 return 0;
389 }
390
391 lci = wpabuf_parse_bin(cmd);
392 if (!lci)
393 return -1;
394
395 if (os_get_reltime(&wpa_s->lci_time)) {
396 wpabuf_free(lci);
397 return -1;
398 }
399
400 wpabuf_free(wpa_s->lci);
401 wpa_s->lci = lci;
402
403 return 0;
404 }
405
406
407 static int
wpas_ctrl_set_relative_rssi(struct wpa_supplicant * wpa_s,const char * cmd)408 wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd)
409 {
410 int relative_rssi;
411
412 if (os_strcmp(cmd, "disable") == 0) {
413 wpa_s->srp.relative_rssi_set = 0;
414 return 0;
415 }
416
417 relative_rssi = atoi(cmd);
418 if (relative_rssi < 0 || relative_rssi > 100)
419 return -1;
420 wpa_s->srp.relative_rssi = relative_rssi;
421 wpa_s->srp.relative_rssi_set = 1;
422 return 0;
423 }
424
425
wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant * wpa_s,const char * cmd)426 static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s,
427 const char *cmd)
428 {
429 char *pos;
430 int adjust_rssi;
431
432 /* <band>:adjust_value */
433 pos = os_strchr(cmd, ':');
434 if (!pos)
435 return -1;
436 pos++;
437 adjust_rssi = atoi(pos);
438 if (adjust_rssi < -100 || adjust_rssi > 100)
439 return -1;
440
441 if (os_strncmp(cmd, "2G", 2) == 0)
442 wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G;
443 else if (os_strncmp(cmd, "5G", 2) == 0)
444 wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G;
445 else
446 return -1;
447
448 wpa_s->srp.relative_adjust_rssi = adjust_rssi;
449
450 return 0;
451 }
452
453
wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant * wpa_s,const char * cmd)454 static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s,
455 const char *cmd)
456 {
457 struct wpabuf *ric_ies;
458
459 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
460 wpabuf_free(wpa_s->ric_ies);
461 wpa_s->ric_ies = NULL;
462 return 0;
463 }
464
465 ric_ies = wpabuf_parse_bin(cmd);
466 if (!ric_ies)
467 return -1;
468
469 wpabuf_free(wpa_s->ric_ies);
470 wpa_s->ric_ies = ric_ies;
471
472 return 0;
473 }
474
475
476 #ifdef CONFIG_TESTING_OPTIONS
wpas_ctrl_iface_set_dso(struct wpa_supplicant * wpa_s,const char * val)477 static int wpas_ctrl_iface_set_dso(struct wpa_supplicant *wpa_s,
478 const char *val)
479 {
480 u8 bssid[ETH_ALEN];
481 const char *pos = val;
482 struct driver_signal_override *dso = NULL, *tmp, parsed;
483
484 if (hwaddr_aton(pos, bssid))
485 return -1;
486 pos = os_strchr(pos, ' ');
487
488 dl_list_for_each(tmp, &wpa_s->drv_signal_override,
489 struct driver_signal_override, list) {
490 if (ether_addr_equal(bssid, tmp->bssid)) {
491 dso = tmp;
492 break;
493 }
494 }
495
496 if (!pos) {
497 /* Remove existing entry */
498 if (dso) {
499 dl_list_del(&dso->list);
500 os_free(dso);
501 }
502 return 0;
503 }
504 pos++;
505
506 /* Update an existing entry or add a new one */
507 os_memset(&parsed, 0, sizeof(parsed));
508 if (sscanf(pos, "%d %d %d %d %d",
509 &parsed.si_current_signal,
510 &parsed.si_avg_signal,
511 &parsed.si_avg_beacon_signal,
512 &parsed.si_current_noise,
513 &parsed.scan_level) != 5)
514 return -1;
515
516 if (!dso) {
517 dso = os_zalloc(sizeof(*dso));
518 if (!dso)
519 return -1;
520 os_memcpy(dso->bssid, bssid, ETH_ALEN);
521 dl_list_add(&wpa_s->drv_signal_override, &dso->list);
522 }
523 dso->si_current_signal = parsed.si_current_signal;
524 dso->si_avg_signal = parsed.si_avg_signal;
525 dso->si_avg_beacon_signal = parsed.si_avg_beacon_signal;
526 dso->si_current_noise = parsed.si_current_noise;
527 dso->scan_level = parsed.scan_level;
528
529 return 0;
530 }
531 #endif /* CONFIG_TESTING_OPTIONS */
532
533
wpa_supplicant_ctrl_iface_set(struct wpa_supplicant * wpa_s,char * cmd)534 int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
535 char *cmd)
536 {
537 char *value;
538 int ret = 0;
539 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET %s", get_anonymized_result_for_set(cmd));
540 value = os_strchr(cmd, ' ');
541 if (value == NULL)
542 return -1;
543 *value++ = '\0';
544
545 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
546 eapol_sm_configure(wpa_s->eapol,
547 StrtoInt(value), -1, -1, -1);
548 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
549 eapol_sm_configure(wpa_s->eapol,
550 -1, StrtoInt(value), -1, -1);
551 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
552 eapol_sm_configure(wpa_s->eapol,
553 -1, -1, StrtoInt(value), -1);
554 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
555 eapol_sm_configure(wpa_s->eapol,
556 -1, -1, -1, StrtoInt(value));
557 #ifdef CONFIG_TESTING_OPTIONS
558 } else if (os_strcasecmp(cmd, "EAPOL::portControl") == 0) {
559 if (os_strcmp(value, "Auto") == 0)
560 eapol_sm_notify_portControl(wpa_s->eapol, Auto);
561 else if (os_strcmp(value, "ForceUnauthorized") == 0)
562 eapol_sm_notify_portControl(wpa_s->eapol,
563 ForceUnauthorized);
564 else if (os_strcmp(value, "ForceAuthorized") == 0)
565 eapol_sm_notify_portControl(wpa_s->eapol,
566 ForceAuthorized);
567 else
568 ret = -1;
569 #endif /* CONFIG_TESTING_OPTIONS */
570 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
571 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
572 StrtoUint(value))) {
573 ret = -1;
574 } else {
575 value[-1] = '=';
576 wpa_config_process_global(wpa_s->conf, cmd, -1);
577 }
578 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
579 0) {
580 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
581 StrtoUint(value))) {
582 ret = -1;
583 } else {
584 value[-1] = '=';
585 wpa_config_process_global(wpa_s->conf, cmd, -1);
586 }
587 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
588 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
589 StrtoUint(value))) {
590 ret = -1;
591 } else {
592 value[-1] = '=';
593 wpa_config_process_global(wpa_s->conf, cmd, -1);
594 }
595 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
596 wpa_s->wps_fragment_size = StrtoInt(value);
597 #ifdef CONFIG_WPS_TESTING
598 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
599 long int val;
600 val = strtol(value, NULL, 0);
601 if (val < 0 || val > 0xff) {
602 ret = -1;
603 wpa_printf(MSG_DEBUG, "WPS: Invalid "
604 "wps_version_number %ld", val);
605 } else {
606 wps_version_number = val;
607 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
608 "version %u.%u",
609 (wps_version_number & 0xf0) >> 4,
610 wps_version_number & 0x0f);
611 }
612 } else if (os_strcasecmp(cmd, "wps_testing_stub_cred") == 0) {
613 wps_testing_stub_cred = atoi(value);
614 wpa_printf(MSG_DEBUG, "WPS: Testing - stub_cred=%d",
615 wps_testing_stub_cred);
616 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
617 wps_corrupt_pkhash = atoi(value);
618 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
619 wps_corrupt_pkhash);
620 } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
621 if (value[0] == '\0') {
622 wps_force_auth_types_in_use = 0;
623 } else {
624 wps_force_auth_types = strtol(value, NULL, 0);
625 wps_force_auth_types_in_use = 1;
626 }
627 } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
628 if (value[0] == '\0') {
629 wps_force_encr_types_in_use = 0;
630 } else {
631 wps_force_encr_types = strtol(value, NULL, 0);
632 wps_force_encr_types_in_use = 1;
633 }
634 #endif /* CONFIG_WPS_TESTING */
635 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
636 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
637 ret = -1;
638 #ifdef CONFIG_TDLS
639 #ifdef CONFIG_TDLS_TESTING
640 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
641 tdls_testing = strtol(value, NULL, 0);
642 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
643 #endif /* CONFIG_TDLS_TESTING */
644 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
645 int disabled = StrtoInt(value);
646 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
647 if (disabled) {
648 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
649 ret = -1;
650 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
651 ret = -1;
652 wpa_tdls_enable(wpa_s->wpa, !disabled);
653 #endif /* CONFIG_TDLS */
654 } else if (os_strcasecmp(cmd, "pno") == 0) {
655 ret = wpas_ctrl_pno(wpa_s, value);
656 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
657 int disabled = StrtoInt(value);
658 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
659 ret = -1;
660 else if (disabled)
661 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
662 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
663 if (os_strcmp(value, "disable") == 0)
664 wpa_s->set_sta_uapsd = 0;
665 else {
666 int be, bk, vi, vo;
667 char *pos;
668 /* format: BE,BK,VI,VO;max SP Length */
669 be = atoi(value);
670 pos = os_strchr(value, ',');
671 if (pos == NULL)
672 return -1;
673 pos++;
674 bk = atoi(pos);
675 pos = os_strchr(pos, ',');
676 if (pos == NULL)
677 return -1;
678 pos++;
679 vi = atoi(pos);
680 pos = os_strchr(pos, ',');
681 if (pos == NULL)
682 return -1;
683 pos++;
684 vo = atoi(pos);
685 /* ignore max SP Length for now */
686
687 wpa_s->set_sta_uapsd = 1;
688 wpa_s->sta_uapsd = 0;
689 if (be)
690 wpa_s->sta_uapsd |= BIT(0);
691 if (bk)
692 wpa_s->sta_uapsd |= BIT(1);
693 if (vi)
694 wpa_s->sta_uapsd |= BIT(2);
695 if (vo)
696 wpa_s->sta_uapsd |= BIT(3);
697 }
698 } else if (os_strcasecmp(cmd, "ps") == 0) {
699 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
700 #ifdef CONFIG_WIFI_DISPLAY
701 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
702 int enabled = !!atoi(value);
703 if (enabled && !wpa_s->global->p2p)
704 ret = -1;
705 else
706 wifi_display_enable(wpa_s->global, enabled);
707 #endif /* CONFIG_WIFI_DISPLAY */
708 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
709 ret = set_bssid_filter(wpa_s, value);
710 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
711 ret = set_disallow_aps(wpa_s, value);
712 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
713 wpa_s->no_keep_alive = !!atoi(value);
714 #ifdef CONFIG_DPP
715 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
716 os_free(wpa_s->dpp_configurator_params);
717 wpa_s->dpp_configurator_params = os_strdup(value);
718 #ifdef CONFIG_DPP2
719 dpp_controller_set_params(wpa_s->dpp, value);
720 #endif /* CONFIG_DPP2 */
721 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
722 wpa_s->dpp_init_max_tries = atoi(value);
723 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
724 wpa_s->dpp_init_retry_time = atoi(value);
725 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
726 wpa_s->dpp_resp_wait_time = atoi(value);
727 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
728 wpa_s->dpp_resp_max_tries = atoi(value);
729 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
730 wpa_s->dpp_resp_retry_time = atoi(value);
731 #ifdef CONFIG_TESTING_OPTIONS
732 } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
733 if (hwaddr_aton(value, dpp_pkex_own_mac_override))
734 ret = -1;
735 } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
736 if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
737 ret = -1;
738 } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
739 size_t hex_len = os_strlen(value);
740
741 if (hex_len >
742 2 * sizeof(dpp_pkex_ephemeral_key_override))
743 ret = -1;
744 else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
745 hex_len / 2))
746 ret = -1;
747 else
748 dpp_pkex_ephemeral_key_override_len = hex_len / 2;
749 } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) {
750 size_t hex_len = os_strlen(value);
751
752 if (hex_len > 2 * sizeof(dpp_protocol_key_override))
753 ret = -1;
754 else if (hexstr2bin(value, dpp_protocol_key_override,
755 hex_len / 2))
756 ret = -1;
757 else
758 dpp_protocol_key_override_len = hex_len / 2;
759 } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) {
760 size_t hex_len = os_strlen(value);
761
762 if (hex_len > 2 * sizeof(dpp_nonce_override))
763 ret = -1;
764 else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2))
765 ret = -1;
766 else
767 dpp_nonce_override_len = hex_len / 2;
768 } else if (os_strcasecmp(cmd, "dpp_version_override") == 0) {
769 dpp_version_override = atoi(value);
770 #endif /* CONFIG_TESTING_OPTIONS */
771 #endif /* CONFIG_DPP */
772 #ifdef CONFIG_TESTING_OPTIONS
773 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
774 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
775 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
776 wpa_s->ext_eapol_frame_io = !!atoi(value);
777 #ifdef CONFIG_AP
778 if (wpa_s->ap_iface) {
779 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
780 wpa_s->ext_eapol_frame_io;
781 }
782 #endif /* CONFIG_AP */
783 } else if (os_strcasecmp(cmd, "encrypt_eapol_m2") == 0) {
784 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ENCRYPT_EAPOL_M2,
785 !!atoi(value));
786 } else if (os_strcasecmp(cmd, "encrypt_eapol_m4") == 0) {
787 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ENCRYPT_EAPOL_M4,
788 !!atoi(value));
789 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
790 wpa_s->extra_roc_dur = atoi(value);
791 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
792 wpa_s->test_failure = atoi(value);
793 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
794 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
795 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
796 wpa_s->ignore_auth_resp = !!atoi(value);
797 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
798 wpa_s->ignore_assoc_disallow = !!atoi(value);
799 wpa_drv_ignore_assoc_disallow(wpa_s,
800 wpa_s->ignore_assoc_disallow);
801 } else if (os_strcasecmp(cmd, "disable_sa_query") == 0) {
802 wpa_s->disable_sa_query = !!atoi(value);
803 } else if (os_strcasecmp(cmd, "ignore_sae_h2e_only") == 0) {
804 wpa_s->ignore_sae_h2e_only = !!atoi(value);
805 } else if (os_strcasecmp(cmd, "extra_sae_rejected_groups") == 0) {
806 char *pos;
807
808 os_free(wpa_s->extra_sae_rejected_groups);
809 wpa_s->extra_sae_rejected_groups = NULL;
810 pos = value;
811 while (pos && pos[0]) {
812 int group;
813
814 group = atoi(pos);
815 wpa_printf(MSG_DEBUG,
816 "TESTING: Extra rejection of SAE group %d",
817 group);
818 if (group)
819 int_array_add_unique(
820 &wpa_s->extra_sae_rejected_groups,
821 group);
822 pos = os_strchr(pos, ' ');
823 if (!pos)
824 break;
825 pos++;
826 }
827 } else if (os_strcasecmp(cmd, "ft_rsnxe_used") == 0) {
828 wpa_s->ft_rsnxe_used = atoi(value);
829 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol") == 0) {
830 wpa_s->oci_freq_override_eapol = atoi(value);
831 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_req") == 0) {
832 wpa_s->oci_freq_override_saquery_req = atoi(value);
833 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_resp") == 0) {
834 wpa_s->oci_freq_override_saquery_resp = atoi(value);
835 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol_g2") == 0) {
836 wpa_s->oci_freq_override_eapol_g2 = atoi(value);
837 /* Populate value to wpa_sm if already associated. */
838 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_EAPOL_G2,
839 wpa_s->oci_freq_override_eapol_g2);
840 } else if (os_strcasecmp(cmd, "oci_freq_override_ft_assoc") == 0) {
841 wpa_s->oci_freq_override_ft_assoc = atoi(value);
842 /* Populate value to wpa_sm if already associated. */
843 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_FT_ASSOC,
844 wpa_s->oci_freq_override_ft_assoc);
845 } else if (os_strcasecmp(cmd, "oci_freq_override_fils_assoc") == 0) {
846 wpa_s->oci_freq_override_fils_assoc = atoi(value);
847 } else if (os_strcasecmp(cmd, "oci_freq_override_wnm_sleep") == 0) {
848 wpa_s->oci_freq_override_wnm_sleep = atoi(value);
849 } else if (os_strcasecmp(cmd, "rsne_override_eapol") == 0) {
850 wpabuf_free(wpa_s->rsne_override_eapol);
851 if (os_strcmp(value, "NULL") == 0)
852 wpa_s->rsne_override_eapol = NULL;
853 else
854 wpa_s->rsne_override_eapol = wpabuf_parse_bin(value);
855 } else if (os_strcasecmp(cmd, "rsnxe_override_assoc") == 0) {
856 wpabuf_free(wpa_s->rsnxe_override_assoc);
857 if (os_strcmp(value, "NULL") == 0)
858 wpa_s->rsnxe_override_assoc = NULL;
859 else
860 wpa_s->rsnxe_override_assoc = wpabuf_parse_bin(value);
861 } else if (os_strcasecmp(cmd, "rsnxe_override_eapol") == 0) {
862 wpabuf_free(wpa_s->rsnxe_override_eapol);
863 if (os_strcmp(value, "NULL") == 0)
864 wpa_s->rsnxe_override_eapol = NULL;
865 else
866 wpa_s->rsnxe_override_eapol = wpabuf_parse_bin(value);
867 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
868 wpa_s->reject_btm_req_reason = atoi(value);
869 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
870 os_free(wpa_s->get_pref_freq_list_override);
871 if (!value[0])
872 wpa_s->get_pref_freq_list_override = NULL;
873 else
874 wpa_s->get_pref_freq_list_override = os_strdup(value);
875 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
876 wpabuf_free(wpa_s->sae_commit_override);
877 if (value[0] == '\0')
878 wpa_s->sae_commit_override = NULL;
879 else
880 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
881 } else if (os_strcasecmp(cmd, "driver_signal_override") == 0) {
882 ret = wpas_ctrl_iface_set_dso(wpa_s, value);
883 #ifndef CONFIG_NO_ROBUST_AV
884 } else if (os_strcasecmp(cmd, "disable_scs_support") == 0) {
885 wpa_s->disable_scs_support = !!atoi(value);
886 } else if (os_strcasecmp(cmd, "disable_mscs_support") == 0) {
887 wpa_s->disable_mscs_support = !!atoi(value);
888 #endif /* CONFIG_NO_ROBUST_AV */
889 } else if (os_strcasecmp(cmd, "disable_eapol_g2_tx") == 0) {
890 wpa_s->disable_eapol_g2_tx = !!atoi(value);
891 /* Populate value to wpa_sm if already associated. */
892 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DISABLE_EAPOL_G2_TX,
893 wpa_s->disable_eapol_g2_tx);
894 } else if (os_strcasecmp(cmd, "test_assoc_comeback_type") == 0) {
895 wpa_s->test_assoc_comeback_type = atoi(value);
896 #ifdef CONFIG_DPP
897 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
898 os_free(wpa_s->dpp_config_obj_override);
899 if (value[0] == '\0')
900 wpa_s->dpp_config_obj_override = NULL;
901 else
902 wpa_s->dpp_config_obj_override = os_strdup(value);
903 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
904 os_free(wpa_s->dpp_discovery_override);
905 if (value[0] == '\0')
906 wpa_s->dpp_discovery_override = NULL;
907 else
908 wpa_s->dpp_discovery_override = os_strdup(value);
909 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
910 os_free(wpa_s->dpp_groups_override);
911 if (value[0] == '\0')
912 wpa_s->dpp_groups_override = NULL;
913 else
914 wpa_s->dpp_groups_override = os_strdup(value);
915 } else if (os_strcasecmp(cmd,
916 "dpp_ignore_netaccesskey_mismatch") == 0) {
917 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
918 } else if (os_strcasecmp(cmd, "dpp_discard_public_action") == 0) {
919 wpa_s->dpp_discard_public_action = atoi(value);
920 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
921 dpp_test = atoi(value);
922 #endif /* CONFIG_DPP */
923 #endif /* CONFIG_TESTING_OPTIONS */
924 #ifdef CONFIG_FILS
925 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
926 wpa_s->disable_fils = !!atoi(value);
927 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
928 wpa_supplicant_set_default_scan_ies(wpa_s);
929 #endif /* CONFIG_FILS */
930 #ifndef CONFIG_NO_CONFIG_BLOBS
931 } else if (os_strcmp(cmd, "blob") == 0) {
932 ret = wpas_ctrl_set_blob(wpa_s, value);
933 #endif /* CONFIG_NO_CONFIG_BLOBS */
934 } else if (os_strcasecmp(cmd, "setband") == 0) {
935 ret = wpas_ctrl_set_band(wpa_s, value);
936 #ifdef CONFIG_MBO
937 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
938 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
939 if (ret == 0) {
940 value[-1] = '=';
941 wpa_config_process_global(wpa_s->conf, cmd, -1);
942 }
943 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
944 int val = atoi(value);
945
946 if (val < MBO_CELL_CAPA_AVAILABLE ||
947 val > MBO_CELL_CAPA_NOT_SUPPORTED)
948 return -1;
949
950 wpas_mbo_update_cell_capa(wpa_s, val);
951 } else if (os_strcasecmp(cmd, "oce") == 0) {
952 int val = atoi(value);
953
954 if (val < 0 || val > 3)
955 return -1;
956
957 wpa_s->conf->oce = val;
958 if (wpa_s->conf->oce) {
959 if ((wpa_s->conf->oce & OCE_STA) &&
960 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
961 wpa_s->enable_oce = OCE_STA;
962
963 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
964 (wpa_s->drv_flags &
965 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
966 /* TODO: Need to add STA-CFON support */
967 wpa_printf(MSG_ERROR,
968 "OCE STA-CFON feature is not yet supported");
969 return -1;
970 }
971 } else {
972 wpa_s->enable_oce = 0;
973 }
974 wpa_supplicant_set_default_scan_ies(wpa_s);
975 #endif /* CONFIG_MBO */
976 } else if (os_strcasecmp(cmd, "lci") == 0) {
977 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
978 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
979 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
980 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
981 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
982 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
983 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
984 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
985 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
986 } else if (os_strcasecmp(cmd, "roaming") == 0) {
987 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
988 #ifdef CONFIG_WNM
989 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
990 struct wpabuf *elems;
991
992 elems = wpabuf_parse_bin(value);
993 if (!elems)
994 return -1;
995 wnm_set_coloc_intf_elems(wpa_s, elems);
996 #endif /* CONFIG_WNM */
997 #ifndef CONFIG_NO_ROBUST_AV
998 } else if (os_strcasecmp(cmd, "enable_dscp_policy_capa") == 0) {
999 wpa_s->enable_dscp_policy_capa = !!atoi(value);
1000 #endif /* CONFIG_NO_ROBUST_AV */
1001 } else {
1002 value[-1] = '=';
1003 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
1004 if (ret == 0)
1005 wpa_supplicant_update_config(wpa_s);
1006 else if (ret == 1)
1007 ret = 0;
1008 }
1009
1010 return ret;
1011 }
1012
1013
wpa_supplicant_ctrl_iface_get(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)1014 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
1015 char *cmd, char *buf, size_t buflen)
1016 {
1017 int res = -1;
1018
1019 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
1020
1021 if (os_strcmp(cmd, "version") == 0) {
1022 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
1023 } else if (os_strcasecmp(cmd, "max_command_len") == 0) {
1024 res = os_snprintf(buf, buflen, "%u", CTRL_IFACE_MAX_LEN);
1025 } else if (os_strcasecmp(cmd, "country") == 0) {
1026 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
1027 res = os_snprintf(buf, buflen, "%c%c",
1028 wpa_s->conf->country[0],
1029 wpa_s->conf->country[1]);
1030 #ifdef CONFIG_WIFI_DISPLAY
1031 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
1032 int enabled;
1033 if (wpa_s->global->p2p == NULL ||
1034 wpa_s->global->p2p_disabled)
1035 enabled = 0;
1036 else
1037 enabled = wpa_s->global->wifi_display;
1038 res = os_snprintf(buf, buflen, "%d", enabled);
1039 #endif /* CONFIG_WIFI_DISPLAY */
1040 #ifdef CONFIG_TESTING_GET_GTK
1041 } else if (os_strcmp(cmd, "gtk") == 0) {
1042 if (wpa_s->last_gtk_len == 0)
1043 return -1;
1044 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
1045 wpa_s->last_gtk_len);
1046 return res;
1047 #endif /* CONFIG_TESTING_GET_GTK */
1048 } else if (os_strcmp(cmd, "tls_library") == 0) {
1049 res = tls_get_library_version(buf, buflen);
1050 #ifdef CONFIG_TESTING_OPTIONS
1051 } else if (os_strcmp(cmd, "anonce") == 0) {
1052 return wpa_snprintf_hex(buf, buflen,
1053 wpa_sm_get_anonce(wpa_s->wpa),
1054 WPA_NONCE_LEN);
1055 } else if (os_strcasecmp(cmd, "last_tk_key_idx") == 0) {
1056 res = os_snprintf(buf, buflen, "%d", wpa_s->last_tk_key_idx);
1057 #endif /* CONFIG_TESTING_OPTIONS */
1058 } else {
1059 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
1060 }
1061
1062 if (os_snprintf_error(buflen, res))
1063 return -1;
1064 return res;
1065 }
1066
1067
1068 #ifdef IEEE8021X_EAPOL
wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant * wpa_s,char * addr)1069 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
1070 char *addr)
1071 {
1072 u8 bssid[ETH_ALEN];
1073 struct wpa_ssid *ssid = wpa_s->current_ssid;
1074
1075 if (hwaddr_aton(addr, bssid)) {
1076 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
1077 "'%s'", addr);
1078 return -1;
1079 }
1080
1081 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR_SEC, MAC2STR_SEC(bssid));
1082 rsn_preauth_deinit(wpa_s->wpa);
1083 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
1084 return -1;
1085
1086 return 0;
1087 }
1088 #endif /* IEEE8021X_EAPOL */
1089
1090
1091 #ifdef CONFIG_TDLS
1092
wpa_supplicant_ctrl_iface_tdls_discover(struct wpa_supplicant * wpa_s,char * addr)1093 static int wpa_supplicant_ctrl_iface_tdls_discover(
1094 struct wpa_supplicant *wpa_s, char *addr)
1095 {
1096 u8 peer[ETH_ALEN];
1097 int ret;
1098
1099 if (hwaddr_aton(addr, peer)) {
1100 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
1101 "address '%s'", addr);
1102 return -1;
1103 }
1104
1105 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR_SEC,
1106 MAC2STR_SEC(peer));
1107
1108 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1109 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
1110 else
1111 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
1112
1113 return ret;
1114 }
1115
1116
wpa_supplicant_ctrl_iface_tdls_setup(struct wpa_supplicant * wpa_s,char * addr)1117 static int wpa_supplicant_ctrl_iface_tdls_setup(
1118 struct wpa_supplicant *wpa_s, char *addr)
1119 {
1120 u8 peer[ETH_ALEN];
1121 int ret;
1122
1123 if (hwaddr_aton(addr, peer)) {
1124 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
1125 "address '%s'", addr);
1126 return -1;
1127 }
1128
1129 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR_SEC,
1130 MAC2STR_SEC(peer));
1131
1132 if ((wpa_s->conf->tdls_external_control) &&
1133 wpa_tdls_is_external_setup(wpa_s->wpa))
1134 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
1135
1136 wpa_tdls_remove(wpa_s->wpa, peer);
1137
1138 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1139 ret = wpa_tdls_start(wpa_s->wpa, peer);
1140 else
1141 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
1142
1143 return ret;
1144 }
1145
1146
wpa_supplicant_ctrl_iface_tdls_teardown(struct wpa_supplicant * wpa_s,char * addr)1147 static int wpa_supplicant_ctrl_iface_tdls_teardown(
1148 struct wpa_supplicant *wpa_s, char *addr)
1149 {
1150 u8 peer[ETH_ALEN];
1151 int ret;
1152
1153 if (os_strcmp(addr, "*") == 0) {
1154 /* remove everyone */
1155 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
1156 wpa_tdls_teardown_peers(wpa_s->wpa);
1157 return 0;
1158 }
1159
1160 if (hwaddr_aton(addr, peer)) {
1161 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
1162 "address '%s'", addr);
1163 return -1;
1164 }
1165
1166 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR_SEC,
1167 MAC2STR_SEC(peer));
1168
1169 if ((wpa_s->conf->tdls_external_control) &&
1170 wpa_tdls_is_external_setup(wpa_s->wpa))
1171 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1172
1173 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1174 ret = wpa_tdls_teardown_link(
1175 wpa_s->wpa, peer,
1176 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
1177 else
1178 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1179
1180 return ret;
1181 }
1182
1183
ctrl_iface_get_capability_tdls(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)1184 static int ctrl_iface_get_capability_tdls(
1185 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1186 {
1187 int ret;
1188
1189 ret = os_snprintf(buf, buflen, "%s\n",
1190 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
1191 (wpa_s->drv_flags &
1192 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
1193 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
1194 if (os_snprintf_error(buflen, ret))
1195 return -1;
1196 return ret;
1197 }
1198
1199
wpa_supplicant_ctrl_iface_tdls_chan_switch(struct wpa_supplicant * wpa_s,char * cmd)1200 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
1201 struct wpa_supplicant *wpa_s, char *cmd)
1202 {
1203 u8 peer[ETH_ALEN];
1204 struct hostapd_freq_params freq_params;
1205 u8 oper_class;
1206 char *pos, *end;
1207
1208 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1209 wpa_printf(MSG_INFO,
1210 "tdls_chanswitch: Only supported with external setup");
1211 return -1;
1212 }
1213
1214 os_memset(&freq_params, 0, sizeof(freq_params));
1215
1216 pos = os_strchr(cmd, ' ');
1217 if (pos == NULL)
1218 return -1;
1219 *pos++ = '\0';
1220
1221 oper_class = strtol(pos, &end, 10);
1222 if (pos == end) {
1223 wpa_printf(MSG_INFO,
1224 "tdls_chanswitch: Invalid op class provided");
1225 return -1;
1226 }
1227
1228 pos = end;
1229 freq_params.freq = atoi(pos);
1230 if (freq_params.freq == 0) {
1231 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
1232 return -1;
1233 }
1234
1235 #define SET_FREQ_SETTING(str) \
1236 do { \
1237 const char *pos2 = os_strstr(pos, " " #str "="); \
1238 if (pos2) { \
1239 pos2 += sizeof(" " #str "=") - 1; \
1240 freq_params.str = atoi(pos2); \
1241 } \
1242 } while (0)
1243
1244 SET_FREQ_SETTING(center_freq1);
1245 SET_FREQ_SETTING(center_freq2);
1246 SET_FREQ_SETTING(bandwidth);
1247 SET_FREQ_SETTING(sec_channel_offset);
1248 #undef SET_FREQ_SETTING
1249
1250 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1251 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1252
1253 if (hwaddr_aton(cmd, peer)) {
1254 wpa_printf(MSG_DEBUG,
1255 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1256 cmd);
1257 return -1;
1258 }
1259
1260 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR_SEC
1261 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1262 MAC2STR_SEC(peer), oper_class, freq_params.freq,
1263 freq_params.center_freq1, freq_params.center_freq2,
1264 freq_params.bandwidth, freq_params.sec_channel_offset,
1265 freq_params.ht_enabled ? " HT" : "",
1266 freq_params.vht_enabled ? " VHT" : "");
1267
1268 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1269 &freq_params);
1270 }
1271
1272
wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(struct wpa_supplicant * wpa_s,char * cmd)1273 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1274 struct wpa_supplicant *wpa_s, char *cmd)
1275 {
1276 u8 peer[ETH_ALEN];
1277
1278 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1279 wpa_printf(MSG_INFO,
1280 "tdls_chanswitch: Only supported with external setup");
1281 return -1;
1282 }
1283
1284 if (hwaddr_aton(cmd, peer)) {
1285 wpa_printf(MSG_DEBUG,
1286 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1287 cmd);
1288 return -1;
1289 }
1290
1291 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR_SEC,
1292 MAC2STR_SEC(peer));
1293
1294 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1295 }
1296
1297
wpa_supplicant_ctrl_iface_tdls_link_status(struct wpa_supplicant * wpa_s,const char * addr,char * buf,size_t buflen)1298 static int wpa_supplicant_ctrl_iface_tdls_link_status(
1299 struct wpa_supplicant *wpa_s, const char *addr,
1300 char *buf, size_t buflen)
1301 {
1302 u8 peer[ETH_ALEN];
1303 const char *tdls_status;
1304 int ret;
1305
1306 if (hwaddr_aton(addr, peer)) {
1307 wpa_printf(MSG_DEBUG,
1308 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1309 addr);
1310 return -1;
1311 }
1312 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR_SEC,
1313 MAC2STR_SEC(peer));
1314
1315 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1316 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1317 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1318 if (os_snprintf_error(buflen, ret))
1319 return -1;
1320
1321 return ret;
1322 }
1323
1324 #endif /* CONFIG_TDLS */
1325
1326
1327 #ifndef CONFIG_NO_WMM_AC
1328
wmm_ac_ctrl_addts(struct wpa_supplicant * wpa_s,char * cmd)1329 static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1330 {
1331 char *token, *context = NULL;
1332 struct wmm_ac_ts_setup_params params = {
1333 .tsid = 0xff,
1334 .direction = 0xff,
1335 };
1336
1337 while ((token = str_token(cmd, " ", &context))) {
1338 if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 ||
1339 sscanf(token, "up=%i", ¶ms.user_priority) == 1 ||
1340 sscanf(token, "nominal_msdu_size=%i",
1341 ¶ms.nominal_msdu_size) == 1 ||
1342 sscanf(token, "mean_data_rate=%i",
1343 ¶ms.mean_data_rate) == 1 ||
1344 sscanf(token, "min_phy_rate=%i",
1345 ¶ms.minimum_phy_rate) == 1 ||
1346 sscanf(token, "sba=%i",
1347 ¶ms.surplus_bandwidth_allowance) == 1)
1348 continue;
1349
1350 if (os_strcasecmp(token, "downlink") == 0) {
1351 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1352 } else if (os_strcasecmp(token, "uplink") == 0) {
1353 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1354 } else if (os_strcasecmp(token, "bidi") == 0) {
1355 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1356 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1357 params.fixed_nominal_msdu = 1;
1358 } else {
1359 wpa_printf(MSG_DEBUG,
1360 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1361 token);
1362 return -1;
1363 }
1364
1365 }
1366
1367 return wpas_wmm_ac_addts(wpa_s, ¶ms);
1368 }
1369
1370
wmm_ac_ctrl_delts(struct wpa_supplicant * wpa_s,char * cmd)1371 static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1372 {
1373 u8 tsid = atoi(cmd);
1374
1375 return wpas_wmm_ac_delts(wpa_s, tsid);
1376 }
1377
1378 #endif /* CONFIG_NO_WMM_AC */
1379
1380
1381 #ifdef CONFIG_IEEE80211R
wpa_supplicant_ctrl_iface_ft_ds(struct wpa_supplicant * wpa_s,char * addr)1382 static int wpa_supplicant_ctrl_iface_ft_ds(
1383 struct wpa_supplicant *wpa_s, char *addr)
1384 {
1385 u8 target_ap[ETH_ALEN];
1386 struct wpa_bss *bss;
1387 const u8 *mdie;
1388 bool force = os_strstr(addr, " force") != NULL;
1389
1390 if (hwaddr_aton(addr, target_ap)) {
1391 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1392 "address '%s'", addr);
1393 return -1;
1394 }
1395
1396 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR_SEC, MAC2STR_SEC(target_ap));
1397
1398 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1399 if (bss)
1400 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1401 else
1402 mdie = NULL;
1403
1404 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie, force);
1405 }
1406 #endif /* CONFIG_IEEE80211R */
1407
1408
1409 #ifdef CONFIG_WPS
wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant * wpa_s,char * cmd)1410 int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1411 char *cmd)
1412 {
1413 u8 bssid[ETH_ALEN], *_bssid = bssid;
1414 #ifdef CONFIG_P2P
1415 u8 p2p_dev_addr[ETH_ALEN];
1416 #endif /* CONFIG_P2P */
1417 #ifdef CONFIG_AP
1418 u8 *_p2p_dev_addr = NULL;
1419 #endif /* CONFIG_AP */
1420 char *pos;
1421 int multi_ap = 0;
1422
1423 if (!cmd || os_strcmp(cmd, "any") == 0 ||
1424 os_strncmp(cmd, "any ", 4) == 0) {
1425 _bssid = NULL;
1426 #ifdef CONFIG_P2P
1427 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1428 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1429 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1430 "P2P Device Address '%s'",
1431 cmd + 13);
1432 return -1;
1433 }
1434 _p2p_dev_addr = p2p_dev_addr;
1435 #endif /* CONFIG_P2P */
1436 } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) {
1437 _bssid = NULL;
1438 multi_ap = atoi(cmd + 9);
1439 } else if (hwaddr_aton(cmd, bssid)) {
1440 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1441 anonymize_common(cmd));
1442 return -1;
1443 }
1444
1445 if (cmd) {
1446 pos = os_strstr(cmd, " multi_ap=");
1447 if (pos) {
1448 pos += 10;
1449 multi_ap = atoi(pos);
1450 }
1451 }
1452
1453 #ifdef CONFIG_AP
1454 if (wpa_s->ap_iface)
1455 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1456 #endif /* CONFIG_AP */
1457
1458 return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap);
1459 }
1460
1461
wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)1462 int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1463 char *cmd, char *buf,
1464 size_t buflen)
1465 {
1466 u8 bssid[ETH_ALEN], *_bssid = bssid;
1467 char *pin;
1468 int ret;
1469
1470 pin = os_strchr(cmd, ' ');
1471 if (pin)
1472 *pin++ = '\0';
1473
1474 if (os_strcmp(cmd, "any") == 0)
1475 _bssid = NULL;
1476 else if (os_strcmp(cmd, "get") == 0) {
1477 if (wps_generate_pin((unsigned int *) &ret) < 0)
1478 return -1;
1479 goto done;
1480 } else if (hwaddr_aton(cmd, bssid)) {
1481 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1482 cmd);
1483 return -1;
1484 }
1485
1486 #ifdef CONFIG_AP
1487 if (wpa_s->ap_iface) {
1488 int timeout = 0;
1489 char *pos;
1490
1491 if (pin) {
1492 pos = os_strchr(pin, ' ');
1493 if (pos) {
1494 *pos++ = '\0';
1495 timeout = atoi(pos);
1496 }
1497 }
1498
1499 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
1500 buf, buflen, timeout);
1501 }
1502 #endif /* CONFIG_AP */
1503
1504 if (pin) {
1505 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1506 DEV_PW_DEFAULT);
1507 if (ret < 0)
1508 return -1;
1509 ret = os_snprintf(buf, buflen, "%s", pin);
1510 if (os_snprintf_error(buflen, ret))
1511 return -1;
1512 return ret;
1513 }
1514
1515 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1516 if (ret < 0)
1517 return -1;
1518
1519 done:
1520 /* Return the generated PIN */
1521 ret = os_snprintf(buf, buflen, "%08d", ret);
1522 if (os_snprintf_error(buflen, ret))
1523 return -1;
1524 return ret;
1525 }
1526
1527
wpa_supplicant_ctrl_iface_wps_check_pin(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)1528 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1529 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1530 {
1531 char pin[9];
1532 size_t len;
1533 char *pos;
1534 int ret;
1535
1536 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1537 (u8 *) cmd, os_strlen(cmd));
1538 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1539 if (*pos < '0' || *pos > '9')
1540 continue;
1541 pin[len++] = *pos;
1542 if (len == 9) {
1543 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1544 return -1;
1545 }
1546 }
1547 if (len != 4 && len != 8) {
1548 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1549 return -1;
1550 }
1551 pin[len] = '\0';
1552
1553 if (len == 8) {
1554 unsigned int pin_val;
1555 pin_val = atoi(pin);
1556 if (!wps_pin_valid(pin_val)) {
1557 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1558 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
1559 if (os_snprintf_error(buflen, ret))
1560 return -1;
1561 return ret;
1562 }
1563 }
1564
1565 ret = os_snprintf(buf, buflen, "%s", pin);
1566 if (os_snprintf_error(buflen, ret))
1567 return -1;
1568
1569 return ret;
1570 }
1571
1572
1573 #ifdef CONFIG_WPS_NFC
1574
wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant * wpa_s,char * cmd)1575 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1576 char *cmd)
1577 {
1578 u8 bssid[ETH_ALEN], *_bssid = bssid;
1579
1580 if (cmd == NULL || cmd[0] == '\0')
1581 _bssid = NULL;
1582 else if (hwaddr_aton(cmd, bssid))
1583 return -1;
1584
1585 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1586 0, 0);
1587 }
1588
1589
wpa_supplicant_ctrl_iface_wps_nfc_config_token(struct wpa_supplicant * wpa_s,char * cmd,char * reply,size_t max_len)1590 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1591 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1592 {
1593 int ndef;
1594 struct wpabuf *buf;
1595 int res;
1596 char *pos;
1597
1598 pos = os_strchr(cmd, ' ');
1599 if (pos)
1600 *pos++ = '\0';
1601 if (os_strcmp(cmd, "WPS") == 0)
1602 ndef = 0;
1603 else if (os_strcmp(cmd, "NDEF") == 0)
1604 ndef = 1;
1605 else
1606 return -1;
1607
1608 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
1609 if (buf == NULL)
1610 return -1;
1611
1612 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1613 wpabuf_len(buf));
1614 reply[res++] = '\n';
1615 reply[res] = '\0';
1616
1617 wpabuf_free(buf);
1618
1619 return res;
1620 }
1621
1622
wpa_supplicant_ctrl_iface_wps_nfc_token(struct wpa_supplicant * wpa_s,char * cmd,char * reply,size_t max_len)1623 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1624 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1625 {
1626 int ndef;
1627 struct wpabuf *buf;
1628 int res;
1629
1630 if (os_strcmp(cmd, "WPS") == 0)
1631 ndef = 0;
1632 else if (os_strcmp(cmd, "NDEF") == 0)
1633 ndef = 1;
1634 else
1635 return -1;
1636
1637 buf = wpas_wps_nfc_token(wpa_s, ndef);
1638 if (buf == NULL)
1639 return -1;
1640
1641 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1642 wpabuf_len(buf));
1643 reply[res++] = '\n';
1644 reply[res] = '\0';
1645
1646 wpabuf_free(buf);
1647
1648 return res;
1649 }
1650
1651
wpa_supplicant_ctrl_iface_wps_nfc_tag_read(struct wpa_supplicant * wpa_s,char * pos)1652 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1653 struct wpa_supplicant *wpa_s, char *pos)
1654 {
1655 size_t len;
1656 struct wpabuf *buf;
1657 int ret;
1658 char *freq;
1659 int forced_freq = 0;
1660
1661 freq = strstr(pos, " freq=");
1662 if (freq) {
1663 *freq = '\0';
1664 freq += 6;
1665 forced_freq = atoi(freq);
1666 }
1667
1668 len = os_strlen(pos);
1669 if (len & 0x01)
1670 return -1;
1671 len /= 2;
1672
1673 buf = wpabuf_alloc(len);
1674 if (buf == NULL)
1675 return -1;
1676 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1677 wpabuf_free(buf);
1678 return -1;
1679 }
1680
1681 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
1682 wpabuf_free(buf);
1683
1684 return ret;
1685 }
1686
1687
wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant * wpa_s,char * reply,size_t max_len,int ndef)1688 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
1689 char *reply, size_t max_len,
1690 int ndef)
1691 {
1692 struct wpabuf *buf;
1693 int res;
1694
1695 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
1696 if (buf == NULL)
1697 return -1;
1698
1699 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1700 wpabuf_len(buf));
1701 reply[res++] = '\n';
1702 reply[res] = '\0';
1703
1704 wpabuf_free(buf);
1705
1706 return res;
1707 }
1708
1709
1710 #ifdef CONFIG_P2P
wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant * wpa_s,char * reply,size_t max_len,int ndef)1711 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1712 char *reply, size_t max_len,
1713 int ndef)
1714 {
1715 struct wpabuf *buf;
1716 int res;
1717
1718 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1719 if (buf == NULL) {
1720 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1721 return -1;
1722 }
1723
1724 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1725 wpabuf_len(buf));
1726 reply[res++] = '\n';
1727 reply[res] = '\0';
1728
1729 wpabuf_free(buf);
1730
1731 return res;
1732 }
1733 #endif /* CONFIG_P2P */
1734
1735
wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant * wpa_s,char * cmd,char * reply,size_t max_len)1736 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1737 char *cmd, char *reply,
1738 size_t max_len)
1739 {
1740 char *pos;
1741 int ndef;
1742
1743 pos = os_strchr(cmd, ' ');
1744 if (pos == NULL)
1745 return -1;
1746 *pos++ = '\0';
1747
1748 if (os_strcmp(cmd, "WPS") == 0)
1749 ndef = 0;
1750 else if (os_strcmp(cmd, "NDEF") == 0)
1751 ndef = 1;
1752 else
1753 return -1;
1754
1755 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1756 if (!ndef)
1757 return -1;
1758 return wpas_ctrl_nfc_get_handover_req_wps(
1759 wpa_s, reply, max_len, ndef);
1760 }
1761
1762 #ifdef CONFIG_P2P
1763 if (os_strcmp(pos, "P2P-CR") == 0) {
1764 return wpas_ctrl_nfc_get_handover_req_p2p(
1765 wpa_s, reply, max_len, ndef);
1766 }
1767 #endif /* CONFIG_P2P */
1768
1769 return -1;
1770 }
1771
1772
wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant * wpa_s,char * reply,size_t max_len,int ndef,int cr,char * uuid)1773 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1774 char *reply, size_t max_len,
1775 int ndef, int cr, char *uuid)
1776 {
1777 struct wpabuf *buf;
1778 int res;
1779
1780 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1781 if (buf == NULL)
1782 return -1;
1783
1784 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1785 wpabuf_len(buf));
1786 reply[res++] = '\n';
1787 reply[res] = '\0';
1788
1789 wpabuf_free(buf);
1790
1791 return res;
1792 }
1793
1794
1795 #ifdef CONFIG_P2P
wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant * wpa_s,char * reply,size_t max_len,int ndef,int tag)1796 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1797 char *reply, size_t max_len,
1798 int ndef, int tag)
1799 {
1800 struct wpabuf *buf;
1801 int res;
1802
1803 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1804 if (buf == NULL)
1805 return -1;
1806
1807 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1808 wpabuf_len(buf));
1809 reply[res++] = '\n';
1810 reply[res] = '\0';
1811
1812 wpabuf_free(buf);
1813
1814 return res;
1815 }
1816 #endif /* CONFIG_P2P */
1817
1818
wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant * wpa_s,char * cmd,char * reply,size_t max_len)1819 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1820 char *cmd, char *reply,
1821 size_t max_len)
1822 {
1823 char *pos, *pos2;
1824 int ndef;
1825
1826 pos = os_strchr(cmd, ' ');
1827 if (pos == NULL)
1828 return -1;
1829 *pos++ = '\0';
1830
1831 if (os_strcmp(cmd, "WPS") == 0)
1832 ndef = 0;
1833 else if (os_strcmp(cmd, "NDEF") == 0)
1834 ndef = 1;
1835 else
1836 return -1;
1837
1838 pos2 = os_strchr(pos, ' ');
1839 if (pos2)
1840 *pos2++ = '\0';
1841 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1842 if (!ndef)
1843 return -1;
1844 return wpas_ctrl_nfc_get_handover_sel_wps(
1845 wpa_s, reply, max_len, ndef,
1846 os_strcmp(pos, "WPS-CR") == 0, pos2);
1847 }
1848
1849 #ifdef CONFIG_P2P
1850 if (os_strcmp(pos, "P2P-CR") == 0) {
1851 return wpas_ctrl_nfc_get_handover_sel_p2p(
1852 wpa_s, reply, max_len, ndef, 0);
1853 }
1854
1855 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1856 return wpas_ctrl_nfc_get_handover_sel_p2p(
1857 wpa_s, reply, max_len, ndef, 1);
1858 }
1859 #endif /* CONFIG_P2P */
1860
1861 return -1;
1862 }
1863
1864
wpas_ctrl_nfc_report_handover(struct wpa_supplicant * wpa_s,char * cmd)1865 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1866 char *cmd)
1867 {
1868 size_t len;
1869 struct wpabuf *req, *sel;
1870 int ret;
1871 char *pos, *role, *type, *pos2;
1872 #ifdef CONFIG_P2P
1873 char *freq;
1874 int forced_freq = 0;
1875
1876 freq = strstr(cmd, " freq=");
1877 if (freq) {
1878 *freq = '\0';
1879 freq += 6;
1880 forced_freq = atoi(freq);
1881 }
1882 #endif /* CONFIG_P2P */
1883
1884 role = cmd;
1885 pos = os_strchr(role, ' ');
1886 if (pos == NULL) {
1887 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1888 return -1;
1889 }
1890 *pos++ = '\0';
1891
1892 type = pos;
1893 pos = os_strchr(type, ' ');
1894 if (pos == NULL) {
1895 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1896 return -1;
1897 }
1898 *pos++ = '\0';
1899
1900 pos2 = os_strchr(pos, ' ');
1901 if (pos2 == NULL) {
1902 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1903 return -1;
1904 }
1905 *pos2++ = '\0';
1906
1907 len = os_strlen(pos);
1908 if (len & 0x01) {
1909 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1910 return -1;
1911 }
1912 len /= 2;
1913
1914 req = wpabuf_alloc(len);
1915 if (req == NULL) {
1916 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1917 return -1;
1918 }
1919 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1920 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1921 wpabuf_free(req);
1922 return -1;
1923 }
1924
1925 len = os_strlen(pos2);
1926 if (len & 0x01) {
1927 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1928 wpabuf_free(req);
1929 return -1;
1930 }
1931 len /= 2;
1932
1933 sel = wpabuf_alloc(len);
1934 if (sel == NULL) {
1935 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1936 wpabuf_free(req);
1937 return -1;
1938 }
1939 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1940 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1941 wpabuf_free(req);
1942 wpabuf_free(sel);
1943 return -1;
1944 }
1945
1946 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1947 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1948
1949 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1950 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1951 #ifdef CONFIG_AP
1952 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1953 {
1954 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1955 if (ret < 0)
1956 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1957 #endif /* CONFIG_AP */
1958 #ifdef CONFIG_P2P
1959 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1960 {
1961 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1962 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1963 {
1964 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1965 forced_freq);
1966 #endif /* CONFIG_P2P */
1967 } else {
1968 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1969 "reported: role=%s type=%s", role, type);
1970 ret = -1;
1971 }
1972 wpabuf_free(req);
1973 wpabuf_free(sel);
1974
1975 if (ret)
1976 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1977
1978 return ret;
1979 }
1980
1981 #endif /* CONFIG_WPS_NFC */
1982
1983
wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant * wpa_s,char * cmd)1984 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1985 char *cmd)
1986 {
1987 u8 bssid[ETH_ALEN];
1988 char *pin;
1989 char *new_ssid;
1990 char *new_auth;
1991 char *new_encr;
1992 char *new_key;
1993 struct wps_new_ap_settings ap;
1994
1995 pin = os_strchr(cmd, ' ');
1996 if (pin == NULL)
1997 return -1;
1998 *pin++ = '\0';
1999
2000 if (hwaddr_aton(cmd, bssid)) {
2001 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
2002 cmd);
2003 return -1;
2004 }
2005
2006 new_ssid = os_strchr(pin, ' ');
2007 if (new_ssid == NULL)
2008 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
2009 *new_ssid++ = '\0';
2010
2011 new_auth = os_strchr(new_ssid, ' ');
2012 if (new_auth == NULL)
2013 return -1;
2014 *new_auth++ = '\0';
2015
2016 new_encr = os_strchr(new_auth, ' ');
2017 if (new_encr == NULL)
2018 return -1;
2019 *new_encr++ = '\0';
2020
2021 new_key = os_strchr(new_encr, ' ');
2022 if (new_key == NULL)
2023 return -1;
2024 *new_key++ = '\0';
2025
2026 os_memset(&ap, 0, sizeof(ap));
2027 ap.ssid_hex = new_ssid;
2028 ap.auth = new_auth;
2029 ap.encr = new_encr;
2030 ap.key_hex = new_key;
2031 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
2032 }
2033
2034
2035 #ifdef CONFIG_AP
wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)2036 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
2037 char *cmd, char *buf,
2038 size_t buflen)
2039 {
2040 int timeout = 300;
2041 char *pos;
2042 const char *pin_txt;
2043
2044 if (!wpa_s->ap_iface)
2045 return -1;
2046
2047 pos = os_strchr(cmd, ' ');
2048 if (pos)
2049 *pos++ = '\0';
2050
2051 if (os_strcmp(cmd, "disable") == 0) {
2052 wpas_wps_ap_pin_disable(wpa_s);
2053 return os_snprintf(buf, buflen, "OK\n");
2054 }
2055
2056 if (os_strcmp(cmd, "random") == 0) {
2057 if (pos)
2058 timeout = atoi(pos);
2059 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
2060 if (pin_txt == NULL)
2061 return -1;
2062 return os_snprintf(buf, buflen, "%s", pin_txt);
2063 }
2064
2065 if (os_strcmp(cmd, "get") == 0) {
2066 pin_txt = wpas_wps_ap_pin_get(wpa_s);
2067 if (pin_txt == NULL)
2068 return -1;
2069 return os_snprintf(buf, buflen, "%s", pin_txt);
2070 }
2071
2072 if (os_strcmp(cmd, "set") == 0) {
2073 char *pin;
2074 if (pos == NULL)
2075 return -1;
2076 pin = pos;
2077 pos = os_strchr(pos, ' ');
2078 if (pos) {
2079 *pos++ = '\0';
2080 timeout = atoi(pos);
2081 }
2082 if (os_strlen(pin) > buflen)
2083 return -1;
2084 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
2085 return -1;
2086 return os_snprintf(buf, buflen, "%s", pin);
2087 }
2088
2089 return -1;
2090 }
2091 #endif /* CONFIG_AP */
2092
2093
2094 #ifdef CONFIG_WPS_ER
wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant * wpa_s,char * cmd)2095 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
2096 char *cmd)
2097 {
2098 char *uuid = cmd, *pin, *pos;
2099 u8 addr_buf[ETH_ALEN], *addr = NULL;
2100 pin = os_strchr(uuid, ' ');
2101 if (pin == NULL)
2102 return -1;
2103 *pin++ = '\0';
2104 pos = os_strchr(pin, ' ');
2105 if (pos) {
2106 *pos++ = '\0';
2107 if (hwaddr_aton(pos, addr_buf) == 0)
2108 addr = addr_buf;
2109 }
2110 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
2111 }
2112
2113
wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant * wpa_s,char * cmd)2114 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
2115 char *cmd)
2116 {
2117 char *uuid = cmd, *pin;
2118 pin = os_strchr(uuid, ' ');
2119 if (pin == NULL)
2120 return -1;
2121 *pin++ = '\0';
2122 return wpas_wps_er_learn(wpa_s, uuid, pin);
2123 }
2124
2125
wpa_supplicant_ctrl_iface_wps_er_set_config(struct wpa_supplicant * wpa_s,char * cmd)2126 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
2127 struct wpa_supplicant *wpa_s, char *cmd)
2128 {
2129 char *uuid = cmd, *id;
2130 id = os_strchr(uuid, ' ');
2131 if (id == NULL)
2132 return -1;
2133 *id++ = '\0';
2134 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
2135 }
2136
2137
wpa_supplicant_ctrl_iface_wps_er_config(struct wpa_supplicant * wpa_s,char * cmd)2138 static int wpa_supplicant_ctrl_iface_wps_er_config(
2139 struct wpa_supplicant *wpa_s, char *cmd)
2140 {
2141 char *pin;
2142 char *new_ssid;
2143 char *new_auth;
2144 char *new_encr;
2145 char *new_key;
2146 struct wps_new_ap_settings ap;
2147
2148 pin = os_strchr(cmd, ' ');
2149 if (pin == NULL)
2150 return -1;
2151 *pin++ = '\0';
2152
2153 new_ssid = os_strchr(pin, ' ');
2154 if (new_ssid == NULL)
2155 return -1;
2156 *new_ssid++ = '\0';
2157
2158 new_auth = os_strchr(new_ssid, ' ');
2159 if (new_auth == NULL)
2160 return -1;
2161 *new_auth++ = '\0';
2162
2163 new_encr = os_strchr(new_auth, ' ');
2164 if (new_encr == NULL)
2165 return -1;
2166 *new_encr++ = '\0';
2167
2168 new_key = os_strchr(new_encr, ' ');
2169 if (new_key == NULL)
2170 return -1;
2171 *new_key++ = '\0';
2172
2173 os_memset(&ap, 0, sizeof(ap));
2174 ap.ssid_hex = new_ssid;
2175 ap.auth = new_auth;
2176 ap.encr = new_encr;
2177 ap.key_hex = new_key;
2178 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
2179 }
2180
2181
2182 #ifdef CONFIG_WPS_NFC
wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(struct wpa_supplicant * wpa_s,char * cmd,char * reply,size_t max_len)2183 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
2184 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2185 {
2186 int ndef;
2187 struct wpabuf *buf;
2188 int res;
2189 char *uuid;
2190
2191 uuid = os_strchr(cmd, ' ');
2192 if (uuid == NULL)
2193 return -1;
2194 *uuid++ = '\0';
2195
2196 if (os_strcmp(cmd, "WPS") == 0)
2197 ndef = 0;
2198 else if (os_strcmp(cmd, "NDEF") == 0)
2199 ndef = 1;
2200 else
2201 return -1;
2202
2203 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
2204 if (buf == NULL)
2205 return -1;
2206
2207 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
2208 wpabuf_len(buf));
2209 reply[res++] = '\n';
2210 reply[res] = '\0';
2211
2212 wpabuf_free(buf);
2213
2214 return res;
2215 }
2216 #endif /* CONFIG_WPS_NFC */
2217 #endif /* CONFIG_WPS_ER */
2218
2219 #endif /* CONFIG_WPS */
2220
2221
2222 #ifdef CONFIG_IBSS_RSN
wpa_supplicant_ctrl_iface_ibss_rsn(struct wpa_supplicant * wpa_s,char * addr)2223 static int wpa_supplicant_ctrl_iface_ibss_rsn(
2224 struct wpa_supplicant *wpa_s, char *addr)
2225 {
2226 u8 peer[ETH_ALEN];
2227
2228 if (hwaddr_aton(addr, peer)) {
2229 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
2230 "address '%s'", addr);
2231 return -1;
2232 }
2233
2234 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR_SEC,
2235 MAC2STR_SEC(peer));
2236
2237 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
2238 }
2239 #endif /* CONFIG_IBSS_RSN */
2240
2241
wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant * wpa_s,char * rsp)2242 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
2243 char *rsp)
2244 {
2245 #ifdef IEEE8021X_EAPOL
2246 char *pos, *id_pos;
2247 int id;
2248 struct wpa_ssid *ssid;
2249
2250 pos = os_strchr(rsp, '-');
2251 if (pos == NULL)
2252 return -1;
2253 *pos++ = '\0';
2254 id_pos = pos;
2255 pos = os_strchr(pos, ':');
2256 if (pos == NULL)
2257 return -1;
2258 *pos++ = '\0';
2259 id = atoi(id_pos);
2260 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
2261 wpa_hexdump_ascii_key(MSG_EXCESSIVE, "CTRL_IFACE: value",
2262 (u8 *) pos, os_strlen(pos));
2263
2264 ssid = wpa_config_get_network(wpa_s->conf, id);
2265 if (ssid == NULL) {
2266 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2267 "to update", id);
2268 return -1;
2269 }
2270
2271 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2272 pos);
2273 #else /* IEEE8021X_EAPOL */
2274 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2275 return -1;
2276 #endif /* IEEE8021X_EAPOL */
2277 }
2278
2279 #ifdef CONFIG_WAPI
wapi_key_mgmt_txt(int key_mgmt)2280 static const char* wapi_key_mgmt_txt(int key_mgmt)
2281 {
2282 switch (key_mgmt) {
2283 case WPA_KEY_MGMT_WAPI_PSK:
2284 return "WAPI-PSK";
2285 case WPA_KEY_MGMT_WAPI_CERT:
2286 return "WAPI-CERT";
2287 default:
2288 return "UNKNOWN";
2289 }
2290 }
2291
wapi_get_cipher_key_mgmt(unsigned int key_mgmt,char * buf,size_t buflen,int verbose)2292 static int wapi_get_cipher_key_mgmt(unsigned int key_mgmt, char *buf, size_t buflen, int verbose)
2293 {
2294 char *pos = buf, *end = buf + buflen;
2295 int ret;
2296
2297 ret = os_snprintf(pos, end - pos,
2298 "pairwise_cipher=SMS4\n"
2299 "group_cipher=SMS4\n"
2300 "key_mgmt=%s\n",
2301 wapi_key_mgmt_txt(key_mgmt));
2302 if (ret < 0 || ret >= end - pos)
2303 return pos - buf;
2304 pos += ret;
2305 return pos - buf;
2306 }
2307
wapi_psk_type_txt(int psk_key_type)2308 static const char* wapi_psk_type_txt(int psk_key_type)
2309 {
2310 switch (psk_key_type) {
2311 case KEY_TYPE_ASCII:
2312 return "ASCII";
2313 case KEY_TYPE_HEX:
2314 return "HEX";
2315 default:
2316 return "UNKNOWN";
2317 }
2318 }
2319
wapi_get_psk_key_type(int key_type,char * buf,size_t buflen,int verbose)2320 static int wapi_get_psk_key_type(int key_type, char *buf, size_t buflen, int verbose)
2321 {
2322 char *pos = buf, *end = buf + buflen;
2323 int ret;
2324
2325 ret = os_snprintf(pos, end - pos,
2326 "psk_key_type=%s\n",
2327 wapi_psk_type_txt(key_type));
2328 if (ret < 0 || ret >= end - pos)
2329 return pos - buf;
2330 pos += ret;
2331 return pos - buf;
2332 }
2333 #endif
2334
wpa_supplicant_ctrl_iface_status(struct wpa_supplicant * wpa_s,const char * params,char * buf,size_t buflen)2335 int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2336 const char *params,
2337 char *buf, size_t buflen)
2338 {
2339 char *pos, *end, tmp[30];
2340 int res, verbose, wps, ret;
2341 #ifdef CONFIG_HS20
2342 const u8 *hs20;
2343 #endif /* CONFIG_HS20 */
2344 const u8 *sess_id;
2345 size_t sess_id_len;
2346
2347 if (os_strcmp(params, "-DRIVER") == 0)
2348 return wpa_drv_status(wpa_s, buf, buflen);
2349 verbose = os_strcmp(params, "-VERBOSE") == 0;
2350 wps = os_strcmp(params, "-WPS") == 0;
2351 pos = buf;
2352 end = buf + buflen;
2353 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2354 struct wpa_ssid *ssid = wpa_s->current_ssid;
2355 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2356 MAC2STR(wpa_s->bssid));
2357 if (os_snprintf_error(end - pos, ret))
2358 return pos - buf;
2359 pos += ret;
2360 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2361 wpa_s->assoc_freq);
2362 if (os_snprintf_error(end - pos, ret))
2363 return pos - buf;
2364 pos += ret;
2365 if (ssid) {
2366 u8 *_ssid = ssid->ssid;
2367 size_t ssid_len = ssid->ssid_len;
2368 u8 ssid_buf[SSID_MAX_LEN];
2369 if (ssid_len == 0) {
2370 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2371 if (_res < 0)
2372 ssid_len = 0;
2373 else
2374 ssid_len = _res;
2375 _ssid = ssid_buf;
2376 }
2377 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2378 wpa_ssid_txt(_ssid, ssid_len),
2379 ssid->id);
2380 if (os_snprintf_error(end - pos, ret))
2381 return pos - buf;
2382 pos += ret;
2383
2384 if (wps && ssid->passphrase &&
2385 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2386 (ssid->mode == WPAS_MODE_AP ||
2387 ssid->mode == WPAS_MODE_P2P_GO)) {
2388 ret = os_snprintf(pos, end - pos,
2389 "passphrase=%s\n",
2390 ssid->passphrase);
2391 if (os_snprintf_error(end - pos, ret))
2392 return pos - buf;
2393 pos += ret;
2394 }
2395 if (ssid->id_str) {
2396 ret = os_snprintf(pos, end - pos,
2397 "id_str=%s\n",
2398 ssid->id_str);
2399 if (os_snprintf_error(end - pos, ret))
2400 return pos - buf;
2401 pos += ret;
2402 }
2403
2404 switch (ssid->mode) {
2405 case WPAS_MODE_INFRA:
2406 ret = os_snprintf(pos, end - pos,
2407 "mode=station\n");
2408 break;
2409 case WPAS_MODE_IBSS:
2410 ret = os_snprintf(pos, end - pos,
2411 "mode=IBSS\n");
2412 break;
2413 case WPAS_MODE_AP:
2414 ret = os_snprintf(pos, end - pos,
2415 "mode=AP\n");
2416 break;
2417 case WPAS_MODE_P2P_GO:
2418 ret = os_snprintf(pos, end - pos,
2419 "mode=P2P GO\n");
2420 break;
2421 case WPAS_MODE_P2P_GROUP_FORMATION:
2422 ret = os_snprintf(pos, end - pos,
2423 "mode=P2P GO - group "
2424 "formation\n");
2425 break;
2426 case WPAS_MODE_MESH:
2427 ret = os_snprintf(pos, end - pos,
2428 "mode=mesh\n");
2429 break;
2430 default:
2431 ret = 0;
2432 break;
2433 }
2434 if (os_snprintf_error(end - pos, ret))
2435 return pos - buf;
2436 pos += ret;
2437 }
2438
2439 if (wpa_s->connection_set &&
2440 (wpa_s->connection_ht || wpa_s->connection_vht ||
2441 wpa_s->connection_he || wpa_s->connection_eht)) {
2442 ret = os_snprintf(pos, end - pos,
2443 "wifi_generation=%u\n",
2444 wpa_s->connection_eht ? 7 :
2445 (wpa_s->connection_he ? 6 :
2446 (wpa_s->connection_vht ? 5 : 4)));
2447 if (os_snprintf_error(end - pos, ret))
2448 return pos - buf;
2449 pos += ret;
2450 }
2451 #ifdef CONFIG_WAPI
2452 if (ssid->wapi) {
2453 wpa_printf(MSG_DEBUG, "wapi_get_cipher_key_mgmt");
2454 pos += wapi_get_cipher_key_mgmt(ssid->key_mgmt, pos, end - pos, verbose);
2455 if (ssid->key_mgmt == WPA_KEY_MGMT_WAPI_PSK)
2456 pos += wapi_get_psk_key_type(ssid->psk_key_type, pos,
2457 end - pos, verbose);
2458 } else
2459 #endif
2460 #ifdef CONFIG_AP
2461 if (wpa_s->ap_iface) {
2462 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2463 end - pos,
2464 verbose);
2465 } else
2466 #endif /* CONFIG_AP */
2467 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2468 }
2469 #ifdef CONFIG_SME
2470 #ifdef CONFIG_SAE
2471 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
2472 #ifdef CONFIG_AP
2473 !wpa_s->ap_iface &&
2474 #endif /* CONFIG_AP */
2475 wpa_s->sme.sae.state == SAE_ACCEPTED) {
2476 ret = os_snprintf(pos, end - pos, "sae_group=%d\n"
2477 "sae_h2e=%d\n"
2478 "sae_pk=%d\n",
2479 wpa_s->sme.sae.group,
2480 wpa_s->sme.sae.h2e,
2481 wpa_s->sme.sae.pk);
2482 if (os_snprintf_error(end - pos, ret))
2483 return pos - buf;
2484 pos += ret;
2485 }
2486 #endif /* CONFIG_SAE */
2487 #endif /* CONFIG_SME */
2488 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2489 wpa_supplicant_state_txt(wpa_s->wpa_state));
2490 if (os_snprintf_error(end - pos, ret))
2491 return pos - buf;
2492 pos += ret;
2493
2494 if (wpa_s->l2 &&
2495 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2496 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
2497 if (os_snprintf_error(end - pos, ret))
2498 return pos - buf;
2499 pos += ret;
2500 }
2501
2502 #ifdef CONFIG_P2P
2503 if (wpa_s->global->p2p) {
2504 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2505 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
2506 if (os_snprintf_error(end - pos, ret))
2507 return pos - buf;
2508 pos += ret;
2509 }
2510 #endif /* CONFIG_P2P */
2511
2512 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2513 MAC2STR(wpa_s->own_addr));
2514 if (os_snprintf_error(end - pos, ret))
2515 return pos - buf;
2516 pos += ret;
2517
2518 if (wpa_s->valid_links) {
2519 ret = os_snprintf(pos, end - pos, "ap_mld_addr=" MACSTR "\n",
2520 MAC2STR(wpa_s->ap_mld_addr));
2521 if (os_snprintf_error(end - pos, ret))
2522 return pos - buf;
2523 pos += ret;
2524 }
2525
2526 #ifdef CONFIG_HS20
2527 if (wpa_s->current_bss &&
2528 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2529 HS20_IE_VENDOR_TYPE)) &&
2530 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2531 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2532 int release = 1;
2533 if (hs20[1] >= 5) {
2534 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2535 release = rel_num + 1;
2536 }
2537 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
2538 if (os_snprintf_error(end - pos, ret))
2539 return pos - buf;
2540 pos += ret;
2541 }
2542
2543 if (wpa_s->current_ssid) {
2544 struct wpa_cred *cred;
2545 char *type;
2546
2547 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
2548 size_t i;
2549
2550 if (wpa_s->current_ssid->parent_cred != cred)
2551 continue;
2552
2553 if (cred->provisioning_sp) {
2554 ret = os_snprintf(pos, end - pos,
2555 "provisioning_sp=%s\n",
2556 cred->provisioning_sp);
2557 if (os_snprintf_error(end - pos, ret))
2558 return pos - buf;
2559 pos += ret;
2560 }
2561
2562 if (!cred->domain)
2563 goto no_domain;
2564
2565 i = 0;
2566 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2567 struct wpabuf *names =
2568 wpa_s->current_bss->anqp->domain_name;
2569 for (i = 0; names && i < cred->num_domain; i++)
2570 {
2571 if (domain_name_list_contains(
2572 names, cred->domain[i], 1))
2573 break;
2574 }
2575 if (i == cred->num_domain)
2576 i = 0; /* show first entry by default */
2577 }
2578 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2579 cred->domain[i]);
2580 if (os_snprintf_error(end - pos, ret))
2581 return pos - buf;
2582 pos += ret;
2583
2584 no_domain:
2585 if (wpa_s->current_bss == NULL ||
2586 wpa_s->current_bss->anqp == NULL)
2587 res = -1;
2588 else
2589 res = interworking_home_sp_cred(
2590 wpa_s, cred,
2591 wpa_s->current_bss->anqp->domain_name);
2592 if (res > 0)
2593 type = "home";
2594 else if (res == 0)
2595 type = "roaming";
2596 else
2597 type = "unknown";
2598
2599 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
2600 if (os_snprintf_error(end - pos, ret))
2601 return pos - buf;
2602 pos += ret;
2603
2604 break;
2605 }
2606 }
2607 #endif /* CONFIG_HS20 */
2608
2609 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2610 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2611 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2612 verbose);
2613 if (res >= 0)
2614 pos += res;
2615 }
2616
2617 #ifdef CONFIG_MACSEC
2618 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2619 if (res > 0)
2620 pos += res;
2621 #endif /* CONFIG_MACSEC */
2622
2623 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2624 if (sess_id) {
2625 char *start = pos;
2626
2627 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2628 if (os_snprintf_error(end - pos, ret))
2629 return start - buf;
2630 pos += ret;
2631 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2632 if (ret <= 0)
2633 return start - buf;
2634 pos += ret;
2635 ret = os_snprintf(pos, end - pos, "\n");
2636 if (os_snprintf_error(end - pos, ret))
2637 return start - buf;
2638 pos += ret;
2639 }
2640
2641 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2642 if (res >= 0)
2643 pos += res;
2644
2645 #ifdef CONFIG_WPS
2646 {
2647 char uuid_str[100];
2648 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2649 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
2650 if (os_snprintf_error(end - pos, ret))
2651 return pos - buf;
2652 pos += ret;
2653 }
2654 #endif /* CONFIG_WPS */
2655
2656 if (wpa_s->ieee80211ac) {
2657 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2658 if (os_snprintf_error(end - pos, ret))
2659 return pos - buf;
2660 pos += ret;
2661 }
2662
2663 #ifdef CONFIG_SME
2664 if (wpa_s->sme.bss_max_idle_period) {
2665 ret = os_snprintf(pos, end - pos, "bss_max_idle_period=%d\n",
2666 wpa_s->sme.bss_max_idle_period);
2667 if (os_snprintf_error(end - pos, ret))
2668 return pos - buf;
2669 pos += ret;
2670 }
2671 #endif /* CONFIG_SME */
2672
2673 if (wpa_s->ssid_verified) {
2674 ret = os_snprintf(pos, end - pos, "ssid_verified=1\n");
2675 if (os_snprintf_error(end - pos, ret))
2676 return pos - buf;
2677 pos += ret;
2678 }
2679
2680 if (wpa_s->bigtk_set) {
2681 ret = os_snprintf(pos, end - pos, "bigtk_set=1\n");
2682 if (os_snprintf_error(end - pos, ret))
2683 return pos - buf;
2684 pos += ret;
2685 }
2686
2687 #ifdef ANDROID
2688 /*
2689 * Allow using the STATUS command with default behavior, say for debug,
2690 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2691 * events with STATUS-NO_EVENTS.
2692 */
2693 if (os_strcmp(params, "-NO_EVENTS")) {
2694 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2695 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2696 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2697 wpa_s->wpa_state,
2698 MAC2STR(wpa_s->bssid),
2699 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2700 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2701 wpa_s->current_ssid->ssid_len) : "");
2702 if (wpa_s->wpa_state == WPA_COMPLETED) {
2703 struct wpa_ssid *ssid = wpa_s->current_ssid;
2704 char mld_addr[50];
2705
2706 mld_addr[0] = '\0';
2707 if (wpa_s->valid_links)
2708 os_snprintf(mld_addr, sizeof(mld_addr),
2709 " ap_mld_addr=" MACSTR,
2710 MAC2STR(wpa_s->ap_mld_addr));
2711
2712 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2713 "- connection to " MACSTR
2714 " completed %s [id=%d id_str=%s]%s",
2715 MAC2STR(wpa_s->bssid), "(auth)",
2716 ssid ? ssid->id : -1,
2717 ssid && ssid->id_str ? ssid->id_str : "",
2718 mld_addr);
2719 }
2720 }
2721 #endif /* ANDROID */
2722
2723 return pos - buf;
2724 }
2725
wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant * wpa_s,char * cmd)2726 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2727 char *cmd)
2728 {
2729 char *pos;
2730 int id;
2731 struct wpa_ssid *ssid;
2732 u8 bssid[ETH_ALEN];
2733
2734 /* cmd: "<network id> <BSSID>" */
2735 pos = os_strchr(cmd, ' ');
2736 if (pos == NULL)
2737 return -1;
2738 *pos++ = '\0';
2739 id = atoi(cmd);
2740 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, anonymize_common(pos));
2741 if (hwaddr_aton(pos, bssid)) {
2742 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", anonymize_common(pos));
2743 return -1;
2744 }
2745
2746 ssid = wpa_config_get_network(wpa_s->conf, id);
2747 if (ssid == NULL) {
2748 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2749 "to update", id);
2750 return -1;
2751 }
2752
2753 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2754 ssid->bssid_set = !is_zero_ether_addr(bssid);
2755
2756 return 0;
2757 }
2758
2759
wpa_supplicant_ctrl_iface_bssid_ignore(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)2760 static int wpa_supplicant_ctrl_iface_bssid_ignore(struct wpa_supplicant *wpa_s,
2761 char *cmd, char *buf,
2762 size_t buflen)
2763 {
2764 u8 bssid[ETH_ALEN];
2765 struct wpa_bssid_ignore *e;
2766 char *pos, *end;
2767 int ret;
2768
2769 /* cmd: "BSSID_IGNORE [<BSSID>]" */
2770 if (*cmd == '\0') {
2771 pos = buf;
2772 end = buf + buflen;
2773 e = wpa_s->bssid_ignore;
2774 while (e) {
2775 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2776 MAC2STR(e->bssid));
2777 if (os_snprintf_error(end - pos, ret))
2778 return pos - buf;
2779 pos += ret;
2780 e = e->next;
2781 }
2782 return pos - buf;
2783 }
2784
2785 cmd++;
2786 if (os_strncmp(cmd, "clear", 5) == 0) {
2787 wpa_bssid_ignore_clear(wpa_s);
2788 os_memcpy(buf, "OK\n", 3);
2789 return 3;
2790 }
2791
2792 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BSSID_IGNORE bssid='%s'", cmd);
2793 if (hwaddr_aton(cmd, bssid)) {
2794 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
2795 return -1;
2796 }
2797
2798 /*
2799 * Add the BSSID twice, so its count will be 2, causing it to be
2800 * skipped when processing scan results.
2801 */
2802 ret = wpa_bssid_ignore_add(wpa_s, bssid);
2803 if (ret < 0)
2804 return -1;
2805 ret = wpa_bssid_ignore_add(wpa_s, bssid);
2806 if (ret < 0)
2807 return -1;
2808 os_memcpy(buf, "OK\n", 3);
2809 return 3;
2810 }
2811
2812
wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)2813 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2814 char *cmd, char *buf,
2815 size_t buflen)
2816 {
2817 char *pos, *end, *stamp;
2818 int ret;
2819
2820 /* cmd: "LOG_LEVEL [<level>]" */
2821 if (*cmd == '\0') {
2822 pos = buf;
2823 end = buf + buflen;
2824 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2825 "Timestamp: %d\n",
2826 debug_level_str(wpa_debug_level),
2827 wpa_debug_timestamp);
2828 if (os_snprintf_error(end - pos, ret))
2829 ret = 0;
2830
2831 return ret;
2832 }
2833
2834 while (*cmd == ' ')
2835 cmd++;
2836
2837 stamp = os_strchr(cmd, ' ');
2838 if (stamp) {
2839 *stamp++ = '\0';
2840 while (*stamp == ' ') {
2841 stamp++;
2842 }
2843 }
2844
2845 if (os_strlen(cmd)) {
2846 int level = str_to_debug_level(cmd);
2847 if (level < 0)
2848 return -1;
2849 wpa_debug_level = level;
2850 }
2851
2852 if (stamp && os_strlen(stamp))
2853 wpa_debug_timestamp = atoi(stamp);
2854
2855 os_memcpy(buf, "OK\n", 3);
2856 return 3;
2857 }
2858
2859
wpa_supplicant_ctrl_iface_list_networks(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)2860 int wpa_supplicant_ctrl_iface_list_networks(
2861 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2862 {
2863 char *pos, *end, *prev;
2864 struct wpa_ssid *ssid;
2865 int ret;
2866
2867 pos = buf;
2868 end = buf + buflen;
2869 ret = os_snprintf(pos, end - pos,
2870 "network id / ssid / bssid / flags\n");
2871 if (os_snprintf_error(end - pos, ret))
2872 return pos - buf;
2873 pos += ret;
2874
2875 ssid = wpa_s->conf->ssid;
2876
2877 /* skip over ssids until we find next one */
2878 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2879 int last_id = atoi(cmd + 8);
2880 if (last_id != -1) {
2881 while (ssid != NULL && ssid->id <= last_id) {
2882 ssid = ssid->next;
2883 }
2884 }
2885 }
2886
2887 while (ssid) {
2888 prev = pos;
2889 ret = os_snprintf(pos, end - pos, "%d\t%s",
2890 ssid->id,
2891 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2892 if (os_snprintf_error(end - pos, ret))
2893 return prev - buf;
2894 pos += ret;
2895 if (ssid->bssid_set) {
2896 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2897 MAC2STR(ssid->bssid));
2898 } else {
2899 ret = os_snprintf(pos, end - pos, "\tany");
2900 }
2901 if (os_snprintf_error(end - pos, ret))
2902 return prev - buf;
2903 pos += ret;
2904 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2905 ssid == wpa_s->current_ssid ?
2906 "[CURRENT]" : "",
2907 ssid->disabled ? "[DISABLED]" : "",
2908 ssid->disabled_until.sec ?
2909 "[TEMP-DISABLED]" : "",
2910 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2911 "");
2912 if (os_snprintf_error(end - pos, ret))
2913 return prev - buf;
2914 pos += ret;
2915 ret = os_snprintf(pos, end - pos, "\n");
2916 if (os_snprintf_error(end - pos, ret))
2917 return prev - buf;
2918 pos += ret;
2919
2920 ssid = ssid->next;
2921 }
2922
2923 return pos - buf;
2924 }
2925
2926
wpa_supplicant_cipher_txt(char * pos,char * end,int cipher)2927 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2928 {
2929 int ret;
2930 ret = os_snprintf(pos, end - pos, "-");
2931 if (os_snprintf_error(end - pos, ret))
2932 return pos;
2933 pos += ret;
2934 ret = wpa_write_ciphers(pos, end, cipher, "+");
2935 if (ret < 0)
2936 return pos;
2937 pos += ret;
2938 return pos;
2939 }
2940
2941 #ifdef CONFIG_WAPI
2942 #define WAPIIE_ELEMENT_ID_LEN 1
2943 #define WAPIIE_LENGTH_LEN 1
2944 #define WAPIIE_VERSION_LEN 2
2945 #define WAPIIE_AKM_CNT_LEN 2
2946 #define WAPIIE_AKM_SUIT_LEN 4
2947 #define WAPIIE_AKM_SUIT_CERT 0x00147201
2948 #define WAPIIE_AKM_SUIT_PSK 0x00147202
2949 #define WAPI_HEAD_LEN (WAPIIE_ELEMENT_ID_LEN + WAPIIE_LENGTH_LEN + WAPIIE_VERSION_LEN + 2)
2950 #define AKM_SUIT_CNT_MAX 2
2951 #define SHIFT_OPT8 8
2952 #define MY_GET32(p) ((((*p) << 24) & 0xff000000) | (((*(p+1)) << 16) & 0xff0000) | \
2953 (((*(p+2)) << 8) & 0xff00) | ((*(p+3)) & 0xff))
2954
wpa_supplicant_wapi_ie_txt(char * pos,char * end,const u8 * ie,size_t ie_len)2955 static char *wpa_supplicant_wapi_ie_txt(char *pos, char *end,
2956 const u8 *ie, size_t ie_len)
2957 {
2958 int i, ret;
2959 u8 *ie_hdr = (u8 *)ie, *p_akm_auit_cnt, *p_akm;
2960 int akm_suit_cnt = 0;
2961 char *old_pos = pos;
2962
2963 if (ie_len < WAPI_HEAD_LEN) {
2964 wpa_printf(MSG_ERROR, "ie_len is too short, ie_len = %zu(<6)", ie_len);
2965 return old_pos;
2966 }
2967
2968 p_akm_auit_cnt = ie_hdr + (WAPIIE_ELEMENT_ID_LEN + WAPIIE_LENGTH_LEN + WAPIIE_VERSION_LEN);
2969 akm_suit_cnt = ((*p_akm_auit_cnt) | ((*(p_akm_auit_cnt + 1) << SHIFT_OPT8) & 0xff00)) & 0xffff;
2970 if (akm_suit_cnt > AKM_SUIT_CNT_MAX) {
2971 wpa_printf(MSG_ERROR, "akm_suit_cnt: %d is error!", akm_suit_cnt);
2972 return old_pos;
2973 }
2974 if (ie_len < (size_t)(WAPI_HEAD_LEN + akm_suit_cnt * WAPIIE_AKM_SUIT_LEN)) {
2975 wpa_printf(MSG_ERROR, "ie_len is too short, ie_len = %zu(<6), need more than: %d",
2976 ie_len, (WAPI_HEAD_LEN + akm_suit_cnt * WAPIIE_AKM_SUIT_LEN));
2977 return old_pos;
2978 }
2979 p_akm = (p_akm_auit_cnt + WAPIIE_AKM_CNT_LEN);
2980 for (i = 0; i < akm_suit_cnt; i++) {
2981 if (MY_GET32(p_akm) == WAPIIE_AKM_SUIT_PSK) {
2982 wpa_printf(MSG_DEBUG, "AKM_SUIT is : [WAPI-PSK]");
2983 ret = os_snprintf(pos, end - pos, "[WAPI-KEY]");
2984 if (os_snprintf_error(end - pos, ret)) {
2985 wpa_printf(MSG_ERROR, "snprintf failed.");
2986 return pos;
2987 }
2988 pos += ret;
2989 } else if (MY_GET32(p_akm) == WAPIIE_AKM_SUIT_CERT) {
2990 wpa_printf(MSG_DEBUG, "AKM_SUIT is : [WAPI-CERT]");
2991 ret = os_snprintf(pos, end - pos, "[WAPI-CERT]");
2992 if (os_snprintf_error(end - pos, ret)) {
2993 wpa_printf(MSG_ERROR, "snprintf failed.");
2994 return pos;
2995 }
2996 pos += ret;
2997 }
2998 p_akm += WAPIIE_AKM_SUIT_LEN;
2999 }
3000 return pos;
3001 }
3002 #endif
3003
wpa_supplicant_ie_txt(char * pos,char * end,const char * proto,const u8 * ie,size_t ie_len)3004 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
3005 const u8 *ie, size_t ie_len)
3006 {
3007 struct wpa_ie_data data;
3008 char *start;
3009 int ret;
3010
3011 ret = os_snprintf(pos, end - pos, "[%s-", proto);
3012 if (os_snprintf_error(end - pos, ret))
3013 return pos;
3014 pos += ret;
3015
3016 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
3017 ret = os_snprintf(pos, end - pos, "?]");
3018 if (os_snprintf_error(end - pos, ret))
3019 return pos;
3020 pos += ret;
3021 return pos;
3022 }
3023
3024 start = pos;
3025 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
3026 ret = os_snprintf(pos, end - pos, "%sEAP",
3027 pos == start ? "" : "+");
3028 if (os_snprintf_error(end - pos, ret))
3029 return pos;
3030 pos += ret;
3031 }
3032 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
3033 ret = os_snprintf(pos, end - pos, "%sPSK",
3034 pos == start ? "" : "+");
3035 if (os_snprintf_error(end - pos, ret))
3036 return pos;
3037 pos += ret;
3038 }
3039 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
3040 ret = os_snprintf(pos, end - pos, "%sNone",
3041 pos == start ? "" : "+");
3042 if (os_snprintf_error(end - pos, ret))
3043 return pos;
3044 pos += ret;
3045 }
3046 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
3047 ret = os_snprintf(pos, end - pos, "%sSAE",
3048 pos == start ? "" : "+");
3049 if (os_snprintf_error(end - pos, ret))
3050 return pos;
3051 pos += ret;
3052 }
3053 if (data.key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) {
3054 ret = os_snprintf(pos, end - pos, "%sSAE-EXT-KEY",
3055 pos == start ? "" : "+");
3056 if (os_snprintf_error(end - pos, ret))
3057 return pos;
3058 pos += ret;
3059 }
3060 #ifdef CONFIG_IEEE80211R
3061 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
3062 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
3063 pos == start ? "" : "+");
3064 if (os_snprintf_error(end - pos, ret))
3065 return pos;
3066 pos += ret;
3067 }
3068 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
3069 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
3070 pos == start ? "" : "+");
3071 if (os_snprintf_error(end - pos, ret))
3072 return pos;
3073 pos += ret;
3074 }
3075 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
3076 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
3077 pos == start ? "" : "+");
3078 if (os_snprintf_error(end - pos, ret))
3079 return pos;
3080 pos += ret;
3081 }
3082 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE_EXT_KEY) {
3083 ret = os_snprintf(pos, end - pos, "%sFT/SAE-EXT-KEY",
3084 pos == start ? "" : "+");
3085 if (os_snprintf_error(end - pos, ret))
3086 return pos;
3087 pos += ret;
3088 }
3089 #endif /* CONFIG_IEEE80211R */
3090 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
3091 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
3092 pos == start ? "" : "+");
3093 if (os_snprintf_error(end - pos, ret))
3094 return pos;
3095 pos += ret;
3096 }
3097 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
3098 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
3099 pos == start ? "" : "+");
3100 if (os_snprintf_error(end - pos, ret))
3101 return pos;
3102 pos += ret;
3103 }
3104
3105 #ifdef CONFIG_SUITEB
3106 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
3107 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
3108 pos == start ? "" : "+");
3109 if (os_snprintf_error(end - pos, ret))
3110 return pos;
3111 pos += ret;
3112 }
3113 #endif /* CONFIG_SUITEB */
3114
3115 #ifdef CONFIG_SUITEB192
3116 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
3117 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
3118 pos == start ? "" : "+");
3119 if (os_snprintf_error(end - pos, ret))
3120 return pos;
3121 pos += ret;
3122 }
3123 #endif /* CONFIG_SUITEB192 */
3124
3125 #ifdef CONFIG_FILS
3126 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
3127 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
3128 pos == start ? "" : "+");
3129 if (os_snprintf_error(end - pos, ret))
3130 return pos;
3131 pos += ret;
3132 }
3133 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
3134 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
3135 pos == start ? "" : "+");
3136 if (os_snprintf_error(end - pos, ret))
3137 return pos;
3138 pos += ret;
3139 }
3140 #ifdef CONFIG_IEEE80211R
3141 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
3142 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
3143 pos == start ? "" : "+");
3144 if (os_snprintf_error(end - pos, ret))
3145 return pos;
3146 pos += ret;
3147 }
3148 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
3149 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
3150 pos == start ? "" : "+");
3151 if (os_snprintf_error(end - pos, ret))
3152 return pos;
3153 pos += ret;
3154 }
3155 #endif /* CONFIG_IEEE80211R */
3156 #endif /* CONFIG_FILS */
3157
3158 #ifdef CONFIG_OWE
3159 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
3160 ret = os_snprintf(pos, end - pos, "%sOWE",
3161 pos == start ? "" : "+");
3162 if (os_snprintf_error(end - pos, ret))
3163 return pos;
3164 pos += ret;
3165 }
3166 #endif /* CONFIG_OWE */
3167
3168 #ifdef CONFIG_DPP
3169 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
3170 ret = os_snprintf(pos, end - pos, "%sDPP",
3171 pos == start ? "" : "+");
3172 if (os_snprintf_error(end - pos, ret))
3173 return pos;
3174 pos += ret;
3175 }
3176 #endif /* CONFIG_DPP */
3177
3178 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
3179 ret = os_snprintf(pos, end - pos, "%sOSEN",
3180 pos == start ? "" : "+");
3181 if (os_snprintf_error(end - pos, ret))
3182 return pos;
3183 pos += ret;
3184 }
3185
3186 #ifdef CONFIG_SHA384
3187 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA384) {
3188 ret = os_snprintf(pos, end - pos, "%sEAP-SHA384",
3189 pos == start ? "" : "+");
3190 if (os_snprintf_error(end - pos, ret))
3191 return pos;
3192 pos += ret;
3193 }
3194 #endif /* CONFIG_SHA384 */
3195
3196 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
3197
3198 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
3199 ret = os_snprintf(pos, end - pos, "-preauth");
3200 if (os_snprintf_error(end - pos, ret))
3201 return pos;
3202 pos += ret;
3203 }
3204
3205 ret = os_snprintf(pos, end - pos, "]");
3206 if (os_snprintf_error(end - pos, ret))
3207 return pos;
3208 pos += ret;
3209
3210 return pos;
3211 }
3212
3213
3214 #ifdef CONFIG_WPS
wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant * wpa_s,char * pos,char * end,struct wpabuf * wps_ie)3215 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
3216 char *pos, char *end,
3217 struct wpabuf *wps_ie)
3218 {
3219 int ret;
3220 const char *txt;
3221
3222 if (wps_ie == NULL)
3223 return pos;
3224 if (wps_is_selected_pbc_registrar(wps_ie))
3225 txt = "[WPS-PBC]";
3226 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
3227 txt = "[WPS-AUTH]";
3228 else if (wps_is_selected_pin_registrar(wps_ie))
3229 txt = "[WPS-PIN]";
3230 else
3231 txt = "[WPS]";
3232
3233 ret = os_snprintf(pos, end - pos, "%s", txt);
3234 if (!os_snprintf_error(end - pos, ret))
3235 pos += ret;
3236 wpabuf_free(wps_ie);
3237 return pos;
3238 }
3239 #endif /* CONFIG_WPS */
3240
3241
wpa_supplicant_wps_ie_txt(struct wpa_supplicant * wpa_s,char * pos,char * end,const struct wpa_bss * bss)3242 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
3243 char *pos, char *end,
3244 const struct wpa_bss *bss)
3245 {
3246 #ifdef CONFIG_WPS
3247 struct wpabuf *wps_ie;
3248 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
3249 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
3250 #else /* CONFIG_WPS */
3251 return pos;
3252 #endif /* CONFIG_WPS */
3253 }
3254
3255
3256 /* Format one result on one text line into a buffer. */
wpa_supplicant_ctrl_iface_scan_result(struct wpa_supplicant * wpa_s,const struct wpa_bss * bss,char * buf,size_t buflen)3257 static int wpa_supplicant_ctrl_iface_scan_result(
3258 struct wpa_supplicant *wpa_s,
3259 const struct wpa_bss *bss, char *buf, size_t buflen)
3260 {
3261 char *pos, *end;
3262 int ret;
3263 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe, *rsnxe;
3264 #ifdef CONFIG_OPEN_HARMONY_PATCH
3265 const u8 *infoEle;
3266 #endif
3267 #ifdef CONFIG_WAPI
3268 const u8 *ie3;
3269 #endif
3270
3271 wpa_printf(MSG_INFO, "enter wpa_supplicant_ctrl_iface_scan_result");
3272
3273 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
3274 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
3275 if (!p2p)
3276 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
3277 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
3278 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
3279 0)
3280 return 0; /* Do not show P2P listen discovery results here */
3281
3282 pos = buf;
3283 end = buf + buflen;
3284
3285 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
3286 MAC2STR(bss->bssid), bss->freq, bss->level);
3287 if (os_snprintf_error(end - pos, ret))
3288 return -1;
3289 pos += ret;
3290 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3291 if (ie)
3292 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
3293 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3294 if (ie2) {
3295 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
3296 ie2, 2 + ie2[1]);
3297 }
3298 #ifdef CONFIG_WAPI
3299 ie3 = wpa_bss_get_ie(bss, WLAN_EID_WAPI);
3300 if (ie3) {
3301 char *pos_b = pos;
3302 pos = wpa_supplicant_wapi_ie_txt(pos, end, ie3, 2 + ie3[1]);
3303 if (pos == pos_b) {
3304 ie3 = NULL;
3305 }
3306 }
3307 #endif
3308 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
3309 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
3310 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
3311 if (os_snprintf_error(end - pos, ret))
3312 return -1;
3313 pos += ret;
3314 }
3315 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
3316 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
3317 if (os_snprintf_error(end - pos, ret))
3318 return -1;
3319 pos += ret;
3320 }
3321 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
3322 if (osen_ie)
3323 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
3324 osen_ie, 2 + osen_ie[1]);
3325 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
3326 if (owe) {
3327 ret = os_snprintf(pos, end - pos,
3328 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
3329 if (os_snprintf_error(end - pos, ret))
3330 return -1;
3331 pos += ret;
3332 }
3333 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3334 #ifdef CONFIG_WAPI
3335 if (!ie && !ie2 && !ie3 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
3336 #else
3337 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
3338 #endif
3339 ret = os_snprintf(pos, end - pos, "[WEP]");
3340 if (os_snprintf_error(end - pos, ret))
3341 return -1;
3342 pos += ret;
3343 }
3344 if (mesh) {
3345 ret = os_snprintf(pos, end - pos, "[MESH]");
3346 if (os_snprintf_error(end - pos, ret))
3347 return -1;
3348 pos += ret;
3349 }
3350 if (bss_is_dmg(bss)) {
3351 const char *s;
3352
3353 if (wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_EDMG_OPERATION)) {
3354 ret = os_snprintf(pos, end - pos, "[EDMG]");
3355 if (os_snprintf_error(end - pos, ret))
3356 return -1;
3357 pos += ret;
3358 }
3359
3360 ret = os_snprintf(pos, end - pos, "[DMG]");
3361 if (os_snprintf_error(end - pos, ret))
3362 return -1;
3363 pos += ret;
3364 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3365 case IEEE80211_CAP_DMG_IBSS:
3366 s = "[IBSS]";
3367 break;
3368 case IEEE80211_CAP_DMG_AP:
3369 s = "[ESS]";
3370 break;
3371 case IEEE80211_CAP_DMG_PBSS:
3372 s = "[PBSS]";
3373 break;
3374 default:
3375 s = "";
3376 break;
3377 }
3378 ret = os_snprintf(pos, end - pos, "%s", s);
3379 if (os_snprintf_error(end - pos, ret))
3380 return -1;
3381 pos += ret;
3382 } else {
3383 if (bss->caps & IEEE80211_CAP_IBSS) {
3384 ret = os_snprintf(pos, end - pos, "[IBSS]");
3385 if (os_snprintf_error(end - pos, ret))
3386 return -1;
3387 pos += ret;
3388 }
3389 if (bss->caps & IEEE80211_CAP_ESS) {
3390 ret = os_snprintf(pos, end - pos, "[ESS]");
3391 if (os_snprintf_error(end - pos, ret))
3392 return -1;
3393 pos += ret;
3394 }
3395 }
3396 if (p2p) {
3397 ret = os_snprintf(pos, end - pos, "[P2P]");
3398 if (os_snprintf_error(end - pos, ret))
3399 return -1;
3400 pos += ret;
3401 }
3402 #ifdef CONFIG_HS20
3403 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
3404 ret = os_snprintf(pos, end - pos, "[HS20]");
3405 if (os_snprintf_error(end - pos, ret))
3406 return -1;
3407 pos += ret;
3408 }
3409 #endif /* CONFIG_HS20 */
3410 #ifdef CONFIG_FILS
3411 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
3412 ret = os_snprintf(pos, end - pos, "[FILS]");
3413 if (os_snprintf_error(end - pos, ret))
3414 return -1;
3415 pos += ret;
3416 }
3417 #endif /* CONFIG_FILS */
3418 #ifdef CONFIG_FST
3419 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
3420 ret = os_snprintf(pos, end - pos, "[FST]");
3421 if (os_snprintf_error(end - pos, ret))
3422 return -1;
3423 pos += ret;
3424 }
3425 #endif /* CONFIG_FST */
3426 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
3427 ret = os_snprintf(pos, end - pos, "[UTF-8]");
3428 if (os_snprintf_error(end - pos, ret))
3429 return -1;
3430 pos += ret;
3431 }
3432 #ifdef CONFIG_OPEN_HARMONY_PATCH
3433 ret = os_snprintf(pos, end - pos, "\t%s\t",
3434 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3435 #else
3436 ret = os_snprintf(pos, end - pos, "\t%s",
3437 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3438 #endif
3439
3440 if (os_snprintf_error(end - pos, ret))
3441 return -1;
3442 pos += ret;
3443 #ifdef CONFIG_OPEN_HARMONY_PATCH
3444 for (int j = 0; j < WLAN_EID_EXTENSION; j++) {
3445 if ((j != WLAN_EID_VHT_OPERATION) && (j != WLAN_EID_HT_OPERATION) &&
3446 (j != WLAN_EID_SUPPORTED_CHANNELS) && (j != WLAN_EID_COUNTRY)) {
3447 continue;
3448 }
3449 infoEle = wpa_bss_get_ie(bss, j);
3450 if (infoEle && infoEle[1] > 0) {
3451 ret = os_snprintf(pos, end - pos, "[%d ", j);
3452 if (os_snprintf_error(end - pos, ret))
3453 return -1;
3454 pos += ret;
3455 for (u8 i = 0; i < infoEle[1]; i++) {
3456 ret = os_snprintf(pos, end - pos, "%02x", infoEle[i + 2]);
3457 if (os_snprintf_error(end - pos, ret))
3458 return -1;
3459 pos += ret;
3460 }
3461 ret = os_snprintf(pos, end - pos, "]");
3462 if (os_snprintf_error(end - pos, ret))
3463 return -1;
3464 pos += ret;
3465 }
3466 }
3467
3468 infoEle = wpa_bss_get_ie(bss, WLAN_EID_EXTENSION);
3469 if (infoEle) {
3470 unsigned int len = infoEle[1];
3471 if (len > 1 && infoEle[2] == WLAN_EID_EXT_HE_OPERATION) {
3472 ret = os_snprintf(pos, end - pos, "[%d %d ",
3473 WLAN_EID_EXTENSION, WLAN_EID_EXT_HE_OPERATION);
3474 if (os_snprintf_error(end - pos, ret))
3475 return -1;
3476 pos += ret;
3477 for (size_t i = 0; i < len; i++) {
3478 ret = os_snprintf(pos, end - pos, "%02x", infoEle[i + 3]);
3479 if (os_snprintf_error(end - pos, ret))
3480 return -1;
3481 pos += ret;
3482 }
3483 ret = os_snprintf(pos, end - pos, "]");
3484 if (os_snprintf_error(end - pos, ret))
3485 return -1;
3486 pos += ret;
3487 }
3488 }
3489 #endif
3490 ret = os_snprintf(pos, end - pos, "\n");
3491 if (os_snprintf_error(end - pos, ret))
3492 return -1;
3493 pos += ret;
3494
3495 return pos - buf;
3496 }
3497
3498
3499 int wpa_supplicant_ctrl_iface_scan_results(
3500 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3501 {
3502 char *pos, *end;
3503 struct wpa_bss *bss;
3504 int ret;
3505
3506 pos = buf;
3507 end = buf + buflen;
3508 #ifdef CONFIG_OPEN_HARMONY_PATCH
3509 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
3510 "flags / ssid / informationElements\n");
3511 #else
3512 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
3513 "flags / ssid\n");
3514 #endif
3515 if (os_snprintf_error(end - pos, ret))
3516 return pos - buf;
3517 pos += ret;
3518
3519 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3520 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
3521 end - pos);
3522 if (ret < 0 || ret >= end - pos)
3523 return pos - buf;
3524 pos += ret;
3525 }
3526
3527 return pos - buf;
3528 }
3529
3530
3531 #ifdef CONFIG_MESH
3532
3533 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3534 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
3535 {
3536 char *pos, ifname[IFNAMSIZ + 1];
3537
3538 ifname[0] = '\0';
3539
3540 pos = os_strstr(cmd, "ifname=");
3541 if (pos) {
3542 pos += 7;
3543 os_strlcpy(ifname, pos, sizeof(ifname));
3544 }
3545
3546 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
3547 return -1;
3548
3549 os_strlcpy(reply, ifname, max_len);
3550 return os_strlen(ifname);
3551 }
3552
3553
3554 static int wpa_supplicant_ctrl_iface_mesh_group_add(
3555 struct wpa_supplicant *wpa_s, char *cmd)
3556 {
3557 int id;
3558 struct wpa_ssid *ssid;
3559
3560 id = atoi(cmd);
3561 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
3562
3563 ssid = wpa_config_get_network(wpa_s->conf, id);
3564 if (ssid == NULL) {
3565 wpa_printf(MSG_DEBUG,
3566 "CTRL_IFACE: Could not find network id=%d", id);
3567 return -1;
3568 }
3569 if (ssid->mode != WPAS_MODE_MESH) {
3570 wpa_printf(MSG_DEBUG,
3571 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3572 return -1;
3573 }
3574 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
3575 ssid->key_mgmt != WPA_KEY_MGMT_SAE &&
3576 ssid->key_mgmt != WPA_KEY_MGMT_SAE_EXT_KEY) {
3577 wpa_printf(MSG_ERROR,
3578 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3579 return -1;
3580 }
3581
3582 /*
3583 * TODO: If necessary write our own group_add function,
3584 * for now we can reuse select_network
3585 */
3586 wpa_supplicant_select_network(wpa_s, ssid);
3587
3588 return 0;
3589 }
3590
3591
3592 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3593 struct wpa_supplicant *wpa_s, char *cmd)
3594 {
3595 struct wpa_supplicant *orig;
3596 struct wpa_global *global;
3597 int found = 0;
3598
3599 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3600
3601 global = wpa_s->global;
3602 orig = wpa_s;
3603
3604 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3605 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3606 found = 1;
3607 break;
3608 }
3609 }
3610 if (!found) {
3611 wpa_printf(MSG_ERROR,
3612 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3613 cmd);
3614 return -1;
3615 }
3616 if (wpa_s->mesh_if_created && wpa_s == orig) {
3617 wpa_printf(MSG_ERROR,
3618 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3619 return -1;
3620 }
3621
3622 wpa_s->reassociate = 0;
3623 wpa_s->disconnected = 1;
3624 wpa_supplicant_cancel_sched_scan(wpa_s);
3625 wpa_supplicant_cancel_scan(wpa_s);
3626
3627 /*
3628 * TODO: If necessary write our own group_remove function,
3629 * for now we can reuse deauthenticate
3630 */
3631 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3632
3633 if (wpa_s->mesh_if_created)
3634 wpa_supplicant_remove_iface(global, wpa_s, 0);
3635
3636 return 0;
3637 }
3638
3639
3640 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3641 struct wpa_supplicant *wpa_s, char *cmd)
3642 {
3643 u8 addr[ETH_ALEN];
3644
3645 if (hwaddr_aton(cmd, addr) < 0)
3646 return -1;
3647
3648 return wpas_mesh_peer_remove(wpa_s, addr);
3649 }
3650
3651
3652 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3653 struct wpa_supplicant *wpa_s, char *cmd)
3654 {
3655 u8 addr[ETH_ALEN];
3656 int duration;
3657 char *pos;
3658
3659 pos = os_strstr(cmd, " duration=");
3660 if (pos) {
3661 *pos = '\0';
3662 duration = atoi(pos + 10);
3663 } else {
3664 duration = -1;
3665 }
3666
3667 if (hwaddr_aton(cmd, addr))
3668 return -1;
3669
3670 return wpas_mesh_peer_add(wpa_s, addr, duration);
3671 }
3672
3673
3674 static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3675 struct wpa_supplicant *wpa_s, char *cmd)
3676 {
3677 struct ether_header *eth;
3678 u8 addr[ETH_ALEN];
3679 u8 *buf;
3680 char *pos;
3681 size_t payload_len = 0, len;
3682 int ret = -1;
3683
3684 if (hwaddr_aton(cmd, addr))
3685 return -1;
3686
3687 pos = os_strstr(cmd, " payload=");
3688 if (pos) {
3689 pos = pos + 9;
3690 payload_len = os_strlen(pos);
3691 if (payload_len & 1)
3692 return -1;
3693
3694 payload_len /= 2;
3695 }
3696
3697 len = ETH_HLEN + payload_len;
3698 buf = os_malloc(len);
3699 if (!buf)
3700 return -1;
3701
3702 eth = (struct ether_header *) buf;
3703 os_memcpy(eth->ether_dhost, addr, ETH_ALEN);
3704 os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN);
3705 eth->ether_type = htons(ETH_P_802_3);
3706
3707 if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0)
3708 goto fail;
3709
3710 ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len);
3711 fail:
3712 os_free(buf);
3713 return -ret;
3714 }
3715
3716 #endif /* CONFIG_MESH */
3717
3718
3719 int wpa_supplicant_ctrl_iface_select_network(
3720 struct wpa_supplicant *wpa_s, char *cmd)
3721 {
3722 int id;
3723 struct wpa_ssid *ssid;
3724 char *pos;
3725
3726 /* cmd: "<network id>" or "any" */
3727 if (os_strncmp(cmd, "any", 3) == 0) {
3728 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3729 ssid = NULL;
3730 } else {
3731 id = atoi(cmd);
3732 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3733
3734 ssid = wpa_config_get_network(wpa_s->conf, id);
3735 if (ssid == NULL) {
3736 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3737 "network id=%d", id);
3738 return -1;
3739 }
3740 if (ssid->disabled == 2) {
3741 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3742 "SELECT_NETWORK with persistent P2P group");
3743 return -1;
3744 }
3745 }
3746
3747 pos = os_strstr(cmd, " freq=");
3748 if (pos) {
3749 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3750 if (freqs) {
3751 os_free(wpa_s->select_network_scan_freqs);
3752 wpa_s->select_network_scan_freqs = freqs;
3753 }
3754 }
3755
3756 wpa_s->scan_min_time.sec = 0;
3757 wpa_s->scan_min_time.usec = 0;
3758 wpa_supplicant_select_network(wpa_s, ssid);
3759
3760 return 0;
3761 }
3762
3763
3764 int wpa_supplicant_ctrl_iface_enable_network(
3765 struct wpa_supplicant *wpa_s, char *cmd)
3766 {
3767 int id;
3768 struct wpa_ssid *ssid;
3769
3770 /* cmd: "<network id>" or "all" */
3771 if (os_strcmp(cmd, "all") == 0) {
3772 wpa_printf(MSG_INFO, "CTRL_IFACE: ENABLE_NETWORK all");
3773 ssid = NULL;
3774 } else {
3775 id = atoi(cmd);
3776 wpa_printf(MSG_INFO, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3777
3778 ssid = wpa_config_get_network(wpa_s->conf, id);
3779 if (ssid == NULL) {
3780 wpa_printf(MSG_INFO, "CTRL_IFACE: Could not find "
3781 "network id=%d", id);
3782 return -1;
3783 }
3784 if (ssid->disabled == 2) {
3785 wpa_printf(MSG_INFO, "CTRL_IFACE: Cannot use "
3786 "ENABLE_NETWORK with persistent P2P group");
3787 return -1;
3788 }
3789
3790 if (os_strstr(cmd, " no-connect")) {
3791 ssid->disabled = 0;
3792 return 0;
3793 }
3794 }
3795 wpa_s->scan_min_time.sec = 0;
3796 wpa_s->scan_min_time.usec = 0;
3797 wpa_supplicant_enable_network(wpa_s, ssid);
3798
3799 return 0;
3800 }
3801
3802
3803 int wpa_supplicant_ctrl_iface_disable_network(
3804 struct wpa_supplicant *wpa_s, char *cmd)
3805 {
3806 int id;
3807 struct wpa_ssid *ssid;
3808
3809 /* cmd: "<network id>" or "all" */
3810 if (os_strcmp(cmd, "all") == 0) {
3811 wpa_printf(MSG_INFO, "CTRL_IFACE: DISABLE_NETWORK all");
3812 ssid = NULL;
3813 } else {
3814 id = atoi(cmd);
3815 wpa_printf(MSG_INFO, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3816
3817 ssid = wpa_config_get_network(wpa_s->conf, id);
3818 if (ssid == NULL) {
3819 wpa_printf(MSG_INFO, "CTRL_IFACE: Could not find "
3820 "network id=%d", id);
3821 return -1;
3822 }
3823 if (ssid->disabled == 2) {
3824 wpa_printf(MSG_INFO, "CTRL_IFACE: Cannot use "
3825 "DISABLE_NETWORK with persistent P2P "
3826 "group");
3827 return -1;
3828 }
3829 }
3830 wpa_supplicant_disable_network(wpa_s, ssid);
3831
3832 return 0;
3833 }
3834
3835
3836 int wpa_supplicant_ctrl_iface_add_network(
3837 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3838 {
3839 struct wpa_ssid *ssid;
3840 int ret;
3841
3842 wpa_printf(MSG_INFO, "CTRL_IFACE: ADD_NETWORK");
3843
3844 ssid = wpa_supplicant_add_network(wpa_s);
3845 if (ssid == NULL) {
3846 wpa_printf(MSG_ERROR, "CTRL_IFACE: ssid is null!");
3847 return -1;
3848 }
3849
3850 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
3851 if (os_snprintf_error(buflen, ret))
3852 return -1;
3853 return ret;
3854 }
3855
3856
3857 int wpa_supplicant_ctrl_iface_remove_network(
3858 struct wpa_supplicant *wpa_s, char *cmd)
3859 {
3860 int id;
3861 int result;
3862
3863 /* cmd: "<network id>" or "all" */
3864 if (os_strcmp(cmd, "all") == 0) {
3865 wpa_printf(MSG_INFO, "CTRL_IFACE: REMOVE_NETWORK all");
3866 return wpa_supplicant_remove_all_networks(wpa_s);
3867 }
3868
3869 id = atoi(cmd);
3870 wpa_printf(MSG_INFO, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3871
3872 result = wpa_supplicant_remove_network(wpa_s, id);
3873 if (result == -1) {
3874 wpa_printf(MSG_INFO, "CTRL_IFACE: Could not find network "
3875 "id=%d", id);
3876 return -1;
3877 }
3878 if (result == -2) {
3879 wpa_printf(MSG_INFO, "CTRL_IFACE: Not able to remove the "
3880 "network id=%d", id);
3881 return -1;
3882 }
3883 return 0;
3884 }
3885
3886
3887 static int wpa_supplicant_ctrl_iface_update_network(
3888 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3889 char *name, char *value)
3890 {
3891 int ret;
3892
3893 ret = wpa_config_set(ssid, name, value, 0);
3894 if (ret < 0) {
3895 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3896 "variable '%s'", name);
3897 return -1;
3898 }
3899 if (ret == 1)
3900 return 0; /* No change to the previously configured value */
3901
3902 #ifdef CONFIG_BGSCAN
3903 if (os_strcmp(name, "bgscan") == 0) {
3904 /*
3905 * Reset the bgscan parameters for the current network and
3906 * return. There's no need to flush caches for bgscan parameter
3907 * changes.
3908 */
3909 if (wpa_s->current_ssid == ssid &&
3910 wpa_s->wpa_state == WPA_COMPLETED)
3911 wpa_supplicant_reset_bgscan(wpa_s);
3912 return 0;
3913 }
3914 #endif /* CONFIG_BGSCAN */
3915
3916 if (os_strcmp(name, "bssid") != 0 &&
3917 os_strncmp(name, "bssid_", 6) != 0 &&
3918 os_strcmp(name, "scan_freq") != 0 &&
3919 os_strcmp(name, "priority") != 0) {
3920 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3921
3922 if (wpa_s->current_ssid == ssid ||
3923 wpa_s->current_ssid == NULL) {
3924 /*
3925 * Invalidate the EAP session cache if anything in the
3926 * current or previously used configuration changes.
3927 */
3928 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3929 }
3930 }
3931
3932 if ((os_strcmp(name, "psk") == 0 &&
3933 value[0] == '"' && ssid->ssid_len) ||
3934 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3935 wpa_config_update_psk(ssid);
3936 else if (os_strcmp(name, "priority") == 0)
3937 wpa_config_update_prio_list(wpa_s->conf);
3938
3939 return 0;
3940 }
3941
3942 #ifdef CONFIG_EAP_AUTH
3943 static int wpa_supplicant_ctrl_iface_get_eap_params(
3944 char *name, char *value)
3945 {
3946 size_t i;
3947 char* eap_params[] = {"sim_kc", "sim_sres", "param_ki", "param_opc", "param_amf", "param_sqn"};
3948 char* simaka_params[] = {eapsim_params.kc, eapsim_params.sres, eapaka_params.ki,
3949 eapaka_params.opc, eapaka_params.amf, eapaka_params.sqn};
3950 for (i = 0; i < (sizeof(simaka_params) / sizeof(simaka_params[0])); i++) {
3951 if (os_strcmp(name, eap_params[i]) == 0) {
3952 os_memcpy(simaka_params[i], value, os_strlen(value));
3953 return 1;
3954 }
3955 }
3956 return 0;
3957 }
3958 #endif
3959
3960 #ifdef CONFIG_DRIVER_NL80211_HISI
3961 static void wpa_supplicant_ctrl_iface_skip_ft(
3962 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
3963 {
3964 struct i802_bss *bss = NULL;
3965 if (wpa_s != NULL && os_strncmp(wpa_s->ifname, "wlan1", strlen("wlan1")) == 0) {
3966 bss = (struct i802_bss *)wpa_s->drv_priv;
3967 if (bss != NULL && bss->drv != NULL && bss->drv->nlmode == NL80211_IFTYPE_STATION) {
3968 wpa_printf(MSG_DEBUG, "wlan1 skip FT");
3969 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_PSK) {
3970 ssid->key_mgmt &= ~WPA_KEY_MGMT_FT_PSK;
3971 ssid->key_mgmt |= WPA_KEY_MGMT_PSK;
3972 }
3973 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
3974 ssid->key_mgmt &= ~WPA_KEY_MGMT_FT_IEEE8021X;
3975 ssid->key_mgmt |= WPA_KEY_MGMT_IEEE8021X;
3976 }
3977 #ifdef CONFIG_SAE
3978 if (ssid->key_mgmt & WPA_KEY_MGMT_FT_SAE) {
3979 ssid->key_mgmt &= ~WPA_KEY_MGMT_FT_SAE;
3980 ssid->key_mgmt |= WPA_KEY_MGMT_SAE;
3981 }
3982 #endif /* CONFIG_SAE */
3983 }
3984 }
3985 }
3986 #endif /* CONFIG_DRIVER_NL80211_HISI */
3987
3988 int wpa_supplicant_ctrl_iface_set_network(
3989 struct wpa_supplicant *wpa_s, char *cmd)
3990 {
3991 int id, ret, prev_bssid_set, prev_disabled;
3992 struct wpa_ssid *ssid;
3993 char *name, *value;
3994 u8 prev_bssid[ETH_ALEN];
3995 if (!disable_anonymized_print()) {
3996 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK %s", os_strstr(cmd, "bssid") ?
3997 get_anonymized_result_setnetwork_for_bssid(cmd) : get_anonymized_result_setnetwork(cmd));
3998 }
3999 /* cmd: "<network id> <variable name> <value>" */
4000 name = os_strchr(cmd, ' ');
4001 if (name == NULL)
4002 return -1;
4003 *name++ = '\0';
4004
4005 value = os_strchr(name, ' ');
4006 if (value == NULL)
4007 return -1;
4008 *value++ = '\0';
4009
4010 id = atoi(cmd);
4011 size_t length = os_strlen(value);
4012 wpa_printf(MSG_INFO, "CTRL_IFACE: SET_NETWORK id=%d name='%s' value length='%zu'", id, name, length);
4013 #ifdef CONFIG_WIFI_RPT
4014 if (wpa_s->global != NULL && wpa_s->global->p2p != NULL) {
4015 struct p2p_data *p2p = wpa_s->global->p2p;
4016 if (os_strcmp(name, "rptid") == 0) {
4017 p2p->p2p_rpt_net_id = id;
4018 } else if (id == p2p->p2p_rpt_net_id) {
4019 char* dest = NULL;
4020 int len = 0;
4021 if (os_strcmp(name, "ssid") == 0) {
4022 dest = p2p->ssid_preconfigured;
4023 len = sizeof(p2p->ssid_preconfigured);
4024 } else if (os_strcmp(name, "psk") == 0) {
4025 dest = p2p->passphrase_preconfigured;
4026 len = sizeof(p2p->passphrase_preconfigured);
4027 }
4028 if (dest != NULL) {
4029 os_memset(dest, 0, len);
4030 os_memcpy(dest, value + 1, os_strlen(value));
4031 dest[os_strlen(dest) - 1] = '\0';
4032 }
4033 }
4034 }
4035 #endif /* CONFIG_WIFI_RPT */
4036 #ifdef CONFIG_EAP_AUTH
4037 if (wpa_supplicant_ctrl_iface_get_eap_params(name, value))
4038 wpa_printf(MSG_DEBUG, "get eap params success");
4039 #endif
4040 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
4041 (u8 *) value, os_strlen(value));
4042
4043 ssid = wpa_config_get_network(wpa_s->conf, id);
4044 if (ssid == NULL) {
4045 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
4046 "id=%d", id);
4047 return -1;
4048 }
4049
4050 prev_bssid_set = ssid->bssid_set;
4051 prev_disabled = ssid->disabled;
4052 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
4053 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
4054 value);
4055 #ifdef CONFIG_DRIVER_NL80211_HISI
4056 wpa_supplicant_ctrl_iface_skip_ft(wpa_s, ssid);
4057 #endif /* CONFIG_DRIVER_NL80211_HISI */
4058 if (ret == 0 &&
4059 (ssid->bssid_set != prev_bssid_set ||
4060 !ether_addr_equal(ssid->bssid, prev_bssid)))
4061 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
4062
4063 if (prev_disabled != ssid->disabled &&
4064 (prev_disabled == 2 || ssid->disabled == 2))
4065 wpas_notify_network_type_changed(wpa_s, ssid);
4066
4067 return ret;
4068 }
4069
4070
4071 int wpa_supplicant_ctrl_iface_get_network(
4072 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
4073 {
4074 int id;
4075 size_t res;
4076 struct wpa_ssid *ssid;
4077 char *name, *value;
4078
4079 /* cmd: "<network id> <variable name>" */
4080 name = os_strchr(cmd, ' ');
4081 if (name == NULL || buflen == 0)
4082 return -1;
4083 *name++ = '\0';
4084
4085 id = atoi(cmd);
4086 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
4087 id, name);
4088
4089 ssid = wpa_config_get_network(wpa_s->conf, id);
4090 if (ssid == NULL) {
4091 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
4092 "id=%d", id);
4093 return -1;
4094 }
4095
4096 value = wpa_config_get_no_key(ssid, name);
4097 if (value == NULL) {
4098 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
4099 "variable '%s'", name);
4100 return -1;
4101 }
4102
4103 res = os_strlcpy(buf, value, buflen);
4104 if (res >= buflen) {
4105 os_free(value);
4106 return -1;
4107 }
4108
4109 os_free(value);
4110
4111 return res;
4112 }
4113
4114
4115 static int wpa_supplicant_ctrl_iface_dup_network(
4116 struct wpa_supplicant *wpa_s, char *cmd,
4117 struct wpa_supplicant *dst_wpa_s)
4118 {
4119 struct wpa_ssid *ssid_s, *ssid_d;
4120 char *name, *id, *value;
4121 int id_s, id_d, ret;
4122
4123 /* cmd: "<src network id> <dst network id> <variable name>" */
4124 id = os_strchr(cmd, ' ');
4125 if (id == NULL)
4126 return -1;
4127 *id++ = '\0';
4128
4129 name = os_strchr(id, ' ');
4130 if (name == NULL)
4131 return -1;
4132 *name++ = '\0';
4133
4134 id_s = atoi(cmd);
4135 id_d = atoi(id);
4136
4137 wpa_printf(MSG_DEBUG,
4138 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
4139 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
4140
4141 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
4142 if (ssid_s == NULL) {
4143 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4144 "network id=%d", id_s);
4145 return -1;
4146 }
4147
4148 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
4149 if (ssid_d == NULL) {
4150 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4151 "network id=%d", id_d);
4152 return -1;
4153 }
4154
4155 value = wpa_config_get(ssid_s, name);
4156 if (value == NULL) {
4157 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
4158 "variable '%s'", name);
4159 return -1;
4160 }
4161
4162 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
4163 value);
4164
4165 os_free(value);
4166
4167 return ret;
4168 }
4169
4170
4171 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
4172 char *buf, size_t buflen)
4173 {
4174 char *pos, *end;
4175 struct wpa_cred *cred;
4176 int ret;
4177
4178 pos = buf;
4179 end = buf + buflen;
4180 ret = os_snprintf(pos, end - pos,
4181 "cred id / realm / username / domain / imsi\n");
4182 if (os_snprintf_error(end - pos, ret))
4183 return pos - buf;
4184 pos += ret;
4185
4186 cred = wpa_s->conf->cred;
4187 while (cred) {
4188 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
4189 cred->id, cred->realm ? cred->realm : "",
4190 cred->username ? cred->username : "",
4191 cred->domain ? cred->domain[0] : "",
4192 cred->imsi ? cred->imsi : "");
4193 if (os_snprintf_error(end - pos, ret))
4194 return pos - buf;
4195 pos += ret;
4196
4197 cred = cred->next;
4198 }
4199
4200 return pos - buf;
4201 }
4202
4203
4204 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
4205 char *buf, size_t buflen)
4206 {
4207 struct wpa_cred *cred;
4208 int ret;
4209
4210 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
4211
4212 cred = wpa_config_add_cred(wpa_s->conf);
4213 if (cred == NULL)
4214 return -1;
4215
4216 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
4217
4218 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
4219 if (os_snprintf_error(buflen, ret))
4220 return -1;
4221 return ret;
4222 }
4223
4224
4225 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
4226 char *cmd)
4227 {
4228 int id;
4229 struct wpa_cred *cred, *prev;
4230
4231 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
4232 * "provisioning_sp=<FQDN> */
4233 if (os_strcmp(cmd, "all") == 0) {
4234 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
4235 return wpas_remove_all_creds(wpa_s);
4236 }
4237
4238 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
4239 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
4240 cmd + 8);
4241 cred = wpa_s->conf->cred;
4242 while (cred) {
4243 prev = cred;
4244 cred = cred->next;
4245 if (prev->domain) {
4246 size_t i;
4247 for (i = 0; i < prev->num_domain; i++) {
4248 if (os_strcmp(prev->domain[i], cmd + 8)
4249 != 0)
4250 continue;
4251 wpas_remove_cred(wpa_s, prev);
4252 break;
4253 }
4254 }
4255 }
4256 return 0;
4257 }
4258
4259 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
4260 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
4261 cmd + 16);
4262 cred = wpa_s->conf->cred;
4263 while (cred) {
4264 prev = cred;
4265 cred = cred->next;
4266 if (prev->provisioning_sp &&
4267 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
4268 wpas_remove_cred(wpa_s, prev);
4269 }
4270 return 0;
4271 }
4272
4273 id = atoi(cmd);
4274 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
4275
4276 cred = wpa_config_get_cred(wpa_s->conf, id);
4277 return wpas_remove_cred(wpa_s, cred);
4278 }
4279
4280
4281 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
4282 char *cmd)
4283 {
4284 int id;
4285 struct wpa_cred *cred;
4286 char *name, *value;
4287
4288 /* cmd: "<cred id> <variable name> <value>" */
4289 name = os_strchr(cmd, ' ');
4290 if (name == NULL)
4291 return -1;
4292 *name++ = '\0';
4293
4294 value = os_strchr(name, ' ');
4295 if (value == NULL)
4296 return -1;
4297 *value++ = '\0';
4298
4299 id = atoi(cmd);
4300 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
4301 id, name);
4302 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
4303 (u8 *) value, os_strlen(value));
4304
4305 cred = wpa_config_get_cred(wpa_s->conf, id);
4306 if (cred == NULL) {
4307 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
4308 id);
4309 return -1;
4310 }
4311
4312 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
4313 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
4314 "variable '%s'", name);
4315 return -1;
4316 }
4317
4318 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
4319
4320 return 0;
4321 }
4322
4323
4324 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
4325 char *cmd, char *buf,
4326 size_t buflen)
4327 {
4328 int id;
4329 size_t res;
4330 struct wpa_cred *cred;
4331 char *name, *value;
4332
4333 /* cmd: "<cred id> <variable name>" */
4334 name = os_strchr(cmd, ' ');
4335 if (name == NULL)
4336 return -1;
4337 *name++ = '\0';
4338
4339 id = atoi(cmd);
4340 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
4341 id, name);
4342
4343 cred = wpa_config_get_cred(wpa_s->conf, id);
4344 if (cred == NULL) {
4345 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
4346 id);
4347 return -1;
4348 }
4349
4350 value = wpa_config_get_cred_no_key(cred, name);
4351 if (value == NULL) {
4352 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
4353 name);
4354 return -1;
4355 }
4356
4357 res = os_strlcpy(buf, value, buflen);
4358 if (res >= buflen) {
4359 os_free(value);
4360 return -1;
4361 }
4362
4363 os_free(value);
4364
4365 return res;
4366 }
4367
4368
4369 #ifndef CONFIG_NO_CONFIG_WRITE
4370 int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
4371 {
4372 int ret;
4373
4374 if (!wpa_s->conf->update_config) {
4375 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
4376 "to update configuration (update_config=0)");
4377 return -1;
4378 }
4379
4380 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
4381 if (ret) {
4382 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
4383 "update configuration");
4384 } else {
4385 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
4386 " updated");
4387 }
4388
4389 return ret;
4390 }
4391 #endif /* CONFIG_NO_CONFIG_WRITE */
4392
4393
4394 struct cipher_info {
4395 unsigned int capa;
4396 const char *name;
4397 int group_only;
4398 };
4399
4400 static const struct cipher_info ciphers[] = {
4401 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
4402 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
4403 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
4404 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
4405 #ifndef CONFIG_NO_TKIP
4406 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
4407 #endif /* CONFIG_NO_TKIP */
4408 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
4409 #ifdef CONFIG_WEP
4410 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
4411 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
4412 #endif /* CONFIG_WEP */
4413 };
4414
4415 static const struct cipher_info ciphers_group_mgmt[] = {
4416 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
4417 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
4418 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
4419 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
4420 };
4421
4422
4423 static int ctrl_iface_get_capability_pairwise(int res, bool strict,
4424 struct wpa_driver_capa *capa,
4425 char *buf, size_t buflen)
4426 {
4427 int ret;
4428 char *pos, *end;
4429 size_t len;
4430 unsigned int i;
4431
4432 pos = buf;
4433 end = pos + buflen;
4434
4435 if (res < 0) {
4436 if (strict)
4437 return 0;
4438 #ifdef CONFIG_NO_TKIP
4439 len = os_strlcpy(buf, "CCMP NONE", buflen);
4440 #else /* CONFIG_NO_TKIP */
4441 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
4442 #endif /* CONFIG_NO_TKIP */
4443 if (len >= buflen)
4444 return -1;
4445 return len;
4446 }
4447
4448 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4449 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
4450 ret = os_snprintf(pos, end - pos, "%s%s",
4451 pos == buf ? "" : " ",
4452 ciphers[i].name);
4453 if (os_snprintf_error(end - pos, ret))
4454 return pos - buf;
4455 pos += ret;
4456 }
4457 }
4458
4459 return pos - buf;
4460 }
4461
4462
4463 static int ctrl_iface_get_capability_group(int res, bool strict,
4464 struct wpa_driver_capa *capa,
4465 char *buf, size_t buflen)
4466 {
4467 int ret;
4468 char *pos, *end;
4469 size_t len;
4470 unsigned int i;
4471
4472 pos = buf;
4473 end = pos + buflen;
4474
4475 if (res < 0) {
4476 if (strict)
4477 return 0;
4478 #ifdef CONFIG_WEP
4479 #ifdef CONFIG_NO_TKIP
4480 len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen);
4481 #else /* CONFIG_NO_TKIP */
4482 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
4483 #endif /* CONFIG_NO_TKIP */
4484 #else /* CONFIG_WEP */
4485 #ifdef CONFIG_NO_TKIP
4486 len = os_strlcpy(buf, "CCMP", buflen);
4487 #else /* CONFIG_NO_TKIP */
4488 len = os_strlcpy(buf, "CCMP TKIP", buflen);
4489 #endif /* CONFIG_NO_TKIP */
4490 #endif /* CONFIG_WEP */
4491 if (len >= buflen)
4492 return -1;
4493 return len;
4494 }
4495
4496 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4497 if (capa->enc & ciphers[i].capa) {
4498 ret = os_snprintf(pos, end - pos, "%s%s",
4499 pos == buf ? "" : " ",
4500 ciphers[i].name);
4501 if (os_snprintf_error(end - pos, ret))
4502 return pos - buf;
4503 pos += ret;
4504 }
4505 }
4506
4507 return pos - buf;
4508 }
4509
4510
4511 static int ctrl_iface_get_capability_group_mgmt(int res, bool strict,
4512 struct wpa_driver_capa *capa,
4513 char *buf, size_t buflen)
4514 {
4515 int ret;
4516 char *pos, *end;
4517 unsigned int i;
4518
4519 pos = buf;
4520 end = pos + buflen;
4521
4522 if (res < 0)
4523 return 0;
4524
4525 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
4526 if (capa->enc & ciphers_group_mgmt[i].capa) {
4527 ret = os_snprintf(pos, end - pos, "%s%s",
4528 pos == buf ? "" : " ",
4529 ciphers_group_mgmt[i].name);
4530 if (os_snprintf_error(end - pos, ret))
4531 return pos - buf;
4532 pos += ret;
4533 }
4534 }
4535
4536 return pos - buf;
4537 }
4538
4539
4540 static int iftype_str_to_index(const char *iftype_str)
4541 {
4542 if (!iftype_str)
4543 return WPA_IF_MAX;
4544
4545 if (os_strcmp(iftype_str, "STATION") == 0)
4546 return WPA_IF_STATION;
4547
4548 if (os_strcmp(iftype_str, "AP_VLAN") == 0)
4549 return WPA_IF_AP_VLAN;
4550
4551 if (os_strcmp(iftype_str, "AP") == 0)
4552 return WPA_IF_AP_BSS;
4553
4554 if (os_strcmp(iftype_str, "P2P_GO") == 0)
4555 return WPA_IF_P2P_GO;
4556
4557 if (os_strcmp(iftype_str, "P2P_CLIENT") == 0)
4558 return WPA_IF_P2P_CLIENT;
4559
4560 if (os_strcmp(iftype_str, "P2P_DEVICE") == 0)
4561 return WPA_IF_P2P_DEVICE;
4562
4563 if (os_strcmp(iftype_str, "MESH") == 0)
4564 return WPA_IF_MESH;
4565
4566 if (os_strcmp(iftype_str, "IBSS") == 0)
4567 return WPA_IF_IBSS;
4568
4569 if (os_strcmp(iftype_str, "NAN") == 0)
4570 return WPA_IF_NAN;
4571
4572 return WPA_IF_MAX;
4573 }
4574
4575
4576 static int ctrl_iface_get_capability_key_mgmt(int res, bool strict,
4577 struct wpa_driver_capa *capa,
4578 const char *iftype_str,
4579 char *buf, size_t buflen)
4580 {
4581 int ret;
4582 unsigned int key_mgmt;
4583 char *pos, *end;
4584 size_t len;
4585
4586 pos = buf;
4587 end = pos + buflen;
4588
4589 if (res < 0) {
4590 if (strict)
4591 return 0;
4592 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4593 "NONE", buflen);
4594 if (len >= buflen)
4595 return -1;
4596 return len;
4597 }
4598
4599 if (iftype_str) {
4600 enum wpa_driver_if_type iftype;
4601
4602 iftype = iftype_str_to_index(iftype_str);
4603 if (iftype == WPA_IF_MAX)
4604 return -1;
4605 key_mgmt = capa->key_mgmt_iftype[iftype];
4606 } else {
4607 key_mgmt = capa->key_mgmt;
4608 }
4609
4610 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
4611 if (os_snprintf_error(end - pos, ret))
4612 return pos - buf;
4613 pos += ret;
4614
4615 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4616 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
4617 ret = os_snprintf(pos, end - pos, " WPA-EAP");
4618 if (os_snprintf_error(end - pos, ret))
4619 return pos - buf;
4620 pos += ret;
4621 }
4622
4623 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
4624 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
4625 ret = os_snprintf(pos, end - pos, " WPA-PSK");
4626 if (os_snprintf_error(end - pos, ret))
4627 return pos - buf;
4628 pos += ret;
4629 }
4630
4631 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
4632 ret = os_snprintf(pos, end - pos, " WPA-NONE");
4633 if (os_snprintf_error(end - pos, ret))
4634 return pos - buf;
4635 pos += ret;
4636 }
4637
4638 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WAPI_PSK) {
4639 ret = os_snprintf(pos, end - pos, " WAPI-PSK");
4640 if (os_snprintf_error(end - pos, ret))
4641 return pos - buf;
4642 pos += ret;
4643 }
4644
4645 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE) {
4646 ret = os_snprintf(pos, end - pos, " TPK-HANDSHAKE");
4647 if (os_snprintf_error(end - pos, ret))
4648 return pos - buf;
4649 pos += ret;
4650 }
4651
4652 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_CCKM) {
4653 ret = os_snprintf(pos, end - pos, " CCKM");
4654 if (os_snprintf_error(end - pos, ret))
4655 return pos - buf;
4656 pos += ret;
4657 }
4658
4659 #ifdef CONFIG_SUITEB
4660 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
4661 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
4662 if (os_snprintf_error(end - pos, ret))
4663 return pos - buf;
4664 pos += ret;
4665 }
4666 #endif /* CONFIG_SUITEB */
4667 #ifdef CONFIG_SUITEB192
4668 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
4669 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
4670 if (os_snprintf_error(end - pos, ret))
4671 return pos - buf;
4672 pos += ret;
4673 }
4674 #endif /* CONFIG_SUITEB192 */
4675 #ifdef CONFIG_OWE
4676 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
4677 ret = os_snprintf(pos, end - pos, " OWE");
4678 if (os_snprintf_error(end - pos, ret))
4679 return pos - buf;
4680 pos += ret;
4681 }
4682 #endif /* CONFIG_OWE */
4683 #ifdef CONFIG_DPP
4684 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
4685 ret = os_snprintf(pos, end - pos, " DPP");
4686 if (os_snprintf_error(end - pos, ret))
4687 return pos - buf;
4688 pos += ret;
4689 }
4690 #endif /* CONFIG_DPP */
4691 #ifdef CONFIG_FILS
4692 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
4693 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
4694 if (os_snprintf_error(end - pos, ret))
4695 return pos - buf;
4696 pos += ret;
4697 }
4698 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
4699 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
4700 if (os_snprintf_error(end - pos, ret))
4701 return pos - buf;
4702 pos += ret;
4703 }
4704 #ifdef CONFIG_IEEE80211R
4705 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
4706 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
4707 if (os_snprintf_error(end - pos, ret))
4708 return pos - buf;
4709 pos += ret;
4710 }
4711 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
4712 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
4713 if (os_snprintf_error(end - pos, ret))
4714 return pos - buf;
4715 pos += ret;
4716 }
4717 #endif /* CONFIG_IEEE80211R */
4718 #endif /* CONFIG_FILS */
4719 #ifdef CONFIG_IEEE80211R
4720 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
4721 ret = os_snprintf(pos, end - pos, " FT-PSK");
4722 if (os_snprintf_error(end - pos, ret))
4723 return pos - buf;
4724 pos += ret;
4725 }
4726 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) {
4727 ret = os_snprintf(pos, end - pos, " FT-EAP");
4728 if (os_snprintf_error(end - pos, ret))
4729 return pos - buf;
4730 pos += ret;
4731 }
4732 #ifdef CONFIG_SAE
4733 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE) {
4734 ret = os_snprintf(pos, end - pos, " FT-SAE");
4735 if (os_snprintf_error(end - pos, ret))
4736 return pos - buf;
4737 pos += ret;
4738 }
4739 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE_EXT_KEY) {
4740 ret = os_snprintf(pos, end - pos, " FT-SAE-EXT-KEY");
4741 if (os_snprintf_error(end - pos, ret))
4742 return pos - buf;
4743 pos += ret;
4744 }
4745 #endif /* CONFIG_SAE */
4746 #ifdef CONFIG_SHA384
4747 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384) {
4748 ret = os_snprintf(pos, end - pos, " FT-EAP-SHA384");
4749 if (os_snprintf_error(end - pos, ret))
4750 return pos - buf;
4751 pos += ret;
4752 }
4753 #endif /* CONFIG_SHA384 */
4754 #endif /* CONFIG_IEEE80211R */
4755 #ifdef CONFIG_SAE
4756 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
4757 ret = os_snprintf(pos, end - pos, " SAE");
4758 if (os_snprintf_error(end - pos, ret))
4759 return pos - buf;
4760 pos += ret;
4761 }
4762 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE_EXT_KEY) {
4763 ret = os_snprintf(pos, end - pos, " SAE-EXT-KEY");
4764 if (os_snprintf_error(end - pos, ret))
4765 return pos - buf;
4766 pos += ret;
4767 }
4768 #endif /* CONFIG_SAE */
4769 #ifdef CONFIG_SHA256
4770 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256) {
4771 ret = os_snprintf(pos, end - pos, " WPA-EAP-SHA256");
4772 if (os_snprintf_error(end - pos, ret))
4773 return pos - buf;
4774 pos += ret;
4775 }
4776
4777 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256) {
4778 ret = os_snprintf(pos, end - pos, " WPA-PSK-SHA256");
4779 if (os_snprintf_error(end - pos, ret))
4780 return pos - buf;
4781 pos += ret;
4782 }
4783 #endif /* CONFIG_SHA256 */
4784 #ifdef CONFIG_HS20
4785 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OSEN) {
4786 ret = os_snprintf(pos, end - pos, " OSEN");
4787 if (os_snprintf_error(end - pos, ret))
4788 return pos - buf;
4789 pos += ret;
4790 }
4791 #endif /* CONFIG_HS20 */
4792
4793 return pos - buf;
4794 }
4795
4796
4797 static int ctrl_iface_get_capability_proto(int res, bool strict,
4798 struct wpa_driver_capa *capa,
4799 char *buf, size_t buflen)
4800 {
4801 int ret;
4802 char *pos, *end;
4803 size_t len;
4804
4805 pos = buf;
4806 end = pos + buflen;
4807
4808 if (res < 0) {
4809 if (strict)
4810 return 0;
4811 len = os_strlcpy(buf, "RSN WPA", buflen);
4812 if (len >= buflen)
4813 return -1;
4814 return len;
4815 }
4816
4817 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4818 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
4819 ret = os_snprintf(pos, end - pos, "%sRSN",
4820 pos == buf ? "" : " ");
4821 if (os_snprintf_error(end - pos, ret))
4822 return pos - buf;
4823 pos += ret;
4824 }
4825
4826 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4827 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
4828 ret = os_snprintf(pos, end - pos, "%sWPA",
4829 pos == buf ? "" : " ");
4830 if (os_snprintf_error(end - pos, ret))
4831 return pos - buf;
4832 pos += ret;
4833 }
4834
4835 return pos - buf;
4836 }
4837
4838
4839 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
4840 int res, bool strict,
4841 struct wpa_driver_capa *capa,
4842 char *buf, size_t buflen)
4843 {
4844 int ret;
4845 char *pos, *end;
4846 size_t len;
4847
4848 pos = buf;
4849 end = pos + buflen;
4850
4851 if (res < 0) {
4852 if (strict)
4853 return 0;
4854 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4855 if (len >= buflen)
4856 return -1;
4857 return len;
4858 }
4859
4860 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
4861 ret = os_snprintf(pos, end - pos, "%sOPEN",
4862 pos == buf ? "" : " ");
4863 if (os_snprintf_error(end - pos, ret))
4864 return pos - buf;
4865 pos += ret;
4866 }
4867
4868 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4869 ret = os_snprintf(pos, end - pos, "%sSHARED",
4870 pos == buf ? "" : " ");
4871 if (os_snprintf_error(end - pos, ret))
4872 return pos - buf;
4873 pos += ret;
4874 }
4875
4876 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
4877 ret = os_snprintf(pos, end - pos, "%sLEAP",
4878 pos == buf ? "" : " ");
4879 if (os_snprintf_error(end - pos, ret))
4880 return pos - buf;
4881 pos += ret;
4882 }
4883
4884 #ifdef CONFIG_SAE
4885 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4886 ret = os_snprintf(pos, end - pos, "%sSAE",
4887 pos == buf ? "" : " ");
4888 if (os_snprintf_error(end - pos, ret))
4889 return pos - buf;
4890 pos += ret;
4891 }
4892 #endif /* CONFIG_SAE */
4893
4894 #ifdef CONFIG_FILS
4895 if (wpa_is_fils_supported(wpa_s)) {
4896 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4897 pos == buf ? "" : " ");
4898 if (os_snprintf_error(end - pos, ret))
4899 return pos - buf;
4900 pos += ret;
4901 }
4902
4903 #ifdef CONFIG_FILS_SK_PFS
4904 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4905 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4906 pos == buf ? "" : " ");
4907 if (os_snprintf_error(end - pos, ret))
4908 return pos - buf;
4909 pos += ret;
4910 }
4911 #endif /* CONFIG_FILS_SK_PFS */
4912 #endif /* CONFIG_FILS */
4913
4914 #ifdef CONFIG_PASN
4915 ret = os_snprintf(pos, end - pos, "%sPASN",
4916 pos == buf ? "" : " ");
4917 if (os_snprintf_error(end - pos, ret))
4918 return pos - buf;
4919 pos += ret;
4920
4921 #endif /* CONFIG_PASN */
4922
4923 return pos - buf;
4924 }
4925
4926
4927 static int ctrl_iface_get_capability_modes(int res, bool strict,
4928 struct wpa_driver_capa *capa,
4929 char *buf, size_t buflen)
4930 {
4931 int ret;
4932 char *pos, *end;
4933 size_t len;
4934
4935 pos = buf;
4936 end = pos + buflen;
4937
4938 if (res < 0) {
4939 if (strict)
4940 return 0;
4941 len = os_strlcpy(buf, "IBSS AP", buflen);
4942 if (len >= buflen)
4943 return -1;
4944 return len;
4945 }
4946
4947 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
4948 ret = os_snprintf(pos, end - pos, "%sIBSS",
4949 pos == buf ? "" : " ");
4950 if (os_snprintf_error(end - pos, ret))
4951 return pos - buf;
4952 pos += ret;
4953 }
4954
4955 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
4956 ret = os_snprintf(pos, end - pos, "%sAP",
4957 pos == buf ? "" : " ");
4958 if (os_snprintf_error(end - pos, ret))
4959 return pos - buf;
4960 pos += ret;
4961 }
4962
4963 #ifdef CONFIG_MESH
4964 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4965 ret = os_snprintf(pos, end - pos, "%sMESH",
4966 pos == buf ? "" : " ");
4967 if (os_snprintf_error(end - pos, ret))
4968 return pos - buf;
4969 pos += ret;
4970 }
4971 #endif /* CONFIG_MESH */
4972
4973 return pos - buf;
4974 }
4975
4976
4977 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4978 char *buf, size_t buflen)
4979 {
4980 struct hostapd_channel_data *chnl;
4981 int ret, i, j;
4982 char *pos, *end, *hmode;
4983
4984 pos = buf;
4985 end = pos + buflen;
4986
4987 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4988 switch (wpa_s->hw.modes[j].mode) {
4989 case HOSTAPD_MODE_IEEE80211B:
4990 hmode = "B";
4991 break;
4992 case HOSTAPD_MODE_IEEE80211G:
4993 hmode = "G";
4994 break;
4995 case HOSTAPD_MODE_IEEE80211A:
4996 hmode = "A";
4997 break;
4998 case HOSTAPD_MODE_IEEE80211AD:
4999 hmode = "AD";
5000 break;
5001 default:
5002 continue;
5003 }
5004 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
5005 if (os_snprintf_error(end - pos, ret))
5006 return pos - buf;
5007 pos += ret;
5008 chnl = wpa_s->hw.modes[j].channels;
5009 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
5010 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
5011 continue;
5012 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
5013 if (os_snprintf_error(end - pos, ret))
5014 return pos - buf;
5015 pos += ret;
5016 }
5017 ret = os_snprintf(pos, end - pos, "\n");
5018 if (os_snprintf_error(end - pos, ret))
5019 return pos - buf;
5020 pos += ret;
5021 }
5022
5023 return pos - buf;
5024 }
5025
5026
5027 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
5028 char *buf, size_t buflen)
5029 {
5030 struct hostapd_channel_data *chnl;
5031 int ret, i, j;
5032 char *pos, *end, *hmode;
5033
5034 pos = buf;
5035 end = pos + buflen;
5036
5037 for (j = 0; j < wpa_s->hw.num_modes; j++) {
5038 switch (wpa_s->hw.modes[j].mode) {
5039 case HOSTAPD_MODE_IEEE80211B:
5040 hmode = "B";
5041 break;
5042 case HOSTAPD_MODE_IEEE80211G:
5043 hmode = "G";
5044 break;
5045 case HOSTAPD_MODE_IEEE80211A:
5046 hmode = "A";
5047 break;
5048 case HOSTAPD_MODE_IEEE80211AD:
5049 hmode = "AD";
5050 break;
5051 default:
5052 continue;
5053 }
5054 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
5055 hmode);
5056 if (os_snprintf_error(end - pos, ret))
5057 return pos - buf;
5058 pos += ret;
5059 chnl = wpa_s->hw.modes[j].channels;
5060 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
5061 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
5062 continue;
5063 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
5064 chnl[i].chan, chnl[i].freq,
5065 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
5066 " (NO_IR)" : "",
5067 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
5068 " (DFS)" : "");
5069
5070 if (os_snprintf_error(end - pos, ret))
5071 return pos - buf;
5072 pos += ret;
5073 }
5074 ret = os_snprintf(pos, end - pos, "\n");
5075 if (os_snprintf_error(end - pos, ret))
5076 return pos - buf;
5077 pos += ret;
5078 }
5079
5080 return pos - buf;
5081 }
5082
5083
5084 static int wpa_supplicant_ctrl_iface_get_capability(
5085 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
5086 size_t buflen)
5087 {
5088 struct wpa_driver_capa capa;
5089 int res;
5090 char *next_param, *curr_param, *iftype = NULL;
5091 bool strict = false;
5092 char field[50];
5093 size_t len;
5094
5095 /* Determine whether or not strict checking was requested */
5096 len = os_strlcpy(field, _field, sizeof(field));
5097 if (len >= sizeof(field))
5098 return -1;
5099
5100 next_param = os_strchr(field, ' ');
5101 while (next_param) {
5102 *next_param++ = '\0';
5103 curr_param = next_param;
5104 next_param = os_strchr(next_param, ' ');
5105
5106 if (next_param)
5107 *next_param = '\0';
5108
5109 if (os_strcmp(curr_param, "strict") == 0)
5110 strict = true;
5111 else if (os_strncmp(curr_param, "iftype=", 7) == 0)
5112 iftype = curr_param + 7;
5113 else
5114 return -1;
5115 }
5116
5117 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'%s%s%s",
5118 field, iftype ? " iftype=" : "", iftype ? iftype : "",
5119 strict ? " strict" : "");
5120
5121 if (os_strcmp(field, "eap") == 0) {
5122 return eap_get_names(buf, buflen);
5123 }
5124
5125 res = wpa_drv_get_capa(wpa_s, &capa);
5126
5127 if (os_strcmp(field, "pairwise") == 0)
5128 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
5129 buf, buflen);
5130
5131 if (os_strcmp(field, "group") == 0)
5132 return ctrl_iface_get_capability_group(res, strict, &capa,
5133 buf, buflen);
5134
5135 if (os_strcmp(field, "group_mgmt") == 0)
5136 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
5137 buf, buflen);
5138
5139 if (os_strcmp(field, "key_mgmt") == 0)
5140 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
5141 iftype, buf, buflen);
5142
5143 if (os_strcmp(field, "proto") == 0)
5144 return ctrl_iface_get_capability_proto(res, strict, &capa,
5145 buf, buflen);
5146
5147 if (os_strcmp(field, "auth_alg") == 0)
5148 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
5149 &capa, buf, buflen);
5150
5151 if (os_strcmp(field, "modes") == 0)
5152 return ctrl_iface_get_capability_modes(res, strict, &capa,
5153 buf, buflen);
5154
5155 if (os_strcmp(field, "channels") == 0)
5156 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
5157
5158 if (os_strcmp(field, "freq") == 0)
5159 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
5160
5161 #ifdef CONFIG_TDLS
5162 if (os_strcmp(field, "tdls") == 0)
5163 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
5164 #endif /* CONFIG_TDLS */
5165
5166 #ifdef CONFIG_ERP
5167 if (os_strcmp(field, "erp") == 0) {
5168 res = os_snprintf(buf, buflen, "ERP");
5169 if (os_snprintf_error(buflen, res))
5170 return -1;
5171 return res;
5172 }
5173 #endif /* CONFIG_EPR */
5174
5175 #ifdef CONFIG_FIPS
5176 if (os_strcmp(field, "fips") == 0) {
5177 res = os_snprintf(buf, buflen, "FIPS");
5178 if (os_snprintf_error(buflen, res))
5179 return -1;
5180 return res;
5181 }
5182 #endif /* CONFIG_FIPS */
5183
5184 #ifdef CONFIG_ACS
5185 if (os_strcmp(field, "acs") == 0) {
5186 res = os_snprintf(buf, buflen, "ACS");
5187 if (os_snprintf_error(buflen, res))
5188 return -1;
5189 return res;
5190 }
5191 #endif /* CONFIG_ACS */
5192
5193 #ifdef CONFIG_FILS
5194 if (os_strcmp(field, "fils") == 0) {
5195 #ifdef CONFIG_FILS_SK_PFS
5196 if (wpa_is_fils_supported(wpa_s) &&
5197 wpa_is_fils_sk_pfs_supported(wpa_s)) {
5198 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
5199 if (os_snprintf_error(buflen, res))
5200 return -1;
5201 return res;
5202 }
5203 #endif /* CONFIG_FILS_SK_PFS */
5204
5205 if (wpa_is_fils_supported(wpa_s)) {
5206 res = os_snprintf(buf, buflen, "FILS");
5207 if (os_snprintf_error(buflen, res))
5208 return -1;
5209 return res;
5210 }
5211 }
5212 #endif /* CONFIG_FILS */
5213
5214 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
5215 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
5216 if (os_snprintf_error(buflen, res))
5217 return -1;
5218 return res;
5219 }
5220
5221 #ifdef CONFIG_DPP
5222 if (os_strcmp(field, "dpp") == 0) {
5223 #ifdef CONFIG_DPP3
5224 res = os_snprintf(buf, buflen, "DPP=3");
5225 #elif defined(CONFIG_DPP2)
5226 res = os_snprintf(buf, buflen, "DPP=2");
5227 #else /* CONFIG_DPP2 */
5228 res = os_snprintf(buf, buflen, "DPP=1");
5229 #endif /* CONFIG_DPP2 */
5230 if (os_snprintf_error(buflen, res))
5231 return -1;
5232 return res;
5233 }
5234 #endif /* CONFIG_DPP */
5235
5236 #ifdef CONFIG_NAN_USD
5237 if (os_strcmp(field, "nan") == 0) {
5238 res = os_snprintf(buf, buflen, "USD");
5239 if (os_snprintf_error(buflen, res))
5240 return -1;
5241 return res;
5242 }
5243 #endif /* CONFIG_NAN_USD */
5244
5245 #ifdef CONFIG_SAE
5246 if (os_strcmp(field, "sae") == 0 &&
5247 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
5248 #ifdef CONFIG_SAE_PK
5249 res = os_snprintf(buf, buflen, "H2E PK");
5250 #else /* CONFIG_SAE_PK */
5251 res = os_snprintf(buf, buflen, "H2E");
5252 #endif /* CONFIG_SAE_PK */
5253 if (os_snprintf_error(buflen, res))
5254 return -1;
5255 return res;
5256 }
5257 #endif /* CONFIG_SAE */
5258
5259 #ifdef CONFIG_OCV
5260 if (os_strcmp(field, "ocv") == 0) {
5261 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
5262 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV))
5263 res = os_snprintf(buf, buflen, "supported");
5264 else
5265 res = os_snprintf(buf, buflen, "not supported");
5266 if (os_snprintf_error(buflen, res))
5267 return -1;
5268 return res;
5269 }
5270 #endif /* CONFIG_OCV */
5271
5272 if (os_strcmp(field, "beacon_prot") == 0) {
5273 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) ||
5274 (wpa_s->drv_flags2 &
5275 WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT))
5276 res = os_snprintf(buf, buflen, "supported");
5277 else
5278 res = os_snprintf(buf, buflen, "not supported");
5279 if (os_snprintf_error(buflen, res))
5280 return -1;
5281 return res;
5282 }
5283
5284 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
5285 field);
5286
5287 return -1;
5288 }
5289
5290
5291 #ifdef CONFIG_INTERWORKING
5292 static char * anqp_add_hex(char *pos, char *end, const char *title,
5293 struct wpabuf *data)
5294 {
5295 char *start = pos;
5296 size_t i;
5297 int ret;
5298 const u8 *d;
5299
5300 if (data == NULL)
5301 return start;
5302
5303 ret = os_snprintf(pos, end - pos, "%s=", title);
5304 if (os_snprintf_error(end - pos, ret))
5305 return start;
5306 pos += ret;
5307
5308 d = wpabuf_head_u8(data);
5309 for (i = 0; i < wpabuf_len(data); i++) {
5310 ret = os_snprintf(pos, end - pos, "%02x", *d++);
5311 if (os_snprintf_error(end - pos, ret))
5312 return start;
5313 pos += ret;
5314 }
5315
5316 ret = os_snprintf(pos, end - pos, "\n");
5317 if (os_snprintf_error(end - pos, ret))
5318 return start;
5319 pos += ret;
5320
5321 return pos;
5322 }
5323 #endif /* CONFIG_INTERWORKING */
5324
5325
5326 #ifdef CONFIG_FILS
5327 static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
5328 {
5329 char *start = pos;
5330 const u8 *ie, *ie_end;
5331 u16 info, realms;
5332 int ret;
5333
5334 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
5335 if (!ie)
5336 return 0;
5337 ie_end = ie + 2 + ie[1];
5338 ie += 2;
5339 if (ie_end - ie < 2)
5340 return 0;
5341
5342 info = WPA_GET_LE16(ie);
5343 ie += 2;
5344 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
5345 if (os_snprintf_error(end - pos, ret))
5346 return 0;
5347 pos += ret;
5348
5349 if (info & BIT(7)) {
5350 /* Cache Identifier Included */
5351 if (ie_end - ie < 2)
5352 return 0;
5353 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
5354 ie[0], ie[1]);
5355 if (os_snprintf_error(end - pos, ret))
5356 return 0;
5357 pos += ret;
5358 ie += 2;
5359 }
5360
5361 if (info & BIT(8)) {
5362 /* HESSID Included */
5363 if (ie_end - ie < ETH_ALEN)
5364 return 0;
5365 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
5366 MAC2STR(ie));
5367 if (os_snprintf_error(end - pos, ret))
5368 return 0;
5369 pos += ret;
5370 ie += ETH_ALEN;
5371 }
5372
5373 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
5374 if (realms) {
5375 if (ie_end - ie < realms * 2)
5376 return 0;
5377 ret = os_snprintf(pos, end - pos, "fils_realms=");
5378 if (os_snprintf_error(end - pos, ret))
5379 return 0;
5380 pos += ret;
5381
5382 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
5383 if (ret <= 0)
5384 return 0;
5385 pos += ret;
5386 ie += realms * 2;
5387 ret = os_snprintf(pos, end - pos, "\n");
5388 if (os_snprintf_error(end - pos, ret))
5389 return 0;
5390 pos += ret;
5391 }
5392
5393 return pos - start;
5394 }
5395 #endif /* CONFIG_FILS */
5396
5397
5398 static int print_rnr(struct wpa_bss *bss, char *pos, char *end)
5399 {
5400 char *start = pos;
5401 const u8 *ie, *ie_end;
5402 unsigned int n = 0;
5403 int ret;
5404
5405 ie = wpa_bss_get_ie(bss, WLAN_EID_REDUCED_NEIGHBOR_REPORT);
5406 if (!ie)
5407 return 0;
5408
5409 ie_end = ie + 2 + ie[1];
5410 ie += 2;
5411
5412 while (ie < ie_end) {
5413 const struct ieee80211_neighbor_ap_info *info =
5414 (const struct ieee80211_neighbor_ap_info *) ie;
5415 const u8 *tbtt_start;
5416 size_t left = ie_end - ie;
5417
5418 if (left < sizeof(struct ieee80211_neighbor_ap_info))
5419 return 0;
5420
5421 left -= sizeof(struct ieee80211_neighbor_ap_info);
5422 if (left < info->tbtt_info_len)
5423 return 0;
5424
5425 ret = os_snprintf(pos, end - pos,
5426 "ap_info[%u]: tbtt_info: hdr=0x%x, len=%u, op_c=%u, channel=%u, ",
5427 n, *ie, info->tbtt_info_len,
5428 info->op_class, info->channel);
5429 if (os_snprintf_error(end - pos, ret))
5430 return 0;
5431 pos += ret;
5432
5433 ie += sizeof(struct ieee80211_neighbor_ap_info);
5434 tbtt_start = ie;
5435 if (info->tbtt_info_len >= 1) {
5436 ret = os_snprintf(pos, end - pos,
5437 "tbtt_offset=%u, ", *ie);
5438 if (os_snprintf_error(end - pos, ret))
5439 return 0;
5440
5441 ie++;
5442 pos += ret;
5443 }
5444
5445 if (info->tbtt_info_len >= 7) {
5446 ret = os_snprintf(pos, end - pos,
5447 "bssid=" MACSTR ", ",
5448 MAC2STR(ie));
5449 if (os_snprintf_error(end - pos, ret))
5450 return 0;
5451
5452 ie += ETH_ALEN;
5453 pos += ret;
5454 }
5455
5456 if (info->tbtt_info_len >= 11) {
5457 ret = os_snprintf(pos, end - pos,
5458 "short SSID=0x%x, ",
5459 WPA_GET_LE32(ie));
5460 if (os_snprintf_error(end - pos, ret))
5461 return 0;
5462
5463 ie += 4;
5464 pos += ret;
5465 }
5466
5467 if (info->tbtt_info_len >= 12) {
5468 ret = os_snprintf(pos, end - pos,
5469 "bss_params=0x%x, ", *ie);
5470 if (os_snprintf_error(end - pos, ret))
5471 return 0;
5472
5473 ie++;
5474 pos += ret;
5475 }
5476
5477 if (info->tbtt_info_len >= 13) {
5478 ret = os_snprintf(pos, end - pos,
5479 "PSD=0x%x, ", *ie);
5480 if (os_snprintf_error(end - pos, ret))
5481 return 0;
5482
5483 ie++;
5484 pos += ret;
5485 }
5486
5487 if (info->tbtt_info_len >= 16) {
5488 ret = os_snprintf(pos, end - pos,
5489 "mld ID=%u, link ID=%u",
5490 *ie, *(ie + 1) & 0xF);
5491 if (os_snprintf_error(end - pos, ret))
5492 return 0;
5493
5494 ie += 3;
5495 pos += ret;
5496 }
5497
5498 ie = tbtt_start + info->tbtt_info_len;
5499
5500 ret = os_snprintf(pos, end - pos, "\n");
5501 if (os_snprintf_error(end - pos, ret))
5502 return 0;
5503 pos += ret;
5504
5505 n++;
5506 }
5507
5508 return pos - start;
5509 }
5510
5511
5512 static int print_ml(struct wpa_bss *bss, char *pos, char *end)
5513 {
5514 const struct ieee80211_eht_ml *ml;
5515 char *start = pos;
5516 const u8 *ie, *ie_end;
5517 u16 ml_control;
5518 u8 common_info_length;
5519 int ret;
5520
5521 ie = get_ml_ie(wpa_bss_ie_ptr(bss), bss->ie_len,
5522 MULTI_LINK_CONTROL_TYPE_BASIC);
5523 if (!ie)
5524 return 0;
5525
5526 ie_end = ie + 2 + ie[1];
5527 ie += 3;
5528 ml = (const struct ieee80211_eht_ml *) ie;
5529
5530 /* control + common info length + MLD MAC Address */
5531 if (ie_end - ie < 2 + 1 + ETH_ALEN)
5532 return 0;
5533
5534 ml_control = le_to_host16(ml->ml_control);
5535
5536 common_info_length = *(ie + 2);
5537 ret = os_snprintf(pos, end - pos,
5538 "multi-link: control=0x%x, common info len=%u",
5539 ml_control, common_info_length);
5540 if (os_snprintf_error(end - pos, ret))
5541 return 0;
5542 pos += ret;
5543
5544 ie += 2;
5545 if (ie_end - ie < common_info_length)
5546 return 0;
5547
5548 ie++;
5549 common_info_length--;
5550
5551 if (common_info_length < ETH_ALEN)
5552 return 0;
5553
5554 ret = os_snprintf(pos, end - pos, ", MLD addr=" MACSTR, MAC2STR(ie));
5555 if (os_snprintf_error(end - pos, ret))
5556 return 0;
5557 pos += ret;
5558
5559 ie += ETH_ALEN;
5560 common_info_length -= ETH_ALEN;
5561
5562 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_LINK_ID) {
5563 if (common_info_length < 1)
5564 return 0;
5565
5566 ret = os_snprintf(pos, end - pos, ", link ID=%u", *ie & 0x0f);
5567 if (os_snprintf_error(end - pos, ret))
5568 return 0;
5569 pos += ret;
5570 ie++;
5571 common_info_length--;
5572 }
5573
5574 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT) {
5575 if (common_info_length < 1)
5576 return 0;
5577
5578 ret = os_snprintf(pos, end - pos,
5579 ", BSS change parameters=0x%x", *ie);
5580 if (os_snprintf_error(end - pos, ret))
5581 return 0;
5582 pos += ret;
5583 ie++;
5584 common_info_length--;
5585 }
5586
5587 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
5588 if (common_info_length < 2)
5589 return 0;
5590
5591 ret = os_snprintf(pos, end - pos, ", MSD Info=0x%x",
5592 WPA_GET_LE16(ie));
5593 if (os_snprintf_error(end - pos, ret))
5594 return 0;
5595 pos += ret;
5596 ie += 2;
5597 common_info_length -= 2;
5598 }
5599
5600 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
5601 if (common_info_length < 2)
5602 return 0;
5603
5604 ret = os_snprintf(pos, end - pos, ", EML capabilities=0x%x",
5605 WPA_GET_LE16(ie));
5606 if (os_snprintf_error(end - pos, ret))
5607 return 0;
5608 pos += ret;
5609 ie += 2;
5610 common_info_length -= 2;
5611 }
5612
5613 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
5614 if (common_info_length < 2)
5615 return 0;
5616
5617 ret = os_snprintf(pos, end - pos, ", MLD capabilities=0x%x",
5618 WPA_GET_LE16(ie));
5619 if (os_snprintf_error(end - pos, ret))
5620 return 0;
5621 pos += ret;
5622 ie += 2;
5623 common_info_length -= 2;
5624 }
5625
5626 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
5627 if (common_info_length < 1)
5628 return 0;
5629
5630 ret = os_snprintf(pos, end - pos, ", MLD ID=0x%x", *ie);
5631 if (os_snprintf_error(end - pos, ret))
5632 return 0;
5633 pos += ret;
5634 ie += 1;
5635 common_info_length--;
5636 }
5637
5638 ret = os_snprintf(pos, end - pos, "\n");
5639 if (os_snprintf_error(end - pos, ret))
5640 return 0;
5641 pos += ret;
5642
5643 return pos - start;
5644 }
5645
5646
5647 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
5648 unsigned long mask, char *buf, size_t buflen)
5649 {
5650 size_t i;
5651 int ret;
5652 char *pos, *end;
5653 const u8 *ie, *ie2, *osen_ie, *mesh, *owe, *rsnxe;
5654 #ifdef CONFIG_WAPI
5655 const u8 *ie3;
5656 #endif
5657
5658 pos = buf;
5659 end = buf + buflen;
5660
5661 if (mask & WPA_BSS_MASK_ID) {
5662 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
5663 if (os_snprintf_error(end - pos, ret))
5664 return 0;
5665 pos += ret;
5666 }
5667
5668 if (mask & WPA_BSS_MASK_BSSID) {
5669 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
5670 MAC2STR(bss->bssid));
5671 if (os_snprintf_error(end - pos, ret))
5672 return 0;
5673 pos += ret;
5674 }
5675
5676 if (mask & WPA_BSS_MASK_FREQ) {
5677 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
5678 if (os_snprintf_error(end - pos, ret))
5679 return 0;
5680 pos += ret;
5681 }
5682
5683 if (mask & WPA_BSS_MASK_BEACON_INT) {
5684 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
5685 bss->beacon_int);
5686 if (os_snprintf_error(end - pos, ret))
5687 return 0;
5688 pos += ret;
5689 }
5690
5691 if (mask & WPA_BSS_MASK_CAPABILITIES) {
5692 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
5693 bss->caps);
5694 if (os_snprintf_error(end - pos, ret))
5695 return 0;
5696 pos += ret;
5697 }
5698
5699 if (mask & WPA_BSS_MASK_QUAL) {
5700 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
5701 if (os_snprintf_error(end - pos, ret))
5702 return 0;
5703 pos += ret;
5704 }
5705
5706 if (mask & WPA_BSS_MASK_NOISE) {
5707 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
5708 if (os_snprintf_error(end - pos, ret))
5709 return 0;
5710 pos += ret;
5711 }
5712
5713 if (mask & WPA_BSS_MASK_LEVEL) {
5714 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
5715 if (os_snprintf_error(end - pos, ret))
5716 return 0;
5717 pos += ret;
5718 }
5719
5720 if (mask & WPA_BSS_MASK_TSF) {
5721 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
5722 (unsigned long long) bss->tsf);
5723 if (os_snprintf_error(end - pos, ret))
5724 return 0;
5725 pos += ret;
5726 }
5727 #if defined(CONFIG_OPEN_HARMONY_PATCH) && defined(CONFIG_HILINK_OKC_STA)
5728 if (mask & WPA_BSS_MASK_HILINK) {
5729 ret = snprintf_s(pos, end - pos, (end - pos - 1), "hilink=%d\n", bss->hilink);
5730 if(ret == -1){
5731 wpa_printf(MSG_DEBUG, "%s:Fail to snprintf hilink", __func__);
5732 return 0;
5733 }
5734 pos += ret;
5735 }
5736 #endif
5737 if (mask & WPA_BSS_MASK_AGE) {
5738 struct os_reltime now;
5739
5740 os_get_reltime(&now);
5741 ret = os_snprintf(pos, end - pos, "age=%d\n",
5742 (int) (now.sec - bss->last_update.sec));
5743 if (os_snprintf_error(end - pos, ret))
5744 return 0;
5745 pos += ret;
5746 }
5747
5748 if (mask & WPA_BSS_MASK_IE) {
5749 ret = os_snprintf(pos, end - pos, "ie=");
5750 if (os_snprintf_error(end - pos, ret))
5751 return 0;
5752 pos += ret;
5753
5754 ie = wpa_bss_ie_ptr(bss);
5755 for (i = 0; i < bss->ie_len; i++) {
5756 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
5757 if (os_snprintf_error(end - pos, ret))
5758 return 0;
5759 pos += ret;
5760 }
5761
5762 ret = os_snprintf(pos, end - pos, "\n");
5763 if (os_snprintf_error(end - pos, ret))
5764 return 0;
5765 pos += ret;
5766 }
5767
5768 if (mask & WPA_BSS_MASK_FLAGS) {
5769 ret = os_snprintf(pos, end - pos, "flags=");
5770 if (os_snprintf_error(end - pos, ret))
5771 return 0;
5772 pos += ret;
5773
5774 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
5775
5776 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
5777 if (ie)
5778 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
5779 2 + ie[1]);
5780 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
5781 if (ie2)
5782 pos = wpa_supplicant_ie_txt(pos, end,
5783 mesh ? "RSN" : "WPA2", ie2,
5784 2 + ie2[1]);
5785 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
5786 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
5787 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
5788 if (os_snprintf_error(end - pos, ret))
5789 return 0;
5790 pos += ret;
5791 }
5792 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
5793 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
5794 if (os_snprintf_error(end - pos, ret))
5795 return 0;
5796 pos += ret;
5797 }
5798 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
5799 if (osen_ie)
5800 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
5801 osen_ie, 2 + osen_ie[1]);
5802 #ifdef CONFIG_WAPI
5803 ie3 = wpa_bss_get_ie(bss, WLAN_EID_WAPI);
5804 if (ie3) {
5805 char *pos_b = pos;
5806 pos = wpa_supplicant_wapi_ie_txt(pos, end, ie3, 2 + ie3[1]);
5807 if (pos == pos_b) {
5808 ie3 = NULL;
5809 }
5810 }
5811 if (!ie && !ie2 && !ie3 && (bss->caps & IEEE80211_CAP_PRIVACY)) {
5812 ret = os_snprintf(pos, end - pos, "[WEP]");
5813 if (os_snprintf_error(end - pos, ret)) {
5814 return -1;
5815 }
5816 pos += ret;
5817 }
5818 #endif
5819 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
5820 if (owe) {
5821 ret = os_snprintf(
5822 pos, end - pos,
5823 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
5824 if (os_snprintf_error(end - pos, ret))
5825 return 0;
5826 pos += ret;
5827 }
5828 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
5829 if (!ie && !ie2 && !osen_ie &&
5830 (bss->caps & IEEE80211_CAP_PRIVACY)) {
5831 ret = os_snprintf(pos, end - pos, "[WEP]");
5832 if (os_snprintf_error(end - pos, ret))
5833 return 0;
5834 pos += ret;
5835 }
5836
5837 if (mesh) {
5838 ret = os_snprintf(pos, end - pos, "[MESH]");
5839 if (os_snprintf_error(end - pos, ret))
5840 return 0;
5841 pos += ret;
5842 }
5843
5844 if (bss_is_dmg(bss)) {
5845 const char *s;
5846 ret = os_snprintf(pos, end - pos, "[DMG]");
5847 if (os_snprintf_error(end - pos, ret))
5848 return 0;
5849 pos += ret;
5850 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
5851 case IEEE80211_CAP_DMG_IBSS:
5852 s = "[IBSS]";
5853 break;
5854 case IEEE80211_CAP_DMG_AP:
5855 s = "[ESS]";
5856 break;
5857 case IEEE80211_CAP_DMG_PBSS:
5858 s = "[PBSS]";
5859 break;
5860 default:
5861 s = "";
5862 break;
5863 }
5864 ret = os_snprintf(pos, end - pos, "%s", s);
5865 if (os_snprintf_error(end - pos, ret))
5866 return 0;
5867 pos += ret;
5868 } else {
5869 if (bss->caps & IEEE80211_CAP_IBSS) {
5870 ret = os_snprintf(pos, end - pos, "[IBSS]");
5871 if (os_snprintf_error(end - pos, ret))
5872 return 0;
5873 pos += ret;
5874 }
5875 if (bss->caps & IEEE80211_CAP_ESS) {
5876 ret = os_snprintf(pos, end - pos, "[ESS]");
5877 if (os_snprintf_error(end - pos, ret))
5878 return 0;
5879 pos += ret;
5880 }
5881 }
5882 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
5883 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
5884 ret = os_snprintf(pos, end - pos, "[P2P]");
5885 if (os_snprintf_error(end - pos, ret))
5886 return 0;
5887 pos += ret;
5888 }
5889 #ifdef CONFIG_HS20
5890 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
5891 ret = os_snprintf(pos, end - pos, "[HS20]");
5892 if (os_snprintf_error(end - pos, ret))
5893 return 0;
5894 pos += ret;
5895 }
5896 #endif /* CONFIG_HS20 */
5897 #ifdef CONFIG_FILS
5898 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
5899 ret = os_snprintf(pos, end - pos, "[FILS]");
5900 if (os_snprintf_error(end - pos, ret))
5901 return 0;
5902 pos += ret;
5903 }
5904 #endif /* CONFIG_FILS */
5905 #ifdef CONFIG_FST
5906 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
5907 ret = os_snprintf(pos, end - pos, "[FST]");
5908 if (os_snprintf_error(end - pos, ret))
5909 return 0;
5910 pos += ret;
5911 }
5912 #endif /* CONFIG_FST */
5913 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
5914 ret = os_snprintf(pos, end - pos, "[UTF-8]");
5915 if (os_snprintf_error(end - pos, ret))
5916 return 0;
5917 pos += ret;
5918 }
5919
5920 ret = os_snprintf(pos, end - pos, "\n");
5921 if (os_snprintf_error(end - pos, ret))
5922 return 0;
5923 pos += ret;
5924 }
5925
5926 if (mask & WPA_BSS_MASK_SSID) {
5927 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
5928 wpa_ssid_txt(bss->ssid, bss->ssid_len));
5929 if (os_snprintf_error(end - pos, ret))
5930 return 0;
5931 pos += ret;
5932 }
5933
5934 #ifdef CONFIG_WPS
5935 if (mask & WPA_BSS_MASK_WPS_SCAN) {
5936 ie = wpa_bss_ie_ptr(bss);
5937 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
5938 if (ret >= end - pos)
5939 return 0;
5940 if (ret > 0)
5941 pos += ret;
5942 }
5943 #endif /* CONFIG_WPS */
5944
5945 #ifdef CONFIG_P2P
5946 if (mask & WPA_BSS_MASK_P2P_SCAN) {
5947 ie = wpa_bss_ie_ptr(bss);
5948 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
5949 if (ret >= end - pos)
5950 return 0;
5951 if (ret > 0)
5952 pos += ret;
5953 }
5954 #endif /* CONFIG_P2P */
5955
5956 #ifdef CONFIG_WIFI_DISPLAY
5957 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
5958 struct wpabuf *wfd;
5959
5960 ie = wpa_bss_ie_ptr(bss);
5961 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
5962 WFD_IE_VENDOR_TYPE);
5963 if (wfd) {
5964 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
5965 if (os_snprintf_error(end - pos, ret)) {
5966 wpabuf_free(wfd);
5967 return 0;
5968 }
5969 pos += ret;
5970
5971 pos += wpa_snprintf_hex(pos, end - pos,
5972 wpabuf_head(wfd),
5973 wpabuf_len(wfd));
5974 wpabuf_free(wfd);
5975
5976 ret = os_snprintf(pos, end - pos, "\n");
5977 if (os_snprintf_error(end - pos, ret))
5978 return 0;
5979 pos += ret;
5980 }
5981 }
5982 #endif /* CONFIG_WIFI_DISPLAY */
5983
5984 #ifdef CONFIG_INTERWORKING
5985 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
5986 struct wpa_bss_anqp *anqp = bss->anqp;
5987 struct wpa_bss_anqp_elem *elem;
5988
5989 pos = anqp_add_hex(pos, end, "anqp_capability_list",
5990 anqp->capability_list);
5991 pos = anqp_add_hex(pos, end, "anqp_venue_name",
5992 anqp->venue_name);
5993 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
5994 anqp->network_auth_type);
5995 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
5996 anqp->roaming_consortium);
5997 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
5998 anqp->ip_addr_type_availability);
5999 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
6000 anqp->nai_realm);
6001 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
6002 pos = anqp_add_hex(pos, end, "anqp_domain_name",
6003 anqp->domain_name);
6004 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
6005 anqp->fils_realm_info);
6006 #ifdef CONFIG_HS20
6007 pos = anqp_add_hex(pos, end, "hs20_capability_list",
6008 anqp->hs20_capability_list);
6009 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
6010 anqp->hs20_operator_friendly_name);
6011 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
6012 anqp->hs20_wan_metrics);
6013 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
6014 anqp->hs20_connection_capability);
6015 pos = anqp_add_hex(pos, end, "hs20_operating_class",
6016 anqp->hs20_operating_class);
6017 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
6018 anqp->hs20_osu_providers_list);
6019 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
6020 anqp->hs20_operator_icon_metadata);
6021 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
6022 anqp->hs20_osu_providers_nai_list);
6023 #endif /* CONFIG_HS20 */
6024
6025 dl_list_for_each(elem, &anqp->anqp_elems,
6026 struct wpa_bss_anqp_elem, list) {
6027 char title[20];
6028
6029 os_snprintf(title, sizeof(title), "anqp[%u]",
6030 elem->infoid);
6031 pos = anqp_add_hex(pos, end, title, elem->payload);
6032 if (elem->protected_response) {
6033 ret = os_snprintf(pos, end - pos,
6034 "protected-anqp-info[%u]=1\n",
6035 elem->infoid);
6036 if (os_snprintf_error(end - pos, ret))
6037 return 0;
6038 pos += ret;
6039 }
6040 }
6041 }
6042 #endif /* CONFIG_INTERWORKING */
6043
6044 #ifdef CONFIG_MESH
6045 if (mask & WPA_BSS_MASK_MESH_SCAN) {
6046 ie = wpa_bss_ie_ptr(bss);
6047 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
6048 if (ret >= end - pos)
6049 return 0;
6050 if (ret > 0)
6051 pos += ret;
6052 }
6053 #endif /* CONFIG_MESH */
6054
6055 if (mask & WPA_BSS_MASK_SNR) {
6056 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
6057 if (os_snprintf_error(end - pos, ret))
6058 return 0;
6059 pos += ret;
6060 }
6061
6062 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
6063 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
6064 bss->est_throughput);
6065 if (os_snprintf_error(end - pos, ret))
6066 return 0;
6067 pos += ret;
6068 }
6069
6070 #ifdef CONFIG_FST
6071 if (mask & WPA_BSS_MASK_FST) {
6072 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
6073 if (ret < 0 || ret >= end - pos)
6074 return 0;
6075 pos += ret;
6076 }
6077 #endif /* CONFIG_FST */
6078
6079 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
6080 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
6081 bss->last_update_idx);
6082 if (os_snprintf_error(end - pos, ret))
6083 return 0;
6084 pos += ret;
6085 }
6086
6087 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
6088 ret = os_snprintf(pos, end - pos, "beacon_ie=");
6089 if (os_snprintf_error(end - pos, ret))
6090 return 0;
6091 pos += ret;
6092
6093 ie = wpa_bss_ie_ptr(bss);
6094 ie += bss->ie_len;
6095 for (i = 0; i < bss->beacon_ie_len; i++) {
6096 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
6097 if (os_snprintf_error(end - pos, ret))
6098 return 0;
6099 pos += ret;
6100 }
6101
6102 ret = os_snprintf(pos, end - pos, "\n");
6103 if (os_snprintf_error(end - pos, ret))
6104 return 0;
6105 pos += ret;
6106 }
6107
6108 #ifdef CONFIG_FILS
6109 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
6110 ret = print_fils_indication(bss, pos, end);
6111 pos += ret;
6112 }
6113 #endif /* CONFIG_FILS */
6114
6115 if (!is_zero_ether_addr(bss->mld_addr) &&
6116 (mask & WPA_BSS_MASK_AP_MLD_ADDR)) {
6117 ret = os_snprintf(pos, end - pos,
6118 "ap_mld_addr=" MACSTR "\n",
6119 MAC2STR(bss->mld_addr));
6120 if (os_snprintf_error(end - pos, ret))
6121 return 0;
6122 pos += ret;
6123 }
6124
6125 if (mask & WPA_BSS_MASK_RNR)
6126 pos += print_rnr(bss, pos, end);
6127
6128 if (mask & WPA_BSS_MASK_ML)
6129 pos += print_ml(bss, pos, end);
6130
6131 if (mask & WPA_BSS_MASK_DELIM) {
6132 ret = os_snprintf(pos, end - pos, "====\n");
6133 if (os_snprintf_error(end - pos, ret))
6134 return 0;
6135 pos += ret;
6136 }
6137
6138 return pos - buf;
6139 }
6140
6141
6142 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
6143 const char *cmd, char *buf,
6144 size_t buflen)
6145 {
6146 u8 bssid[ETH_ALEN];
6147 size_t i;
6148 struct wpa_bss *bss;
6149 struct wpa_bss *bsslast = NULL;
6150 struct dl_list *next;
6151 int ret = 0;
6152 int len;
6153 char *ctmp, *end = buf + buflen;
6154 unsigned long mask = WPA_BSS_MASK_ALL;
6155
6156 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
6157 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
6158 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
6159 list_id);
6160 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
6161 list_id);
6162 } else { /* N1-N2 */
6163 unsigned int id1, id2;
6164
6165 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
6166 wpa_printf(MSG_INFO, "Wrong BSS range "
6167 "format");
6168 return 0;
6169 }
6170
6171 if (*(cmd + 6) == '-')
6172 id1 = 0;
6173 else
6174 id1 = atoi(cmd + 6);
6175 ctmp++;
6176 if (*ctmp >= '0' && *ctmp <= '9')
6177 id2 = atoi(ctmp);
6178 else
6179 id2 = (unsigned int) -1;
6180 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
6181 if (id2 == (unsigned int) -1)
6182 bsslast = dl_list_last(&wpa_s->bss_id,
6183 struct wpa_bss,
6184 list_id);
6185 else {
6186 bsslast = wpa_bss_get_id(wpa_s, id2);
6187 if (bsslast == NULL && bss && id2 > id1) {
6188 struct wpa_bss *tmp = bss;
6189 for (;;) {
6190 next = tmp->list_id.next;
6191 if (next == &wpa_s->bss_id)
6192 break;
6193 tmp = dl_list_entry(
6194 next, struct wpa_bss,
6195 list_id);
6196 if (tmp->id > id2)
6197 break;
6198 bsslast = tmp;
6199 }
6200 }
6201 }
6202 }
6203 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
6204 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
6205 else if (os_strncmp(cmd, "LAST", 4) == 0)
6206 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
6207 else if (os_strncmp(cmd, "ID-", 3) == 0) {
6208 i = atoi(cmd + 3);
6209 bss = wpa_bss_get_id(wpa_s, i);
6210 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
6211 i = atoi(cmd + 5);
6212 bss = wpa_bss_get_id(wpa_s, i);
6213 if (bss) {
6214 next = bss->list_id.next;
6215 if (next == &wpa_s->bss_id)
6216 bss = NULL;
6217 else
6218 bss = dl_list_entry(next, struct wpa_bss,
6219 list_id);
6220 }
6221 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
6222 bss = wpa_s->current_bss;
6223 #ifdef CONFIG_P2P
6224 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
6225 if (hwaddr_aton(cmd + 13, bssid) == 0)
6226 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
6227 else
6228 bss = NULL;
6229 #endif /* CONFIG_P2P */
6230 } else if (hwaddr_aton(cmd, bssid) == 0)
6231 bss = wpa_bss_get_bssid(wpa_s, bssid);
6232 else {
6233 struct wpa_bss *tmp;
6234 i = atoi(cmd);
6235 bss = NULL;
6236 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
6237 {
6238 if (i == 0) {
6239 bss = tmp;
6240 break;
6241 }
6242 i--;
6243 }
6244 }
6245
6246 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
6247 mask = strtoul(ctmp + 5, NULL, 0x10);
6248 if (mask == 0)
6249 mask = WPA_BSS_MASK_ALL;
6250 }
6251
6252 if (bss == NULL)
6253 return 0;
6254
6255 if (bsslast == NULL)
6256 bsslast = bss;
6257 do {
6258 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
6259 ret += len;
6260 buf += len;
6261 buflen -= len;
6262 if (bss == bsslast) {
6263 if ((mask & WPA_BSS_MASK_DELIM) && len &&
6264 (bss == dl_list_last(&wpa_s->bss_id,
6265 struct wpa_bss, list_id))) {
6266 int res;
6267
6268 res = os_snprintf(buf - 5, end - buf + 5,
6269 "####\n");
6270 if (os_snprintf_error(end - buf + 5, res)) {
6271 wpa_printf(MSG_DEBUG,
6272 "Could not add end delim");
6273 }
6274 }
6275 break;
6276 }
6277 next = bss->list_id.next;
6278 if (next == &wpa_s->bss_id)
6279 break;
6280 bss = dl_list_entry(next, struct wpa_bss, list_id);
6281 } while (bss && len);
6282
6283 return ret;
6284 }
6285
6286
6287 static int wpa_supplicant_ctrl_iface_ap_scan(
6288 struct wpa_supplicant *wpa_s, char *cmd)
6289 {
6290 int ap_scan = atoi(cmd);
6291 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
6292 }
6293
6294
6295 static int wpa_supplicant_ctrl_iface_scan_interval(
6296 struct wpa_supplicant *wpa_s, char *cmd)
6297 {
6298 int scan_int = atoi(cmd);
6299 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
6300 }
6301
6302
6303 static int wpa_supplicant_ctrl_iface_bss_expire_age(
6304 struct wpa_supplicant *wpa_s, char *cmd)
6305 {
6306 int expire_age = atoi(cmd);
6307 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
6308 }
6309
6310
6311 static int wpa_supplicant_ctrl_iface_bss_expire_count(
6312 struct wpa_supplicant *wpa_s, char *cmd)
6313 {
6314 int expire_count = atoi(cmd);
6315 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
6316 }
6317
6318
6319 static void wpa_supplicant_ctrl_iface_bss_flush(
6320 struct wpa_supplicant *wpa_s, char *cmd)
6321 {
6322 int flush_age = atoi(cmd);
6323
6324 if (flush_age == 0)
6325 wpa_bss_flush(wpa_s);
6326 else
6327 wpa_bss_flush_by_age(wpa_s, flush_age);
6328 }
6329
6330
6331 #ifdef CONFIG_TESTING_OPTIONS
6332 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
6333 {
6334 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
6335 /* MLME-DELETEKEYS.request */
6336 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL,
6337 0, KEY_FLAG_GROUP);
6338 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL,
6339 0, KEY_FLAG_GROUP);
6340 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL,
6341 0, KEY_FLAG_GROUP);
6342 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL,
6343 0, KEY_FLAG_GROUP);
6344 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL,
6345 0, KEY_FLAG_GROUP);
6346 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL,
6347 0, KEY_FLAG_GROUP);
6348
6349 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0,
6350 NULL, 0, KEY_FLAG_PAIRWISE);
6351 if (wpa_sm_ext_key_id(wpa_s->wpa))
6352 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, wpa_s->bssid, 1, 0,
6353 NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE);
6354 /* MLME-SETPROTECTION.request(None) */
6355 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
6356 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
6357 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
6358 wpa_sm_drop_sa(wpa_s->wpa);
6359 }
6360 #endif /* CONFIG_TESTING_OPTIONS */
6361
6362
6363 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
6364 char *addr)
6365 {
6366 #ifdef CONFIG_NO_SCAN_PROCESSING
6367 return -1;
6368 #else /* CONFIG_NO_SCAN_PROCESSING */
6369 u8 bssid[ETH_ALEN];
6370 struct wpa_bss *bss;
6371 struct wpa_ssid *ssid = wpa_s->current_ssid;
6372 struct wpa_radio_work *already_connecting;
6373
6374 if (hwaddr_aton(addr, bssid)) {
6375 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
6376 "address '%s'", addr);
6377 return -1;
6378 }
6379
6380 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR_SEC, MAC2STR_SEC(bssid));
6381
6382 if (!ssid) {
6383 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
6384 "configuration known for the target AP");
6385 return -1;
6386 }
6387
6388 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
6389 if (!bss) {
6390 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
6391 "from BSS table");
6392 return -1;
6393 }
6394
6395 /*
6396 * TODO: Find best network configuration block from configuration to
6397 * allow roaming to other networks
6398 */
6399
6400 already_connecting = radio_work_pending(wpa_s, "sme-connect");
6401 wpa_s->reassociate = 1;
6402 wpa_supplicant_connect(wpa_s, bss, ssid);
6403
6404 /*
6405 * Indicate that an explicitly requested roam is in progress so scan
6406 * results that come in before the 'sme-connect' radio work gets
6407 * executed do not override the original connection attempt.
6408 */
6409 if (!already_connecting && radio_work_pending(wpa_s, "sme-connect"))
6410 wpa_s->roam_in_progress = true;
6411
6412 return 0;
6413 #endif /* CONFIG_NO_SCAN_PROCESSING */
6414 }
6415
6416 #ifdef CONFIG_OPEN_HARMONY_SPECIFIC_P2P_FIND
6417 static int parse_p2p_find_timeout(char *cmd) {
6418 int channelid = atoi(cmd);
6419 int ret = (channelid - DISCOVER_TIMEOUT_S) >> 16;
6420 wpa_printf(MSG_DEBUG, "P2P: parse miracast channelid = %d", ret);
6421 return ret;
6422 }
6423 #endif
6424
6425 #ifdef CONFIG_P2P
6426 int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
6427 {
6428 unsigned int timeout = atoi(cmd);
6429 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
6430 #ifdef CONFIG_OPEN_HARMONY_SPECIFIC_P2P_FIND
6431 int res = parse_p2p_find_timeout(cmd);
6432 if (res == DISCOVER_CHANNELID) {
6433 type = P2P_FIND_SPECIFIC_FREQ;
6434 }
6435 #endif
6436 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
6437 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
6438 char *pos;
6439 unsigned int search_delay;
6440 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
6441 u8 seek_count = 0;
6442 int freq = 0;
6443 bool include_6ghz = false;
6444
6445 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6446 wpa_dbg(wpa_s, MSG_INFO,
6447 "Reject P2P_FIND since interface is disabled");
6448 return -1;
6449 }
6450
6451 if (os_strstr(cmd, " include_6ghz"))
6452 include_6ghz = true;
6453 if (os_strstr(cmd, "type=social"))
6454 type = P2P_FIND_ONLY_SOCIAL;
6455 else if (os_strstr(cmd, "type=progressive"))
6456 type = P2P_FIND_PROGRESSIVE;
6457
6458 pos = os_strstr(cmd, "dev_id=");
6459 if (pos) {
6460 pos += 7;
6461 if (hwaddr_aton(pos, dev_id))
6462 return -1;
6463 _dev_id = dev_id;
6464 }
6465
6466 pos = os_strstr(cmd, "dev_type=");
6467 if (pos) {
6468 pos += 9;
6469 if (wps_dev_type_str2bin(pos, dev_type) < 0)
6470 return -1;
6471 _dev_type = dev_type;
6472 }
6473
6474 pos = os_strstr(cmd, "delay=");
6475 if (pos) {
6476 pos += 6;
6477 search_delay = atoi(pos);
6478 } else
6479 search_delay = wpas_p2p_search_delay(wpa_s);
6480
6481 pos = os_strstr(cmd, "freq=");
6482 if (pos) {
6483 pos += 5;
6484 freq = atoi(pos);
6485 if (freq <= 0)
6486 return -1;
6487 }
6488
6489 /* Must be searched for last, because it adds nul termination */
6490 pos = os_strstr(cmd, " seek=");
6491 if (pos)
6492 pos += 6;
6493 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
6494 char *term;
6495
6496 _seek[seek_count++] = pos;
6497 seek = _seek;
6498 term = os_strchr(pos, ' ');
6499 if (!term)
6500 break;
6501 *term = '\0';
6502 pos = os_strstr(term + 1, "seek=");
6503 if (pos)
6504 pos += 5;
6505 }
6506 if (seek_count > P2P_MAX_QUERY_HASH) {
6507 seek[0] = NULL;
6508 seek_count = 1;
6509 }
6510
6511 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
6512 _dev_id, search_delay, seek_count, seek, freq,
6513 include_6ghz);
6514 }
6515
6516
6517 static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
6518 {
6519 const char *last = NULL;
6520 const char *token;
6521 long int token_len;
6522 unsigned int i;
6523
6524 /* Expected predefined CPT names delimited by ':' */
6525 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
6526 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
6527 wpa_printf(MSG_ERROR,
6528 "P2PS: CPT name list is too long, expected up to %d names",
6529 P2PS_FEATURE_CAPAB_CPT_MAX);
6530 cpt[0] = 0;
6531 return -1;
6532 }
6533
6534 token_len = last - token;
6535
6536 if (token_len == 3 &&
6537 os_memcmp(token, "UDP", token_len) == 0) {
6538 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6539 } else if (token_len == 3 &&
6540 os_memcmp(token, "MAC", token_len) == 0) {
6541 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
6542 } else {
6543 wpa_printf(MSG_ERROR,
6544 "P2PS: Unsupported CPT name '%s'", token);
6545 cpt[0] = 0;
6546 return -1;
6547 }
6548
6549 if (isblank((unsigned char) *last)) {
6550 i++;
6551 break;
6552 }
6553 }
6554 cpt[i] = 0;
6555 return 0;
6556 }
6557
6558
6559 static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
6560 {
6561 struct p2ps_provision *p2ps_prov;
6562 char *pos;
6563 size_t info_len = 0;
6564 char *info = NULL;
6565 u8 role = P2PS_SETUP_NONE;
6566 long long unsigned val;
6567 int i;
6568
6569 pos = os_strstr(cmd, "info=");
6570 if (pos) {
6571 pos += 5;
6572 info_len = os_strlen(pos);
6573
6574 if (info_len) {
6575 info = os_malloc(info_len + 1);
6576 if (info) {
6577 info_len = utf8_unescape(pos, info_len,
6578 info, info_len + 1);
6579 } else
6580 info_len = 0;
6581 }
6582 }
6583
6584 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
6585 if (p2ps_prov == NULL) {
6586 os_free(info);
6587 return NULL;
6588 }
6589
6590 if (info) {
6591 os_memcpy(p2ps_prov->info, info, info_len);
6592 p2ps_prov->info[info_len] = '\0';
6593 os_free(info);
6594 }
6595
6596 pos = os_strstr(cmd, "status=");
6597 if (pos)
6598 p2ps_prov->status = atoi(pos + 7);
6599 else
6600 p2ps_prov->status = -1;
6601
6602 pos = os_strstr(cmd, "adv_id=");
6603 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
6604 goto invalid_args;
6605 p2ps_prov->adv_id = val;
6606
6607 pos = os_strstr(cmd, "method=");
6608 if (pos)
6609 p2ps_prov->method = strtol(pos + 7, NULL, 16);
6610 else
6611 p2ps_prov->method = 0;
6612
6613 pos = os_strstr(cmd, "session=");
6614 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
6615 goto invalid_args;
6616 p2ps_prov->session_id = val;
6617
6618 pos = os_strstr(cmd, "adv_mac=");
6619 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
6620 goto invalid_args;
6621
6622 pos = os_strstr(cmd, "session_mac=");
6623 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
6624 goto invalid_args;
6625
6626 pos = os_strstr(cmd, "cpt=");
6627 if (pos) {
6628 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
6629 p2ps_prov->cpt_priority))
6630 goto invalid_args;
6631 } else {
6632 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6633 }
6634
6635 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
6636 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
6637
6638 /* force conncap with tstCap (no validity checks) */
6639 pos = os_strstr(cmd, "tstCap=");
6640 if (pos) {
6641 role = strtol(pos + 7, NULL, 16);
6642 } else {
6643 pos = os_strstr(cmd, "role=");
6644 if (pos) {
6645 role = strtol(pos + 5, NULL, 16);
6646 if (role != P2PS_SETUP_CLIENT &&
6647 role != P2PS_SETUP_GROUP_OWNER)
6648 role = P2PS_SETUP_NONE;
6649 }
6650 }
6651 p2ps_prov->role = role;
6652
6653 return p2ps_prov;
6654
6655 invalid_args:
6656 os_free(p2ps_prov);
6657 return NULL;
6658 }
6659
6660
6661 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
6662 {
6663 u8 addr[ETH_ALEN];
6664 struct p2ps_provision *p2ps_prov;
6665 char *pos;
6666
6667 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
6668
6669 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
6670
6671 if (hwaddr_aton(cmd, addr))
6672 return -1;
6673
6674 pos = cmd + 17;
6675 if (*pos != ' ')
6676 return -1;
6677
6678 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
6679 if (!p2ps_prov)
6680 return -1;
6681
6682 if (p2ps_prov->status < 0) {
6683 os_free(p2ps_prov);
6684 return -1;
6685 }
6686
6687 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
6688 p2ps_prov);
6689 }
6690
6691
6692 static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
6693 {
6694 u8 addr[ETH_ALEN];
6695 struct p2ps_provision *p2ps_prov;
6696 char *pos;
6697
6698 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
6699 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
6700 */
6701
6702 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
6703 if (hwaddr_aton(cmd, addr))
6704 return -1;
6705
6706 pos = cmd + 17;
6707 if (*pos != ' ')
6708 return -1;
6709
6710 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
6711 if (!p2ps_prov)
6712 return -1;
6713
6714 p2ps_prov->pd_seeker = 1;
6715
6716 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
6717 p2ps_prov);
6718 }
6719
6720 static int p2p_ctrl_deliver_data(struct wpa_supplicant *wpa_s, char *cmd)
6721 {
6722 int cmdType, dataType;
6723 char *carryData;
6724 char *token = cmd;
6725 if (token == NULL) {
6726 wpa_printf(MSG_DEBUG, "p2p_ctrl_deliver_data info is empty");
6727 return -1;
6728 }
6729
6730 token = strtok(cmd, " ");
6731 while (token != NULL) {
6732 if (strncmp(token, "cmdType=", 8) == 0) {
6733 cmdType = atoi(token + 8);
6734 } else if (strncmp(token, "dataType=", 9) == 0) {
6735 dataType = atoi(token + 9);
6736 } else if (strncmp(token, "carryData=", 10) == 0) {
6737 carryData = token + 10;
6738 }
6739 token = strtok(NULL, " ");
6740 }
6741 if (cmdType != 2) {
6742 wpa_printf(MSG_ERROR, "cmdType Type error");
6743 return -1;
6744 }
6745
6746 switch (dataType) {
6747 #ifdef CONFIG_OPEN_HARMONY_MIRACAST_MAC
6748 case P2P_RANDOM_MAC_TYPE:
6749 wpa_printf(MSG_ERROR, "P2P_RANDOM_MAC_TYPE %d", atoi(carryData));
6750 wpa_s->p2p_business = atoi(carryData);
6751 break;
6752 #endif
6753
6754 #ifdef OPEN_HARMONY_P2P_ONEHOP_FIND
6755 case SET_ONENINE_SCAN_STATE:
6756 if (wpa_s->global->p2p != NULL && os_strcmp(carryData, "1") == 0) {
6757 wpa_printf(MSG_ERROR, "SET_ONENINE_SCAN_STATE SUCCESS");
6758 p2p_onehop_set_state(wpa_s);
6759 }
6760 break;
6761 #endif
6762 default:
6763 wpa_printf(MSG_DEBUG, "dataType error");
6764 break;
6765 }
6766 return 0;
6767 }
6768
6769 int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
6770 char *buf, size_t buflen)
6771 {
6772 u8 addr[ETH_ALEN];
6773 char *pos, *pos2;
6774 char *pin = NULL;
6775 enum p2p_wps_method wps_method;
6776 int new_pin;
6777 int ret;
6778 int persistent_group, persistent_id = -1;
6779 int join;
6780 int auth;
6781 int automatic;
6782 int go_intent = -1;
6783 int freq = 0;
6784 int pd;
6785 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
6786 int edmg;
6787 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
6788 size_t group_ssid_len = 0;
6789 int he;
6790 bool allow_6ghz;
6791
6792 if (!wpa_s->global->p2p_init_wpa_s)
6793 return -1;
6794 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
6795 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
6796 wpa_s->global->p2p_init_wpa_s->ifname);
6797 wpa_s = wpa_s->global->p2p_init_wpa_s;
6798 }
6799
6800 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
6801 * [persistent|persistent=<network id>]
6802 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
6803 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
6804
6805 if (hwaddr_aton(cmd, addr))
6806 return -1;
6807
6808 pos = cmd + 17;
6809 if (*pos != ' ')
6810 return -1;
6811 pos++;
6812
6813 persistent_group = os_strstr(pos, " persistent") != NULL;
6814 pos2 = os_strstr(pos, " persistent=");
6815 if (pos2) {
6816 struct wpa_ssid *ssid;
6817 persistent_id = atoi(pos2 + 12);
6818 if (persistent_id >= 0) {
6819 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
6820 if (ssid == NULL || ssid->disabled != 2 ||
6821 ssid->mode != WPAS_MODE_P2P_GO) {
6822 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
6823 "SSID id=%d for persistent P2P group (GO)",
6824 persistent_id);
6825 return -1;
6826 }
6827 }
6828 }
6829 join = os_strstr(pos, " join") != NULL;
6830 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
6831 auth = os_strstr(pos, " auth") != NULL;
6832 automatic = os_strstr(pos, " auto") != NULL;
6833 pd = os_strstr(pos, " provdisc") != NULL;
6834 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6835 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6836 vht;
6837 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
6838 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
6839
6840 pos2 = os_strstr(pos, " go_intent=");
6841 if (pos2) {
6842 pos2 += 11;
6843 go_intent = atoi(pos2);
6844 if (go_intent < 0 || go_intent > 15)
6845 return -1;
6846 }
6847 #ifdef CONFIG_OPEN_HARMONY_PATCH
6848 #ifdef OPEN_HARMONY_MIRACAST_SINK_OPT
6849 go_intent = hm_wpas_go_neg_vendor_intent_opt(wpa_s, go_intent, addr);
6850 #else
6851 #ifdef HARMONY_P2P_CONNECTIVITY_PATCH
6852 /* GO negotiation optimization to modify intent*/
6853 go_intent = wpas_go_neg_opt_intent_modify(wpa_s, go_intent);
6854 #endif
6855 #endif
6856 #endif
6857 pos2 = os_strstr(pos, " freq=");
6858 if (pos2) {
6859 pos2 += 6;
6860 freq = atoi(pos2);
6861 if (freq <= 0)
6862 return -1;
6863 }
6864
6865 pos2 = os_strstr(pos, " freq2=");
6866 if (pos2)
6867 freq2 = atoi(pos2 + 7);
6868
6869 pos2 = os_strstr(pos, " max_oper_chwidth=");
6870 if (pos2)
6871 chwidth = atoi(pos2 + 18);
6872
6873 max_oper_chwidth = chwidth_freq2_to_ch_width(chwidth, freq2);
6874 if (max_oper_chwidth < 0)
6875 return -1;
6876
6877 if (allow_6ghz && chwidth == 40)
6878 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
6879
6880 pos2 = os_strstr(pos, " ssid=");
6881 if (pos2) {
6882 char *end;
6883
6884 pos2 += 6;
6885 end = os_strchr(pos2, ' ');
6886 if (!end)
6887 group_ssid_len = os_strlen(pos2) / 2;
6888 else
6889 group_ssid_len = (end - pos2) / 2;
6890 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
6891 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
6892 return -1;
6893 group_ssid = _group_ssid;
6894 }
6895
6896 if (os_strncmp(pos, "pin", 3) == 0) {
6897 /* Request random PIN (to be displayed) and enable the PIN */
6898 wps_method = WPS_PIN_DISPLAY;
6899 } else if (os_strncmp(pos, "pbc", 3) == 0) {
6900 wps_method = WPS_PBC;
6901 } else if (os_strstr(pos, "p2ps") != NULL) {
6902 wps_method = WPS_P2PS;
6903 } else {
6904 pin = pos;
6905 pos = os_strchr(pin, ' ');
6906 wps_method = WPS_PIN_KEYPAD;
6907 if (pos) {
6908 *pos++ = '\0';
6909 if (os_strncmp(pos, "display", 7) == 0)
6910 wps_method = WPS_PIN_DISPLAY;
6911 }
6912 if (!wps_pin_str_valid(pin)) {
6913 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
6914 return 17;
6915 }
6916 }
6917
6918 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
6919 persistent_group, automatic, join,
6920 auth, go_intent, freq, freq2, persistent_id,
6921 pd, ht40, vht, max_oper_chwidth, he, edmg,
6922 group_ssid, group_ssid_len, allow_6ghz);
6923 if (new_pin == -2) {
6924 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
6925 return 25;
6926 }
6927 if (new_pin == -3) {
6928 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
6929 return 25;
6930 }
6931 if (new_pin < 0)
6932 return -1;
6933 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
6934 ret = os_snprintf(buf, buflen, "%08d", new_pin);
6935 if (os_snprintf_error(buflen, ret))
6936 return -1;
6937 return ret;
6938 }
6939
6940 os_memcpy(buf, "OK\n", 3);
6941 return 3;
6942 }
6943
6944
6945 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
6946 {
6947 unsigned int timeout = atoi(cmd);
6948 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6949 wpa_dbg(wpa_s, MSG_INFO,
6950 "Reject P2P_LISTEN since interface is disabled");
6951 return -1;
6952 }
6953 return wpas_p2p_listen(wpa_s, timeout);
6954 }
6955
6956
6957 int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
6958 {
6959 u8 addr[ETH_ALEN];
6960 char *pos;
6961 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
6962
6963 /* <addr> <config method> [join|auto] */
6964
6965 if (hwaddr_aton(cmd, addr))
6966 return -1;
6967
6968 pos = cmd + 17;
6969 if (*pos != ' ')
6970 return -1;
6971 pos++;
6972
6973 if (os_strstr(pos, " join") != NULL)
6974 use = WPAS_P2P_PD_FOR_JOIN;
6975 else if (os_strstr(pos, " auto") != NULL)
6976 use = WPAS_P2P_PD_AUTO;
6977
6978 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
6979 }
6980
6981
6982 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
6983 size_t buflen)
6984 {
6985 struct wpa_ssid *ssid = wpa_s->current_ssid;
6986
6987 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
6988 ssid->passphrase == NULL)
6989 return -1;
6990
6991 os_strlcpy(buf, ssid->passphrase, buflen);
6992 return os_strlen(buf);
6993 }
6994
6995
6996 int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
6997 char *buf, size_t buflen)
6998 {
6999 u64 ref;
7000 int res;
7001 u8 dst_buf[ETH_ALEN], *dst;
7002 struct wpabuf *tlvs;
7003 char *pos;
7004 size_t len;
7005
7006 if (hwaddr_aton(cmd, dst_buf))
7007 return -1;
7008 dst = dst_buf;
7009 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
7010 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
7011 dst = NULL;
7012 pos = cmd + 17;
7013 if (*pos != ' ')
7014 return -1;
7015 pos++;
7016
7017 if (os_strncmp(pos, "upnp ", 5) == 0) {
7018 u8 version;
7019 pos += 5;
7020 if (hexstr2bin(pos, &version, 1) < 0)
7021 return -1;
7022 pos += 2;
7023 if (*pos != ' ')
7024 return -1;
7025 pos++;
7026 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
7027 #ifdef CONFIG_WIFI_DISPLAY
7028 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
7029 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
7030 #endif /* CONFIG_WIFI_DISPLAY */
7031 } else if (os_strncmp(pos, "asp ", 4) == 0) {
7032 char *svc_str;
7033 char *svc_info = NULL;
7034 u32 id;
7035
7036 pos += 4;
7037 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
7038 return -1;
7039
7040 pos = os_strchr(pos, ' ');
7041 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
7042 return -1;
7043
7044 svc_str = pos + 1;
7045
7046 pos = os_strchr(svc_str, ' ');
7047
7048 if (pos)
7049 *pos++ = '\0';
7050
7051 /* All remaining data is the svc_info string */
7052 if (pos && pos[0] && pos[0] != ' ') {
7053 len = os_strlen(pos);
7054
7055 /* Unescape in place */
7056 len = utf8_unescape(pos, len, pos, len);
7057 if (len > 0xff)
7058 return -1;
7059
7060 svc_info = pos;
7061 }
7062
7063 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
7064 svc_str, svc_info);
7065 } else {
7066 len = os_strlen(pos);
7067 if (len & 1)
7068 return -1;
7069 len /= 2;
7070 tlvs = wpabuf_alloc(len);
7071 if (tlvs == NULL)
7072 return -1;
7073 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
7074 wpabuf_free(tlvs);
7075 return -1;
7076 }
7077
7078 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
7079 wpabuf_free(tlvs);
7080 }
7081 if (ref == 0)
7082 return -1;
7083 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
7084 if (os_snprintf_error(buflen, res))
7085 return -1;
7086 return res;
7087 }
7088
7089
7090 int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
7091 char *cmd)
7092 {
7093 long long unsigned val;
7094 u64 req;
7095 if (sscanf(cmd, "%llx", &val) != 1)
7096 return -1;
7097 req = val;
7098 return wpas_p2p_sd_cancel_request(wpa_s, req);
7099 }
7100
7101
7102 int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
7103 {
7104 int freq;
7105 u8 dst[ETH_ALEN];
7106 u8 dialog_token;
7107 struct wpabuf *resp_tlvs;
7108 char *pos, *pos2;
7109 size_t len;
7110
7111 pos = os_strchr(cmd, ' ');
7112 if (pos == NULL)
7113 return -1;
7114 *pos++ = '\0';
7115 freq = atoi(cmd);
7116 if (freq == 0)
7117 return -1;
7118
7119 if (hwaddr_aton(pos, dst))
7120 return -1;
7121 pos += 17;
7122 if (*pos != ' ')
7123 return -1;
7124 pos++;
7125
7126 pos2 = os_strchr(pos, ' ');
7127 if (pos2 == NULL)
7128 return -1;
7129 *pos2++ = '\0';
7130 dialog_token = atoi(pos);
7131
7132 len = os_strlen(pos2);
7133 if (len & 1)
7134 return -1;
7135 len /= 2;
7136 resp_tlvs = wpabuf_alloc(len);
7137 if (resp_tlvs == NULL)
7138 return -1;
7139 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
7140 wpabuf_free(resp_tlvs);
7141 return -1;
7142 }
7143
7144 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
7145 wpabuf_free(resp_tlvs);
7146 return 0;
7147 }
7148
7149
7150 int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
7151 char *cmd)
7152 {
7153 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
7154 return -1;
7155 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
7156 return 0;
7157 }
7158
7159
7160 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
7161 char *cmd)
7162 {
7163 char *pos;
7164 size_t len;
7165 struct wpabuf *query, *resp;
7166 int ret;
7167
7168 pos = os_strchr(cmd, ' ');
7169 if (pos == NULL)
7170 return -1;
7171 *pos++ = '\0';
7172
7173 len = os_strlen(cmd);
7174 if (len & 1)
7175 return -1;
7176 len /= 2;
7177 query = wpabuf_alloc(len);
7178 if (query == NULL)
7179 return -1;
7180 ret = hexstr2bin(cmd, wpabuf_put(query, len), len);
7181 if (ret < 0)
7182 goto err_query;
7183 ret = -1;
7184 len = os_strlen(pos);
7185 if (len & 1)
7186 goto err_query;
7187 len /= 2;
7188 resp = wpabuf_alloc(len);
7189 if (!resp)
7190 goto err_query;
7191 ret = hexstr2bin(pos, wpabuf_put(resp, len), len);
7192 if (ret < 0)
7193 goto err_resp;
7194
7195 ret = wpas_p2p_service_add_bonjour(wpa_s, query, resp);
7196
7197 err_resp:
7198 wpabuf_free(resp);
7199 err_query:
7200 wpabuf_free(query);
7201 return ret;
7202 }
7203
7204
7205 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
7206 {
7207 char *pos;
7208 u8 version;
7209
7210 pos = os_strchr(cmd, ' ');
7211 if (pos == NULL)
7212 return -1;
7213 *pos++ = '\0';
7214
7215 if (hexstr2bin(cmd, &version, 1) < 0)
7216 return -1;
7217
7218 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
7219 }
7220
7221
7222 static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
7223 u8 replace, char *cmd)
7224 {
7225 char *pos;
7226 char *adv_str;
7227 u32 auto_accept, adv_id, svc_state, config_methods;
7228 char *svc_info = NULL;
7229 char *cpt_prio_str;
7230 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
7231
7232 pos = os_strchr(cmd, ' ');
7233 if (pos == NULL)
7234 return -1;
7235 *pos++ = '\0';
7236
7237 /* Auto-Accept value is mandatory, and must be one of the
7238 * single values (0, 1, 2, 4) */
7239 auto_accept = atoi(cmd);
7240 switch (auto_accept) {
7241 case P2PS_SETUP_NONE: /* No auto-accept */
7242 case P2PS_SETUP_NEW:
7243 case P2PS_SETUP_CLIENT:
7244 case P2PS_SETUP_GROUP_OWNER:
7245 break;
7246 default:
7247 return -1;
7248 }
7249
7250 /* Advertisement ID is mandatory */
7251 cmd = pos;
7252 pos = os_strchr(cmd, ' ');
7253 if (pos == NULL)
7254 return -1;
7255 *pos++ = '\0';
7256
7257 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
7258 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
7259 return -1;
7260
7261 /* Only allow replacements if exist, and adds if not */
7262 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
7263 if (!replace)
7264 return -1;
7265 } else {
7266 if (replace)
7267 return -1;
7268 }
7269
7270 /* svc_state between 0 - 0xff is mandatory */
7271 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
7272 return -1;
7273
7274 pos = os_strchr(pos, ' ');
7275 if (pos == NULL)
7276 return -1;
7277
7278 /* config_methods is mandatory */
7279 pos++;
7280 if (sscanf(pos, "%x", &config_methods) != 1)
7281 return -1;
7282
7283 if (!(config_methods &
7284 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
7285 return -1;
7286
7287 pos = os_strchr(pos, ' ');
7288 if (pos == NULL)
7289 return -1;
7290
7291 pos++;
7292 adv_str = pos;
7293
7294 /* Advertisement string is mandatory */
7295 if (!pos[0] || pos[0] == ' ')
7296 return -1;
7297
7298 /* Terminate svc string */
7299 pos = os_strchr(pos, ' ');
7300 if (pos != NULL)
7301 *pos++ = '\0';
7302
7303 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
7304 if (cpt_prio_str) {
7305 pos = os_strchr(pos, ' ');
7306 if (pos != NULL)
7307 *pos++ = '\0';
7308
7309 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
7310 return -1;
7311 } else {
7312 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
7313 cpt_prio[1] = 0;
7314 }
7315
7316 /* Service and Response Information are optional */
7317 if (pos && pos[0]) {
7318 size_t len;
7319
7320 /* Note the bare ' included, which cannot exist legally
7321 * in unescaped string. */
7322 svc_info = os_strstr(pos, "svc_info='");
7323
7324 if (svc_info) {
7325 svc_info += 9;
7326 len = os_strlen(svc_info);
7327 utf8_unescape(svc_info, len, svc_info, len);
7328 }
7329 }
7330
7331 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
7332 (u8) svc_state, (u16) config_methods,
7333 svc_info, cpt_prio);
7334 }
7335
7336
7337 int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
7338 {
7339 char *pos;
7340
7341 pos = os_strchr(cmd, ' ');
7342 if (pos == NULL)
7343 return -1;
7344 *pos++ = '\0';
7345
7346 if (os_strcmp(cmd, "bonjour") == 0)
7347 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
7348 if (os_strcmp(cmd, "upnp") == 0)
7349 return p2p_ctrl_service_add_upnp(wpa_s, pos);
7350 if (os_strcmp(cmd, "asp") == 0)
7351 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
7352 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
7353 return -1;
7354 }
7355
7356
7357 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
7358 char *cmd)
7359 {
7360 size_t len;
7361 struct wpabuf *query;
7362 int ret;
7363
7364 len = os_strlen(cmd);
7365 if (len & 1)
7366 return -1;
7367 len /= 2;
7368 query = wpabuf_alloc(len);
7369 if (query == NULL)
7370 return -1;
7371 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
7372 wpabuf_free(query);
7373 return -1;
7374 }
7375
7376 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
7377 wpabuf_free(query);
7378 return ret;
7379 }
7380
7381
7382 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
7383 {
7384 char *pos;
7385 u8 version;
7386
7387 pos = os_strchr(cmd, ' ');
7388 if (pos == NULL)
7389 return -1;
7390 *pos++ = '\0';
7391
7392 if (hexstr2bin(cmd, &version, 1) < 0)
7393 return -1;
7394
7395 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
7396 }
7397
7398
7399 static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
7400 {
7401 u32 adv_id;
7402
7403 if (os_strcmp(cmd, "all") == 0) {
7404 wpas_p2p_service_flush_asp(wpa_s);
7405 return 0;
7406 }
7407
7408 if (sscanf(cmd, "%x", &adv_id) != 1)
7409 return -1;
7410
7411 return wpas_p2p_service_del_asp(wpa_s, adv_id);
7412 }
7413
7414
7415 int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
7416 {
7417 char *pos;
7418
7419 pos = os_strchr(cmd, ' ');
7420 if (pos == NULL)
7421 return -1;
7422 *pos++ = '\0';
7423
7424 if (os_strcmp(cmd, "bonjour") == 0)
7425 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
7426 if (os_strcmp(cmd, "upnp") == 0)
7427 return p2p_ctrl_service_del_upnp(wpa_s, pos);
7428 if (os_strcmp(cmd, "asp") == 0)
7429 return p2p_ctrl_service_del_asp(wpa_s, pos);
7430 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
7431 return -1;
7432 }
7433
7434
7435 static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
7436 {
7437 char *pos;
7438
7439 pos = os_strchr(cmd, ' ');
7440 if (pos == NULL)
7441 return -1;
7442 *pos++ = '\0';
7443
7444 if (os_strcmp(cmd, "asp") == 0)
7445 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
7446
7447 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
7448 return -1;
7449 }
7450
7451
7452 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
7453 {
7454 u8 addr[ETH_ALEN];
7455
7456 /* <addr> */
7457
7458 if (hwaddr_aton(cmd, addr))
7459 return -1;
7460
7461 return wpas_p2p_reject(wpa_s, addr);
7462 }
7463
7464
7465 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
7466 {
7467 char *pos;
7468 int id;
7469 struct wpa_ssid *ssid;
7470 u8 *_peer = NULL, peer[ETH_ALEN];
7471 int freq = 0, pref_freq = 0;
7472 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
7473 int edmg;
7474 bool allow_6ghz;
7475
7476 id = atoi(cmd);
7477 pos = os_strstr(cmd, " peer=");
7478 if (pos) {
7479 pos += 6;
7480 if (hwaddr_aton(pos, peer))
7481 return -1;
7482 _peer = peer;
7483 }
7484 ssid = wpa_config_get_network(wpa_s->conf, id);
7485 if (ssid == NULL || ssid->disabled != 2) {
7486 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
7487 "for persistent P2P group",
7488 id);
7489 return -1;
7490 }
7491
7492 pos = os_strstr(cmd, " freq=");
7493 if (pos) {
7494 pos += 6;
7495 freq = atoi(pos);
7496 if (freq <= 0)
7497 return -1;
7498 }
7499
7500 pos = os_strstr(cmd, " pref=");
7501 if (pos) {
7502 pos += 6;
7503 pref_freq = atoi(pos);
7504 if (pref_freq <= 0)
7505 return -1;
7506 }
7507
7508 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
7509 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
7510 vht;
7511 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
7512 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
7513
7514 pos = os_strstr(cmd, "freq2=");
7515 if (pos)
7516 freq2 = atoi(pos + 6);
7517
7518 pos = os_strstr(cmd, " max_oper_chwidth=");
7519 if (pos)
7520 chwidth = atoi(pos + 18);
7521
7522 max_oper_chwidth = chwidth_freq2_to_ch_width(chwidth, freq2);
7523 if (max_oper_chwidth < 0)
7524 return -1;
7525
7526 allow_6ghz = os_strstr(cmd, " allow_6ghz") != NULL;
7527
7528 if (allow_6ghz && chwidth == 40)
7529 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
7530
7531 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
7532 max_oper_chwidth, pref_freq, he, edmg,
7533 allow_6ghz);
7534 }
7535
7536
7537 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
7538 {
7539 char *pos;
7540 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
7541 bool allow_6ghz;
7542
7543 pos = os_strstr(cmd, " peer=");
7544 if (!pos)
7545 return -1;
7546
7547 *pos = '\0';
7548 pos += 6;
7549 if (hwaddr_aton(pos, peer)) {
7550 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
7551 return -1;
7552 }
7553
7554 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
7555
7556 pos = os_strstr(pos, " go_dev_addr=");
7557 if (pos) {
7558 pos += 13;
7559 if (hwaddr_aton(pos, go_dev_addr)) {
7560 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
7561 pos);
7562 return -1;
7563 }
7564 go_dev = go_dev_addr;
7565 }
7566
7567 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev, allow_6ghz);
7568 }
7569
7570
7571 int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
7572 {
7573 if (os_strncmp(cmd, "persistent=", 11) == 0)
7574 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
7575 if (os_strncmp(cmd, "group=", 6) == 0)
7576 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
7577
7578 return -1;
7579 }
7580
7581
7582 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
7583 int id, int freq, int vht_center_freq2,
7584 int ht40, int vht, int vht_chwidth,
7585 int he, int edmg, bool allow_6ghz,
7586 const u8 *go_bssid)
7587 {
7588 struct wpa_ssid *ssid;
7589
7590 ssid = wpa_config_get_network(wpa_s->conf, id);
7591 if (ssid == NULL || ssid->disabled != 2) {
7592 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
7593 "for persistent P2P group",
7594 id);
7595 return -1;
7596 }
7597
7598 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0,
7599 vht_center_freq2, ht40, vht,
7600 vht_chwidth, he, edmg,
7601 NULL, 0, 0, allow_6ghz, 0,
7602 go_bssid);
7603 }
7604
7605
7606 int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
7607 {
7608 int freq = 0, persistent = 0, group_id = -1;
7609 bool allow_6ghz = false;
7610 int vht = wpa_s->conf->p2p_go_vht;
7611 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
7612 int he = wpa_s->conf->p2p_go_he;
7613 int edmg = wpa_s->conf->p2p_go_edmg;
7614 int max_oper_chwidth, chwidth = 0, freq2 = 0;
7615 char *token, *context = NULL;
7616 u8 go_bssid_buf[ETH_ALEN], *go_bssid = NULL;
7617 #ifdef CONFIG_ACS
7618 int acs = 0;
7619 #endif /* CONFIG_ACS */
7620
7621 while ((token = str_token(cmd, " ", &context))) {
7622 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
7623 sscanf(token, "persistent=%d", &group_id) == 1 ||
7624 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
7625 continue;
7626 #ifdef CONFIG_ACS
7627 } else if (os_strcmp(token, "freq=acs") == 0) {
7628 acs = 1;
7629 #endif /* CONFIG_ACS */
7630 } else if (sscanf(token, "freq=%d", &freq) == 1) {
7631 continue;
7632 } else if (os_strcmp(token, "ht40") == 0) {
7633 ht40 = 1;
7634 } else if (os_strcmp(token, "vht") == 0) {
7635 vht = 1;
7636 ht40 = 1;
7637 } else if (os_strcmp(token, "he") == 0) {
7638 he = 1;
7639 } else if (os_strcmp(token, "edmg") == 0) {
7640 edmg = 1;
7641 } else if (os_strcmp(token, "persistent") == 0) {
7642 persistent = 1;
7643 } else if (os_strcmp(token, "allow_6ghz") == 0) {
7644 allow_6ghz = true;
7645 } else if (os_strncmp(token, "go_bssid=", 9) == 0) {
7646 if (hwaddr_aton(token + 9, go_bssid_buf))
7647 return -1;
7648 go_bssid = go_bssid_buf;
7649 #ifdef CONFIG_VENDOR_EXT
7650 } else if (os_strstr(token, "{") != NULL) {
7651 p2p_cmd_parse_add_group(wpa_s, token);
7652 #endif
7653 } else {
7654 wpa_printf(MSG_DEBUG,
7655 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
7656 token);
7657 return -1;
7658 }
7659 }
7660 #ifdef CONFIG_WIFI_RPT
7661 if (wpa_s->global != NULL && wpa_s->global->p2p != NULL &&
7662 wpa_s->global->p2p->p2p_rpt_net_id == group_id) {
7663 struct p2p_data *p2p = wpa_s->global->p2p;
7664 p2p->p2p_rpt_freq = freq;
7665 p2p->p2p_rpt = true;
7666 int ret = wpas_p2p_group_add(wpa_s, 0, 0, 0, 0, 0, 0, 0, 0, 0);
7667 if (ret < 0) {
7668 p2p->p2p_rpt = false;
7669 p2p->p2p_rpt_net_id = DEFAULT_RPT_ID;
7670 }
7671 return ret;
7672 }
7673 #endif /* CONFIG_WIFI_RPT */
7674
7675 #ifdef CONFIG_ACS
7676 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
7677 (acs || freq == 2 || freq == 5)) {
7678 if (freq == 2 && wpa_s->best_24_freq <= 0) {
7679 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
7680 wpa_s->p2p_go_do_acs = 1;
7681 freq = 0;
7682 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
7683 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
7684 wpa_s->p2p_go_do_acs = 1;
7685 freq = 0;
7686 } else {
7687 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
7688 wpa_s->p2p_go_do_acs = 1;
7689 }
7690 } else {
7691 wpa_s->p2p_go_do_acs = 0;
7692 }
7693 #endif /* CONFIG_ACS */
7694 #ifdef CONFIG_OPEN_HARMONY_PATCH
7695 #ifdef CONFIG_P2P_160M
7696 if (freq & P2P_160M_MASK) {
7697 freq = freq - P2P_160M_MASK;
7698 chwidth = 160;
7699 } else {
7700 chwidth = 80;
7701 }
7702 #endif
7703 #endif
7704 max_oper_chwidth = chwidth_freq2_to_ch_width(chwidth, freq2);
7705 wpa_printf(MSG_DEBUG, "wpa_supplicant::p2p_ctrl_group_add freq = %d, max_oper_chwidth = %d, group_id = %d",
7706 freq, max_oper_chwidth, group_id);
7707 if (max_oper_chwidth < 0)
7708 return -1;
7709
7710 if (allow_6ghz && chwidth == 40)
7711 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
7712
7713 /* Allow DFS to be used for Autonomous GO */
7714 wpa_s->p2p_go_allow_dfs = !!(wpa_s->drv_flags &
7715 WPA_DRIVER_FLAGS_DFS_OFFLOAD);
7716
7717 if (group_id >= 0)
7718 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
7719 freq, freq2, ht40, vht,
7720 max_oper_chwidth, he,
7721 edmg, allow_6ghz,
7722 go_bssid);
7723
7724 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
7725 max_oper_chwidth, he, edmg, allow_6ghz);
7726 }
7727
7728
7729 static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
7730 char *buf, size_t buflen)
7731 {
7732 u8 dev_addr[ETH_ALEN];
7733 struct wpa_ssid *ssid;
7734 int res;
7735 const u8 *iaddr;
7736
7737 ssid = wpa_s->current_ssid;
7738 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
7739 hwaddr_aton(cmd, dev_addr))
7740 return -1;
7741
7742 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
7743 if (!iaddr)
7744 return -1;
7745 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
7746 if (os_snprintf_error(buflen, res))
7747 return -1;
7748 return res;
7749 }
7750
7751
7752 static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
7753 const u8 *p2p_dev_addr)
7754 {
7755 struct wpa_supplicant *wpa_s;
7756
7757 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7758 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
7759 return 1;
7760 }
7761
7762 return 0;
7763 }
7764
7765
7766 int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
7767 char *buf, size_t buflen)
7768 {
7769 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
7770 int next, res;
7771 const struct p2p_peer_info *info;
7772 char *pos, *end;
7773 char devtype[WPS_DEV_TYPE_BUFSIZE];
7774 struct wpa_ssid *ssid;
7775 size_t i;
7776
7777 if (!wpa_s->global->p2p)
7778 return -1;
7779
7780 if (os_strcmp(cmd, "FIRST") == 0) {
7781 addr_ptr = NULL;
7782 next = 0;
7783 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
7784 if (hwaddr_aton(cmd + 5, addr) < 0)
7785 return -1;
7786 addr_ptr = addr;
7787 next = 1;
7788 } else {
7789 if (hwaddr_aton(cmd, addr) < 0)
7790 return -1;
7791 addr_ptr = addr;
7792 next = 0;
7793 }
7794
7795 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
7796 if (info == NULL)
7797 return -1;
7798 group_capab = info->group_capab;
7799
7800 if (group_capab &&
7801 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
7802 wpa_printf(MSG_DEBUG,
7803 "P2P: Could not find any BSS with p2p_dev_addr "
7804 MACSTR_SEC ", hence override group_capab from 0x%x to 0",
7805 MAC2STR_SEC(info->p2p_device_addr), group_capab);
7806 group_capab = 0;
7807 }
7808
7809 pos = buf;
7810 end = buf + buflen;
7811
7812 res = os_snprintf(pos, end - pos, MACSTR "\n"
7813 "pri_dev_type=%s\n"
7814 "device_name=%s\n"
7815 "manufacturer=%s\n"
7816 "model_name=%s\n"
7817 "model_number=%s\n"
7818 "serial_number=%s\n"
7819 "config_methods=0x%x\n"
7820 "dev_capab=0x%x\n"
7821 "group_capab=0x%x\n"
7822 "level=%d\n",
7823 MAC2STR(info->p2p_device_addr),
7824 wps_dev_type_bin2str(info->pri_dev_type,
7825 devtype, sizeof(devtype)),
7826 info->device_name,
7827 info->manufacturer,
7828 info->model_name,
7829 info->model_number,
7830 info->serial_number,
7831 info->config_methods,
7832 info->dev_capab,
7833 group_capab,
7834 info->level);
7835 if (os_snprintf_error(end - pos, res))
7836 return pos - buf;
7837 pos += res;
7838
7839 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
7840 {
7841 const u8 *t;
7842 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
7843 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
7844 wps_dev_type_bin2str(t, devtype,
7845 sizeof(devtype)));
7846 if (os_snprintf_error(end - pos, res))
7847 return pos - buf;
7848 pos += res;
7849 }
7850
7851 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
7852 if (ssid) {
7853 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
7854 if (os_snprintf_error(end - pos, res))
7855 return pos - buf;
7856 pos += res;
7857 }
7858
7859 res = p2p_get_peer_info_txt(info, pos, end - pos);
7860 if (res < 0)
7861 return pos - buf;
7862 pos += res;
7863
7864 if (info->vendor_elems) {
7865 res = os_snprintf(pos, end - pos, "vendor_elems=");
7866 if (os_snprintf_error(end - pos, res))
7867 return pos - buf;
7868 pos += res;
7869
7870 pos += wpa_snprintf_hex(pos, end - pos,
7871 wpabuf_head(info->vendor_elems),
7872 wpabuf_len(info->vendor_elems));
7873
7874 res = os_snprintf(pos, end - pos, "\n");
7875 if (os_snprintf_error(end - pos, res))
7876 return pos - buf;
7877 pos += res;
7878 }
7879
7880 return pos - buf;
7881 }
7882
7883
7884 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
7885 const char *param)
7886 {
7887 unsigned int i;
7888
7889 if (wpa_s->global->p2p == NULL)
7890 return -1;
7891
7892 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
7893 return -1;
7894
7895 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
7896 struct wpa_freq_range *freq;
7897 freq = &wpa_s->global->p2p_disallow_freq.range[i];
7898 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
7899 freq->min, freq->max);
7900 }
7901
7902 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
7903 return 0;
7904 }
7905
7906
7907 int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
7908 {
7909 char *param;
7910
7911 if (wpa_s->global->p2p == NULL)
7912 return -1;
7913
7914 param = os_strchr(cmd, ' ');
7915 if (param == NULL)
7916 return -1;
7917 *param++ = '\0';
7918
7919 if (os_strcmp(cmd, "discoverability") == 0) {
7920 p2p_set_client_discoverability(wpa_s->global->p2p,
7921 atoi(param));
7922 return 0;
7923 }
7924
7925 if (os_strcmp(cmd, "managed") == 0) {
7926 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
7927 return 0;
7928 }
7929
7930 if (os_strcmp(cmd, "listen_channel") == 0) {
7931 char *pos;
7932 u8 channel, op_class;
7933
7934 channel = atoi(param);
7935 pos = os_strchr(param, ' ');
7936 op_class = pos ? atoi(pos) : 81;
7937
7938 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
7939 channel, 1);
7940 }
7941
7942 if (os_strcmp(cmd, "ssid_postfix") == 0) {
7943 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
7944 os_strlen(param));
7945 }
7946
7947 if (os_strcmp(cmd, "noa") == 0) {
7948 char *pos;
7949 int count, start, duration;
7950 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
7951 count = atoi(param);
7952 pos = os_strchr(param, ',');
7953 if (pos == NULL)
7954 return -1;
7955 pos++;
7956 start = atoi(pos);
7957 pos = os_strchr(pos, ',');
7958 if (pos == NULL)
7959 return -1;
7960 pos++;
7961 duration = atoi(pos);
7962 if (count < 0 || count > 255 || start < 0 || duration < 0)
7963 return -1;
7964 if (count == 0 && duration > 0)
7965 return -1;
7966 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
7967 "start=%d duration=%d", count, start, duration);
7968 return wpas_p2p_set_noa(wpa_s, count, start, duration);
7969 }
7970
7971 if (os_strcmp(cmd, "ps") == 0)
7972 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
7973
7974 if (os_strcmp(cmd, "oppps") == 0)
7975 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
7976
7977 if (os_strcmp(cmd, "ctwindow") == 0)
7978 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
7979
7980 if (os_strcmp(cmd, "disabled") == 0) {
7981 wpa_s->global->p2p_disabled = atoi(param);
7982 wpa_printf(MSG_DEBUG, "P2P functionality %s",
7983 wpa_s->global->p2p_disabled ?
7984 "disabled" : "enabled");
7985 if (wpa_s->global->p2p_disabled) {
7986 wpas_p2p_stop_find(wpa_s);
7987 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7988 p2p_flush(wpa_s->global->p2p);
7989 }
7990 return 0;
7991 }
7992
7993 if (os_strcmp(cmd, "conc_pref") == 0) {
7994 if (os_strcmp(param, "sta") == 0)
7995 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
7996 else if (os_strcmp(param, "p2p") == 0)
7997 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
7998 else {
7999 wpa_printf(MSG_INFO, "Invalid conc_pref value");
8000 return -1;
8001 }
8002 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
8003 "%s", param);
8004 return 0;
8005 }
8006
8007 if (os_strcmp(cmd, "force_long_sd") == 0) {
8008 wpa_s->force_long_sd = atoi(param);
8009 return 0;
8010 }
8011
8012 if (os_strcmp(cmd, "peer_filter") == 0) {
8013 u8 addr[ETH_ALEN];
8014 if (hwaddr_aton(param, addr))
8015 return -1;
8016 p2p_set_peer_filter(wpa_s->global->p2p, addr);
8017 return 0;
8018 }
8019
8020 if (os_strcmp(cmd, "cross_connect") == 0)
8021 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
8022
8023 if (os_strcmp(cmd, "go_apsd") == 0) {
8024 if (os_strcmp(param, "disable") == 0)
8025 wpa_s->set_ap_uapsd = 0;
8026 else {
8027 wpa_s->set_ap_uapsd = 1;
8028 wpa_s->ap_uapsd = atoi(param);
8029 }
8030 return 0;
8031 }
8032
8033 if (os_strcmp(cmd, "client_apsd") == 0) {
8034 if (os_strcmp(param, "disable") == 0)
8035 wpa_s->set_sta_uapsd = 0;
8036 else {
8037 int be, bk, vi, vo;
8038 char *pos;
8039 /* format: BE,BK,VI,VO;max SP Length */
8040 be = atoi(param);
8041 pos = os_strchr(param, ',');
8042 if (pos == NULL)
8043 return -1;
8044 pos++;
8045 bk = atoi(pos);
8046 pos = os_strchr(pos, ',');
8047 if (pos == NULL)
8048 return -1;
8049 pos++;
8050 vi = atoi(pos);
8051 pos = os_strchr(pos, ',');
8052 if (pos == NULL)
8053 return -1;
8054 pos++;
8055 vo = atoi(pos);
8056 /* ignore max SP Length for now */
8057
8058 wpa_s->set_sta_uapsd = 1;
8059 wpa_s->sta_uapsd = 0;
8060 if (be)
8061 wpa_s->sta_uapsd |= BIT(0);
8062 if (bk)
8063 wpa_s->sta_uapsd |= BIT(1);
8064 if (vi)
8065 wpa_s->sta_uapsd |= BIT(2);
8066 if (vo)
8067 wpa_s->sta_uapsd |= BIT(3);
8068 }
8069 return 0;
8070 }
8071
8072 if (os_strcmp(cmd, "disallow_freq") == 0)
8073 return p2p_ctrl_disallow_freq(wpa_s, param);
8074
8075 if (os_strcmp(cmd, "disc_int") == 0) {
8076 int min_disc_int, max_disc_int, max_disc_tu;
8077 char *pos;
8078
8079 pos = param;
8080
8081 min_disc_int = atoi(pos);
8082 pos = os_strchr(pos, ' ');
8083 if (pos == NULL)
8084 return -1;
8085 *pos++ = '\0';
8086
8087 max_disc_int = atoi(pos);
8088 pos = os_strchr(pos, ' ');
8089 if (pos == NULL)
8090 return -1;
8091 *pos++ = '\0';
8092
8093 max_disc_tu = atoi(pos);
8094
8095 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
8096 max_disc_int, max_disc_tu);
8097 }
8098
8099 if (os_strcmp(cmd, "per_sta_psk") == 0) {
8100 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
8101 return 0;
8102 }
8103
8104 #ifdef CONFIG_WPS_NFC
8105 if (os_strcmp(cmd, "nfc_tag") == 0)
8106 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
8107 #endif /* CONFIG_WPS_NFC */
8108
8109 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
8110 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
8111 return 0;
8112 }
8113
8114 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
8115 int op_class, chan;
8116
8117 op_class = atoi(param);
8118 param = os_strchr(param, ':');
8119 if (!param)
8120 return -1;
8121 param++;
8122 chan = atoi(param);
8123 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
8124 chan);
8125 return 0;
8126 }
8127 #ifdef HARMONY_P2P_CONNECTIVITY_PATCH
8128 if (os_strcmp(cmd, "enable_go_neg_opt") == 0) {
8129 int enable_go_neg_opt;
8130 enable_go_neg_opt = atoi(param);
8131 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GON optimization: enable=%d ", enable_go_neg_opt);
8132 if(enable_go_neg_opt == 0 || enable_go_neg_opt == 1) {
8133 p2p_set_enable_go_neg_opt(wpa_s->global->p2p, enable_go_neg_opt);
8134 p2p_set_process_go_neg_opt(wpa_s->global->p2p, enable_go_neg_opt);
8135 } else {
8136 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET unknown enable_go_neg_opt '%d'",enable_go_neg_opt);
8137 return -1;
8138 }
8139 return 0;
8140 }
8141 #endif
8142
8143 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
8144 cmd);
8145
8146 return -1;
8147 }
8148
8149
8150 void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
8151 {
8152 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
8153 wpa_s->force_long_sd = 0;
8154
8155 #ifdef CONFIG_TESTING_OPTIONS
8156 os_free(wpa_s->get_pref_freq_list_override);
8157 wpa_s->get_pref_freq_list_override = NULL;
8158 #endif /* CONFIG_TESTING_OPTIONS */
8159
8160 wpas_p2p_stop_find(wpa_s);
8161 wpa_s->parent->p2ps_method_config_any = 0;
8162 if (wpa_s->global->p2p)
8163 p2p_flush(wpa_s->global->p2p);
8164 }
8165
8166
8167 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
8168 {
8169 char *pos, *pos2;
8170 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
8171
8172 if (cmd[0]) {
8173 pos = os_strchr(cmd, ' ');
8174 if (pos == NULL)
8175 return -1;
8176 *pos++ = '\0';
8177 dur1 = atoi(cmd);
8178
8179 pos2 = os_strchr(pos, ' ');
8180 if (pos2)
8181 *pos2++ = '\0';
8182 int1 = atoi(pos);
8183 } else
8184 pos2 = NULL;
8185
8186 if (pos2) {
8187 pos = os_strchr(pos2, ' ');
8188 if (pos == NULL)
8189 return -1;
8190 *pos++ = '\0';
8191 dur2 = atoi(pos2);
8192 int2 = atoi(pos);
8193 }
8194
8195 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
8196 }
8197
8198
8199 int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
8200 {
8201 char *pos;
8202 unsigned int period = 0, interval = 0;
8203
8204 if (cmd[0]) {
8205 pos = os_strchr(cmd, ' ');
8206 if (pos == NULL)
8207 return -1;
8208 *pos++ = '\0';
8209 period = atoi(cmd);
8210 interval = atoi(pos);
8211 }
8212
8213 return wpas_p2p_ext_listen(wpa_s, period, interval);
8214 }
8215
8216
8217 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
8218 {
8219 const char *pos;
8220 u8 peer[ETH_ALEN];
8221 int iface_addr = 0;
8222
8223 pos = cmd;
8224 if (os_strncmp(pos, "iface=", 6) == 0) {
8225 iface_addr = 1;
8226 pos += 6;
8227 }
8228 if (hwaddr_aton(pos, peer))
8229 return -1;
8230
8231 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
8232 return 0;
8233 }
8234
8235
8236 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
8237 {
8238 int freq = 0, period = 0, interval = 0, count = 0;
8239
8240 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
8241 {
8242 wpa_printf(MSG_DEBUG,
8243 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
8244 return -1;
8245 }
8246
8247 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
8248 }
8249
8250 #endif /* CONFIG_P2P */
8251
8252
8253 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
8254 {
8255 struct wpa_freq_range_list ranges;
8256 int *freqs = NULL;
8257 struct hostapd_hw_modes *mode;
8258 u16 i;
8259
8260 if (wpa_s->hw.modes == NULL)
8261 return NULL;
8262
8263 os_memset(&ranges, 0, sizeof(ranges));
8264 if (freq_range_list_parse(&ranges, val) < 0)
8265 return NULL;
8266
8267 for (i = 0; i < wpa_s->hw.num_modes; i++) {
8268 int j;
8269
8270 mode = &wpa_s->hw.modes[i];
8271 for (j = 0; j < mode->num_channels; j++) {
8272 unsigned int freq;
8273
8274 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
8275 continue;
8276
8277 freq = mode->channels[j].freq;
8278 if (!freq_range_list_includes(&ranges, freq))
8279 continue;
8280
8281 int_array_add_unique(&freqs, freq);
8282 }
8283 }
8284
8285 os_free(ranges.range);
8286 return freqs;
8287 }
8288
8289
8290 #ifdef CONFIG_INTERWORKING
8291
8292 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
8293 {
8294 int auto_sel = 0;
8295 int *freqs = NULL;
8296
8297 if (param) {
8298 char *pos;
8299
8300 auto_sel = os_strstr(param, "auto") != NULL;
8301
8302 pos = os_strstr(param, "freq=");
8303 if (pos) {
8304 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
8305 if (freqs == NULL)
8306 return -1;
8307 }
8308
8309 }
8310
8311 return interworking_select(wpa_s, auto_sel, freqs);
8312 }
8313
8314
8315 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
8316 int only_add)
8317 {
8318 u8 bssid[ETH_ALEN];
8319 struct wpa_bss *bss;
8320
8321 if (hwaddr_aton(dst, bssid)) {
8322 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
8323 return -1;
8324 }
8325
8326 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
8327 if (bss == NULL) {
8328 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR_SEC,
8329 MAC2STR_SEC(bssid));
8330 return -1;
8331 }
8332
8333 if (bss->ssid_len == 0) {
8334 int found = 0;
8335
8336 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR_SEC
8337 " does not have SSID information", MAC2STR_SEC(bssid));
8338
8339 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
8340 list) {
8341 if (ether_addr_equal(bss->bssid, bssid) &&
8342 bss->ssid_len > 0) {
8343 found = 1;
8344 break;
8345 }
8346 }
8347
8348 if (!found)
8349 return -1;
8350 wpa_printf(MSG_DEBUG,
8351 "Found another matching BSS entry with SSID");
8352 }
8353
8354 return interworking_connect(wpa_s, bss, only_add);
8355 }
8356
8357
8358 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
8359 {
8360 u8 dst_addr[ETH_ALEN];
8361 int used, freq = 0;
8362 char *pos;
8363 #define MAX_ANQP_INFO_ID 100
8364 u16 id[MAX_ANQP_INFO_ID];
8365 size_t num_id = 0;
8366 u32 subtypes = 0;
8367 u32 mbo_subtypes = 0;
8368
8369 used = hwaddr_aton2(dst, dst_addr);
8370 if (used < 0)
8371 return -1;
8372 pos = dst + used;
8373 if (*pos == ' ')
8374 pos++;
8375
8376 if (os_strncmp(pos, "freq=", 5) == 0) {
8377 freq = atoi(pos + 5);
8378 pos = os_strchr(pos, ' ');
8379 if (!pos)
8380 return -1;
8381 pos++;
8382 }
8383
8384 while (num_id < MAX_ANQP_INFO_ID) {
8385 if (os_strncmp(pos, "hs20:", 5) == 0) {
8386 #ifdef CONFIG_HS20
8387 int num = atoi(pos + 5);
8388 if (num <= 0 || num > 31)
8389 return -1;
8390 subtypes |= BIT(num);
8391 #else /* CONFIG_HS20 */
8392 return -1;
8393 #endif /* CONFIG_HS20 */
8394 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
8395 #ifdef CONFIG_MBO
8396 int num = atoi(pos + 4);
8397
8398 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
8399 return -1;
8400 mbo_subtypes |= BIT(num);
8401 #else /* CONFIG_MBO */
8402 return -1;
8403 #endif /* CONFIG_MBO */
8404 } else {
8405 id[num_id] = atoi(pos);
8406 if (id[num_id])
8407 num_id++;
8408 }
8409 pos = os_strchr(pos + 1, ',');
8410 if (pos == NULL)
8411 break;
8412 pos++;
8413 }
8414
8415 if (num_id == 0 && !subtypes && !mbo_subtypes)
8416 return -1;
8417
8418 return anqp_send_req(wpa_s, dst_addr, freq, id, num_id, subtypes,
8419 mbo_subtypes);
8420 }
8421
8422
8423 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
8424 {
8425 u8 dst_addr[ETH_ALEN];
8426 struct wpabuf *advproto, *query = NULL;
8427 int used, ret = -1;
8428 char *pos, *end;
8429 size_t len;
8430
8431 used = hwaddr_aton2(cmd, dst_addr);
8432 if (used < 0)
8433 return -1;
8434
8435 pos = cmd + used;
8436 while (*pos == ' ')
8437 pos++;
8438
8439 /* Advertisement Protocol ID */
8440 end = os_strchr(pos, ' ');
8441 if (end)
8442 len = end - pos;
8443 else
8444 len = os_strlen(pos);
8445 if (len & 0x01)
8446 return -1;
8447 len /= 2;
8448 if (len == 0)
8449 return -1;
8450 advproto = wpabuf_alloc(len);
8451 if (advproto == NULL)
8452 return -1;
8453 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
8454 goto fail;
8455
8456 if (end) {
8457 /* Optional Query Request */
8458 pos = end + 1;
8459 while (*pos == ' ')
8460 pos++;
8461
8462 len = os_strlen(pos);
8463 if (len) {
8464 if (len & 0x01)
8465 goto fail;
8466 len /= 2;
8467 if (len == 0)
8468 goto fail;
8469 query = wpabuf_alloc(len);
8470 if (query == NULL)
8471 goto fail;
8472 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
8473 goto fail;
8474 }
8475 }
8476
8477 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
8478
8479 fail:
8480 wpabuf_free(advproto);
8481 wpabuf_free(query);
8482
8483 return ret;
8484 }
8485
8486
8487 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
8488 size_t buflen)
8489 {
8490 u8 addr[ETH_ALEN];
8491 int dialog_token;
8492 int used;
8493 char *pos;
8494 size_t resp_len, start, requested_len;
8495 struct wpabuf *resp;
8496 int ret;
8497
8498 used = hwaddr_aton2(cmd, addr);
8499 if (used < 0)
8500 return -1;
8501
8502 pos = cmd + used;
8503 while (*pos == ' ')
8504 pos++;
8505 dialog_token = atoi(pos);
8506
8507 if (wpa_s->last_gas_resp &&
8508 ether_addr_equal(addr, wpa_s->last_gas_addr) &&
8509 dialog_token == wpa_s->last_gas_dialog_token)
8510 resp = wpa_s->last_gas_resp;
8511 else if (wpa_s->prev_gas_resp &&
8512 ether_addr_equal(addr, wpa_s->prev_gas_addr) &&
8513 dialog_token == wpa_s->prev_gas_dialog_token)
8514 resp = wpa_s->prev_gas_resp;
8515 else
8516 return -1;
8517
8518 resp_len = wpabuf_len(resp);
8519 start = 0;
8520 requested_len = resp_len;
8521
8522 pos = os_strchr(pos, ' ');
8523 if (pos) {
8524 start = atoi(pos);
8525 if (start > resp_len)
8526 return os_snprintf(buf, buflen, "FAIL-Invalid range");
8527 pos = os_strchr(pos, ',');
8528 if (pos == NULL)
8529 return -1;
8530 pos++;
8531 requested_len = atoi(pos);
8532 if (start + requested_len > resp_len)
8533 return os_snprintf(buf, buflen, "FAIL-Invalid range");
8534 }
8535
8536 if (requested_len * 2 + 1 > buflen)
8537 return os_snprintf(buf, buflen, "FAIL-Too long response");
8538
8539 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
8540 requested_len);
8541
8542 if (start + requested_len == resp_len) {
8543 /*
8544 * Free memory by dropping the response after it has been
8545 * fetched.
8546 */
8547 if (resp == wpa_s->prev_gas_resp) {
8548 wpabuf_free(wpa_s->prev_gas_resp);
8549 wpa_s->prev_gas_resp = NULL;
8550 } else {
8551 wpabuf_free(wpa_s->last_gas_resp);
8552 wpa_s->last_gas_resp = NULL;
8553 }
8554 }
8555
8556 return ret;
8557 }
8558 #endif /* CONFIG_INTERWORKING */
8559
8560
8561 #ifdef CONFIG_HS20
8562
8563 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
8564 {
8565 u8 dst_addr[ETH_ALEN];
8566 int used;
8567 char *pos;
8568 u32 subtypes = 0;
8569
8570 used = hwaddr_aton2(dst, dst_addr);
8571 if (used < 0)
8572 return -1;
8573 pos = dst + used;
8574 if (*pos == ' ')
8575 pos++;
8576 for (;;) {
8577 int num = atoi(pos);
8578 if (num <= 0 || num > 31)
8579 return -1;
8580 subtypes |= BIT(num);
8581 pos = os_strchr(pos + 1, ',');
8582 if (pos == NULL)
8583 break;
8584 pos++;
8585 }
8586
8587 if (subtypes == 0)
8588 return -1;
8589
8590 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
8591 }
8592
8593
8594 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
8595 const u8 *addr, const char *realm)
8596 {
8597 u8 *buf;
8598 size_t rlen, len;
8599 int ret;
8600
8601 rlen = os_strlen(realm);
8602 len = 3 + rlen;
8603 buf = os_malloc(len);
8604 if (buf == NULL)
8605 return -1;
8606 buf[0] = 1; /* NAI Home Realm Count */
8607 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
8608 buf[2] = rlen;
8609 os_memcpy(buf + 3, realm, rlen);
8610
8611 ret = hs20_anqp_send_req(wpa_s, addr,
8612 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
8613 buf, len, 0);
8614
8615 os_free(buf);
8616
8617 return ret;
8618 }
8619
8620
8621 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
8622 char *dst)
8623 {
8624 struct wpa_cred *cred = wpa_s->conf->cred;
8625 u8 dst_addr[ETH_ALEN];
8626 int used;
8627 u8 *buf;
8628 size_t len;
8629 int ret;
8630
8631 used = hwaddr_aton2(dst, dst_addr);
8632 if (used < 0)
8633 return -1;
8634
8635 while (dst[used] == ' ')
8636 used++;
8637 if (os_strncmp(dst + used, "realm=", 6) == 0)
8638 return hs20_nai_home_realm_list(wpa_s, dst_addr,
8639 dst + used + 6);
8640
8641 len = os_strlen(dst + used);
8642
8643 if (len == 0 && cred && cred->realm)
8644 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
8645
8646 if (len & 1)
8647 return -1;
8648 len /= 2;
8649 buf = os_malloc(len);
8650 if (buf == NULL)
8651 return -1;
8652 if (hexstr2bin(dst + used, buf, len) < 0) {
8653 os_free(buf);
8654 return -1;
8655 }
8656
8657 ret = hs20_anqp_send_req(wpa_s, dst_addr,
8658 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
8659 buf, len, 0);
8660 os_free(buf);
8661
8662 return ret;
8663 }
8664
8665
8666 static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
8667 int buflen)
8668 {
8669 u8 dst_addr[ETH_ALEN];
8670 int used;
8671 char *ctx = NULL, *icon, *poffset, *psize;
8672
8673 used = hwaddr_aton2(cmd, dst_addr);
8674 if (used < 0)
8675 return -1;
8676 cmd += used;
8677
8678 icon = str_token(cmd, " ", &ctx);
8679 poffset = str_token(cmd, " ", &ctx);
8680 psize = str_token(cmd, " ", &ctx);
8681 if (!icon || !poffset || !psize)
8682 return -1;
8683
8684 wpa_s->fetch_osu_icon_in_progress = 0;
8685 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
8686 reply, buflen);
8687 }
8688
8689
8690 static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
8691 {
8692 u8 dst_addr[ETH_ALEN];
8693 int used;
8694 char *icon;
8695
8696 if (!cmd[0])
8697 return hs20_del_icon(wpa_s, NULL, NULL);
8698
8699 used = hwaddr_aton2(cmd, dst_addr);
8700 if (used < 0)
8701 return -1;
8702
8703 while (cmd[used] == ' ')
8704 used++;
8705 icon = cmd[used] ? &cmd[used] : NULL;
8706
8707 return hs20_del_icon(wpa_s, dst_addr, icon);
8708 }
8709
8710
8711 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
8712 {
8713 u8 dst_addr[ETH_ALEN];
8714 int used;
8715 char *icon;
8716
8717 used = hwaddr_aton2(cmd, dst_addr);
8718 if (used < 0)
8719 return -1;
8720
8721 while (cmd[used] == ' ')
8722 used++;
8723 icon = &cmd[used];
8724
8725 wpa_s->fetch_osu_icon_in_progress = 0;
8726 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
8727 (u8 *) icon, os_strlen(icon), inmem);
8728 }
8729
8730 #endif /* CONFIG_HS20 */
8731
8732
8733 #ifdef CONFIG_AUTOSCAN
8734
8735 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
8736 char *cmd)
8737 {
8738 enum wpa_states state = wpa_s->wpa_state;
8739 char *new_params = NULL;
8740
8741 if (os_strlen(cmd) > 0) {
8742 new_params = os_strdup(cmd);
8743 if (new_params == NULL)
8744 return -1;
8745 }
8746
8747 os_free(wpa_s->conf->autoscan);
8748 wpa_s->conf->autoscan = new_params;
8749
8750 if (wpa_s->conf->autoscan == NULL)
8751 autoscan_deinit(wpa_s);
8752 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
8753 autoscan_init(wpa_s, 1);
8754 else if (state == WPA_SCANNING)
8755 wpa_supplicant_reinit_autoscan(wpa_s);
8756 else
8757 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
8758 wpa_supplicant_state_txt(state));
8759
8760 return 0;
8761 }
8762
8763 #endif /* CONFIG_AUTOSCAN */
8764
8765
8766 #ifdef CONFIG_WNM
8767
8768 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
8769 {
8770 int enter;
8771 int intval = 0;
8772 char *pos;
8773 int ret;
8774 struct wpabuf *tfs_req = NULL;
8775
8776 if (os_strncmp(cmd, "enter", 5) == 0)
8777 enter = 1;
8778 else if (os_strncmp(cmd, "exit", 4) == 0)
8779 enter = 0;
8780 else
8781 return -1;
8782
8783 pos = os_strstr(cmd, " interval=");
8784 if (pos)
8785 intval = atoi(pos + 10);
8786
8787 pos = os_strstr(cmd, " tfs_req=");
8788 if (pos) {
8789 char *end;
8790 size_t len;
8791 pos += 9;
8792 end = os_strchr(pos, ' ');
8793 if (end)
8794 len = end - pos;
8795 else
8796 len = os_strlen(pos);
8797 if (len & 1)
8798 return -1;
8799 len /= 2;
8800 tfs_req = wpabuf_alloc(len);
8801 if (tfs_req == NULL)
8802 return -1;
8803 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
8804 wpabuf_free(tfs_req);
8805 return -1;
8806 }
8807 }
8808
8809 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
8810 WNM_SLEEP_MODE_EXIT, intval,
8811 tfs_req);
8812 wpabuf_free(tfs_req);
8813
8814 return ret;
8815 }
8816
8817
8818 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
8819 {
8820 int query_reason, list = 0;
8821 char *btm_candidates = NULL;
8822
8823 query_reason = atoi(cmd);
8824
8825 cmd = os_strchr(cmd, ' ');
8826 if (cmd) {
8827 if (os_strncmp(cmd, " list", 5) == 0)
8828 list = 1;
8829 else
8830 btm_candidates = cmd;
8831 }
8832
8833 wpa_printf(MSG_DEBUG,
8834 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
8835 query_reason, list ? " candidate list" : "");
8836
8837 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
8838 btm_candidates,
8839 list);
8840 }
8841
8842
8843 static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
8844 char *cmd)
8845 {
8846 struct wpabuf *elems;
8847 int ret;
8848
8849 elems = wpabuf_parse_bin(cmd);
8850 if (!elems)
8851 return -1;
8852
8853 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
8854 wpabuf_free(elems);
8855 return ret;
8856 }
8857
8858 #endif /* CONFIG_WNM */
8859
8860
8861 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
8862 size_t buflen)
8863 {
8864 struct wpa_signal_info si;
8865 int ret;
8866 char *pos, *end;
8867
8868 ret = wpa_drv_signal_poll(wpa_s, &si);
8869 if (ret)
8870 return -1;
8871
8872 pos = buf;
8873 end = buf + buflen;
8874
8875 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%lu\n"
8876 "NOISE=%d\nFREQUENCY=%u\n",
8877 si.data.signal, si.data.current_tx_rate / 1000,
8878 si.current_noise, si.frequency);
8879 if (os_snprintf_error(end - pos, ret))
8880 return -1;
8881 pos += ret;
8882
8883 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
8884 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
8885 channel_width_to_string(si.chanwidth));
8886 if (os_snprintf_error(end - pos, ret))
8887 return -1;
8888 pos += ret;
8889 }
8890
8891 if (si.center_frq1 > 0) {
8892 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
8893 si.center_frq1);
8894 if (os_snprintf_error(end - pos, ret))
8895 return -1;
8896 pos += ret;
8897 }
8898
8899 if (si.center_frq2 > 0) {
8900 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
8901 si.center_frq2);
8902 if (os_snprintf_error(end - pos, ret))
8903 return -1;
8904 pos += ret;
8905 }
8906
8907 if (si.data.avg_signal) {
8908 ret = os_snprintf(pos, end - pos,
8909 "AVG_RSSI=%d\n", si.data.avg_signal);
8910 if (os_snprintf_error(end - pos, ret))
8911 return -1;
8912 pos += ret;
8913 }
8914
8915 if (si.data.avg_beacon_signal) {
8916 ret = os_snprintf(pos, end - pos,
8917 "AVG_BEACON_RSSI=%d\n",
8918 si.data.avg_beacon_signal);
8919 if (os_snprintf_error(end - pos, ret))
8920 return -1;
8921 pos += ret;
8922 }
8923
8924 return pos - buf;
8925 }
8926
8927
8928 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
8929 const char *cmd)
8930 {
8931 const char *pos;
8932 int threshold = 0;
8933 int hysteresis = 0;
8934
8935 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
8936 wpa_printf(MSG_DEBUG,
8937 "Reject SIGNAL_MONITOR command - bgscan is active");
8938 return -1;
8939 }
8940 pos = os_strstr(cmd, "THRESHOLD=");
8941 if (pos)
8942 threshold = atoi(pos + 10);
8943 pos = os_strstr(cmd, "HYSTERESIS=");
8944 if (pos)
8945 hysteresis = atoi(pos + 11);
8946 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
8947 }
8948
8949
8950 #ifdef CONFIG_TESTING_OPTIONS
8951 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
8952 enum wpa_driver_if_type if_type,
8953 unsigned int *num,
8954 struct weighted_pcl *freq_list)
8955 {
8956 char *pos = wpa_s->get_pref_freq_list_override;
8957 char *end;
8958 unsigned int count = 0;
8959
8960 /* Override string format:
8961 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
8962
8963 while (pos) {
8964 if (atoi(pos) == (int) if_type)
8965 break;
8966 pos = os_strchr(pos, ' ');
8967 if (pos)
8968 pos++;
8969 }
8970 if (!pos)
8971 return -1;
8972 pos = os_strchr(pos, ':');
8973 if (!pos)
8974 return -1;
8975 pos++;
8976 end = os_strchr(pos, ' ');
8977 while (pos && (!end || pos < end) && count < *num) {
8978 freq_list[count].freq = atoi(pos);
8979 freq_list[count++].flag = WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI;
8980 pos = os_strchr(pos, ',');
8981 if (pos)
8982 pos++;
8983 }
8984
8985 *num = count;
8986 return 0;
8987 }
8988 #endif /* CONFIG_TESTING_OPTIONS */
8989
8990
8991 static int wpas_ctrl_iface_get_pref_freq_list(
8992 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
8993 {
8994 unsigned int num = 100, i;
8995 int ret;
8996 enum wpa_driver_if_type iface_type;
8997 char *pos, *end;
8998 struct weighted_pcl freq_list[100];
8999
9000 pos = buf;
9001 end = buf + buflen;
9002
9003 /* buf: "<interface_type>" */
9004 if (os_strcmp(cmd, "STATION") == 0)
9005 iface_type = WPA_IF_STATION;
9006 else if (os_strcmp(cmd, "AP") == 0)
9007 iface_type = WPA_IF_AP_BSS;
9008 else if (os_strcmp(cmd, "P2P_GO") == 0)
9009 iface_type = WPA_IF_P2P_GO;
9010 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
9011 iface_type = WPA_IF_P2P_CLIENT;
9012 else if (os_strcmp(cmd, "IBSS") == 0)
9013 iface_type = WPA_IF_IBSS;
9014 else if (os_strcmp(cmd, "TDLS") == 0)
9015 iface_type = WPA_IF_TDLS;
9016 else
9017 return -1;
9018
9019 wpa_printf(MSG_DEBUG,
9020 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
9021 iface_type, cmd);
9022
9023 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
9024 if (ret)
9025 return -1;
9026
9027 for (i = 0; i < num; i++) {
9028 ret = os_snprintf(pos, end - pos, "%s%u",
9029 i > 0 ? "," : "", freq_list[i].freq);
9030 if (os_snprintf_error(end - pos, ret))
9031 return -1;
9032 pos += ret;
9033 }
9034
9035 return pos - buf;
9036 }
9037
9038
9039 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
9040 char *buf, size_t buflen)
9041 {
9042 int ret, i;
9043 char *pos, *end;
9044
9045 ret = os_snprintf(buf, buflen, "%016llX:\n",
9046 (long long unsigned) wpa_s->drv_flags);
9047 if (os_snprintf_error(buflen, ret))
9048 return -1;
9049
9050 pos = buf + ret;
9051 end = buf + buflen;
9052 if (strcmp(wpa_s->ifname, "p2p0") == 0) {
9053 wpa_s->drv_flags |= WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE;
9054 }
9055 for (i = 0; i < 64; i++) {
9056 if (wpa_s->drv_flags & (1LLU << i)) {
9057 ret = os_snprintf(pos, end - pos, "%s\n",
9058 driver_flag_to_string(1LLU << i));
9059 if (os_snprintf_error(end - pos, ret))
9060 return -1;
9061 pos += ret;
9062 }
9063 }
9064
9065 return pos - buf;
9066 }
9067
9068
9069 static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s,
9070 char *buf, size_t buflen)
9071 {
9072 int ret, i;
9073 char *pos, *end;
9074
9075 ret = os_snprintf(buf, buflen, "%016llX:\n",
9076 (long long unsigned) wpa_s->drv_flags2);
9077 if (os_snprintf_error(buflen, ret))
9078 return -1;
9079
9080 pos = buf + ret;
9081 end = buf + buflen;
9082
9083 for (i = 0; i < 64; i++) {
9084 if (wpa_s->drv_flags2 & (1LLU << i)) {
9085 ret = os_snprintf(pos, end - pos, "%s\n",
9086 driver_flag2_to_string(1LLU << i));
9087 if (os_snprintf_error(end - pos, ret))
9088 return -1;
9089 pos += ret;
9090 }
9091 }
9092
9093 return pos - buf;
9094 }
9095
9096
9097 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
9098 size_t buflen)
9099 {
9100 struct hostap_sta_driver_data sta;
9101 int ret;
9102
9103 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
9104 if (ret)
9105 return -1;
9106
9107 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
9108 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
9109 if (os_snprintf_error(buflen, ret))
9110 return -1;
9111 return ret;
9112 }
9113
9114 int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
9115 char *buf, size_t buflen)
9116 {
9117 #if defined(ANDROID) || defined(CONFIG_DRIVER_NL80211_HISI)
9118 int ret;
9119 size_t len = buflen;
9120 wpa_printf(MSG_INFO, "CONFIG_DRIVER_NL80211_HISI and enter wpa_supplicant_driver_cmd");
9121
9122 #ifdef CONFIG_OPEN_HARMONY_PATCH
9123 len = buflen > 4096 ? 4096 : buflen;
9124 #endif
9125 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, len);
9126 if (ret == 0) {
9127 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
9128 struct p2p_data *p2p = wpa_s->global->p2p;
9129 if (p2p) {
9130 char country[3];
9131 country[0] = cmd[8];
9132 country[1] = cmd[9];
9133 country[2] = 0x04;
9134 p2p_set_country(p2p, country);
9135 }
9136 }
9137 ret = os_snprintf(buf, buflen, "%s\n", "OK");
9138 if (os_snprintf_error(buflen, ret))
9139 ret = -1;
9140 }
9141 return ret;
9142 #else
9143 wpa_printf(MSG_ERROR, "don't CONFIG_DRIVER_NL80211_HISI and enter wpa_supplicant_driver_cmd");
9144 return -1;
9145 #endif /* ANDROID || CONFIG_DRIVER_NL80211_HISI */
9146 }
9147
9148
9149 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
9150 char *buf, size_t buflen)
9151 {
9152 int ret;
9153 char *pos, *temp = NULL;
9154 u8 *data = NULL;
9155 unsigned int vendor_id, subcmd;
9156 enum nested_attr nested_attr_flag = NESTED_ATTR_UNSPECIFIED;
9157 struct wpabuf *reply;
9158 size_t data_len = 0;
9159
9160 /**
9161 * cmd: <vendor id> <subcommand id> [<hex formatted data>]
9162 * [nested=<0|1>]
9163 */
9164 vendor_id = strtoul(cmd, &pos, 16);
9165 if (!isblank((unsigned char) *pos))
9166 return -EINVAL;
9167
9168 subcmd = strtoul(pos, &pos, 10);
9169
9170 if (*pos != '\0') {
9171 if (!isblank((unsigned char) *pos++))
9172 return -EINVAL;
9173
9174 temp = os_strchr(pos, ' ');
9175 data_len = temp ? (size_t) (temp - pos) : os_strlen(pos);
9176 }
9177
9178 if (data_len) {
9179 data_len /= 2;
9180 data = os_malloc(data_len);
9181 if (!data)
9182 return -1;
9183
9184 if (hexstr2bin(pos, data, data_len)) {
9185 wpa_printf(MSG_DEBUG,
9186 "Vendor command: wrong parameter format");
9187 os_free(data);
9188 return -EINVAL;
9189 }
9190 }
9191
9192 pos = os_strstr(cmd, "nested=");
9193 if (pos)
9194 nested_attr_flag = atoi(pos + 7) ? NESTED_ATTR_USED :
9195 NESTED_ATTR_NOT_USED;
9196
9197 reply = wpabuf_alloc((buflen - 1) / 2);
9198 if (!reply) {
9199 os_free(data);
9200 return -1;
9201 }
9202
9203 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
9204 nested_attr_flag, reply);
9205
9206 if (ret == 0)
9207 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
9208 wpabuf_len(reply));
9209
9210 wpabuf_free(reply);
9211 os_free(data);
9212
9213 return ret;
9214 }
9215
9216
9217 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
9218 {
9219 #ifdef CONFIG_P2P
9220 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
9221 wpa_s->global->p2p_init_wpa_s : wpa_s;
9222 #endif /* CONFIG_P2P */
9223
9224 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
9225
9226 if (wpas_abort_ongoing_scan(wpa_s) == 0)
9227 wpa_s->ignore_post_flush_scan_res = 1;
9228
9229 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
9230 /*
9231 * Avoid possible auto connect re-connection on getting
9232 * disconnected due to state flush.
9233 */
9234 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
9235 }
9236
9237 #ifdef CONFIG_P2P
9238 wpas_p2p_group_remove(p2p_wpa_s, "*");
9239 wpas_p2p_cancel(p2p_wpa_s);
9240 p2p_ctrl_flush(p2p_wpa_s);
9241 wpas_p2p_service_flush(p2p_wpa_s);
9242 p2p_wpa_s->global->p2p_disabled = 0;
9243 p2p_wpa_s->global->p2p_per_sta_psk = 0;
9244 p2p_wpa_s->conf->num_sec_device_types = 0;
9245 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
9246 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
9247 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
9248 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
9249 p2p_wpa_s->global->pending_p2ps_group = 0;
9250 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
9251 #endif /* CONFIG_P2P */
9252
9253 #ifdef CONFIG_WPS_TESTING
9254 wps_version_number = 0x20;
9255 wps_testing_stub_cred = 0;
9256 wps_corrupt_pkhash = 0;
9257 wps_force_auth_types_in_use = 0;
9258 wps_force_encr_types_in_use = 0;
9259 #endif /* CONFIG_WPS_TESTING */
9260 #ifdef CONFIG_WPS
9261 wpa_s->wps_fragment_size = 0;
9262 wpas_wps_cancel(wpa_s);
9263 wps_registrar_flush(wpa_s->wps->registrar);
9264 #endif /* CONFIG_WPS */
9265 wpa_s->after_wps = 0;
9266 wpa_s->known_wps_freq = 0;
9267
9268 #ifdef CONFIG_DPP
9269 wpas_dpp_deinit(wpa_s);
9270 wpa_s->dpp_init_max_tries = 0;
9271 wpa_s->dpp_init_retry_time = 0;
9272 wpa_s->dpp_resp_wait_time = 0;
9273 wpa_s->dpp_resp_max_tries = 0;
9274 wpa_s->dpp_resp_retry_time = 0;
9275 #ifdef CONFIG_DPP2
9276 wpas_dpp_chirp_stop(wpa_s);
9277 wpa_s->dpp_pfs_fallback = 0;
9278 #endif /* CONFIG_DPP2 */
9279 #ifdef CONFIG_DPP3
9280 {
9281 int i;
9282
9283 for (i = 0; i < DPP_PB_INFO_COUNT; i++) {
9284 struct dpp_pb_info *info;
9285
9286 info = &wpa_s->dpp_pb[i];
9287 info->rx_time.sec = 0;
9288 info->rx_time.usec = 0;
9289 }
9290 }
9291 #endif /* CONFIG_DPP3 */
9292 #ifdef CONFIG_TESTING_OPTIONS
9293 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
9294 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
9295 dpp_pkex_ephemeral_key_override_len = 0;
9296 dpp_protocol_key_override_len = 0;
9297 dpp_nonce_override_len = 0;
9298 #ifdef CONFIG_DPP3
9299 dpp_version_override = 3;
9300 #elif defined(CONFIG_DPP2)
9301 dpp_version_override = 2;
9302 #else /* CONFIG_DPP2 */
9303 dpp_version_override = 1;
9304 #endif /* CONFIG_DPP2 */
9305 #endif /* CONFIG_TESTING_OPTIONS */
9306 #endif /* CONFIG_DPP */
9307
9308 #ifdef CONFIG_TDLS
9309 #ifdef CONFIG_TDLS_TESTING
9310 tdls_testing = 0;
9311 #endif /* CONFIG_TDLS_TESTING */
9312 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
9313 wpa_tdls_enable(wpa_s->wpa, 1);
9314 #endif /* CONFIG_TDLS */
9315
9316 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
9317 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
9318 wpa_s->last_michael_mic_error.sec = 0;
9319
9320 wpa_s->no_keep_alive = 0;
9321 wpa_s->own_disconnect_req = 0;
9322 wpa_s->own_reconnect_req = 0;
9323 wpa_s->deny_ptk0_rekey = 0;
9324
9325 os_free(wpa_s->disallow_aps_bssid);
9326 wpa_s->disallow_aps_bssid = NULL;
9327 wpa_s->disallow_aps_bssid_count = 0;
9328 os_free(wpa_s->disallow_aps_ssid);
9329 wpa_s->disallow_aps_ssid = NULL;
9330 wpa_s->disallow_aps_ssid_count = 0;
9331
9332 wpa_s->set_sta_uapsd = 0;
9333 wpa_s->sta_uapsd = 0;
9334
9335 wpa_s->consecutive_conn_failures = 0;
9336
9337 wpa_drv_radio_disable(wpa_s, 0);
9338 wpa_bssid_ignore_clear(wpa_s);
9339 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
9340 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
9341 wpa_config_flush_blobs(wpa_s->conf);
9342 wpa_s->conf->auto_interworking = 0;
9343 wpa_s->conf->okc = 0;
9344
9345 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
9346 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
9347 rsn_preauth_deinit(wpa_s->wpa);
9348
9349 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
9350 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
9351 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
9352 eapol_sm_notify_logoff(wpa_s->eapol, false);
9353
9354 radio_remove_works(wpa_s, NULL, 1);
9355 wpa_s->ext_work_in_progress = 0;
9356
9357 wpa_s->next_ssid = NULL;
9358
9359 wnm_btm_reset(wpa_s);
9360
9361 #ifdef CONFIG_INTERWORKING
9362 #ifdef CONFIG_HS20
9363 hs20_cancel_fetch_osu(wpa_s);
9364 hs20_del_icon(wpa_s, NULL, NULL);
9365 #endif /* CONFIG_HS20 */
9366 #endif /* CONFIG_INTERWORKING */
9367
9368 wpa_s->ext_mgmt_frame_handling = 0;
9369 wpa_s->ext_eapol_frame_io = 0;
9370 #ifdef CONFIG_TESTING_OPTIONS
9371 wpa_s->extra_roc_dur = 0;
9372 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
9373 wpa_s->p2p_go_csa_on_inv = 0;
9374 wpa_s->ignore_auth_resp = 0;
9375 wpa_s->ignore_assoc_disallow = 0;
9376 wpa_s->disable_sa_query = 0;
9377 wpa_s->testing_resend_assoc = 0;
9378 wpa_s->ignore_sae_h2e_only = 0;
9379 wpa_s->ft_rsnxe_used = 0;
9380 wpa_s->reject_btm_req_reason = 0;
9381 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
9382 wpa_sm_set_test_eapol_m2_elems(wpa_s->wpa, NULL);
9383 wpa_sm_set_test_eapol_m4_elems(wpa_s->wpa, NULL);
9384 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ENCRYPT_EAPOL_M2, 0);
9385 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ENCRYPT_EAPOL_M4, 0);
9386 os_free(wpa_s->get_pref_freq_list_override);
9387 wpa_s->get_pref_freq_list_override = NULL;
9388 wpabuf_free(wpa_s->sae_commit_override);
9389 wpa_s->sae_commit_override = NULL;
9390 os_free(wpa_s->extra_sae_rejected_groups);
9391 wpa_s->extra_sae_rejected_groups = NULL;
9392 wpabuf_free(wpa_s->rsne_override_eapol);
9393 wpa_s->rsne_override_eapol = NULL;
9394 wpabuf_free(wpa_s->rsnxe_override_assoc);
9395 wpa_s->rsnxe_override_assoc = NULL;
9396 wpabuf_free(wpa_s->rsnxe_override_eapol);
9397 wpa_s->rsnxe_override_eapol = NULL;
9398 wpas_clear_driver_signal_override(wpa_s);
9399 #ifndef CONFIG_NO_ROBUST_AV
9400 wpa_s->disable_scs_support = 0;
9401 wpa_s->disable_mscs_support = 0;
9402 wpa_s->enable_dscp_policy_capa = 0;
9403 #endif /* CONFIG_NO_ROBUST_AV */
9404 wpa_s->oci_freq_override_eapol = 0;
9405 wpa_s->oci_freq_override_saquery_req = 0;
9406 wpa_s->oci_freq_override_saquery_resp = 0;
9407 wpa_s->oci_freq_override_eapol_g2 = 0;
9408 wpa_s->oci_freq_override_ft_assoc = 0;
9409 wpa_s->oci_freq_override_fils_assoc = 0;
9410 wpa_s->oci_freq_override_wnm_sleep = 0;
9411 wpa_s->disable_eapol_g2_tx = 0;
9412 wpa_s->test_assoc_comeback_type = -1;
9413 #ifdef CONFIG_DPP
9414 os_free(wpa_s->dpp_config_obj_override);
9415 wpa_s->dpp_config_obj_override = NULL;
9416 os_free(wpa_s->dpp_discovery_override);
9417 wpa_s->dpp_discovery_override = NULL;
9418 os_free(wpa_s->dpp_groups_override);
9419 wpa_s->dpp_groups_override = NULL;
9420 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
9421 wpa_s->dpp_discard_public_action = 0;
9422 dpp_test = DPP_TEST_DISABLED;
9423 #endif /* CONFIG_DPP */
9424 #endif /* CONFIG_TESTING_OPTIONS */
9425
9426 wpa_s->disconnected = 0;
9427 os_free(wpa_s->next_scan_freqs);
9428 wpa_s->next_scan_freqs = NULL;
9429 os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN);
9430 wpa_s->next_scan_bssid_wildcard_ssid = 0;
9431 os_free(wpa_s->select_network_scan_freqs);
9432 wpa_s->select_network_scan_freqs = NULL;
9433 #ifndef CONFIG_NO_ROBUST_AV
9434 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
9435 #endif /* CONFIG_NO_ROBUST_AV */
9436
9437 wpa_bss_flush(wpa_s);
9438 if (!dl_list_empty(&wpa_s->bss)) {
9439 wpa_printf(MSG_DEBUG,
9440 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
9441 MACSTR_SEC " pending_bssid=" MACSTR_SEC,
9442 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
9443 MAC2STR_SEC(wpa_s->bssid),
9444 MAC2STR_SEC(wpa_s->pending_bssid));
9445 }
9446
9447 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
9448 wpa_s->wnmsleep_used = 0;
9449
9450 #ifdef CONFIG_SME
9451 wpa_s->sme.last_unprot_disconnect.sec = 0;
9452 wpa_s->sme.auth_alg = 0;
9453 #endif /* CONFIG_SME */
9454
9455 wpabuf_free(wpa_s->ric_ies);
9456 wpa_s->ric_ies = NULL;
9457
9458 wpa_supplicant_update_channel_list(wpa_s, NULL);
9459
9460 free_bss_tmp_disallowed(wpa_s);
9461
9462 #ifndef CONFIG_NO_ROBUST_AV
9463 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
9464 #endif /* CONFIG_NO_ROBUST_AV */
9465
9466 #ifdef CONFIG_PASN
9467 wpas_pasn_auth_stop(wpa_s);
9468 #endif /* CONFIG_PASN */
9469
9470 if (wpa_s->mac_addr_changed && wpa_s->conf->mac_addr == 0)
9471 wpas_restore_permanent_mac_addr(wpa_s);
9472
9473 wpa_s->conf->ignore_old_scan_res = 0;
9474
9475 #ifdef CONFIG_NAN_USD
9476 wpas_nan_usd_flush(wpa_s);
9477 #endif /* CONFIG_NAN_USD */
9478 }
9479
9480
9481 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
9482 char *buf, size_t buflen)
9483 {
9484 struct wpa_radio_work *work;
9485 char *pos, *end;
9486 struct os_reltime now, diff;
9487
9488 pos = buf;
9489 end = buf + buflen;
9490
9491 os_get_reltime(&now);
9492
9493 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
9494 {
9495 int ret;
9496
9497 os_reltime_sub(&now, &work->time, &diff);
9498 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
9499 work->type, work->wpa_s->ifname, work->freq,
9500 work->started, diff.sec, diff.usec);
9501 if (os_snprintf_error(end - pos, ret))
9502 break;
9503 pos += ret;
9504 }
9505
9506 return pos - buf;
9507 }
9508
9509
9510 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
9511 {
9512 struct wpa_radio_work *work = eloop_ctx;
9513 struct wpa_external_work *ework = work->ctx;
9514
9515 wpa_dbg(work->wpa_s, MSG_DEBUG,
9516 "Timing out external radio work %u (%s)",
9517 ework->id, work->type);
9518 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
9519 work->wpa_s->ext_work_in_progress = 0;
9520 radio_work_done(work);
9521 os_free(ework);
9522 }
9523
9524
9525 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
9526 {
9527 struct wpa_external_work *ework = work->ctx;
9528
9529 if (deinit) {
9530 if (work->started)
9531 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
9532 work, NULL);
9533
9534 /*
9535 * work->type points to a buffer in ework, so need to replace
9536 * that here with a fixed string to avoid use of freed memory
9537 * in debug prints.
9538 */
9539 work->type = "freed-ext-work";
9540 work->ctx = NULL;
9541 os_free(ework);
9542 return;
9543 }
9544
9545 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
9546 ework->id, ework->type);
9547 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
9548 work->wpa_s->ext_work_in_progress = 1;
9549 if (!ework->timeout)
9550 ework->timeout = 10;
9551 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
9552 work, NULL);
9553 }
9554
9555
9556 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
9557 char *buf, size_t buflen)
9558 {
9559 struct wpa_external_work *ework;
9560 char *pos, *pos2;
9561 size_t type_len;
9562 int ret;
9563 unsigned int freq = 0;
9564
9565 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
9566
9567 ework = os_zalloc(sizeof(*ework));
9568 if (ework == NULL)
9569 return -1;
9570
9571 pos = os_strchr(cmd, ' ');
9572 if (pos) {
9573 type_len = pos - cmd;
9574 pos++;
9575
9576 pos2 = os_strstr(pos, "freq=");
9577 if (pos2)
9578 freq = atoi(pos2 + 5);
9579
9580 pos2 = os_strstr(pos, "timeout=");
9581 if (pos2)
9582 ework->timeout = atoi(pos2 + 8);
9583 } else {
9584 type_len = os_strlen(cmd);
9585 }
9586 if (4 + type_len >= sizeof(ework->type))
9587 type_len = sizeof(ework->type) - 4 - 1;
9588 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
9589 os_memcpy(ework->type + 4, cmd, type_len);
9590 ework->type[4 + type_len] = '\0';
9591
9592 wpa_s->ext_work_id++;
9593 if (wpa_s->ext_work_id == 0)
9594 wpa_s->ext_work_id++;
9595 ework->id = wpa_s->ext_work_id;
9596
9597 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
9598 ework) < 0) {
9599 os_free(ework);
9600 return -1;
9601 }
9602
9603 ret = os_snprintf(buf, buflen, "%u", ework->id);
9604 if (os_snprintf_error(buflen, ret))
9605 return -1;
9606 return ret;
9607 }
9608
9609
9610 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
9611 {
9612 struct wpa_radio_work *work;
9613 unsigned int id = atoi(cmd);
9614
9615 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
9616 {
9617 struct wpa_external_work *ework;
9618
9619 if (os_strncmp(work->type, "ext:", 4) != 0)
9620 continue;
9621 ework = work->ctx;
9622 if (id && ework->id != id)
9623 continue;
9624 wpa_dbg(wpa_s, MSG_DEBUG,
9625 "Completed external radio work %u (%s)",
9626 ework->id, ework->type);
9627 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
9628 wpa_s->ext_work_in_progress = 0;
9629 radio_work_done(work);
9630 os_free(ework);
9631 return 3; /* "OK\n" */
9632 }
9633
9634 return -1;
9635 }
9636
9637
9638 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
9639 char *buf, size_t buflen)
9640 {
9641 if (os_strcmp(cmd, "show") == 0)
9642 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
9643 if (os_strncmp(cmd, "add ", 4) == 0)
9644 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
9645 if (os_strncmp(cmd, "done ", 5) == 0)
9646 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
9647 return -1;
9648 }
9649
9650
9651 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
9652 {
9653 struct wpa_radio_work *work, *tmp;
9654
9655 if (!wpa_s || !wpa_s->radio)
9656 return;
9657
9658 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
9659 struct wpa_radio_work, list) {
9660 struct wpa_external_work *ework;
9661
9662 if (os_strncmp(work->type, "ext:", 4) != 0)
9663 continue;
9664 ework = work->ctx;
9665 wpa_dbg(wpa_s, MSG_DEBUG,
9666 "Flushing%s external radio work %u (%s)",
9667 work->started ? " started" : "", ework->id,
9668 ework->type);
9669 if (work->started)
9670 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
9671 work, NULL);
9672 radio_work_done(work);
9673 os_free(ework);
9674 }
9675 }
9676
9677
9678 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
9679 {
9680 struct wpa_supplicant *wpa_s = eloop_ctx;
9681 eapol_sm_notify_ctrl_response(wpa_s->eapol);
9682 }
9683
9684
9685 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
9686 unsigned int *scan_id_count, int scan_id[])
9687 {
9688 const char *pos = value;
9689
9690 while (pos) {
9691 if (*pos == ' ' || *pos == '\0')
9692 break;
9693 if (*scan_id_count == MAX_SCAN_ID)
9694 return -1;
9695 scan_id[(*scan_id_count)++] = atoi(pos);
9696 pos = os_strchr(pos, ',');
9697 if (pos)
9698 pos++;
9699 }
9700
9701 return 0;
9702 }
9703
9704
9705 void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
9706 char *reply, int reply_size, int *reply_len)
9707 {
9708 wpa_printf(MSG_INFO, "Ready to start scan");
9709 char *pos;
9710 unsigned int manual_scan_passive = 0;
9711 unsigned int manual_scan_use_id = 0;
9712 unsigned int manual_scan_only_new = 0;
9713 unsigned int scan_only = 0;
9714 unsigned int scan_id_count = 0;
9715 unsigned int manual_non_coloc_6ghz = 0;
9716 int scan_id[MAX_SCAN_ID];
9717 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
9718 struct wpa_scan_results *scan_res);
9719 int *manual_scan_freqs = NULL;
9720 struct wpa_ssid_value *ssid = NULL, *ns;
9721 unsigned int ssid_count = 0;
9722 wpa_printf(MSG_DEBUG, "enter wpas_ctrl_scan");
9723
9724 if (wpa_s != NULL) {
9725 wpa_printf(MSG_DEBUG, "wpa_s = %p", wpa_s);
9726 } else {
9727 wpa_printf(MSG_DEBUG, "wpa_s = NULL");
9728 }
9729 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
9730 *reply_len = -1;
9731 return;
9732 }
9733
9734 if (radio_work_pending(wpa_s, "scan")) {
9735 wpa_printf(MSG_DEBUG,
9736 "Pending scan scheduled - reject new request");
9737 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9738 return;
9739 }
9740
9741 #ifdef CONFIG_INTERWORKING
9742 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
9743 wpa_printf(MSG_DEBUG,
9744 "Interworking select in progress - reject new scan");
9745 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9746 return;
9747 }
9748 #endif /* CONFIG_INTERWORKING */
9749
9750 if (params) {
9751 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
9752 scan_only = 1;
9753
9754 pos = os_strstr(params, "freq=");
9755 if (pos) {
9756 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
9757 pos + 5);
9758 if (manual_scan_freqs == NULL) {
9759 *reply_len = -1;
9760 goto done;
9761 }
9762 }
9763
9764 pos = os_strstr(params, "passive=");
9765 if (pos)
9766 manual_scan_passive = !!atoi(pos + 8);
9767
9768 pos = os_strstr(params, "use_id=");
9769 if (pos)
9770 manual_scan_use_id = atoi(pos + 7);
9771
9772 pos = os_strstr(params, "only_new=1");
9773 if (pos)
9774 manual_scan_only_new = 1;
9775
9776 pos = os_strstr(params, "scan_id=");
9777 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
9778 scan_id) < 0) {
9779 *reply_len = -1;
9780 goto done;
9781 }
9782
9783 pos = os_strstr(params, "bssid=");
9784 if (pos) {
9785 u8 bssid[ETH_ALEN];
9786
9787 pos += 6;
9788 if (hwaddr_aton(pos, bssid)) {
9789 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
9790 *reply_len = -1;
9791 goto done;
9792 }
9793 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
9794
9795 wpa_s->next_scan_bssid_wildcard_ssid =
9796 os_strstr(params, "wildcard_ssid=1") != NULL;
9797 }
9798
9799 pos = os_strstr(params, "non_coloc_6ghz=");
9800 if (pos)
9801 manual_non_coloc_6ghz = !!atoi(pos + 15);
9802
9803 pos = params;
9804 while (pos && *pos != '\0') {
9805 if (os_strncmp(pos, "ssid ", 5) == 0) {
9806 char *end;
9807
9808 pos += 5;
9809 end = pos;
9810 while (*end) {
9811 if (*end == '\0' || *end == ' ')
9812 break;
9813 end++;
9814 }
9815
9816 ns = os_realloc_array(
9817 ssid, ssid_count + 1,
9818 sizeof(struct wpa_ssid_value));
9819 if (ns == NULL) {
9820 *reply_len = -1;
9821 goto done;
9822 }
9823 ssid = ns;
9824
9825 if ((end - pos) & 0x01 ||
9826 end - pos > 2 * SSID_MAX_LEN ||
9827 hexstr2bin(pos, ssid[ssid_count].ssid,
9828 (end - pos) / 2) < 0) {
9829 wpa_printf(MSG_DEBUG,
9830 "Invalid SSID value '%s'",
9831 pos);
9832 *reply_len = -1;
9833 goto done;
9834 }
9835 ssid[ssid_count].ssid_len = (end - pos) / 2;
9836 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
9837 ssid[ssid_count].ssid,
9838 ssid[ssid_count].ssid_len);
9839 ssid_count++;
9840 pos = end;
9841 }
9842
9843 pos = os_strchr(pos, ' ');
9844 if (pos)
9845 pos++;
9846 }
9847 }
9848
9849 wpa_s->num_ssids_from_scan_req = ssid_count;
9850 os_free(wpa_s->ssids_from_scan_req);
9851 if (ssid_count) {
9852 wpa_s->ssids_from_scan_req = ssid;
9853 ssid = NULL;
9854 } else {
9855 wpa_s->ssids_from_scan_req = NULL;
9856 }
9857
9858 if (scan_only)
9859 scan_res_handler = scan_only_handler;
9860 else if (wpa_s->scan_res_handler == scan_only_handler)
9861 scan_res_handler = NULL;
9862 else
9863 scan_res_handler = wpa_s->scan_res_handler;
9864
9865 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
9866 ((wpa_s->wpa_state <= WPA_SCANNING) ||
9867 (wpa_s->wpa_state == WPA_COMPLETED))) {
9868 wpa_s->manual_scan_passive = manual_scan_passive;
9869 wpa_s->manual_scan_use_id = manual_scan_use_id;
9870 wpa_s->manual_scan_only_new = manual_scan_only_new;
9871 wpa_s->scan_id_count = scan_id_count;
9872 wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz;
9873 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9874 wpa_s->scan_res_handler = scan_res_handler;
9875 os_free(wpa_s->manual_scan_freqs);
9876 wpa_s->manual_scan_freqs = manual_scan_freqs;
9877 manual_scan_freqs = NULL;
9878
9879 wpa_s->normal_scans = 0;
9880 wpa_s->scan_req = MANUAL_SCAN_REQ;
9881 wpa_s->after_wps = 0;
9882 wpa_s->known_wps_freq = 0;
9883 wpa_supplicant_req_scan(wpa_s, 0, 0);
9884 if (wpa_s->manual_scan_use_id) {
9885 wpa_s->manual_scan_id++;
9886 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9887 wpa_s->manual_scan_id);
9888 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9889 wpa_s->manual_scan_id);
9890 }
9891 } else if (wpa_s->sched_scanning) {
9892 wpa_s->manual_scan_passive = manual_scan_passive;
9893 wpa_s->manual_scan_use_id = manual_scan_use_id;
9894 wpa_s->manual_scan_only_new = manual_scan_only_new;
9895 wpa_s->scan_id_count = scan_id_count;
9896 wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz;
9897 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9898 wpa_s->scan_res_handler = scan_res_handler;
9899 os_free(wpa_s->manual_scan_freqs);
9900 wpa_s->manual_scan_freqs = manual_scan_freqs;
9901 manual_scan_freqs = NULL;
9902
9903 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
9904 wpa_supplicant_cancel_sched_scan(wpa_s);
9905 wpa_s->scan_req = MANUAL_SCAN_REQ;
9906 wpa_supplicant_req_scan(wpa_s, 0, 0);
9907 if (wpa_s->manual_scan_use_id) {
9908 wpa_s->manual_scan_id++;
9909 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9910 wpa_s->manual_scan_id);
9911 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9912 wpa_s->manual_scan_id);
9913 }
9914 } else {
9915 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
9916 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9917 }
9918
9919 done:
9920 os_free(manual_scan_freqs);
9921 os_free(ssid);
9922 }
9923
9924
9925 #ifdef CONFIG_TESTING_OPTIONS
9926
9927 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
9928 unsigned int freq, const u8 *dst,
9929 const u8 *src, const u8 *bssid,
9930 const u8 *data, size_t data_len,
9931 enum offchannel_send_action_result
9932 result)
9933 {
9934 wpa_msg_only_for_cb(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
9935 " src=" MACSTR " bssid=" MACSTR " result=%s",
9936 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
9937 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
9938 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
9939 "NO_ACK" : "FAILED"));
9940 wpa_printf(MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR_SEC
9941 " src=" MACSTR_SEC " bssid=" MACSTR_SEC " result=%s",
9942 freq, MAC2STR_SEC(dst), MAC2STR_SEC(src), MAC2STR_SEC(bssid),
9943 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
9944 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
9945 "NO_ACK" : "FAILED"));
9946 }
9947
9948
9949 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
9950 {
9951 char *pos, *param;
9952 size_t len;
9953 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
9954 int res, used;
9955 int freq = 0, no_cck = 0, wait_time = 0;
9956
9957 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
9958 * <action=Action frame payload> */
9959
9960 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
9961
9962 pos = cmd;
9963 used = hwaddr_aton2(pos, da);
9964 if (used < 0)
9965 return -1;
9966 pos += used;
9967 while (*pos == ' ')
9968 pos++;
9969 used = hwaddr_aton2(pos, bssid);
9970 if (used < 0)
9971 return -1;
9972 pos += used;
9973
9974 param = os_strstr(pos, " freq=");
9975 if (param) {
9976 param += 6;
9977 freq = atoi(param);
9978 }
9979
9980 param = os_strstr(pos, " no_cck=");
9981 if (param) {
9982 param += 8;
9983 no_cck = atoi(param);
9984 }
9985
9986 param = os_strstr(pos, " wait_time=");
9987 if (param) {
9988 param += 11;
9989 wait_time = atoi(param);
9990 }
9991
9992 param = os_strstr(pos, " action=");
9993 if (param == NULL)
9994 return -1;
9995 param += 8;
9996
9997 len = os_strlen(param);
9998 if (len & 1)
9999 return -1;
10000 len /= 2;
10001
10002 buf = os_malloc(len);
10003 if (buf == NULL)
10004 return -1;
10005
10006 if (hexstr2bin(param, buf, len) < 0) {
10007 os_free(buf);
10008 return -1;
10009 }
10010
10011 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
10012 buf, len, wait_time,
10013 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
10014 os_free(buf);
10015 return res;
10016 }
10017
10018
10019 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
10020 {
10021 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
10022 offchannel_send_action_done(wpa_s);
10023 }
10024
10025
10026 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
10027 char *cmd)
10028 {
10029 char *pos, *param;
10030 size_t len;
10031 u8 *buf;
10032 int freq = 0, datarate = 0, ssi_signal = 0;
10033 union wpa_event_data event;
10034
10035 if (!wpa_s->ext_mgmt_frame_handling)
10036 return -1;
10037
10038 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
10039
10040 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
10041
10042 pos = cmd;
10043 param = os_strstr(pos, "freq=");
10044 if (param) {
10045 param += 5;
10046 freq = atoi(param);
10047 }
10048
10049 param = os_strstr(pos, " datarate=");
10050 if (param) {
10051 param += 10;
10052 datarate = atoi(param);
10053 }
10054
10055 param = os_strstr(pos, " ssi_signal=");
10056 if (param) {
10057 param += 12;
10058 ssi_signal = atoi(param);
10059 }
10060
10061 param = os_strstr(pos, " frame=");
10062 if (param == NULL)
10063 return -1;
10064 param += 7;
10065
10066 len = os_strlen(param);
10067 if (len & 1)
10068 return -1;
10069 len /= 2;
10070
10071 buf = os_malloc(len);
10072 if (buf == NULL)
10073 return -1;
10074
10075 if (hexstr2bin(param, buf, len) < 0) {
10076 os_free(buf);
10077 return -1;
10078 }
10079
10080 os_memset(&event, 0, sizeof(event));
10081 event.rx_mgmt.freq = freq;
10082 event.rx_mgmt.frame = buf;
10083 event.rx_mgmt.frame_len = len;
10084 event.rx_mgmt.ssi_signal = ssi_signal;
10085 event.rx_mgmt.datarate = datarate;
10086 wpa_s->ext_mgmt_frame_handling = 0;
10087 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
10088 wpa_s->ext_mgmt_frame_handling = 1;
10089
10090 os_free(buf);
10091
10092 return 0;
10093 }
10094
10095
10096 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
10097 char *param)
10098 {
10099 struct wpa_scan_res *res;
10100 struct os_reltime now;
10101 char *pos, *end;
10102 int ret = -1;
10103
10104 if (!param)
10105 return -1;
10106
10107 if (os_strcmp(param, "START") == 0) {
10108 wpa_bss_update_start(wpa_s);
10109 return 0;
10110 }
10111
10112 if (os_strcmp(param, "END") == 0) {
10113 wpa_bss_update_end(wpa_s, NULL, 1);
10114 return 0;
10115 }
10116
10117 if (os_strncmp(param, "BSS ", 4) != 0)
10118 return -1;
10119 param += 3;
10120
10121 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
10122 if (!res)
10123 return -1;
10124
10125 pos = os_strstr(param, " flags=");
10126 if (pos)
10127 res->flags = strtol(pos + 7, NULL, 16);
10128
10129 pos = os_strstr(param, " bssid=");
10130 if (pos && hwaddr_aton(pos + 7, res->bssid))
10131 goto fail;
10132
10133 pos = os_strstr(param, " freq=");
10134 if (pos)
10135 res->freq = atoi(pos + 6);
10136
10137 pos = os_strstr(param, " beacon_int=");
10138 if (pos)
10139 res->beacon_int = atoi(pos + 12);
10140
10141 pos = os_strstr(param, " caps=");
10142 if (pos)
10143 res->caps = strtol(pos + 6, NULL, 16);
10144
10145 pos = os_strstr(param, " qual=");
10146 if (pos)
10147 res->qual = atoi(pos + 6);
10148
10149 pos = os_strstr(param, " noise=");
10150 if (pos)
10151 res->noise = atoi(pos + 7);
10152
10153 pos = os_strstr(param, " level=");
10154 if (pos)
10155 res->level = atoi(pos + 7);
10156
10157 pos = os_strstr(param, " tsf=");
10158 if (pos)
10159 res->tsf = strtoll(pos + 5, NULL, 16);
10160
10161 pos = os_strstr(param, " age=");
10162 if (pos)
10163 res->age = atoi(pos + 5);
10164
10165 pos = os_strstr(param, " est_throughput=");
10166 if (pos)
10167 res->est_throughput = atoi(pos + 16);
10168
10169 pos = os_strstr(param, " snr=");
10170 if (pos)
10171 res->snr = atoi(pos + 5);
10172
10173 pos = os_strstr(param, " parent_tsf=");
10174 if (pos)
10175 res->parent_tsf = strtoll(pos + 7, NULL, 16);
10176
10177 pos = os_strstr(param, " tsf_bssid=");
10178 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
10179 goto fail;
10180
10181 pos = os_strstr(param, " ie=");
10182 if (pos) {
10183 pos += 4;
10184 end = os_strchr(pos, ' ');
10185 if (!end)
10186 end = pos + os_strlen(pos);
10187 res->ie_len = (end - pos) / 2;
10188 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
10189 goto fail;
10190 }
10191
10192 pos = os_strstr(param, " beacon_ie=");
10193 if (pos) {
10194 pos += 11;
10195 end = os_strchr(pos, ' ');
10196 if (!end)
10197 end = pos + os_strlen(pos);
10198 res->beacon_ie_len = (end - pos) / 2;
10199 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
10200 res->beacon_ie_len))
10201 goto fail;
10202 }
10203
10204 os_get_reltime(&now);
10205 wpa_bss_update_scan_res(wpa_s, res, &now);
10206 ret = 0;
10207 fail:
10208 os_free(res);
10209
10210 return ret;
10211 }
10212
10213
10214 static int wpas_ctrl_iface_driver_event_assoc(struct wpa_supplicant *wpa_s,
10215 char *param)
10216 {
10217 union wpa_event_data event;
10218 struct assoc_info *ai;
10219 char *ctx = NULL;
10220 int ret = -1;
10221 struct wpabuf *req_ies = NULL;
10222 struct wpabuf *resp_ies = NULL;
10223 struct wpabuf *resp_frame = NULL;
10224 struct wpabuf *beacon_ies = NULL;
10225 struct wpabuf *key_replay_ctr = NULL;
10226 struct wpabuf *ptk_kck = NULL;
10227 struct wpabuf *ptk_kek = NULL;
10228 struct wpabuf *fils_pmk = NULL;
10229 char *str, *pos;
10230 u8 addr[ETH_ALEN];
10231 u8 fils_pmkid[PMKID_LEN];
10232
10233 os_memset(&event, 0, sizeof(event));
10234 ai = &event.assoc_info;
10235
10236 while ((str = str_token(param, " ", &ctx))) {
10237 pos = os_strchr(str, '=');
10238 if (!pos)
10239 goto fail;
10240 *pos++ = '\0';
10241
10242 if (os_strcmp(str, "reassoc") == 0) {
10243 ai->reassoc = atoi(pos);
10244 } else if (os_strcmp(str, "req_ies") == 0) {
10245 wpabuf_free(req_ies);
10246 req_ies = wpabuf_parse_bin(pos);
10247 if (!req_ies)
10248 goto fail;
10249 ai->req_ies = wpabuf_head(req_ies);
10250 ai->req_ies_len = wpabuf_len(req_ies);
10251 } else if (os_strcmp(str, "resp_ies") == 0) {
10252 wpabuf_free(resp_ies);
10253 resp_ies = wpabuf_parse_bin(pos);
10254 if (!resp_ies)
10255 goto fail;
10256 ai->resp_ies = wpabuf_head(resp_ies);
10257 ai->resp_ies_len = wpabuf_len(resp_ies);
10258 } else if (os_strcmp(str, "resp_frame") == 0) {
10259 wpabuf_free(resp_frame);
10260 resp_frame = wpabuf_parse_bin(pos);
10261 if (!resp_frame)
10262 goto fail;
10263 ai->resp_frame = wpabuf_head(resp_frame);
10264 ai->resp_frame_len = wpabuf_len(resp_frame);
10265 } else if (os_strcmp(str, "beacon_ies") == 0) {
10266 wpabuf_free(beacon_ies);
10267 beacon_ies = wpabuf_parse_bin(pos);
10268 if (!beacon_ies)
10269 goto fail;
10270 ai->beacon_ies = wpabuf_head(beacon_ies);
10271 ai->beacon_ies_len = wpabuf_len(beacon_ies);
10272 } else if (os_strcmp(str, "freq") == 0) {
10273 ai->freq = atoi(pos);
10274 } else if (os_strcmp(str, "wmm::info_bitmap") == 0) {
10275 ai->wmm_params.info_bitmap = atoi(pos);
10276 } else if (os_strcmp(str, "wmm::uapsd_queues") == 0) {
10277 ai->wmm_params.uapsd_queues = atoi(pos);
10278 } else if (os_strcmp(str, "addr") == 0) {
10279 if (hwaddr_aton(pos, addr))
10280 goto fail;
10281 ai->addr = addr;
10282 } else if (os_strcmp(str, "authorized") == 0) {
10283 ai->authorized = atoi(pos);
10284 } else if (os_strcmp(str, "key_replay_ctr") == 0) {
10285 wpabuf_free(key_replay_ctr);
10286 key_replay_ctr = wpabuf_parse_bin(pos);
10287 if (!key_replay_ctr)
10288 goto fail;
10289 ai->key_replay_ctr = wpabuf_head(key_replay_ctr);
10290 ai->key_replay_ctr_len = wpabuf_len(key_replay_ctr);
10291 } else if (os_strcmp(str, "ptk_kck") == 0) {
10292 wpabuf_free(ptk_kck);
10293 ptk_kck = wpabuf_parse_bin(pos);
10294 if (!ptk_kck)
10295 goto fail;
10296 ai->ptk_kck = wpabuf_head(ptk_kck);
10297 ai->ptk_kck_len = wpabuf_len(ptk_kck);
10298 } else if (os_strcmp(str, "ptk_kek") == 0) {
10299 wpabuf_free(ptk_kek);
10300 ptk_kek = wpabuf_parse_bin(pos);
10301 if (!ptk_kek)
10302 goto fail;
10303 ai->ptk_kek = wpabuf_head(ptk_kek);
10304 ai->ptk_kek_len = wpabuf_len(ptk_kek);
10305 } else if (os_strcmp(str, "subnet_status") == 0) {
10306 ai->subnet_status = atoi(pos);
10307 } else if (os_strcmp(str, "fils_erp_next_seq_num") == 0) {
10308 ai->fils_erp_next_seq_num = atoi(pos);
10309 } else if (os_strcmp(str, "fils_pmk") == 0) {
10310 wpabuf_free(fils_pmk);
10311 fils_pmk = wpabuf_parse_bin(pos);
10312 if (!fils_pmk)
10313 goto fail;
10314 ai->fils_pmk = wpabuf_head(fils_pmk);
10315 ai->fils_pmk_len = wpabuf_len(fils_pmk);
10316 } else if (os_strcmp(str, "fils_pmkid") == 0) {
10317 if (hexstr2bin(pos, fils_pmkid, PMKID_LEN) < 0)
10318 goto fail;
10319 ai->fils_pmkid = fils_pmkid;
10320 } else {
10321 goto fail;
10322 }
10323 }
10324
10325 wpa_supplicant_event(wpa_s, EVENT_ASSOC, &event);
10326 ret = 0;
10327 fail:
10328 wpabuf_free(req_ies);
10329 wpabuf_free(resp_ies);
10330 wpabuf_free(resp_frame);
10331 wpabuf_free(beacon_ies);
10332 wpabuf_free(key_replay_ctr);
10333 wpabuf_free(ptk_kck);
10334 wpabuf_free(ptk_kek);
10335 wpabuf_free(fils_pmk);
10336 return ret;
10337 }
10338
10339
10340 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
10341 {
10342 char *pos, *param;
10343 union wpa_event_data event;
10344 enum wpa_event_type ev;
10345
10346 /* <event name> [parameters..] */
10347
10348 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
10349
10350 pos = cmd;
10351 param = os_strchr(pos, ' ');
10352 if (param)
10353 *param++ = '\0';
10354
10355 os_memset(&event, 0, sizeof(event));
10356
10357 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
10358 ev = EVENT_INTERFACE_ENABLED;
10359 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
10360 ev = EVENT_INTERFACE_DISABLED;
10361 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
10362 ev = EVENT_AVOID_FREQUENCIES;
10363 if (param == NULL)
10364 param = "";
10365 if (freq_range_list_parse(&event.freq_range, param) < 0)
10366 return -1;
10367 wpa_supplicant_event(wpa_s, ev, &event);
10368 os_free(event.freq_range.range);
10369 return 0;
10370 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
10371 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
10372 } else if (os_strcmp(cmd, "ASSOC") == 0) {
10373 return wpas_ctrl_iface_driver_event_assoc(wpa_s, param);
10374 } else {
10375 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
10376 cmd);
10377 return -1;
10378 }
10379
10380 wpa_supplicant_event(wpa_s, ev, &event);
10381
10382 return 0;
10383 }
10384
10385
10386 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
10387 {
10388 char *pos;
10389 u8 src[ETH_ALEN], *buf;
10390 int used;
10391 size_t len;
10392
10393 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
10394
10395 pos = cmd;
10396 used = hwaddr_aton2(pos, src);
10397 if (used < 0)
10398 return -1;
10399 pos += used;
10400 while (*pos == ' ')
10401 pos++;
10402
10403 len = os_strlen(pos);
10404 if (len & 1)
10405 return -1;
10406 len /= 2;
10407
10408 buf = os_malloc(len);
10409 if (buf == NULL)
10410 return -1;
10411
10412 if (hexstr2bin(pos, buf, len) < 0) {
10413 os_free(buf);
10414 return -1;
10415 }
10416
10417 wpa_supplicant_rx_eapol(wpa_s, src, buf, len, FRAME_ENCRYPTION_UNKNOWN);
10418 os_free(buf);
10419
10420 return 0;
10421 }
10422
10423
10424 static int wpas_ctrl_iface_eapol_tx(struct wpa_supplicant *wpa_s, char *cmd)
10425 {
10426 char *pos;
10427 u8 dst[ETH_ALEN], *buf;
10428 int used, ret;
10429 size_t len;
10430 unsigned int prev;
10431
10432 wpa_printf(MSG_DEBUG, "External EAPOL TX: %s", cmd);
10433
10434 pos = cmd;
10435 used = hwaddr_aton2(pos, dst);
10436 if (used < 0)
10437 return -1;
10438 pos += used;
10439 while (*pos == ' ')
10440 pos++;
10441
10442 len = os_strlen(pos);
10443 if (len & 1)
10444 return -1;
10445 len /= 2;
10446
10447 buf = os_malloc(len);
10448 if (!buf || hexstr2bin(pos, buf, len) < 0) {
10449 os_free(buf);
10450 return -1;
10451 }
10452
10453 prev = wpa_s->ext_eapol_frame_io;
10454 wpa_s->ext_eapol_frame_io = 0;
10455 ret = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, buf, len);
10456 wpa_s->ext_eapol_frame_io = prev;
10457 os_free(buf);
10458
10459 return ret;
10460 }
10461
10462
10463 static u16 ipv4_hdr_checksum(const void *buf, size_t len)
10464 {
10465 size_t i;
10466 u32 sum = 0;
10467 const u16 *pos = buf;
10468
10469 for (i = 0; i < len / 2; i++)
10470 sum += *pos++;
10471
10472 while (sum >> 16)
10473 sum = (sum & 0xffff) + (sum >> 16);
10474
10475 return sum ^ 0xffff;
10476 }
10477
10478
10479 #define HWSIM_PACKETLEN 1500
10480 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
10481
10482 static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
10483 size_t len)
10484 {
10485 struct wpa_supplicant *wpa_s = ctx;
10486 const struct ether_header *eth;
10487 struct ip ip;
10488 const u8 *pos;
10489 unsigned int i;
10490 char extra[30];
10491
10492 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
10493 wpa_printf(MSG_DEBUG,
10494 "test data: RX - ignore unexpected length %d",
10495 (int) len);
10496 return;
10497 }
10498
10499 eth = (const struct ether_header *) buf;
10500 os_memcpy(&ip, eth + 1, sizeof(ip));
10501 pos = &buf[sizeof(*eth) + sizeof(ip)];
10502
10503 if (ip.ip_hl != 5 || ip.ip_v != 4 || ntohs(ip.ip_len) > HWSIM_IP_LEN) {
10504 wpa_printf(MSG_DEBUG,
10505 "test data: RX - ignore unexpected IP header");
10506 return;
10507 }
10508
10509 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
10510 if (*pos != (u8) i) {
10511 wpa_printf(MSG_DEBUG,
10512 "test data: RX - ignore mismatching payload");
10513 return;
10514 }
10515 pos++;
10516 }
10517 extra[0] = '\0';
10518 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
10519 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
10520 wpa_msg_only_for_cb(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
10521 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
10522 wpa_printf(MSG_INFO, "DATA-TEST-RX " MACSTR_SEC " " MACSTR_SEC "%s",
10523 MAC2STR_SEC(eth->ether_dhost), MAC2STR_SEC(eth->ether_shost), extra);
10524 }
10525
10526
10527 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
10528 char *cmd)
10529 {
10530 int enabled = atoi(cmd);
10531 char *pos;
10532 const char *ifname;
10533
10534 if (!enabled) {
10535 if (wpa_s->l2_test) {
10536 l2_packet_deinit(wpa_s->l2_test);
10537 wpa_s->l2_test = NULL;
10538 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
10539 }
10540 return 0;
10541 }
10542
10543 if (wpa_s->l2_test)
10544 return 0;
10545
10546 pos = os_strstr(cmd, " ifname=");
10547 if (pos)
10548 ifname = pos + 8;
10549 else
10550 ifname = wpa_s->ifname;
10551
10552 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
10553 ETHERTYPE_IP, wpas_data_test_rx,
10554 wpa_s, 1);
10555 if (wpa_s->l2_test == NULL)
10556 return -1;
10557
10558 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
10559
10560 return 0;
10561 }
10562
10563
10564 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
10565 {
10566 u8 dst[ETH_ALEN], src[ETH_ALEN];
10567 char *pos, *pos2;
10568 int used;
10569 long int val;
10570 u8 tos;
10571 u8 buf[2 + HWSIM_PACKETLEN];
10572 struct ether_header *eth;
10573 struct ip *ip;
10574 u8 *dpos;
10575 unsigned int i;
10576 size_t send_len = HWSIM_IP_LEN;
10577
10578 if (wpa_s->l2_test == NULL)
10579 return -1;
10580
10581 /* format: <dst> <src> <tos> [len=<length>] */
10582
10583 pos = cmd;
10584 used = hwaddr_aton2(pos, dst);
10585 if (used < 0)
10586 return -1;
10587 pos += used;
10588 while (*pos == ' ')
10589 pos++;
10590 used = hwaddr_aton2(pos, src);
10591 if (used < 0)
10592 return -1;
10593 pos += used;
10594
10595 val = strtol(pos, &pos2, 0);
10596 if (val < 0 || val > 0xff)
10597 return -1;
10598 tos = val;
10599
10600 pos = os_strstr(pos2, " len=");
10601 if (pos) {
10602 i = atoi(pos + 5);
10603 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
10604 return -1;
10605 send_len = i;
10606 }
10607
10608 eth = (struct ether_header *) &buf[2];
10609 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
10610 os_memcpy(eth->ether_shost, src, ETH_ALEN);
10611 eth->ether_type = htons(ETHERTYPE_IP);
10612 ip = (struct ip *) (eth + 1);
10613 os_memset(ip, 0, sizeof(*ip));
10614 ip->ip_hl = 5;
10615 ip->ip_v = 4;
10616 ip->ip_ttl = 64;
10617 ip->ip_tos = tos;
10618 ip->ip_len = htons(send_len);
10619 ip->ip_p = 1;
10620 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
10621 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
10622 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
10623 dpos = (u8 *) (ip + 1);
10624 for (i = 0; i < send_len - sizeof(*ip); i++)
10625 *dpos++ = i;
10626
10627 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
10628 sizeof(struct ether_header) + send_len) < 0)
10629 return -1;
10630
10631 wpa_msg_only_for_cb(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
10632 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
10633 wpa_printf(MSG_DEBUG, "test data: TX dst=" MACSTR_SEC " src=" MACSTR_SEC
10634 " tos=0x%x", MAC2STR_SEC(dst), MAC2STR_SEC(src), tos);
10635
10636 return 0;
10637 }
10638
10639
10640 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
10641 char *cmd)
10642 {
10643 u8 *buf;
10644 struct ether_header *eth;
10645 struct l2_packet_data *l2 = NULL;
10646 size_t len;
10647 u16 ethertype;
10648 int res = -1;
10649
10650 len = os_strlen(cmd);
10651 if (len & 1 || len < ETH_HLEN * 2)
10652 return -1;
10653 len /= 2;
10654
10655 buf = os_malloc(len);
10656 if (buf == NULL)
10657 return -1;
10658
10659 if (hexstr2bin(cmd, buf, len) < 0)
10660 goto done;
10661
10662 eth = (struct ether_header *) buf;
10663 ethertype = ntohs(eth->ether_type);
10664
10665 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
10666 wpas_data_test_rx, wpa_s, 1);
10667 if (l2 == NULL)
10668 goto done;
10669
10670 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
10671 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
10672 done:
10673 if (l2)
10674 l2_packet_deinit(l2);
10675 os_free(buf);
10676
10677 return res < 0 ? -1 : 0;
10678 }
10679
10680
10681 static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
10682 {
10683 struct wpa_supplicant *wpa_s = eloop_ctx;
10684 int i, count = (intptr_t) timeout_ctx;
10685
10686 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
10687 count);
10688 for (i = 0; i < count; i++) {
10689 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
10690 i + 1, count);
10691 }
10692 }
10693
10694
10695 static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
10696 {
10697 int count;
10698
10699 count = atoi(cmd);
10700 if (count <= 0)
10701 return -1;
10702
10703 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
10704 (void *) (intptr_t) count);
10705 }
10706
10707
10708 static int wpas_get_hex_buf(const char *val, struct wpabuf **ret)
10709 {
10710 struct wpabuf *buf;
10711 size_t len;
10712
10713 len = os_strlen(val);
10714 if (len & 1)
10715 return -1;
10716 len /= 2;
10717
10718 if (len == 0) {
10719 buf = NULL;
10720 } else {
10721 buf = wpabuf_alloc(len);
10722 if (!buf)
10723 return -1;
10724
10725 if (hexstr2bin(val, wpabuf_put(buf, len), len) < 0) {
10726 wpabuf_free(buf);
10727 return -1;
10728 }
10729 }
10730
10731 *ret = buf;
10732 return 0;
10733 }
10734
10735
10736 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
10737 const char *cmd)
10738 {
10739 struct wpabuf *buf;
10740
10741 if (wpas_get_hex_buf(cmd, &buf) < 0)
10742 return -1;
10743 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
10744 return 0;
10745 }
10746
10747
10748 static int wpas_ctrl_test_eapol_m2_elems(struct wpa_supplicant *wpa_s,
10749 const char *cmd)
10750 {
10751 struct wpabuf *buf;
10752
10753 if (wpas_get_hex_buf(cmd, &buf) < 0)
10754 return -1;
10755 wpa_sm_set_test_eapol_m2_elems(wpa_s->wpa, buf);
10756 return 0;
10757 }
10758
10759
10760 static int wpas_ctrl_test_eapol_m4_elems(struct wpa_supplicant *wpa_s,
10761 const char *cmd)
10762 {
10763 struct wpabuf *buf;
10764
10765 if (wpas_get_hex_buf(cmd, &buf) < 0)
10766 return -1;
10767 wpa_sm_set_test_eapol_m4_elems(wpa_s->wpa, buf);
10768 return 0;
10769 }
10770
10771
10772 static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
10773 {
10774 u8 zero[WPA_TK_MAX_LEN];
10775
10776 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
10777 return -1;
10778
10779 wpa_printf(MSG_INFO, "TESTING: Reset PN");
10780 os_memset(zero, 0, sizeof(zero));
10781
10782 /* First, use a zero key to avoid any possible duplicate key avoidance
10783 * in the driver. */
10784 if (wpa_drv_set_key(wpa_s, -1, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
10785 wpa_s->last_tk_key_idx, 1, zero, 6,
10786 zero, wpa_s->last_tk_len,
10787 KEY_FLAG_PAIRWISE_RX_TX) < 0)
10788 return -1;
10789
10790 /* Set the previously configured key to reset its TSC/RSC */
10791 return wpa_drv_set_key(wpa_s, -1, wpa_s->last_tk_alg,
10792 wpa_s->last_tk_addr,
10793 wpa_s->last_tk_key_idx, 1, zero, 6,
10794 wpa_s->last_tk, wpa_s->last_tk_len,
10795 KEY_FLAG_PAIRWISE_RX_TX);
10796 }
10797
10798
10799 static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
10800 {
10801 const char *pos = cmd;
10802 int error, pairwise;
10803
10804 error = atoi(pos);
10805 pos = os_strchr(pos, ' ');
10806 if (!pos)
10807 return -1;
10808 pairwise = atoi(pos);
10809 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
10810 return 0;
10811 }
10812
10813
10814 static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
10815 {
10816 #ifdef CONFIG_SME
10817 struct wpa_driver_associate_params params;
10818 int ret;
10819
10820 os_memset(¶ms, 0, sizeof(params));
10821 params.bssid = wpa_s->bssid;
10822 params.ssid = wpa_s->sme.ssid;
10823 params.ssid_len = wpa_s->sme.ssid_len;
10824 params.freq.freq = wpa_s->sme.freq;
10825 if (wpa_s->last_assoc_req_wpa_ie) {
10826 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
10827 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
10828 }
10829 params.pairwise_suite = wpa_s->pairwise_cipher;
10830 params.group_suite = wpa_s->group_cipher;
10831 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
10832 params.key_mgmt_suite = wpa_s->key_mgmt;
10833 params.wpa_proto = wpa_s->wpa_proto;
10834 params.mgmt_frame_protection = wpa_s->sme.mfp;
10835 params.rrm_used = wpa_s->rrm.rrm_used;
10836 if (wpa_s->sme.prev_bssid_set)
10837 params.prev_bssid = wpa_s->sme.prev_bssid;
10838 wpa_printf(MSG_INFO, "TESTING: Resend association request");
10839 ret = wpa_drv_associate(wpa_s, ¶ms);
10840 wpa_s->testing_resend_assoc = 1;
10841 return ret;
10842 #else /* CONFIG_SME */
10843 return -1;
10844 #endif /* CONFIG_SME */
10845 }
10846
10847
10848 static int wpas_ctrl_iface_send_twt_setup(struct wpa_supplicant *wpa_s,
10849 const char *cmd)
10850 {
10851 u8 dtok = 1;
10852 int exponent = 10;
10853 int mantissa = 8192;
10854 u8 min_twt = 255;
10855 unsigned long long twt = 0;
10856 bool requestor = true;
10857 int setup_cmd = 0;
10858 bool trigger = true;
10859 bool implicit = true;
10860 bool flow_type = true;
10861 int flow_id = 0;
10862 bool protection = false;
10863 u8 twt_channel = 0;
10864 u8 control = BIT(4); /* Control field (IEEE Std 802.11ax-2021,
10865 * Figure 9-687 - Control field format):
10866 * B4 = TWT Information Frame Disabled */
10867 const char *tok_s;
10868
10869 tok_s = os_strstr(cmd, " dialog=");
10870 if (tok_s)
10871 dtok = atoi(tok_s + os_strlen(" dialog="));
10872
10873 tok_s = os_strstr(cmd, " exponent=");
10874 if (tok_s)
10875 exponent = atoi(tok_s + os_strlen(" exponent="));
10876
10877 tok_s = os_strstr(cmd, " mantissa=");
10878 if (tok_s)
10879 mantissa = atoi(tok_s + os_strlen(" mantissa="));
10880
10881 tok_s = os_strstr(cmd, " min_twt=");
10882 if (tok_s)
10883 min_twt = atoi(tok_s + os_strlen(" min_twt="));
10884
10885 tok_s = os_strstr(cmd, " setup_cmd=");
10886 if (tok_s)
10887 setup_cmd = atoi(tok_s + os_strlen(" setup_cmd="));
10888
10889 tok_s = os_strstr(cmd, " twt=");
10890 if (tok_s &&
10891 sscanf(tok_s + os_strlen(" twt="), "%llu", &twt) != 1)
10892 return -1;
10893
10894 tok_s = os_strstr(cmd, " requestor=");
10895 if (tok_s)
10896 requestor = atoi(tok_s + os_strlen(" requestor="));
10897
10898 tok_s = os_strstr(cmd, " trigger=");
10899 if (tok_s)
10900 trigger = atoi(tok_s + os_strlen(" trigger="));
10901
10902 tok_s = os_strstr(cmd, " implicit=");
10903 if (tok_s)
10904 implicit = atoi(tok_s + os_strlen(" implicit="));
10905
10906 tok_s = os_strstr(cmd, " flow_type=");
10907 if (tok_s)
10908 flow_type = atoi(tok_s + os_strlen(" flow_type="));
10909
10910 tok_s = os_strstr(cmd, " flow_id=");
10911 if (tok_s)
10912 flow_id = atoi(tok_s + os_strlen(" flow_id="));
10913
10914 tok_s = os_strstr(cmd, " protection=");
10915 if (tok_s)
10916 protection = atoi(tok_s + os_strlen(" protection="));
10917
10918 tok_s = os_strstr(cmd, " twt_channel=");
10919 if (tok_s)
10920 twt_channel = atoi(tok_s + os_strlen(" twt_channel="));
10921
10922 tok_s = os_strstr(cmd, " control=");
10923 if (tok_s)
10924 control = atoi(tok_s + os_strlen(" control="));
10925
10926 return wpas_twt_send_setup(wpa_s, dtok, exponent, mantissa, min_twt,
10927 setup_cmd, twt, requestor, trigger, implicit,
10928 flow_type, flow_id, protection, twt_channel,
10929 control);
10930 }
10931
10932
10933 static int wpas_ctrl_iface_send_twt_teardown(struct wpa_supplicant *wpa_s,
10934 const char *cmd)
10935 {
10936 u8 flags = 0x1;
10937 const char *tok_s;
10938
10939 tok_s = os_strstr(cmd, " flags=");
10940 if (tok_s)
10941 flags = atoi(tok_s + os_strlen(" flags="));
10942
10943 return wpas_twt_send_teardown(wpa_s, flags);
10944 }
10945
10946 #endif /* CONFIG_TESTING_OPTIONS */
10947
10948
10949 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
10950 {
10951 char *pos = cmd;
10952 int frame;
10953 size_t len;
10954 struct wpabuf *buf;
10955 struct ieee802_11_elems elems;
10956
10957 frame = atoi(pos);
10958 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10959 return -1;
10960 wpa_s = wpas_vendor_elem(wpa_s, frame);
10961
10962 pos = os_strchr(pos, ' ');
10963 if (pos == NULL)
10964 return -1;
10965 pos++;
10966
10967 len = os_strlen(pos);
10968 if (len == 0)
10969 return 0;
10970 if (len & 1)
10971 return -1;
10972 len /= 2;
10973
10974 buf = wpabuf_alloc(len);
10975 if (buf == NULL)
10976 return -1;
10977
10978 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
10979 wpabuf_free(buf);
10980 return -1;
10981 }
10982
10983 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
10984 ParseFailed) {
10985 wpabuf_free(buf);
10986 return -1;
10987 }
10988
10989 if (wpa_s->vendor_elem[frame] == NULL) {
10990 wpa_s->vendor_elem[frame] = buf;
10991 goto update_ies;
10992 }
10993
10994 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
10995 wpabuf_free(buf);
10996 return -1;
10997 }
10998
10999 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
11000 wpabuf_free(buf);
11001
11002 update_ies:
11003 wpas_vendor_elem_update(wpa_s);
11004
11005 if (frame == VENDOR_ELEM_PROBE_REQ ||
11006 frame == VENDOR_ELEM_PROBE_REQ_P2P)
11007 wpa_supplicant_set_default_scan_ies(wpa_s);
11008
11009 return 0;
11010 }
11011
11012
11013 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
11014 char *buf, size_t buflen)
11015 {
11016 int frame = atoi(cmd);
11017
11018 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
11019 return -1;
11020 wpa_s = wpas_vendor_elem(wpa_s, frame);
11021
11022 if (wpa_s->vendor_elem[frame] == NULL)
11023 return 0;
11024
11025 return wpa_snprintf_hex(buf, buflen,
11026 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
11027 wpabuf_len(wpa_s->vendor_elem[frame]));
11028 }
11029
11030
11031 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
11032 {
11033 char *pos = cmd;
11034 int frame;
11035 size_t len;
11036 u8 *buf;
11037 struct ieee802_11_elems elems;
11038 int res;
11039
11040 frame = atoi(pos);
11041 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
11042 return -1;
11043 wpa_s = wpas_vendor_elem(wpa_s, frame);
11044
11045 pos = os_strchr(pos, ' ');
11046 if (pos == NULL)
11047 return -1;
11048 pos++;
11049
11050 if (*pos == '*') {
11051 wpabuf_free(wpa_s->vendor_elem[frame]);
11052 wpa_s->vendor_elem[frame] = NULL;
11053 wpas_vendor_elem_update(wpa_s);
11054 return 0;
11055 }
11056
11057 if (wpa_s->vendor_elem[frame] == NULL)
11058 return -1;
11059
11060 len = os_strlen(pos);
11061 if (len == 0)
11062 return 0;
11063 if (len & 1)
11064 return -1;
11065 len /= 2;
11066
11067 buf = os_malloc(len);
11068 if (buf == NULL)
11069 return -1;
11070
11071 if (hexstr2bin(pos, buf, len) < 0) {
11072 os_free(buf);
11073 return -1;
11074 }
11075
11076 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
11077 os_free(buf);
11078 return -1;
11079 }
11080
11081 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
11082 os_free(buf);
11083 return res;
11084 }
11085
11086
11087 #ifndef CONFIG_NO_RRM
11088
11089 static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
11090 {
11091 struct wpa_supplicant *wpa_s = ctx;
11092 size_t len;
11093 const u8 *data;
11094
11095 /*
11096 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
11097 * BSSID[6]
11098 * BSSID Information[4]
11099 * Operating Class[1]
11100 * Channel Number[1]
11101 * PHY Type[1]
11102 * Optional Subelements[variable]
11103 */
11104 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
11105
11106 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
11107 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
11108 goto out;
11109 }
11110
11111 data = wpabuf_head_u8(neighbor_rep);
11112 len = wpabuf_len(neighbor_rep);
11113
11114 while (len >= 2 + NR_IE_MIN_LEN) {
11115 const u8 *nr;
11116 char lci[256 * 2 + 1];
11117 char civic[256 * 2 + 1];
11118 u8 nr_len = data[1];
11119 const u8 *pos = data, *end;
11120
11121 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
11122 nr_len < NR_IE_MIN_LEN) {
11123 wpa_dbg(wpa_s, MSG_DEBUG,
11124 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
11125 data[0], nr_len);
11126 goto out;
11127 }
11128
11129 if (2U + nr_len > len) {
11130 wpa_dbg(wpa_s, MSG_DEBUG,
11131 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
11132 data[0], len, nr_len);
11133 goto out;
11134 }
11135 pos += 2;
11136 end = pos + nr_len;
11137
11138 nr = pos;
11139 pos += NR_IE_MIN_LEN;
11140
11141 lci[0] = '\0';
11142 civic[0] = '\0';
11143 while (end - pos > 2) {
11144 u8 s_id, s_len;
11145
11146 s_id = *pos++;
11147 s_len = *pos++;
11148 if (s_len > end - pos)
11149 goto out;
11150 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
11151 /* Measurement Token[1] */
11152 /* Measurement Report Mode[1] */
11153 /* Measurement Type[1] */
11154 /* Measurement Report[variable] */
11155 switch (pos[2]) {
11156 case MEASURE_TYPE_LCI:
11157 if (lci[0])
11158 break;
11159 wpa_snprintf_hex(lci, sizeof(lci),
11160 pos, s_len);
11161 break;
11162 case MEASURE_TYPE_LOCATION_CIVIC:
11163 if (civic[0])
11164 break;
11165 wpa_snprintf_hex(civic, sizeof(civic),
11166 pos, s_len);
11167 break;
11168 }
11169 }
11170
11171 pos += s_len;
11172 }
11173
11174 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
11175 "bssid=" MACSTR
11176 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
11177 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
11178 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
11179 nr[ETH_ALEN + 6],
11180 lci[0] ? " lci=" : "", lci,
11181 civic[0] ? " civic=" : "", civic);
11182
11183 data = end;
11184 len -= 2 + nr_len;
11185 }
11186
11187 out:
11188 wpabuf_free(neighbor_rep);
11189 }
11190
11191
11192 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
11193 char *cmd)
11194 {
11195 struct wpa_ssid_value ssid, *ssid_p = NULL;
11196 int ret, lci = 0, civic = 0;
11197 char *ssid_s;
11198
11199 ssid_s = os_strstr(cmd, "ssid=");
11200 if (ssid_s) {
11201 if (ssid_parse(ssid_s + 5, &ssid)) {
11202 wpa_msg_only_for_cb(wpa_s, MSG_INFO,
11203 "CTRL: Send Neighbor Report: bad SSID");
11204 wpa_printf(MSG_INFO, "CTRL: Send Neighbor Report: bad SSID");
11205 return -1;
11206 }
11207
11208 ssid_p = &ssid;
11209
11210 /*
11211 * Move cmd after the SSID text that may include "lci" or
11212 * "civic".
11213 */
11214 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
11215 if (cmd)
11216 cmd++;
11217
11218 }
11219
11220 if (cmd && os_strstr(cmd, "lci"))
11221 lci = 1;
11222
11223 if (cmd && os_strstr(cmd, "civic"))
11224 civic = 1;
11225
11226 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
11227 wpas_ctrl_neighbor_rep_cb,
11228 wpa_s);
11229
11230 return ret;
11231 }
11232
11233 #endif /* CONFIG_NO_RRM */
11234
11235
11236 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
11237 {
11238 eapol_sm_erp_flush(wpa_s->eapol);
11239 return 0;
11240 }
11241
11242
11243 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
11244 char *cmd)
11245 {
11246 char *token, *context = NULL;
11247 unsigned int enable = ~0, type = 0;
11248 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
11249 u8 *addr = NULL, *mask = NULL;
11250
11251 while ((token = str_token(cmd, " ", &context))) {
11252 if (os_strcasecmp(token, "scan") == 0) {
11253 type |= MAC_ADDR_RAND_SCAN;
11254 } else if (os_strcasecmp(token, "sched") == 0) {
11255 type |= MAC_ADDR_RAND_SCHED_SCAN;
11256 } else if (os_strcasecmp(token, "pno") == 0) {
11257 type |= MAC_ADDR_RAND_PNO;
11258 } else if (os_strcasecmp(token, "all") == 0) {
11259 type = wpa_s->mac_addr_rand_supported;
11260 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
11261 enable = atoi(token + 7);
11262 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
11263 addr = _addr;
11264 if (hwaddr_aton(token + 5, addr)) {
11265 wpa_printf(MSG_INFO,
11266 "CTRL: Invalid MAC address: %s",
11267 token);
11268 return -1;
11269 }
11270 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
11271 mask = _mask;
11272 if (hwaddr_aton(token + 5, mask)) {
11273 wpa_printf(MSG_INFO,
11274 "CTRL: Invalid MAC address mask: %s",
11275 token);
11276 return -1;
11277 }
11278 } else {
11279 wpa_printf(MSG_INFO,
11280 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
11281 token);
11282 return -1;
11283 }
11284 }
11285
11286 if (!type) {
11287 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
11288 return -1;
11289 }
11290
11291 if (enable > 1) {
11292 wpa_printf(MSG_INFO,
11293 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
11294 return -1;
11295 }
11296
11297 if (!enable)
11298 return wpas_disable_mac_addr_randomization(wpa_s, type);
11299
11300 return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask);
11301 }
11302
11303
11304 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
11305 char *buf, size_t buflen)
11306 {
11307 size_t reply_len;
11308
11309 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
11310 #ifdef CONFIG_AP
11311 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
11312 buflen - reply_len);
11313 #endif /* CONFIG_AP */
11314 return reply_len;
11315 }
11316
11317
11318 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
11319 {
11320 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
11321 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
11322 #ifdef CONFIG_AP
11323 wpas_ap_pmksa_cache_flush(wpa_s);
11324 #endif /* CONFIG_AP */
11325 }
11326
11327
11328 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
11329
11330 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
11331 const char *cmd, char *buf, size_t buflen)
11332 {
11333 struct rsn_pmksa_cache_entry *entry;
11334 struct wpa_ssid *ssid;
11335 char *pos, *pos2, *end;
11336 int ret;
11337 struct os_reltime now;
11338
11339 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
11340 if (!ssid)
11341 return -1;
11342
11343 pos = buf;
11344 end = buf + buflen;
11345
11346 os_get_reltime(&now);
11347
11348 /*
11349 * Entry format:
11350 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
11351 * <expiration in seconds> <akmp> <opportunistic>
11352 * [FILS Cache Identifier]
11353 */
11354
11355 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
11356 entry = entry->next) {
11357 if (entry->network_ctx != ssid)
11358 continue;
11359
11360 pos2 = pos;
11361 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
11362 MAC2STR(entry->aa));
11363 if (os_snprintf_error(end - pos2, ret))
11364 break;
11365 pos2 += ret;
11366
11367 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
11368 PMKID_LEN);
11369
11370 ret = os_snprintf(pos2, end - pos2, " ");
11371 if (os_snprintf_error(end - pos2, ret))
11372 break;
11373 pos2 += ret;
11374
11375 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
11376 entry->pmk_len);
11377
11378 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
11379 (int) (entry->reauth_time - now.sec),
11380 (int) (entry->expiration - now.sec),
11381 entry->akmp,
11382 entry->opportunistic);
11383 if (os_snprintf_error(end - pos2, ret))
11384 break;
11385 pos2 += ret;
11386
11387 if (entry->fils_cache_id_set) {
11388 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
11389 entry->fils_cache_id[0],
11390 entry->fils_cache_id[1]);
11391 if (os_snprintf_error(end - pos2, ret))
11392 break;
11393 pos2 += ret;
11394 }
11395
11396 ret = os_snprintf(pos2, end - pos2, "\n");
11397 if (os_snprintf_error(end - pos2, ret))
11398 break;
11399 pos2 += ret;
11400
11401 pos = pos2;
11402 }
11403
11404 return pos - buf;
11405 }
11406
11407
11408 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
11409 char *cmd)
11410 {
11411 struct rsn_pmksa_cache_entry *entry;
11412 struct wpa_ssid *ssid;
11413 char *pos, *pos2;
11414 int ret = -1;
11415 struct os_reltime now;
11416 int reauth_time = 0, expiration = 0, i;
11417
11418 /*
11419 * Entry format:
11420 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
11421 * <expiration in seconds> <akmp> <opportunistic>
11422 * [FILS Cache Identifier]
11423 */
11424
11425 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
11426 if (!ssid)
11427 return -1;
11428
11429 pos = os_strchr(cmd, ' ');
11430 if (!pos)
11431 return -1;
11432 pos++;
11433
11434 entry = os_zalloc(sizeof(*entry));
11435 if (!entry)
11436 return -1;
11437
11438 if (hwaddr_aton(pos, entry->aa))
11439 goto fail;
11440
11441 pos = os_strchr(pos, ' ');
11442 if (!pos)
11443 goto fail;
11444 pos++;
11445
11446 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
11447 goto fail;
11448
11449 pos = os_strchr(pos, ' ');
11450 if (!pos)
11451 goto fail;
11452 pos++;
11453
11454 pos2 = os_strchr(pos, ' ');
11455 if (!pos2)
11456 goto fail;
11457 entry->pmk_len = (pos2 - pos) / 2;
11458 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
11459 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
11460 goto fail;
11461
11462 pos = os_strchr(pos, ' ');
11463 if (!pos)
11464 goto fail;
11465 pos++;
11466
11467 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
11468 &entry->akmp, &entry->opportunistic) != 4)
11469 goto fail;
11470 if (reauth_time > expiration)
11471 goto fail;
11472 for (i = 0; i < 4; i++) {
11473 pos = os_strchr(pos, ' ');
11474 if (!pos) {
11475 if (i < 3)
11476 goto fail;
11477 break;
11478 }
11479 pos++;
11480 }
11481 if (pos) {
11482 if (hexstr2bin(pos, entry->fils_cache_id,
11483 FILS_CACHE_ID_LEN) < 0)
11484 goto fail;
11485 entry->fils_cache_id_set = 1;
11486 }
11487 os_get_reltime(&now);
11488 entry->expiration = now.sec + expiration;
11489 entry->reauth_time = now.sec + reauth_time;
11490
11491 entry->network_ctx = ssid;
11492 os_memcpy(entry->spa, wpa_s->own_addr, ETH_ALEN);
11493
11494 entry->external = true;
11495
11496 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
11497 entry = NULL;
11498 ret = 0;
11499 fail:
11500 os_free(entry);
11501 return ret;
11502 }
11503
11504
11505 #ifdef CONFIG_MESH
11506
11507 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
11508 const char *cmd, char *buf,
11509 size_t buflen)
11510 {
11511 u8 spa[ETH_ALEN];
11512
11513 if (!wpa_s->ifmsh)
11514 return -1;
11515
11516 if (os_strcasecmp(cmd, "any") == 0)
11517 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
11518
11519 if (hwaddr_aton(cmd, spa))
11520 return -1;
11521
11522 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
11523 }
11524
11525
11526 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
11527 char *cmd)
11528 {
11529 /*
11530 * We do not check mesh interface existence because PMKSA should be
11531 * stored before wpa_s->ifmsh creation to suppress commit message
11532 * creation.
11533 */
11534 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
11535 }
11536
11537 #endif /* CONFIG_MESH */
11538 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
11539
11540
11541 #ifdef CONFIG_FILS
11542 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
11543 const char *cmd)
11544 {
11545 struct fils_hlp_req *req;
11546 const char *pos;
11547
11548 /* format: <dst> <packet starting from ethertype> */
11549
11550 req = os_zalloc(sizeof(*req));
11551 if (!req)
11552 return -1;
11553
11554 if (hwaddr_aton(cmd, req->dst))
11555 goto fail;
11556
11557 pos = os_strchr(cmd, ' ');
11558 if (!pos)
11559 goto fail;
11560 pos++;
11561 req->pkt = wpabuf_parse_bin(pos);
11562 if (!req->pkt)
11563 goto fail;
11564
11565 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
11566 return 0;
11567 fail:
11568 wpabuf_free(req->pkt);
11569 os_free(req);
11570 return -1;
11571 }
11572 #endif /* CONFIG_FILS */
11573
11574
11575 int wpas_ctrl_cmd_debug_level(const char *cmd)
11576 {
11577 if (os_strcmp(cmd, "PING") == 0 ||
11578 os_strncmp(cmd, "BSS ", 4) == 0 ||
11579 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
11580 os_strncmp(cmd, "STATUS", 6) == 0 ||
11581 os_strncmp(cmd, "STA ", 4) == 0 ||
11582 os_strncmp(cmd, "STA-", 4) == 0)
11583 return MSG_EXCESSIVE;
11584 return MSG_DEBUG;
11585 }
11586
11587
11588 #ifndef CONFIG_NO_ROBUST_AV
11589 static int wpas_ctrl_iface_configure_mscs(struct wpa_supplicant *wpa_s,
11590 const char *cmd)
11591 {
11592 size_t frame_classifier_len;
11593 const char *pos, *end;
11594 struct robust_av_data *robust_av = &wpa_s->robust_av;
11595 int val;
11596
11597 /*
11598 * format:
11599 * <add|remove|change> [up_bitmap=<hex byte>] [up_limit=<integer>]
11600 * [stream_timeout=<in TUs>] [frame_classifier=<hex bytes>]
11601 */
11602 os_memset(robust_av, 0, sizeof(struct robust_av_data));
11603 if (os_strncmp(cmd, "add ", 4) == 0) {
11604 robust_av->request_type = SCS_REQ_ADD;
11605 } else if (os_strcmp(cmd, "remove") == 0) {
11606 robust_av->request_type = SCS_REQ_REMOVE;
11607 robust_av->valid_config = false;
11608 return wpas_send_mscs_req(wpa_s);
11609 } else if (os_strncmp(cmd, "change ", 7) == 0) {
11610 robust_av->request_type = SCS_REQ_CHANGE;
11611 } else {
11612 return -1;
11613 }
11614
11615 pos = os_strstr(cmd, "up_bitmap=");
11616 if (!pos)
11617 return -1;
11618
11619 val = hex2byte(pos + 10);
11620 if (val < 0)
11621 return -1;
11622 robust_av->up_bitmap = val;
11623
11624 pos = os_strstr(cmd, "up_limit=");
11625 if (!pos)
11626 return -1;
11627
11628 robust_av->up_limit = atoi(pos + 9);
11629
11630 pos = os_strstr(cmd, "stream_timeout=");
11631 if (!pos)
11632 return -1;
11633
11634 robust_av->stream_timeout = atoi(pos + 15);
11635 if (robust_av->stream_timeout == 0)
11636 return -1;
11637
11638 pos = os_strstr(cmd, "frame_classifier=");
11639 if (!pos)
11640 return -1;
11641
11642 pos += 17;
11643 end = os_strchr(pos, ' ');
11644 if (!end)
11645 end = pos + os_strlen(pos);
11646
11647 frame_classifier_len = (end - pos) / 2;
11648 if (frame_classifier_len > sizeof(robust_av->frame_classifier) ||
11649 hexstr2bin(pos, robust_av->frame_classifier, frame_classifier_len))
11650 return -1;
11651
11652 robust_av->frame_classifier_len = frame_classifier_len;
11653 robust_av->valid_config = true;
11654
11655 return wpas_send_mscs_req(wpa_s);
11656 }
11657 #endif /* CONFIG_NO_ROBUST_AV */
11658
11659
11660 #ifdef CONFIG_PASN
11661 static int wpas_ctrl_iface_pasn_start(struct wpa_supplicant *wpa_s, char *cmd)
11662 {
11663 char *token, *context = NULL;
11664 u8 bssid[ETH_ALEN];
11665 int akmp = -1, cipher = -1, got_bssid = 0;
11666 u16 group = 0xFFFF;
11667 u8 *comeback = NULL;
11668 size_t comeback_len = 0;
11669 int id = 0, ret = -1;
11670
11671 /*
11672 * Entry format: bssid=<BSSID> akmp=<AKMP> cipher=<CIPHER> group=<group>
11673 * [comeback=<hexdump>]
11674 */
11675 while ((token = str_token(cmd, " ", &context))) {
11676 if (os_strncmp(token, "bssid=", 6) == 0) {
11677 if (hwaddr_aton(token + 6, bssid))
11678 goto out;
11679 got_bssid = 1;
11680 } else if (os_strcmp(token, "akmp=PASN") == 0) {
11681 akmp = WPA_KEY_MGMT_PASN;
11682 #ifdef CONFIG_IEEE80211R
11683 } else if (os_strcmp(token, "akmp=FT-PSK") == 0) {
11684 akmp = WPA_KEY_MGMT_FT_PSK;
11685 } else if (os_strcmp(token, "akmp=FT-EAP-SHA384") == 0) {
11686 akmp = WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
11687 } else if (os_strcmp(token, "akmp=FT-EAP") == 0) {
11688 akmp = WPA_KEY_MGMT_FT_IEEE8021X;
11689 #endif /* CONFIG_IEEE80211R */
11690 #ifdef CONFIG_SAE
11691 } else if (os_strcmp(token, "akmp=SAE") == 0) {
11692 akmp = WPA_KEY_MGMT_SAE;
11693 } else if (os_strcmp(token, "akmp=SAE-EXT-KEY") == 0) {
11694 akmp = WPA_KEY_MGMT_SAE_EXT_KEY;
11695 #endif /* CONFIG_SAE */
11696 #ifdef CONFIG_FILS
11697 } else if (os_strcmp(token, "akmp=FILS-SHA256") == 0) {
11698 akmp = WPA_KEY_MGMT_FILS_SHA256;
11699 } else if (os_strcmp(token, "akmp=FILS-SHA384") == 0) {
11700 akmp = WPA_KEY_MGMT_FILS_SHA384;
11701 #endif /* CONFIG_FILS */
11702 } else if (os_strcmp(token, "cipher=CCMP-256") == 0) {
11703 cipher = WPA_CIPHER_CCMP_256;
11704 } else if (os_strcmp(token, "cipher=GCMP-256") == 0) {
11705 cipher = WPA_CIPHER_GCMP_256;
11706 } else if (os_strcmp(token, "cipher=CCMP") == 0) {
11707 cipher = WPA_CIPHER_CCMP;
11708 } else if (os_strcmp(token, "cipher=GCMP") == 0) {
11709 cipher = WPA_CIPHER_GCMP;
11710 } else if (os_strncmp(token, "group=", 6) == 0) {
11711 group = atoi(token + 6);
11712 } else if (os_strncmp(token, "nid=", 4) == 0) {
11713 id = atoi(token + 4);
11714 } else if (os_strncmp(token, "comeback=", 9) == 0) {
11715 comeback_len = os_strlen(token + 9);
11716 if (comeback || !comeback_len || comeback_len % 2)
11717 goto out;
11718
11719 comeback_len /= 2;
11720 comeback = os_malloc(comeback_len);
11721 if (!comeback ||
11722 hexstr2bin(token + 9, comeback, comeback_len))
11723 goto out;
11724 } else {
11725 wpa_printf(MSG_DEBUG,
11726 "CTRL: PASN Invalid parameter: '%s'",
11727 token);
11728 goto out;
11729 }
11730 }
11731
11732 if (!got_bssid || akmp == -1 || cipher == -1 || group == 0xFFFF) {
11733 wpa_printf(MSG_DEBUG,"CTRL: PASN missing parameter");
11734 goto out;
11735 }
11736
11737 ret = wpas_pasn_auth_start(wpa_s, wpa_s->own_addr, bssid, akmp, cipher,
11738 group, id, comeback, comeback_len);
11739 out:
11740 os_free(comeback);
11741 return ret;
11742 }
11743
11744
11745 static int wpas_ctrl_iface_pasn_deauthenticate(struct wpa_supplicant *wpa_s,
11746 const char *cmd)
11747 {
11748 u8 bssid[ETH_ALEN];
11749
11750 if (os_strncmp(cmd, "bssid=", 6) != 0 || hwaddr_aton(cmd + 6, bssid)) {
11751 wpa_printf(MSG_DEBUG,
11752 "CTRL: PASN_DEAUTH without valid BSSID");
11753 return -1;
11754 }
11755
11756 return wpas_pasn_deauthenticate(wpa_s, wpa_s->own_addr, bssid);
11757 }
11758
11759 #ifdef CONFIG_TESTING_OPTIONS
11760 static int wpas_ctrl_iface_pasn_driver(struct wpa_supplicant *wpa_s,
11761 const char *cmd)
11762 {
11763 union wpa_event_data event;
11764 const char *pos = cmd;
11765 u8 addr[ETH_ALEN];
11766
11767 os_memset(&event, 0, sizeof(event));
11768
11769 if (os_strncmp(pos, "auth ", 5) == 0)
11770 event.pasn_auth.action = PASN_ACTION_AUTH;
11771 else if (os_strncmp(pos, "del ", 4) == 0)
11772 event.pasn_auth.action =
11773 PASN_ACTION_DELETE_SECURE_RANGING_CONTEXT;
11774 else
11775 return -1;
11776
11777 pos = os_strchr(pos, ' ');
11778 if (!pos)
11779 return -1;
11780 pos++;
11781 while (hwaddr_aton(pos, addr) == 0) {
11782 struct pasn_peer *peer;
11783
11784 if (event.pasn_auth.num_peers == WPAS_MAX_PASN_PEERS)
11785 return -1;
11786 peer = &event.pasn_auth.peer[event.pasn_auth.num_peers];
11787 os_memcpy(peer->own_addr, wpa_s->own_addr, ETH_ALEN);
11788 os_memcpy(peer->peer_addr, addr, ETH_ALEN);
11789 event.pasn_auth.num_peers++;
11790
11791 pos = os_strchr(pos, ' ');
11792 if (!pos)
11793 break;
11794 pos++;
11795 }
11796
11797 wpa_supplicant_event(wpa_s, EVENT_PASN_AUTH, &event);
11798 return 0;
11799 }
11800 #endif /* CONFIG_TESTING_OPTIONS */
11801
11802 #endif /* CONFIG_PASN */
11803
11804
11805 #ifndef CONFIG_NO_ROBUST_AV
11806
11807 static int set_type4_frame_classifier(const char *cmd,
11808 struct type4_params *param)
11809 {
11810 const char *pos, *end;
11811 u8 classifier_mask = 0;
11812 int ret;
11813 char addr[INET6_ADDRSTRLEN];
11814 size_t alen;
11815
11816 if (os_strstr(cmd, "ip_version=ipv4")) {
11817 param->ip_version = IPV4;
11818 } else if (os_strstr(cmd, "ip_version=ipv6")) {
11819 param->ip_version = IPV6;
11820 } else {
11821 wpa_printf(MSG_ERROR, "IP version missing/invalid");
11822 return -1;
11823 }
11824
11825 classifier_mask |= BIT(0);
11826
11827 pos = os_strstr(cmd, "src_ip=");
11828 if (pos) {
11829 pos += 7;
11830 end = os_strchr(pos, ' ');
11831 if (!end)
11832 end = pos + os_strlen(pos);
11833
11834 alen = end - pos;
11835 if (alen >= INET6_ADDRSTRLEN)
11836 return -1;
11837 os_memcpy(addr, pos, alen);
11838 addr[alen] = '\0';
11839 if (param->ip_version == IPV4)
11840 ret = inet_pton(AF_INET, addr,
11841 ¶m->ip_params.v4.src_ip);
11842 else
11843 ret = inet_pton(AF_INET6, addr,
11844 ¶m->ip_params.v6.src_ip);
11845
11846 if (ret != 1) {
11847 wpa_printf(MSG_ERROR,
11848 "Error converting src IP address to binary ret=%d",
11849 ret);
11850 return -1;
11851 }
11852
11853 classifier_mask |= BIT(1);
11854 }
11855
11856 pos = os_strstr(cmd, "dst_ip=");
11857 if (pos) {
11858 pos += 7;
11859 end = os_strchr(pos, ' ');
11860 if (!end)
11861 end = pos + os_strlen(pos);
11862
11863 alen = end - pos;
11864 if (alen >= INET6_ADDRSTRLEN)
11865 return -1;
11866 os_memcpy(addr, pos, alen);
11867 addr[alen] = '\0';
11868 if (param->ip_version == IPV4)
11869 ret = inet_pton(AF_INET, addr,
11870 ¶m->ip_params.v4.dst_ip);
11871 else
11872 ret = inet_pton(AF_INET6, addr,
11873 ¶m->ip_params.v6.dst_ip);
11874
11875 if (ret != 1) {
11876 wpa_printf(MSG_ERROR,
11877 "Error converting dst IP address to binary ret=%d",
11878 ret);
11879 return -1;
11880 }
11881
11882 classifier_mask |= BIT(2);
11883 }
11884
11885 pos = os_strstr(cmd, "src_port=");
11886 if (pos && atoi(pos + 9) > 0) {
11887 if (param->ip_version == IPV4)
11888 param->ip_params.v4.src_port = atoi(pos + 9);
11889 else
11890 param->ip_params.v6.src_port = atoi(pos + 9);
11891 classifier_mask |= BIT(3);
11892 }
11893
11894 pos = os_strstr(cmd, "dst_port=");
11895 if (pos && atoi(pos + 9) > 0) {
11896 if (param->ip_version == IPV4)
11897 param->ip_params.v4.dst_port = atoi(pos + 9);
11898 else
11899 param->ip_params.v6.dst_port = atoi(pos + 9);
11900 classifier_mask |= BIT(4);
11901 }
11902
11903 pos = os_strstr(cmd, "dscp=");
11904 if (pos && atoi(pos + 5) > 0) {
11905 if (param->ip_version == IPV4)
11906 param->ip_params.v4.dscp = atoi(pos + 5);
11907 else
11908 param->ip_params.v6.dscp = atoi(pos + 5);
11909 classifier_mask |= BIT(5);
11910 }
11911
11912 if (param->ip_version == IPV4) {
11913 pos = os_strstr(cmd, "protocol=");
11914 if (pos) {
11915 if (os_strstr(pos, "udp")) {
11916 param->ip_params.v4.protocol = 17;
11917 } else if (os_strstr(pos, "tcp")) {
11918 param->ip_params.v4.protocol = 6;
11919 } else if (os_strstr(pos, "esp")) {
11920 param->ip_params.v4.protocol = 50;
11921 } else {
11922 wpa_printf(MSG_ERROR, "Invalid protocol");
11923 return -1;
11924 }
11925 classifier_mask |= BIT(6);
11926 }
11927 } else {
11928 pos = os_strstr(cmd, "next_header=");
11929 if (pos) {
11930 if (os_strstr(pos, "udp")) {
11931 param->ip_params.v6.next_header = 17;
11932 } else if (os_strstr(pos, "tcp")) {
11933 param->ip_params.v6.next_header = 6;
11934 } else if (os_strstr(pos, "esp")) {
11935 param->ip_params.v6.next_header = 50;
11936 } else {
11937 wpa_printf(MSG_ERROR, "Invalid next header");
11938 return -1;
11939 }
11940
11941 classifier_mask |= BIT(6);
11942 }
11943
11944 pos = os_strstr(cmd, "flow_label=");
11945 if (pos) {
11946 pos += 11;
11947 end = os_strchr(pos, ' ');
11948 if (!end)
11949 end = pos + os_strlen(pos);
11950
11951 if (end - pos != 6 ||
11952 hexstr2bin(pos, param->ip_params.v6.flow_label,
11953 3) ||
11954 param->ip_params.v6.flow_label[0] > 0x0F) {
11955 wpa_printf(MSG_ERROR, "Invalid flow label");
11956 return -1;
11957 }
11958
11959 classifier_mask |= BIT(7);
11960 }
11961 }
11962
11963 param->classifier_mask = classifier_mask;
11964 return 0;
11965 }
11966
11967
11968 static int set_type10_frame_classifier(const char *cmd,
11969 struct type10_params *param)
11970 {
11971 const char *pos, *end;
11972 size_t filter_len;
11973
11974 pos = os_strstr(cmd, "prot_instance=");
11975 if (!pos) {
11976 wpa_printf(MSG_ERROR, "Protocol instance missing");
11977 return -1;
11978 }
11979 param->prot_instance = atoi(pos + 14);
11980
11981 pos = os_strstr(cmd, "prot_number=");
11982 if (!pos) {
11983 wpa_printf(MSG_ERROR, "Protocol number missing");
11984 return -1;
11985 }
11986 if (os_strstr(pos, "udp")) {
11987 param->prot_number = 17;
11988 } else if (os_strstr(pos, "tcp")) {
11989 param->prot_number = 6;
11990 } else if (os_strstr(pos, "esp")) {
11991 param->prot_number = 50;
11992 } else {
11993 wpa_printf(MSG_ERROR, "Invalid protocol number");
11994 return -1;
11995 }
11996
11997 pos = os_strstr(cmd, "filter_value=");
11998 if (!pos) {
11999 wpa_printf(MSG_ERROR,
12000 "Classifier parameter filter_value missing");
12001 return -1;
12002 }
12003
12004 pos += 13;
12005 end = os_strchr(pos, ' ');
12006 if (!end)
12007 end = pos + os_strlen(pos);
12008
12009 filter_len = (end - pos) / 2;
12010 param->filter_value = os_malloc(filter_len);
12011 if (!param->filter_value)
12012 return -1;
12013
12014 if (hexstr2bin(pos, param->filter_value, filter_len)) {
12015 wpa_printf(MSG_ERROR, "Invalid filter_value %s", pos);
12016 goto free;
12017 }
12018
12019 pos = os_strstr(cmd, "filter_mask=");
12020 if (!pos) {
12021 wpa_printf(MSG_ERROR,
12022 "Classifier parameter filter_mask missing");
12023 goto free;
12024 }
12025
12026 pos += 12;
12027 end = os_strchr(pos, ' ');
12028 if (!end)
12029 end = pos + os_strlen(pos);
12030
12031 if (filter_len != (size_t) (end - pos) / 2) {
12032 wpa_printf(MSG_ERROR,
12033 "Filter mask length mismatch expected=%zu received=%zu",
12034 filter_len, (size_t) (end - pos) / 2);
12035 goto free;
12036 }
12037
12038 param->filter_mask = os_malloc(filter_len);
12039 if (!param->filter_mask)
12040 goto free;
12041
12042 if (hexstr2bin(pos, param->filter_mask, filter_len)) {
12043 wpa_printf(MSG_ERROR, "Invalid filter mask %s", pos);
12044 os_free(param->filter_mask);
12045 param->filter_mask = NULL;
12046 goto free;
12047 }
12048
12049 param->filter_len = filter_len;
12050 return 0;
12051 free:
12052 os_free(param->filter_value);
12053 param->filter_value = NULL;
12054 return -1;
12055 }
12056
12057
12058 static int scs_parse_type4(struct tclas_element *elem, const char *pos)
12059 {
12060 struct type4_params type4_param = { 0 };
12061
12062 if (set_type4_frame_classifier(pos, &type4_param) == -1) {
12063 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 4");
12064 return -1;
12065 }
12066
12067 os_memcpy(&elem->frame_classifier.type4_param,
12068 &type4_param, sizeof(struct type4_params));
12069 return 0;
12070 }
12071
12072
12073 static int scs_parse_type10(struct tclas_element *elem, const char *pos)
12074 {
12075 struct type10_params type10_param = { 0 };
12076
12077 if (set_type10_frame_classifier(pos, &type10_param) == -1) {
12078 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 10");
12079 return -1;
12080 }
12081
12082 os_memcpy(&elem->frame_classifier.type10_param,
12083 &type10_param, sizeof(struct type10_params));
12084 return 0;
12085 }
12086
12087
12088 static int wpas_ctrl_iface_configure_scs(struct wpa_supplicant *wpa_s,
12089 char *cmd)
12090 {
12091 char *pos1, *pos;
12092 struct scs_robust_av_data *scs_data = &wpa_s->scs_robust_av_req;
12093 struct scs_desc_elem desc_elem = { 0 };
12094 int val;
12095 unsigned int num_scs_desc = 0;
12096
12097 if (wpa_s->ongoing_scs_req) {
12098 wpa_printf(MSG_ERROR, "%s: SCS Request already in queue",
12099 __func__);
12100 return -1;
12101 }
12102
12103 /**
12104 * format:
12105 * [scs_id=<decimal number>] <add|remove|change> [scs_up=<0-7>]
12106 * [classifier_type=<4|10>]
12107 * [classifier params based on classifier type]
12108 * [tclas_processing=<0|1>]
12109 * [qos_characteristics] <up/down/direct> [min_si=<decimal number>]
12110 * [max_si=<decimal number>] [min_data_rate=<decimal number>]
12111 * [delay_bound=<decimal number>] [max_msdu=<decimal number>]
12112 * [service_start_time=<decimal number>]
12113 * [service_start_time_link_id=<decimal number>]
12114 * [mean_data_rate=<decimal number>] [burst_size=<decimal number>]
12115 * [msdu_lifetime=<decimal number>]
12116 * [msdu_delivery_info=<decimal number>] [medium_time=<decimal number>]
12117 * [scs_id=<decimal number>] ...
12118 */
12119 pos1 = os_strstr(cmd, "scs_id=");
12120 if (!pos1) {
12121 wpa_printf(MSG_ERROR, "SCSID not present");
12122 return -1;
12123 }
12124
12125 free_up_scs_desc(scs_data);
12126
12127 while (pos1) {
12128 struct scs_desc_elem *n1;
12129 struct active_scs_elem *active_scs_desc;
12130 char *next_scs_desc, *pos2;
12131 unsigned int num_tclas_elem = 0;
12132 bool scsid_active = false, tclas_present = false;
12133 struct qos_characteristics *qos_elem = &desc_elem.qos_char_elem;
12134
12135 desc_elem.scs_id = atoi(pos1 + 7);
12136 pos1 += 7;
12137
12138 next_scs_desc = os_strstr(pos1, "scs_id=");
12139 if (next_scs_desc) {
12140 char temp[20];
12141
12142 os_snprintf(temp, sizeof(temp), "scs_id=%d ",
12143 desc_elem.scs_id);
12144 if (os_strstr(next_scs_desc, temp)) {
12145 wpa_printf(MSG_ERROR,
12146 "Multiple SCS descriptors configured with same SCSID(=%d)",
12147 desc_elem.scs_id);
12148 goto free_scs_desc;
12149 }
12150 pos1[next_scs_desc - pos1 - 1] = '\0';
12151 }
12152
12153 dl_list_for_each(active_scs_desc, &wpa_s->active_scs_ids,
12154 struct active_scs_elem, list) {
12155 if (desc_elem.scs_id == active_scs_desc->scs_id) {
12156 scsid_active = true;
12157 break;
12158 }
12159 }
12160
12161 if (os_strstr(pos1, "add ")) {
12162 desc_elem.request_type = SCS_REQ_ADD;
12163 if (scsid_active) {
12164 wpa_printf(MSG_ERROR, "SCSID %d already active",
12165 desc_elem.scs_id);
12166 return -1;
12167 }
12168 } else if (os_strstr(pos1, "remove")) {
12169 desc_elem.request_type = SCS_REQ_REMOVE;
12170 if (!scsid_active) {
12171 wpa_printf(MSG_ERROR, "SCSID %d not active",
12172 desc_elem.scs_id);
12173 return -1;
12174 }
12175 goto scs_desc_end;
12176 } else if (os_strstr(pos1, "change ")) {
12177 desc_elem.request_type = SCS_REQ_CHANGE;
12178 if (!scsid_active) {
12179 wpa_printf(MSG_ERROR, "SCSID %d not active",
12180 desc_elem.scs_id);
12181 return -1;
12182 }
12183 } else {
12184 wpa_printf(MSG_ERROR, "SCS Request type invalid");
12185 goto free_scs_desc;
12186 }
12187
12188 pos1 = os_strstr(pos1, "scs_up=");
12189 if (!pos1) {
12190 wpa_printf(MSG_ERROR,
12191 "Intra-Access user priority not present");
12192 goto free_scs_desc;
12193 }
12194
12195 val = atoi(pos1 + 7);
12196 if (val < 0 || val > 7) {
12197 wpa_printf(MSG_ERROR,
12198 "Intra-Access user priority invalid %d",
12199 val);
12200 goto free_scs_desc;
12201 }
12202
12203 desc_elem.intra_access_priority = val;
12204 desc_elem.scs_up_avail = true;
12205
12206 pos = os_strstr(pos1, "classifier_type=");
12207 if (!pos) {
12208 wpa_printf(MSG_ERROR, "classifier type empty");
12209 goto qos_characteristics;
12210 }
12211 tclas_present = true;
12212
12213 while (pos) {
12214 struct tclas_element elem = { 0 }, *n;
12215 char *next_tclas_elem;
12216
12217 val = atoi(pos + 16);
12218 if (val != 4 && val != 10) {
12219 wpa_printf(MSG_ERROR,
12220 "classifier type invalid %d", val);
12221 goto free_scs_desc;
12222 }
12223
12224 elem.classifier_type = val;
12225 pos += 16;
12226
12227 next_tclas_elem = os_strstr(pos, "classifier_type=");
12228 if (next_tclas_elem) {
12229 pos1 = next_tclas_elem;
12230 pos[next_tclas_elem - pos - 1] = '\0';
12231 }
12232
12233 switch (val) {
12234 case 4:
12235 if (scs_parse_type4(&elem, pos) < 0)
12236 goto free_scs_desc;
12237 break;
12238 case 10:
12239 if (scs_parse_type10(&elem, pos) < 0)
12240 goto free_scs_desc;
12241 break;
12242 }
12243
12244 n = os_realloc(desc_elem.tclas_elems,
12245 (num_tclas_elem + 1) * sizeof(elem));
12246 if (!n)
12247 goto free_scs_desc;
12248
12249 desc_elem.tclas_elems = n;
12250 os_memcpy((u8 *) desc_elem.tclas_elems +
12251 num_tclas_elem * sizeof(elem),
12252 &elem, sizeof(elem));
12253 num_tclas_elem++;
12254 desc_elem.num_tclas_elem = num_tclas_elem;
12255 pos = next_tclas_elem;
12256 }
12257
12258 if (desc_elem.num_tclas_elem > 1) {
12259 pos1 = os_strstr(pos1, "tclas_processing=");
12260 if (!pos1) {
12261 wpa_printf(MSG_ERROR, "tclas_processing empty");
12262 goto free_scs_desc;
12263 }
12264
12265 val = atoi(pos1 + 17);
12266 if (val != 0 && val != 1) {
12267 wpa_printf(MSG_ERROR,
12268 "tclas_processing invalid");
12269 goto free_scs_desc;
12270 }
12271
12272 desc_elem.tclas_processing = val;
12273 }
12274
12275 qos_characteristics:
12276 pos1 = os_strstr(pos1, "qos_characteristics");
12277 if (!pos1 && !tclas_present)
12278 goto free_scs_desc;
12279 if (!pos1)
12280 goto scs_desc_end;
12281
12282 qos_elem->available = true;
12283 if (os_strstr(pos1, "up ")) {
12284 qos_elem->direction = SCS_DIRECTION_UP;
12285 if (tclas_present) {
12286 wpa_printf(MSG_ERROR,
12287 "TCLAS with direction:UP not allowed");
12288 goto free_scs_desc;
12289 }
12290 } else if (os_strstr(pos1, "down ")) {
12291 qos_elem->direction = SCS_DIRECTION_DOWN;
12292 } else if (os_strstr(pos1, "direct ")) {
12293 qos_elem->direction = SCS_DIRECTION_DIRECT;
12294 }
12295
12296 pos1 = os_strstr(pos1, "min_si=");
12297 if (!pos1) {
12298 wpa_printf(MSG_ERROR, "Min SI is required");
12299 goto free_scs_desc;
12300 }
12301 qos_elem->min_si = atoi(pos1 + 7);
12302
12303 pos1 = os_strstr(pos1, "max_si=");
12304 if (!pos1) {
12305 wpa_printf(MSG_ERROR, "Max SI is required");
12306 goto free_scs_desc;
12307 }
12308 qos_elem->max_si = atoi(pos1 + 7);
12309
12310 if (qos_elem->min_si && qos_elem->max_si &&
12311 qos_elem->max_si < qos_elem->min_si) {
12312 wpa_printf(MSG_ERROR, "Invalid Max SI");
12313 goto free_scs_desc;
12314 }
12315
12316 pos1 = os_strstr(pos1, "min_data_rate=");
12317 if (!pos1) {
12318 wpa_printf(MSG_ERROR, "Min data rate is required");
12319 goto free_scs_desc;
12320 }
12321 qos_elem->min_data_rate = atoi(pos1 + 14);
12322
12323 pos1 = os_strstr(pos1, "delay_bound=");
12324 if (!pos1) {
12325 wpa_printf(MSG_ERROR, "Delay Bound is required");
12326 goto free_scs_desc;
12327 }
12328 qos_elem->delay_bound = atoi(pos1 + 12);
12329
12330 if (qos_elem->min_data_rate >= BIT(24) ||
12331 qos_elem->delay_bound >= BIT(24)) {
12332 wpa_printf(MSG_ERROR,
12333 "Invalid min_data_rate or delay_bound");
12334 goto free_scs_desc;
12335 }
12336
12337 pos2 = os_strstr(pos1, "max_msdu=");
12338 if (pos2) {
12339 qos_elem->max_msdu_size = atoi(pos2 + 9);
12340 qos_elem->mask |= SCS_QOS_BIT_MAX_MSDU_SIZE;
12341 }
12342
12343 pos2 = os_strstr(pos1, "service_start_time=");
12344 if (pos2) {
12345 qos_elem->service_start_time = atoi(pos2 + 19);
12346 qos_elem->mask |= SCS_QOS_BIT_SERVICE_START_TIME;
12347 }
12348
12349 pos2 = os_strstr(pos1, "service_start_time_link_id=");
12350 if (pos2) {
12351 qos_elem->service_start_time_link_id = atoi(pos2 + 27);
12352 qos_elem->mask |= SCS_QOS_BIT_SERVICE_START_TIME_LINKID;
12353 }
12354
12355 pos2 = os_strstr(pos1, "mean_data_rate=");
12356 if (pos2) {
12357 qos_elem->mean_data_rate = atoi(pos2 + 15);
12358 qos_elem->mask |= SCS_QOS_BIT_MEAN_DATA_RATE;
12359 }
12360
12361 pos2 = os_strstr(pos1, "burst_size=");
12362 if (pos2) {
12363 qos_elem->burst_size = atoi(pos2 + 11);
12364 qos_elem->mask |=
12365 SCS_QOS_BIT_DELAYED_BOUNDED_BURST_SIZE;
12366 }
12367
12368 pos2 = os_strstr(pos1, "msdu_lifetime=");
12369 if (pos2) {
12370 qos_elem->msdu_lifetime = atoi(pos2 + 14);
12371 qos_elem->mask |= SCS_QOS_BIT_MSDU_LIFETIME;
12372 }
12373
12374 pos2 = os_strstr(pos1, "msdu_delivery_info=");
12375 if (pos2) {
12376 qos_elem->msdu_delivery_info = atoi(pos2 + 19);
12377 qos_elem->mask |= SCS_QOS_BIT_MSDU_DELIVERY_INFO;
12378 }
12379
12380 pos2 = os_strstr(pos1, "medium_time=");
12381 if (pos2) {
12382 qos_elem->medium_time = atoi(pos2 + 12);
12383 qos_elem->mask |= SCS_QOS_BIT_MEDIUM_TIME;
12384 }
12385
12386 scs_desc_end:
12387 n1 = os_realloc(scs_data->scs_desc_elems, (num_scs_desc + 1) *
12388 sizeof(struct scs_desc_elem));
12389 if (!n1)
12390 goto free_scs_desc;
12391
12392 scs_data->scs_desc_elems = n1;
12393 os_memcpy((u8 *) scs_data->scs_desc_elems + num_scs_desc *
12394 sizeof(desc_elem), &desc_elem, sizeof(desc_elem));
12395 num_scs_desc++;
12396 scs_data->num_scs_desc = num_scs_desc;
12397 pos1 = next_scs_desc;
12398 os_memset(&desc_elem, 0, sizeof(desc_elem));
12399 }
12400
12401 return wpas_send_scs_req(wpa_s);
12402
12403 free_scs_desc:
12404 free_up_tclas_elem(&desc_elem);
12405 free_up_scs_desc(scs_data);
12406 return -1;
12407 }
12408
12409
12410 static int wpas_ctrl_iface_send_dscp_resp(struct wpa_supplicant *wpa_s,
12411 const char *cmd)
12412 {
12413 char *pos;
12414 struct dscp_policy_status *policy = NULL, *n;
12415 int num_policies = 0, ret = -1;
12416 struct dscp_resp_data resp_data;
12417
12418 /*
12419 * format:
12420 * <[reset]>/<[solicited] [policy_id=1 status=0...]> [more]
12421 */
12422
12423 os_memset(&resp_data, 0, sizeof(resp_data));
12424
12425 resp_data.more = os_strstr(cmd, "more") != NULL;
12426
12427 if (os_strstr(cmd, "reset")) {
12428 resp_data.reset = true;
12429 resp_data.solicited = false;
12430 goto send_resp;
12431 }
12432
12433 resp_data.solicited = os_strstr(cmd, "solicited") != NULL;
12434
12435 pos = os_strstr(cmd, "policy_id=");
12436 while (pos) {
12437 n = os_realloc(policy, (num_policies + 1) * sizeof(*policy));
12438 if (!n)
12439 goto fail;
12440
12441 policy = n;
12442 pos += 10;
12443 policy[num_policies].id = atoi(pos);
12444 if (policy[num_policies].id == 0) {
12445 wpa_printf(MSG_ERROR, "DSCP: Invalid policy id");
12446 goto fail;
12447 }
12448
12449 pos = os_strstr(pos, "status=");
12450 if (!pos) {
12451 wpa_printf(MSG_ERROR,
12452 "DSCP: Status is not found for a policy");
12453 goto fail;
12454 }
12455
12456 pos += 7;
12457 policy[num_policies].status = atoi(pos);
12458 num_policies++;
12459
12460 pos = os_strstr(pos, "policy_id");
12461 }
12462
12463 resp_data.policy = policy;
12464 resp_data.num_policies = num_policies;
12465 send_resp:
12466 ret = wpas_send_dscp_response(wpa_s, &resp_data);
12467 if (ret)
12468 wpa_printf(MSG_ERROR, "DSCP: Failed to send DSCP response");
12469 fail:
12470 os_free(policy);
12471 return ret;
12472 }
12473
12474
12475 static int wpas_ctrl_iface_send_dscp_query(struct wpa_supplicant *wpa_s,
12476 const char *cmd)
12477 {
12478 char *pos;
12479
12480 /*
12481 * format:
12482 * Wildcard DSCP query
12483 * <wildcard>
12484 *
12485 * DSCP query with a domain name attribute:
12486 * [domain_name=<string>]
12487 */
12488
12489 if (os_strstr(cmd, "wildcard")) {
12490 wpa_printf(MSG_DEBUG, "QM: Send wildcard DSCP policy query");
12491 return wpas_send_dscp_query(wpa_s, NULL, 0);
12492 }
12493
12494 pos = os_strstr(cmd, "domain_name=");
12495 if (!pos || !os_strlen(pos + 12)) {
12496 wpa_printf(MSG_ERROR, "QM: Domain name not preset");
12497 return -1;
12498 }
12499
12500 return wpas_send_dscp_query(wpa_s, pos + 12, os_strlen(pos + 12));
12501 }
12502
12503 #endif /* CONFIG_NO_ROBUST_AV */
12504 enum {
12505 UNKNOWN = 0,
12506 LEGACY = 1,
12507 HT = 2,
12508 VHT = 3,
12509 HE = 4,
12510 };
12511
12512 enum {
12513 WIDTH_20 = 0,
12514 WIDTH_40 = 1,
12515 WIDTH_80 = 2,
12516 WIDTH_160 = 3,
12517 WIDTH_80P80 = 4,
12518 };
12519
12520 enum {
12521 UNKNOWN_MODE = 0,
12522 A_MODE = 1,
12523 B_MODE = 2,
12524 G_MODE = 3,
12525 };
12526
12527 static int wpa_supplicant_ctrl_iface_get_connection_capability(struct wpa_supplicant *wpa_s,
12528 char *buf, size_t buflen)
12529 {
12530 int technology = UNKNOWN;
12531 int channelBandwidth = WIDTH_20;
12532 int maxNumberTxSpatialStreams = 1;
12533 int maxNumberRxSpatialStreams = 1;
12534 int legacyMode = UNKNOWN_MODE;
12535 if (wpa_s->connection_set) {
12536 if (wpa_s->connection_he) {
12537 technology = HE;
12538 } else if (wpa_s->connection_vht) {
12539 technology = VHT;
12540 } else if (wpa_s->connection_ht) {
12541 technology = HT;
12542 } else {
12543 technology = LEGACY;
12544 if (wpas_freq_to_band(wpa_s->assoc_freq) == BAND_2_4_GHZ) {
12545 legacyMode = (wpa_s->connection_11b_only) ? B_MODE : G_MODE;
12546 } else {
12547 legacyMode = A_MODE;
12548 }
12549 }
12550 if (wpa_s->connection_channel_bandwidth == CHAN_WIDTH_20) {
12551 channelBandwidth = WIDTH_20;
12552 } else if (wpa_s->connection_channel_bandwidth == CHAN_WIDTH_40) {
12553 channelBandwidth = WIDTH_40;
12554 } else if (wpa_s->connection_channel_bandwidth == CHAN_WIDTH_80) {
12555 channelBandwidth = WIDTH_80;
12556 } else if (wpa_s->connection_channel_bandwidth == CHAN_WIDTH_160) {
12557 channelBandwidth = WIDTH_160;
12558 } else if (wpa_s->connection_channel_bandwidth == CHAN_WIDTH_80P80) {
12559 channelBandwidth = WIDTH_80P80;
12560 }
12561 maxNumberRxSpatialStreams = wpa_s->connection_max_nss_rx;
12562 maxNumberTxSpatialStreams = wpa_s->connection_max_nss_tx;
12563 }
12564 char *pos = buf;
12565 char *end = buf + buflen;
12566 int ret = os_snprintf(pos, end - pos, "technology=%d\n", technology);
12567 pos += ret;
12568 ret = os_snprintf(pos, end - pos, "channelBandwidth=%d\n", channelBandwidth);
12569 pos += ret;
12570 ret = os_snprintf(pos, end - pos, "maxNumberTxSpatialStreams=%d\n", maxNumberTxSpatialStreams);
12571 pos += ret;
12572 ret = os_snprintf(pos, end - pos, "maxNumberRxSpatialStreams=%d\n", maxNumberRxSpatialStreams);
12573 pos += ret;
12574 ret = os_snprintf(pos, end - pos, "legacyMode=%d\n", legacyMode);
12575 pos += ret;
12576 return pos - buf;
12577 }
12578
12579 static int wpa_supplicant_ctrl_iface_get_scan_ssid(struct wpa_supplicant *wpa_s,
12580 char *buf, size_t buflen)
12581 {
12582 if ((wpa_s != NULL) && (wpa_s->current_ssid != NULL)) {
12583 return os_snprintf(buf, buflen, "scan_ssid=%d\n",
12584 wpa_s->current_ssid->scan_ssid);
12585 }
12586 wpa_printf(MSG_ERROR, "can't get scan ssid");
12587 return 0;
12588 }
12589
12590 static int wpa_supplicant_ctrl_iface_get_psk_passphrase(struct wpa_supplicant *wpa_s,
12591 char *buf, size_t buflen)
12592 {
12593 if ((wpa_s != NULL) && (wpa_s->current_ssid != NULL) &&
12594 (wpa_s->current_ssid->passphrase != NULL)) {
12595 return os_snprintf(buf, buflen, "passphrase=%s\n",
12596 wpa_s->current_ssid->passphrase);
12597 }
12598 wpa_printf(MSG_ERROR, "can't get psk passphrase");
12599 return 0;
12600 }
12601
12602 static int wpa_supplicant_ctrl_iface_get_psk(struct wpa_supplicant *wpa_s,
12603 char *buf, size_t buflen)
12604 {
12605 if ((wpa_s != NULL) && (wpa_s->current_ssid != NULL) && wpa_s->current_ssid->psk_set) {
12606 char psk_encode[sizeof(wpa_s->current_ssid->psk) * 4 + 1];
12607 printf_encode(psk_encode, sizeof(psk_encode), wpa_s->current_ssid->psk,
12608 sizeof(wpa_s->current_ssid->psk));
12609 return os_snprintf(buf, buflen, "psk=%s\n", psk_encode);
12610 }
12611 wpa_printf(MSG_ERROR, "can't get psk");
12612 return 0;
12613 }
12614
12615 static int wpa_supplicant_ctrl_iface_get_wep_key(struct wpa_supplicant *wpa_s, char *cmd,
12616 char *buf, size_t buflen)
12617 {
12618 int idx = atoi(cmd);
12619 if ((wpa_s != NULL) && (wpa_s->current_ssid != NULL) && (idx < NUM_WEP_KEYS) && idx >= 0) {
12620 size_t wep_key_len = wpa_s->current_ssid->wep_key_len[idx];
12621 char wep_key_encode[wep_key_len * 4 + 1];
12622 printf_encode(wep_key_encode, sizeof(wep_key_encode), wpa_s->current_ssid->wep_key[idx],
12623 wep_key_len);
12624 return os_snprintf(buf, buflen, "wep_key=%s\n", wep_key_encode);
12625 }
12626 wpa_printf(MSG_ERROR, "can't get wep key");
12627 return 0;
12628 }
12629
12630 static int wpa_supplicant_ctrl_iface_get_wep_tx_key_idx(struct wpa_supplicant *wpa_s,
12631 char *buf, size_t buflen)
12632 {
12633 if ((wpa_s != NULL) && (wpa_s->current_ssid != NULL)) {
12634 return os_snprintf(buf, buflen, "wep_tx_keyidx=%d\n",
12635 wpa_s->current_ssid->wep_tx_keyidx);
12636 }
12637 wpa_printf(MSG_ERROR, "can't get wep key idx");
12638 return 0;
12639 }
12640
12641 static int wpa_supplicant_ctrl_iface_get_require_pmf(struct wpa_supplicant *wpa_s,
12642 char *buf, size_t buflen)
12643 {
12644 if ((wpa_s != NULL) && (wpa_s->current_ssid != NULL)) {
12645 return os_snprintf(buf, buflen, "require_pmf=%d\n",
12646 (wpa_s->current_ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED));
12647 }
12648 wpa_printf(MSG_ERROR, "can't get require pmf");
12649 return 0;
12650 }
12651
12652 static int wpa_supplicant_sta_shell_cmd(struct wpa_supplicant *wpa_s, char *params)
12653 {
12654 int ret;
12655 if (wpa_s == NULL || params == NULL) {
12656 return -1;
12657 }
12658
12659 wpa_printf(MSG_DEBUG, "ctrl_iface: wpa_supplicant_sta_shell_cmd");
12660 if ((strncmp(params, GSM_AUTH_PREFIX, GSM_AUTH_PREFIX_SIZE) == 0) ||
12661 (strncmp(params, UMTS_AUTH_PREFIX, UMTS_AUTH_PREFIX_SIZE) == 0) ||
12662 (strncmp(params, UMTS_AUTS_PREFIX, UMTS_AUTS_PREFIX_SIZE) == 0)) {
12663 ret = wpas_eap_sim_auth_rsp(wpa_s, params);
12664 if (ret == 0) {
12665 wpa_printf(MSG_DEBUG, "ctrl_iface: sim auth rsp done");
12666 }
12667 return 0;
12668 } else if (strncmp(params, SET_EXT_SIM, SET_EXT_SIM_SIZE) == 0) {
12669 ret = wpas_set_external_sim(wpa_s, params);
12670 if (ret == 0) {
12671 wpa_printf(MSG_DEBUG, "ctrl_iface: set external sim done");
12672 }
12673 return 0;
12674 }
12675 #if defined(CONFIG_OPEN_HARMONY_PATCH) && defined(CONFIG_HILINK_OKC_STA)
12676 else if (strncmp(params, "ENABLE", strlen("ENABLE")) == 0) {
12677 wpas_ctrl_iface_enable_hilink(wpa_s, params);
12678 return 0;
12679 } else if (strncmp(params, "HILINK_MAC", strlen("HILINK_MAC")) == 0) {
12680 wpas_ctrl_iface_delever_mac(wpa_s, params);
12681 return 0;
12682 }
12683 #endif
12684 else {
12685 wpa_printf(MSG_DEBUG, "no");
12686 return -1;
12687 }
12688 }
12689 #ifdef CONFIG_MLD_PATCH
12690 static int wpas_ctrl_iface_mlo_signal_poll(struct wpa_supplicant *wpa_s,
12691 char *buf, size_t buflen)
12692 {
12693 int ret, i;
12694 char *pos, *end;
12695 struct wpa_mlo_signal_info mlo_si;
12696
12697 if (!wpa_s->valid_links)
12698 return -1;
12699
12700 ret = wpa_drv_mlo_signal_poll(wpa_s, &mlo_si);
12701 if (ret)
12702 return -1;
12703
12704 pos = buf;
12705 end = buf + buflen;
12706
12707 for_each_link(mlo_si.valid_links, i) {
12708 ret = os_snprintf(pos, end - pos,
12709 "LINK_ID=%d\nRSSI=%d\nNOISE=%d\nFREQUENCY=%u\nTXLINKSPEED=%lu\nRXLINKSPEED=%lu\nTXPACKETS=%lu"
12710 "\nRXPACKETS=%lu\n",
12711 i, mlo_si.links[i].data.signal,
12712 mlo_si.links[i].current_noise,
12713 mlo_si.links[i].frequency,
12714 mlo_si.links[i].data.current_tx_rate / KBPS_OF_MBPS,
12715 mlo_si.links[i].data.current_rx_rate / KBPS_OF_MBPS,
12716 mlo_si.links[i].data.tx_packets,
12717 mlo_si.links[i].data.rx_packets);
12718 if (os_snprintf_error(end - pos, ret))
12719 return -1;
12720 pos += ret;
12721
12722 if (mlo_si.links[i].chanwidth != CHAN_WIDTH_UNKNOWN) {
12723 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
12724 channel_width_to_string(
12725 mlo_si.links[i].chanwidth));
12726 if (os_snprintf_error(end - pos, ret))
12727 return -1;
12728 pos += ret;
12729 }
12730
12731 if (mlo_si.links[i].center_frq1 > 0) {
12732 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
12733 mlo_si.links[i].center_frq1);
12734 if (os_snprintf_error(end - pos, ret))
12735 return -1;
12736 pos += ret;
12737 }
12738
12739 if (mlo_si.links[i].center_frq2 > 0) {
12740 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
12741 mlo_si.links[i].center_frq2);
12742 if (os_snprintf_error(end - pos, ret))
12743 return -1;
12744 pos += ret;
12745 }
12746
12747 if (mlo_si.links[i].data.avg_signal) {
12748 ret = os_snprintf(pos, end - pos,
12749 "AVG_RSSI=%d\n",
12750 mlo_si.links[i].data.avg_signal);
12751 if (os_snprintf_error(end - pos, ret))
12752 return -1;
12753 pos += ret;
12754 }
12755
12756 if (mlo_si.links[i].data.avg_beacon_signal) {
12757 ret = os_snprintf(
12758 pos, end - pos, "AVG_BEACON_RSSI=%d\n",
12759 mlo_si.links[i].data.avg_beacon_signal);
12760 if (os_snprintf_error(end - pos, ret))
12761 return -1;
12762 pos += ret;
12763 }
12764 }
12765
12766 return pos - buf;
12767 }
12768 #endif
12769 #ifdef CONFIG_MLD_PATCH
12770 static int wpas_ctrl_iface_mlo_status(struct wpa_supplicant *wpa_s,
12771 char *buf, size_t buflen)
12772 {
12773 int ret, i;
12774 char *pos, *end;
12775
12776 if (!wpa_s->valid_links)
12777 return -1;
12778
12779 pos = buf;
12780 end = buf + buflen;
12781
12782 for_each_link(wpa_s->valid_links, i) {
12783 ret = os_snprintf(pos, end - pos, "link_id=%d\nfreq=%u\n"
12784 "ap_link_addr=" MACSTR
12785 "\nsta_link_addr=" MACSTR "\n",
12786 i, wpa_s->links[i].freq,
12787 MAC2STR(wpa_s->links[i].bssid),
12788 MAC2STR(wpa_s->links[i].addr));
12789 if (os_snprintf_error(end - pos, ret))
12790 return pos - buf;
12791 pos += ret;
12792 }
12793
12794 return pos - buf;
12795 }
12796 #endif
12797
12798
12799 #ifdef CONFIG_TESTING_OPTIONS
12800 static int wpas_ctrl_ml_probe(struct wpa_supplicant *wpa_s, char *cmd)
12801 {
12802 char *token, *context = NULL;
12803 u8 bssid[ETH_ALEN];
12804 int mld_id = -1, link_id = -1;
12805 struct wpa_bss *bss;
12806 int *freqs;
12807
12808 os_memset(bssid, 0, sizeof(bssid));
12809
12810 while ((token = str_token(cmd, " ", &context))) {
12811 if (os_strncmp(token, "bssid=", 6) == 0) {
12812 if (hwaddr_aton(token + 6, bssid))
12813 return -1;
12814 } else if (os_strncmp(token, "mld_id=", 7) == 0) {
12815 mld_id = atoi(token + 7);
12816 } else if (os_strncmp(token, "link_id=", 8) == 0) {
12817 link_id = atoi(token + 8);
12818 }
12819 }
12820
12821 if (is_zero_ether_addr(bssid)) {
12822 wpa_printf(MSG_DEBUG,
12823 "MLD: Failed parsing ML probe request arguments");
12824 return -1;
12825 }
12826
12827 bss = wpa_bss_get_bssid(wpa_s, bssid);
12828 if (!bss) {
12829 wpa_printf(MSG_DEBUG,
12830 "MLD: Unknown BSS for " MACSTR, MAC2STR(bssid));
12831 return -1;
12832 }
12833
12834 if (wpa_s->sched_scanning || wpa_s->scanning ||
12835 (wpa_s->wpa_state > WPA_SCANNING &&
12836 wpa_s->wpa_state != WPA_COMPLETED)) {
12837 wpa_printf(MSG_DEBUG,
12838 "MLO: Ongoing scan: Reject ML probe request");
12839 return -1;
12840 }
12841
12842 freqs = os_malloc(sizeof(int) * 2);
12843 if (!freqs)
12844 return -1;
12845
12846 freqs[0] = bss->freq;
12847 freqs[1] = 0;
12848
12849 wpa_s->manual_scan_passive = 0;
12850 wpa_s->manual_scan_use_id = 0;
12851 wpa_s->manual_scan_only_new = 0;
12852 wpa_s->scan_id_count = 0;
12853 wpa_s->scan_res_handler = scan_only_handler;
12854 os_free(wpa_s->manual_scan_freqs);
12855 wpa_s->manual_scan_freqs = freqs;
12856
12857 os_memcpy(wpa_s->ml_probe_bssid, bssid, ETH_ALEN);
12858 wpa_s->ml_probe_mld_id = mld_id;
12859 if (link_id >= 0)
12860 wpa_s->ml_probe_links = BIT(link_id);
12861
12862 wpa_s->normal_scans = 0;
12863 wpa_s->scan_req = MANUAL_SCAN_REQ;
12864 wpa_s->after_wps = 0;
12865 wpa_s->known_wps_freq = 0;
12866 wpa_supplicant_req_scan(wpa_s, 0, 0);
12867
12868 return 0;
12869 }
12870 #endif /* CONFIG_TESTING_OPTIONS */
12871
12872
12873 #ifdef CONFIG_NAN_USD
12874
12875 static int wpas_ctrl_nan_publish(struct wpa_supplicant *wpa_s, char *cmd,
12876 char *buf, size_t buflen)
12877 {
12878 char *token, *context = NULL;
12879 int publish_id;
12880 struct nan_publish_params params;
12881 const char *service_name = NULL;
12882 struct wpabuf *ssi = NULL;
12883 int ret = -1;
12884 enum nan_service_protocol_type srv_proto_type = 0;
12885 int *freq_list = NULL;
12886
12887 os_memset(¶ms, 0, sizeof(params));
12888 /* USD shall use both solicited and unsolicited transmissions */
12889 params.unsolicited = true;
12890 params.solicited = true;
12891 /* USD shall require FSD without GAS */
12892 params.fsd = true;
12893 params.freq = NAN_USD_DEFAULT_FREQ;
12894
12895 while ((token = str_token(cmd, " ", &context))) {
12896 if (os_strncmp(token, "service_name=", 13) == 0) {
12897 service_name = token + 13;
12898 continue;
12899 }
12900
12901 if (os_strncmp(token, "ttl=", 4) == 0) {
12902 params.ttl = atoi(token + 4);
12903 continue;
12904 }
12905
12906 if (os_strncmp(token, "freq=", 5) == 0) {
12907 params.freq = atoi(token + 5);
12908 continue;
12909 }
12910
12911 if (os_strncmp(token, "freq_list=", 10) == 0) {
12912 char *pos = token + 10;
12913
12914 if (os_strcmp(pos, "all") == 0) {
12915 os_free(freq_list);
12916 freq_list = wpas_nan_usd_all_freqs(wpa_s);
12917 params.freq_list = freq_list;
12918 continue;
12919 }
12920
12921 while (pos && pos[0]) {
12922 int_array_add_unique(&freq_list, atoi(pos));
12923 pos = os_strchr(pos, ',');
12924 if (pos)
12925 pos++;
12926 }
12927
12928 params.freq_list = freq_list;
12929 continue;
12930 }
12931
12932 if (os_strncmp(token, "srv_proto_type=", 15) == 0) {
12933 srv_proto_type = atoi(token + 15);
12934 continue;
12935 }
12936
12937 if (os_strncmp(token, "ssi=", 4) == 0) {
12938 if (ssi)
12939 goto fail;
12940 ssi = wpabuf_parse_bin(token + 4);
12941 if (!ssi)
12942 goto fail;
12943 continue;
12944 }
12945
12946 if (os_strcmp(token, "solicited=0") == 0) {
12947 params.solicited = false;
12948 continue;
12949 }
12950
12951 if (os_strcmp(token, "unsolicited=0") == 0) {
12952 params.unsolicited = false;
12953 continue;
12954 }
12955
12956 if (os_strcmp(token, "fsd=0") == 0) {
12957 params.fsd = false;
12958 continue;
12959 }
12960
12961 wpa_printf(MSG_INFO, "CTRL: Invalid NAN_PUBLISH parameter: %s",
12962 token);
12963 goto fail;
12964 }
12965
12966 publish_id = wpas_nan_usd_publish(wpa_s, service_name, srv_proto_type,
12967 ssi, ¶ms);
12968 if (publish_id > 0)
12969 ret = os_snprintf(buf, buflen, "%d", publish_id);
12970 fail:
12971 wpabuf_free(ssi);
12972 os_free(freq_list);
12973 return ret;
12974 }
12975
12976
12977 static int wpas_ctrl_nan_cancel_publish(struct wpa_supplicant *wpa_s,
12978 char *cmd)
12979 {
12980 char *token, *context = NULL;
12981 int publish_id = 0;
12982
12983 while ((token = str_token(cmd, " ", &context))) {
12984 if (sscanf(token, "publish_id=%i", &publish_id) == 1)
12985 continue;
12986 wpa_printf(MSG_INFO,
12987 "CTRL: Invalid NAN_CANCEL_PUBLISH parameter: %s",
12988 token);
12989 return -1;
12990 }
12991
12992 if (publish_id <= 0) {
12993 wpa_printf(MSG_INFO,
12994 "CTRL: Invalid or missing NAN_CANCEL_PUBLISH publish_id");
12995 return -1;
12996 }
12997
12998 wpas_nan_usd_cancel_publish(wpa_s, publish_id);
12999 return 0;
13000 }
13001
13002
13003 static int wpas_ctrl_nan_update_publish(struct wpa_supplicant *wpa_s,
13004 char *cmd)
13005 {
13006 char *token, *context = NULL;
13007 int publish_id = 0;
13008 struct wpabuf *ssi = NULL;
13009 int ret = -1;
13010
13011 while ((token = str_token(cmd, " ", &context))) {
13012 if (sscanf(token, "publish_id=%i", &publish_id) == 1)
13013 continue;
13014 if (os_strncmp(token, "ssi=", 4) == 0) {
13015 if (ssi)
13016 goto fail;
13017 ssi = wpabuf_parse_bin(token + 4);
13018 if (!ssi)
13019 goto fail;
13020 continue;
13021 }
13022 wpa_printf(MSG_INFO,
13023 "CTRL: Invalid NAN_UPDATE_PUBLISH parameter: %s",
13024 token);
13025 goto fail;
13026 }
13027
13028 if (publish_id <= 0) {
13029 wpa_printf(MSG_INFO,
13030 "CTRL: Invalid or missing NAN_UPDATE_PUBLISH publish_id");
13031 goto fail;
13032 }
13033
13034 ret = wpas_nan_usd_update_publish(wpa_s, publish_id, ssi);
13035 fail:
13036 wpabuf_free(ssi);
13037 return ret;
13038 }
13039
13040
13041 static int wpas_ctrl_nan_subscribe(struct wpa_supplicant *wpa_s, char *cmd,
13042 char *buf, size_t buflen)
13043 {
13044 char *token, *context = NULL;
13045 int subscribe_id;
13046 struct nan_subscribe_params params;
13047 const char *service_name = NULL;
13048 struct wpabuf *ssi = NULL;
13049 int ret = -1;
13050 enum nan_service_protocol_type srv_proto_type = 0;
13051
13052 os_memset(¶ms, 0, sizeof(params));
13053 params.freq = NAN_USD_DEFAULT_FREQ;
13054
13055 while ((token = str_token(cmd, " ", &context))) {
13056 if (os_strncmp(token, "service_name=", 13) == 0) {
13057 service_name = token + 13;
13058 continue;
13059 }
13060
13061 if (os_strcmp(token, "active=1") == 0) {
13062 params.active = true;
13063 continue;
13064 }
13065
13066 if (os_strncmp(token, "ttl=", 4) == 0) {
13067 params.ttl = atoi(token + 4);
13068 continue;
13069 }
13070
13071 if (os_strncmp(token, "freq=", 5) == 0) {
13072 params.freq = atoi(token + 5);
13073 continue;
13074 }
13075
13076 if (os_strncmp(token, "srv_proto_type=", 15) == 0) {
13077 srv_proto_type = atoi(token + 15);
13078 continue;
13079 }
13080
13081 if (os_strncmp(token, "ssi=", 4) == 0) {
13082 if (ssi)
13083 goto fail;
13084 ssi = wpabuf_parse_bin(token + 4);
13085 if (!ssi)
13086 goto fail;
13087 continue;
13088 }
13089
13090 wpa_printf(MSG_INFO,
13091 "CTRL: Invalid NAN_SUBSCRIBE parameter: %s",
13092 token);
13093 goto fail;
13094 }
13095
13096 subscribe_id = wpas_nan_usd_subscribe(wpa_s, service_name,
13097 srv_proto_type, ssi,
13098 ¶ms);
13099 if (subscribe_id > 0)
13100 ret = os_snprintf(buf, buflen, "%d", subscribe_id);
13101 fail:
13102 wpabuf_free(ssi);
13103 return ret;
13104 }
13105
13106
13107 static int wpas_ctrl_nan_cancel_subscribe(struct wpa_supplicant *wpa_s,
13108 char *cmd)
13109 {
13110 char *token, *context = NULL;
13111 int subscribe_id = 0;
13112
13113 while ((token = str_token(cmd, " ", &context))) {
13114 if (sscanf(token, "subscribe_id=%i", &subscribe_id) == 1)
13115 continue;
13116 wpa_printf(MSG_INFO,
13117 "CTRL: Invalid NAN_CANCEL_SUBSCRIBE parameter: %s",
13118 token);
13119 return -1;
13120 }
13121
13122 if (subscribe_id <= 0) {
13123 wpa_printf(MSG_INFO,
13124 "CTRL: Invalid or missing NAN_CANCEL_SUBSCRIBE subscribe_id");
13125 return -1;
13126 }
13127
13128 wpas_nan_usd_cancel_subscribe(wpa_s, subscribe_id);
13129 return 0;
13130 }
13131
13132
13133 static int wpas_ctrl_nan_transmit(struct wpa_supplicant *wpa_s, char *cmd)
13134 {
13135 char *token, *context = NULL;
13136 int handle = 0;
13137 int req_instance_id = 0;
13138 struct wpabuf *ssi = NULL;
13139 u8 peer_addr[ETH_ALEN];
13140 int ret = -1;
13141
13142 os_memset(peer_addr, 0, ETH_ALEN);
13143
13144 while ((token = str_token(cmd, " ", &context))) {
13145 if (sscanf(token, "handle=%i", &handle) == 1)
13146 continue;
13147
13148 if (sscanf(token, "req_instance_id=%i", &req_instance_id) == 1)
13149 continue;
13150
13151 if (os_strncmp(token, "address=", 8) == 0) {
13152 if (hwaddr_aton(token + 8, peer_addr) < 0)
13153 return -1;
13154 continue;
13155 }
13156
13157 if (os_strncmp(token, "ssi=", 4) == 0) {
13158 if (ssi)
13159 goto fail;
13160 ssi = wpabuf_parse_bin(token + 4);
13161 if (!ssi)
13162 goto fail;
13163 continue;
13164 }
13165
13166 wpa_printf(MSG_INFO,
13167 "CTRL: Invalid NAN_TRANSMIT parameter: %s",
13168 token);
13169 goto fail;
13170 }
13171
13172 if (handle <= 0) {
13173 wpa_printf(MSG_INFO,
13174 "CTRL: Invalid or missing NAN_TRANSMIT handle");
13175 goto fail;
13176 }
13177
13178 if (is_zero_ether_addr(peer_addr)) {
13179 wpa_printf(MSG_INFO,
13180 "CTRL: Invalid or missing NAN_TRANSMIT address");
13181 goto fail;
13182 }
13183
13184 ret = wpas_nan_usd_transmit(wpa_s, handle, ssi, NULL, peer_addr,
13185 req_instance_id);
13186 fail:
13187 wpabuf_free(ssi);
13188 return ret;
13189 }
13190
13191 #endif /* CONFIG_NAN_USD */
13192
13193
13194 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
13195 char *buf, size_t *resp_len)
13196 {
13197 char *reply;
13198 #ifdef CONFIG_OPEN_HARMONY_PATCH
13199 const int reply_size = 4096 * 10;
13200 #else
13201 const int reply_size = 4096;
13202 #endif
13203 int reply_len;
13204
13205 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
13206 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
13207 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
13208 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
13209 if (wpa_debug_show_keys)
13210 wpa_msg_only_for_cb(wpa_s, MSG_DEBUG,
13211 "Control interface command '%s'", buf);
13212 else
13213 wpa_dbg(wpa_s, MSG_EXCESSIVE,
13214 "Control interface command '%s [REMOVED]'",
13215 os_strncmp(buf, WPA_CTRL_RSP,
13216 os_strlen(WPA_CTRL_RSP)) == 0 ?
13217 WPA_CTRL_RSP :
13218 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
13219 "SET_NETWORK" : "key-add"));
13220 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
13221 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
13222 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
13223 (const u8 *) buf, os_strlen(buf));
13224 } else {
13225 int level = wpas_ctrl_cmd_debug_level(buf);
13226 wpa_msg_only_for_cb(wpa_s, level, "Control interface command '%s'", buf);
13227 }
13228
13229 reply = os_malloc(reply_size);
13230 if (reply == NULL) {
13231 wpa_printf(MSG_ERROR, "reply is NULL!");
13232 *resp_len = 1;
13233 return NULL;
13234 }
13235
13236 os_memcpy(reply, "OK\n", 3);
13237 reply_len = 3;
13238
13239 if (os_strcmp(buf, "PING") == 0) {
13240 os_memcpy(reply, "PONG\n", 5);
13241 reply_len = 5;
13242 } else if (os_strcmp(buf, "IFNAME") == 0) {
13243 reply_len = os_strlen(wpa_s->ifname);
13244 os_memcpy(reply, wpa_s->ifname, reply_len);
13245 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
13246 if (wpa_debug_reopen_file() < 0)
13247 reply_len = -1;
13248 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
13249 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
13250 } else if (os_strcmp(buf, "MIB") == 0) {
13251 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
13252 if (reply_len >= 0) {
13253 reply_len += eapol_sm_get_mib(wpa_s->eapol,
13254 reply + reply_len,
13255 reply_size - reply_len);
13256 #ifdef CONFIG_MACSEC
13257 reply_len += ieee802_1x_kay_get_mib(
13258 wpa_s->kay, reply + reply_len,
13259 reply_size - reply_len);
13260 #endif /* CONFIG_MACSEC */
13261 }
13262 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
13263 reply_len = wpa_supplicant_ctrl_iface_status(
13264 wpa_s, buf + 6, reply, reply_size);
13265 } else if (os_strcmp(buf, "PMKSA") == 0) {
13266 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
13267 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
13268 wpas_ctrl_iface_pmksa_flush(wpa_s);
13269 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
13270 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
13271 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
13272 reply, reply_size);
13273 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
13274 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
13275 reply_len = -1;
13276 #ifdef CONFIG_MESH
13277 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
13278 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
13279 reply, reply_size);
13280 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
13281 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
13282 reply_len = -1;
13283 #endif /* CONFIG_MESH */
13284 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
13285 } else if (os_strncmp(buf, "SET ", 4) == 0) {
13286 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
13287 reply_len = -1;
13288 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
13289 reply_len = wpa_config_dump_values(wpa_s->conf,
13290 reply, reply_size);
13291 } else if (os_strncmp(buf, "GET ", 4) == 0) {
13292 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
13293 reply, reply_size);
13294 } else if (os_strcmp(buf, "LOGON") == 0) {
13295 eapol_sm_notify_logoff(wpa_s->eapol, false);
13296 } else if (os_strcmp(buf, "LOGOFF") == 0) {
13297 eapol_sm_notify_logoff(wpa_s->eapol, true);
13298 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
13299 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
13300 reply_len = -1;
13301 else
13302 wpas_request_connection(wpa_s);
13303 } else if (os_strcmp(buf, "REATTACH") == 0) {
13304 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
13305 !wpa_s->current_ssid)
13306 reply_len = -1;
13307 else {
13308 wpa_s->reattach = 1;
13309 wpas_request_connection(wpa_s);
13310 }
13311 } else if (os_strcmp(buf, "RECONNECT") == 0) {
13312 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
13313 reply_len = -1;
13314 else if (wpa_s->disconnected)
13315 wpas_request_connection(wpa_s);
13316 #ifdef IEEE8021X_EAPOL
13317 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
13318 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
13319 reply_len = -1;
13320 #endif /* IEEE8021X_EAPOL */
13321 #ifdef CONFIG_IEEE80211R
13322 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
13323 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
13324 reply_len = -1;
13325 #endif /* CONFIG_IEEE80211R */
13326 #ifdef CONFIG_WPS
13327 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
13328 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
13329 if (res == -2) {
13330 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
13331 reply_len = 17;
13332 } else if (res)
13333 reply_len = -1;
13334 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
13335 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
13336 if (res == -2) {
13337 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
13338 reply_len = 17;
13339 } else if (res)
13340 reply_len = -1;
13341 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
13342 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
13343 reply,
13344 reply_size);
13345 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
13346 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
13347 wpa_s, buf + 14, reply, reply_size);
13348 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
13349 if (wpas_wps_cancel(wpa_s))
13350 reply_len = -1;
13351 #ifdef CONFIG_WPS_NFC
13352 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
13353 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
13354 reply_len = -1;
13355 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
13356 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
13357 reply_len = -1;
13358 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
13359 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
13360 wpa_s, buf + 21, reply, reply_size);
13361 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
13362 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
13363 wpa_s, buf + 14, reply, reply_size);
13364 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
13365 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
13366 buf + 17))
13367 reply_len = -1;
13368 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
13369 reply_len = wpas_ctrl_nfc_get_handover_req(
13370 wpa_s, buf + 21, reply, reply_size);
13371 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
13372 reply_len = wpas_ctrl_nfc_get_handover_sel(
13373 wpa_s, buf + 21, reply, reply_size);
13374 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
13375 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
13376 reply_len = -1;
13377 #endif /* CONFIG_WPS_NFC */
13378 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
13379 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
13380 reply_len = -1;
13381 #ifdef CONFIG_AP
13382 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
13383 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
13384 wpa_s, buf + 11, reply, reply_size);
13385 #endif /* CONFIG_AP */
13386 #ifdef CONFIG_WPS_ER
13387 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
13388 if (wpas_wps_er_start(wpa_s, NULL))
13389 reply_len = -1;
13390 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
13391 if (wpas_wps_er_start(wpa_s, buf + 13))
13392 reply_len = -1;
13393 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
13394 wpas_wps_er_stop(wpa_s);
13395 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
13396 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
13397 reply_len = -1;
13398 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
13399 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
13400 if (ret == -2) {
13401 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
13402 reply_len = 17;
13403 } else if (ret == -3) {
13404 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
13405 reply_len = 18;
13406 } else if (ret == -4) {
13407 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
13408 reply_len = 20;
13409 } else if (ret)
13410 reply_len = -1;
13411 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
13412 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
13413 reply_len = -1;
13414 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
13415 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
13416 buf + 18))
13417 reply_len = -1;
13418 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
13419 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
13420 reply_len = -1;
13421 #ifdef CONFIG_WPS_NFC
13422 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
13423 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
13424 wpa_s, buf + 24, reply, reply_size);
13425 #endif /* CONFIG_WPS_NFC */
13426 #endif /* CONFIG_WPS_ER */
13427 #endif /* CONFIG_WPS */
13428 #ifdef CONFIG_IBSS_RSN
13429 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
13430 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
13431 reply_len = -1;
13432 #endif /* CONFIG_IBSS_RSN */
13433 #ifdef CONFIG_MESH
13434 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
13435 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
13436 wpa_s, buf + 19, reply, reply_size);
13437 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
13438 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
13439 wpa_s, "", reply, reply_size);
13440 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
13441 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
13442 reply_len = -1;
13443 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
13444 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
13445 buf + 18))
13446 reply_len = -1;
13447 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
13448 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
13449 reply_len = -1;
13450 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
13451 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
13452 reply_len = -1;
13453 } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) {
13454 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16))
13455 reply_len = -1;
13456 #endif /* CONFIG_MESH */
13457 #ifdef CONFIG_P2P
13458 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
13459 if (p2p_ctrl_find(wpa_s, buf + 8))
13460 reply_len = -1;
13461 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
13462 if (p2p_ctrl_find(wpa_s, ""))
13463 reply_len = -1;
13464 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
13465 wpas_p2p_stop_find(wpa_s);
13466 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
13467 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
13468 reply_len = -1;
13469 } else if (os_strncmp(buf, "P2P_DELIVER_DATA ", 17) == 0) {
13470 if (p2p_ctrl_deliver_data(wpa_s, buf + 17))
13471 reply_len = -1;
13472 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
13473 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
13474 reply_len = -1;
13475 #ifdef CONFIG_MAGICLINK
13476 } else if (os_strncmp(buf, "MAGICLINK ",
13477 os_strlen("MAGICLINK ")) == 0) {
13478 wpa_dbg(wpa_s, MSG_ERROR, "magiclink cmd in");
13479 if (hw_magiclink_p2p_ctrl_connect(wpa_s,
13480 buf + os_strlen("MAGICLINK ")))
13481 reply_len = -1;
13482 #endif /* CONFIG_MAGICLINK */
13483 #ifdef CONFIG_VENDOR_EXT
13484 } else if (wpa_vendor_ext_process_cli_cmd(wpa_s, buf, reply, reply_size, &reply_len) == 0) {
13485 /* Vendor ext command has been processed. */
13486 wpa_dbg(wpa_s, MSG_INFO, "Vendor ext command process %s",
13487 reply_len == -1 ? "fail" : "success");
13488 #endif
13489 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
13490 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
13491 reply_size);
13492 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
13493 if (p2p_ctrl_listen(wpa_s, buf + 11))
13494 reply_len = -1;
13495 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
13496 if (p2p_ctrl_listen(wpa_s, ""))
13497 reply_len = -1;
13498 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
13499 if (wpas_p2p_group_remove(wpa_s, buf + 17))
13500 reply_len = -1;
13501 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
13502 if (p2p_ctrl_group_add(wpa_s, ""))
13503 reply_len = -1;
13504 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
13505 if (p2p_ctrl_group_add(wpa_s, buf + 14))
13506 reply_len = -1;
13507 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
13508 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
13509 reply_size);
13510 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
13511 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
13512 reply_len = -1;
13513 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
13514 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
13515 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
13516 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
13517 reply_size);
13518 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
13519 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
13520 reply_len = -1;
13521 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
13522 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
13523 reply_len = -1;
13524 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
13525 wpas_p2p_sd_service_update(wpa_s);
13526 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
13527 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
13528 reply_len = -1;
13529 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
13530 wpas_p2p_service_flush(wpa_s);
13531 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
13532 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
13533 reply_len = -1;
13534 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
13535 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
13536 reply_len = -1;
13537 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
13538 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
13539 reply_len = -1;
13540 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
13541 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
13542 reply_len = -1;
13543 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
13544 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
13545 reply_len = -1;
13546 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
13547 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
13548 reply_size);
13549 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
13550 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
13551 reply_len = -1;
13552 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
13553 p2p_ctrl_flush(wpa_s);
13554 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
13555 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
13556 reply_len = -1;
13557 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
13558 if (wpas_p2p_cancel(wpa_s))
13559 reply_len = -1;
13560 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
13561 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
13562 reply_len = -1;
13563 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
13564 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
13565 reply_len = -1;
13566 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
13567 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
13568 reply_len = -1;
13569 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
13570 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
13571 reply_len = -1;
13572 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
13573 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
13574 reply_len = -1;
13575 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
13576 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
13577 reply_len = -1;
13578 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
13579 if (wpas_p2p_lo_stop(wpa_s))
13580 reply_len = -1;
13581 #endif /* CONFIG_P2P */
13582 #ifdef CONFIG_WIFI_DISPLAY
13583 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
13584 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
13585 reply_len = -1;
13586 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
13587 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
13588 reply, reply_size);
13589 #endif /* CONFIG_WIFI_DISPLAY */
13590 #ifdef CONFIG_INTERWORKING
13591 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
13592 if (interworking_fetch_anqp(wpa_s) < 0)
13593 reply_len = -1;
13594 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
13595 interworking_stop_fetch_anqp(wpa_s);
13596 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
13597 if (ctrl_interworking_select(wpa_s, NULL) < 0)
13598 reply_len = -1;
13599 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
13600 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
13601 reply_len = -1;
13602 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
13603 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
13604 reply_len = -1;
13605 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
13606 int id;
13607
13608 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
13609 if (id < 0)
13610 reply_len = -1;
13611 else {
13612 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
13613 if (os_snprintf_error(reply_size, reply_len))
13614 reply_len = -1;
13615 }
13616 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
13617 if (get_anqp(wpa_s, buf + 9) < 0)
13618 reply_len = -1;
13619 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
13620 if (gas_request(wpa_s, buf + 12) < 0)
13621 reply_len = -1;
13622 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
13623 reply_len = gas_response_get(wpa_s, buf + 17, reply,
13624 reply_size);
13625 #endif /* CONFIG_INTERWORKING */
13626 #ifdef CONFIG_HS20
13627 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
13628 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
13629 reply_len = -1;
13630 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
13631 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
13632 reply_len = -1;
13633 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
13634 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
13635 reply_len = -1;
13636 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
13637 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
13638 reply_len = -1;
13639 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
13640 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
13641 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
13642 if (del_hs20_icon(wpa_s, buf + 14) < 0)
13643 reply_len = -1;
13644 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
13645 if (hs20_fetch_osu(wpa_s, 0) < 0)
13646 reply_len = -1;
13647 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
13648 if (hs20_fetch_osu(wpa_s, 1) < 0)
13649 reply_len = -1;
13650 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
13651 hs20_cancel_fetch_osu(wpa_s);
13652 #endif /* CONFIG_HS20 */
13653 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
13654 {
13655 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
13656 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
13657 reply_len = -1;
13658 else {
13659 /*
13660 * Notify response from timeout to allow the control
13661 * interface response to be sent first.
13662 */
13663 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
13664 wpa_s, NULL);
13665 }
13666 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
13667 if (wpa_supplicant_reload_configuration(wpa_s))
13668 reply_len = -1;
13669 #ifdef CONFIG_DRIVER_HDF
13670 } else if (os_strcmp(buf, "TERMINATE_WITH_RESET_DRIVER") == 0) {
13671 wpa_supplicant_terminate_with_reset_driver(wpa_s->global);
13672 #endif
13673 } else if (os_strcmp(buf, "TERMINATE") == 0) {
13674 wpa_supplicant_terminate_proc(wpa_s->global);
13675 } else if (os_strcmp(buf, "GET_CONNECTION_CAPABILITY") == 0) {
13676 reply_len = wpa_supplicant_ctrl_iface_get_connection_capability(
13677 wpa_s, reply, reply_size);
13678 } else if (os_strcmp(buf, "GET_SCAN_SSID") == 0) {
13679 reply_len = wpa_supplicant_ctrl_iface_get_scan_ssid(
13680 wpa_s, reply, reply_size);
13681 } else if (os_strcmp(buf, "GET_PSK_PASSPHRASE") == 0) {
13682 reply_len = wpa_supplicant_ctrl_iface_get_psk_passphrase(
13683 wpa_s, reply, reply_size);
13684 } else if (os_strcmp(buf, "GET_PSK") == 0) {
13685 reply_len = wpa_supplicant_ctrl_iface_get_psk(
13686 wpa_s, reply, reply_size);
13687 } else if (os_strncmp(buf, "GET_WEP_KEY ", os_strlen("GET_WEP_KEY ")) == 0) {
13688 reply_len = wpa_supplicant_ctrl_iface_get_wep_key(
13689 wpa_s, buf + os_strlen("GET_WEP_KEY_IDX "), reply, reply_size);
13690 } else if (os_strcmp(buf, "GET_WEP_KEY_IDX") == 0) {
13691 reply_len = wpa_supplicant_ctrl_iface_get_wep_tx_key_idx(
13692 wpa_s, reply, reply_size);
13693 } else if (os_strcmp(buf, "GET_REQUIRE_PMF") == 0) {
13694 reply_len = wpa_supplicant_ctrl_iface_get_require_pmf(
13695 wpa_s, reply, reply_size);
13696 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
13697 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
13698 reply_len = -1;
13699 } else if (os_strncmp(buf, "BSSID_IGNORE", 12) == 0) {
13700 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
13701 wpa_s, buf + 12, reply, reply_size);
13702 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
13703 /* deprecated backwards compatibility alias for BSSID_IGNORE */
13704 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
13705 wpa_s, buf + 9, reply, reply_size);
13706 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
13707 reply_len = wpa_supplicant_ctrl_iface_log_level(
13708 wpa_s, buf + 9, reply, reply_size);
13709 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
13710 reply_len = wpa_supplicant_ctrl_iface_list_networks(
13711 wpa_s, buf + 14, reply, reply_size);
13712 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
13713 reply_len = wpa_supplicant_ctrl_iface_list_networks(
13714 wpa_s, NULL, reply, reply_size);
13715 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
13716 wpas_request_disconnection(wpa_s);
13717 } else if (os_strcmp(buf, "SCAN") == 0) {
13718 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
13719 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
13720 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
13721 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
13722 reply_len = wpa_supplicant_ctrl_iface_scan_results(
13723 wpa_s, reply, reply_size);
13724 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
13725 if (wpas_abort_ongoing_scan(wpa_s) < 0)
13726 reply_len = -1;
13727 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
13728 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
13729 reply_len = -1;
13730 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
13731 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
13732 reply_len = -1;
13733 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
13734 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
13735 reply_len = -1;
13736 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
13737 reply_len = wpa_supplicant_ctrl_iface_add_network(
13738 wpa_s, reply, reply_size);
13739 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
13740 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
13741 reply_len = -1;
13742 } else if (os_strncmp(buf, "STA_SHELL ", 10) == 0) {
13743 if (wpa_supplicant_sta_shell_cmd(wpa_s, buf + 10))
13744 reply_len = -1;
13745 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
13746 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
13747 reply_len = -1;
13748 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
13749 reply_len = wpa_supplicant_ctrl_iface_get_network(
13750 wpa_s, buf + 12, reply, reply_size);
13751 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
13752 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
13753 wpa_s))
13754 reply_len = -1;
13755 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
13756 reply_len = wpa_supplicant_ctrl_iface_list_creds(
13757 wpa_s, reply, reply_size);
13758 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
13759 reply_len = wpa_supplicant_ctrl_iface_add_cred(
13760 wpa_s, reply, reply_size);
13761 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
13762 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
13763 reply_len = -1;
13764 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
13765 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
13766 reply_len = -1;
13767 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
13768 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
13769 reply,
13770 reply_size);
13771 #ifndef CONFIG_NO_CONFIG_WRITE
13772 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
13773 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
13774 reply_len = -1;
13775 #endif /* CONFIG_NO_CONFIG_WRITE */
13776 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
13777 reply_len = wpa_supplicant_ctrl_iface_get_capability(
13778 wpa_s, buf + 15, reply, reply_size);
13779 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
13780 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
13781 reply_len = -1;
13782 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
13783 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
13784 reply_len = -1;
13785 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
13786 reply_len = wpa_supplicant_global_iface_list(
13787 wpa_s->global, reply, reply_size);
13788 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
13789 reply_len = wpa_supplicant_global_iface_interfaces(
13790 wpa_s->global, buf + 10, reply, reply_size);
13791 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
13792 reply_len = wpa_supplicant_ctrl_iface_bss(
13793 wpa_s, buf + 4, reply, reply_size);
13794 #ifdef CONFIG_AP
13795 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
13796 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
13797 } else if (os_strncmp(buf, "STA ", 4) == 0) {
13798 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
13799 reply_size);
13800 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
13801 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
13802 reply_size);
13803 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
13804 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
13805 reply_len = -1;
13806 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
13807 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
13808 reply_len = -1;
13809 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
13810 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
13811 reply_len = -1;
13812 } else if (os_strcmp(buf, "STOP_AP") == 0) {
13813 if (wpas_ap_stop_ap(wpa_s))
13814 reply_len = -1;
13815 } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) {
13816 if (wpas_ap_update_beacon(wpa_s))
13817 reply_len = -1;
13818 } else if (os_strncmp(buf, "ACCEPT_ACL ", 11) == 0) {
13819 if (os_strncmp(buf + 11, "ADD_MAC ", 8) == 0) {
13820 if (ap_ctrl_iface_acl_add_mac(wpa_s,
13821 DENY_UNLESS_ACCEPTED,
13822 buf + 19) ||
13823 ap_ctrl_iface_set_acl(wpa_s))
13824 reply_len = -1;
13825 } else if (os_strncmp((buf + 11), "DEL_MAC ", 8) == 0) {
13826 if (ap_ctrl_iface_acl_del_mac(wpa_s,
13827 DENY_UNLESS_ACCEPTED,
13828 buf + 19) ||
13829 ap_ctrl_iface_set_acl(wpa_s) ||
13830 ap_ctrl_iface_disassoc_accept_mac(wpa_s))
13831 reply_len = -1;
13832 } else if (os_strcmp(buf + 11, "SHOW") == 0) {
13833 reply_len = ap_ctrl_iface_acl_show_mac(
13834 wpa_s, DENY_UNLESS_ACCEPTED,
13835 reply, reply_size);
13836 } else if (os_strcmp(buf + 11, "CLEAR") == 0) {
13837 ap_ctrl_iface_acl_clear_list(wpa_s,
13838 DENY_UNLESS_ACCEPTED);
13839 if (ap_ctrl_iface_set_acl(wpa_s) ||
13840 ap_ctrl_iface_disassoc_accept_mac(wpa_s))
13841 reply_len = -1;
13842 } else {
13843 reply_len = -1;
13844 }
13845 } else if (os_strncmp(buf, "DENY_ACL ", 9) == 0) {
13846 if (os_strncmp(buf + 9, "ADD_MAC ", 8) == 0) {
13847 if (ap_ctrl_iface_acl_add_mac(wpa_s,
13848 ACCEPT_UNLESS_DENIED,
13849 buf + 17) ||
13850 ap_ctrl_iface_set_acl(wpa_s) ||
13851 ap_ctrl_iface_disassoc_deny_mac(wpa_s))
13852 reply_len = -1;
13853 } else if (os_strncmp(buf + 9, "DEL_MAC ", 8) == 0) {
13854 if (ap_ctrl_iface_acl_del_mac(wpa_s,
13855 ACCEPT_UNLESS_DENIED,
13856 buf + 17) ||
13857 ap_ctrl_iface_set_acl(wpa_s))
13858 reply_len = -1;
13859 } else if (os_strcmp(buf + 9, "SHOW") == 0) {
13860 reply_len = ap_ctrl_iface_acl_show_mac(
13861 wpa_s, ACCEPT_UNLESS_DENIED, reply, reply_size);
13862 } else if (os_strcmp(buf + 9, "CLEAR") == 0) {
13863 ap_ctrl_iface_acl_clear_list(wpa_s,
13864 ACCEPT_UNLESS_DENIED);
13865 if (ap_ctrl_iface_set_acl(wpa_s))
13866 reply_len = -1;
13867 } else {
13868 reply_len = -1;
13869 }
13870 #endif /* CONFIG_AP */
13871 } else if (os_strcmp(buf, "SUSPEND") == 0) {
13872 wpas_notify_suspend(wpa_s->global);
13873 } else if (os_strcmp(buf, "RESUME") == 0) {
13874 wpas_notify_resume(wpa_s->global);
13875 #ifdef CONFIG_TESTING_OPTIONS
13876 } else if (os_strcmp(buf, "DROP_SA") == 0) {
13877 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
13878 #endif /* CONFIG_TESTING_OPTIONS */
13879 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
13880 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
13881 reply_len = -1;
13882 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
13883 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
13884 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
13885 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
13886 reply_len = -1;
13887 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
13888 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
13889 buf + 17))
13890 reply_len = -1;
13891 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
13892 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
13893 #ifdef CONFIG_TDLS
13894 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
13895 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
13896 reply_len = -1;
13897 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
13898 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
13899 reply_len = -1;
13900 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
13901 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
13902 reply_len = -1;
13903 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
13904 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
13905 buf + 17))
13906 reply_len = -1;
13907 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
13908 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
13909 buf + 24))
13910 reply_len = -1;
13911 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
13912 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
13913 wpa_s, buf + 17, reply, reply_size);
13914 #endif /* CONFIG_TDLS */
13915 #ifndef CONFIG_NO_WMM_AC
13916 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
13917 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
13918 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
13919 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
13920 reply_len = -1;
13921 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
13922 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
13923 reply_len = -1;
13924 #endif /* CONFIG_NO_WMM_AC */
13925 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
13926 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
13927 reply_size);
13928 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
13929 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
13930 reply_len = -1;
13931 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
13932 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
13933 reply_size);
13934 #ifdef CONFIG_AUTOSCAN
13935 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
13936 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
13937 reply_len = -1;
13938 #endif /* CONFIG_AUTOSCAN */
13939 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
13940 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
13941 reply_size);
13942 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
13943 reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply,
13944 reply_size);
13945 #if defined(ANDROID) || defined(CONFIG_DRIVER_NL80211_HISI)
13946 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
13947 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
13948 reply_size);
13949 #endif /* ANDROID */
13950 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
13951 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
13952 reply_size);
13953 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
13954 pmksa_cache_clear_current(wpa_s->wpa);
13955 eapol_sm_request_reauth(wpa_s->eapol);
13956 #ifdef CONFIG_WNM
13957 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
13958 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
13959 reply_len = -1;
13960 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
13961 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
13962 reply_len = -1;
13963 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
13964 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
13965 reply_len = -1;
13966 #endif /* CONFIG_WNM */
13967 #ifdef CONFIG_WNM_AP
13968 } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
13969 if (ap_ctrl_iface_disassoc_imminent(wpa_s, buf + 18))
13970 reply_len = -1;
13971 } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
13972 if (ap_ctrl_iface_ess_disassoc(wpa_s, buf + 13))
13973 reply_len = -1;
13974 } else if (os_strncmp(buf, "BSS_TM_REQ ", 11) == 0) {
13975 if (ap_ctrl_iface_bss_tm_req(wpa_s, buf + 11))
13976 reply_len = -1;
13977 #endif /* CONFIG_WNM_AP */
13978 } else if (os_strcmp(buf, "FLUSH") == 0) {
13979 wpa_supplicant_ctrl_iface_flush(wpa_s);
13980 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
13981 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
13982 reply_size);
13983 #ifdef CONFIG_TESTING_OPTIONS
13984 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
13985 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
13986 reply_len = -1;
13987 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
13988 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
13989 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
13990 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
13991 reply_len = -1;
13992 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
13993 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
13994 reply_len = -1;
13995 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
13996 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
13997 reply_len = -1;
13998 } else if (os_strncmp(buf, "EAPOL_TX ", 9) == 0) {
13999 if (wpas_ctrl_iface_eapol_tx(wpa_s, buf + 9) < 0)
14000 reply_len = -1;
14001 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
14002 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
14003 reply_len = -1;
14004 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
14005 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
14006 reply_len = -1;
14007 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
14008 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
14009 reply_len = -1;
14010 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
14011 if (testing_set_fail_pattern(true, buf + 16) < 0)
14012 reply_len = -1;
14013 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
14014 reply_len = testing_get_fail_pattern(true, reply, reply_size);
14015 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
14016 if (testing_set_fail_pattern(false, buf + 10) < 0)
14017 reply_len = -1;
14018 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
14019 reply_len = testing_get_fail_pattern(false, reply, reply_size);
14020 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
14021 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
14022 reply_len = -1;
14023 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
14024 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
14025 reply_len = -1;
14026 } else if (os_strncmp(buf, "TEST_EAPOL_M2_ELEMS ", 20) == 0) {
14027 if (wpas_ctrl_test_eapol_m2_elems(wpa_s, buf + 20) < 0)
14028 reply_len = -1;
14029 } else if (os_strncmp(buf, "TEST_EAPOL_M4_ELEMS ", 20) == 0) {
14030 if (wpas_ctrl_test_eapol_m4_elems(wpa_s, buf + 20) < 0)
14031 reply_len = -1;
14032 } else if (os_strcmp(buf, "RESET_PN") == 0) {
14033 if (wpas_ctrl_reset_pn(wpa_s) < 0)
14034 reply_len = -1;
14035 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
14036 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
14037 reply_len = -1;
14038 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
14039 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
14040 reply_len = -1;
14041 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
14042 sme_event_unprot_disconnect(
14043 wpa_s, wpa_s->bssid, NULL,
14044 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
14045 } else if (os_strncmp(buf, "TWT_SETUP ", 10) == 0) {
14046 if (wpas_ctrl_iface_send_twt_setup(wpa_s, buf + 9))
14047 reply_len = -1;
14048 } else if (os_strcmp(buf, "TWT_SETUP") == 0) {
14049 if (wpas_ctrl_iface_send_twt_setup(wpa_s, ""))
14050 reply_len = -1;
14051 } else if (os_strncmp(buf, "TWT_TEARDOWN ", 13) == 0) {
14052 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, buf + 12))
14053 reply_len = -1;
14054 } else if (os_strcmp(buf, "TWT_TEARDOWN") == 0) {
14055 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, ""))
14056 reply_len = -1;
14057 } else if (os_strncmp(buf, "ML_PROBE_REQ ", 13) == 0) {
14058 if (wpas_ctrl_ml_probe(wpa_s, buf + 13))
14059 reply_len = -1;
14060 #endif /* CONFIG_TESTING_OPTIONS */
14061 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
14062 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
14063 reply_len = -1;
14064 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
14065 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
14066 reply_size);
14067 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
14068 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
14069 reply_len = -1;
14070 #ifndef CONFIG_NO_RRM
14071 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
14072 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
14073 reply_len = -1;
14074 #endif /* CONFIG_NO_RRM */
14075 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
14076 wpas_ctrl_iface_erp_flush(wpa_s);
14077 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
14078 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
14079 reply_len = -1;
14080 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
14081 reply_len = wpas_ctrl_iface_get_pref_freq_list(
14082 wpa_s, buf + 19, reply, reply_size);
14083 #ifdef CONFIG_FILS
14084 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
14085 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
14086 reply_len = -1;
14087 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
14088 wpas_flush_fils_hlp_req(wpa_s);
14089 #endif /* CONFIG_FILS */
14090 #ifdef CONFIG_DPP
14091 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
14092 int res;
14093
14094 res = wpas_dpp_qr_code(wpa_s, buf + 12);
14095 if (res < 0) {
14096 reply_len = -1;
14097 } else {
14098 reply_len = os_snprintf(reply, reply_size, "%d", res);
14099 if (os_snprintf_error(reply_size, reply_len))
14100 reply_len = -1;
14101 }
14102 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
14103 int res;
14104
14105 res = wpas_dpp_nfc_uri(wpa_s, buf + 12);
14106 if (res < 0) {
14107 reply_len = -1;
14108 } else {
14109 reply_len = os_snprintf(reply, reply_size, "%d", res);
14110 if (os_snprintf_error(reply_size, reply_len))
14111 reply_len = -1;
14112 }
14113 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
14114 int res;
14115
14116 res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20);
14117 if (res < 0) {
14118 reply_len = -1;
14119 } else {
14120 reply_len = os_snprintf(reply, reply_size, "%d", res);
14121 if (os_snprintf_error(reply_size, reply_len))
14122 reply_len = -1;
14123 }
14124 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
14125 int res;
14126
14127 res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20);
14128 if (res < 0) {
14129 reply_len = -1;
14130 } else {
14131 reply_len = os_snprintf(reply, reply_size, "%d", res);
14132 if (os_snprintf_error(reply_size, reply_len))
14133 reply_len = -1;
14134 }
14135 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
14136 int res;
14137
14138 res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18);
14139 if (res < 0) {
14140 reply_len = -1;
14141 } else {
14142 reply_len = os_snprintf(reply, reply_size, "%d", res);
14143 if (os_snprintf_error(reply_size, reply_len))
14144 reply_len = -1;
14145 }
14146 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
14147 if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0)
14148 reply_len = -1;
14149 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
14150 const char *uri;
14151
14152 uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22));
14153 if (!uri) {
14154 reply_len = -1;
14155 } else {
14156 reply_len = os_snprintf(reply, reply_size, "%s", uri);
14157 if (os_snprintf_error(reply_size, reply_len))
14158 reply_len = -1;
14159 }
14160 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
14161 reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19),
14162 reply, reply_size);
14163 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
14164 if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18),
14165 os_strchr(buf + 18, ' ')) < 0)
14166 reply_len = -1;
14167 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
14168 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
14169 reply_len = -1;
14170 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
14171 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
14172 reply_len = -1;
14173 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
14174 wpas_dpp_stop(wpa_s);
14175 wpas_dpp_listen_stop(wpa_s);
14176 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
14177 int res;
14178
14179 res = dpp_configurator_add(wpa_s->dpp, buf + 20);
14180 if (res < 0) {
14181 reply_len = -1;
14182 } else {
14183 reply_len = os_snprintf(reply, reply_size, "%d", res);
14184 if (os_snprintf_error(reply_size, reply_len))
14185 reply_len = -1;
14186 }
14187 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SET ", 21) == 0) {
14188 if (dpp_configurator_set(wpa_s->dpp, buf + 20) < 0)
14189 reply_len = -1;
14190 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
14191 if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0)
14192 reply_len = -1;
14193 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
14194 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
14195 reply_len = -1;
14196 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
14197 reply_len = dpp_configurator_get_key_id(wpa_s->dpp,
14198 atoi(buf + 25),
14199 reply, reply_size);
14200 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
14201 int res;
14202
14203 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
14204 if (res < 0) {
14205 reply_len = -1;
14206 } else {
14207 reply_len = os_snprintf(reply, reply_size, "%d", res);
14208 if (os_snprintf_error(reply_size, reply_len))
14209 reply_len = -1;
14210 }
14211 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
14212 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
14213 reply_len = -1;
14214 } else if (os_strncmp(buf, "DPP_CONF_SET ", 13) == 0) {
14215 if (wpas_dpp_conf_set(wpa_s, buf + 12) < 0)
14216 reply_len = -1;
14217 #ifdef CONFIG_DPP2
14218 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
14219 if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0)
14220 reply_len = -1;
14221 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
14222 if (wpas_dpp_controller_start(wpa_s, NULL) < 0)
14223 reply_len = -1;
14224 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
14225 dpp_controller_stop(wpa_s->dpp);
14226 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
14227 if (wpas_dpp_chirp(wpa_s, buf + 9) < 0)
14228 reply_len = -1;
14229 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
14230 wpas_dpp_chirp_stop(wpa_s);
14231 } else if (os_strncmp(buf, "DPP_RECONFIG ", 13) == 0) {
14232 if (wpas_dpp_reconfig(wpa_s, buf + 13) < 0)
14233 reply_len = -1;
14234 } else if (os_strncmp(buf, "DPP_CA_SET ", 11) == 0) {
14235 if (wpas_dpp_ca_set(wpa_s, buf + 10) < 0)
14236 reply_len = -1;
14237 #endif /* CONFIG_DPP2 */
14238 #ifdef CONFIG_DPP3
14239 } else if (os_strcmp(buf, "DPP_PUSH_BUTTON") == 0) {
14240 if (wpas_dpp_push_button(wpa_s, NULL) < 0)
14241 reply_len = -1;
14242 } else if (os_strncmp(buf, "DPP_PUSH_BUTTON ", 16) == 0) {
14243 if (wpas_dpp_push_button(wpa_s, buf + 15) < 0)
14244 reply_len = -1;
14245 #endif /* CONFIG_DPP3 */
14246 #endif /* CONFIG_DPP */
14247 #ifdef CONFIG_NAN_USD
14248 } else if (os_strncmp(buf, "NAN_PUBLISH ", 12) == 0) {
14249 reply_len = wpas_ctrl_nan_publish(wpa_s, buf + 12, reply,
14250 reply_size);
14251 } else if (os_strncmp(buf, "NAN_CANCEL_PUBLISH ", 19) == 0) {
14252 if (wpas_ctrl_nan_cancel_publish(wpa_s, buf + 19) < 0)
14253 reply_len = -1;
14254 } else if (os_strncmp(buf, "NAN_UPDATE_PUBLISH ", 19) == 0) {
14255 if (wpas_ctrl_nan_update_publish(wpa_s, buf + 19) < 0)
14256 reply_len = -1;
14257 } else if (os_strncmp(buf, "NAN_SUBSCRIBE ", 14) == 0) {
14258 reply_len = wpas_ctrl_nan_subscribe(wpa_s, buf + 14, reply,
14259 reply_size);
14260 } else if (os_strncmp(buf, "NAN_CANCEL_SUBSCRIBE ", 21) == 0) {
14261 if (wpas_ctrl_nan_cancel_subscribe(wpa_s, buf + 21) < 0)
14262 reply_len = -1;
14263 } else if (os_strncmp(buf, "NAN_TRANSMIT ", 13) == 0) {
14264 if (wpas_ctrl_nan_transmit(wpa_s, buf + 13) < 0)
14265 reply_len = -1;
14266 #endif /* CONFIG_NAN_USD */
14267 #ifdef CONFIG_PASN
14268 } else if (os_strncmp(buf, "PASN_START ", 11) == 0) {
14269 if (wpas_ctrl_iface_pasn_start(wpa_s, buf + 11) < 0)
14270 reply_len = -1;
14271 } else if (os_strcmp(buf, "PASN_STOP") == 0) {
14272 wpas_pasn_auth_stop(wpa_s);
14273 } else if (os_strcmp(buf, "PTKSA_CACHE_LIST") == 0) {
14274 reply_len = ptksa_cache_list(wpa_s->ptksa, reply, reply_size);
14275 } else if (os_strncmp(buf, "PASN_DEAUTH ", 12) == 0) {
14276 if (wpas_ctrl_iface_pasn_deauthenticate(wpa_s, buf + 12) < 0)
14277 reply_len = -1;
14278 #ifdef CONFIG_TESTING_OPTIONS
14279 } else if (os_strncmp(buf, "PASN_DRIVER ", 12) == 0) {
14280 if (wpas_ctrl_iface_pasn_driver(wpa_s, buf + 12) < 0)
14281 reply_len = -1;
14282 #endif /* CONFIG_TESTING_OPTIONS */
14283 #endif /* CONFIG_PASN */
14284 #ifndef CONFIG_NO_ROBUST_AV
14285 } else if (os_strncmp(buf, "MSCS ", 5) == 0) {
14286 if (wpas_ctrl_iface_configure_mscs(wpa_s, buf + 5))
14287 reply_len = -1;
14288 } else if (os_strncmp(buf, "SCS ", 4) == 0) {
14289 if (wpas_ctrl_iface_configure_scs(wpa_s, buf + 4))
14290 reply_len = -1;
14291 } else if (os_strncmp(buf, "DSCP_RESP ", 10) == 0) {
14292 if (wpas_ctrl_iface_send_dscp_resp(wpa_s, buf + 10))
14293 reply_len = -1;
14294 } else if (os_strncmp(buf, "DSCP_QUERY ", 11) == 0) {
14295 if (wpas_ctrl_iface_send_dscp_query(wpa_s, buf + 11))
14296 reply_len = -1;
14297 #endif /* CONFIG_NO_ROBUST_AV */
14298 #ifdef CONFIG_MLD_PATCH
14299 } else if (os_strcmp(buf, "MLO_STATUS") == 0) {
14300 reply_len = wpas_ctrl_iface_mlo_status(wpa_s, reply,
14301 reply_size);
14302 } else if (os_strcmp(buf, "MLO_SIGNAL_POLL") == 0) {
14303 reply_len = wpas_ctrl_iface_mlo_signal_poll(wpa_s, reply,
14304 reply_size);
14305 #endif
14306 } else {
14307 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
14308 reply_len = 16;
14309 }
14310
14311 if (reply_len < 0) {
14312 os_memcpy(reply, "FAIL\n", 5);
14313 reply_len = 5;
14314 }
14315
14316 *resp_len = reply_len;
14317 return reply;
14318 }
14319
14320
14321 int wpa_supplicant_global_iface_add(struct wpa_global *global,
14322 char *cmd)
14323 {
14324 struct wpa_interface iface;
14325 char *pos, *extra;
14326 struct wpa_supplicant *wpa_s;
14327 unsigned int create_iface = 0;
14328 u8 mac_addr[ETH_ALEN];
14329 enum wpa_driver_if_type type = WPA_IF_STATION;
14330
14331 /*
14332 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
14333 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
14334 */
14335 wpa_printf(MSG_INFO, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
14336
14337 os_memset(&iface, 0, sizeof(iface));
14338
14339 do {
14340 iface.ifname = pos = cmd;
14341 pos = os_strchr(pos, '\t');
14342 if (pos)
14343 *pos++ = '\0';
14344 if (iface.ifname[0] == '\0')
14345 return -1;
14346 if (pos == NULL)
14347 break;
14348
14349 iface.confname = pos;
14350 pos = os_strchr(pos, '\t');
14351 if (pos)
14352 *pos++ = '\0';
14353 if (iface.confname[0] == '\0')
14354 iface.confname = NULL;
14355 if (pos == NULL)
14356 break;
14357
14358 iface.driver = pos;
14359 pos = os_strchr(pos, '\t');
14360 if (pos)
14361 *pos++ = '\0';
14362 if (iface.driver[0] == '\0')
14363 iface.driver = NULL;
14364 if (pos == NULL)
14365 break;
14366
14367 iface.ctrl_interface = pos;
14368 pos = os_strchr(pos, '\t');
14369 if (pos)
14370 *pos++ = '\0';
14371 if (iface.ctrl_interface[0] == '\0')
14372 iface.ctrl_interface = NULL;
14373 if (pos == NULL)
14374 break;
14375
14376 iface.driver_param = pos;
14377 pos = os_strchr(pos, '\t');
14378 if (pos)
14379 *pos++ = '\0';
14380 if (iface.driver_param[0] == '\0')
14381 iface.driver_param = NULL;
14382 if (pos == NULL)
14383 break;
14384
14385 iface.bridge_ifname = pos;
14386 pos = os_strchr(pos, '\t');
14387 if (pos)
14388 *pos++ = '\0';
14389 if (iface.bridge_ifname[0] == '\0')
14390 iface.bridge_ifname = NULL;
14391 if (pos == NULL)
14392 break;
14393
14394 extra = pos;
14395 pos = os_strchr(pos, '\t');
14396 if (pos)
14397 *pos++ = '\0';
14398 if (!extra[0])
14399 break;
14400
14401 if (os_strcmp(extra, "create") == 0) {
14402 create_iface = 1;
14403 if (!pos)
14404 break;
14405
14406 if (os_strcmp(pos, "sta") == 0) {
14407 type = WPA_IF_STATION;
14408 } else if (os_strcmp(pos, "ap") == 0) {
14409 type = WPA_IF_AP_BSS;
14410 } else {
14411 wpa_printf(MSG_DEBUG,
14412 "INTERFACE_ADD unsupported interface type: '%s'",
14413 pos);
14414 return -1;
14415 }
14416 } else {
14417 wpa_printf(MSG_DEBUG,
14418 "INTERFACE_ADD unsupported extra parameter: '%s'",
14419 extra);
14420 return -1;
14421 }
14422 } while (0);
14423
14424 if (create_iface) {
14425 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
14426 iface.ifname);
14427 if (!global->ifaces)
14428 return -1;
14429 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
14430 NULL, NULL, NULL, mac_addr, NULL) < 0) {
14431 wpa_printf(MSG_ERROR,
14432 "CTRL_IFACE interface creation failed");
14433 return -1;
14434 }
14435
14436 wpa_printf(MSG_DEBUG,
14437 "CTRL_IFACE interface '%s' created with MAC addr: "
14438 MACSTR_SEC, iface.ifname, MAC2STR_SEC(mac_addr));
14439 }
14440
14441 if (wpa_supplicant_get_iface(global, iface.ifname))
14442 goto fail;
14443
14444 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
14445 if (!wpa_s)
14446 goto fail;
14447 wpa_s->added_vif = create_iface;
14448 return 0;
14449
14450 fail:
14451 if (create_iface) {
14452 /* wpa_supplicant does not create multi-BSS AP, so collapse to
14453 * WPA_IF_STATION to avoid unwanted clean up in the driver. */
14454 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
14455 }
14456 return -1;
14457 }
14458
14459
14460 int wpa_supplicant_global_iface_remove(struct wpa_global *global,
14461 char *cmd)
14462 {
14463 struct wpa_supplicant *wpa_s;
14464 int ret;
14465 unsigned int delete_iface;
14466
14467 wpa_printf(MSG_INFO, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
14468
14469 wpa_s = wpa_supplicant_get_iface(global, cmd);
14470 if (wpa_s == NULL)
14471 return -1;
14472 delete_iface = wpa_s->added_vif;
14473 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
14474 if (!ret && delete_iface) {
14475 wpa_printf(MSG_INFO, "CTRL_IFACE deleting the interface '%s'",
14476 cmd);
14477 /* wpa_supplicant does not create multi-BSS AP, so collapse to
14478 * WPA_IF_STATION to avoid unwanted clean up in the driver. */
14479 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
14480 }
14481 return ret;
14482 }
14483
14484
14485 static void wpa_free_iface_info(struct wpa_interface_info *iface)
14486 {
14487 struct wpa_interface_info *prev;
14488
14489 while (iface) {
14490 prev = iface;
14491 iface = iface->next;
14492
14493 os_free(prev->ifname);
14494 os_free(prev->desc);
14495 os_free(prev);
14496 }
14497 }
14498
14499
14500 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
14501 char *buf, int len)
14502 {
14503 int i, res;
14504 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
14505 char *pos, *end;
14506
14507 for (i = 0; wpa_drivers[i]; i++) {
14508 const struct wpa_driver_ops *drv = wpa_drivers[i];
14509 if (drv->get_interfaces == NULL)
14510 continue;
14511 tmp = drv->get_interfaces(global->drv_priv[i]);
14512 if (tmp == NULL)
14513 continue;
14514
14515 if (last == NULL)
14516 iface = last = tmp;
14517 else
14518 last->next = tmp;
14519 while (last->next)
14520 last = last->next;
14521 }
14522
14523 pos = buf;
14524 end = buf + len;
14525 for (tmp = iface; tmp; tmp = tmp->next) {
14526 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
14527 tmp->drv_name, tmp->ifname,
14528 tmp->desc ? tmp->desc : "");
14529 if (os_snprintf_error(end - pos, res)) {
14530 *pos = '\0';
14531 break;
14532 }
14533 pos += res;
14534 }
14535
14536 wpa_free_iface_info(iface);
14537
14538 return pos - buf;
14539 }
14540
14541
14542 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
14543 const char *input,
14544 char *buf, int len)
14545 {
14546 int res;
14547 char *pos, *end;
14548 struct wpa_supplicant *wpa_s;
14549 int show_ctrl = 0;
14550
14551 if (input)
14552 show_ctrl = !!os_strstr(input, "ctrl");
14553
14554 wpa_s = global->ifaces;
14555 pos = buf;
14556 end = buf + len;
14557
14558 while (wpa_s) {
14559 if (show_ctrl)
14560 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
14561 wpa_s->ifname,
14562 wpa_s->conf->ctrl_interface ?
14563 wpa_s->conf->ctrl_interface : "N/A");
14564 else
14565 res = os_snprintf(pos, end - pos, "%s\n",
14566 wpa_s->ifname);
14567
14568 if (os_snprintf_error(end - pos, res)) {
14569 *pos = '\0';
14570 break;
14571 }
14572 pos += res;
14573 wpa_s = wpa_s->next;
14574 }
14575 return pos - buf;
14576 }
14577
14578
14579 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
14580 const char *ifname,
14581 char *cmd, size_t *resp_len)
14582 {
14583 struct wpa_supplicant *wpa_s;
14584
14585 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
14586 if (os_strcmp(ifname, wpa_s->ifname) == 0)
14587 break;
14588 }
14589
14590 if (wpa_s == NULL) {
14591 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
14592 if (resp)
14593 *resp_len = os_strlen(resp);
14594 else
14595 *resp_len = 1;
14596 return resp;
14597 }
14598
14599 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
14600 }
14601
14602
14603 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
14604 char *buf, size_t *resp_len)
14605 {
14606 #ifdef CONFIG_P2P
14607 static const char * cmd[] = {
14608 "LIST_NETWORKS",
14609 "P2P_FIND",
14610 "P2P_STOP_FIND",
14611 "P2P_LISTEN",
14612 "P2P_GROUP_ADD",
14613 "P2P_GET_PASSPHRASE",
14614 "P2P_SERVICE_UPDATE",
14615 "P2P_SERVICE_FLUSH",
14616 "P2P_FLUSH",
14617 "P2P_CANCEL",
14618 "P2P_PRESENCE_REQ",
14619 "P2P_EXT_LISTEN",
14620 #ifdef CONFIG_AP
14621 "STA-FIRST",
14622 #endif /* CONFIG_AP */
14623 NULL
14624 };
14625 static const char * prefix[] = {
14626 #ifdef ANDROID
14627 "DRIVER ",
14628 #endif /* ANDROID */
14629 "GET_CAPABILITY ",
14630 "GET_NETWORK ",
14631 "REMOVE_NETWORK ",
14632 "P2P_FIND ",
14633 "P2P_CONNECT ",
14634 "P2P_LISTEN ",
14635 "P2P_GROUP_REMOVE ",
14636 "P2P_GROUP_ADD ",
14637 "P2P_GROUP_MEMBER ",
14638 "P2P_PROV_DISC ",
14639 "P2P_SERV_DISC_REQ ",
14640 "P2P_SERV_DISC_CANCEL_REQ ",
14641 "P2P_SERV_DISC_RESP ",
14642 "P2P_SERV_DISC_EXTERNAL ",
14643 "P2P_SERVICE_ADD ",
14644 "P2P_SERVICE_DEL ",
14645 "P2P_SERVICE_REP ",
14646 "P2P_REJECT ",
14647 "P2P_INVITE ",
14648 "P2P_PEER ",
14649 "P2P_SET ",
14650 "P2P_UNAUTHORIZE ",
14651 "P2P_PRESENCE_REQ ",
14652 "P2P_EXT_LISTEN ",
14653 "P2P_REMOVE_CLIENT ",
14654 "WPS_NFC_TOKEN ",
14655 "WPS_NFC_TAG_READ ",
14656 "NFC_GET_HANDOVER_SEL ",
14657 "NFC_GET_HANDOVER_REQ ",
14658 "NFC_REPORT_HANDOVER ",
14659 "P2P_ASP_PROVISION ",
14660 "P2P_ASP_PROVISION_RESP ",
14661 #ifdef CONFIG_AP
14662 "STA ",
14663 "STA-NEXT ",
14664 #endif /* CONFIG_AP */
14665 #ifdef CONFIG_MAGICLINK
14666 "MAGICLINK ",
14667 #endif /* CONFIG_MAGICLINK */
14668 NULL
14669 };
14670 int found = 0;
14671 int i;
14672
14673 if (global->p2p_init_wpa_s == NULL)
14674 return NULL;
14675
14676 for (i = 0; !found && cmd[i]; i++) {
14677 if (os_strcmp(buf, cmd[i]) == 0)
14678 found = 1;
14679 }
14680
14681 for (i = 0; !found && prefix[i]; i++) {
14682 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
14683 found = 1;
14684 }
14685
14686 if (found)
14687 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
14688 buf, resp_len);
14689 #endif /* CONFIG_P2P */
14690 return NULL;
14691 }
14692
14693
14694 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
14695 char *buf, size_t *resp_len)
14696 {
14697 #ifdef CONFIG_WIFI_DISPLAY
14698 if (global->p2p_init_wpa_s == NULL)
14699 return NULL;
14700 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
14701 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
14702 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
14703 buf, resp_len);
14704 #endif /* CONFIG_WIFI_DISPLAY */
14705 return NULL;
14706 }
14707
14708
14709 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
14710 char *buf, size_t *resp_len)
14711 {
14712 char *ret;
14713
14714 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
14715 if (ret)
14716 return ret;
14717
14718 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
14719 if (ret)
14720 return ret;
14721
14722 return NULL;
14723 }
14724
14725
14726 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
14727 {
14728 char *value;
14729
14730 value = os_strchr(cmd, ' ');
14731 if (value == NULL)
14732 return -1;
14733 *value++ = '\0';
14734
14735 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
14736
14737 #ifdef CONFIG_WIFI_DISPLAY
14738 if (os_strcasecmp(cmd, "wifi_display") == 0) {
14739 wifi_display_enable(global, !!atoi(value));
14740 return 0;
14741 }
14742 #endif /* CONFIG_WIFI_DISPLAY */
14743
14744 /* Restore cmd to its original value to allow redirection */
14745 value[-1] = ' ';
14746
14747 return -1;
14748 }
14749
14750
14751 static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
14752 char *cmd)
14753 {
14754 struct wpa_supplicant *wpa_s[2]; /* src, dst */
14755 char *p;
14756 unsigned int i;
14757
14758 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
14759 * <variable name> */
14760
14761 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
14762 p = os_strchr(cmd, ' ');
14763 if (p == NULL)
14764 return -1;
14765 *p = '\0';
14766
14767 wpa_s[i] = global->ifaces;
14768 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
14769 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
14770 break;
14771 }
14772
14773 if (!wpa_s[i]) {
14774 wpa_printf(MSG_DEBUG,
14775 "CTRL_IFACE: Could not find iface=%s", cmd);
14776 return -1;
14777 }
14778
14779 cmd = p + 1;
14780 }
14781
14782 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
14783 }
14784
14785
14786 #ifndef CONFIG_NO_CONFIG_WRITE
14787 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
14788 {
14789 int ret = 0, saved = 0;
14790 struct wpa_supplicant *wpa_s;
14791
14792 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
14793 if (!wpa_s->conf->update_config) {
14794 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
14795 continue;
14796 }
14797
14798 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
14799 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
14800 ret = 1;
14801 } else {
14802 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
14803 saved++;
14804 }
14805 }
14806
14807 if (!saved && !ret) {
14808 wpa_dbg(wpa_s, MSG_DEBUG,
14809 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
14810 ret = 1;
14811 }
14812
14813 return ret;
14814 }
14815 #endif /* CONFIG_NO_CONFIG_WRITE */
14816
14817
14818 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
14819 char *buf, size_t buflen)
14820 {
14821 char *pos, *end;
14822 int ret;
14823 struct wpa_supplicant *wpa_s;
14824
14825 pos = buf;
14826 end = buf + buflen;
14827
14828 #ifdef CONFIG_P2P
14829 if (global->p2p && !global->p2p_disabled) {
14830 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
14831 "\n"
14832 "p2p_state=%s\n",
14833 MAC2STR(global->p2p_dev_addr),
14834 p2p_get_state_txt(global->p2p));
14835 if (os_snprintf_error(end - pos, ret))
14836 return pos - buf;
14837 pos += ret;
14838 } else if (global->p2p) {
14839 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
14840 if (os_snprintf_error(end - pos, ret))
14841 return pos - buf;
14842 pos += ret;
14843 }
14844 #endif /* CONFIG_P2P */
14845
14846 #ifdef CONFIG_WIFI_DISPLAY
14847 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
14848 !!global->wifi_display);
14849 if (os_snprintf_error(end - pos, ret))
14850 return pos - buf;
14851 pos += ret;
14852 #endif /* CONFIG_WIFI_DISPLAY */
14853
14854 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
14855 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
14856 "address=" MACSTR "\n",
14857 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
14858 if (os_snprintf_error(end - pos, ret))
14859 return pos - buf;
14860 pos += ret;
14861 }
14862
14863 return pos - buf;
14864 }
14865
14866
14867 #ifdef CONFIG_FST
14868
14869 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
14870 char *cmd, char *buf,
14871 size_t reply_size)
14872 {
14873 char ifname[IFNAMSIZ + 1];
14874 struct fst_iface_cfg cfg;
14875 struct wpa_supplicant *wpa_s;
14876 struct fst_wpa_obj iface_obj;
14877
14878 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
14879 wpa_s = wpa_supplicant_get_iface(global, ifname);
14880 if (wpa_s) {
14881 if (wpa_s->fst) {
14882 wpa_printf(MSG_INFO, "FST: Already attached");
14883 return -1;
14884 }
14885 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
14886 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
14887 &iface_obj, &cfg);
14888 if (wpa_s->fst)
14889 return os_snprintf(buf, reply_size, "OK\n");
14890 }
14891 }
14892
14893 return -1;
14894 }
14895
14896
14897 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
14898 char *cmd, char *buf,
14899 size_t reply_size)
14900 {
14901 char ifname[IFNAMSIZ + 1];
14902 struct wpa_supplicant *wpa_s;
14903
14904 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
14905 wpa_s = wpa_supplicant_get_iface(global, ifname);
14906 if (wpa_s) {
14907 if (!fst_iface_detach(ifname)) {
14908 wpa_s->fst = NULL;
14909 return os_snprintf(buf, reply_size, "OK\n");
14910 }
14911 }
14912 }
14913
14914 return -1;
14915 }
14916
14917 #endif /* CONFIG_FST */
14918
14919 #ifdef CONFIG_MAGICLINK
14920 int hw_magiclink_ctrl_iface_update_network(
14921 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
14922 char *name, char *value)
14923 {
14924 return wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name, value);
14925 }
14926 #endif /* CONFIG_MAGICLINK */
14927
14928 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
14929 char *buf, size_t *resp_len)
14930 {
14931 char *reply;
14932 const int reply_size = 2048;
14933 int reply_len;
14934 int level = MSG_EXCESSIVE;
14935
14936 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
14937 char *pos = os_strchr(buf + 7, ' ');
14938 if (pos) {
14939 *pos++ = '\0';
14940 return wpas_global_ctrl_iface_ifname(global,
14941 buf + 7, pos,
14942 resp_len);
14943 }
14944 }
14945
14946 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
14947 if (reply)
14948 return reply;
14949
14950 if (os_strcmp(buf, "PING") == 0)
14951 level = MSG_EXCESSIVE;
14952 wpa_hexdump_ascii(level, "RX global ctrl_iface",
14953 (const u8 *) buf, os_strlen(buf));
14954
14955 reply = os_malloc(reply_size);
14956 if (reply == NULL) {
14957 *resp_len = 1;
14958 return NULL;
14959 }
14960
14961 os_memcpy(reply, "OK\n", 3);
14962 reply_len = 3;
14963
14964 if (os_strcmp(buf, "PING") == 0) {
14965 os_memcpy(reply, "PONG\n", 5);
14966 reply_len = 5;
14967 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
14968 if (wpa_supplicant_global_iface_add(global, buf + 14))
14969 reply_len = -1;
14970 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
14971 if (wpa_supplicant_global_iface_remove(global, buf + 17))
14972 reply_len = -1;
14973 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
14974 reply_len = wpa_supplicant_global_iface_list(
14975 global, reply, reply_size);
14976 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
14977 reply_len = wpa_supplicant_global_iface_interfaces(
14978 global, buf + 10, reply, reply_size);
14979 #ifdef CONFIG_FST
14980 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
14981 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
14982 reply,
14983 reply_size);
14984 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
14985 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
14986 reply,
14987 reply_size);
14988 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
14989 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
14990 #endif /* CONFIG_FST */
14991 } else if (os_strcmp(buf, "TERMINATE") == 0) {
14992 wpa_supplicant_terminate_proc(global);
14993 } else if (os_strcmp(buf, "SUSPEND") == 0) {
14994 wpas_notify_suspend(global);
14995 } else if (os_strcmp(buf, "RESUME") == 0) {
14996 wpas_notify_resume(global);
14997 } else if (os_strncmp(buf, "SET ", 4) == 0) {
14998 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
14999 #ifdef CONFIG_P2P
15000 if (global->p2p_init_wpa_s) {
15001 os_free(reply);
15002 /* Check if P2P redirection would work for this
15003 * command. */
15004 return wpa_supplicant_ctrl_iface_process(
15005 global->p2p_init_wpa_s,
15006 buf, resp_len);
15007 }
15008 #endif /* CONFIG_P2P */
15009 reply_len = -1;
15010 }
15011 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
15012 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
15013 reply_len = -1;
15014 #ifndef CONFIG_NO_CONFIG_WRITE
15015 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
15016 if (wpas_global_ctrl_iface_save_config(global))
15017 reply_len = -1;
15018 #endif /* CONFIG_NO_CONFIG_WRITE */
15019 } else if (os_strcmp(buf, "STATUS") == 0) {
15020 reply_len = wpas_global_ctrl_iface_status(global, reply,
15021 reply_size);
15022 #ifdef CONFIG_MODULE_TESTS
15023 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
15024 if (wpas_module_tests() < 0)
15025 reply_len = -1;
15026 #endif /* CONFIG_MODULE_TESTS */
15027 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
15028 if (wpa_debug_reopen_file() < 0)
15029 reply_len = -1;
15030 } else {
15031 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
15032 reply_len = 16;
15033 }
15034
15035 if (reply_len < 0) {
15036 os_memcpy(reply, "FAIL\n", 5);
15037 reply_len = 5;
15038 }
15039
15040 *resp_len = reply_len;
15041 return reply;
15042 }
15043
15044 int magiclink_p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd)
15045 {
15046 #ifdef CONFIG_MAGICLINK
15047 return hw_magiclink_p2p_ctrl_connect(wpa_s, cmd);
15048 #else
15049 return 0;
15050 #endif
15051 }
15052
15053 int p2p_wifi_display_subelem_set(struct wpa_global *global, char *cmd)
15054 {
15055 #ifdef CONFIG_WIFI_DISPLAY
15056 return wifi_display_subelem_set(global, cmd);
15057 #else
15058 return 0;
15059 #endif
15060 }