1 /*
2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2020, 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/ptksa_cache.h"
26 #include "crypto/tls.h"
27 #include "ap/hostapd.h"
28 #include "eap_peer/eap.h"
29 #include "eapol_supp/eapol_supp_sm.h"
30 #include "rsn_supp/wpa.h"
31 #include "rsn_supp/preauth.h"
32 #include "rsn_supp/pmksa_cache.h"
33 #include "l2_packet/l2_packet.h"
34 #include "wps/wps.h"
35 #include "fst/fst.h"
36 #include "fst/fst_ctrl_iface.h"
37 #include "config.h"
38 #include "wpa_supplicant_i.h"
39 #include "driver_i.h"
40 #include "wps_supplicant.h"
41 #include "ibss_rsn.h"
42 #include "wpas_glue.h"
43 #include "ap.h"
44 #include "p2p_supplicant.h"
45 #include "p2p/p2p.h"
46 #include "hs20_supplicant.h"
47 #include "wifi_display.h"
48 #include "notify.h"
49 #include "bss.h"
50 #include "scan.h"
51 #include "ctrl_iface.h"
52 #include "interworking.h"
53 #include "bssid_ignore.h"
54 #include "autoscan.h"
55 #include "wnm_sta.h"
56 #include "offchannel.h"
57 #include "drivers/driver.h"
58 #include "mesh.h"
59 #include "dpp_supplicant.h"
60 #include "sme.h"
61
62 #ifdef __NetBSD__
63 #include <net/if_ether.h>
64 #elif !defined(__CYGWIN__) && !defined(CONFIG_NATIVE_WINDOWS)
65 #include <net/ethernet.h>
66 #endif
67
68 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
69 char *buf, int len);
70 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
71 const char *input,
72 char *buf, int len);
73 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
74 char *val);
75
76
set_bssid_filter(struct wpa_supplicant * wpa_s,char * val)77 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
78 {
79 char *pos;
80 u8 addr[ETH_ALEN], *filter = NULL, *n;
81 size_t count = 0;
82
83 pos = val;
84 while (pos) {
85 if (*pos == '\0')
86 break;
87 if (hwaddr_aton(pos, addr)) {
88 os_free(filter);
89 return -1;
90 }
91 n = os_realloc_array(filter, count + 1, ETH_ALEN);
92 if (n == NULL) {
93 os_free(filter);
94 return -1;
95 }
96 filter = n;
97 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
98 count++;
99
100 pos = os_strchr(pos, ' ');
101 if (pos)
102 pos++;
103 }
104
105 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
106 os_free(wpa_s->bssid_filter);
107 wpa_s->bssid_filter = filter;
108 wpa_s->bssid_filter_count = count;
109
110 return 0;
111 }
112
113
set_disallow_aps(struct wpa_supplicant * wpa_s,char * val)114 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
115 {
116 char *pos;
117 u8 addr[ETH_ALEN], *bssid = NULL, *n;
118 struct wpa_ssid_value *ssid = NULL, *ns;
119 size_t count = 0, ssid_count = 0;
120 struct wpa_ssid *c;
121
122 /*
123 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
124 * SSID_SPEC ::= ssid <SSID_HEX>
125 * BSSID_SPEC ::= bssid <BSSID_HEX>
126 */
127
128 pos = val;
129 while (pos) {
130 if (*pos == '\0')
131 break;
132 if (os_strncmp(pos, "bssid ", 6) == 0) {
133 int res;
134 pos += 6;
135 res = hwaddr_aton2(pos, addr);
136 if (res < 0) {
137 os_free(ssid);
138 os_free(bssid);
139 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
140 "BSSID value '%s'", pos);
141 return -1;
142 }
143 pos += res;
144 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
145 if (n == NULL) {
146 os_free(ssid);
147 os_free(bssid);
148 return -1;
149 }
150 bssid = n;
151 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
152 count++;
153 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
154 char *end;
155 pos += 5;
156
157 end = pos;
158 while (*end) {
159 if (*end == '\0' || *end == ' ')
160 break;
161 end++;
162 }
163
164 ns = os_realloc_array(ssid, ssid_count + 1,
165 sizeof(struct wpa_ssid_value));
166 if (ns == NULL) {
167 os_free(ssid);
168 os_free(bssid);
169 return -1;
170 }
171 ssid = ns;
172
173 if ((end - pos) & 0x01 ||
174 end - pos > 2 * SSID_MAX_LEN ||
175 hexstr2bin(pos, ssid[ssid_count].ssid,
176 (end - pos) / 2) < 0) {
177 os_free(ssid);
178 os_free(bssid);
179 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
180 "SSID value '%s'", pos);
181 return -1;
182 }
183 ssid[ssid_count].ssid_len = (end - pos) / 2;
184 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
185 ssid[ssid_count].ssid,
186 ssid[ssid_count].ssid_len);
187 ssid_count++;
188 pos = end;
189 } else {
190 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
191 "'%s'", pos);
192 os_free(ssid);
193 os_free(bssid);
194 return -1;
195 }
196
197 pos = os_strchr(pos, ' ');
198 if (pos)
199 pos++;
200 }
201
202 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
203 os_free(wpa_s->disallow_aps_bssid);
204 wpa_s->disallow_aps_bssid = bssid;
205 wpa_s->disallow_aps_bssid_count = count;
206
207 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
208 os_free(wpa_s->disallow_aps_ssid);
209 wpa_s->disallow_aps_ssid = ssid;
210 wpa_s->disallow_aps_ssid_count = ssid_count;
211
212 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
213 return 0;
214
215 c = wpa_s->current_ssid;
216 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
217 return 0;
218
219 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
220 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
221 return 0;
222
223 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
224 "because current AP was marked disallowed");
225
226 #ifdef CONFIG_SME
227 wpa_s->sme.prev_bssid_set = 0;
228 #endif /* CONFIG_SME */
229 wpa_s->reassociate = 1;
230 wpa_s->own_disconnect_req = 1;
231 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
232 wpa_supplicant_req_scan(wpa_s, 0, 0);
233
234 return 0;
235 }
236
237
238 #ifndef CONFIG_NO_CONFIG_BLOBS
wpas_ctrl_set_blob(struct wpa_supplicant * wpa_s,char * pos)239 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
240 {
241 char *name = pos;
242 struct wpa_config_blob *blob;
243 size_t len;
244
245 pos = os_strchr(pos, ' ');
246 if (pos == NULL)
247 return -1;
248 *pos++ = '\0';
249 len = os_strlen(pos);
250 if (len & 1)
251 return -1;
252
253 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
254 blob = os_zalloc(sizeof(*blob));
255 if (blob == NULL)
256 return -1;
257 blob->name = os_strdup(name);
258 blob->data = os_malloc(len / 2);
259 if (blob->name == NULL || blob->data == NULL) {
260 wpa_config_free_blob(blob);
261 return -1;
262 }
263
264 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
265 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
266 wpa_config_free_blob(blob);
267 return -1;
268 }
269 blob->len = len / 2;
270
271 wpa_config_set_blob(wpa_s->conf, blob);
272
273 return 0;
274 }
275 #endif /* CONFIG_NO_CONFIG_BLOBS */
276
277
wpas_ctrl_pno(struct wpa_supplicant * wpa_s,char * cmd)278 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
279 {
280 char *params;
281 char *pos;
282 int *freqs = NULL;
283 int ret;
284
285 if (atoi(cmd)) {
286 params = os_strchr(cmd, ' ');
287 os_free(wpa_s->manual_sched_scan_freqs);
288 if (params) {
289 params++;
290 pos = os_strstr(params, "freq=");
291 if (pos)
292 freqs = freq_range_to_channel_list(wpa_s,
293 pos + 5);
294 }
295 wpa_s->manual_sched_scan_freqs = freqs;
296 ret = wpas_start_pno(wpa_s);
297 } else {
298 ret = wpas_stop_pno(wpa_s);
299 }
300 return ret;
301 }
302
303
wpas_ctrl_set_band(struct wpa_supplicant * wpa_s,char * bands)304 static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *bands)
305 {
306 union wpa_event_data event;
307 u32 setband_mask = WPA_SETBAND_AUTO;
308
309 /*
310 * For example:
311 * SET setband 2G,6G
312 * SET setband 5G
313 * SET setband AUTO
314 */
315 if (!os_strstr(bands, "AUTO")) {
316 if (os_strstr(bands, "5G"))
317 setband_mask |= WPA_SETBAND_5G;
318 if (os_strstr(bands, "6G"))
319 setband_mask |= WPA_SETBAND_6G;
320 if (os_strstr(bands, "2G"))
321 setband_mask |= WPA_SETBAND_2G;
322 if (setband_mask == WPA_SETBAND_AUTO)
323 return -1;
324 }
325
326 wpa_s->setband_mask = setband_mask;
327 if (wpa_drv_setband(wpa_s, wpa_s->setband_mask) == 0) {
328 os_memset(&event, 0, sizeof(event));
329 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
330 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
331 wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
332 }
333
334 return 0;
335 }
336
337
wpas_ctrl_iface_set_lci(struct wpa_supplicant * wpa_s,const char * cmd)338 static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s,
339 const char *cmd)
340 {
341 struct wpabuf *lci;
342
343 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
344 wpabuf_free(wpa_s->lci);
345 wpa_s->lci = NULL;
346 return 0;
347 }
348
349 lci = wpabuf_parse_bin(cmd);
350 if (!lci)
351 return -1;
352
353 if (os_get_reltime(&wpa_s->lci_time)) {
354 wpabuf_free(lci);
355 return -1;
356 }
357
358 wpabuf_free(wpa_s->lci);
359 wpa_s->lci = lci;
360
361 return 0;
362 }
363
364
365 static int
wpas_ctrl_set_relative_rssi(struct wpa_supplicant * wpa_s,const char * cmd)366 wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd)
367 {
368 int relative_rssi;
369
370 if (os_strcmp(cmd, "disable") == 0) {
371 wpa_s->srp.relative_rssi_set = 0;
372 return 0;
373 }
374
375 relative_rssi = atoi(cmd);
376 if (relative_rssi < 0 || relative_rssi > 100)
377 return -1;
378 wpa_s->srp.relative_rssi = relative_rssi;
379 wpa_s->srp.relative_rssi_set = 1;
380 return 0;
381 }
382
383
wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant * wpa_s,const char * cmd)384 static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s,
385 const char *cmd)
386 {
387 char *pos;
388 int adjust_rssi;
389
390 /* <band>:adjust_value */
391 pos = os_strchr(cmd, ':');
392 if (!pos)
393 return -1;
394 pos++;
395 adjust_rssi = atoi(pos);
396 if (adjust_rssi < -100 || adjust_rssi > 100)
397 return -1;
398
399 if (os_strncmp(cmd, "2G", 2) == 0)
400 wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G;
401 else if (os_strncmp(cmd, "5G", 2) == 0)
402 wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G;
403 else
404 return -1;
405
406 wpa_s->srp.relative_adjust_rssi = adjust_rssi;
407
408 return 0;
409 }
410
411
wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant * wpa_s,const char * cmd)412 static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s,
413 const char *cmd)
414 {
415 struct wpabuf *ric_ies;
416
417 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
418 wpabuf_free(wpa_s->ric_ies);
419 wpa_s->ric_ies = NULL;
420 return 0;
421 }
422
423 ric_ies = wpabuf_parse_bin(cmd);
424 if (!ric_ies)
425 return -1;
426
427 wpabuf_free(wpa_s->ric_ies);
428 wpa_s->ric_ies = ric_ies;
429
430 return 0;
431 }
432
433
434 #ifdef CONFIG_TESTING_OPTIONS
wpas_ctrl_iface_set_dso(struct wpa_supplicant * wpa_s,const char * val)435 static int wpas_ctrl_iface_set_dso(struct wpa_supplicant *wpa_s,
436 const char *val)
437 {
438 u8 bssid[ETH_ALEN];
439 const char *pos = val;
440 struct driver_signal_override *dso = NULL, *tmp, parsed;
441
442 if (hwaddr_aton(pos, bssid))
443 return -1;
444 pos = os_strchr(pos, ' ');
445
446 dl_list_for_each(tmp, &wpa_s->drv_signal_override,
447 struct driver_signal_override, list) {
448 if (os_memcmp(bssid, tmp->bssid, ETH_ALEN) == 0) {
449 dso = tmp;
450 break;
451 }
452 }
453
454 if (!pos) {
455 /* Remove existing entry */
456 if (dso) {
457 dl_list_del(&dso->list);
458 os_free(dso);
459 }
460 return 0;
461 }
462 pos++;
463
464 /* Update an existing entry or add a new one */
465 os_memset(&parsed, 0, sizeof(parsed));
466 if (sscanf(pos, "%d %d %d %d %d",
467 &parsed.si_current_signal,
468 &parsed.si_avg_signal,
469 &parsed.si_avg_beacon_signal,
470 &parsed.si_current_noise,
471 &parsed.scan_level) != 5)
472 return -1;
473
474 if (!dso) {
475 dso = os_zalloc(sizeof(*dso));
476 if (!dso)
477 return -1;
478 os_memcpy(dso->bssid, bssid, ETH_ALEN);
479 dl_list_add(&wpa_s->drv_signal_override, &dso->list);
480 }
481 dso->si_current_signal = parsed.si_current_signal;
482 dso->si_avg_signal = parsed.si_avg_signal;
483 dso->si_avg_beacon_signal = parsed.si_avg_beacon_signal;
484 dso->si_current_noise = parsed.si_current_noise;
485 dso->scan_level = parsed.scan_level;
486
487 return 0;
488 }
489 #endif /* CONFIG_TESTING_OPTIONS */
490
491
wpa_supplicant_ctrl_iface_set(struct wpa_supplicant * wpa_s,char * cmd)492 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
493 char *cmd)
494 {
495 char *value;
496 int ret = 0;
497
498 value = os_strchr(cmd, ' ');
499 if (value == NULL)
500 return -1;
501 *value++ = '\0';
502
503 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
504 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
505 eapol_sm_configure(wpa_s->eapol,
506 atoi(value), -1, -1, -1);
507 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
508 eapol_sm_configure(wpa_s->eapol,
509 -1, atoi(value), -1, -1);
510 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
511 eapol_sm_configure(wpa_s->eapol,
512 -1, -1, atoi(value), -1);
513 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
514 eapol_sm_configure(wpa_s->eapol,
515 -1, -1, -1, atoi(value));
516 #ifdef CONFIG_TESTING_OPTIONS
517 } else if (os_strcasecmp(cmd, "EAPOL::portControl") == 0) {
518 if (os_strcmp(value, "Auto") == 0)
519 eapol_sm_notify_portControl(wpa_s->eapol, Auto);
520 else if (os_strcmp(value, "ForceUnauthorized") == 0)
521 eapol_sm_notify_portControl(wpa_s->eapol,
522 ForceUnauthorized);
523 else if (os_strcmp(value, "ForceAuthorized") == 0)
524 eapol_sm_notify_portControl(wpa_s->eapol,
525 ForceAuthorized);
526 else
527 ret = -1;
528 #endif /* CONFIG_TESTING_OPTIONS */
529 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
530 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
531 atoi(value))) {
532 ret = -1;
533 } else {
534 value[-1] = '=';
535 wpa_config_process_global(wpa_s->conf, cmd, -1);
536 }
537 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
538 0) {
539 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
540 atoi(value))) {
541 ret = -1;
542 } else {
543 value[-1] = '=';
544 wpa_config_process_global(wpa_s->conf, cmd, -1);
545 }
546 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
547 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
548 atoi(value))) {
549 ret = -1;
550 } else {
551 value[-1] = '=';
552 wpa_config_process_global(wpa_s->conf, cmd, -1);
553 }
554 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
555 wpa_s->wps_fragment_size = atoi(value);
556 #ifdef CONFIG_WPS_TESTING
557 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
558 long int val;
559 val = strtol(value, NULL, 0);
560 if (val < 0 || val > 0xff) {
561 ret = -1;
562 wpa_printf(MSG_DEBUG, "WPS: Invalid "
563 "wps_version_number %ld", val);
564 } else {
565 wps_version_number = val;
566 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
567 "version %u.%u",
568 (wps_version_number & 0xf0) >> 4,
569 wps_version_number & 0x0f);
570 }
571 } else if (os_strcasecmp(cmd, "wps_testing_stub_cred") == 0) {
572 wps_testing_stub_cred = atoi(value);
573 wpa_printf(MSG_DEBUG, "WPS: Testing - stub_cred=%d",
574 wps_testing_stub_cred);
575 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
576 wps_corrupt_pkhash = atoi(value);
577 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
578 wps_corrupt_pkhash);
579 } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
580 if (value[0] == '\0') {
581 wps_force_auth_types_in_use = 0;
582 } else {
583 wps_force_auth_types = strtol(value, NULL, 0);
584 wps_force_auth_types_in_use = 1;
585 }
586 } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
587 if (value[0] == '\0') {
588 wps_force_encr_types_in_use = 0;
589 } else {
590 wps_force_encr_types = strtol(value, NULL, 0);
591 wps_force_encr_types_in_use = 1;
592 }
593 #endif /* CONFIG_WPS_TESTING */
594 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
595 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
596 ret = -1;
597 #ifdef CONFIG_TDLS
598 #ifdef CONFIG_TDLS_TESTING
599 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
600 tdls_testing = strtol(value, NULL, 0);
601 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
602 #endif /* CONFIG_TDLS_TESTING */
603 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
604 int disabled = atoi(value);
605 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
606 if (disabled) {
607 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
608 ret = -1;
609 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
610 ret = -1;
611 wpa_tdls_enable(wpa_s->wpa, !disabled);
612 #endif /* CONFIG_TDLS */
613 } else if (os_strcasecmp(cmd, "pno") == 0) {
614 ret = wpas_ctrl_pno(wpa_s, value);
615 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
616 int disabled = atoi(value);
617 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
618 ret = -1;
619 else if (disabled)
620 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
621 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
622 if (os_strcmp(value, "disable") == 0)
623 wpa_s->set_sta_uapsd = 0;
624 else {
625 int be, bk, vi, vo;
626 char *pos;
627 /* format: BE,BK,VI,VO;max SP Length */
628 be = atoi(value);
629 pos = os_strchr(value, ',');
630 if (pos == NULL)
631 return -1;
632 pos++;
633 bk = atoi(pos);
634 pos = os_strchr(pos, ',');
635 if (pos == NULL)
636 return -1;
637 pos++;
638 vi = atoi(pos);
639 pos = os_strchr(pos, ',');
640 if (pos == NULL)
641 return -1;
642 pos++;
643 vo = atoi(pos);
644 /* ignore max SP Length for now */
645
646 wpa_s->set_sta_uapsd = 1;
647 wpa_s->sta_uapsd = 0;
648 if (be)
649 wpa_s->sta_uapsd |= BIT(0);
650 if (bk)
651 wpa_s->sta_uapsd |= BIT(1);
652 if (vi)
653 wpa_s->sta_uapsd |= BIT(2);
654 if (vo)
655 wpa_s->sta_uapsd |= BIT(3);
656 }
657 } else if (os_strcasecmp(cmd, "ps") == 0) {
658 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
659 #ifdef CONFIG_WIFI_DISPLAY
660 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
661 int enabled = !!atoi(value);
662 if (enabled && !wpa_s->global->p2p)
663 ret = -1;
664 else
665 wifi_display_enable(wpa_s->global, enabled);
666 #endif /* CONFIG_WIFI_DISPLAY */
667 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
668 ret = set_bssid_filter(wpa_s, value);
669 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
670 ret = set_disallow_aps(wpa_s, value);
671 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
672 wpa_s->no_keep_alive = !!atoi(value);
673 #ifdef CONFIG_DPP
674 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
675 os_free(wpa_s->dpp_configurator_params);
676 wpa_s->dpp_configurator_params = os_strdup(value);
677 #ifdef CONFIG_DPP2
678 dpp_controller_set_params(wpa_s->dpp, value);
679 #endif /* CONFIG_DPP2 */
680 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
681 wpa_s->dpp_init_max_tries = atoi(value);
682 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
683 wpa_s->dpp_init_retry_time = atoi(value);
684 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
685 wpa_s->dpp_resp_wait_time = atoi(value);
686 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
687 wpa_s->dpp_resp_max_tries = atoi(value);
688 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
689 wpa_s->dpp_resp_retry_time = atoi(value);
690 #ifdef CONFIG_TESTING_OPTIONS
691 } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
692 if (hwaddr_aton(value, dpp_pkex_own_mac_override))
693 ret = -1;
694 } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
695 if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
696 ret = -1;
697 } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
698 size_t hex_len = os_strlen(value);
699
700 if (hex_len >
701 2 * sizeof(dpp_pkex_ephemeral_key_override))
702 ret = -1;
703 else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
704 hex_len / 2))
705 ret = -1;
706 else
707 dpp_pkex_ephemeral_key_override_len = hex_len / 2;
708 } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) {
709 size_t hex_len = os_strlen(value);
710
711 if (hex_len > 2 * sizeof(dpp_protocol_key_override))
712 ret = -1;
713 else if (hexstr2bin(value, dpp_protocol_key_override,
714 hex_len / 2))
715 ret = -1;
716 else
717 dpp_protocol_key_override_len = hex_len / 2;
718 } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) {
719 size_t hex_len = os_strlen(value);
720
721 if (hex_len > 2 * sizeof(dpp_nonce_override))
722 ret = -1;
723 else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2))
724 ret = -1;
725 else
726 dpp_nonce_override_len = hex_len / 2;
727 } else if (os_strcasecmp(cmd, "dpp_version_override") == 0) {
728 dpp_version_override = atoi(value);
729 #endif /* CONFIG_TESTING_OPTIONS */
730 #endif /* CONFIG_DPP */
731 #ifdef CONFIG_TESTING_OPTIONS
732 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
733 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
734 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
735 wpa_s->ext_eapol_frame_io = !!atoi(value);
736 #ifdef CONFIG_AP
737 if (wpa_s->ap_iface) {
738 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
739 wpa_s->ext_eapol_frame_io;
740 }
741 #endif /* CONFIG_AP */
742 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
743 wpa_s->extra_roc_dur = atoi(value);
744 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
745 wpa_s->test_failure = atoi(value);
746 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
747 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
748 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
749 wpa_s->ignore_auth_resp = !!atoi(value);
750 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
751 wpa_s->ignore_assoc_disallow = !!atoi(value);
752 wpa_drv_ignore_assoc_disallow(wpa_s,
753 wpa_s->ignore_assoc_disallow);
754 } else if (os_strcasecmp(cmd, "disable_sa_query") == 0) {
755 wpa_s->disable_sa_query = !!atoi(value);
756 } else if (os_strcasecmp(cmd, "ignore_sae_h2e_only") == 0) {
757 wpa_s->ignore_sae_h2e_only = !!atoi(value);
758 } else if (os_strcasecmp(cmd, "extra_sae_rejected_groups") == 0) {
759 char *pos;
760
761 os_free(wpa_s->extra_sae_rejected_groups);
762 wpa_s->extra_sae_rejected_groups = NULL;
763 pos = value;
764 while (pos && pos[0]) {
765 int group;
766
767 group = atoi(pos);
768 wpa_printf(MSG_DEBUG,
769 "TESTING: Extra rejection of SAE group %d",
770 group);
771 if (group)
772 int_array_add_unique(
773 &wpa_s->extra_sae_rejected_groups,
774 group);
775 pos = os_strchr(pos, ' ');
776 if (!pos)
777 break;
778 pos++;
779 }
780 } else if (os_strcasecmp(cmd, "ft_rsnxe_used") == 0) {
781 wpa_s->ft_rsnxe_used = atoi(value);
782 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol") == 0) {
783 wpa_s->oci_freq_override_eapol = atoi(value);
784 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_req") == 0) {
785 wpa_s->oci_freq_override_saquery_req = atoi(value);
786 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_resp") == 0) {
787 wpa_s->oci_freq_override_saquery_resp = atoi(value);
788 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol_g2") == 0) {
789 wpa_s->oci_freq_override_eapol_g2 = atoi(value);
790 /* Populate value to wpa_sm if already associated. */
791 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_EAPOL_G2,
792 wpa_s->oci_freq_override_eapol_g2);
793 } else if (os_strcasecmp(cmd, "oci_freq_override_ft_assoc") == 0) {
794 wpa_s->oci_freq_override_ft_assoc = atoi(value);
795 /* Populate value to wpa_sm if already associated. */
796 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_FT_ASSOC,
797 wpa_s->oci_freq_override_ft_assoc);
798 } else if (os_strcasecmp(cmd, "oci_freq_override_fils_assoc") == 0) {
799 wpa_s->oci_freq_override_fils_assoc = atoi(value);
800 } else if (os_strcasecmp(cmd, "oci_freq_override_wnm_sleep") == 0) {
801 wpa_s->oci_freq_override_wnm_sleep = atoi(value);
802 } else if (os_strcasecmp(cmd, "rsne_override_eapol") == 0) {
803 wpabuf_free(wpa_s->rsne_override_eapol);
804 if (os_strcmp(value, "NULL") == 0)
805 wpa_s->rsne_override_eapol = NULL;
806 else
807 wpa_s->rsne_override_eapol = wpabuf_parse_bin(value);
808 } else if (os_strcasecmp(cmd, "rsnxe_override_assoc") == 0) {
809 wpabuf_free(wpa_s->rsnxe_override_assoc);
810 if (os_strcmp(value, "NULL") == 0)
811 wpa_s->rsnxe_override_assoc = NULL;
812 else
813 wpa_s->rsnxe_override_assoc = wpabuf_parse_bin(value);
814 } else if (os_strcasecmp(cmd, "rsnxe_override_eapol") == 0) {
815 wpabuf_free(wpa_s->rsnxe_override_eapol);
816 if (os_strcmp(value, "NULL") == 0)
817 wpa_s->rsnxe_override_eapol = NULL;
818 else
819 wpa_s->rsnxe_override_eapol = wpabuf_parse_bin(value);
820 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
821 wpa_s->reject_btm_req_reason = atoi(value);
822 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
823 os_free(wpa_s->get_pref_freq_list_override);
824 if (!value[0])
825 wpa_s->get_pref_freq_list_override = NULL;
826 else
827 wpa_s->get_pref_freq_list_override = os_strdup(value);
828 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
829 wpabuf_free(wpa_s->sae_commit_override);
830 if (value[0] == '\0')
831 wpa_s->sae_commit_override = NULL;
832 else
833 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
834 } else if (os_strcasecmp(cmd, "driver_signal_override") == 0) {
835 ret = wpas_ctrl_iface_set_dso(wpa_s, value);
836 } else if (os_strcasecmp(cmd, "disable_scs_support") == 0) {
837 wpa_s->disable_scs_support = !!atoi(value);
838 } else if (os_strcasecmp(cmd, "disable_mscs_support") == 0) {
839 wpa_s->disable_mscs_support = !!atoi(value);
840 } else if (os_strcasecmp(cmd, "disable_eapol_g2_tx") == 0) {
841 wpa_s->disable_eapol_g2_tx = !!atoi(value);
842 /* Populate value to wpa_sm if already associated. */
843 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DISABLE_EAPOL_G2_TX,
844 wpa_s->disable_eapol_g2_tx);
845 #ifdef CONFIG_DPP
846 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
847 os_free(wpa_s->dpp_config_obj_override);
848 if (value[0] == '\0')
849 wpa_s->dpp_config_obj_override = NULL;
850 else
851 wpa_s->dpp_config_obj_override = os_strdup(value);
852 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
853 os_free(wpa_s->dpp_discovery_override);
854 if (value[0] == '\0')
855 wpa_s->dpp_discovery_override = NULL;
856 else
857 wpa_s->dpp_discovery_override = os_strdup(value);
858 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
859 os_free(wpa_s->dpp_groups_override);
860 if (value[0] == '\0')
861 wpa_s->dpp_groups_override = NULL;
862 else
863 wpa_s->dpp_groups_override = os_strdup(value);
864 } else if (os_strcasecmp(cmd,
865 "dpp_ignore_netaccesskey_mismatch") == 0) {
866 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
867 } else if (os_strcasecmp(cmd, "dpp_discard_public_action") == 0) {
868 wpa_s->dpp_discard_public_action = atoi(value);
869 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
870 dpp_test = atoi(value);
871 #endif /* CONFIG_DPP */
872 #endif /* CONFIG_TESTING_OPTIONS */
873 #ifdef CONFIG_FILS
874 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
875 wpa_s->disable_fils = !!atoi(value);
876 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
877 wpa_supplicant_set_default_scan_ies(wpa_s);
878 #endif /* CONFIG_FILS */
879 #ifndef CONFIG_NO_CONFIG_BLOBS
880 } else if (os_strcmp(cmd, "blob") == 0) {
881 ret = wpas_ctrl_set_blob(wpa_s, value);
882 #endif /* CONFIG_NO_CONFIG_BLOBS */
883 } else if (os_strcasecmp(cmd, "setband") == 0) {
884 ret = wpas_ctrl_set_band(wpa_s, value);
885 #ifdef CONFIG_MBO
886 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
887 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
888 if (ret == 0) {
889 value[-1] = '=';
890 wpa_config_process_global(wpa_s->conf, cmd, -1);
891 }
892 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
893 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
894 } else if (os_strcasecmp(cmd, "oce") == 0) {
895 wpa_s->conf->oce = atoi(value);
896 if (wpa_s->conf->oce) {
897 if ((wpa_s->conf->oce & OCE_STA) &&
898 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
899 wpa_s->enable_oce = OCE_STA;
900
901 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
902 (wpa_s->drv_flags &
903 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
904 /* TODO: Need to add STA-CFON support */
905 wpa_printf(MSG_ERROR,
906 "OCE STA-CFON feature is not yet supported");
907 return -1;
908 }
909 } else {
910 wpa_s->enable_oce = 0;
911 }
912 wpa_supplicant_set_default_scan_ies(wpa_s);
913 #endif /* CONFIG_MBO */
914 } else if (os_strcasecmp(cmd, "lci") == 0) {
915 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
916 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
917 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
918 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
919 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
920 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
921 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
922 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
923 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
924 } else if (os_strcasecmp(cmd, "roaming") == 0) {
925 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
926 #ifdef CONFIG_WNM
927 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
928 struct wpabuf *elems;
929
930 elems = wpabuf_parse_bin(value);
931 if (!elems)
932 return -1;
933 wnm_set_coloc_intf_elems(wpa_s, elems);
934 #endif /* CONFIG_WNM */
935 } else if (os_strcasecmp(cmd, "enable_dscp_policy_capa") == 0) {
936 wpa_s->enable_dscp_policy_capa = !!atoi(value);
937 } else {
938 value[-1] = '=';
939 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
940 if (ret == 0)
941 wpa_supplicant_update_config(wpa_s);
942 else if (ret == 1)
943 ret = 0;
944 }
945
946 return ret;
947 }
948
949
wpa_supplicant_ctrl_iface_get(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)950 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
951 char *cmd, char *buf, size_t buflen)
952 {
953 int res = -1;
954
955 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
956
957 if (os_strcmp(cmd, "version") == 0) {
958 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
959 } else if (os_strcasecmp(cmd, "max_command_len") == 0) {
960 res = os_snprintf(buf, buflen, "%u", CTRL_IFACE_MAX_LEN);
961 } else if (os_strcasecmp(cmd, "country") == 0) {
962 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
963 res = os_snprintf(buf, buflen, "%c%c",
964 wpa_s->conf->country[0],
965 wpa_s->conf->country[1]);
966 #ifdef CONFIG_WIFI_DISPLAY
967 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
968 int enabled;
969 if (wpa_s->global->p2p == NULL ||
970 wpa_s->global->p2p_disabled)
971 enabled = 0;
972 else
973 enabled = wpa_s->global->wifi_display;
974 res = os_snprintf(buf, buflen, "%d", enabled);
975 #endif /* CONFIG_WIFI_DISPLAY */
976 #ifdef CONFIG_TESTING_GET_GTK
977 } else if (os_strcmp(cmd, "gtk") == 0) {
978 if (wpa_s->last_gtk_len == 0)
979 return -1;
980 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
981 wpa_s->last_gtk_len);
982 return res;
983 #endif /* CONFIG_TESTING_GET_GTK */
984 } else if (os_strcmp(cmd, "tls_library") == 0) {
985 res = tls_get_library_version(buf, buflen);
986 #ifdef CONFIG_TESTING_OPTIONS
987 } else if (os_strcmp(cmd, "anonce") == 0) {
988 return wpa_snprintf_hex(buf, buflen,
989 wpa_sm_get_anonce(wpa_s->wpa),
990 WPA_NONCE_LEN);
991 } else if (os_strcasecmp(cmd, "last_tk_key_idx") == 0) {
992 res = os_snprintf(buf, buflen, "%d", wpa_s->last_tk_key_idx);
993 #endif /* CONFIG_TESTING_OPTIONS */
994 } else {
995 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
996 }
997
998 if (os_snprintf_error(buflen, res))
999 return -1;
1000 return res;
1001 }
1002
1003
1004 #ifdef IEEE8021X_EAPOL
wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant * wpa_s,char * addr)1005 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
1006 char *addr)
1007 {
1008 u8 bssid[ETH_ALEN];
1009 struct wpa_ssid *ssid = wpa_s->current_ssid;
1010
1011 if (hwaddr_aton(addr, bssid)) {
1012 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
1013 "'%s'", addr);
1014 return -1;
1015 }
1016
1017 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
1018 rsn_preauth_deinit(wpa_s->wpa);
1019 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
1020 return -1;
1021
1022 return 0;
1023 }
1024 #endif /* IEEE8021X_EAPOL */
1025
1026
1027 #ifdef CONFIG_TDLS
1028
wpa_supplicant_ctrl_iface_tdls_discover(struct wpa_supplicant * wpa_s,char * addr)1029 static int wpa_supplicant_ctrl_iface_tdls_discover(
1030 struct wpa_supplicant *wpa_s, char *addr)
1031 {
1032 u8 peer[ETH_ALEN];
1033 int ret;
1034
1035 if (hwaddr_aton(addr, peer)) {
1036 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
1037 "address '%s'", addr);
1038 return -1;
1039 }
1040
1041 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
1042 MAC2STR(peer));
1043
1044 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1045 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
1046 else
1047 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
1048
1049 return ret;
1050 }
1051
1052
wpa_supplicant_ctrl_iface_tdls_setup(struct wpa_supplicant * wpa_s,char * addr)1053 static int wpa_supplicant_ctrl_iface_tdls_setup(
1054 struct wpa_supplicant *wpa_s, char *addr)
1055 {
1056 u8 peer[ETH_ALEN];
1057 int ret;
1058
1059 if (hwaddr_aton(addr, peer)) {
1060 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
1061 "address '%s'", addr);
1062 return -1;
1063 }
1064
1065 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
1066 MAC2STR(peer));
1067
1068 if ((wpa_s->conf->tdls_external_control) &&
1069 wpa_tdls_is_external_setup(wpa_s->wpa))
1070 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
1071
1072 wpa_tdls_remove(wpa_s->wpa, peer);
1073
1074 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1075 ret = wpa_tdls_start(wpa_s->wpa, peer);
1076 else
1077 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
1078
1079 return ret;
1080 }
1081
1082
wpa_supplicant_ctrl_iface_tdls_teardown(struct wpa_supplicant * wpa_s,char * addr)1083 static int wpa_supplicant_ctrl_iface_tdls_teardown(
1084 struct wpa_supplicant *wpa_s, char *addr)
1085 {
1086 u8 peer[ETH_ALEN];
1087 int ret;
1088
1089 if (os_strcmp(addr, "*") == 0) {
1090 /* remove everyone */
1091 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
1092 wpa_tdls_teardown_peers(wpa_s->wpa);
1093 return 0;
1094 }
1095
1096 if (hwaddr_aton(addr, peer)) {
1097 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
1098 "address '%s'", addr);
1099 return -1;
1100 }
1101
1102 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
1103 MAC2STR(peer));
1104
1105 if ((wpa_s->conf->tdls_external_control) &&
1106 wpa_tdls_is_external_setup(wpa_s->wpa))
1107 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1108
1109 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1110 ret = wpa_tdls_teardown_link(
1111 wpa_s->wpa, peer,
1112 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
1113 else
1114 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1115
1116 return ret;
1117 }
1118
1119
ctrl_iface_get_capability_tdls(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)1120 static int ctrl_iface_get_capability_tdls(
1121 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1122 {
1123 int ret;
1124
1125 ret = os_snprintf(buf, buflen, "%s\n",
1126 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
1127 (wpa_s->drv_flags &
1128 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
1129 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
1130 if (os_snprintf_error(buflen, ret))
1131 return -1;
1132 return ret;
1133 }
1134
1135
wpa_supplicant_ctrl_iface_tdls_chan_switch(struct wpa_supplicant * wpa_s,char * cmd)1136 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
1137 struct wpa_supplicant *wpa_s, char *cmd)
1138 {
1139 u8 peer[ETH_ALEN];
1140 struct hostapd_freq_params freq_params;
1141 u8 oper_class;
1142 char *pos, *end;
1143
1144 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1145 wpa_printf(MSG_INFO,
1146 "tdls_chanswitch: Only supported with external setup");
1147 return -1;
1148 }
1149
1150 os_memset(&freq_params, 0, sizeof(freq_params));
1151
1152 pos = os_strchr(cmd, ' ');
1153 if (pos == NULL)
1154 return -1;
1155 *pos++ = '\0';
1156
1157 oper_class = strtol(pos, &end, 10);
1158 if (pos == end) {
1159 wpa_printf(MSG_INFO,
1160 "tdls_chanswitch: Invalid op class provided");
1161 return -1;
1162 }
1163
1164 pos = end;
1165 freq_params.freq = atoi(pos);
1166 if (freq_params.freq == 0) {
1167 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
1168 return -1;
1169 }
1170
1171 #define SET_FREQ_SETTING(str) \
1172 do { \
1173 const char *pos2 = os_strstr(pos, " " #str "="); \
1174 if (pos2) { \
1175 pos2 += sizeof(" " #str "=") - 1; \
1176 freq_params.str = atoi(pos2); \
1177 } \
1178 } while (0)
1179
1180 SET_FREQ_SETTING(center_freq1);
1181 SET_FREQ_SETTING(center_freq2);
1182 SET_FREQ_SETTING(bandwidth);
1183 SET_FREQ_SETTING(sec_channel_offset);
1184 #undef SET_FREQ_SETTING
1185
1186 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1187 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1188
1189 if (hwaddr_aton(cmd, peer)) {
1190 wpa_printf(MSG_DEBUG,
1191 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1192 cmd);
1193 return -1;
1194 }
1195
1196 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1197 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1198 MAC2STR(peer), oper_class, freq_params.freq,
1199 freq_params.center_freq1, freq_params.center_freq2,
1200 freq_params.bandwidth, freq_params.sec_channel_offset,
1201 freq_params.ht_enabled ? " HT" : "",
1202 freq_params.vht_enabled ? " VHT" : "");
1203
1204 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1205 &freq_params);
1206 }
1207
1208
wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(struct wpa_supplicant * wpa_s,char * cmd)1209 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1210 struct wpa_supplicant *wpa_s, char *cmd)
1211 {
1212 u8 peer[ETH_ALEN];
1213
1214 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1215 wpa_printf(MSG_INFO,
1216 "tdls_chanswitch: Only supported with external setup");
1217 return -1;
1218 }
1219
1220 if (hwaddr_aton(cmd, peer)) {
1221 wpa_printf(MSG_DEBUG,
1222 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1223 cmd);
1224 return -1;
1225 }
1226
1227 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1228 MAC2STR(peer));
1229
1230 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1231 }
1232
1233
wpa_supplicant_ctrl_iface_tdls_link_status(struct wpa_supplicant * wpa_s,const char * addr,char * buf,size_t buflen)1234 static int wpa_supplicant_ctrl_iface_tdls_link_status(
1235 struct wpa_supplicant *wpa_s, const char *addr,
1236 char *buf, size_t buflen)
1237 {
1238 u8 peer[ETH_ALEN];
1239 const char *tdls_status;
1240 int ret;
1241
1242 if (hwaddr_aton(addr, peer)) {
1243 wpa_printf(MSG_DEBUG,
1244 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1245 addr);
1246 return -1;
1247 }
1248 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1249 MAC2STR(peer));
1250
1251 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1252 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1253 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1254 if (os_snprintf_error(buflen, ret))
1255 return -1;
1256
1257 return ret;
1258 }
1259
1260 #endif /* CONFIG_TDLS */
1261
1262
wmm_ac_ctrl_addts(struct wpa_supplicant * wpa_s,char * cmd)1263 static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1264 {
1265 char *token, *context = NULL;
1266 struct wmm_ac_ts_setup_params params = {
1267 .tsid = 0xff,
1268 .direction = 0xff,
1269 };
1270
1271 while ((token = str_token(cmd, " ", &context))) {
1272 if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 ||
1273 sscanf(token, "up=%i", ¶ms.user_priority) == 1 ||
1274 sscanf(token, "nominal_msdu_size=%i",
1275 ¶ms.nominal_msdu_size) == 1 ||
1276 sscanf(token, "mean_data_rate=%i",
1277 ¶ms.mean_data_rate) == 1 ||
1278 sscanf(token, "min_phy_rate=%i",
1279 ¶ms.minimum_phy_rate) == 1 ||
1280 sscanf(token, "sba=%i",
1281 ¶ms.surplus_bandwidth_allowance) == 1)
1282 continue;
1283
1284 if (os_strcasecmp(token, "downlink") == 0) {
1285 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1286 } else if (os_strcasecmp(token, "uplink") == 0) {
1287 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1288 } else if (os_strcasecmp(token, "bidi") == 0) {
1289 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1290 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1291 params.fixed_nominal_msdu = 1;
1292 } else {
1293 wpa_printf(MSG_DEBUG,
1294 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1295 token);
1296 return -1;
1297 }
1298
1299 }
1300
1301 return wpas_wmm_ac_addts(wpa_s, ¶ms);
1302 }
1303
1304
wmm_ac_ctrl_delts(struct wpa_supplicant * wpa_s,char * cmd)1305 static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1306 {
1307 u8 tsid = atoi(cmd);
1308
1309 return wpas_wmm_ac_delts(wpa_s, tsid);
1310 }
1311
1312
1313 #ifdef CONFIG_IEEE80211R
wpa_supplicant_ctrl_iface_ft_ds(struct wpa_supplicant * wpa_s,char * addr)1314 static int wpa_supplicant_ctrl_iface_ft_ds(
1315 struct wpa_supplicant *wpa_s, char *addr)
1316 {
1317 u8 target_ap[ETH_ALEN];
1318 struct wpa_bss *bss;
1319 const u8 *mdie;
1320 bool force = os_strstr(addr, " force") != NULL;
1321
1322 if (hwaddr_aton(addr, target_ap)) {
1323 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1324 "address '%s'", addr);
1325 return -1;
1326 }
1327
1328 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1329
1330 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1331 if (bss)
1332 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1333 else
1334 mdie = NULL;
1335
1336 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie, force);
1337 }
1338 #endif /* CONFIG_IEEE80211R */
1339
1340
1341 #ifdef CONFIG_WPS
wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant * wpa_s,char * cmd)1342 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1343 char *cmd)
1344 {
1345 u8 bssid[ETH_ALEN], *_bssid = bssid;
1346 #ifdef CONFIG_P2P
1347 u8 p2p_dev_addr[ETH_ALEN];
1348 #endif /* CONFIG_P2P */
1349 #ifdef CONFIG_AP
1350 u8 *_p2p_dev_addr = NULL;
1351 #endif /* CONFIG_AP */
1352 char *pos;
1353 int multi_ap = 0;
1354
1355 if (!cmd || os_strcmp(cmd, "any") == 0 ||
1356 os_strncmp(cmd, "any ", 4) == 0) {
1357 _bssid = NULL;
1358 #ifdef CONFIG_P2P
1359 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1360 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1361 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1362 "P2P Device Address '%s'",
1363 cmd + 13);
1364 return -1;
1365 }
1366 _p2p_dev_addr = p2p_dev_addr;
1367 #endif /* CONFIG_P2P */
1368 } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) {
1369 _bssid = NULL;
1370 multi_ap = atoi(cmd + 9);
1371 } else if (hwaddr_aton(cmd, bssid)) {
1372 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1373 cmd);
1374 return -1;
1375 }
1376
1377 if (cmd) {
1378 pos = os_strstr(cmd, " multi_ap=");
1379 if (pos) {
1380 pos += 10;
1381 multi_ap = atoi(pos);
1382 }
1383 }
1384
1385 #ifdef CONFIG_AP
1386 if (wpa_s->ap_iface)
1387 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1388 #endif /* CONFIG_AP */
1389
1390 return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap);
1391 }
1392
1393
wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)1394 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1395 char *cmd, char *buf,
1396 size_t buflen)
1397 {
1398 u8 bssid[ETH_ALEN], *_bssid = bssid;
1399 char *pin;
1400 int ret;
1401
1402 pin = os_strchr(cmd, ' ');
1403 if (pin)
1404 *pin++ = '\0';
1405
1406 if (os_strcmp(cmd, "any") == 0)
1407 _bssid = NULL;
1408 else if (os_strcmp(cmd, "get") == 0) {
1409 if (wps_generate_pin((unsigned int *) &ret) < 0)
1410 return -1;
1411 goto done;
1412 } else if (hwaddr_aton(cmd, bssid)) {
1413 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1414 cmd);
1415 return -1;
1416 }
1417
1418 #ifdef CONFIG_AP
1419 if (wpa_s->ap_iface) {
1420 int timeout = 0;
1421 char *pos;
1422
1423 if (pin) {
1424 pos = os_strchr(pin, ' ');
1425 if (pos) {
1426 *pos++ = '\0';
1427 timeout = atoi(pos);
1428 }
1429 }
1430
1431 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
1432 buf, buflen, timeout);
1433 }
1434 #endif /* CONFIG_AP */
1435
1436 if (pin) {
1437 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1438 DEV_PW_DEFAULT);
1439 if (ret < 0)
1440 return -1;
1441 ret = os_snprintf(buf, buflen, "%s", pin);
1442 if (os_snprintf_error(buflen, ret))
1443 return -1;
1444 return ret;
1445 }
1446
1447 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1448 if (ret < 0)
1449 return -1;
1450
1451 done:
1452 /* Return the generated PIN */
1453 ret = os_snprintf(buf, buflen, "%08d", ret);
1454 if (os_snprintf_error(buflen, ret))
1455 return -1;
1456 return ret;
1457 }
1458
1459
wpa_supplicant_ctrl_iface_wps_check_pin(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)1460 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1461 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1462 {
1463 char pin[9];
1464 size_t len;
1465 char *pos;
1466 int ret;
1467
1468 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1469 (u8 *) cmd, os_strlen(cmd));
1470 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1471 if (*pos < '0' || *pos > '9')
1472 continue;
1473 pin[len++] = *pos;
1474 if (len == 9) {
1475 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1476 return -1;
1477 }
1478 }
1479 if (len != 4 && len != 8) {
1480 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1481 return -1;
1482 }
1483 pin[len] = '\0';
1484
1485 if (len == 8) {
1486 unsigned int pin_val;
1487 pin_val = atoi(pin);
1488 if (!wps_pin_valid(pin_val)) {
1489 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1490 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
1491 if (os_snprintf_error(buflen, ret))
1492 return -1;
1493 return ret;
1494 }
1495 }
1496
1497 ret = os_snprintf(buf, buflen, "%s", pin);
1498 if (os_snprintf_error(buflen, ret))
1499 return -1;
1500
1501 return ret;
1502 }
1503
1504
1505 #ifdef CONFIG_WPS_NFC
1506
wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant * wpa_s,char * cmd)1507 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1508 char *cmd)
1509 {
1510 u8 bssid[ETH_ALEN], *_bssid = bssid;
1511
1512 if (cmd == NULL || cmd[0] == '\0')
1513 _bssid = NULL;
1514 else if (hwaddr_aton(cmd, bssid))
1515 return -1;
1516
1517 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1518 0, 0);
1519 }
1520
1521
wpa_supplicant_ctrl_iface_wps_nfc_config_token(struct wpa_supplicant * wpa_s,char * cmd,char * reply,size_t max_len)1522 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1523 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1524 {
1525 int ndef;
1526 struct wpabuf *buf;
1527 int res;
1528 char *pos;
1529
1530 pos = os_strchr(cmd, ' ');
1531 if (pos)
1532 *pos++ = '\0';
1533 if (os_strcmp(cmd, "WPS") == 0)
1534 ndef = 0;
1535 else if (os_strcmp(cmd, "NDEF") == 0)
1536 ndef = 1;
1537 else
1538 return -1;
1539
1540 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
1541 if (buf == NULL)
1542 return -1;
1543
1544 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1545 wpabuf_len(buf));
1546 reply[res++] = '\n';
1547 reply[res] = '\0';
1548
1549 wpabuf_free(buf);
1550
1551 return res;
1552 }
1553
1554
wpa_supplicant_ctrl_iface_wps_nfc_token(struct wpa_supplicant * wpa_s,char * cmd,char * reply,size_t max_len)1555 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1556 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1557 {
1558 int ndef;
1559 struct wpabuf *buf;
1560 int res;
1561
1562 if (os_strcmp(cmd, "WPS") == 0)
1563 ndef = 0;
1564 else if (os_strcmp(cmd, "NDEF") == 0)
1565 ndef = 1;
1566 else
1567 return -1;
1568
1569 buf = wpas_wps_nfc_token(wpa_s, ndef);
1570 if (buf == NULL)
1571 return -1;
1572
1573 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1574 wpabuf_len(buf));
1575 reply[res++] = '\n';
1576 reply[res] = '\0';
1577
1578 wpabuf_free(buf);
1579
1580 return res;
1581 }
1582
1583
wpa_supplicant_ctrl_iface_wps_nfc_tag_read(struct wpa_supplicant * wpa_s,char * pos)1584 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1585 struct wpa_supplicant *wpa_s, char *pos)
1586 {
1587 size_t len;
1588 struct wpabuf *buf;
1589 int ret;
1590 char *freq;
1591 int forced_freq = 0;
1592
1593 freq = strstr(pos, " freq=");
1594 if (freq) {
1595 *freq = '\0';
1596 freq += 6;
1597 forced_freq = atoi(freq);
1598 }
1599
1600 len = os_strlen(pos);
1601 if (len & 0x01)
1602 return -1;
1603 len /= 2;
1604
1605 buf = wpabuf_alloc(len);
1606 if (buf == NULL)
1607 return -1;
1608 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1609 wpabuf_free(buf);
1610 return -1;
1611 }
1612
1613 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
1614 wpabuf_free(buf);
1615
1616 return ret;
1617 }
1618
1619
wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant * wpa_s,char * reply,size_t max_len,int ndef)1620 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
1621 char *reply, size_t max_len,
1622 int ndef)
1623 {
1624 struct wpabuf *buf;
1625 int res;
1626
1627 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
1628 if (buf == NULL)
1629 return -1;
1630
1631 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1632 wpabuf_len(buf));
1633 reply[res++] = '\n';
1634 reply[res] = '\0';
1635
1636 wpabuf_free(buf);
1637
1638 return res;
1639 }
1640
1641
1642 #ifdef CONFIG_P2P
wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant * wpa_s,char * reply,size_t max_len,int ndef)1643 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1644 char *reply, size_t max_len,
1645 int ndef)
1646 {
1647 struct wpabuf *buf;
1648 int res;
1649
1650 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1651 if (buf == NULL) {
1652 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1653 return -1;
1654 }
1655
1656 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1657 wpabuf_len(buf));
1658 reply[res++] = '\n';
1659 reply[res] = '\0';
1660
1661 wpabuf_free(buf);
1662
1663 return res;
1664 }
1665 #endif /* CONFIG_P2P */
1666
1667
wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant * wpa_s,char * cmd,char * reply,size_t max_len)1668 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1669 char *cmd, char *reply,
1670 size_t max_len)
1671 {
1672 char *pos;
1673 int ndef;
1674
1675 pos = os_strchr(cmd, ' ');
1676 if (pos == NULL)
1677 return -1;
1678 *pos++ = '\0';
1679
1680 if (os_strcmp(cmd, "WPS") == 0)
1681 ndef = 0;
1682 else if (os_strcmp(cmd, "NDEF") == 0)
1683 ndef = 1;
1684 else
1685 return -1;
1686
1687 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1688 if (!ndef)
1689 return -1;
1690 return wpas_ctrl_nfc_get_handover_req_wps(
1691 wpa_s, reply, max_len, ndef);
1692 }
1693
1694 #ifdef CONFIG_P2P
1695 if (os_strcmp(pos, "P2P-CR") == 0) {
1696 return wpas_ctrl_nfc_get_handover_req_p2p(
1697 wpa_s, reply, max_len, ndef);
1698 }
1699 #endif /* CONFIG_P2P */
1700
1701 return -1;
1702 }
1703
1704
wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant * wpa_s,char * reply,size_t max_len,int ndef,int cr,char * uuid)1705 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1706 char *reply, size_t max_len,
1707 int ndef, int cr, char *uuid)
1708 {
1709 struct wpabuf *buf;
1710 int res;
1711
1712 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1713 if (buf == NULL)
1714 return -1;
1715
1716 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1717 wpabuf_len(buf));
1718 reply[res++] = '\n';
1719 reply[res] = '\0';
1720
1721 wpabuf_free(buf);
1722
1723 return res;
1724 }
1725
1726
1727 #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)1728 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1729 char *reply, size_t max_len,
1730 int ndef, int tag)
1731 {
1732 struct wpabuf *buf;
1733 int res;
1734
1735 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1736 if (buf == NULL)
1737 return -1;
1738
1739 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1740 wpabuf_len(buf));
1741 reply[res++] = '\n';
1742 reply[res] = '\0';
1743
1744 wpabuf_free(buf);
1745
1746 return res;
1747 }
1748 #endif /* CONFIG_P2P */
1749
1750
wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant * wpa_s,char * cmd,char * reply,size_t max_len)1751 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1752 char *cmd, char *reply,
1753 size_t max_len)
1754 {
1755 char *pos, *pos2;
1756 int ndef;
1757
1758 pos = os_strchr(cmd, ' ');
1759 if (pos == NULL)
1760 return -1;
1761 *pos++ = '\0';
1762
1763 if (os_strcmp(cmd, "WPS") == 0)
1764 ndef = 0;
1765 else if (os_strcmp(cmd, "NDEF") == 0)
1766 ndef = 1;
1767 else
1768 return -1;
1769
1770 pos2 = os_strchr(pos, ' ');
1771 if (pos2)
1772 *pos2++ = '\0';
1773 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1774 if (!ndef)
1775 return -1;
1776 return wpas_ctrl_nfc_get_handover_sel_wps(
1777 wpa_s, reply, max_len, ndef,
1778 os_strcmp(pos, "WPS-CR") == 0, pos2);
1779 }
1780
1781 #ifdef CONFIG_P2P
1782 if (os_strcmp(pos, "P2P-CR") == 0) {
1783 return wpas_ctrl_nfc_get_handover_sel_p2p(
1784 wpa_s, reply, max_len, ndef, 0);
1785 }
1786
1787 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1788 return wpas_ctrl_nfc_get_handover_sel_p2p(
1789 wpa_s, reply, max_len, ndef, 1);
1790 }
1791 #endif /* CONFIG_P2P */
1792
1793 return -1;
1794 }
1795
1796
wpas_ctrl_nfc_report_handover(struct wpa_supplicant * wpa_s,char * cmd)1797 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1798 char *cmd)
1799 {
1800 size_t len;
1801 struct wpabuf *req, *sel;
1802 int ret;
1803 char *pos, *role, *type, *pos2;
1804 #ifdef CONFIG_P2P
1805 char *freq;
1806 int forced_freq = 0;
1807
1808 freq = strstr(cmd, " freq=");
1809 if (freq) {
1810 *freq = '\0';
1811 freq += 6;
1812 forced_freq = atoi(freq);
1813 }
1814 #endif /* CONFIG_P2P */
1815
1816 role = cmd;
1817 pos = os_strchr(role, ' ');
1818 if (pos == NULL) {
1819 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1820 return -1;
1821 }
1822 *pos++ = '\0';
1823
1824 type = pos;
1825 pos = os_strchr(type, ' ');
1826 if (pos == NULL) {
1827 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1828 return -1;
1829 }
1830 *pos++ = '\0';
1831
1832 pos2 = os_strchr(pos, ' ');
1833 if (pos2 == NULL) {
1834 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1835 return -1;
1836 }
1837 *pos2++ = '\0';
1838
1839 len = os_strlen(pos);
1840 if (len & 0x01) {
1841 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1842 return -1;
1843 }
1844 len /= 2;
1845
1846 req = wpabuf_alloc(len);
1847 if (req == NULL) {
1848 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1849 return -1;
1850 }
1851 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1852 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1853 wpabuf_free(req);
1854 return -1;
1855 }
1856
1857 len = os_strlen(pos2);
1858 if (len & 0x01) {
1859 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1860 wpabuf_free(req);
1861 return -1;
1862 }
1863 len /= 2;
1864
1865 sel = wpabuf_alloc(len);
1866 if (sel == NULL) {
1867 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1868 wpabuf_free(req);
1869 return -1;
1870 }
1871 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1872 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1873 wpabuf_free(req);
1874 wpabuf_free(sel);
1875 return -1;
1876 }
1877
1878 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1879 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1880
1881 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1882 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1883 #ifdef CONFIG_AP
1884 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1885 {
1886 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1887 if (ret < 0)
1888 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1889 #endif /* CONFIG_AP */
1890 #ifdef CONFIG_P2P
1891 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1892 {
1893 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1894 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1895 {
1896 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1897 forced_freq);
1898 #endif /* CONFIG_P2P */
1899 } else {
1900 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1901 "reported: role=%s type=%s", role, type);
1902 ret = -1;
1903 }
1904 wpabuf_free(req);
1905 wpabuf_free(sel);
1906
1907 if (ret)
1908 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1909
1910 return ret;
1911 }
1912
1913 #endif /* CONFIG_WPS_NFC */
1914
1915
wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant * wpa_s,char * cmd)1916 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1917 char *cmd)
1918 {
1919 u8 bssid[ETH_ALEN];
1920 char *pin;
1921 char *new_ssid;
1922 char *new_auth;
1923 char *new_encr;
1924 char *new_key;
1925 struct wps_new_ap_settings ap;
1926
1927 pin = os_strchr(cmd, ' ');
1928 if (pin == NULL)
1929 return -1;
1930 *pin++ = '\0';
1931
1932 if (hwaddr_aton(cmd, bssid)) {
1933 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1934 cmd);
1935 return -1;
1936 }
1937
1938 new_ssid = os_strchr(pin, ' ');
1939 if (new_ssid == NULL)
1940 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1941 *new_ssid++ = '\0';
1942
1943 new_auth = os_strchr(new_ssid, ' ');
1944 if (new_auth == NULL)
1945 return -1;
1946 *new_auth++ = '\0';
1947
1948 new_encr = os_strchr(new_auth, ' ');
1949 if (new_encr == NULL)
1950 return -1;
1951 *new_encr++ = '\0';
1952
1953 new_key = os_strchr(new_encr, ' ');
1954 if (new_key == NULL)
1955 return -1;
1956 *new_key++ = '\0';
1957
1958 os_memset(&ap, 0, sizeof(ap));
1959 ap.ssid_hex = new_ssid;
1960 ap.auth = new_auth;
1961 ap.encr = new_encr;
1962 ap.key_hex = new_key;
1963 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1964 }
1965
1966
1967 #ifdef CONFIG_AP
wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)1968 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1969 char *cmd, char *buf,
1970 size_t buflen)
1971 {
1972 int timeout = 300;
1973 char *pos;
1974 const char *pin_txt;
1975
1976 if (!wpa_s->ap_iface)
1977 return -1;
1978
1979 pos = os_strchr(cmd, ' ');
1980 if (pos)
1981 *pos++ = '\0';
1982
1983 if (os_strcmp(cmd, "disable") == 0) {
1984 wpas_wps_ap_pin_disable(wpa_s);
1985 return os_snprintf(buf, buflen, "OK\n");
1986 }
1987
1988 if (os_strcmp(cmd, "random") == 0) {
1989 if (pos)
1990 timeout = atoi(pos);
1991 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1992 if (pin_txt == NULL)
1993 return -1;
1994 return os_snprintf(buf, buflen, "%s", pin_txt);
1995 }
1996
1997 if (os_strcmp(cmd, "get") == 0) {
1998 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1999 if (pin_txt == NULL)
2000 return -1;
2001 return os_snprintf(buf, buflen, "%s", pin_txt);
2002 }
2003
2004 if (os_strcmp(cmd, "set") == 0) {
2005 char *pin;
2006 if (pos == NULL)
2007 return -1;
2008 pin = pos;
2009 pos = os_strchr(pos, ' ');
2010 if (pos) {
2011 *pos++ = '\0';
2012 timeout = atoi(pos);
2013 }
2014 if (os_strlen(pin) > buflen)
2015 return -1;
2016 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
2017 return -1;
2018 return os_snprintf(buf, buflen, "%s", pin);
2019 }
2020
2021 return -1;
2022 }
2023 #endif /* CONFIG_AP */
2024
2025
2026 #ifdef CONFIG_WPS_ER
wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant * wpa_s,char * cmd)2027 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
2028 char *cmd)
2029 {
2030 char *uuid = cmd, *pin, *pos;
2031 u8 addr_buf[ETH_ALEN], *addr = NULL;
2032 pin = os_strchr(uuid, ' ');
2033 if (pin == NULL)
2034 return -1;
2035 *pin++ = '\0';
2036 pos = os_strchr(pin, ' ');
2037 if (pos) {
2038 *pos++ = '\0';
2039 if (hwaddr_aton(pos, addr_buf) == 0)
2040 addr = addr_buf;
2041 }
2042 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
2043 }
2044
2045
wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant * wpa_s,char * cmd)2046 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
2047 char *cmd)
2048 {
2049 char *uuid = cmd, *pin;
2050 pin = os_strchr(uuid, ' ');
2051 if (pin == NULL)
2052 return -1;
2053 *pin++ = '\0';
2054 return wpas_wps_er_learn(wpa_s, uuid, pin);
2055 }
2056
2057
wpa_supplicant_ctrl_iface_wps_er_set_config(struct wpa_supplicant * wpa_s,char * cmd)2058 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
2059 struct wpa_supplicant *wpa_s, char *cmd)
2060 {
2061 char *uuid = cmd, *id;
2062 id = os_strchr(uuid, ' ');
2063 if (id == NULL)
2064 return -1;
2065 *id++ = '\0';
2066 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
2067 }
2068
2069
wpa_supplicant_ctrl_iface_wps_er_config(struct wpa_supplicant * wpa_s,char * cmd)2070 static int wpa_supplicant_ctrl_iface_wps_er_config(
2071 struct wpa_supplicant *wpa_s, char *cmd)
2072 {
2073 char *pin;
2074 char *new_ssid;
2075 char *new_auth;
2076 char *new_encr;
2077 char *new_key;
2078 struct wps_new_ap_settings ap;
2079
2080 pin = os_strchr(cmd, ' ');
2081 if (pin == NULL)
2082 return -1;
2083 *pin++ = '\0';
2084
2085 new_ssid = os_strchr(pin, ' ');
2086 if (new_ssid == NULL)
2087 return -1;
2088 *new_ssid++ = '\0';
2089
2090 new_auth = os_strchr(new_ssid, ' ');
2091 if (new_auth == NULL)
2092 return -1;
2093 *new_auth++ = '\0';
2094
2095 new_encr = os_strchr(new_auth, ' ');
2096 if (new_encr == NULL)
2097 return -1;
2098 *new_encr++ = '\0';
2099
2100 new_key = os_strchr(new_encr, ' ');
2101 if (new_key == NULL)
2102 return -1;
2103 *new_key++ = '\0';
2104
2105 os_memset(&ap, 0, sizeof(ap));
2106 ap.ssid_hex = new_ssid;
2107 ap.auth = new_auth;
2108 ap.encr = new_encr;
2109 ap.key_hex = new_key;
2110 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
2111 }
2112
2113
2114 #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)2115 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
2116 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2117 {
2118 int ndef;
2119 struct wpabuf *buf;
2120 int res;
2121 char *uuid;
2122
2123 uuid = os_strchr(cmd, ' ');
2124 if (uuid == NULL)
2125 return -1;
2126 *uuid++ = '\0';
2127
2128 if (os_strcmp(cmd, "WPS") == 0)
2129 ndef = 0;
2130 else if (os_strcmp(cmd, "NDEF") == 0)
2131 ndef = 1;
2132 else
2133 return -1;
2134
2135 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
2136 if (buf == NULL)
2137 return -1;
2138
2139 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
2140 wpabuf_len(buf));
2141 reply[res++] = '\n';
2142 reply[res] = '\0';
2143
2144 wpabuf_free(buf);
2145
2146 return res;
2147 }
2148 #endif /* CONFIG_WPS_NFC */
2149 #endif /* CONFIG_WPS_ER */
2150
2151 #endif /* CONFIG_WPS */
2152
2153
2154 #ifdef CONFIG_IBSS_RSN
wpa_supplicant_ctrl_iface_ibss_rsn(struct wpa_supplicant * wpa_s,char * addr)2155 static int wpa_supplicant_ctrl_iface_ibss_rsn(
2156 struct wpa_supplicant *wpa_s, char *addr)
2157 {
2158 u8 peer[ETH_ALEN];
2159
2160 if (hwaddr_aton(addr, peer)) {
2161 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
2162 "address '%s'", addr);
2163 return -1;
2164 }
2165
2166 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
2167 MAC2STR(peer));
2168
2169 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
2170 }
2171 #endif /* CONFIG_IBSS_RSN */
2172
2173
wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant * wpa_s,char * rsp)2174 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
2175 char *rsp)
2176 {
2177 #ifdef IEEE8021X_EAPOL
2178 char *pos, *id_pos;
2179 int id;
2180 struct wpa_ssid *ssid;
2181
2182 pos = os_strchr(rsp, '-');
2183 if (pos == NULL)
2184 return -1;
2185 *pos++ = '\0';
2186 id_pos = pos;
2187 pos = os_strchr(pos, ':');
2188 if (pos == NULL)
2189 return -1;
2190 *pos++ = '\0';
2191 id = atoi(id_pos);
2192 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
2193 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2194 (u8 *) pos, os_strlen(pos));
2195
2196 ssid = wpa_config_get_network(wpa_s->conf, id);
2197 if (ssid == NULL) {
2198 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2199 "to update", id);
2200 return -1;
2201 }
2202
2203 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2204 pos);
2205 #else /* IEEE8021X_EAPOL */
2206 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2207 return -1;
2208 #endif /* IEEE8021X_EAPOL */
2209 }
2210
2211
wpa_supplicant_ctrl_iface_status(struct wpa_supplicant * wpa_s,const char * params,char * buf,size_t buflen)2212 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2213 const char *params,
2214 char *buf, size_t buflen)
2215 {
2216 char *pos, *end, tmp[30];
2217 int res, verbose, wps, ret;
2218 #ifdef CONFIG_HS20
2219 const u8 *hs20;
2220 #endif /* CONFIG_HS20 */
2221 const u8 *sess_id;
2222 size_t sess_id_len;
2223
2224 if (os_strcmp(params, "-DRIVER") == 0)
2225 return wpa_drv_status(wpa_s, buf, buflen);
2226 verbose = os_strcmp(params, "-VERBOSE") == 0;
2227 wps = os_strcmp(params, "-WPS") == 0;
2228 pos = buf;
2229 end = buf + buflen;
2230 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2231 struct wpa_ssid *ssid = wpa_s->current_ssid;
2232 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2233 MAC2STR(wpa_s->bssid));
2234 if (os_snprintf_error(end - pos, ret))
2235 return pos - buf;
2236 pos += ret;
2237 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2238 wpa_s->assoc_freq);
2239 if (os_snprintf_error(end - pos, ret))
2240 return pos - buf;
2241 pos += ret;
2242 if (ssid) {
2243 u8 *_ssid = ssid->ssid;
2244 size_t ssid_len = ssid->ssid_len;
2245 u8 ssid_buf[SSID_MAX_LEN];
2246 if (ssid_len == 0) {
2247 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2248 if (_res < 0)
2249 ssid_len = 0;
2250 else
2251 ssid_len = _res;
2252 _ssid = ssid_buf;
2253 }
2254 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2255 wpa_ssid_txt(_ssid, ssid_len),
2256 ssid->id);
2257 if (os_snprintf_error(end - pos, ret))
2258 return pos - buf;
2259 pos += ret;
2260
2261 if (wps && ssid->passphrase &&
2262 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2263 (ssid->mode == WPAS_MODE_AP ||
2264 ssid->mode == WPAS_MODE_P2P_GO)) {
2265 ret = os_snprintf(pos, end - pos,
2266 "passphrase=%s\n",
2267 ssid->passphrase);
2268 if (os_snprintf_error(end - pos, ret))
2269 return pos - buf;
2270 pos += ret;
2271 }
2272 if (ssid->id_str) {
2273 ret = os_snprintf(pos, end - pos,
2274 "id_str=%s\n",
2275 ssid->id_str);
2276 if (os_snprintf_error(end - pos, ret))
2277 return pos - buf;
2278 pos += ret;
2279 }
2280
2281 switch (ssid->mode) {
2282 case WPAS_MODE_INFRA:
2283 ret = os_snprintf(pos, end - pos,
2284 "mode=station\n");
2285 break;
2286 case WPAS_MODE_IBSS:
2287 ret = os_snprintf(pos, end - pos,
2288 "mode=IBSS\n");
2289 break;
2290 case WPAS_MODE_AP:
2291 ret = os_snprintf(pos, end - pos,
2292 "mode=AP\n");
2293 break;
2294 case WPAS_MODE_P2P_GO:
2295 ret = os_snprintf(pos, end - pos,
2296 "mode=P2P GO\n");
2297 break;
2298 case WPAS_MODE_P2P_GROUP_FORMATION:
2299 ret = os_snprintf(pos, end - pos,
2300 "mode=P2P GO - group "
2301 "formation\n");
2302 break;
2303 case WPAS_MODE_MESH:
2304 ret = os_snprintf(pos, end - pos,
2305 "mode=mesh\n");
2306 break;
2307 default:
2308 ret = 0;
2309 break;
2310 }
2311 if (os_snprintf_error(end - pos, ret))
2312 return pos - buf;
2313 pos += ret;
2314 }
2315
2316 if (wpa_s->connection_set &&
2317 (wpa_s->connection_ht || wpa_s->connection_vht ||
2318 wpa_s->connection_he || wpa_s->connection_eht)) {
2319 ret = os_snprintf(pos, end - pos,
2320 "wifi_generation=%u\n",
2321 wpa_s->connection_eht ? 7 :
2322 (wpa_s->connection_he ? 6 :
2323 (wpa_s->connection_vht ? 5 : 4)));
2324 if (os_snprintf_error(end - pos, ret))
2325 return pos - buf;
2326 pos += ret;
2327 }
2328
2329 #ifdef CONFIG_AP
2330 if (wpa_s->ap_iface) {
2331 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2332 end - pos,
2333 verbose);
2334 } else
2335 #endif /* CONFIG_AP */
2336 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2337 }
2338 #ifdef CONFIG_SME
2339 #ifdef CONFIG_SAE
2340 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
2341 #ifdef CONFIG_AP
2342 !wpa_s->ap_iface &&
2343 #endif /* CONFIG_AP */
2344 wpa_s->sme.sae.state == SAE_ACCEPTED) {
2345 ret = os_snprintf(pos, end - pos, "sae_group=%d\n"
2346 "sae_h2e=%d\n"
2347 "sae_pk=%d\n",
2348 wpa_s->sme.sae.group,
2349 wpa_s->sme.sae.h2e,
2350 wpa_s->sme.sae.pk);
2351 if (os_snprintf_error(end - pos, ret))
2352 return pos - buf;
2353 pos += ret;
2354 }
2355 #endif /* CONFIG_SAE */
2356 #endif /* CONFIG_SME */
2357 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2358 wpa_supplicant_state_txt(wpa_s->wpa_state));
2359 if (os_snprintf_error(end - pos, ret))
2360 return pos - buf;
2361 pos += ret;
2362
2363 if (wpa_s->l2 &&
2364 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2365 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
2366 if (os_snprintf_error(end - pos, ret))
2367 return pos - buf;
2368 pos += ret;
2369 }
2370
2371 #ifdef CONFIG_P2P
2372 if (wpa_s->global->p2p) {
2373 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2374 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
2375 if (os_snprintf_error(end - pos, ret))
2376 return pos - buf;
2377 pos += ret;
2378 }
2379 #endif /* CONFIG_P2P */
2380
2381 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2382 MAC2STR(wpa_s->own_addr));
2383 if (os_snprintf_error(end - pos, ret))
2384 return pos - buf;
2385 pos += ret;
2386
2387 if (wpa_s->valid_links) {
2388 ret = os_snprintf(pos, end - pos, "ap_mld_addr=" MACSTR "\n",
2389 MAC2STR(wpa_s->ap_mld_addr));
2390 if (os_snprintf_error(end - pos, ret))
2391 return pos - buf;
2392 pos += ret;
2393 }
2394
2395 #ifdef CONFIG_HS20
2396 if (wpa_s->current_bss &&
2397 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2398 HS20_IE_VENDOR_TYPE)) &&
2399 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2400 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
2401 int release = 1;
2402 if (hs20[1] >= 5) {
2403 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2404 release = rel_num + 1;
2405 }
2406 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
2407 if (os_snprintf_error(end - pos, ret))
2408 return pos - buf;
2409 pos += ret;
2410 }
2411
2412 if (wpa_s->current_ssid) {
2413 struct wpa_cred *cred;
2414 char *type;
2415
2416 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
2417 size_t i;
2418
2419 if (wpa_s->current_ssid->parent_cred != cred)
2420 continue;
2421
2422 if (cred->provisioning_sp) {
2423 ret = os_snprintf(pos, end - pos,
2424 "provisioning_sp=%s\n",
2425 cred->provisioning_sp);
2426 if (os_snprintf_error(end - pos, ret))
2427 return pos - buf;
2428 pos += ret;
2429 }
2430
2431 if (!cred->domain)
2432 goto no_domain;
2433
2434 i = 0;
2435 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2436 struct wpabuf *names =
2437 wpa_s->current_bss->anqp->domain_name;
2438 for (i = 0; names && i < cred->num_domain; i++)
2439 {
2440 if (domain_name_list_contains(
2441 names, cred->domain[i], 1))
2442 break;
2443 }
2444 if (i == cred->num_domain)
2445 i = 0; /* show first entry by default */
2446 }
2447 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2448 cred->domain[i]);
2449 if (os_snprintf_error(end - pos, ret))
2450 return pos - buf;
2451 pos += ret;
2452
2453 no_domain:
2454 if (wpa_s->current_bss == NULL ||
2455 wpa_s->current_bss->anqp == NULL)
2456 res = -1;
2457 else
2458 res = interworking_home_sp_cred(
2459 wpa_s, cred,
2460 wpa_s->current_bss->anqp->domain_name);
2461 if (res > 0)
2462 type = "home";
2463 else if (res == 0)
2464 type = "roaming";
2465 else
2466 type = "unknown";
2467
2468 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
2469 if (os_snprintf_error(end - pos, ret))
2470 return pos - buf;
2471 pos += ret;
2472
2473 break;
2474 }
2475 }
2476 #endif /* CONFIG_HS20 */
2477
2478 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2479 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2480 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2481 verbose);
2482 if (res >= 0)
2483 pos += res;
2484 }
2485
2486 #ifdef CONFIG_MACSEC
2487 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2488 if (res > 0)
2489 pos += res;
2490 #endif /* CONFIG_MACSEC */
2491
2492 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2493 if (sess_id) {
2494 char *start = pos;
2495
2496 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2497 if (os_snprintf_error(end - pos, ret))
2498 return start - buf;
2499 pos += ret;
2500 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2501 if (ret <= 0)
2502 return start - buf;
2503 pos += ret;
2504 ret = os_snprintf(pos, end - pos, "\n");
2505 if (os_snprintf_error(end - pos, ret))
2506 return start - buf;
2507 pos += ret;
2508 }
2509
2510 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2511 if (res >= 0)
2512 pos += res;
2513
2514 #ifdef CONFIG_WPS
2515 {
2516 char uuid_str[100];
2517 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2518 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
2519 if (os_snprintf_error(end - pos, ret))
2520 return pos - buf;
2521 pos += ret;
2522 }
2523 #endif /* CONFIG_WPS */
2524
2525 if (wpa_s->ieee80211ac) {
2526 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2527 if (os_snprintf_error(end - pos, ret))
2528 return pos - buf;
2529 pos += ret;
2530 }
2531
2532 #ifdef ANDROID
2533 /*
2534 * Allow using the STATUS command with default behavior, say for debug,
2535 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2536 * events with STATUS-NO_EVENTS.
2537 */
2538 if (os_strcmp(params, "-NO_EVENTS")) {
2539 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2540 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2541 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2542 wpa_s->wpa_state,
2543 MAC2STR(wpa_s->bssid),
2544 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2545 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2546 wpa_s->current_ssid->ssid_len) : "");
2547 if (wpa_s->wpa_state == WPA_COMPLETED) {
2548 struct wpa_ssid *ssid = wpa_s->current_ssid;
2549 char mld_addr[50];
2550
2551 mld_addr[0] = '\0';
2552 if (wpa_s->valid_links)
2553 os_snprintf(mld_addr, sizeof(mld_addr),
2554 " ap_mld_addr=" MACSTR,
2555 MAC2STR(wpa_s->ap_mld_addr));
2556
2557 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2558 "- connection to " MACSTR
2559 " completed %s [id=%d id_str=%s]%s",
2560 MAC2STR(wpa_s->bssid), "(auth)",
2561 ssid ? ssid->id : -1,
2562 ssid && ssid->id_str ? ssid->id_str : "",
2563 mld_addr);
2564 }
2565 }
2566 #endif /* ANDROID */
2567
2568 return pos - buf;
2569 }
2570
2571
wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant * wpa_s,char * cmd)2572 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2573 char *cmd)
2574 {
2575 char *pos;
2576 int id;
2577 struct wpa_ssid *ssid;
2578 u8 bssid[ETH_ALEN];
2579
2580 /* cmd: "<network id> <BSSID>" */
2581 pos = os_strchr(cmd, ' ');
2582 if (pos == NULL)
2583 return -1;
2584 *pos++ = '\0';
2585 id = atoi(cmd);
2586 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2587 if (hwaddr_aton(pos, bssid)) {
2588 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2589 return -1;
2590 }
2591
2592 ssid = wpa_config_get_network(wpa_s->conf, id);
2593 if (ssid == NULL) {
2594 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2595 "to update", id);
2596 return -1;
2597 }
2598
2599 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2600 ssid->bssid_set = !is_zero_ether_addr(bssid);
2601
2602 return 0;
2603 }
2604
2605
wpa_supplicant_ctrl_iface_bssid_ignore(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)2606 static int wpa_supplicant_ctrl_iface_bssid_ignore(struct wpa_supplicant *wpa_s,
2607 char *cmd, char *buf,
2608 size_t buflen)
2609 {
2610 u8 bssid[ETH_ALEN];
2611 struct wpa_bssid_ignore *e;
2612 char *pos, *end;
2613 int ret;
2614
2615 /* cmd: "BSSID_IGNORE [<BSSID>]" */
2616 if (*cmd == '\0') {
2617 pos = buf;
2618 end = buf + buflen;
2619 e = wpa_s->bssid_ignore;
2620 while (e) {
2621 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2622 MAC2STR(e->bssid));
2623 if (os_snprintf_error(end - pos, ret))
2624 return pos - buf;
2625 pos += ret;
2626 e = e->next;
2627 }
2628 return pos - buf;
2629 }
2630
2631 cmd++;
2632 if (os_strncmp(cmd, "clear", 5) == 0) {
2633 wpa_bssid_ignore_clear(wpa_s);
2634 os_memcpy(buf, "OK\n", 3);
2635 return 3;
2636 }
2637
2638 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BSSID_IGNORE bssid='%s'", cmd);
2639 if (hwaddr_aton(cmd, bssid)) {
2640 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
2641 return -1;
2642 }
2643
2644 /*
2645 * Add the BSSID twice, so its count will be 2, causing it to be
2646 * skipped when processing scan results.
2647 */
2648 ret = wpa_bssid_ignore_add(wpa_s, bssid);
2649 if (ret < 0)
2650 return -1;
2651 ret = wpa_bssid_ignore_add(wpa_s, bssid);
2652 if (ret < 0)
2653 return -1;
2654 os_memcpy(buf, "OK\n", 3);
2655 return 3;
2656 }
2657
2658
wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)2659 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2660 char *cmd, char *buf,
2661 size_t buflen)
2662 {
2663 char *pos, *end, *stamp;
2664 int ret;
2665
2666 /* cmd: "LOG_LEVEL [<level>]" */
2667 if (*cmd == '\0') {
2668 pos = buf;
2669 end = buf + buflen;
2670 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2671 "Timestamp: %d\n",
2672 debug_level_str(wpa_debug_level),
2673 wpa_debug_timestamp);
2674 if (os_snprintf_error(end - pos, ret))
2675 ret = 0;
2676
2677 return ret;
2678 }
2679
2680 while (*cmd == ' ')
2681 cmd++;
2682
2683 stamp = os_strchr(cmd, ' ');
2684 if (stamp) {
2685 *stamp++ = '\0';
2686 while (*stamp == ' ') {
2687 stamp++;
2688 }
2689 }
2690
2691 if (os_strlen(cmd)) {
2692 int level = str_to_debug_level(cmd);
2693 if (level < 0)
2694 return -1;
2695 wpa_debug_level = level;
2696 }
2697
2698 if (stamp && os_strlen(stamp))
2699 wpa_debug_timestamp = atoi(stamp);
2700
2701 os_memcpy(buf, "OK\n", 3);
2702 return 3;
2703 }
2704
2705
wpa_supplicant_ctrl_iface_list_networks(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)2706 static int wpa_supplicant_ctrl_iface_list_networks(
2707 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2708 {
2709 char *pos, *end, *prev;
2710 struct wpa_ssid *ssid;
2711 int ret;
2712
2713 pos = buf;
2714 end = buf + buflen;
2715 ret = os_snprintf(pos, end - pos,
2716 "network id / ssid / bssid / flags\n");
2717 if (os_snprintf_error(end - pos, ret))
2718 return pos - buf;
2719 pos += ret;
2720
2721 ssid = wpa_s->conf->ssid;
2722
2723 /* skip over ssids until we find next one */
2724 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2725 int last_id = atoi(cmd + 8);
2726 if (last_id != -1) {
2727 while (ssid != NULL && ssid->id <= last_id) {
2728 ssid = ssid->next;
2729 }
2730 }
2731 }
2732
2733 while (ssid) {
2734 prev = pos;
2735 ret = os_snprintf(pos, end - pos, "%d\t%s",
2736 ssid->id,
2737 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2738 if (os_snprintf_error(end - pos, ret))
2739 return prev - buf;
2740 pos += ret;
2741 if (ssid->bssid_set) {
2742 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2743 MAC2STR(ssid->bssid));
2744 } else {
2745 ret = os_snprintf(pos, end - pos, "\tany");
2746 }
2747 if (os_snprintf_error(end - pos, ret))
2748 return prev - buf;
2749 pos += ret;
2750 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2751 ssid == wpa_s->current_ssid ?
2752 "[CURRENT]" : "",
2753 ssid->disabled ? "[DISABLED]" : "",
2754 ssid->disabled_until.sec ?
2755 "[TEMP-DISABLED]" : "",
2756 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2757 "");
2758 if (os_snprintf_error(end - pos, ret))
2759 return prev - buf;
2760 pos += ret;
2761 ret = os_snprintf(pos, end - pos, "\n");
2762 if (os_snprintf_error(end - pos, ret))
2763 return prev - buf;
2764 pos += ret;
2765
2766 ssid = ssid->next;
2767 }
2768
2769 return pos - buf;
2770 }
2771
2772
wpa_supplicant_cipher_txt(char * pos,char * end,int cipher)2773 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2774 {
2775 int ret;
2776 ret = os_snprintf(pos, end - pos, "-");
2777 if (os_snprintf_error(end - pos, ret))
2778 return pos;
2779 pos += ret;
2780 ret = wpa_write_ciphers(pos, end, cipher, "+");
2781 if (ret < 0)
2782 return pos;
2783 pos += ret;
2784 return pos;
2785 }
2786
2787
wpa_supplicant_ie_txt(char * pos,char * end,const char * proto,const u8 * ie,size_t ie_len)2788 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2789 const u8 *ie, size_t ie_len)
2790 {
2791 struct wpa_ie_data data;
2792 char *start;
2793 int ret;
2794
2795 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2796 if (os_snprintf_error(end - pos, ret))
2797 return pos;
2798 pos += ret;
2799
2800 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2801 ret = os_snprintf(pos, end - pos, "?]");
2802 if (os_snprintf_error(end - pos, ret))
2803 return pos;
2804 pos += ret;
2805 return pos;
2806 }
2807
2808 start = pos;
2809 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2810 ret = os_snprintf(pos, end - pos, "%sEAP",
2811 pos == start ? "" : "+");
2812 if (os_snprintf_error(end - pos, ret))
2813 return pos;
2814 pos += ret;
2815 }
2816 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2817 ret = os_snprintf(pos, end - pos, "%sPSK",
2818 pos == start ? "" : "+");
2819 if (os_snprintf_error(end - pos, ret))
2820 return pos;
2821 pos += ret;
2822 }
2823 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2824 ret = os_snprintf(pos, end - pos, "%sNone",
2825 pos == start ? "" : "+");
2826 if (os_snprintf_error(end - pos, ret))
2827 return pos;
2828 pos += ret;
2829 }
2830 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2831 ret = os_snprintf(pos, end - pos, "%sSAE",
2832 pos == start ? "" : "+");
2833 if (os_snprintf_error(end - pos, ret))
2834 return pos;
2835 pos += ret;
2836 }
2837 if (data.key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) {
2838 ret = os_snprintf(pos, end - pos, "%sSAE-EXT-KEY",
2839 pos == start ? "" : "+");
2840 if (os_snprintf_error(end - pos, ret))
2841 return pos;
2842 pos += ret;
2843 }
2844 #ifdef CONFIG_IEEE80211R
2845 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2846 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2847 pos == start ? "" : "+");
2848 if (os_snprintf_error(end - pos, ret))
2849 return pos;
2850 pos += ret;
2851 }
2852 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2853 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2854 pos == start ? "" : "+");
2855 if (os_snprintf_error(end - pos, ret))
2856 return pos;
2857 pos += ret;
2858 }
2859 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2860 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2861 pos == start ? "" : "+");
2862 if (os_snprintf_error(end - pos, ret))
2863 return pos;
2864 pos += ret;
2865 }
2866 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE_EXT_KEY) {
2867 ret = os_snprintf(pos, end - pos, "%sFT/SAE-EXT-KEY",
2868 pos == start ? "" : "+");
2869 if (os_snprintf_error(end - pos, ret))
2870 return pos;
2871 pos += ret;
2872 }
2873 #endif /* CONFIG_IEEE80211R */
2874 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2875 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2876 pos == start ? "" : "+");
2877 if (os_snprintf_error(end - pos, ret))
2878 return pos;
2879 pos += ret;
2880 }
2881 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2882 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2883 pos == start ? "" : "+");
2884 if (os_snprintf_error(end - pos, ret))
2885 return pos;
2886 pos += ret;
2887 }
2888
2889 #ifdef CONFIG_SUITEB
2890 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2891 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2892 pos == start ? "" : "+");
2893 if (os_snprintf_error(end - pos, ret))
2894 return pos;
2895 pos += ret;
2896 }
2897 #endif /* CONFIG_SUITEB */
2898
2899 #ifdef CONFIG_SUITEB192
2900 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2901 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2902 pos == start ? "" : "+");
2903 if (os_snprintf_error(end - pos, ret))
2904 return pos;
2905 pos += ret;
2906 }
2907 #endif /* CONFIG_SUITEB192 */
2908
2909 #ifdef CONFIG_FILS
2910 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2911 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2912 pos == start ? "" : "+");
2913 if (os_snprintf_error(end - pos, ret))
2914 return pos;
2915 pos += ret;
2916 }
2917 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2918 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2919 pos == start ? "" : "+");
2920 if (os_snprintf_error(end - pos, ret))
2921 return pos;
2922 pos += ret;
2923 }
2924 #ifdef CONFIG_IEEE80211R
2925 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2926 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2927 pos == start ? "" : "+");
2928 if (os_snprintf_error(end - pos, ret))
2929 return pos;
2930 pos += ret;
2931 }
2932 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2933 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2934 pos == start ? "" : "+");
2935 if (os_snprintf_error(end - pos, ret))
2936 return pos;
2937 pos += ret;
2938 }
2939 #endif /* CONFIG_IEEE80211R */
2940 #endif /* CONFIG_FILS */
2941
2942 #ifdef CONFIG_OWE
2943 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2944 ret = os_snprintf(pos, end - pos, "%sOWE",
2945 pos == start ? "" : "+");
2946 if (os_snprintf_error(end - pos, ret))
2947 return pos;
2948 pos += ret;
2949 }
2950 #endif /* CONFIG_OWE */
2951
2952 #ifdef CONFIG_DPP
2953 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
2954 ret = os_snprintf(pos, end - pos, "%sDPP",
2955 pos == start ? "" : "+");
2956 if (os_snprintf_error(end - pos, ret))
2957 return pos;
2958 pos += ret;
2959 }
2960 #endif /* CONFIG_DPP */
2961
2962 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2963 ret = os_snprintf(pos, end - pos, "%sOSEN",
2964 pos == start ? "" : "+");
2965 if (os_snprintf_error(end - pos, ret))
2966 return pos;
2967 pos += ret;
2968 }
2969
2970 #ifdef CONFIG_SHA384
2971 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA384) {
2972 ret = os_snprintf(pos, end - pos, "%sEAP-SHA384",
2973 pos == start ? "" : "+");
2974 if (os_snprintf_error(end - pos, ret))
2975 return pos;
2976 pos += ret;
2977 }
2978 #endif /* CONFIG_SHA384 */
2979
2980 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2981
2982 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2983 ret = os_snprintf(pos, end - pos, "-preauth");
2984 if (os_snprintf_error(end - pos, ret))
2985 return pos;
2986 pos += ret;
2987 }
2988
2989 ret = os_snprintf(pos, end - pos, "]");
2990 if (os_snprintf_error(end - pos, ret))
2991 return pos;
2992 pos += ret;
2993
2994 return pos;
2995 }
2996
2997
2998 #ifdef CONFIG_WPS
wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant * wpa_s,char * pos,char * end,struct wpabuf * wps_ie)2999 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
3000 char *pos, char *end,
3001 struct wpabuf *wps_ie)
3002 {
3003 int ret;
3004 const char *txt;
3005
3006 if (wps_ie == NULL)
3007 return pos;
3008 if (wps_is_selected_pbc_registrar(wps_ie))
3009 txt = "[WPS-PBC]";
3010 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
3011 txt = "[WPS-AUTH]";
3012 else if (wps_is_selected_pin_registrar(wps_ie))
3013 txt = "[WPS-PIN]";
3014 else
3015 txt = "[WPS]";
3016
3017 ret = os_snprintf(pos, end - pos, "%s", txt);
3018 if (!os_snprintf_error(end - pos, ret))
3019 pos += ret;
3020 wpabuf_free(wps_ie);
3021 return pos;
3022 }
3023 #endif /* CONFIG_WPS */
3024
3025
wpa_supplicant_wps_ie_txt(struct wpa_supplicant * wpa_s,char * pos,char * end,const struct wpa_bss * bss)3026 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
3027 char *pos, char *end,
3028 const struct wpa_bss *bss)
3029 {
3030 #ifdef CONFIG_WPS
3031 struct wpabuf *wps_ie;
3032 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
3033 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
3034 #else /* CONFIG_WPS */
3035 return pos;
3036 #endif /* CONFIG_WPS */
3037 }
3038
3039
3040 /* 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)3041 static int wpa_supplicant_ctrl_iface_scan_result(
3042 struct wpa_supplicant *wpa_s,
3043 const struct wpa_bss *bss, char *buf, size_t buflen)
3044 {
3045 char *pos, *end;
3046 int ret;
3047 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe, *rsnxe;
3048
3049 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
3050 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
3051 if (!p2p)
3052 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
3053 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
3054 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
3055 0)
3056 return 0; /* Do not show P2P listen discovery results here */
3057
3058 pos = buf;
3059 end = buf + buflen;
3060
3061 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
3062 MAC2STR(bss->bssid), bss->freq, bss->level);
3063 if (os_snprintf_error(end - pos, ret))
3064 return -1;
3065 pos += ret;
3066 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3067 if (ie)
3068 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
3069 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3070 if (ie2) {
3071 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
3072 ie2, 2 + ie2[1]);
3073 }
3074 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
3075 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
3076 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
3077 if (os_snprintf_error(end - pos, ret))
3078 return -1;
3079 pos += ret;
3080 }
3081 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
3082 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
3083 if (os_snprintf_error(end - pos, ret))
3084 return -1;
3085 pos += ret;
3086 }
3087 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
3088 if (osen_ie)
3089 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
3090 osen_ie, 2 + osen_ie[1]);
3091 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
3092 if (owe) {
3093 ret = os_snprintf(pos, end - pos,
3094 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
3095 if (os_snprintf_error(end - pos, ret))
3096 return -1;
3097 pos += ret;
3098 }
3099 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3100 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
3101 ret = os_snprintf(pos, end - pos, "[WEP]");
3102 if (os_snprintf_error(end - pos, ret))
3103 return -1;
3104 pos += ret;
3105 }
3106 if (mesh) {
3107 ret = os_snprintf(pos, end - pos, "[MESH]");
3108 if (os_snprintf_error(end - pos, ret))
3109 return -1;
3110 pos += ret;
3111 }
3112 if (bss_is_dmg(bss)) {
3113 const char *s;
3114
3115 if (wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_EDMG_OPERATION)) {
3116 ret = os_snprintf(pos, end - pos, "[EDMG]");
3117 if (os_snprintf_error(end - pos, ret))
3118 return -1;
3119 pos += ret;
3120 }
3121
3122 ret = os_snprintf(pos, end - pos, "[DMG]");
3123 if (os_snprintf_error(end - pos, ret))
3124 return -1;
3125 pos += ret;
3126 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3127 case IEEE80211_CAP_DMG_IBSS:
3128 s = "[IBSS]";
3129 break;
3130 case IEEE80211_CAP_DMG_AP:
3131 s = "[ESS]";
3132 break;
3133 case IEEE80211_CAP_DMG_PBSS:
3134 s = "[PBSS]";
3135 break;
3136 default:
3137 s = "";
3138 break;
3139 }
3140 ret = os_snprintf(pos, end - pos, "%s", s);
3141 if (os_snprintf_error(end - pos, ret))
3142 return -1;
3143 pos += ret;
3144 } else {
3145 if (bss->caps & IEEE80211_CAP_IBSS) {
3146 ret = os_snprintf(pos, end - pos, "[IBSS]");
3147 if (os_snprintf_error(end - pos, ret))
3148 return -1;
3149 pos += ret;
3150 }
3151 if (bss->caps & IEEE80211_CAP_ESS) {
3152 ret = os_snprintf(pos, end - pos, "[ESS]");
3153 if (os_snprintf_error(end - pos, ret))
3154 return -1;
3155 pos += ret;
3156 }
3157 }
3158 if (p2p) {
3159 ret = os_snprintf(pos, end - pos, "[P2P]");
3160 if (os_snprintf_error(end - pos, ret))
3161 return -1;
3162 pos += ret;
3163 }
3164 #ifdef CONFIG_HS20
3165 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
3166 ret = os_snprintf(pos, end - pos, "[HS20]");
3167 if (os_snprintf_error(end - pos, ret))
3168 return -1;
3169 pos += ret;
3170 }
3171 #endif /* CONFIG_HS20 */
3172 #ifdef CONFIG_FILS
3173 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
3174 ret = os_snprintf(pos, end - pos, "[FILS]");
3175 if (os_snprintf_error(end - pos, ret))
3176 return -1;
3177 pos += ret;
3178 }
3179 #endif /* CONFIG_FILS */
3180 #ifdef CONFIG_FST
3181 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
3182 ret = os_snprintf(pos, end - pos, "[FST]");
3183 if (os_snprintf_error(end - pos, ret))
3184 return -1;
3185 pos += ret;
3186 }
3187 #endif /* CONFIG_FST */
3188 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
3189 ret = os_snprintf(pos, end - pos, "[UTF-8]");
3190 if (os_snprintf_error(end - pos, ret))
3191 return -1;
3192 pos += ret;
3193 }
3194
3195 ret = os_snprintf(pos, end - pos, "\t%s",
3196 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3197 if (os_snprintf_error(end - pos, ret))
3198 return -1;
3199 pos += ret;
3200
3201 ret = os_snprintf(pos, end - pos, "\n");
3202 if (os_snprintf_error(end - pos, ret))
3203 return -1;
3204 pos += ret;
3205
3206 return pos - buf;
3207 }
3208
3209
wpa_supplicant_ctrl_iface_scan_results(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)3210 static int wpa_supplicant_ctrl_iface_scan_results(
3211 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3212 {
3213 char *pos, *end;
3214 struct wpa_bss *bss;
3215 int ret;
3216
3217 pos = buf;
3218 end = buf + buflen;
3219 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
3220 "flags / ssid\n");
3221 if (os_snprintf_error(end - pos, ret))
3222 return pos - buf;
3223 pos += ret;
3224
3225 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3226 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
3227 end - pos);
3228 if (ret < 0 || ret >= end - pos)
3229 return pos - buf;
3230 pos += ret;
3231 }
3232
3233 return pos - buf;
3234 }
3235
3236
3237 #ifdef CONFIG_MESH
3238
wpa_supplicant_ctrl_iface_mesh_interface_add(struct wpa_supplicant * wpa_s,char * cmd,char * reply,size_t max_len)3239 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3240 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
3241 {
3242 char *pos, ifname[IFNAMSIZ + 1];
3243
3244 ifname[0] = '\0';
3245
3246 pos = os_strstr(cmd, "ifname=");
3247 if (pos) {
3248 pos += 7;
3249 os_strlcpy(ifname, pos, sizeof(ifname));
3250 }
3251
3252 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
3253 return -1;
3254
3255 os_strlcpy(reply, ifname, max_len);
3256 return os_strlen(ifname);
3257 }
3258
3259
wpa_supplicant_ctrl_iface_mesh_group_add(struct wpa_supplicant * wpa_s,char * cmd)3260 static int wpa_supplicant_ctrl_iface_mesh_group_add(
3261 struct wpa_supplicant *wpa_s, char *cmd)
3262 {
3263 int id;
3264 struct wpa_ssid *ssid;
3265
3266 id = atoi(cmd);
3267 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
3268
3269 ssid = wpa_config_get_network(wpa_s->conf, id);
3270 if (ssid == NULL) {
3271 wpa_printf(MSG_DEBUG,
3272 "CTRL_IFACE: Could not find network id=%d", id);
3273 return -1;
3274 }
3275 if (ssid->mode != WPAS_MODE_MESH) {
3276 wpa_printf(MSG_DEBUG,
3277 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3278 return -1;
3279 }
3280 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
3281 ssid->key_mgmt != WPA_KEY_MGMT_SAE &&
3282 ssid->key_mgmt != WPA_KEY_MGMT_SAE_EXT_KEY) {
3283 wpa_printf(MSG_ERROR,
3284 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3285 return -1;
3286 }
3287
3288 /*
3289 * TODO: If necessary write our own group_add function,
3290 * for now we can reuse select_network
3291 */
3292 wpa_supplicant_select_network(wpa_s, ssid);
3293
3294 return 0;
3295 }
3296
3297
wpa_supplicant_ctrl_iface_mesh_group_remove(struct wpa_supplicant * wpa_s,char * cmd)3298 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3299 struct wpa_supplicant *wpa_s, char *cmd)
3300 {
3301 struct wpa_supplicant *orig;
3302 struct wpa_global *global;
3303 int found = 0;
3304
3305 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3306
3307 global = wpa_s->global;
3308 orig = wpa_s;
3309
3310 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3311 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3312 found = 1;
3313 break;
3314 }
3315 }
3316 if (!found) {
3317 wpa_printf(MSG_ERROR,
3318 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3319 cmd);
3320 return -1;
3321 }
3322 if (wpa_s->mesh_if_created && wpa_s == orig) {
3323 wpa_printf(MSG_ERROR,
3324 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3325 return -1;
3326 }
3327
3328 wpa_s->reassociate = 0;
3329 wpa_s->disconnected = 1;
3330 wpa_supplicant_cancel_sched_scan(wpa_s);
3331 wpa_supplicant_cancel_scan(wpa_s);
3332
3333 /*
3334 * TODO: If necessary write our own group_remove function,
3335 * for now we can reuse deauthenticate
3336 */
3337 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3338
3339 if (wpa_s->mesh_if_created)
3340 wpa_supplicant_remove_iface(global, wpa_s, 0);
3341
3342 return 0;
3343 }
3344
3345
wpa_supplicant_ctrl_iface_mesh_peer_remove(struct wpa_supplicant * wpa_s,char * cmd)3346 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3347 struct wpa_supplicant *wpa_s, char *cmd)
3348 {
3349 u8 addr[ETH_ALEN];
3350
3351 if (hwaddr_aton(cmd, addr) < 0)
3352 return -1;
3353
3354 return wpas_mesh_peer_remove(wpa_s, addr);
3355 }
3356
3357
wpa_supplicant_ctrl_iface_mesh_peer_add(struct wpa_supplicant * wpa_s,char * cmd)3358 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3359 struct wpa_supplicant *wpa_s, char *cmd)
3360 {
3361 u8 addr[ETH_ALEN];
3362 int duration;
3363 char *pos;
3364
3365 pos = os_strstr(cmd, " duration=");
3366 if (pos) {
3367 *pos = '\0';
3368 duration = atoi(pos + 10);
3369 } else {
3370 duration = -1;
3371 }
3372
3373 if (hwaddr_aton(cmd, addr))
3374 return -1;
3375
3376 return wpas_mesh_peer_add(wpa_s, addr, duration);
3377 }
3378
3379
wpa_supplicant_ctrl_iface_mesh_link_probe(struct wpa_supplicant * wpa_s,char * cmd)3380 static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3381 struct wpa_supplicant *wpa_s, char *cmd)
3382 {
3383 struct ether_header *eth;
3384 u8 addr[ETH_ALEN];
3385 u8 *buf;
3386 char *pos;
3387 size_t payload_len = 0, len;
3388 int ret = -1;
3389
3390 if (hwaddr_aton(cmd, addr))
3391 return -1;
3392
3393 pos = os_strstr(cmd, " payload=");
3394 if (pos) {
3395 pos = pos + 9;
3396 payload_len = os_strlen(pos);
3397 if (payload_len & 1)
3398 return -1;
3399
3400 payload_len /= 2;
3401 }
3402
3403 len = ETH_HLEN + payload_len;
3404 buf = os_malloc(len);
3405 if (!buf)
3406 return -1;
3407
3408 eth = (struct ether_header *) buf;
3409 os_memcpy(eth->ether_dhost, addr, ETH_ALEN);
3410 os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN);
3411 eth->ether_type = htons(ETH_P_802_3);
3412
3413 if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0)
3414 goto fail;
3415
3416 ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len);
3417 fail:
3418 os_free(buf);
3419 return -ret;
3420 }
3421
3422 #endif /* CONFIG_MESH */
3423
3424
wpa_supplicant_ctrl_iface_select_network(struct wpa_supplicant * wpa_s,char * cmd)3425 static int wpa_supplicant_ctrl_iface_select_network(
3426 struct wpa_supplicant *wpa_s, char *cmd)
3427 {
3428 int id;
3429 struct wpa_ssid *ssid;
3430 char *pos;
3431
3432 /* cmd: "<network id>" or "any" */
3433 if (os_strncmp(cmd, "any", 3) == 0) {
3434 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3435 ssid = NULL;
3436 } else {
3437 id = atoi(cmd);
3438 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3439
3440 ssid = wpa_config_get_network(wpa_s->conf, id);
3441 if (ssid == NULL) {
3442 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3443 "network id=%d", id);
3444 return -1;
3445 }
3446 if (ssid->disabled == 2) {
3447 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3448 "SELECT_NETWORK with persistent P2P group");
3449 return -1;
3450 }
3451 }
3452
3453 pos = os_strstr(cmd, " freq=");
3454 if (pos) {
3455 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3456 if (freqs) {
3457 os_free(wpa_s->select_network_scan_freqs);
3458 wpa_s->select_network_scan_freqs = freqs;
3459 }
3460 }
3461
3462 wpa_s->scan_min_time.sec = 0;
3463 wpa_s->scan_min_time.usec = 0;
3464 wpa_supplicant_select_network(wpa_s, ssid);
3465
3466 return 0;
3467 }
3468
3469
wpa_supplicant_ctrl_iface_enable_network(struct wpa_supplicant * wpa_s,char * cmd)3470 static int wpa_supplicant_ctrl_iface_enable_network(
3471 struct wpa_supplicant *wpa_s, char *cmd)
3472 {
3473 int id;
3474 struct wpa_ssid *ssid;
3475
3476 /* cmd: "<network id>" or "all" */
3477 if (os_strcmp(cmd, "all") == 0) {
3478 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3479 ssid = NULL;
3480 } else {
3481 id = atoi(cmd);
3482 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3483
3484 ssid = wpa_config_get_network(wpa_s->conf, id);
3485 if (ssid == NULL) {
3486 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3487 "network id=%d", id);
3488 return -1;
3489 }
3490 if (ssid->disabled == 2) {
3491 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3492 "ENABLE_NETWORK with persistent P2P group");
3493 return -1;
3494 }
3495
3496 if (os_strstr(cmd, " no-connect")) {
3497 ssid->disabled = 0;
3498 return 0;
3499 }
3500 }
3501 wpa_s->scan_min_time.sec = 0;
3502 wpa_s->scan_min_time.usec = 0;
3503 wpa_supplicant_enable_network(wpa_s, ssid);
3504
3505 return 0;
3506 }
3507
3508
wpa_supplicant_ctrl_iface_disable_network(struct wpa_supplicant * wpa_s,char * cmd)3509 static int wpa_supplicant_ctrl_iface_disable_network(
3510 struct wpa_supplicant *wpa_s, char *cmd)
3511 {
3512 int id;
3513 struct wpa_ssid *ssid;
3514
3515 /* cmd: "<network id>" or "all" */
3516 if (os_strcmp(cmd, "all") == 0) {
3517 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3518 ssid = NULL;
3519 } else {
3520 id = atoi(cmd);
3521 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3522
3523 ssid = wpa_config_get_network(wpa_s->conf, id);
3524 if (ssid == NULL) {
3525 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3526 "network id=%d", id);
3527 return -1;
3528 }
3529 if (ssid->disabled == 2) {
3530 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3531 "DISABLE_NETWORK with persistent P2P "
3532 "group");
3533 return -1;
3534 }
3535 }
3536 wpa_supplicant_disable_network(wpa_s, ssid);
3537
3538 return 0;
3539 }
3540
3541
wpa_supplicant_ctrl_iface_add_network(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)3542 static int wpa_supplicant_ctrl_iface_add_network(
3543 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3544 {
3545 struct wpa_ssid *ssid;
3546 int ret;
3547
3548 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3549
3550 ssid = wpa_supplicant_add_network(wpa_s);
3551 if (ssid == NULL)
3552 return -1;
3553
3554 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
3555 if (os_snprintf_error(buflen, ret))
3556 return -1;
3557 return ret;
3558 }
3559
3560
wpa_supplicant_ctrl_iface_remove_network(struct wpa_supplicant * wpa_s,char * cmd)3561 static int wpa_supplicant_ctrl_iface_remove_network(
3562 struct wpa_supplicant *wpa_s, char *cmd)
3563 {
3564 int id;
3565 int result;
3566
3567 /* cmd: "<network id>" or "all" */
3568 if (os_strcmp(cmd, "all") == 0) {
3569 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
3570 return wpa_supplicant_remove_all_networks(wpa_s);
3571 }
3572
3573 id = atoi(cmd);
3574 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3575
3576 result = wpa_supplicant_remove_network(wpa_s, id);
3577 if (result == -1) {
3578 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3579 "id=%d", id);
3580 return -1;
3581 }
3582 if (result == -2) {
3583 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3584 "network id=%d", id);
3585 return -1;
3586 }
3587 return 0;
3588 }
3589
3590
wpa_supplicant_ctrl_iface_update_network(struct wpa_supplicant * wpa_s,struct wpa_ssid * ssid,char * name,char * value)3591 static int wpa_supplicant_ctrl_iface_update_network(
3592 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3593 char *name, char *value)
3594 {
3595 int ret;
3596
3597 ret = wpa_config_set(ssid, name, value, 0);
3598 if (ret < 0) {
3599 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3600 "variable '%s'", name);
3601 return -1;
3602 }
3603 if (ret == 1)
3604 return 0; /* No change to the previously configured value */
3605
3606 #ifdef CONFIG_BGSCAN
3607 if (os_strcmp(name, "bgscan") == 0) {
3608 /*
3609 * Reset the bgscan parameters for the current network and
3610 * return. There's no need to flush caches for bgscan parameter
3611 * changes.
3612 */
3613 if (wpa_s->current_ssid == ssid &&
3614 wpa_s->wpa_state == WPA_COMPLETED)
3615 wpa_supplicant_reset_bgscan(wpa_s);
3616 return 0;
3617 }
3618 #endif /* CONFIG_BGSCAN */
3619
3620 if (os_strcmp(name, "bssid") != 0 &&
3621 os_strcmp(name, "bssid_hint") != 0 &&
3622 os_strcmp(name, "scan_freq") != 0 &&
3623 os_strcmp(name, "priority") != 0) {
3624 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3625
3626 if (wpa_s->current_ssid == ssid ||
3627 wpa_s->current_ssid == NULL) {
3628 /*
3629 * Invalidate the EAP session cache if anything in the
3630 * current or previously used configuration changes.
3631 */
3632 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3633 }
3634 }
3635
3636 if ((os_strcmp(name, "psk") == 0 &&
3637 value[0] == '"' && ssid->ssid_len) ||
3638 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3639 wpa_config_update_psk(ssid);
3640 else if (os_strcmp(name, "priority") == 0)
3641 wpa_config_update_prio_list(wpa_s->conf);
3642
3643 return 0;
3644 }
3645
3646
wpa_supplicant_ctrl_iface_set_network(struct wpa_supplicant * wpa_s,char * cmd)3647 static int wpa_supplicant_ctrl_iface_set_network(
3648 struct wpa_supplicant *wpa_s, char *cmd)
3649 {
3650 int id, ret, prev_bssid_set, prev_disabled;
3651 struct wpa_ssid *ssid;
3652 char *name, *value;
3653 u8 prev_bssid[ETH_ALEN];
3654
3655 /* cmd: "<network id> <variable name> <value>" */
3656 name = os_strchr(cmd, ' ');
3657 if (name == NULL)
3658 return -1;
3659 *name++ = '\0';
3660
3661 value = os_strchr(name, ' ');
3662 if (value == NULL)
3663 return -1;
3664 *value++ = '\0';
3665
3666 id = atoi(cmd);
3667 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3668 id, name);
3669 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3670 (u8 *) value, os_strlen(value));
3671
3672 ssid = wpa_config_get_network(wpa_s->conf, id);
3673 if (ssid == NULL) {
3674 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3675 "id=%d", id);
3676 return -1;
3677 }
3678
3679 prev_bssid_set = ssid->bssid_set;
3680 prev_disabled = ssid->disabled;
3681 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3682 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3683 value);
3684 if (ret == 0 &&
3685 (ssid->bssid_set != prev_bssid_set ||
3686 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3687 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
3688
3689 if (prev_disabled != ssid->disabled &&
3690 (prev_disabled == 2 || ssid->disabled == 2))
3691 wpas_notify_network_type_changed(wpa_s, ssid);
3692
3693 return ret;
3694 }
3695
3696
wpa_supplicant_ctrl_iface_get_network(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)3697 static int wpa_supplicant_ctrl_iface_get_network(
3698 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3699 {
3700 int id;
3701 size_t res;
3702 struct wpa_ssid *ssid;
3703 char *name, *value;
3704
3705 /* cmd: "<network id> <variable name>" */
3706 name = os_strchr(cmd, ' ');
3707 if (name == NULL || buflen == 0)
3708 return -1;
3709 *name++ = '\0';
3710
3711 id = atoi(cmd);
3712 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3713 id, name);
3714
3715 ssid = wpa_config_get_network(wpa_s->conf, id);
3716 if (ssid == NULL) {
3717 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
3718 "id=%d", id);
3719 return -1;
3720 }
3721
3722 value = wpa_config_get_no_key(ssid, name);
3723 if (value == NULL) {
3724 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
3725 "variable '%s'", name);
3726 return -1;
3727 }
3728
3729 res = os_strlcpy(buf, value, buflen);
3730 if (res >= buflen) {
3731 os_free(value);
3732 return -1;
3733 }
3734
3735 os_free(value);
3736
3737 return res;
3738 }
3739
3740
wpa_supplicant_ctrl_iface_dup_network(struct wpa_supplicant * wpa_s,char * cmd,struct wpa_supplicant * dst_wpa_s)3741 static int wpa_supplicant_ctrl_iface_dup_network(
3742 struct wpa_supplicant *wpa_s, char *cmd,
3743 struct wpa_supplicant *dst_wpa_s)
3744 {
3745 struct wpa_ssid *ssid_s, *ssid_d;
3746 char *name, *id, *value;
3747 int id_s, id_d, ret;
3748
3749 /* cmd: "<src network id> <dst network id> <variable name>" */
3750 id = os_strchr(cmd, ' ');
3751 if (id == NULL)
3752 return -1;
3753 *id++ = '\0';
3754
3755 name = os_strchr(id, ' ');
3756 if (name == NULL)
3757 return -1;
3758 *name++ = '\0';
3759
3760 id_s = atoi(cmd);
3761 id_d = atoi(id);
3762
3763 wpa_printf(MSG_DEBUG,
3764 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3765 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
3766
3767 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3768 if (ssid_s == NULL) {
3769 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3770 "network id=%d", id_s);
3771 return -1;
3772 }
3773
3774 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
3775 if (ssid_d == NULL) {
3776 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3777 "network id=%d", id_d);
3778 return -1;
3779 }
3780
3781 value = wpa_config_get(ssid_s, name);
3782 if (value == NULL) {
3783 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3784 "variable '%s'", name);
3785 return -1;
3786 }
3787
3788 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
3789 value);
3790
3791 os_free(value);
3792
3793 return ret;
3794 }
3795
3796
wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)3797 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3798 char *buf, size_t buflen)
3799 {
3800 char *pos, *end;
3801 struct wpa_cred *cred;
3802 int ret;
3803
3804 pos = buf;
3805 end = buf + buflen;
3806 ret = os_snprintf(pos, end - pos,
3807 "cred id / realm / username / domain / imsi\n");
3808 if (os_snprintf_error(end - pos, ret))
3809 return pos - buf;
3810 pos += ret;
3811
3812 cred = wpa_s->conf->cred;
3813 while (cred) {
3814 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3815 cred->id, cred->realm ? cred->realm : "",
3816 cred->username ? cred->username : "",
3817 cred->domain ? cred->domain[0] : "",
3818 cred->imsi ? cred->imsi : "");
3819 if (os_snprintf_error(end - pos, ret))
3820 return pos - buf;
3821 pos += ret;
3822
3823 cred = cred->next;
3824 }
3825
3826 return pos - buf;
3827 }
3828
3829
wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)3830 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3831 char *buf, size_t buflen)
3832 {
3833 struct wpa_cred *cred;
3834 int ret;
3835
3836 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3837
3838 cred = wpa_config_add_cred(wpa_s->conf);
3839 if (cred == NULL)
3840 return -1;
3841
3842 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3843
3844 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
3845 if (os_snprintf_error(buflen, ret))
3846 return -1;
3847 return ret;
3848 }
3849
3850
wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant * wpa_s,char * cmd)3851 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3852 char *cmd)
3853 {
3854 int id;
3855 struct wpa_cred *cred, *prev;
3856
3857 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3858 * "provisioning_sp=<FQDN> */
3859 if (os_strcmp(cmd, "all") == 0) {
3860 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3861 return wpas_remove_all_creds(wpa_s);
3862 }
3863
3864 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3865 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3866 cmd + 8);
3867 cred = wpa_s->conf->cred;
3868 while (cred) {
3869 prev = cred;
3870 cred = cred->next;
3871 if (prev->domain) {
3872 size_t i;
3873 for (i = 0; i < prev->num_domain; i++) {
3874 if (os_strcmp(prev->domain[i], cmd + 8)
3875 != 0)
3876 continue;
3877 wpas_remove_cred(wpa_s, prev);
3878 break;
3879 }
3880 }
3881 }
3882 return 0;
3883 }
3884
3885 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3886 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3887 cmd + 16);
3888 cred = wpa_s->conf->cred;
3889 while (cred) {
3890 prev = cred;
3891 cred = cred->next;
3892 if (prev->provisioning_sp &&
3893 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3894 wpas_remove_cred(wpa_s, prev);
3895 }
3896 return 0;
3897 }
3898
3899 id = atoi(cmd);
3900 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3901
3902 cred = wpa_config_get_cred(wpa_s->conf, id);
3903 return wpas_remove_cred(wpa_s, cred);
3904 }
3905
3906
wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant * wpa_s,char * cmd)3907 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3908 char *cmd)
3909 {
3910 int id;
3911 struct wpa_cred *cred;
3912 char *name, *value;
3913
3914 /* cmd: "<cred id> <variable name> <value>" */
3915 name = os_strchr(cmd, ' ');
3916 if (name == NULL)
3917 return -1;
3918 *name++ = '\0';
3919
3920 value = os_strchr(name, ' ');
3921 if (value == NULL)
3922 return -1;
3923 *value++ = '\0';
3924
3925 id = atoi(cmd);
3926 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3927 id, name);
3928 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3929 (u8 *) value, os_strlen(value));
3930
3931 cred = wpa_config_get_cred(wpa_s->conf, id);
3932 if (cred == NULL) {
3933 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3934 id);
3935 return -1;
3936 }
3937
3938 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3939 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3940 "variable '%s'", name);
3941 return -1;
3942 }
3943
3944 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3945
3946 return 0;
3947 }
3948
3949
wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)3950 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3951 char *cmd, char *buf,
3952 size_t buflen)
3953 {
3954 int id;
3955 size_t res;
3956 struct wpa_cred *cred;
3957 char *name, *value;
3958
3959 /* cmd: "<cred id> <variable name>" */
3960 name = os_strchr(cmd, ' ');
3961 if (name == NULL)
3962 return -1;
3963 *name++ = '\0';
3964
3965 id = atoi(cmd);
3966 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3967 id, name);
3968
3969 cred = wpa_config_get_cred(wpa_s->conf, id);
3970 if (cred == NULL) {
3971 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3972 id);
3973 return -1;
3974 }
3975
3976 value = wpa_config_get_cred_no_key(cred, name);
3977 if (value == NULL) {
3978 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3979 name);
3980 return -1;
3981 }
3982
3983 res = os_strlcpy(buf, value, buflen);
3984 if (res >= buflen) {
3985 os_free(value);
3986 return -1;
3987 }
3988
3989 os_free(value);
3990
3991 return res;
3992 }
3993
3994
3995 #ifndef CONFIG_NO_CONFIG_WRITE
wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant * wpa_s)3996 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3997 {
3998 int ret;
3999
4000 if (!wpa_s->conf->update_config) {
4001 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
4002 "to update configuration (update_config=0)");
4003 return -1;
4004 }
4005
4006 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
4007 if (ret) {
4008 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
4009 "update configuration");
4010 } else {
4011 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
4012 " updated");
4013 }
4014
4015 return ret;
4016 }
4017 #endif /* CONFIG_NO_CONFIG_WRITE */
4018
4019
4020 struct cipher_info {
4021 unsigned int capa;
4022 const char *name;
4023 int group_only;
4024 };
4025
4026 static const struct cipher_info ciphers[] = {
4027 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
4028 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
4029 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
4030 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
4031 #ifndef CONFIG_NO_TKIP
4032 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
4033 #endif /* CONFIG_NO_TKIP */
4034 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
4035 #ifdef CONFIG_WEP
4036 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
4037 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
4038 #endif /* CONFIG_WEP */
4039 };
4040
4041 static const struct cipher_info ciphers_group_mgmt[] = {
4042 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
4043 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
4044 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
4045 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
4046 };
4047
4048
ctrl_iface_get_capability_pairwise(int res,bool strict,struct wpa_driver_capa * capa,char * buf,size_t buflen)4049 static int ctrl_iface_get_capability_pairwise(int res, bool strict,
4050 struct wpa_driver_capa *capa,
4051 char *buf, size_t buflen)
4052 {
4053 int ret;
4054 char *pos, *end;
4055 size_t len;
4056 unsigned int i;
4057
4058 pos = buf;
4059 end = pos + buflen;
4060
4061 if (res < 0) {
4062 if (strict)
4063 return 0;
4064 #ifdef CONFIG_NO_TKIP
4065 len = os_strlcpy(buf, "CCMP NONE", buflen);
4066 #else /* CONFIG_NO_TKIP */
4067 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
4068 #endif /* CONFIG_NO_TKIP */
4069 if (len >= buflen)
4070 return -1;
4071 return len;
4072 }
4073
4074 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4075 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
4076 ret = os_snprintf(pos, end - pos, "%s%s",
4077 pos == buf ? "" : " ",
4078 ciphers[i].name);
4079 if (os_snprintf_error(end - pos, ret))
4080 return pos - buf;
4081 pos += ret;
4082 }
4083 }
4084
4085 return pos - buf;
4086 }
4087
4088
ctrl_iface_get_capability_group(int res,bool strict,struct wpa_driver_capa * capa,char * buf,size_t buflen)4089 static int ctrl_iface_get_capability_group(int res, bool strict,
4090 struct wpa_driver_capa *capa,
4091 char *buf, size_t buflen)
4092 {
4093 int ret;
4094 char *pos, *end;
4095 size_t len;
4096 unsigned int i;
4097
4098 pos = buf;
4099 end = pos + buflen;
4100
4101 if (res < 0) {
4102 if (strict)
4103 return 0;
4104 #ifdef CONFIG_WEP
4105 #ifdef CONFIG_NO_TKIP
4106 len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen);
4107 #else /* CONFIG_NO_TKIP */
4108 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
4109 #endif /* CONFIG_NO_TKIP */
4110 #else /* CONFIG_WEP */
4111 #ifdef CONFIG_NO_TKIP
4112 len = os_strlcpy(buf, "CCMP", buflen);
4113 #else /* CONFIG_NO_TKIP */
4114 len = os_strlcpy(buf, "CCMP TKIP", buflen);
4115 #endif /* CONFIG_NO_TKIP */
4116 #endif /* CONFIG_WEP */
4117 if (len >= buflen)
4118 return -1;
4119 return len;
4120 }
4121
4122 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4123 if (capa->enc & ciphers[i].capa) {
4124 ret = os_snprintf(pos, end - pos, "%s%s",
4125 pos == buf ? "" : " ",
4126 ciphers[i].name);
4127 if (os_snprintf_error(end - pos, ret))
4128 return pos - buf;
4129 pos += ret;
4130 }
4131 }
4132
4133 return pos - buf;
4134 }
4135
4136
ctrl_iface_get_capability_group_mgmt(int res,bool strict,struct wpa_driver_capa * capa,char * buf,size_t buflen)4137 static int ctrl_iface_get_capability_group_mgmt(int res, bool strict,
4138 struct wpa_driver_capa *capa,
4139 char *buf, size_t buflen)
4140 {
4141 int ret;
4142 char *pos, *end;
4143 unsigned int i;
4144
4145 pos = buf;
4146 end = pos + buflen;
4147
4148 if (res < 0)
4149 return 0;
4150
4151 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
4152 if (capa->enc & ciphers_group_mgmt[i].capa) {
4153 ret = os_snprintf(pos, end - pos, "%s%s",
4154 pos == buf ? "" : " ",
4155 ciphers_group_mgmt[i].name);
4156 if (os_snprintf_error(end - pos, ret))
4157 return pos - buf;
4158 pos += ret;
4159 }
4160 }
4161
4162 return pos - buf;
4163 }
4164
4165
iftype_str_to_index(const char * iftype_str)4166 static int iftype_str_to_index(const char *iftype_str)
4167 {
4168 if (!iftype_str)
4169 return WPA_IF_MAX;
4170
4171 if (os_strcmp(iftype_str, "STATION") == 0)
4172 return WPA_IF_STATION;
4173
4174 if (os_strcmp(iftype_str, "AP_VLAN") == 0)
4175 return WPA_IF_AP_VLAN;
4176
4177 if (os_strcmp(iftype_str, "AP") == 0)
4178 return WPA_IF_AP_BSS;
4179
4180 if (os_strcmp(iftype_str, "P2P_GO") == 0)
4181 return WPA_IF_P2P_GO;
4182
4183 if (os_strcmp(iftype_str, "P2P_CLIENT") == 0)
4184 return WPA_IF_P2P_CLIENT;
4185
4186 if (os_strcmp(iftype_str, "P2P_DEVICE") == 0)
4187 return WPA_IF_P2P_DEVICE;
4188
4189 if (os_strcmp(iftype_str, "MESH") == 0)
4190 return WPA_IF_MESH;
4191
4192 if (os_strcmp(iftype_str, "IBSS") == 0)
4193 return WPA_IF_IBSS;
4194
4195 if (os_strcmp(iftype_str, "NAN") == 0)
4196 return WPA_IF_NAN;
4197
4198 return WPA_IF_MAX;
4199 }
4200
4201
ctrl_iface_get_capability_key_mgmt(int res,bool strict,struct wpa_driver_capa * capa,const char * iftype_str,char * buf,size_t buflen)4202 static int ctrl_iface_get_capability_key_mgmt(int res, bool strict,
4203 struct wpa_driver_capa *capa,
4204 const char *iftype_str,
4205 char *buf, size_t buflen)
4206 {
4207 int ret;
4208 unsigned int key_mgmt;
4209 char *pos, *end;
4210 size_t len;
4211
4212 pos = buf;
4213 end = pos + buflen;
4214
4215 if (res < 0) {
4216 if (strict)
4217 return 0;
4218 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4219 "NONE", buflen);
4220 if (len >= buflen)
4221 return -1;
4222 return len;
4223 }
4224
4225 if (iftype_str) {
4226 enum wpa_driver_if_type iftype;
4227
4228 iftype = iftype_str_to_index(iftype_str);
4229 if (iftype == WPA_IF_MAX)
4230 return -1;
4231 key_mgmt = capa->key_mgmt_iftype[iftype];
4232 } else {
4233 key_mgmt = capa->key_mgmt;
4234 }
4235
4236 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
4237 if (os_snprintf_error(end - pos, ret))
4238 return pos - buf;
4239 pos += ret;
4240
4241 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4242 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
4243 ret = os_snprintf(pos, end - pos, " WPA-EAP");
4244 if (os_snprintf_error(end - pos, ret))
4245 return pos - buf;
4246 pos += ret;
4247 }
4248
4249 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
4250 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
4251 ret = os_snprintf(pos, end - pos, " WPA-PSK");
4252 if (os_snprintf_error(end - pos, ret))
4253 return pos - buf;
4254 pos += ret;
4255 }
4256
4257 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
4258 ret = os_snprintf(pos, end - pos, " WPA-NONE");
4259 if (os_snprintf_error(end - pos, ret))
4260 return pos - buf;
4261 pos += ret;
4262 }
4263
4264 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WAPI_PSK) {
4265 ret = os_snprintf(pos, end - pos, " WAPI-PSK");
4266 if (os_snprintf_error(end - pos, ret))
4267 return pos - buf;
4268 pos += ret;
4269 }
4270
4271 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE) {
4272 ret = os_snprintf(pos, end - pos, " TPK-HANDSHAKE");
4273 if (os_snprintf_error(end - pos, ret))
4274 return pos - buf;
4275 pos += ret;
4276 }
4277
4278 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_CCKM) {
4279 ret = os_snprintf(pos, end - pos, " CCKM");
4280 if (os_snprintf_error(end - pos, ret))
4281 return pos - buf;
4282 pos += ret;
4283 }
4284
4285 #ifdef CONFIG_SUITEB
4286 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
4287 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
4288 if (os_snprintf_error(end - pos, ret))
4289 return pos - buf;
4290 pos += ret;
4291 }
4292 #endif /* CONFIG_SUITEB */
4293 #ifdef CONFIG_SUITEB192
4294 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
4295 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
4296 if (os_snprintf_error(end - pos, ret))
4297 return pos - buf;
4298 pos += ret;
4299 }
4300 #endif /* CONFIG_SUITEB192 */
4301 #ifdef CONFIG_OWE
4302 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
4303 ret = os_snprintf(pos, end - pos, " OWE");
4304 if (os_snprintf_error(end - pos, ret))
4305 return pos - buf;
4306 pos += ret;
4307 }
4308 #endif /* CONFIG_OWE */
4309 #ifdef CONFIG_DPP
4310 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
4311 ret = os_snprintf(pos, end - pos, " DPP");
4312 if (os_snprintf_error(end - pos, ret))
4313 return pos - buf;
4314 pos += ret;
4315 }
4316 #endif /* CONFIG_DPP */
4317 #ifdef CONFIG_FILS
4318 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
4319 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
4320 if (os_snprintf_error(end - pos, ret))
4321 return pos - buf;
4322 pos += ret;
4323 }
4324 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
4325 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
4326 if (os_snprintf_error(end - pos, ret))
4327 return pos - buf;
4328 pos += ret;
4329 }
4330 #ifdef CONFIG_IEEE80211R
4331 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
4332 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
4333 if (os_snprintf_error(end - pos, ret))
4334 return pos - buf;
4335 pos += ret;
4336 }
4337 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
4338 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
4339 if (os_snprintf_error(end - pos, ret))
4340 return pos - buf;
4341 pos += ret;
4342 }
4343 #endif /* CONFIG_IEEE80211R */
4344 #endif /* CONFIG_FILS */
4345 #ifdef CONFIG_IEEE80211R
4346 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
4347 ret = os_snprintf(pos, end - pos, " FT-PSK");
4348 if (os_snprintf_error(end - pos, ret))
4349 return pos - buf;
4350 pos += ret;
4351 }
4352 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) {
4353 ret = os_snprintf(pos, end - pos, " FT-EAP");
4354 if (os_snprintf_error(end - pos, ret))
4355 return pos - buf;
4356 pos += ret;
4357 }
4358 #ifdef CONFIG_SAE
4359 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE) {
4360 ret = os_snprintf(pos, end - pos, " FT-SAE");
4361 if (os_snprintf_error(end - pos, ret))
4362 return pos - buf;
4363 pos += ret;
4364 }
4365 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE_EXT_KEY) {
4366 ret = os_snprintf(pos, end - pos, " FT-SAE-EXT-KEY");
4367 if (os_snprintf_error(end - pos, ret))
4368 return pos - buf;
4369 pos += ret;
4370 }
4371 #endif /* CONFIG_SAE */
4372 #ifdef CONFIG_SHA384
4373 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384) {
4374 ret = os_snprintf(pos, end - pos, " FT-EAP-SHA384");
4375 if (os_snprintf_error(end - pos, ret))
4376 return pos - buf;
4377 pos += ret;
4378 }
4379 #endif /* CONFIG_SHA384 */
4380 #endif /* CONFIG_IEEE80211R */
4381 #ifdef CONFIG_SAE
4382 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
4383 ret = os_snprintf(pos, end - pos, " SAE");
4384 if (os_snprintf_error(end - pos, ret))
4385 return pos - buf;
4386 pos += ret;
4387 }
4388 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE_EXT_KEY) {
4389 ret = os_snprintf(pos, end - pos, " SAE-EXT-KEY");
4390 if (os_snprintf_error(end - pos, ret))
4391 return pos - buf;
4392 pos += ret;
4393 }
4394 #endif /* CONFIG_SAE */
4395 #ifdef CONFIG_SHA256
4396 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256) {
4397 ret = os_snprintf(pos, end - pos, " WPA-EAP-SHA256");
4398 if (os_snprintf_error(end - pos, ret))
4399 return pos - buf;
4400 pos += ret;
4401 }
4402
4403 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256) {
4404 ret = os_snprintf(pos, end - pos, " WPA-PSK-SHA256");
4405 if (os_snprintf_error(end - pos, ret))
4406 return pos - buf;
4407 pos += ret;
4408 }
4409 #endif /* CONFIG_SHA256 */
4410 #ifdef CONFIG_HS20
4411 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OSEN) {
4412 ret = os_snprintf(pos, end - pos, " OSEN");
4413 if (os_snprintf_error(end - pos, ret))
4414 return pos - buf;
4415 pos += ret;
4416 }
4417 #endif /* CONFIG_HS20 */
4418
4419 return pos - buf;
4420 }
4421
4422
ctrl_iface_get_capability_proto(int res,bool strict,struct wpa_driver_capa * capa,char * buf,size_t buflen)4423 static int ctrl_iface_get_capability_proto(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
4431 pos = buf;
4432 end = pos + buflen;
4433
4434 if (res < 0) {
4435 if (strict)
4436 return 0;
4437 len = os_strlcpy(buf, "RSN WPA", buflen);
4438 if (len >= buflen)
4439 return -1;
4440 return len;
4441 }
4442
4443 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4444 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
4445 ret = os_snprintf(pos, end - pos, "%sRSN",
4446 pos == buf ? "" : " ");
4447 if (os_snprintf_error(end - pos, ret))
4448 return pos - buf;
4449 pos += ret;
4450 }
4451
4452 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4453 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
4454 ret = os_snprintf(pos, end - pos, "%sWPA",
4455 pos == buf ? "" : " ");
4456 if (os_snprintf_error(end - pos, ret))
4457 return pos - buf;
4458 pos += ret;
4459 }
4460
4461 return pos - buf;
4462 }
4463
4464
ctrl_iface_get_capability_auth_alg(struct wpa_supplicant * wpa_s,int res,bool strict,struct wpa_driver_capa * capa,char * buf,size_t buflen)4465 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
4466 int res, bool strict,
4467 struct wpa_driver_capa *capa,
4468 char *buf, size_t buflen)
4469 {
4470 int ret;
4471 char *pos, *end;
4472 size_t len;
4473
4474 pos = buf;
4475 end = pos + buflen;
4476
4477 if (res < 0) {
4478 if (strict)
4479 return 0;
4480 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4481 if (len >= buflen)
4482 return -1;
4483 return len;
4484 }
4485
4486 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
4487 ret = os_snprintf(pos, end - pos, "%sOPEN",
4488 pos == buf ? "" : " ");
4489 if (os_snprintf_error(end - pos, ret))
4490 return pos - buf;
4491 pos += ret;
4492 }
4493
4494 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4495 ret = os_snprintf(pos, end - pos, "%sSHARED",
4496 pos == buf ? "" : " ");
4497 if (os_snprintf_error(end - pos, ret))
4498 return pos - buf;
4499 pos += ret;
4500 }
4501
4502 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
4503 ret = os_snprintf(pos, end - pos, "%sLEAP",
4504 pos == buf ? "" : " ");
4505 if (os_snprintf_error(end - pos, ret))
4506 return pos - buf;
4507 pos += ret;
4508 }
4509
4510 #ifdef CONFIG_SAE
4511 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4512 ret = os_snprintf(pos, end - pos, "%sSAE",
4513 pos == buf ? "" : " ");
4514 if (os_snprintf_error(end - pos, ret))
4515 return pos - buf;
4516 pos += ret;
4517 }
4518 #endif /* CONFIG_SAE */
4519
4520 #ifdef CONFIG_FILS
4521 if (wpa_is_fils_supported(wpa_s)) {
4522 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4523 pos == buf ? "" : " ");
4524 if (os_snprintf_error(end - pos, ret))
4525 return pos - buf;
4526 pos += ret;
4527 }
4528
4529 #ifdef CONFIG_FILS_SK_PFS
4530 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4531 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4532 pos == buf ? "" : " ");
4533 if (os_snprintf_error(end - pos, ret))
4534 return pos - buf;
4535 pos += ret;
4536 }
4537 #endif /* CONFIG_FILS_SK_PFS */
4538 #endif /* CONFIG_FILS */
4539
4540 #ifdef CONFIG_PASN
4541 ret = os_snprintf(pos, end - pos, "%sPASN",
4542 pos == buf ? "" : " ");
4543 if (os_snprintf_error(end - pos, ret))
4544 return pos - buf;
4545 pos += ret;
4546
4547 #endif /* CONFIG_PASN */
4548
4549 return pos - buf;
4550 }
4551
4552
ctrl_iface_get_capability_modes(int res,bool strict,struct wpa_driver_capa * capa,char * buf,size_t buflen)4553 static int ctrl_iface_get_capability_modes(int res, bool strict,
4554 struct wpa_driver_capa *capa,
4555 char *buf, size_t buflen)
4556 {
4557 int ret;
4558 char *pos, *end;
4559 size_t len;
4560
4561 pos = buf;
4562 end = pos + buflen;
4563
4564 if (res < 0) {
4565 if (strict)
4566 return 0;
4567 len = os_strlcpy(buf, "IBSS AP", buflen);
4568 if (len >= buflen)
4569 return -1;
4570 return len;
4571 }
4572
4573 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
4574 ret = os_snprintf(pos, end - pos, "%sIBSS",
4575 pos == buf ? "" : " ");
4576 if (os_snprintf_error(end - pos, ret))
4577 return pos - buf;
4578 pos += ret;
4579 }
4580
4581 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
4582 ret = os_snprintf(pos, end - pos, "%sAP",
4583 pos == buf ? "" : " ");
4584 if (os_snprintf_error(end - pos, ret))
4585 return pos - buf;
4586 pos += ret;
4587 }
4588
4589 #ifdef CONFIG_MESH
4590 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4591 ret = os_snprintf(pos, end - pos, "%sMESH",
4592 pos == buf ? "" : " ");
4593 if (os_snprintf_error(end - pos, ret))
4594 return pos - buf;
4595 pos += ret;
4596 }
4597 #endif /* CONFIG_MESH */
4598
4599 return pos - buf;
4600 }
4601
4602
ctrl_iface_get_capability_channels(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)4603 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4604 char *buf, size_t buflen)
4605 {
4606 struct hostapd_channel_data *chnl;
4607 int ret, i, j;
4608 char *pos, *end, *hmode;
4609
4610 pos = buf;
4611 end = pos + buflen;
4612
4613 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4614 switch (wpa_s->hw.modes[j].mode) {
4615 case HOSTAPD_MODE_IEEE80211B:
4616 hmode = "B";
4617 break;
4618 case HOSTAPD_MODE_IEEE80211G:
4619 hmode = "G";
4620 break;
4621 case HOSTAPD_MODE_IEEE80211A:
4622 hmode = "A";
4623 break;
4624 case HOSTAPD_MODE_IEEE80211AD:
4625 hmode = "AD";
4626 break;
4627 default:
4628 continue;
4629 }
4630 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
4631 if (os_snprintf_error(end - pos, ret))
4632 return pos - buf;
4633 pos += ret;
4634 chnl = wpa_s->hw.modes[j].channels;
4635 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4636 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4637 continue;
4638 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
4639 if (os_snprintf_error(end - pos, ret))
4640 return pos - buf;
4641 pos += ret;
4642 }
4643 ret = os_snprintf(pos, end - pos, "\n");
4644 if (os_snprintf_error(end - pos, ret))
4645 return pos - buf;
4646 pos += ret;
4647 }
4648
4649 return pos - buf;
4650 }
4651
4652
ctrl_iface_get_capability_freq(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)4653 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4654 char *buf, size_t buflen)
4655 {
4656 struct hostapd_channel_data *chnl;
4657 int ret, i, j;
4658 char *pos, *end, *hmode;
4659
4660 pos = buf;
4661 end = pos + buflen;
4662
4663 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4664 switch (wpa_s->hw.modes[j].mode) {
4665 case HOSTAPD_MODE_IEEE80211B:
4666 hmode = "B";
4667 break;
4668 case HOSTAPD_MODE_IEEE80211G:
4669 hmode = "G";
4670 break;
4671 case HOSTAPD_MODE_IEEE80211A:
4672 hmode = "A";
4673 break;
4674 case HOSTAPD_MODE_IEEE80211AD:
4675 hmode = "AD";
4676 break;
4677 default:
4678 continue;
4679 }
4680 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4681 hmode);
4682 if (os_snprintf_error(end - pos, ret))
4683 return pos - buf;
4684 pos += ret;
4685 chnl = wpa_s->hw.modes[j].channels;
4686 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4687 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4688 continue;
4689 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
4690 chnl[i].chan, chnl[i].freq,
4691 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4692 " (NO_IR)" : "",
4693 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4694 " (DFS)" : "");
4695
4696 if (os_snprintf_error(end - pos, ret))
4697 return pos - buf;
4698 pos += ret;
4699 }
4700 ret = os_snprintf(pos, end - pos, "\n");
4701 if (os_snprintf_error(end - pos, ret))
4702 return pos - buf;
4703 pos += ret;
4704 }
4705
4706 return pos - buf;
4707 }
4708
4709
wpa_supplicant_ctrl_iface_get_capability(struct wpa_supplicant * wpa_s,const char * _field,char * buf,size_t buflen)4710 static int wpa_supplicant_ctrl_iface_get_capability(
4711 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4712 size_t buflen)
4713 {
4714 struct wpa_driver_capa capa;
4715 int res;
4716 char *next_param, *curr_param, *iftype = NULL;
4717 bool strict = false;
4718 char field[50];
4719 size_t len;
4720
4721 /* Determine whether or not strict checking was requested */
4722 len = os_strlcpy(field, _field, sizeof(field));
4723 if (len >= sizeof(field))
4724 return -1;
4725
4726 next_param = os_strchr(field, ' ');
4727 while (next_param) {
4728 *next_param++ = '\0';
4729 curr_param = next_param;
4730 next_param = os_strchr(next_param, ' ');
4731
4732 if (next_param)
4733 *next_param = '\0';
4734
4735 if (os_strcmp(curr_param, "strict") == 0)
4736 strict = true;
4737 else if (os_strncmp(curr_param, "iftype=", 7) == 0)
4738 iftype = curr_param + 7;
4739 else
4740 return -1;
4741 }
4742
4743 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'%s%s%s",
4744 field, iftype ? " iftype=" : "", iftype ? iftype : "",
4745 strict ? " strict" : "");
4746
4747 if (os_strcmp(field, "eap") == 0) {
4748 return eap_get_names(buf, buflen);
4749 }
4750
4751 res = wpa_drv_get_capa(wpa_s, &capa);
4752
4753 if (os_strcmp(field, "pairwise") == 0)
4754 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4755 buf, buflen);
4756
4757 if (os_strcmp(field, "group") == 0)
4758 return ctrl_iface_get_capability_group(res, strict, &capa,
4759 buf, buflen);
4760
4761 if (os_strcmp(field, "group_mgmt") == 0)
4762 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4763 buf, buflen);
4764
4765 if (os_strcmp(field, "key_mgmt") == 0)
4766 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
4767 iftype, buf, buflen);
4768
4769 if (os_strcmp(field, "proto") == 0)
4770 return ctrl_iface_get_capability_proto(res, strict, &capa,
4771 buf, buflen);
4772
4773 if (os_strcmp(field, "auth_alg") == 0)
4774 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4775 &capa, buf, buflen);
4776
4777 if (os_strcmp(field, "modes") == 0)
4778 return ctrl_iface_get_capability_modes(res, strict, &capa,
4779 buf, buflen);
4780
4781 if (os_strcmp(field, "channels") == 0)
4782 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4783
4784 if (os_strcmp(field, "freq") == 0)
4785 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4786
4787 #ifdef CONFIG_TDLS
4788 if (os_strcmp(field, "tdls") == 0)
4789 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4790 #endif /* CONFIG_TDLS */
4791
4792 #ifdef CONFIG_ERP
4793 if (os_strcmp(field, "erp") == 0) {
4794 res = os_snprintf(buf, buflen, "ERP");
4795 if (os_snprintf_error(buflen, res))
4796 return -1;
4797 return res;
4798 }
4799 #endif /* CONFIG_EPR */
4800
4801 #ifdef CONFIG_FIPS
4802 if (os_strcmp(field, "fips") == 0) {
4803 res = os_snprintf(buf, buflen, "FIPS");
4804 if (os_snprintf_error(buflen, res))
4805 return -1;
4806 return res;
4807 }
4808 #endif /* CONFIG_FIPS */
4809
4810 #ifdef CONFIG_ACS
4811 if (os_strcmp(field, "acs") == 0) {
4812 res = os_snprintf(buf, buflen, "ACS");
4813 if (os_snprintf_error(buflen, res))
4814 return -1;
4815 return res;
4816 }
4817 #endif /* CONFIG_ACS */
4818
4819 #ifdef CONFIG_FILS
4820 if (os_strcmp(field, "fils") == 0) {
4821 #ifdef CONFIG_FILS_SK_PFS
4822 if (wpa_is_fils_supported(wpa_s) &&
4823 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4824 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4825 if (os_snprintf_error(buflen, res))
4826 return -1;
4827 return res;
4828 }
4829 #endif /* CONFIG_FILS_SK_PFS */
4830
4831 if (wpa_is_fils_supported(wpa_s)) {
4832 res = os_snprintf(buf, buflen, "FILS");
4833 if (os_snprintf_error(buflen, res))
4834 return -1;
4835 return res;
4836 }
4837 }
4838 #endif /* CONFIG_FILS */
4839
4840 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
4841 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
4842 if (os_snprintf_error(buflen, res))
4843 return -1;
4844 return res;
4845 }
4846
4847 #ifdef CONFIG_DPP
4848 if (os_strcmp(field, "dpp") == 0) {
4849 #ifdef CONFIG_DPP3
4850 res = os_snprintf(buf, buflen, "DPP=3");
4851 #elif defined(CONFIG_DPP2)
4852 res = os_snprintf(buf, buflen, "DPP=2");
4853 #else /* CONFIG_DPP2 */
4854 res = os_snprintf(buf, buflen, "DPP=1");
4855 #endif /* CONFIG_DPP2 */
4856 if (os_snprintf_error(buflen, res))
4857 return -1;
4858 return res;
4859 }
4860 #endif /* CONFIG_DPP */
4861
4862 #ifdef CONFIG_SAE
4863 if (os_strcmp(field, "sae") == 0 &&
4864 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4865 #ifdef CONFIG_SAE_PK
4866 res = os_snprintf(buf, buflen, "H2E PK");
4867 #else /* CONFIG_SAE_PK */
4868 res = os_snprintf(buf, buflen, "H2E");
4869 #endif /* CONFIG_SAE_PK */
4870 if (os_snprintf_error(buflen, res))
4871 return -1;
4872 return res;
4873 }
4874 #endif /* CONFIG_SAE */
4875
4876 #ifdef CONFIG_OCV
4877 if (os_strcmp(field, "ocv") == 0) {
4878 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
4879 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV))
4880 res = os_snprintf(buf, buflen, "supported");
4881 else
4882 res = os_snprintf(buf, buflen, "not supported");
4883 if (os_snprintf_error(buflen, res))
4884 return -1;
4885 return res;
4886 }
4887 #endif /* CONFIG_OCV */
4888
4889 if (os_strcmp(field, "beacon_prot") == 0) {
4890 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) ||
4891 (wpa_s->drv_flags2 &
4892 WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT))
4893 res = os_snprintf(buf, buflen, "supported");
4894 else
4895 res = os_snprintf(buf, buflen, "not supported");
4896 if (os_snprintf_error(buflen, res))
4897 return -1;
4898 return res;
4899 }
4900
4901 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4902 field);
4903
4904 return -1;
4905 }
4906
4907
4908 #ifdef CONFIG_INTERWORKING
anqp_add_hex(char * pos,char * end,const char * title,struct wpabuf * data)4909 static char * anqp_add_hex(char *pos, char *end, const char *title,
4910 struct wpabuf *data)
4911 {
4912 char *start = pos;
4913 size_t i;
4914 int ret;
4915 const u8 *d;
4916
4917 if (data == NULL)
4918 return start;
4919
4920 ret = os_snprintf(pos, end - pos, "%s=", title);
4921 if (os_snprintf_error(end - pos, ret))
4922 return start;
4923 pos += ret;
4924
4925 d = wpabuf_head_u8(data);
4926 for (i = 0; i < wpabuf_len(data); i++) {
4927 ret = os_snprintf(pos, end - pos, "%02x", *d++);
4928 if (os_snprintf_error(end - pos, ret))
4929 return start;
4930 pos += ret;
4931 }
4932
4933 ret = os_snprintf(pos, end - pos, "\n");
4934 if (os_snprintf_error(end - pos, ret))
4935 return start;
4936 pos += ret;
4937
4938 return pos;
4939 }
4940 #endif /* CONFIG_INTERWORKING */
4941
4942
4943 #ifdef CONFIG_FILS
print_fils_indication(struct wpa_bss * bss,char * pos,char * end)4944 static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4945 {
4946 char *start = pos;
4947 const u8 *ie, *ie_end;
4948 u16 info, realms;
4949 int ret;
4950
4951 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4952 if (!ie)
4953 return 0;
4954 ie_end = ie + 2 + ie[1];
4955 ie += 2;
4956 if (ie_end - ie < 2)
4957 return -1;
4958
4959 info = WPA_GET_LE16(ie);
4960 ie += 2;
4961 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4962 if (os_snprintf_error(end - pos, ret))
4963 return 0;
4964 pos += ret;
4965
4966 if (info & BIT(7)) {
4967 /* Cache Identifier Included */
4968 if (ie_end - ie < 2)
4969 return -1;
4970 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4971 ie[0], ie[1]);
4972 if (os_snprintf_error(end - pos, ret))
4973 return 0;
4974 pos += ret;
4975 ie += 2;
4976 }
4977
4978 if (info & BIT(8)) {
4979 /* HESSID Included */
4980 if (ie_end - ie < ETH_ALEN)
4981 return -1;
4982 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4983 MAC2STR(ie));
4984 if (os_snprintf_error(end - pos, ret))
4985 return 0;
4986 pos += ret;
4987 ie += ETH_ALEN;
4988 }
4989
4990 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4991 if (realms) {
4992 if (ie_end - ie < realms * 2)
4993 return -1;
4994 ret = os_snprintf(pos, end - pos, "fils_realms=");
4995 if (os_snprintf_error(end - pos, ret))
4996 return 0;
4997 pos += ret;
4998
4999 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
5000 if (ret <= 0)
5001 return 0;
5002 pos += ret;
5003 ie += realms * 2;
5004 ret = os_snprintf(pos, end - pos, "\n");
5005 if (os_snprintf_error(end - pos, ret))
5006 return 0;
5007 pos += ret;
5008 }
5009
5010 return pos - start;
5011 }
5012 #endif /* CONFIG_FILS */
5013
5014
print_rnr(struct wpa_bss * bss,char * pos,char * end)5015 static int print_rnr(struct wpa_bss *bss, char *pos, char *end)
5016 {
5017 char *start = pos;
5018 const u8 *ie, *ie_end;
5019 unsigned int n = 0;
5020 int ret;
5021
5022 ie = wpa_bss_get_ie(bss, WLAN_EID_REDUCED_NEIGHBOR_REPORT);
5023 if (!ie)
5024 return 0;
5025
5026 ie_end = ie + 2 + ie[1];
5027 ie += 2;
5028
5029 while (ie < ie_end) {
5030 const struct ieee80211_neighbor_ap_info *info =
5031 (const struct ieee80211_neighbor_ap_info *) ie;
5032 const u8 *tbtt_start;
5033 size_t left = ie_end - ie;
5034
5035 if (left < sizeof(struct ieee80211_neighbor_ap_info))
5036 return 0;
5037
5038 left -= sizeof(struct ieee80211_neighbor_ap_info);
5039 if (left < info->tbtt_info_len)
5040 return 0;
5041
5042 ret = os_snprintf(pos, end - pos,
5043 "ap_info[%u]: tbtt_info: hdr=0x%x, len=%u, op_c=%u, channel=%u, ",
5044 n, *ie, info->tbtt_info_len,
5045 info->op_class, info->channel);
5046 if (os_snprintf_error(end - pos, ret))
5047 return 0;
5048 pos += ret;
5049
5050 ie += sizeof(struct ieee80211_neighbor_ap_info);
5051 tbtt_start = ie;
5052 if (info->tbtt_info_len >= 1) {
5053 ret = os_snprintf(pos, end - pos,
5054 "tbtt_offset=%u, ", *ie);
5055 if (os_snprintf_error(end - pos, ret))
5056 return 0;
5057
5058 ie++;
5059 pos += ret;
5060 }
5061
5062 if (info->tbtt_info_len >= 7) {
5063 ret = os_snprintf(pos, end - pos,
5064 "bssid=" MACSTR ", ",
5065 MAC2STR(ie));
5066 if (os_snprintf_error(end - pos, ret))
5067 return 0;
5068
5069 ie += ETH_ALEN;
5070 pos += ret;
5071 }
5072
5073 if (info->tbtt_info_len >= 11) {
5074 ret = os_snprintf(pos, end - pos,
5075 "short SSID=0x%x, ",
5076 WPA_GET_LE32(ie));
5077 if (os_snprintf_error(end - pos, ret))
5078 return 0;
5079
5080 ie += 4;
5081 pos += ret;
5082 }
5083
5084 if (info->tbtt_info_len >= 12) {
5085 ret = os_snprintf(pos, end - pos,
5086 "bss_params=0x%x, ", *ie);
5087 if (os_snprintf_error(end - pos, ret))
5088 return 0;
5089
5090 ie++;
5091 pos += ret;
5092 }
5093
5094 if (info->tbtt_info_len >= 13) {
5095 ret = os_snprintf(pos, end - pos,
5096 "PSD=0x%x, ", *ie);
5097 if (os_snprintf_error(end - pos, ret))
5098 return 0;
5099
5100 ie++;
5101 pos += ret;
5102 }
5103
5104 if (info->tbtt_info_len >= 16) {
5105 ret = os_snprintf(pos, end - pos,
5106 "mld ID=%u, link ID=%u",
5107 *ie, *(ie + 1) & 0xF);
5108 if (os_snprintf_error(end - pos, ret))
5109 return 0;
5110
5111 ie += 3;
5112 pos += ret;
5113 }
5114
5115 ie = tbtt_start + info->tbtt_info_len;
5116
5117 ret = os_snprintf(pos, end - pos, "\n");
5118 if (os_snprintf_error(end - pos, ret))
5119 return 0;
5120 pos += ret;
5121
5122 n++;
5123 }
5124
5125 return pos - start;
5126 }
5127
5128
print_ml(struct wpa_bss * bss,char * pos,char * end)5129 static int print_ml(struct wpa_bss *bss, char *pos, char *end)
5130 {
5131 const struct ieee80211_eht_ml *ml;
5132 char *start = pos;
5133 const u8 *ie, *ie_end;
5134 u16 ml_control;
5135 u8 common_info_length;
5136 int ret;
5137
5138 ie = get_ml_ie(wpa_bss_ie_ptr(bss), bss->ie_len,
5139 MULTI_LINK_CONTROL_TYPE_BASIC);
5140 if (!ie)
5141 return 0;
5142
5143 ie_end = ie + 2 + ie[1];
5144 ie += 3;
5145 ml = (const struct ieee80211_eht_ml *) ie;
5146
5147 /* control + common info length + MLD MAC Address */
5148 if (ie_end - ie < 2 + 1 + ETH_ALEN)
5149 return 0;
5150
5151 ml_control = le_to_host16(ml->ml_control);
5152
5153 common_info_length = *(ie + 2);
5154 ret = os_snprintf(pos, end - pos,
5155 "multi-link: control=0x%x, common info len=%u",
5156 ml_control, common_info_length);
5157 if (os_snprintf_error(end - pos, ret))
5158 return 0;
5159 pos += ret;
5160
5161 ie += 2;
5162 if (ie_end - ie < common_info_length)
5163 return 0;
5164
5165 ie++;
5166 common_info_length--;
5167
5168 if (common_info_length < ETH_ALEN)
5169 return 0;
5170
5171 ret = os_snprintf(pos, end - pos, ", MLD addr=" MACSTR, MAC2STR(ie));
5172 if (os_snprintf_error(end - pos, ret))
5173 return 0;
5174 pos += ret;
5175
5176 ie += ETH_ALEN;
5177 common_info_length -= ETH_ALEN;
5178
5179 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_LINK_ID) {
5180 if (common_info_length < 1)
5181 return 0;
5182
5183 ret = os_snprintf(pos, end - pos, ", link ID=%u", *ie & 0x0f);
5184 if (os_snprintf_error(end - pos, ret))
5185 return 0;
5186 pos += ret;
5187 ie++;
5188 common_info_length--;
5189 }
5190
5191 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT) {
5192 if (common_info_length < 1)
5193 return 0;
5194
5195 ret = os_snprintf(pos, end - pos,
5196 ", BSS change parameters=0x%x", *ie);
5197 if (os_snprintf_error(end - pos, ret))
5198 return 0;
5199 pos += ret;
5200 ie++;
5201 common_info_length--;
5202 }
5203
5204 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
5205 if (common_info_length < 2)
5206 return 0;
5207
5208 ret = os_snprintf(pos, end - pos, ", MSD Info=0x%x",
5209 WPA_GET_LE16(ie));
5210 if (os_snprintf_error(end - pos, ret))
5211 return 0;
5212 pos += ret;
5213 ie += 2;
5214 common_info_length -= 2;
5215 }
5216
5217 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
5218 if (common_info_length < 2)
5219 return 0;
5220
5221 ret = os_snprintf(pos, end - pos, ", EML capabilities=0x%x",
5222 WPA_GET_LE16(ie));
5223 if (os_snprintf_error(end - pos, ret))
5224 return 0;
5225 pos += ret;
5226 ie += 2;
5227 common_info_length -= 2;
5228 }
5229
5230 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
5231 if (common_info_length < 2)
5232 return 0;
5233
5234 ret = os_snprintf(pos, end - pos, ", MLD capabilities=0x%x",
5235 WPA_GET_LE16(ie));
5236 if (os_snprintf_error(end - pos, ret))
5237 return 0;
5238 pos += ret;
5239 ie += 2;
5240 common_info_length -= 2;
5241 }
5242
5243 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
5244 if (common_info_length < 1)
5245 return 0;
5246
5247 ret = os_snprintf(pos, end - pos, ", MLD ID=0x%x\n", *ie);
5248 if (os_snprintf_error(end - pos, ret))
5249 return 0;
5250 pos += ret;
5251 ie += 1;
5252 common_info_length--;
5253 }
5254
5255 return pos - start;
5256 }
5257
5258
print_bss_info(struct wpa_supplicant * wpa_s,struct wpa_bss * bss,unsigned long mask,char * buf,size_t buflen)5259 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
5260 unsigned long mask, char *buf, size_t buflen)
5261 {
5262 size_t i;
5263 int ret;
5264 char *pos, *end;
5265 const u8 *ie, *ie2, *osen_ie, *mesh, *owe, *rsnxe;
5266
5267 pos = buf;
5268 end = buf + buflen;
5269
5270 if (mask & WPA_BSS_MASK_ID) {
5271 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
5272 if (os_snprintf_error(end - pos, ret))
5273 return 0;
5274 pos += ret;
5275 }
5276
5277 if (mask & WPA_BSS_MASK_BSSID) {
5278 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
5279 MAC2STR(bss->bssid));
5280 if (os_snprintf_error(end - pos, ret))
5281 return 0;
5282 pos += ret;
5283 }
5284
5285 if (mask & WPA_BSS_MASK_FREQ) {
5286 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
5287 if (os_snprintf_error(end - pos, ret))
5288 return 0;
5289 pos += ret;
5290 }
5291
5292 if (mask & WPA_BSS_MASK_BEACON_INT) {
5293 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
5294 bss->beacon_int);
5295 if (os_snprintf_error(end - pos, ret))
5296 return 0;
5297 pos += ret;
5298 }
5299
5300 if (mask & WPA_BSS_MASK_CAPABILITIES) {
5301 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
5302 bss->caps);
5303 if (os_snprintf_error(end - pos, ret))
5304 return 0;
5305 pos += ret;
5306 }
5307
5308 if (mask & WPA_BSS_MASK_QUAL) {
5309 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
5310 if (os_snprintf_error(end - pos, ret))
5311 return 0;
5312 pos += ret;
5313 }
5314
5315 if (mask & WPA_BSS_MASK_NOISE) {
5316 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
5317 if (os_snprintf_error(end - pos, ret))
5318 return 0;
5319 pos += ret;
5320 }
5321
5322 if (mask & WPA_BSS_MASK_LEVEL) {
5323 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
5324 if (os_snprintf_error(end - pos, ret))
5325 return 0;
5326 pos += ret;
5327 }
5328
5329 if (mask & WPA_BSS_MASK_TSF) {
5330 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
5331 (unsigned long long) bss->tsf);
5332 if (os_snprintf_error(end - pos, ret))
5333 return 0;
5334 pos += ret;
5335 }
5336
5337 if (mask & WPA_BSS_MASK_AGE) {
5338 struct os_reltime now;
5339
5340 os_get_reltime(&now);
5341 ret = os_snprintf(pos, end - pos, "age=%d\n",
5342 (int) (now.sec - bss->last_update.sec));
5343 if (os_snprintf_error(end - pos, ret))
5344 return 0;
5345 pos += ret;
5346 }
5347
5348 if (mask & WPA_BSS_MASK_IE) {
5349 ret = os_snprintf(pos, end - pos, "ie=");
5350 if (os_snprintf_error(end - pos, ret))
5351 return 0;
5352 pos += ret;
5353
5354 ie = wpa_bss_ie_ptr(bss);
5355 for (i = 0; i < bss->ie_len; i++) {
5356 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
5357 if (os_snprintf_error(end - pos, ret))
5358 return 0;
5359 pos += ret;
5360 }
5361
5362 ret = os_snprintf(pos, end - pos, "\n");
5363 if (os_snprintf_error(end - pos, ret))
5364 return 0;
5365 pos += ret;
5366 }
5367
5368 if (mask & WPA_BSS_MASK_FLAGS) {
5369 ret = os_snprintf(pos, end - pos, "flags=");
5370 if (os_snprintf_error(end - pos, ret))
5371 return 0;
5372 pos += ret;
5373
5374 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
5375
5376 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
5377 if (ie)
5378 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
5379 2 + ie[1]);
5380 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
5381 if (ie2)
5382 pos = wpa_supplicant_ie_txt(pos, end,
5383 mesh ? "RSN" : "WPA2", ie2,
5384 2 + ie2[1]);
5385 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
5386 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
5387 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
5388 if (os_snprintf_error(end - pos, ret))
5389 return -1;
5390 pos += ret;
5391 }
5392 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
5393 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
5394 if (os_snprintf_error(end - pos, ret))
5395 return -1;
5396 pos += ret;
5397 }
5398 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
5399 if (osen_ie)
5400 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
5401 osen_ie, 2 + osen_ie[1]);
5402 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
5403 if (owe) {
5404 ret = os_snprintf(
5405 pos, end - pos,
5406 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
5407 if (os_snprintf_error(end - pos, ret))
5408 return 0;
5409 pos += ret;
5410 }
5411 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
5412 if (!ie && !ie2 && !osen_ie &&
5413 (bss->caps & IEEE80211_CAP_PRIVACY)) {
5414 ret = os_snprintf(pos, end - pos, "[WEP]");
5415 if (os_snprintf_error(end - pos, ret))
5416 return 0;
5417 pos += ret;
5418 }
5419
5420 if (mesh) {
5421 ret = os_snprintf(pos, end - pos, "[MESH]");
5422 if (os_snprintf_error(end - pos, ret))
5423 return 0;
5424 pos += ret;
5425 }
5426
5427 if (bss_is_dmg(bss)) {
5428 const char *s;
5429 ret = os_snprintf(pos, end - pos, "[DMG]");
5430 if (os_snprintf_error(end - pos, ret))
5431 return 0;
5432 pos += ret;
5433 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
5434 case IEEE80211_CAP_DMG_IBSS:
5435 s = "[IBSS]";
5436 break;
5437 case IEEE80211_CAP_DMG_AP:
5438 s = "[ESS]";
5439 break;
5440 case IEEE80211_CAP_DMG_PBSS:
5441 s = "[PBSS]";
5442 break;
5443 default:
5444 s = "";
5445 break;
5446 }
5447 ret = os_snprintf(pos, end - pos, "%s", s);
5448 if (os_snprintf_error(end - pos, ret))
5449 return 0;
5450 pos += ret;
5451 } else {
5452 if (bss->caps & IEEE80211_CAP_IBSS) {
5453 ret = os_snprintf(pos, end - pos, "[IBSS]");
5454 if (os_snprintf_error(end - pos, ret))
5455 return 0;
5456 pos += ret;
5457 }
5458 if (bss->caps & IEEE80211_CAP_ESS) {
5459 ret = os_snprintf(pos, end - pos, "[ESS]");
5460 if (os_snprintf_error(end - pos, ret))
5461 return 0;
5462 pos += ret;
5463 }
5464 }
5465 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
5466 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
5467 ret = os_snprintf(pos, end - pos, "[P2P]");
5468 if (os_snprintf_error(end - pos, ret))
5469 return 0;
5470 pos += ret;
5471 }
5472 #ifdef CONFIG_HS20
5473 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
5474 ret = os_snprintf(pos, end - pos, "[HS20]");
5475 if (os_snprintf_error(end - pos, ret))
5476 return 0;
5477 pos += ret;
5478 }
5479 #endif /* CONFIG_HS20 */
5480 #ifdef CONFIG_FILS
5481 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
5482 ret = os_snprintf(pos, end - pos, "[FILS]");
5483 if (os_snprintf_error(end - pos, ret))
5484 return 0;
5485 pos += ret;
5486 }
5487 #endif /* CONFIG_FILS */
5488 #ifdef CONFIG_FST
5489 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
5490 ret = os_snprintf(pos, end - pos, "[FST]");
5491 if (os_snprintf_error(end - pos, ret))
5492 return 0;
5493 pos += ret;
5494 }
5495 #endif /* CONFIG_FST */
5496 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
5497 ret = os_snprintf(pos, end - pos, "[UTF-8]");
5498 if (os_snprintf_error(end - pos, ret))
5499 return 0;
5500 pos += ret;
5501 }
5502
5503 ret = os_snprintf(pos, end - pos, "\n");
5504 if (os_snprintf_error(end - pos, ret))
5505 return 0;
5506 pos += ret;
5507 }
5508
5509 if (mask & WPA_BSS_MASK_SSID) {
5510 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
5511 wpa_ssid_txt(bss->ssid, bss->ssid_len));
5512 if (os_snprintf_error(end - pos, ret))
5513 return 0;
5514 pos += ret;
5515 }
5516
5517 #ifdef CONFIG_WPS
5518 if (mask & WPA_BSS_MASK_WPS_SCAN) {
5519 ie = wpa_bss_ie_ptr(bss);
5520 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
5521 if (ret >= end - pos)
5522 return 0;
5523 if (ret > 0)
5524 pos += ret;
5525 }
5526 #endif /* CONFIG_WPS */
5527
5528 #ifdef CONFIG_P2P
5529 if (mask & WPA_BSS_MASK_P2P_SCAN) {
5530 ie = wpa_bss_ie_ptr(bss);
5531 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
5532 if (ret >= end - pos)
5533 return 0;
5534 if (ret > 0)
5535 pos += ret;
5536 }
5537 #endif /* CONFIG_P2P */
5538
5539 #ifdef CONFIG_WIFI_DISPLAY
5540 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
5541 struct wpabuf *wfd;
5542
5543 ie = wpa_bss_ie_ptr(bss);
5544 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
5545 WFD_IE_VENDOR_TYPE);
5546 if (wfd) {
5547 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
5548 if (os_snprintf_error(end - pos, ret)) {
5549 wpabuf_free(wfd);
5550 return 0;
5551 }
5552 pos += ret;
5553
5554 pos += wpa_snprintf_hex(pos, end - pos,
5555 wpabuf_head(wfd),
5556 wpabuf_len(wfd));
5557 wpabuf_free(wfd);
5558
5559 ret = os_snprintf(pos, end - pos, "\n");
5560 if (os_snprintf_error(end - pos, ret))
5561 return 0;
5562 pos += ret;
5563 }
5564 }
5565 #endif /* CONFIG_WIFI_DISPLAY */
5566
5567 #ifdef CONFIG_INTERWORKING
5568 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
5569 struct wpa_bss_anqp *anqp = bss->anqp;
5570 struct wpa_bss_anqp_elem *elem;
5571
5572 pos = anqp_add_hex(pos, end, "anqp_capability_list",
5573 anqp->capability_list);
5574 pos = anqp_add_hex(pos, end, "anqp_venue_name",
5575 anqp->venue_name);
5576 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
5577 anqp->network_auth_type);
5578 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
5579 anqp->roaming_consortium);
5580 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
5581 anqp->ip_addr_type_availability);
5582 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
5583 anqp->nai_realm);
5584 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
5585 pos = anqp_add_hex(pos, end, "anqp_domain_name",
5586 anqp->domain_name);
5587 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
5588 anqp->fils_realm_info);
5589 #ifdef CONFIG_HS20
5590 pos = anqp_add_hex(pos, end, "hs20_capability_list",
5591 anqp->hs20_capability_list);
5592 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
5593 anqp->hs20_operator_friendly_name);
5594 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
5595 anqp->hs20_wan_metrics);
5596 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
5597 anqp->hs20_connection_capability);
5598 pos = anqp_add_hex(pos, end, "hs20_operating_class",
5599 anqp->hs20_operating_class);
5600 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
5601 anqp->hs20_osu_providers_list);
5602 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
5603 anqp->hs20_operator_icon_metadata);
5604 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
5605 anqp->hs20_osu_providers_nai_list);
5606 #endif /* CONFIG_HS20 */
5607
5608 dl_list_for_each(elem, &anqp->anqp_elems,
5609 struct wpa_bss_anqp_elem, list) {
5610 char title[20];
5611
5612 os_snprintf(title, sizeof(title), "anqp[%u]",
5613 elem->infoid);
5614 pos = anqp_add_hex(pos, end, title, elem->payload);
5615 if (elem->protected_response) {
5616 ret = os_snprintf(pos, end - pos,
5617 "protected-anqp-info[%u]=1\n",
5618 elem->infoid);
5619 if (os_snprintf_error(end - pos, ret))
5620 return 0;
5621 pos += ret;
5622 }
5623 }
5624 }
5625 #endif /* CONFIG_INTERWORKING */
5626
5627 #ifdef CONFIG_MESH
5628 if (mask & WPA_BSS_MASK_MESH_SCAN) {
5629 ie = wpa_bss_ie_ptr(bss);
5630 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
5631 if (ret >= end - pos)
5632 return 0;
5633 if (ret > 0)
5634 pos += ret;
5635 }
5636 #endif /* CONFIG_MESH */
5637
5638 if (mask & WPA_BSS_MASK_SNR) {
5639 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
5640 if (os_snprintf_error(end - pos, ret))
5641 return 0;
5642 pos += ret;
5643 }
5644
5645 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
5646 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
5647 bss->est_throughput);
5648 if (os_snprintf_error(end - pos, ret))
5649 return 0;
5650 pos += ret;
5651 }
5652
5653 #ifdef CONFIG_FST
5654 if (mask & WPA_BSS_MASK_FST) {
5655 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
5656 if (ret < 0 || ret >= end - pos)
5657 return 0;
5658 pos += ret;
5659 }
5660 #endif /* CONFIG_FST */
5661
5662 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
5663 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
5664 bss->last_update_idx);
5665 if (os_snprintf_error(end - pos, ret))
5666 return 0;
5667 pos += ret;
5668 }
5669
5670 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
5671 ret = os_snprintf(pos, end - pos, "beacon_ie=");
5672 if (os_snprintf_error(end - pos, ret))
5673 return 0;
5674 pos += ret;
5675
5676 ie = wpa_bss_ie_ptr(bss);
5677 ie += bss->ie_len;
5678 for (i = 0; i < bss->beacon_ie_len; i++) {
5679 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
5680 if (os_snprintf_error(end - pos, ret))
5681 return 0;
5682 pos += ret;
5683 }
5684
5685 ret = os_snprintf(pos, end - pos, "\n");
5686 if (os_snprintf_error(end - pos, ret))
5687 return 0;
5688 pos += ret;
5689 }
5690
5691 #ifdef CONFIG_FILS
5692 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
5693 ret = print_fils_indication(bss, pos, end);
5694 if (ret < 0)
5695 return 0;
5696 pos += ret;
5697 }
5698 #endif /* CONFIG_FILS */
5699
5700 if (!is_zero_ether_addr(bss->mld_addr) &&
5701 (mask & WPA_BSS_MASK_AP_MLD_ADDR)) {
5702 ret = os_snprintf(pos, end - pos,
5703 "ap_mld_addr=" MACSTR "\n",
5704 MAC2STR(bss->mld_addr));
5705 if (os_snprintf_error(end - pos, ret))
5706 return 0;
5707 pos += ret;
5708 }
5709
5710 if (mask & WPA_BSS_MASK_RNR)
5711 pos += print_rnr(bss, pos, end);
5712
5713 if (mask & WPA_BSS_MASK_ML)
5714 pos += print_ml(bss, pos, end);
5715
5716 if (mask & WPA_BSS_MASK_DELIM) {
5717 ret = os_snprintf(pos, end - pos, "====\n");
5718 if (os_snprintf_error(end - pos, ret))
5719 return 0;
5720 pos += ret;
5721 }
5722
5723 return pos - buf;
5724 }
5725
5726
wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant * wpa_s,const char * cmd,char * buf,size_t buflen)5727 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
5728 const char *cmd, char *buf,
5729 size_t buflen)
5730 {
5731 u8 bssid[ETH_ALEN];
5732 size_t i;
5733 struct wpa_bss *bss;
5734 struct wpa_bss *bsslast = NULL;
5735 struct dl_list *next;
5736 int ret = 0;
5737 int len;
5738 char *ctmp, *end = buf + buflen;
5739 unsigned long mask = WPA_BSS_MASK_ALL;
5740
5741 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
5742 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
5743 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
5744 list_id);
5745 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
5746 list_id);
5747 } else { /* N1-N2 */
5748 unsigned int id1, id2;
5749
5750 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
5751 wpa_printf(MSG_INFO, "Wrong BSS range "
5752 "format");
5753 return 0;
5754 }
5755
5756 if (*(cmd + 6) == '-')
5757 id1 = 0;
5758 else
5759 id1 = atoi(cmd + 6);
5760 ctmp++;
5761 if (*ctmp >= '0' && *ctmp <= '9')
5762 id2 = atoi(ctmp);
5763 else
5764 id2 = (unsigned int) -1;
5765 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
5766 if (id2 == (unsigned int) -1)
5767 bsslast = dl_list_last(&wpa_s->bss_id,
5768 struct wpa_bss,
5769 list_id);
5770 else {
5771 bsslast = wpa_bss_get_id(wpa_s, id2);
5772 if (bsslast == NULL && bss && id2 > id1) {
5773 struct wpa_bss *tmp = bss;
5774 for (;;) {
5775 next = tmp->list_id.next;
5776 if (next == &wpa_s->bss_id)
5777 break;
5778 tmp = dl_list_entry(
5779 next, struct wpa_bss,
5780 list_id);
5781 if (tmp->id > id2)
5782 break;
5783 bsslast = tmp;
5784 }
5785 }
5786 }
5787 }
5788 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
5789 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
5790 else if (os_strncmp(cmd, "LAST", 4) == 0)
5791 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
5792 else if (os_strncmp(cmd, "ID-", 3) == 0) {
5793 i = atoi(cmd + 3);
5794 bss = wpa_bss_get_id(wpa_s, i);
5795 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5796 i = atoi(cmd + 5);
5797 bss = wpa_bss_get_id(wpa_s, i);
5798 if (bss) {
5799 next = bss->list_id.next;
5800 if (next == &wpa_s->bss_id)
5801 bss = NULL;
5802 else
5803 bss = dl_list_entry(next, struct wpa_bss,
5804 list_id);
5805 }
5806 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5807 bss = wpa_s->current_bss;
5808 #ifdef CONFIG_P2P
5809 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5810 if (hwaddr_aton(cmd + 13, bssid) == 0)
5811 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5812 else
5813 bss = NULL;
5814 #endif /* CONFIG_P2P */
5815 } else if (hwaddr_aton(cmd, bssid) == 0)
5816 bss = wpa_bss_get_bssid(wpa_s, bssid);
5817 else {
5818 struct wpa_bss *tmp;
5819 i = atoi(cmd);
5820 bss = NULL;
5821 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5822 {
5823 if (i == 0) {
5824 bss = tmp;
5825 break;
5826 }
5827 i--;
5828 }
5829 }
5830
5831 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5832 mask = strtoul(ctmp + 5, NULL, 0x10);
5833 if (mask == 0)
5834 mask = WPA_BSS_MASK_ALL;
5835 }
5836
5837 if (bss == NULL)
5838 return 0;
5839
5840 if (bsslast == NULL)
5841 bsslast = bss;
5842 do {
5843 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5844 ret += len;
5845 buf += len;
5846 buflen -= len;
5847 if (bss == bsslast) {
5848 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5849 (bss == dl_list_last(&wpa_s->bss_id,
5850 struct wpa_bss, list_id))) {
5851 int res;
5852
5853 res = os_snprintf(buf - 5, end - buf + 5,
5854 "####\n");
5855 if (os_snprintf_error(end - buf + 5, res)) {
5856 wpa_printf(MSG_DEBUG,
5857 "Could not add end delim");
5858 }
5859 }
5860 break;
5861 }
5862 next = bss->list_id.next;
5863 if (next == &wpa_s->bss_id)
5864 break;
5865 bss = dl_list_entry(next, struct wpa_bss, list_id);
5866 } while (bss && len);
5867
5868 return ret;
5869 }
5870
5871
wpa_supplicant_ctrl_iface_ap_scan(struct wpa_supplicant * wpa_s,char * cmd)5872 static int wpa_supplicant_ctrl_iface_ap_scan(
5873 struct wpa_supplicant *wpa_s, char *cmd)
5874 {
5875 int ap_scan = atoi(cmd);
5876 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5877 }
5878
5879
wpa_supplicant_ctrl_iface_scan_interval(struct wpa_supplicant * wpa_s,char * cmd)5880 static int wpa_supplicant_ctrl_iface_scan_interval(
5881 struct wpa_supplicant *wpa_s, char *cmd)
5882 {
5883 int scan_int = atoi(cmd);
5884 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
5885 }
5886
5887
wpa_supplicant_ctrl_iface_bss_expire_age(struct wpa_supplicant * wpa_s,char * cmd)5888 static int wpa_supplicant_ctrl_iface_bss_expire_age(
5889 struct wpa_supplicant *wpa_s, char *cmd)
5890 {
5891 int expire_age = atoi(cmd);
5892 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5893 }
5894
5895
wpa_supplicant_ctrl_iface_bss_expire_count(struct wpa_supplicant * wpa_s,char * cmd)5896 static int wpa_supplicant_ctrl_iface_bss_expire_count(
5897 struct wpa_supplicant *wpa_s, char *cmd)
5898 {
5899 int expire_count = atoi(cmd);
5900 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5901 }
5902
5903
wpa_supplicant_ctrl_iface_bss_flush(struct wpa_supplicant * wpa_s,char * cmd)5904 static void wpa_supplicant_ctrl_iface_bss_flush(
5905 struct wpa_supplicant *wpa_s, char *cmd)
5906 {
5907 int flush_age = atoi(cmd);
5908
5909 if (flush_age == 0)
5910 wpa_bss_flush(wpa_s);
5911 else
5912 wpa_bss_flush_by_age(wpa_s, flush_age);
5913 }
5914
5915
5916 #ifdef CONFIG_TESTING_OPTIONS
wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant * wpa_s)5917 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5918 {
5919 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5920 /* MLME-DELETEKEYS.request */
5921 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL,
5922 0, KEY_FLAG_GROUP);
5923 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL,
5924 0, KEY_FLAG_GROUP);
5925 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL,
5926 0, KEY_FLAG_GROUP);
5927 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL,
5928 0, KEY_FLAG_GROUP);
5929 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL,
5930 0, KEY_FLAG_GROUP);
5931 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL,
5932 0, KEY_FLAG_GROUP);
5933
5934 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0,
5935 NULL, 0, KEY_FLAG_PAIRWISE);
5936 if (wpa_sm_ext_key_id(wpa_s->wpa))
5937 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, wpa_s->bssid, 1, 0,
5938 NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE);
5939 /* MLME-SETPROTECTION.request(None) */
5940 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5941 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5942 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5943 wpa_sm_drop_sa(wpa_s->wpa);
5944 }
5945 #endif /* CONFIG_TESTING_OPTIONS */
5946
5947
wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant * wpa_s,char * addr)5948 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5949 char *addr)
5950 {
5951 #ifdef CONFIG_NO_SCAN_PROCESSING
5952 return -1;
5953 #else /* CONFIG_NO_SCAN_PROCESSING */
5954 u8 bssid[ETH_ALEN];
5955 struct wpa_bss *bss;
5956 struct wpa_ssid *ssid = wpa_s->current_ssid;
5957 struct wpa_radio_work *already_connecting;
5958
5959 if (hwaddr_aton(addr, bssid)) {
5960 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5961 "address '%s'", addr);
5962 return -1;
5963 }
5964
5965 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5966
5967 if (!ssid) {
5968 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5969 "configuration known for the target AP");
5970 return -1;
5971 }
5972
5973 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
5974 if (!bss) {
5975 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
5976 "from BSS table");
5977 return -1;
5978 }
5979
5980 /*
5981 * TODO: Find best network configuration block from configuration to
5982 * allow roaming to other networks
5983 */
5984
5985 already_connecting = radio_work_pending(wpa_s, "sme-connect");
5986 wpa_s->reassociate = 1;
5987 wpa_supplicant_connect(wpa_s, bss, ssid);
5988
5989 /*
5990 * Indicate that an explicitly requested roam is in progress so scan
5991 * results that come in before the 'sme-connect' radio work gets
5992 * executed do not override the original connection attempt.
5993 */
5994 if (!already_connecting && radio_work_pending(wpa_s, "sme-connect"))
5995 wpa_s->roam_in_progress = true;
5996
5997 return 0;
5998 #endif /* CONFIG_NO_SCAN_PROCESSING */
5999 }
6000
6001
6002 #ifdef CONFIG_P2P
p2p_ctrl_find(struct wpa_supplicant * wpa_s,char * cmd)6003 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
6004 {
6005 unsigned int timeout = atoi(cmd);
6006 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
6007 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
6008 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
6009 char *pos;
6010 unsigned int search_delay;
6011 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
6012 u8 seek_count = 0;
6013 int freq = 0;
6014 bool include_6ghz = false;
6015
6016 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6017 wpa_dbg(wpa_s, MSG_INFO,
6018 "Reject P2P_FIND since interface is disabled");
6019 return -1;
6020 }
6021
6022 if (os_strstr(cmd, " include_6ghz"))
6023 include_6ghz = true;
6024 if (os_strstr(cmd, "type=social"))
6025 type = P2P_FIND_ONLY_SOCIAL;
6026 else if (os_strstr(cmd, "type=progressive"))
6027 type = P2P_FIND_PROGRESSIVE;
6028
6029 pos = os_strstr(cmd, "dev_id=");
6030 if (pos) {
6031 pos += 7;
6032 if (hwaddr_aton(pos, dev_id))
6033 return -1;
6034 _dev_id = dev_id;
6035 }
6036
6037 pos = os_strstr(cmd, "dev_type=");
6038 if (pos) {
6039 pos += 9;
6040 if (wps_dev_type_str2bin(pos, dev_type) < 0)
6041 return -1;
6042 _dev_type = dev_type;
6043 }
6044
6045 pos = os_strstr(cmd, "delay=");
6046 if (pos) {
6047 pos += 6;
6048 search_delay = atoi(pos);
6049 } else
6050 search_delay = wpas_p2p_search_delay(wpa_s);
6051
6052 pos = os_strstr(cmd, "freq=");
6053 if (pos) {
6054 pos += 5;
6055 freq = atoi(pos);
6056 if (freq <= 0)
6057 return -1;
6058 }
6059
6060 /* Must be searched for last, because it adds nul termination */
6061 pos = os_strstr(cmd, " seek=");
6062 if (pos)
6063 pos += 6;
6064 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
6065 char *term;
6066
6067 _seek[seek_count++] = pos;
6068 seek = _seek;
6069 term = os_strchr(pos, ' ');
6070 if (!term)
6071 break;
6072 *term = '\0';
6073 pos = os_strstr(term + 1, "seek=");
6074 if (pos)
6075 pos += 5;
6076 }
6077 if (seek_count > P2P_MAX_QUERY_HASH) {
6078 seek[0] = NULL;
6079 seek_count = 1;
6080 }
6081
6082 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
6083 _dev_id, search_delay, seek_count, seek, freq,
6084 include_6ghz);
6085 }
6086
6087
p2ps_ctrl_parse_cpt_priority(const char * pos,u8 * cpt)6088 static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
6089 {
6090 const char *last = NULL;
6091 const char *token;
6092 long int token_len;
6093 unsigned int i;
6094
6095 /* Expected predefined CPT names delimited by ':' */
6096 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
6097 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
6098 wpa_printf(MSG_ERROR,
6099 "P2PS: CPT name list is too long, expected up to %d names",
6100 P2PS_FEATURE_CAPAB_CPT_MAX);
6101 cpt[0] = 0;
6102 return -1;
6103 }
6104
6105 token_len = last - token;
6106
6107 if (token_len == 3 &&
6108 os_memcmp(token, "UDP", token_len) == 0) {
6109 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6110 } else if (token_len == 3 &&
6111 os_memcmp(token, "MAC", token_len) == 0) {
6112 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
6113 } else {
6114 wpa_printf(MSG_ERROR,
6115 "P2PS: Unsupported CPT name '%s'", token);
6116 cpt[0] = 0;
6117 return -1;
6118 }
6119
6120 if (isblank((unsigned char) *last)) {
6121 i++;
6122 break;
6123 }
6124 }
6125 cpt[i] = 0;
6126 return 0;
6127 }
6128
6129
p2p_parse_asp_provision_cmd(const char * cmd)6130 static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
6131 {
6132 struct p2ps_provision *p2ps_prov;
6133 char *pos;
6134 size_t info_len = 0;
6135 char *info = NULL;
6136 u8 role = P2PS_SETUP_NONE;
6137 long long unsigned val;
6138 int i;
6139
6140 pos = os_strstr(cmd, "info=");
6141 if (pos) {
6142 pos += 5;
6143 info_len = os_strlen(pos);
6144
6145 if (info_len) {
6146 info = os_malloc(info_len + 1);
6147 if (info) {
6148 info_len = utf8_unescape(pos, info_len,
6149 info, info_len + 1);
6150 } else
6151 info_len = 0;
6152 }
6153 }
6154
6155 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
6156 if (p2ps_prov == NULL) {
6157 os_free(info);
6158 return NULL;
6159 }
6160
6161 if (info) {
6162 os_memcpy(p2ps_prov->info, info, info_len);
6163 p2ps_prov->info[info_len] = '\0';
6164 os_free(info);
6165 }
6166
6167 pos = os_strstr(cmd, "status=");
6168 if (pos)
6169 p2ps_prov->status = atoi(pos + 7);
6170 else
6171 p2ps_prov->status = -1;
6172
6173 pos = os_strstr(cmd, "adv_id=");
6174 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
6175 goto invalid_args;
6176 p2ps_prov->adv_id = val;
6177
6178 pos = os_strstr(cmd, "method=");
6179 if (pos)
6180 p2ps_prov->method = strtol(pos + 7, NULL, 16);
6181 else
6182 p2ps_prov->method = 0;
6183
6184 pos = os_strstr(cmd, "session=");
6185 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
6186 goto invalid_args;
6187 p2ps_prov->session_id = val;
6188
6189 pos = os_strstr(cmd, "adv_mac=");
6190 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
6191 goto invalid_args;
6192
6193 pos = os_strstr(cmd, "session_mac=");
6194 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
6195 goto invalid_args;
6196
6197 pos = os_strstr(cmd, "cpt=");
6198 if (pos) {
6199 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
6200 p2ps_prov->cpt_priority))
6201 goto invalid_args;
6202 } else {
6203 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6204 }
6205
6206 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
6207 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
6208
6209 /* force conncap with tstCap (no validity checks) */
6210 pos = os_strstr(cmd, "tstCap=");
6211 if (pos) {
6212 role = strtol(pos + 7, NULL, 16);
6213 } else {
6214 pos = os_strstr(cmd, "role=");
6215 if (pos) {
6216 role = strtol(pos + 5, NULL, 16);
6217 if (role != P2PS_SETUP_CLIENT &&
6218 role != P2PS_SETUP_GROUP_OWNER)
6219 role = P2PS_SETUP_NONE;
6220 }
6221 }
6222 p2ps_prov->role = role;
6223
6224 return p2ps_prov;
6225
6226 invalid_args:
6227 os_free(p2ps_prov);
6228 return NULL;
6229 }
6230
6231
p2p_ctrl_asp_provision_resp(struct wpa_supplicant * wpa_s,char * cmd)6232 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
6233 {
6234 u8 addr[ETH_ALEN];
6235 struct p2ps_provision *p2ps_prov;
6236 char *pos;
6237
6238 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
6239
6240 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
6241
6242 if (hwaddr_aton(cmd, addr))
6243 return -1;
6244
6245 pos = cmd + 17;
6246 if (*pos != ' ')
6247 return -1;
6248
6249 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
6250 if (!p2ps_prov)
6251 return -1;
6252
6253 if (p2ps_prov->status < 0) {
6254 os_free(p2ps_prov);
6255 return -1;
6256 }
6257
6258 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
6259 p2ps_prov);
6260 }
6261
6262
p2p_ctrl_asp_provision(struct wpa_supplicant * wpa_s,char * cmd)6263 static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
6264 {
6265 u8 addr[ETH_ALEN];
6266 struct p2ps_provision *p2ps_prov;
6267 char *pos;
6268
6269 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
6270 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
6271 */
6272
6273 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
6274 if (hwaddr_aton(cmd, addr))
6275 return -1;
6276
6277 pos = cmd + 17;
6278 if (*pos != ' ')
6279 return -1;
6280
6281 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
6282 if (!p2ps_prov)
6283 return -1;
6284
6285 p2ps_prov->pd_seeker = 1;
6286
6287 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
6288 p2ps_prov);
6289 }
6290
6291
parse_freq(int chwidth,int freq2)6292 static int parse_freq(int chwidth, int freq2)
6293 {
6294 if (freq2 < 0)
6295 return -1;
6296 if (freq2)
6297 return CONF_OPER_CHWIDTH_80P80MHZ;
6298
6299 switch (chwidth) {
6300 case 0:
6301 case 20:
6302 case 40:
6303 return CONF_OPER_CHWIDTH_USE_HT;
6304 case 80:
6305 return CONF_OPER_CHWIDTH_80MHZ;
6306 case 160:
6307 return CONF_OPER_CHWIDTH_160MHZ;
6308 case 320:
6309 return CONF_OPER_CHWIDTH_320MHZ;
6310 default:
6311 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
6312 chwidth);
6313 return -1;
6314 }
6315 }
6316
6317
p2p_ctrl_connect(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)6318 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
6319 char *buf, size_t buflen)
6320 {
6321 u8 addr[ETH_ALEN];
6322 char *pos, *pos2;
6323 char *pin = NULL;
6324 enum p2p_wps_method wps_method;
6325 int new_pin;
6326 int ret;
6327 int persistent_group, persistent_id = -1;
6328 int join;
6329 int auth;
6330 int automatic;
6331 int go_intent = -1;
6332 int freq = 0;
6333 int pd;
6334 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
6335 int edmg;
6336 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
6337 size_t group_ssid_len = 0;
6338 int he;
6339 bool allow_6ghz;
6340
6341 if (!wpa_s->global->p2p_init_wpa_s)
6342 return -1;
6343 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
6344 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
6345 wpa_s->global->p2p_init_wpa_s->ifname);
6346 wpa_s = wpa_s->global->p2p_init_wpa_s;
6347 }
6348
6349 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
6350 * [persistent|persistent=<network id>]
6351 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
6352 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
6353
6354 if (hwaddr_aton(cmd, addr))
6355 return -1;
6356
6357 pos = cmd + 17;
6358 if (*pos != ' ')
6359 return -1;
6360 pos++;
6361
6362 persistent_group = os_strstr(pos, " persistent") != NULL;
6363 pos2 = os_strstr(pos, " persistent=");
6364 if (pos2) {
6365 struct wpa_ssid *ssid;
6366 persistent_id = atoi(pos2 + 12);
6367 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
6368 if (ssid == NULL || ssid->disabled != 2 ||
6369 ssid->mode != WPAS_MODE_P2P_GO) {
6370 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
6371 "SSID id=%d for persistent P2P group (GO)",
6372 persistent_id);
6373 return -1;
6374 }
6375 }
6376 join = os_strstr(pos, " join") != NULL;
6377 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
6378 auth = os_strstr(pos, " auth") != NULL;
6379 automatic = os_strstr(pos, " auto") != NULL;
6380 pd = os_strstr(pos, " provdisc") != NULL;
6381 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6382 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6383 vht;
6384 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
6385 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
6386
6387 pos2 = os_strstr(pos, " go_intent=");
6388 if (pos2) {
6389 pos2 += 11;
6390 go_intent = atoi(pos2);
6391 if (go_intent < 0 || go_intent > 15)
6392 return -1;
6393 }
6394
6395 pos2 = os_strstr(pos, " freq=");
6396 if (pos2) {
6397 pos2 += 6;
6398 freq = atoi(pos2);
6399 if (freq <= 0)
6400 return -1;
6401 }
6402
6403 pos2 = os_strstr(pos, " freq2=");
6404 if (pos2)
6405 freq2 = atoi(pos2 + 7);
6406
6407 pos2 = os_strstr(pos, " max_oper_chwidth=");
6408 if (pos2)
6409 chwidth = atoi(pos2 + 18);
6410
6411 max_oper_chwidth = parse_freq(chwidth, freq2);
6412 if (max_oper_chwidth < 0)
6413 return -1;
6414
6415 if (allow_6ghz && chwidth == 40)
6416 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
6417
6418 pos2 = os_strstr(pos, " ssid=");
6419 if (pos2) {
6420 char *end;
6421
6422 pos2 += 6;
6423 end = os_strchr(pos2, ' ');
6424 if (!end)
6425 group_ssid_len = os_strlen(pos2) / 2;
6426 else
6427 group_ssid_len = (end - pos2) / 2;
6428 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
6429 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
6430 return -1;
6431 group_ssid = _group_ssid;
6432 }
6433
6434 if (os_strncmp(pos, "pin", 3) == 0) {
6435 /* Request random PIN (to be displayed) and enable the PIN */
6436 wps_method = WPS_PIN_DISPLAY;
6437 } else if (os_strncmp(pos, "pbc", 3) == 0) {
6438 wps_method = WPS_PBC;
6439 } else if (os_strstr(pos, "p2ps") != NULL) {
6440 wps_method = WPS_P2PS;
6441 } else {
6442 pin = pos;
6443 pos = os_strchr(pin, ' ');
6444 wps_method = WPS_PIN_KEYPAD;
6445 if (pos) {
6446 *pos++ = '\0';
6447 if (os_strncmp(pos, "display", 7) == 0)
6448 wps_method = WPS_PIN_DISPLAY;
6449 }
6450 if (!wps_pin_str_valid(pin)) {
6451 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
6452 return 17;
6453 }
6454 }
6455
6456 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
6457 persistent_group, automatic, join,
6458 auth, go_intent, freq, freq2, persistent_id,
6459 pd, ht40, vht, max_oper_chwidth, he, edmg,
6460 group_ssid, group_ssid_len, allow_6ghz);
6461 if (new_pin == -2) {
6462 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
6463 return 25;
6464 }
6465 if (new_pin == -3) {
6466 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
6467 return 25;
6468 }
6469 if (new_pin < 0)
6470 return -1;
6471 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
6472 ret = os_snprintf(buf, buflen, "%08d", new_pin);
6473 if (os_snprintf_error(buflen, ret))
6474 return -1;
6475 return ret;
6476 }
6477
6478 os_memcpy(buf, "OK\n", 3);
6479 return 3;
6480 }
6481
6482
p2p_ctrl_listen(struct wpa_supplicant * wpa_s,char * cmd)6483 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
6484 {
6485 unsigned int timeout = atoi(cmd);
6486 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6487 wpa_dbg(wpa_s, MSG_INFO,
6488 "Reject P2P_LISTEN since interface is disabled");
6489 return -1;
6490 }
6491 return wpas_p2p_listen(wpa_s, timeout);
6492 }
6493
6494
p2p_ctrl_prov_disc(struct wpa_supplicant * wpa_s,char * cmd)6495 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
6496 {
6497 u8 addr[ETH_ALEN];
6498 char *pos;
6499 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
6500
6501 /* <addr> <config method> [join|auto] */
6502
6503 if (hwaddr_aton(cmd, addr))
6504 return -1;
6505
6506 pos = cmd + 17;
6507 if (*pos != ' ')
6508 return -1;
6509 pos++;
6510
6511 if (os_strstr(pos, " join") != NULL)
6512 use = WPAS_P2P_PD_FOR_JOIN;
6513 else if (os_strstr(pos, " auto") != NULL)
6514 use = WPAS_P2P_PD_AUTO;
6515
6516 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
6517 }
6518
6519
p2p_get_passphrase(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)6520 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
6521 size_t buflen)
6522 {
6523 struct wpa_ssid *ssid = wpa_s->current_ssid;
6524
6525 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
6526 ssid->passphrase == NULL)
6527 return -1;
6528
6529 os_strlcpy(buf, ssid->passphrase, buflen);
6530 return os_strlen(buf);
6531 }
6532
6533
p2p_ctrl_serv_disc_req(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)6534 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
6535 char *buf, size_t buflen)
6536 {
6537 u64 ref;
6538 int res;
6539 u8 dst_buf[ETH_ALEN], *dst;
6540 struct wpabuf *tlvs;
6541 char *pos;
6542 size_t len;
6543
6544 if (hwaddr_aton(cmd, dst_buf))
6545 return -1;
6546 dst = dst_buf;
6547 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
6548 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
6549 dst = NULL;
6550 pos = cmd + 17;
6551 if (*pos != ' ')
6552 return -1;
6553 pos++;
6554
6555 if (os_strncmp(pos, "upnp ", 5) == 0) {
6556 u8 version;
6557 pos += 5;
6558 if (hexstr2bin(pos, &version, 1) < 0)
6559 return -1;
6560 pos += 2;
6561 if (*pos != ' ')
6562 return -1;
6563 pos++;
6564 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
6565 #ifdef CONFIG_WIFI_DISPLAY
6566 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
6567 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
6568 #endif /* CONFIG_WIFI_DISPLAY */
6569 } else if (os_strncmp(pos, "asp ", 4) == 0) {
6570 char *svc_str;
6571 char *svc_info = NULL;
6572 u32 id;
6573
6574 pos += 4;
6575 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
6576 return -1;
6577
6578 pos = os_strchr(pos, ' ');
6579 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
6580 return -1;
6581
6582 svc_str = pos + 1;
6583
6584 pos = os_strchr(svc_str, ' ');
6585
6586 if (pos)
6587 *pos++ = '\0';
6588
6589 /* All remaining data is the svc_info string */
6590 if (pos && pos[0] && pos[0] != ' ') {
6591 len = os_strlen(pos);
6592
6593 /* Unescape in place */
6594 len = utf8_unescape(pos, len, pos, len);
6595 if (len > 0xff)
6596 return -1;
6597
6598 svc_info = pos;
6599 }
6600
6601 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
6602 svc_str, svc_info);
6603 } else {
6604 len = os_strlen(pos);
6605 if (len & 1)
6606 return -1;
6607 len /= 2;
6608 tlvs = wpabuf_alloc(len);
6609 if (tlvs == NULL)
6610 return -1;
6611 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
6612 wpabuf_free(tlvs);
6613 return -1;
6614 }
6615
6616 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
6617 wpabuf_free(tlvs);
6618 }
6619 if (ref == 0)
6620 return -1;
6621 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
6622 if (os_snprintf_error(buflen, res))
6623 return -1;
6624 return res;
6625 }
6626
6627
p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant * wpa_s,char * cmd)6628 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
6629 char *cmd)
6630 {
6631 long long unsigned val;
6632 u64 req;
6633 if (sscanf(cmd, "%llx", &val) != 1)
6634 return -1;
6635 req = val;
6636 return wpas_p2p_sd_cancel_request(wpa_s, req);
6637 }
6638
6639
p2p_ctrl_serv_disc_resp(struct wpa_supplicant * wpa_s,char * cmd)6640 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
6641 {
6642 int freq;
6643 u8 dst[ETH_ALEN];
6644 u8 dialog_token;
6645 struct wpabuf *resp_tlvs;
6646 char *pos, *pos2;
6647 size_t len;
6648
6649 pos = os_strchr(cmd, ' ');
6650 if (pos == NULL)
6651 return -1;
6652 *pos++ = '\0';
6653 freq = atoi(cmd);
6654 if (freq == 0)
6655 return -1;
6656
6657 if (hwaddr_aton(pos, dst))
6658 return -1;
6659 pos += 17;
6660 if (*pos != ' ')
6661 return -1;
6662 pos++;
6663
6664 pos2 = os_strchr(pos, ' ');
6665 if (pos2 == NULL)
6666 return -1;
6667 *pos2++ = '\0';
6668 dialog_token = atoi(pos);
6669
6670 len = os_strlen(pos2);
6671 if (len & 1)
6672 return -1;
6673 len /= 2;
6674 resp_tlvs = wpabuf_alloc(len);
6675 if (resp_tlvs == NULL)
6676 return -1;
6677 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
6678 wpabuf_free(resp_tlvs);
6679 return -1;
6680 }
6681
6682 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
6683 wpabuf_free(resp_tlvs);
6684 return 0;
6685 }
6686
6687
p2p_ctrl_serv_disc_external(struct wpa_supplicant * wpa_s,char * cmd)6688 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
6689 char *cmd)
6690 {
6691 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
6692 return -1;
6693 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
6694 return 0;
6695 }
6696
6697
p2p_ctrl_service_add_bonjour(struct wpa_supplicant * wpa_s,char * cmd)6698 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
6699 char *cmd)
6700 {
6701 char *pos;
6702 size_t len;
6703 struct wpabuf *query, *resp;
6704
6705 pos = os_strchr(cmd, ' ');
6706 if (pos == NULL)
6707 return -1;
6708 *pos++ = '\0';
6709
6710 len = os_strlen(cmd);
6711 if (len & 1)
6712 return -1;
6713 len /= 2;
6714 query = wpabuf_alloc(len);
6715 if (query == NULL)
6716 return -1;
6717 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6718 wpabuf_free(query);
6719 return -1;
6720 }
6721
6722 len = os_strlen(pos);
6723 if (len & 1) {
6724 wpabuf_free(query);
6725 return -1;
6726 }
6727 len /= 2;
6728 resp = wpabuf_alloc(len);
6729 if (resp == NULL) {
6730 wpabuf_free(query);
6731 return -1;
6732 }
6733 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
6734 wpabuf_free(query);
6735 wpabuf_free(resp);
6736 return -1;
6737 }
6738
6739 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
6740 wpabuf_free(query);
6741 wpabuf_free(resp);
6742 return -1;
6743 }
6744 return 0;
6745 }
6746
6747
p2p_ctrl_service_add_upnp(struct wpa_supplicant * wpa_s,char * cmd)6748 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6749 {
6750 char *pos;
6751 u8 version;
6752
6753 pos = os_strchr(cmd, ' ');
6754 if (pos == NULL)
6755 return -1;
6756 *pos++ = '\0';
6757
6758 if (hexstr2bin(cmd, &version, 1) < 0)
6759 return -1;
6760
6761 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
6762 }
6763
6764
p2p_ctrl_service_add_asp(struct wpa_supplicant * wpa_s,u8 replace,char * cmd)6765 static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
6766 u8 replace, char *cmd)
6767 {
6768 char *pos;
6769 char *adv_str;
6770 u32 auto_accept, adv_id, svc_state, config_methods;
6771 char *svc_info = NULL;
6772 char *cpt_prio_str;
6773 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
6774
6775 pos = os_strchr(cmd, ' ');
6776 if (pos == NULL)
6777 return -1;
6778 *pos++ = '\0';
6779
6780 /* Auto-Accept value is mandatory, and must be one of the
6781 * single values (0, 1, 2, 4) */
6782 auto_accept = atoi(cmd);
6783 switch (auto_accept) {
6784 case P2PS_SETUP_NONE: /* No auto-accept */
6785 case P2PS_SETUP_NEW:
6786 case P2PS_SETUP_CLIENT:
6787 case P2PS_SETUP_GROUP_OWNER:
6788 break;
6789 default:
6790 return -1;
6791 }
6792
6793 /* Advertisement ID is mandatory */
6794 cmd = pos;
6795 pos = os_strchr(cmd, ' ');
6796 if (pos == NULL)
6797 return -1;
6798 *pos++ = '\0';
6799
6800 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6801 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
6802 return -1;
6803
6804 /* Only allow replacements if exist, and adds if not */
6805 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
6806 if (!replace)
6807 return -1;
6808 } else {
6809 if (replace)
6810 return -1;
6811 }
6812
6813 /* svc_state between 0 - 0xff is mandatory */
6814 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
6815 return -1;
6816
6817 pos = os_strchr(pos, ' ');
6818 if (pos == NULL)
6819 return -1;
6820
6821 /* config_methods is mandatory */
6822 pos++;
6823 if (sscanf(pos, "%x", &config_methods) != 1)
6824 return -1;
6825
6826 if (!(config_methods &
6827 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
6828 return -1;
6829
6830 pos = os_strchr(pos, ' ');
6831 if (pos == NULL)
6832 return -1;
6833
6834 pos++;
6835 adv_str = pos;
6836
6837 /* Advertisement string is mandatory */
6838 if (!pos[0] || pos[0] == ' ')
6839 return -1;
6840
6841 /* Terminate svc string */
6842 pos = os_strchr(pos, ' ');
6843 if (pos != NULL)
6844 *pos++ = '\0';
6845
6846 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6847 if (cpt_prio_str) {
6848 pos = os_strchr(pos, ' ');
6849 if (pos != NULL)
6850 *pos++ = '\0';
6851
6852 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6853 return -1;
6854 } else {
6855 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6856 cpt_prio[1] = 0;
6857 }
6858
6859 /* Service and Response Information are optional */
6860 if (pos && pos[0]) {
6861 size_t len;
6862
6863 /* Note the bare ' included, which cannot exist legally
6864 * in unescaped string. */
6865 svc_info = os_strstr(pos, "svc_info='");
6866
6867 if (svc_info) {
6868 svc_info += 9;
6869 len = os_strlen(svc_info);
6870 utf8_unescape(svc_info, len, svc_info, len);
6871 }
6872 }
6873
6874 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6875 (u8) svc_state, (u16) config_methods,
6876 svc_info, cpt_prio);
6877 }
6878
6879
p2p_ctrl_service_add(struct wpa_supplicant * wpa_s,char * cmd)6880 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6881 {
6882 char *pos;
6883
6884 pos = os_strchr(cmd, ' ');
6885 if (pos == NULL)
6886 return -1;
6887 *pos++ = '\0';
6888
6889 if (os_strcmp(cmd, "bonjour") == 0)
6890 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6891 if (os_strcmp(cmd, "upnp") == 0)
6892 return p2p_ctrl_service_add_upnp(wpa_s, pos);
6893 if (os_strcmp(cmd, "asp") == 0)
6894 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
6895 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6896 return -1;
6897 }
6898
6899
p2p_ctrl_service_del_bonjour(struct wpa_supplicant * wpa_s,char * cmd)6900 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6901 char *cmd)
6902 {
6903 size_t len;
6904 struct wpabuf *query;
6905 int ret;
6906
6907 len = os_strlen(cmd);
6908 if (len & 1)
6909 return -1;
6910 len /= 2;
6911 query = wpabuf_alloc(len);
6912 if (query == NULL)
6913 return -1;
6914 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6915 wpabuf_free(query);
6916 return -1;
6917 }
6918
6919 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6920 wpabuf_free(query);
6921 return ret;
6922 }
6923
6924
p2p_ctrl_service_del_upnp(struct wpa_supplicant * wpa_s,char * cmd)6925 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6926 {
6927 char *pos;
6928 u8 version;
6929
6930 pos = os_strchr(cmd, ' ');
6931 if (pos == NULL)
6932 return -1;
6933 *pos++ = '\0';
6934
6935 if (hexstr2bin(cmd, &version, 1) < 0)
6936 return -1;
6937
6938 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6939 }
6940
6941
p2p_ctrl_service_del_asp(struct wpa_supplicant * wpa_s,char * cmd)6942 static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6943 {
6944 u32 adv_id;
6945
6946 if (os_strcmp(cmd, "all") == 0) {
6947 wpas_p2p_service_flush_asp(wpa_s);
6948 return 0;
6949 }
6950
6951 if (sscanf(cmd, "%x", &adv_id) != 1)
6952 return -1;
6953
6954 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6955 }
6956
6957
p2p_ctrl_service_del(struct wpa_supplicant * wpa_s,char * cmd)6958 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6959 {
6960 char *pos;
6961
6962 pos = os_strchr(cmd, ' ');
6963 if (pos == NULL)
6964 return -1;
6965 *pos++ = '\0';
6966
6967 if (os_strcmp(cmd, "bonjour") == 0)
6968 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6969 if (os_strcmp(cmd, "upnp") == 0)
6970 return p2p_ctrl_service_del_upnp(wpa_s, pos);
6971 if (os_strcmp(cmd, "asp") == 0)
6972 return p2p_ctrl_service_del_asp(wpa_s, pos);
6973 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6974 return -1;
6975 }
6976
6977
p2p_ctrl_service_replace(struct wpa_supplicant * wpa_s,char * cmd)6978 static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6979 {
6980 char *pos;
6981
6982 pos = os_strchr(cmd, ' ');
6983 if (pos == NULL)
6984 return -1;
6985 *pos++ = '\0';
6986
6987 if (os_strcmp(cmd, "asp") == 0)
6988 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6989
6990 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6991 return -1;
6992 }
6993
6994
p2p_ctrl_reject(struct wpa_supplicant * wpa_s,char * cmd)6995 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
6996 {
6997 u8 addr[ETH_ALEN];
6998
6999 /* <addr> */
7000
7001 if (hwaddr_aton(cmd, addr))
7002 return -1;
7003
7004 return wpas_p2p_reject(wpa_s, addr);
7005 }
7006
7007
p2p_ctrl_invite_persistent(struct wpa_supplicant * wpa_s,char * cmd)7008 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
7009 {
7010 char *pos;
7011 int id;
7012 struct wpa_ssid *ssid;
7013 u8 *_peer = NULL, peer[ETH_ALEN];
7014 int freq = 0, pref_freq = 0;
7015 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
7016 int edmg;
7017 bool allow_6ghz;
7018
7019 id = atoi(cmd);
7020 pos = os_strstr(cmd, " peer=");
7021 if (pos) {
7022 pos += 6;
7023 if (hwaddr_aton(pos, peer))
7024 return -1;
7025 _peer = peer;
7026 }
7027 ssid = wpa_config_get_network(wpa_s->conf, id);
7028 if (ssid == NULL || ssid->disabled != 2) {
7029 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
7030 "for persistent P2P group",
7031 id);
7032 return -1;
7033 }
7034
7035 pos = os_strstr(cmd, " freq=");
7036 if (pos) {
7037 pos += 6;
7038 freq = atoi(pos);
7039 if (freq <= 0)
7040 return -1;
7041 }
7042
7043 pos = os_strstr(cmd, " pref=");
7044 if (pos) {
7045 pos += 6;
7046 pref_freq = atoi(pos);
7047 if (pref_freq <= 0)
7048 return -1;
7049 }
7050
7051 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
7052 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
7053 vht;
7054 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
7055 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
7056
7057 pos = os_strstr(cmd, "freq2=");
7058 if (pos)
7059 freq2 = atoi(pos + 6);
7060
7061 pos = os_strstr(cmd, " max_oper_chwidth=");
7062 if (pos)
7063 chwidth = atoi(pos + 18);
7064
7065 max_oper_chwidth = parse_freq(chwidth, freq2);
7066 if (max_oper_chwidth < 0)
7067 return -1;
7068
7069 allow_6ghz = os_strstr(cmd, " allow_6ghz") != NULL;
7070
7071 if (allow_6ghz && chwidth == 40)
7072 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
7073
7074 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
7075 max_oper_chwidth, pref_freq, he, edmg,
7076 allow_6ghz);
7077 }
7078
7079
p2p_ctrl_invite_group(struct wpa_supplicant * wpa_s,char * cmd)7080 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
7081 {
7082 char *pos;
7083 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
7084 bool allow_6ghz;
7085
7086 pos = os_strstr(cmd, " peer=");
7087 if (!pos)
7088 return -1;
7089
7090 *pos = '\0';
7091 pos += 6;
7092 if (hwaddr_aton(pos, peer)) {
7093 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
7094 return -1;
7095 }
7096
7097 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
7098
7099 pos = os_strstr(pos, " go_dev_addr=");
7100 if (pos) {
7101 pos += 13;
7102 if (hwaddr_aton(pos, go_dev_addr)) {
7103 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
7104 pos);
7105 return -1;
7106 }
7107 go_dev = go_dev_addr;
7108 }
7109
7110 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev, allow_6ghz);
7111 }
7112
7113
p2p_ctrl_invite(struct wpa_supplicant * wpa_s,char * cmd)7114 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
7115 {
7116 if (os_strncmp(cmd, "persistent=", 11) == 0)
7117 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
7118 if (os_strncmp(cmd, "group=", 6) == 0)
7119 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
7120
7121 return -1;
7122 }
7123
7124
p2p_ctrl_group_add_persistent(struct wpa_supplicant * wpa_s,int id,int freq,int vht_center_freq2,int ht40,int vht,int vht_chwidth,int he,int edmg,bool allow_6ghz,const u8 * go_bssid)7125 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
7126 int id, int freq, int vht_center_freq2,
7127 int ht40, int vht, int vht_chwidth,
7128 int he, int edmg, bool allow_6ghz,
7129 const u8 *go_bssid)
7130 {
7131 struct wpa_ssid *ssid;
7132
7133 ssid = wpa_config_get_network(wpa_s->conf, id);
7134 if (ssid == NULL || ssid->disabled != 2) {
7135 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
7136 "for persistent P2P group",
7137 id);
7138 return -1;
7139 }
7140
7141 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
7142 vht_center_freq2, 0, ht40, vht,
7143 vht_chwidth, he, edmg,
7144 NULL, 0, 0, allow_6ghz, 0,
7145 go_bssid);
7146 }
7147
7148
p2p_ctrl_group_add(struct wpa_supplicant * wpa_s,char * cmd)7149 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
7150 {
7151 int freq = 0, persistent = 0, group_id = -1;
7152 bool allow_6ghz = false;
7153 int vht = wpa_s->conf->p2p_go_vht;
7154 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
7155 int he = wpa_s->conf->p2p_go_he;
7156 int edmg = wpa_s->conf->p2p_go_edmg;
7157 int max_oper_chwidth, chwidth = 0, freq2 = 0;
7158 char *token, *context = NULL;
7159 u8 go_bssid_buf[ETH_ALEN], *go_bssid = NULL;
7160 #ifdef CONFIG_ACS
7161 int acs = 0;
7162 #endif /* CONFIG_ACS */
7163
7164 while ((token = str_token(cmd, " ", &context))) {
7165 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
7166 sscanf(token, "persistent=%d", &group_id) == 1 ||
7167 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
7168 continue;
7169 #ifdef CONFIG_ACS
7170 } else if (os_strcmp(token, "freq=acs") == 0) {
7171 acs = 1;
7172 #endif /* CONFIG_ACS */
7173 } else if (sscanf(token, "freq=%d", &freq) == 1) {
7174 continue;
7175 } else if (os_strcmp(token, "ht40") == 0) {
7176 ht40 = 1;
7177 } else if (os_strcmp(token, "vht") == 0) {
7178 vht = 1;
7179 ht40 = 1;
7180 } else if (os_strcmp(token, "he") == 0) {
7181 he = 1;
7182 } else if (os_strcmp(token, "edmg") == 0) {
7183 edmg = 1;
7184 } else if (os_strcmp(token, "persistent") == 0) {
7185 persistent = 1;
7186 } else if (os_strcmp(token, "allow_6ghz") == 0) {
7187 allow_6ghz = true;
7188 } else if (os_strncmp(token, "go_bssid=", 9) == 0) {
7189 if (hwaddr_aton(token + 9, go_bssid_buf))
7190 return -1;
7191 go_bssid = go_bssid_buf;
7192 } else {
7193 wpa_printf(MSG_DEBUG,
7194 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
7195 token);
7196 return -1;
7197 }
7198 }
7199
7200 #ifdef CONFIG_ACS
7201 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
7202 (acs || freq == 2 || freq == 5)) {
7203 if (freq == 2 && wpa_s->best_24_freq <= 0) {
7204 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
7205 wpa_s->p2p_go_do_acs = 1;
7206 freq = 0;
7207 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
7208 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
7209 wpa_s->p2p_go_do_acs = 1;
7210 freq = 0;
7211 } else {
7212 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
7213 wpa_s->p2p_go_do_acs = 1;
7214 }
7215 } else {
7216 wpa_s->p2p_go_do_acs = 0;
7217 }
7218 #endif /* CONFIG_ACS */
7219
7220 max_oper_chwidth = parse_freq(chwidth, freq2);
7221 if (max_oper_chwidth < 0)
7222 return -1;
7223
7224 if (allow_6ghz && chwidth == 40)
7225 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
7226
7227 /* Allow DFS to be used for Autonomous GO */
7228 wpa_s->p2p_go_allow_dfs = !!(wpa_s->drv_flags &
7229 WPA_DRIVER_FLAGS_DFS_OFFLOAD);
7230
7231 if (group_id >= 0)
7232 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
7233 freq, freq2, ht40, vht,
7234 max_oper_chwidth, he,
7235 edmg, allow_6ghz,
7236 go_bssid);
7237
7238 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
7239 max_oper_chwidth, he, edmg, allow_6ghz);
7240 }
7241
7242
p2p_ctrl_group_member(struct wpa_supplicant * wpa_s,const char * cmd,char * buf,size_t buflen)7243 static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
7244 char *buf, size_t buflen)
7245 {
7246 u8 dev_addr[ETH_ALEN];
7247 struct wpa_ssid *ssid;
7248 int res;
7249 const u8 *iaddr;
7250
7251 ssid = wpa_s->current_ssid;
7252 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
7253 hwaddr_aton(cmd, dev_addr))
7254 return -1;
7255
7256 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
7257 if (!iaddr)
7258 return -1;
7259 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
7260 if (os_snprintf_error(buflen, res))
7261 return -1;
7262 return res;
7263 }
7264
7265
wpas_find_p2p_dev_addr_bss(struct wpa_global * global,const u8 * p2p_dev_addr)7266 static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
7267 const u8 *p2p_dev_addr)
7268 {
7269 struct wpa_supplicant *wpa_s;
7270
7271 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7272 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
7273 return 1;
7274 }
7275
7276 return 0;
7277 }
7278
7279
p2p_ctrl_peer(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)7280 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
7281 char *buf, size_t buflen)
7282 {
7283 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
7284 int next, res;
7285 const struct p2p_peer_info *info;
7286 char *pos, *end;
7287 char devtype[WPS_DEV_TYPE_BUFSIZE];
7288 struct wpa_ssid *ssid;
7289 size_t i;
7290
7291 if (!wpa_s->global->p2p)
7292 return -1;
7293
7294 if (os_strcmp(cmd, "FIRST") == 0) {
7295 addr_ptr = NULL;
7296 next = 0;
7297 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
7298 if (hwaddr_aton(cmd + 5, addr) < 0)
7299 return -1;
7300 addr_ptr = addr;
7301 next = 1;
7302 } else {
7303 if (hwaddr_aton(cmd, addr) < 0)
7304 return -1;
7305 addr_ptr = addr;
7306 next = 0;
7307 }
7308
7309 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
7310 if (info == NULL)
7311 return -1;
7312 group_capab = info->group_capab;
7313
7314 if (group_capab &&
7315 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
7316 wpa_printf(MSG_DEBUG,
7317 "P2P: Could not find any BSS with p2p_dev_addr "
7318 MACSTR ", hence override group_capab from 0x%x to 0",
7319 MAC2STR(info->p2p_device_addr), group_capab);
7320 group_capab = 0;
7321 }
7322
7323 pos = buf;
7324 end = buf + buflen;
7325
7326 res = os_snprintf(pos, end - pos, MACSTR "\n"
7327 "pri_dev_type=%s\n"
7328 "device_name=%s\n"
7329 "manufacturer=%s\n"
7330 "model_name=%s\n"
7331 "model_number=%s\n"
7332 "serial_number=%s\n"
7333 "config_methods=0x%x\n"
7334 "dev_capab=0x%x\n"
7335 "group_capab=0x%x\n"
7336 "level=%d\n",
7337 MAC2STR(info->p2p_device_addr),
7338 wps_dev_type_bin2str(info->pri_dev_type,
7339 devtype, sizeof(devtype)),
7340 info->device_name,
7341 info->manufacturer,
7342 info->model_name,
7343 info->model_number,
7344 info->serial_number,
7345 info->config_methods,
7346 info->dev_capab,
7347 group_capab,
7348 info->level);
7349 if (os_snprintf_error(end - pos, res))
7350 return pos - buf;
7351 pos += res;
7352
7353 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
7354 {
7355 const u8 *t;
7356 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
7357 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
7358 wps_dev_type_bin2str(t, devtype,
7359 sizeof(devtype)));
7360 if (os_snprintf_error(end - pos, res))
7361 return pos - buf;
7362 pos += res;
7363 }
7364
7365 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
7366 if (ssid) {
7367 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
7368 if (os_snprintf_error(end - pos, res))
7369 return pos - buf;
7370 pos += res;
7371 }
7372
7373 res = p2p_get_peer_info_txt(info, pos, end - pos);
7374 if (res < 0)
7375 return pos - buf;
7376 pos += res;
7377
7378 if (info->vendor_elems) {
7379 res = os_snprintf(pos, end - pos, "vendor_elems=");
7380 if (os_snprintf_error(end - pos, res))
7381 return pos - buf;
7382 pos += res;
7383
7384 pos += wpa_snprintf_hex(pos, end - pos,
7385 wpabuf_head(info->vendor_elems),
7386 wpabuf_len(info->vendor_elems));
7387
7388 res = os_snprintf(pos, end - pos, "\n");
7389 if (os_snprintf_error(end - pos, res))
7390 return pos - buf;
7391 pos += res;
7392 }
7393
7394 return pos - buf;
7395 }
7396
7397
p2p_ctrl_disallow_freq(struct wpa_supplicant * wpa_s,const char * param)7398 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
7399 const char *param)
7400 {
7401 unsigned int i;
7402
7403 if (wpa_s->global->p2p == NULL)
7404 return -1;
7405
7406 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
7407 return -1;
7408
7409 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
7410 struct wpa_freq_range *freq;
7411 freq = &wpa_s->global->p2p_disallow_freq.range[i];
7412 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
7413 freq->min, freq->max);
7414 }
7415
7416 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
7417 return 0;
7418 }
7419
7420
p2p_ctrl_set(struct wpa_supplicant * wpa_s,char * cmd)7421 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
7422 {
7423 char *param;
7424
7425 if (wpa_s->global->p2p == NULL)
7426 return -1;
7427
7428 param = os_strchr(cmd, ' ');
7429 if (param == NULL)
7430 return -1;
7431 *param++ = '\0';
7432
7433 if (os_strcmp(cmd, "discoverability") == 0) {
7434 p2p_set_client_discoverability(wpa_s->global->p2p,
7435 atoi(param));
7436 return 0;
7437 }
7438
7439 if (os_strcmp(cmd, "managed") == 0) {
7440 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
7441 return 0;
7442 }
7443
7444 if (os_strcmp(cmd, "listen_channel") == 0) {
7445 char *pos;
7446 u8 channel, op_class;
7447
7448 channel = atoi(param);
7449 pos = os_strchr(param, ' ');
7450 op_class = pos ? atoi(pos) : 81;
7451
7452 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
7453 channel, 1);
7454 }
7455
7456 if (os_strcmp(cmd, "ssid_postfix") == 0) {
7457 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
7458 os_strlen(param));
7459 }
7460
7461 if (os_strcmp(cmd, "noa") == 0) {
7462 char *pos;
7463 int count, start, duration;
7464 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
7465 count = atoi(param);
7466 pos = os_strchr(param, ',');
7467 if (pos == NULL)
7468 return -1;
7469 pos++;
7470 start = atoi(pos);
7471 pos = os_strchr(pos, ',');
7472 if (pos == NULL)
7473 return -1;
7474 pos++;
7475 duration = atoi(pos);
7476 if (count < 0 || count > 255 || start < 0 || duration < 0)
7477 return -1;
7478 if (count == 0 && duration > 0)
7479 return -1;
7480 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
7481 "start=%d duration=%d", count, start, duration);
7482 return wpas_p2p_set_noa(wpa_s, count, start, duration);
7483 }
7484
7485 if (os_strcmp(cmd, "ps") == 0)
7486 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
7487
7488 if (os_strcmp(cmd, "oppps") == 0)
7489 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
7490
7491 if (os_strcmp(cmd, "ctwindow") == 0)
7492 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
7493
7494 if (os_strcmp(cmd, "disabled") == 0) {
7495 wpa_s->global->p2p_disabled = atoi(param);
7496 wpa_printf(MSG_DEBUG, "P2P functionality %s",
7497 wpa_s->global->p2p_disabled ?
7498 "disabled" : "enabled");
7499 if (wpa_s->global->p2p_disabled) {
7500 wpas_p2p_stop_find(wpa_s);
7501 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7502 p2p_flush(wpa_s->global->p2p);
7503 }
7504 return 0;
7505 }
7506
7507 if (os_strcmp(cmd, "conc_pref") == 0) {
7508 if (os_strcmp(param, "sta") == 0)
7509 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
7510 else if (os_strcmp(param, "p2p") == 0)
7511 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
7512 else {
7513 wpa_printf(MSG_INFO, "Invalid conc_pref value");
7514 return -1;
7515 }
7516 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
7517 "%s", param);
7518 return 0;
7519 }
7520
7521 if (os_strcmp(cmd, "force_long_sd") == 0) {
7522 wpa_s->force_long_sd = atoi(param);
7523 return 0;
7524 }
7525
7526 if (os_strcmp(cmd, "peer_filter") == 0) {
7527 u8 addr[ETH_ALEN];
7528 if (hwaddr_aton(param, addr))
7529 return -1;
7530 p2p_set_peer_filter(wpa_s->global->p2p, addr);
7531 return 0;
7532 }
7533
7534 if (os_strcmp(cmd, "cross_connect") == 0)
7535 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
7536
7537 if (os_strcmp(cmd, "go_apsd") == 0) {
7538 if (os_strcmp(param, "disable") == 0)
7539 wpa_s->set_ap_uapsd = 0;
7540 else {
7541 wpa_s->set_ap_uapsd = 1;
7542 wpa_s->ap_uapsd = atoi(param);
7543 }
7544 return 0;
7545 }
7546
7547 if (os_strcmp(cmd, "client_apsd") == 0) {
7548 if (os_strcmp(param, "disable") == 0)
7549 wpa_s->set_sta_uapsd = 0;
7550 else {
7551 int be, bk, vi, vo;
7552 char *pos;
7553 /* format: BE,BK,VI,VO;max SP Length */
7554 be = atoi(param);
7555 pos = os_strchr(param, ',');
7556 if (pos == NULL)
7557 return -1;
7558 pos++;
7559 bk = atoi(pos);
7560 pos = os_strchr(pos, ',');
7561 if (pos == NULL)
7562 return -1;
7563 pos++;
7564 vi = atoi(pos);
7565 pos = os_strchr(pos, ',');
7566 if (pos == NULL)
7567 return -1;
7568 pos++;
7569 vo = atoi(pos);
7570 /* ignore max SP Length for now */
7571
7572 wpa_s->set_sta_uapsd = 1;
7573 wpa_s->sta_uapsd = 0;
7574 if (be)
7575 wpa_s->sta_uapsd |= BIT(0);
7576 if (bk)
7577 wpa_s->sta_uapsd |= BIT(1);
7578 if (vi)
7579 wpa_s->sta_uapsd |= BIT(2);
7580 if (vo)
7581 wpa_s->sta_uapsd |= BIT(3);
7582 }
7583 return 0;
7584 }
7585
7586 if (os_strcmp(cmd, "disallow_freq") == 0)
7587 return p2p_ctrl_disallow_freq(wpa_s, param);
7588
7589 if (os_strcmp(cmd, "disc_int") == 0) {
7590 int min_disc_int, max_disc_int, max_disc_tu;
7591 char *pos;
7592
7593 pos = param;
7594
7595 min_disc_int = atoi(pos);
7596 pos = os_strchr(pos, ' ');
7597 if (pos == NULL)
7598 return -1;
7599 *pos++ = '\0';
7600
7601 max_disc_int = atoi(pos);
7602 pos = os_strchr(pos, ' ');
7603 if (pos == NULL)
7604 return -1;
7605 *pos++ = '\0';
7606
7607 max_disc_tu = atoi(pos);
7608
7609 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
7610 max_disc_int, max_disc_tu);
7611 }
7612
7613 if (os_strcmp(cmd, "per_sta_psk") == 0) {
7614 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
7615 return 0;
7616 }
7617
7618 #ifdef CONFIG_WPS_NFC
7619 if (os_strcmp(cmd, "nfc_tag") == 0)
7620 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
7621 #endif /* CONFIG_WPS_NFC */
7622
7623 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
7624 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
7625 return 0;
7626 }
7627
7628 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
7629 int op_class, chan;
7630
7631 op_class = atoi(param);
7632 param = os_strchr(param, ':');
7633 if (!param)
7634 return -1;
7635 param++;
7636 chan = atoi(param);
7637 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
7638 chan);
7639 return 0;
7640 }
7641
7642 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
7643 cmd);
7644
7645 return -1;
7646 }
7647
7648
p2p_ctrl_flush(struct wpa_supplicant * wpa_s)7649 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
7650 {
7651 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7652 wpa_s->force_long_sd = 0;
7653
7654 #ifdef CONFIG_TESTING_OPTIONS
7655 os_free(wpa_s->get_pref_freq_list_override);
7656 wpa_s->get_pref_freq_list_override = NULL;
7657 #endif /* CONFIG_TESTING_OPTIONS */
7658
7659 wpas_p2p_stop_find(wpa_s);
7660 wpa_s->parent->p2ps_method_config_any = 0;
7661 if (wpa_s->global->p2p)
7662 p2p_flush(wpa_s->global->p2p);
7663 }
7664
7665
p2p_ctrl_presence_req(struct wpa_supplicant * wpa_s,char * cmd)7666 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
7667 {
7668 char *pos, *pos2;
7669 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
7670
7671 if (cmd[0]) {
7672 pos = os_strchr(cmd, ' ');
7673 if (pos == NULL)
7674 return -1;
7675 *pos++ = '\0';
7676 dur1 = atoi(cmd);
7677
7678 pos2 = os_strchr(pos, ' ');
7679 if (pos2)
7680 *pos2++ = '\0';
7681 int1 = atoi(pos);
7682 } else
7683 pos2 = NULL;
7684
7685 if (pos2) {
7686 pos = os_strchr(pos2, ' ');
7687 if (pos == NULL)
7688 return -1;
7689 *pos++ = '\0';
7690 dur2 = atoi(pos2);
7691 int2 = atoi(pos);
7692 }
7693
7694 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
7695 }
7696
7697
p2p_ctrl_ext_listen(struct wpa_supplicant * wpa_s,char * cmd)7698 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
7699 {
7700 char *pos;
7701 unsigned int period = 0, interval = 0;
7702
7703 if (cmd[0]) {
7704 pos = os_strchr(cmd, ' ');
7705 if (pos == NULL)
7706 return -1;
7707 *pos++ = '\0';
7708 period = atoi(cmd);
7709 interval = atoi(pos);
7710 }
7711
7712 return wpas_p2p_ext_listen(wpa_s, period, interval);
7713 }
7714
7715
p2p_ctrl_remove_client(struct wpa_supplicant * wpa_s,const char * cmd)7716 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
7717 {
7718 const char *pos;
7719 u8 peer[ETH_ALEN];
7720 int iface_addr = 0;
7721
7722 pos = cmd;
7723 if (os_strncmp(pos, "iface=", 6) == 0) {
7724 iface_addr = 1;
7725 pos += 6;
7726 }
7727 if (hwaddr_aton(pos, peer))
7728 return -1;
7729
7730 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
7731 return 0;
7732 }
7733
7734
p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant * wpa_s,char * cmd)7735 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
7736 {
7737 int freq = 0, period = 0, interval = 0, count = 0;
7738
7739 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
7740 {
7741 wpa_printf(MSG_DEBUG,
7742 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
7743 return -1;
7744 }
7745
7746 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
7747 }
7748
7749 #endif /* CONFIG_P2P */
7750
7751
freq_range_to_channel_list(struct wpa_supplicant * wpa_s,char * val)7752 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
7753 {
7754 struct wpa_freq_range_list ranges;
7755 int *freqs = NULL;
7756 struct hostapd_hw_modes *mode;
7757 u16 i;
7758
7759 if (wpa_s->hw.modes == NULL)
7760 return NULL;
7761
7762 os_memset(&ranges, 0, sizeof(ranges));
7763 if (freq_range_list_parse(&ranges, val) < 0)
7764 return NULL;
7765
7766 for (i = 0; i < wpa_s->hw.num_modes; i++) {
7767 int j;
7768
7769 mode = &wpa_s->hw.modes[i];
7770 for (j = 0; j < mode->num_channels; j++) {
7771 unsigned int freq;
7772
7773 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
7774 continue;
7775
7776 freq = mode->channels[j].freq;
7777 if (!freq_range_list_includes(&ranges, freq))
7778 continue;
7779
7780 int_array_add_unique(&freqs, freq);
7781 }
7782 }
7783
7784 os_free(ranges.range);
7785 return freqs;
7786 }
7787
7788
7789 #ifdef CONFIG_INTERWORKING
7790
ctrl_interworking_select(struct wpa_supplicant * wpa_s,char * param)7791 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
7792 {
7793 int auto_sel = 0;
7794 int *freqs = NULL;
7795
7796 if (param) {
7797 char *pos;
7798
7799 auto_sel = os_strstr(param, "auto") != NULL;
7800
7801 pos = os_strstr(param, "freq=");
7802 if (pos) {
7803 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
7804 if (freqs == NULL)
7805 return -1;
7806 }
7807
7808 }
7809
7810 return interworking_select(wpa_s, auto_sel, freqs);
7811 }
7812
7813
ctrl_interworking_connect(struct wpa_supplicant * wpa_s,char * dst,int only_add)7814 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
7815 int only_add)
7816 {
7817 u8 bssid[ETH_ALEN];
7818 struct wpa_bss *bss;
7819
7820 if (hwaddr_aton(dst, bssid)) {
7821 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
7822 return -1;
7823 }
7824
7825 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
7826 if (bss == NULL) {
7827 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
7828 MAC2STR(bssid));
7829 return -1;
7830 }
7831
7832 if (bss->ssid_len == 0) {
7833 int found = 0;
7834
7835 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
7836 " does not have SSID information", MAC2STR(bssid));
7837
7838 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
7839 list) {
7840 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
7841 bss->ssid_len > 0) {
7842 found = 1;
7843 break;
7844 }
7845 }
7846
7847 if (!found)
7848 return -1;
7849 wpa_printf(MSG_DEBUG,
7850 "Found another matching BSS entry with SSID");
7851 }
7852
7853 return interworking_connect(wpa_s, bss, only_add);
7854 }
7855
7856
get_anqp(struct wpa_supplicant * wpa_s,char * dst)7857 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
7858 {
7859 u8 dst_addr[ETH_ALEN];
7860 int used, freq = 0;
7861 char *pos;
7862 #define MAX_ANQP_INFO_ID 100
7863 u16 id[MAX_ANQP_INFO_ID];
7864 size_t num_id = 0;
7865 u32 subtypes = 0;
7866 u32 mbo_subtypes = 0;
7867
7868 used = hwaddr_aton2(dst, dst_addr);
7869 if (used < 0)
7870 return -1;
7871 pos = dst + used;
7872 if (*pos == ' ')
7873 pos++;
7874
7875 if (os_strncmp(pos, "freq=", 5) == 0) {
7876 freq = atoi(pos + 5);
7877 pos = os_strchr(pos, ' ');
7878 if (!pos)
7879 return -1;
7880 pos++;
7881 }
7882
7883 while (num_id < MAX_ANQP_INFO_ID) {
7884 if (os_strncmp(pos, "hs20:", 5) == 0) {
7885 #ifdef CONFIG_HS20
7886 int num = atoi(pos + 5);
7887 if (num <= 0 || num > 31)
7888 return -1;
7889 subtypes |= BIT(num);
7890 #else /* CONFIG_HS20 */
7891 return -1;
7892 #endif /* CONFIG_HS20 */
7893 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7894 #ifdef CONFIG_MBO
7895 int num = atoi(pos + 4);
7896
7897 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
7898 return -1;
7899 mbo_subtypes |= BIT(num);
7900 #else /* CONFIG_MBO */
7901 return -1;
7902 #endif /* CONFIG_MBO */
7903 } else {
7904 id[num_id] = atoi(pos);
7905 if (id[num_id])
7906 num_id++;
7907 }
7908 pos = os_strchr(pos + 1, ',');
7909 if (pos == NULL)
7910 break;
7911 pos++;
7912 }
7913
7914 if (num_id == 0 && !subtypes && !mbo_subtypes)
7915 return -1;
7916
7917 return anqp_send_req(wpa_s, dst_addr, freq, id, num_id, subtypes,
7918 mbo_subtypes);
7919 }
7920
7921
gas_request(struct wpa_supplicant * wpa_s,char * cmd)7922 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7923 {
7924 u8 dst_addr[ETH_ALEN];
7925 struct wpabuf *advproto, *query = NULL;
7926 int used, ret = -1;
7927 char *pos, *end;
7928 size_t len;
7929
7930 used = hwaddr_aton2(cmd, dst_addr);
7931 if (used < 0)
7932 return -1;
7933
7934 pos = cmd + used;
7935 while (*pos == ' ')
7936 pos++;
7937
7938 /* Advertisement Protocol ID */
7939 end = os_strchr(pos, ' ');
7940 if (end)
7941 len = end - pos;
7942 else
7943 len = os_strlen(pos);
7944 if (len & 0x01)
7945 return -1;
7946 len /= 2;
7947 if (len == 0)
7948 return -1;
7949 advproto = wpabuf_alloc(len);
7950 if (advproto == NULL)
7951 return -1;
7952 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7953 goto fail;
7954
7955 if (end) {
7956 /* Optional Query Request */
7957 pos = end + 1;
7958 while (*pos == ' ')
7959 pos++;
7960
7961 len = os_strlen(pos);
7962 if (len) {
7963 if (len & 0x01)
7964 goto fail;
7965 len /= 2;
7966 if (len == 0)
7967 goto fail;
7968 query = wpabuf_alloc(len);
7969 if (query == NULL)
7970 goto fail;
7971 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7972 goto fail;
7973 }
7974 }
7975
7976 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7977
7978 fail:
7979 wpabuf_free(advproto);
7980 wpabuf_free(query);
7981
7982 return ret;
7983 }
7984
7985
gas_response_get(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)7986 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7987 size_t buflen)
7988 {
7989 u8 addr[ETH_ALEN];
7990 int dialog_token;
7991 int used;
7992 char *pos;
7993 size_t resp_len, start, requested_len;
7994 struct wpabuf *resp;
7995 int ret;
7996
7997 used = hwaddr_aton2(cmd, addr);
7998 if (used < 0)
7999 return -1;
8000
8001 pos = cmd + used;
8002 while (*pos == ' ')
8003 pos++;
8004 dialog_token = atoi(pos);
8005
8006 if (wpa_s->last_gas_resp &&
8007 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
8008 dialog_token == wpa_s->last_gas_dialog_token)
8009 resp = wpa_s->last_gas_resp;
8010 else if (wpa_s->prev_gas_resp &&
8011 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
8012 dialog_token == wpa_s->prev_gas_dialog_token)
8013 resp = wpa_s->prev_gas_resp;
8014 else
8015 return -1;
8016
8017 resp_len = wpabuf_len(resp);
8018 start = 0;
8019 requested_len = resp_len;
8020
8021 pos = os_strchr(pos, ' ');
8022 if (pos) {
8023 start = atoi(pos);
8024 if (start > resp_len)
8025 return os_snprintf(buf, buflen, "FAIL-Invalid range");
8026 pos = os_strchr(pos, ',');
8027 if (pos == NULL)
8028 return -1;
8029 pos++;
8030 requested_len = atoi(pos);
8031 if (start + requested_len > resp_len)
8032 return os_snprintf(buf, buflen, "FAIL-Invalid range");
8033 }
8034
8035 if (requested_len * 2 + 1 > buflen)
8036 return os_snprintf(buf, buflen, "FAIL-Too long response");
8037
8038 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
8039 requested_len);
8040
8041 if (start + requested_len == resp_len) {
8042 /*
8043 * Free memory by dropping the response after it has been
8044 * fetched.
8045 */
8046 if (resp == wpa_s->prev_gas_resp) {
8047 wpabuf_free(wpa_s->prev_gas_resp);
8048 wpa_s->prev_gas_resp = NULL;
8049 } else {
8050 wpabuf_free(wpa_s->last_gas_resp);
8051 wpa_s->last_gas_resp = NULL;
8052 }
8053 }
8054
8055 return ret;
8056 }
8057 #endif /* CONFIG_INTERWORKING */
8058
8059
8060 #ifdef CONFIG_HS20
8061
get_hs20_anqp(struct wpa_supplicant * wpa_s,char * dst)8062 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
8063 {
8064 u8 dst_addr[ETH_ALEN];
8065 int used;
8066 char *pos;
8067 u32 subtypes = 0;
8068
8069 used = hwaddr_aton2(dst, dst_addr);
8070 if (used < 0)
8071 return -1;
8072 pos = dst + used;
8073 if (*pos == ' ')
8074 pos++;
8075 for (;;) {
8076 int num = atoi(pos);
8077 if (num <= 0 || num > 31)
8078 return -1;
8079 subtypes |= BIT(num);
8080 pos = os_strchr(pos + 1, ',');
8081 if (pos == NULL)
8082 break;
8083 pos++;
8084 }
8085
8086 if (subtypes == 0)
8087 return -1;
8088
8089 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
8090 }
8091
8092
hs20_nai_home_realm_list(struct wpa_supplicant * wpa_s,const u8 * addr,const char * realm)8093 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
8094 const u8 *addr, const char *realm)
8095 {
8096 u8 *buf;
8097 size_t rlen, len;
8098 int ret;
8099
8100 rlen = os_strlen(realm);
8101 len = 3 + rlen;
8102 buf = os_malloc(len);
8103 if (buf == NULL)
8104 return -1;
8105 buf[0] = 1; /* NAI Home Realm Count */
8106 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
8107 buf[2] = rlen;
8108 os_memcpy(buf + 3, realm, rlen);
8109
8110 ret = hs20_anqp_send_req(wpa_s, addr,
8111 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
8112 buf, len, 0);
8113
8114 os_free(buf);
8115
8116 return ret;
8117 }
8118
8119
hs20_get_nai_home_realm_list(struct wpa_supplicant * wpa_s,char * dst)8120 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
8121 char *dst)
8122 {
8123 struct wpa_cred *cred = wpa_s->conf->cred;
8124 u8 dst_addr[ETH_ALEN];
8125 int used;
8126 u8 *buf;
8127 size_t len;
8128 int ret;
8129
8130 used = hwaddr_aton2(dst, dst_addr);
8131 if (used < 0)
8132 return -1;
8133
8134 while (dst[used] == ' ')
8135 used++;
8136 if (os_strncmp(dst + used, "realm=", 6) == 0)
8137 return hs20_nai_home_realm_list(wpa_s, dst_addr,
8138 dst + used + 6);
8139
8140 len = os_strlen(dst + used);
8141
8142 if (len == 0 && cred && cred->realm)
8143 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
8144
8145 if (len & 1)
8146 return -1;
8147 len /= 2;
8148 buf = os_malloc(len);
8149 if (buf == NULL)
8150 return -1;
8151 if (hexstr2bin(dst + used, buf, len) < 0) {
8152 os_free(buf);
8153 return -1;
8154 }
8155
8156 ret = hs20_anqp_send_req(wpa_s, dst_addr,
8157 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
8158 buf, len, 0);
8159 os_free(buf);
8160
8161 return ret;
8162 }
8163
8164
get_hs20_icon(struct wpa_supplicant * wpa_s,char * cmd,char * reply,int buflen)8165 static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
8166 int buflen)
8167 {
8168 u8 dst_addr[ETH_ALEN];
8169 int used;
8170 char *ctx = NULL, *icon, *poffset, *psize;
8171
8172 used = hwaddr_aton2(cmd, dst_addr);
8173 if (used < 0)
8174 return -1;
8175 cmd += used;
8176
8177 icon = str_token(cmd, " ", &ctx);
8178 poffset = str_token(cmd, " ", &ctx);
8179 psize = str_token(cmd, " ", &ctx);
8180 if (!icon || !poffset || !psize)
8181 return -1;
8182
8183 wpa_s->fetch_osu_icon_in_progress = 0;
8184 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
8185 reply, buflen);
8186 }
8187
8188
del_hs20_icon(struct wpa_supplicant * wpa_s,char * cmd)8189 static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
8190 {
8191 u8 dst_addr[ETH_ALEN];
8192 int used;
8193 char *icon;
8194
8195 if (!cmd[0])
8196 return hs20_del_icon(wpa_s, NULL, NULL);
8197
8198 used = hwaddr_aton2(cmd, dst_addr);
8199 if (used < 0)
8200 return -1;
8201
8202 while (cmd[used] == ' ')
8203 used++;
8204 icon = cmd[used] ? &cmd[used] : NULL;
8205
8206 return hs20_del_icon(wpa_s, dst_addr, icon);
8207 }
8208
8209
hs20_icon_request(struct wpa_supplicant * wpa_s,char * cmd,int inmem)8210 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
8211 {
8212 u8 dst_addr[ETH_ALEN];
8213 int used;
8214 char *icon;
8215
8216 used = hwaddr_aton2(cmd, dst_addr);
8217 if (used < 0)
8218 return -1;
8219
8220 while (cmd[used] == ' ')
8221 used++;
8222 icon = &cmd[used];
8223
8224 wpa_s->fetch_osu_icon_in_progress = 0;
8225 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
8226 (u8 *) icon, os_strlen(icon), inmem);
8227 }
8228
8229 #endif /* CONFIG_HS20 */
8230
8231
8232 #ifdef CONFIG_AUTOSCAN
8233
wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant * wpa_s,char * cmd)8234 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
8235 char *cmd)
8236 {
8237 enum wpa_states state = wpa_s->wpa_state;
8238 char *new_params = NULL;
8239
8240 if (os_strlen(cmd) > 0) {
8241 new_params = os_strdup(cmd);
8242 if (new_params == NULL)
8243 return -1;
8244 }
8245
8246 os_free(wpa_s->conf->autoscan);
8247 wpa_s->conf->autoscan = new_params;
8248
8249 if (wpa_s->conf->autoscan == NULL)
8250 autoscan_deinit(wpa_s);
8251 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
8252 autoscan_init(wpa_s, 1);
8253 else if (state == WPA_SCANNING)
8254 wpa_supplicant_reinit_autoscan(wpa_s);
8255 else
8256 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
8257 wpa_supplicant_state_txt(state));
8258
8259 return 0;
8260 }
8261
8262 #endif /* CONFIG_AUTOSCAN */
8263
8264
8265 #ifdef CONFIG_WNM
8266
wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant * wpa_s,char * cmd)8267 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
8268 {
8269 int enter;
8270 int intval = 0;
8271 char *pos;
8272 int ret;
8273 struct wpabuf *tfs_req = NULL;
8274
8275 if (os_strncmp(cmd, "enter", 5) == 0)
8276 enter = 1;
8277 else if (os_strncmp(cmd, "exit", 4) == 0)
8278 enter = 0;
8279 else
8280 return -1;
8281
8282 pos = os_strstr(cmd, " interval=");
8283 if (pos)
8284 intval = atoi(pos + 10);
8285
8286 pos = os_strstr(cmd, " tfs_req=");
8287 if (pos) {
8288 char *end;
8289 size_t len;
8290 pos += 9;
8291 end = os_strchr(pos, ' ');
8292 if (end)
8293 len = end - pos;
8294 else
8295 len = os_strlen(pos);
8296 if (len & 1)
8297 return -1;
8298 len /= 2;
8299 tfs_req = wpabuf_alloc(len);
8300 if (tfs_req == NULL)
8301 return -1;
8302 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
8303 wpabuf_free(tfs_req);
8304 return -1;
8305 }
8306 }
8307
8308 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
8309 WNM_SLEEP_MODE_EXIT, intval,
8310 tfs_req);
8311 wpabuf_free(tfs_req);
8312
8313 return ret;
8314 }
8315
8316
wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant * wpa_s,char * cmd)8317 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
8318 {
8319 int query_reason, list = 0;
8320 char *btm_candidates = NULL;
8321
8322 query_reason = atoi(cmd);
8323
8324 cmd = os_strchr(cmd, ' ');
8325 if (cmd) {
8326 if (os_strncmp(cmd, " list", 5) == 0)
8327 list = 1;
8328 else
8329 btm_candidates = cmd;
8330 }
8331
8332 wpa_printf(MSG_DEBUG,
8333 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
8334 query_reason, list ? " candidate list" : "");
8335
8336 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
8337 btm_candidates,
8338 list);
8339 }
8340
8341
wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant * wpa_s,char * cmd)8342 static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
8343 char *cmd)
8344 {
8345 struct wpabuf *elems;
8346 int ret;
8347
8348 elems = wpabuf_parse_bin(cmd);
8349 if (!elems)
8350 return -1;
8351
8352 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
8353 wpabuf_free(elems);
8354 return ret;
8355 }
8356
8357 #endif /* CONFIG_WNM */
8358
8359
wpa_supplicant_signal_poll(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)8360 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
8361 size_t buflen)
8362 {
8363 struct wpa_signal_info si;
8364 int ret;
8365 char *pos, *end;
8366
8367 ret = wpa_drv_signal_poll(wpa_s, &si);
8368 if (ret)
8369 return -1;
8370
8371 pos = buf;
8372 end = buf + buflen;
8373
8374 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%lu\n"
8375 "NOISE=%d\nFREQUENCY=%u\n",
8376 si.data.signal, si.data.current_tx_rate / 1000,
8377 si.current_noise, si.frequency);
8378 if (os_snprintf_error(end - pos, ret))
8379 return -1;
8380 pos += ret;
8381
8382 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
8383 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
8384 channel_width_to_string(si.chanwidth));
8385 if (os_snprintf_error(end - pos, ret))
8386 return -1;
8387 pos += ret;
8388 }
8389
8390 if (si.center_frq1 > 0) {
8391 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
8392 si.center_frq1);
8393 if (os_snprintf_error(end - pos, ret))
8394 return -1;
8395 pos += ret;
8396 }
8397
8398 if (si.center_frq2 > 0) {
8399 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
8400 si.center_frq2);
8401 if (os_snprintf_error(end - pos, ret))
8402 return -1;
8403 pos += ret;
8404 }
8405
8406 if (si.data.avg_signal) {
8407 ret = os_snprintf(pos, end - pos,
8408 "AVG_RSSI=%d\n", si.data.avg_signal);
8409 if (os_snprintf_error(end - pos, ret))
8410 return -1;
8411 pos += ret;
8412 }
8413
8414 if (si.data.avg_beacon_signal) {
8415 ret = os_snprintf(pos, end - pos,
8416 "AVG_BEACON_RSSI=%d\n",
8417 si.data.avg_beacon_signal);
8418 if (os_snprintf_error(end - pos, ret))
8419 return -1;
8420 pos += ret;
8421 }
8422
8423 return pos - buf;
8424 }
8425
8426
wpas_ctrl_iface_signal_monitor(struct wpa_supplicant * wpa_s,const char * cmd)8427 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
8428 const char *cmd)
8429 {
8430 const char *pos;
8431 int threshold = 0;
8432 int hysteresis = 0;
8433
8434 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
8435 wpa_printf(MSG_DEBUG,
8436 "Reject SIGNAL_MONITOR command - bgscan is active");
8437 return -1;
8438 }
8439 pos = os_strstr(cmd, "THRESHOLD=");
8440 if (pos)
8441 threshold = atoi(pos + 10);
8442 pos = os_strstr(cmd, "HYSTERESIS=");
8443 if (pos)
8444 hysteresis = atoi(pos + 11);
8445 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
8446 }
8447
8448
8449 #ifdef CONFIG_TESTING_OPTIONS
wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant * wpa_s,enum wpa_driver_if_type if_type,unsigned int * num,struct weighted_pcl * freq_list)8450 int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
8451 enum wpa_driver_if_type if_type,
8452 unsigned int *num,
8453 struct weighted_pcl *freq_list)
8454 {
8455 char *pos = wpa_s->get_pref_freq_list_override;
8456 char *end;
8457 unsigned int count = 0;
8458
8459 /* Override string format:
8460 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
8461
8462 while (pos) {
8463 if (atoi(pos) == (int) if_type)
8464 break;
8465 pos = os_strchr(pos, ' ');
8466 if (pos)
8467 pos++;
8468 }
8469 if (!pos)
8470 return -1;
8471 pos = os_strchr(pos, ':');
8472 if (!pos)
8473 return -1;
8474 pos++;
8475 end = os_strchr(pos, ' ');
8476 while (pos && (!end || pos < end) && count < *num) {
8477 freq_list[count].freq = atoi(pos);
8478 freq_list[count++].flag = WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI;
8479 pos = os_strchr(pos, ',');
8480 if (pos)
8481 pos++;
8482 }
8483
8484 *num = count;
8485 return 0;
8486 }
8487 #endif /* CONFIG_TESTING_OPTIONS */
8488
8489
wpas_ctrl_iface_get_pref_freq_list(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)8490 static int wpas_ctrl_iface_get_pref_freq_list(
8491 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
8492 {
8493 unsigned int num = 100, i;
8494 int ret;
8495 enum wpa_driver_if_type iface_type;
8496 char *pos, *end;
8497 struct weighted_pcl freq_list[100];
8498
8499 pos = buf;
8500 end = buf + buflen;
8501
8502 /* buf: "<interface_type>" */
8503 if (os_strcmp(cmd, "STATION") == 0)
8504 iface_type = WPA_IF_STATION;
8505 else if (os_strcmp(cmd, "AP") == 0)
8506 iface_type = WPA_IF_AP_BSS;
8507 else if (os_strcmp(cmd, "P2P_GO") == 0)
8508 iface_type = WPA_IF_P2P_GO;
8509 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
8510 iface_type = WPA_IF_P2P_CLIENT;
8511 else if (os_strcmp(cmd, "IBSS") == 0)
8512 iface_type = WPA_IF_IBSS;
8513 else if (os_strcmp(cmd, "TDLS") == 0)
8514 iface_type = WPA_IF_TDLS;
8515 else
8516 return -1;
8517
8518 wpa_printf(MSG_DEBUG,
8519 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
8520 iface_type, cmd);
8521
8522 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
8523 if (ret)
8524 return -1;
8525
8526 for (i = 0; i < num; i++) {
8527 ret = os_snprintf(pos, end - pos, "%s%u",
8528 i > 0 ? "," : "", freq_list[i].freq);
8529 if (os_snprintf_error(end - pos, ret))
8530 return -1;
8531 pos += ret;
8532 }
8533
8534 return pos - buf;
8535 }
8536
8537
wpas_ctrl_iface_driver_flags(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)8538 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
8539 char *buf, size_t buflen)
8540 {
8541 int ret, i;
8542 char *pos, *end;
8543
8544 ret = os_snprintf(buf, buflen, "%016llX:\n",
8545 (long long unsigned) wpa_s->drv_flags);
8546 if (os_snprintf_error(buflen, ret))
8547 return -1;
8548
8549 pos = buf + ret;
8550 end = buf + buflen;
8551
8552 for (i = 0; i < 64; i++) {
8553 if (wpa_s->drv_flags & (1LLU << i)) {
8554 ret = os_snprintf(pos, end - pos, "%s\n",
8555 driver_flag_to_string(1LLU << i));
8556 if (os_snprintf_error(end - pos, ret))
8557 return -1;
8558 pos += ret;
8559 }
8560 }
8561
8562 return pos - buf;
8563 }
8564
8565
wpas_ctrl_iface_driver_flags2(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)8566 static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s,
8567 char *buf, size_t buflen)
8568 {
8569 int ret, i;
8570 char *pos, *end;
8571
8572 ret = os_snprintf(buf, buflen, "%016llX:\n",
8573 (long long unsigned) wpa_s->drv_flags2);
8574 if (os_snprintf_error(buflen, ret))
8575 return -1;
8576
8577 pos = buf + ret;
8578 end = buf + buflen;
8579
8580 for (i = 0; i < 64; i++) {
8581 if (wpa_s->drv_flags2 & (1LLU << i)) {
8582 ret = os_snprintf(pos, end - pos, "%s\n",
8583 driver_flag2_to_string(1LLU << i));
8584 if (os_snprintf_error(end - pos, ret))
8585 return -1;
8586 pos += ret;
8587 }
8588 }
8589
8590 return pos - buf;
8591 }
8592
8593
wpa_supplicant_pktcnt_poll(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)8594 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
8595 size_t buflen)
8596 {
8597 struct hostap_sta_driver_data sta;
8598 int ret;
8599
8600 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
8601 if (ret)
8602 return -1;
8603
8604 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
8605 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
8606 if (os_snprintf_error(buflen, ret))
8607 return -1;
8608 return ret;
8609 }
8610
8611
8612 #ifdef ANDROID
wpa_supplicant_driver_cmd(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)8613 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8614 char *buf, size_t buflen)
8615 {
8616 int ret;
8617
8618 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
8619 if (ret == 0) {
8620 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
8621 struct p2p_data *p2p = wpa_s->global->p2p;
8622 if (p2p) {
8623 char country[3];
8624 country[0] = cmd[8];
8625 country[1] = cmd[9];
8626 country[2] = 0x04;
8627 p2p_set_country(p2p, country);
8628 }
8629 }
8630 ret = os_snprintf(buf, buflen, "%s\n", "OK");
8631 if (os_snprintf_error(buflen, ret))
8632 ret = -1;
8633 }
8634 return ret;
8635 }
8636 #endif /* ANDROID */
8637
8638
wpa_supplicant_vendor_cmd(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)8639 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8640 char *buf, size_t buflen)
8641 {
8642 int ret;
8643 char *pos, *temp = NULL;
8644 u8 *data = NULL;
8645 unsigned int vendor_id, subcmd;
8646 enum nested_attr nested_attr_flag = NESTED_ATTR_UNSPECIFIED;
8647 struct wpabuf *reply;
8648 size_t data_len = 0;
8649
8650 /**
8651 * cmd: <vendor id> <subcommand id> [<hex formatted data>]
8652 * [nested=<0|1>]
8653 */
8654 vendor_id = strtoul(cmd, &pos, 16);
8655 if (!isblank((unsigned char) *pos))
8656 return -EINVAL;
8657
8658 subcmd = strtoul(pos, &pos, 10);
8659
8660 if (*pos != '\0') {
8661 if (!isblank((unsigned char) *pos++))
8662 return -EINVAL;
8663
8664 temp = os_strchr(pos, ' ');
8665 data_len = temp ? (size_t) (temp - pos) : os_strlen(pos);
8666 }
8667
8668 if (data_len) {
8669 data_len /= 2;
8670 data = os_malloc(data_len);
8671 if (!data)
8672 return -1;
8673
8674 if (hexstr2bin(pos, data, data_len)) {
8675 wpa_printf(MSG_DEBUG,
8676 "Vendor command: wrong parameter format");
8677 os_free(data);
8678 return -EINVAL;
8679 }
8680 }
8681
8682 pos = os_strstr(cmd, "nested=");
8683 if (pos)
8684 nested_attr_flag = atoi(pos + 7) ? NESTED_ATTR_USED :
8685 NESTED_ATTR_NOT_USED;
8686
8687 reply = wpabuf_alloc((buflen - 1) / 2);
8688 if (!reply) {
8689 os_free(data);
8690 return -1;
8691 }
8692
8693 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
8694 nested_attr_flag, reply);
8695
8696 if (ret == 0)
8697 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
8698 wpabuf_len(reply));
8699
8700 wpabuf_free(reply);
8701 os_free(data);
8702
8703 return ret;
8704 }
8705
8706
wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant * wpa_s)8707 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
8708 {
8709 #ifdef CONFIG_P2P
8710 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
8711 wpa_s->global->p2p_init_wpa_s : wpa_s;
8712 #endif /* CONFIG_P2P */
8713
8714 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
8715
8716 if (wpas_abort_ongoing_scan(wpa_s) == 0)
8717 wpa_s->ignore_post_flush_scan_res = 1;
8718
8719 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
8720 /*
8721 * Avoid possible auto connect re-connection on getting
8722 * disconnected due to state flush.
8723 */
8724 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
8725 }
8726
8727 #ifdef CONFIG_P2P
8728 wpas_p2p_group_remove(p2p_wpa_s, "*");
8729 wpas_p2p_cancel(p2p_wpa_s);
8730 p2p_ctrl_flush(p2p_wpa_s);
8731 wpas_p2p_service_flush(p2p_wpa_s);
8732 p2p_wpa_s->global->p2p_disabled = 0;
8733 p2p_wpa_s->global->p2p_per_sta_psk = 0;
8734 p2p_wpa_s->conf->num_sec_device_types = 0;
8735 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
8736 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
8737 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
8738 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
8739 p2p_wpa_s->global->pending_p2ps_group = 0;
8740 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
8741 #endif /* CONFIG_P2P */
8742
8743 #ifdef CONFIG_WPS_TESTING
8744 wps_version_number = 0x20;
8745 wps_testing_stub_cred = 0;
8746 wps_corrupt_pkhash = 0;
8747 wps_force_auth_types_in_use = 0;
8748 wps_force_encr_types_in_use = 0;
8749 #endif /* CONFIG_WPS_TESTING */
8750 #ifdef CONFIG_WPS
8751 wpa_s->wps_fragment_size = 0;
8752 wpas_wps_cancel(wpa_s);
8753 wps_registrar_flush(wpa_s->wps->registrar);
8754 #endif /* CONFIG_WPS */
8755 wpa_s->after_wps = 0;
8756 wpa_s->known_wps_freq = 0;
8757
8758 #ifdef CONFIG_DPP
8759 wpas_dpp_deinit(wpa_s);
8760 wpa_s->dpp_init_max_tries = 0;
8761 wpa_s->dpp_init_retry_time = 0;
8762 wpa_s->dpp_resp_wait_time = 0;
8763 wpa_s->dpp_resp_max_tries = 0;
8764 wpa_s->dpp_resp_retry_time = 0;
8765 #ifdef CONFIG_DPP2
8766 wpas_dpp_chirp_stop(wpa_s);
8767 wpa_s->dpp_pfs_fallback = 0;
8768 #endif /* CONFIG_DPP2 */
8769 #ifdef CONFIG_DPP3
8770 {
8771 int i;
8772
8773 for (i = 0; i < DPP_PB_INFO_COUNT; i++) {
8774 struct dpp_pb_info *info;
8775
8776 info = &wpa_s->dpp_pb[i];
8777 info->rx_time.sec = 0;
8778 info->rx_time.usec = 0;
8779 }
8780 }
8781 #endif /* CONFIG_DPP3 */
8782 #ifdef CONFIG_TESTING_OPTIONS
8783 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
8784 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
8785 dpp_pkex_ephemeral_key_override_len = 0;
8786 dpp_protocol_key_override_len = 0;
8787 dpp_nonce_override_len = 0;
8788 #ifdef CONFIG_DPP3
8789 dpp_version_override = 3;
8790 #elif defined(CONFIG_DPP2)
8791 dpp_version_override = 2;
8792 #else /* CONFIG_DPP2 */
8793 dpp_version_override = 1;
8794 #endif /* CONFIG_DPP2 */
8795 #endif /* CONFIG_TESTING_OPTIONS */
8796 #endif /* CONFIG_DPP */
8797
8798 #ifdef CONFIG_TDLS
8799 #ifdef CONFIG_TDLS_TESTING
8800 tdls_testing = 0;
8801 #endif /* CONFIG_TDLS_TESTING */
8802 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
8803 wpa_tdls_enable(wpa_s->wpa, 1);
8804 #endif /* CONFIG_TDLS */
8805
8806 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
8807 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
8808 wpa_s->last_michael_mic_error.sec = 0;
8809
8810 wpa_s->no_keep_alive = 0;
8811 wpa_s->own_disconnect_req = 0;
8812 wpa_s->own_reconnect_req = 0;
8813 wpa_s->deny_ptk0_rekey = 0;
8814
8815 os_free(wpa_s->disallow_aps_bssid);
8816 wpa_s->disallow_aps_bssid = NULL;
8817 wpa_s->disallow_aps_bssid_count = 0;
8818 os_free(wpa_s->disallow_aps_ssid);
8819 wpa_s->disallow_aps_ssid = NULL;
8820 wpa_s->disallow_aps_ssid_count = 0;
8821
8822 wpa_s->set_sta_uapsd = 0;
8823 wpa_s->sta_uapsd = 0;
8824
8825 wpa_s->consecutive_conn_failures = 0;
8826
8827 wpa_drv_radio_disable(wpa_s, 0);
8828 wpa_bssid_ignore_clear(wpa_s);
8829 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
8830 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
8831 wpa_config_flush_blobs(wpa_s->conf);
8832 wpa_s->conf->auto_interworking = 0;
8833 wpa_s->conf->okc = 0;
8834
8835 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
8836 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
8837 rsn_preauth_deinit(wpa_s->wpa);
8838
8839 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
8840 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
8841 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
8842 eapol_sm_notify_logoff(wpa_s->eapol, false);
8843
8844 radio_remove_works(wpa_s, NULL, 1);
8845 wpa_s->ext_work_in_progress = 0;
8846
8847 wpa_s->next_ssid = NULL;
8848
8849 #ifdef CONFIG_INTERWORKING
8850 #ifdef CONFIG_HS20
8851 hs20_cancel_fetch_osu(wpa_s);
8852 hs20_del_icon(wpa_s, NULL, NULL);
8853 #endif /* CONFIG_HS20 */
8854 #endif /* CONFIG_INTERWORKING */
8855
8856 wpa_s->ext_mgmt_frame_handling = 0;
8857 wpa_s->ext_eapol_frame_io = 0;
8858 #ifdef CONFIG_TESTING_OPTIONS
8859 wpa_s->extra_roc_dur = 0;
8860 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
8861 wpa_s->p2p_go_csa_on_inv = 0;
8862 wpa_s->ignore_auth_resp = 0;
8863 wpa_s->ignore_assoc_disallow = 0;
8864 wpa_s->disable_sa_query = 0;
8865 wpa_s->testing_resend_assoc = 0;
8866 wpa_s->ignore_sae_h2e_only = 0;
8867 wpa_s->ft_rsnxe_used = 0;
8868 wpa_s->reject_btm_req_reason = 0;
8869 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
8870 os_free(wpa_s->get_pref_freq_list_override);
8871 wpa_s->get_pref_freq_list_override = NULL;
8872 wpabuf_free(wpa_s->sae_commit_override);
8873 wpa_s->sae_commit_override = NULL;
8874 os_free(wpa_s->extra_sae_rejected_groups);
8875 wpa_s->extra_sae_rejected_groups = NULL;
8876 wpabuf_free(wpa_s->rsne_override_eapol);
8877 wpa_s->rsne_override_eapol = NULL;
8878 wpabuf_free(wpa_s->rsnxe_override_assoc);
8879 wpa_s->rsnxe_override_assoc = NULL;
8880 wpabuf_free(wpa_s->rsnxe_override_eapol);
8881 wpa_s->rsnxe_override_eapol = NULL;
8882 wpas_clear_driver_signal_override(wpa_s);
8883 wpa_s->disable_scs_support = 0;
8884 wpa_s->disable_mscs_support = 0;
8885 wpa_s->enable_dscp_policy_capa = 0;
8886 wpa_s->oci_freq_override_eapol = 0;
8887 wpa_s->oci_freq_override_saquery_req = 0;
8888 wpa_s->oci_freq_override_saquery_resp = 0;
8889 wpa_s->oci_freq_override_eapol_g2 = 0;
8890 wpa_s->oci_freq_override_ft_assoc = 0;
8891 wpa_s->oci_freq_override_fils_assoc = 0;
8892 wpa_s->oci_freq_override_wnm_sleep = 0;
8893 wpa_s->disable_eapol_g2_tx = 0;
8894 #ifdef CONFIG_DPP
8895 os_free(wpa_s->dpp_config_obj_override);
8896 wpa_s->dpp_config_obj_override = NULL;
8897 os_free(wpa_s->dpp_discovery_override);
8898 wpa_s->dpp_discovery_override = NULL;
8899 os_free(wpa_s->dpp_groups_override);
8900 wpa_s->dpp_groups_override = NULL;
8901 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
8902 wpa_s->dpp_discard_public_action = 0;
8903 dpp_test = DPP_TEST_DISABLED;
8904 #endif /* CONFIG_DPP */
8905 #endif /* CONFIG_TESTING_OPTIONS */
8906
8907 wpa_s->disconnected = 0;
8908 os_free(wpa_s->next_scan_freqs);
8909 wpa_s->next_scan_freqs = NULL;
8910 os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN);
8911 wpa_s->next_scan_bssid_wildcard_ssid = 0;
8912 os_free(wpa_s->select_network_scan_freqs);
8913 wpa_s->select_network_scan_freqs = NULL;
8914 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
8915
8916 wpa_bss_flush(wpa_s);
8917 if (!dl_list_empty(&wpa_s->bss)) {
8918 wpa_printf(MSG_DEBUG,
8919 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8920 MACSTR " pending_bssid=" MACSTR,
8921 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
8922 MAC2STR(wpa_s->bssid),
8923 MAC2STR(wpa_s->pending_bssid));
8924 }
8925
8926 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
8927 wpa_s->wnmsleep_used = 0;
8928
8929 #ifdef CONFIG_SME
8930 wpa_s->sme.last_unprot_disconnect.sec = 0;
8931 wpa_s->sme.auth_alg = 0;
8932 #endif /* CONFIG_SME */
8933
8934 wpabuf_free(wpa_s->ric_ies);
8935 wpa_s->ric_ies = NULL;
8936
8937 wpa_supplicant_update_channel_list(wpa_s, NULL);
8938
8939 free_bss_tmp_disallowed(wpa_s);
8940
8941 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
8942
8943 #ifdef CONFIG_PASN
8944 wpas_pasn_auth_stop(wpa_s);
8945 #endif /* CONFIG_PASN */
8946
8947 if (wpa_s->mac_addr_changed && wpa_s->conf->mac_addr == 0)
8948 wpas_restore_permanent_mac_addr(wpa_s);
8949
8950 wpa_s->conf->ignore_old_scan_res = 0;
8951 }
8952
8953
wpas_ctrl_radio_work_show(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)8954 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
8955 char *buf, size_t buflen)
8956 {
8957 struct wpa_radio_work *work;
8958 char *pos, *end;
8959 struct os_reltime now, diff;
8960
8961 pos = buf;
8962 end = buf + buflen;
8963
8964 os_get_reltime(&now);
8965
8966 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8967 {
8968 int ret;
8969
8970 os_reltime_sub(&now, &work->time, &diff);
8971 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
8972 work->type, work->wpa_s->ifname, work->freq,
8973 work->started, diff.sec, diff.usec);
8974 if (os_snprintf_error(end - pos, ret))
8975 break;
8976 pos += ret;
8977 }
8978
8979 return pos - buf;
8980 }
8981
8982
wpas_ctrl_radio_work_timeout(void * eloop_ctx,void * timeout_ctx)8983 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
8984 {
8985 struct wpa_radio_work *work = eloop_ctx;
8986 struct wpa_external_work *ework = work->ctx;
8987
8988 wpa_dbg(work->wpa_s, MSG_DEBUG,
8989 "Timing out external radio work %u (%s)",
8990 ework->id, work->type);
8991 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
8992 work->wpa_s->ext_work_in_progress = 0;
8993 radio_work_done(work);
8994 os_free(ework);
8995 }
8996
8997
wpas_ctrl_radio_work_cb(struct wpa_radio_work * work,int deinit)8998 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
8999 {
9000 struct wpa_external_work *ework = work->ctx;
9001
9002 if (deinit) {
9003 if (work->started)
9004 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
9005 work, NULL);
9006
9007 /*
9008 * work->type points to a buffer in ework, so need to replace
9009 * that here with a fixed string to avoid use of freed memory
9010 * in debug prints.
9011 */
9012 work->type = "freed-ext-work";
9013 work->ctx = NULL;
9014 os_free(ework);
9015 return;
9016 }
9017
9018 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
9019 ework->id, ework->type);
9020 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
9021 work->wpa_s->ext_work_in_progress = 1;
9022 if (!ework->timeout)
9023 ework->timeout = 10;
9024 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
9025 work, NULL);
9026 }
9027
9028
wpas_ctrl_radio_work_add(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)9029 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
9030 char *buf, size_t buflen)
9031 {
9032 struct wpa_external_work *ework;
9033 char *pos, *pos2;
9034 size_t type_len;
9035 int ret;
9036 unsigned int freq = 0;
9037
9038 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
9039
9040 ework = os_zalloc(sizeof(*ework));
9041 if (ework == NULL)
9042 return -1;
9043
9044 pos = os_strchr(cmd, ' ');
9045 if (pos) {
9046 type_len = pos - cmd;
9047 pos++;
9048
9049 pos2 = os_strstr(pos, "freq=");
9050 if (pos2)
9051 freq = atoi(pos2 + 5);
9052
9053 pos2 = os_strstr(pos, "timeout=");
9054 if (pos2)
9055 ework->timeout = atoi(pos2 + 8);
9056 } else {
9057 type_len = os_strlen(cmd);
9058 }
9059 if (4 + type_len >= sizeof(ework->type))
9060 type_len = sizeof(ework->type) - 4 - 1;
9061 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
9062 os_memcpy(ework->type + 4, cmd, type_len);
9063 ework->type[4 + type_len] = '\0';
9064
9065 wpa_s->ext_work_id++;
9066 if (wpa_s->ext_work_id == 0)
9067 wpa_s->ext_work_id++;
9068 ework->id = wpa_s->ext_work_id;
9069
9070 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
9071 ework) < 0) {
9072 os_free(ework);
9073 return -1;
9074 }
9075
9076 ret = os_snprintf(buf, buflen, "%u", ework->id);
9077 if (os_snprintf_error(buflen, ret))
9078 return -1;
9079 return ret;
9080 }
9081
9082
wpas_ctrl_radio_work_done(struct wpa_supplicant * wpa_s,char * cmd)9083 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
9084 {
9085 struct wpa_radio_work *work;
9086 unsigned int id = atoi(cmd);
9087
9088 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
9089 {
9090 struct wpa_external_work *ework;
9091
9092 if (os_strncmp(work->type, "ext:", 4) != 0)
9093 continue;
9094 ework = work->ctx;
9095 if (id && ework->id != id)
9096 continue;
9097 wpa_dbg(wpa_s, MSG_DEBUG,
9098 "Completed external radio work %u (%s)",
9099 ework->id, ework->type);
9100 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
9101 wpa_s->ext_work_in_progress = 0;
9102 radio_work_done(work);
9103 os_free(ework);
9104 return 3; /* "OK\n" */
9105 }
9106
9107 return -1;
9108 }
9109
9110
wpas_ctrl_radio_work(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)9111 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
9112 char *buf, size_t buflen)
9113 {
9114 if (os_strcmp(cmd, "show") == 0)
9115 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
9116 if (os_strncmp(cmd, "add ", 4) == 0)
9117 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
9118 if (os_strncmp(cmd, "done ", 5) == 0)
9119 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
9120 return -1;
9121 }
9122
9123
wpas_ctrl_radio_work_flush(struct wpa_supplicant * wpa_s)9124 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
9125 {
9126 struct wpa_radio_work *work, *tmp;
9127
9128 if (!wpa_s || !wpa_s->radio)
9129 return;
9130
9131 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
9132 struct wpa_radio_work, list) {
9133 struct wpa_external_work *ework;
9134
9135 if (os_strncmp(work->type, "ext:", 4) != 0)
9136 continue;
9137 ework = work->ctx;
9138 wpa_dbg(wpa_s, MSG_DEBUG,
9139 "Flushing%s external radio work %u (%s)",
9140 work->started ? " started" : "", ework->id,
9141 ework->type);
9142 if (work->started)
9143 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
9144 work, NULL);
9145 radio_work_done(work);
9146 os_free(ework);
9147 }
9148 }
9149
9150
wpas_ctrl_eapol_response(void * eloop_ctx,void * timeout_ctx)9151 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
9152 {
9153 struct wpa_supplicant *wpa_s = eloop_ctx;
9154 eapol_sm_notify_ctrl_response(wpa_s->eapol);
9155 }
9156
9157
scan_id_list_parse(struct wpa_supplicant * wpa_s,const char * value,unsigned int * scan_id_count,int scan_id[])9158 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
9159 unsigned int *scan_id_count, int scan_id[])
9160 {
9161 const char *pos = value;
9162
9163 while (pos) {
9164 if (*pos == ' ' || *pos == '\0')
9165 break;
9166 if (*scan_id_count == MAX_SCAN_ID)
9167 return -1;
9168 scan_id[(*scan_id_count)++] = atoi(pos);
9169 pos = os_strchr(pos, ',');
9170 if (pos)
9171 pos++;
9172 }
9173
9174 return 0;
9175 }
9176
9177
wpas_ctrl_scan(struct wpa_supplicant * wpa_s,char * params,char * reply,int reply_size,int * reply_len)9178 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
9179 char *reply, int reply_size, int *reply_len)
9180 {
9181 char *pos;
9182 unsigned int manual_scan_passive = 0;
9183 unsigned int manual_scan_use_id = 0;
9184 unsigned int manual_scan_only_new = 0;
9185 unsigned int scan_only = 0;
9186 unsigned int scan_id_count = 0;
9187 unsigned int manual_non_coloc_6ghz = 0;
9188 int scan_id[MAX_SCAN_ID];
9189 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
9190 struct wpa_scan_results *scan_res);
9191 int *manual_scan_freqs = NULL;
9192 struct wpa_ssid_value *ssid = NULL, *ns;
9193 unsigned int ssid_count = 0;
9194
9195 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
9196 *reply_len = -1;
9197 return;
9198 }
9199
9200 if (radio_work_pending(wpa_s, "scan")) {
9201 wpa_printf(MSG_DEBUG,
9202 "Pending scan scheduled - reject new request");
9203 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9204 return;
9205 }
9206
9207 #ifdef CONFIG_INTERWORKING
9208 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
9209 wpa_printf(MSG_DEBUG,
9210 "Interworking select in progress - reject new scan");
9211 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9212 return;
9213 }
9214 #endif /* CONFIG_INTERWORKING */
9215
9216 if (params) {
9217 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
9218 scan_only = 1;
9219
9220 pos = os_strstr(params, "freq=");
9221 if (pos) {
9222 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
9223 pos + 5);
9224 if (manual_scan_freqs == NULL) {
9225 *reply_len = -1;
9226 goto done;
9227 }
9228 }
9229
9230 pos = os_strstr(params, "passive=");
9231 if (pos)
9232 manual_scan_passive = !!atoi(pos + 8);
9233
9234 pos = os_strstr(params, "use_id=");
9235 if (pos)
9236 manual_scan_use_id = atoi(pos + 7);
9237
9238 pos = os_strstr(params, "only_new=1");
9239 if (pos)
9240 manual_scan_only_new = 1;
9241
9242 pos = os_strstr(params, "scan_id=");
9243 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
9244 scan_id) < 0) {
9245 *reply_len = -1;
9246 goto done;
9247 }
9248
9249 pos = os_strstr(params, "bssid=");
9250 if (pos) {
9251 u8 bssid[ETH_ALEN];
9252
9253 pos += 6;
9254 if (hwaddr_aton(pos, bssid)) {
9255 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
9256 *reply_len = -1;
9257 goto done;
9258 }
9259 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
9260
9261 wpa_s->next_scan_bssid_wildcard_ssid =
9262 os_strstr(params, "wildcard_ssid=1") != NULL;
9263 }
9264
9265 pos = os_strstr(params, "non_coloc_6ghz=");
9266 if (pos)
9267 manual_non_coloc_6ghz = !!atoi(pos + 15);
9268
9269 pos = params;
9270 while (pos && *pos != '\0') {
9271 if (os_strncmp(pos, "ssid ", 5) == 0) {
9272 char *end;
9273
9274 pos += 5;
9275 end = pos;
9276 while (*end) {
9277 if (*end == '\0' || *end == ' ')
9278 break;
9279 end++;
9280 }
9281
9282 ns = os_realloc_array(
9283 ssid, ssid_count + 1,
9284 sizeof(struct wpa_ssid_value));
9285 if (ns == NULL) {
9286 *reply_len = -1;
9287 goto done;
9288 }
9289 ssid = ns;
9290
9291 if ((end - pos) & 0x01 ||
9292 end - pos > 2 * SSID_MAX_LEN ||
9293 hexstr2bin(pos, ssid[ssid_count].ssid,
9294 (end - pos) / 2) < 0) {
9295 wpa_printf(MSG_DEBUG,
9296 "Invalid SSID value '%s'",
9297 pos);
9298 *reply_len = -1;
9299 goto done;
9300 }
9301 ssid[ssid_count].ssid_len = (end - pos) / 2;
9302 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
9303 ssid[ssid_count].ssid,
9304 ssid[ssid_count].ssid_len);
9305 ssid_count++;
9306 pos = end;
9307 }
9308
9309 pos = os_strchr(pos, ' ');
9310 if (pos)
9311 pos++;
9312 }
9313 }
9314
9315 wpa_s->num_ssids_from_scan_req = ssid_count;
9316 os_free(wpa_s->ssids_from_scan_req);
9317 if (ssid_count) {
9318 wpa_s->ssids_from_scan_req = ssid;
9319 ssid = NULL;
9320 } else {
9321 wpa_s->ssids_from_scan_req = NULL;
9322 }
9323
9324 if (scan_only)
9325 scan_res_handler = scan_only_handler;
9326 else if (wpa_s->scan_res_handler == scan_only_handler)
9327 scan_res_handler = NULL;
9328 else
9329 scan_res_handler = wpa_s->scan_res_handler;
9330
9331 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
9332 ((wpa_s->wpa_state <= WPA_SCANNING) ||
9333 (wpa_s->wpa_state == WPA_COMPLETED))) {
9334 wpa_s->manual_scan_passive = manual_scan_passive;
9335 wpa_s->manual_scan_use_id = manual_scan_use_id;
9336 wpa_s->manual_scan_only_new = manual_scan_only_new;
9337 wpa_s->scan_id_count = scan_id_count;
9338 wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz;
9339 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9340 wpa_s->scan_res_handler = scan_res_handler;
9341 os_free(wpa_s->manual_scan_freqs);
9342 wpa_s->manual_scan_freqs = manual_scan_freqs;
9343 manual_scan_freqs = NULL;
9344
9345 wpa_s->normal_scans = 0;
9346 wpa_s->scan_req = MANUAL_SCAN_REQ;
9347 wpa_s->after_wps = 0;
9348 wpa_s->known_wps_freq = 0;
9349 wpa_supplicant_req_scan(wpa_s, 0, 0);
9350 if (wpa_s->manual_scan_use_id) {
9351 wpa_s->manual_scan_id++;
9352 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9353 wpa_s->manual_scan_id);
9354 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9355 wpa_s->manual_scan_id);
9356 }
9357 } else if (wpa_s->sched_scanning) {
9358 wpa_s->manual_scan_passive = manual_scan_passive;
9359 wpa_s->manual_scan_use_id = manual_scan_use_id;
9360 wpa_s->manual_scan_only_new = manual_scan_only_new;
9361 wpa_s->scan_id_count = scan_id_count;
9362 wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz;
9363 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9364 wpa_s->scan_res_handler = scan_res_handler;
9365 os_free(wpa_s->manual_scan_freqs);
9366 wpa_s->manual_scan_freqs = manual_scan_freqs;
9367 manual_scan_freqs = NULL;
9368
9369 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
9370 wpa_supplicant_cancel_sched_scan(wpa_s);
9371 wpa_s->scan_req = MANUAL_SCAN_REQ;
9372 wpa_supplicant_req_scan(wpa_s, 0, 0);
9373 if (wpa_s->manual_scan_use_id) {
9374 wpa_s->manual_scan_id++;
9375 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9376 wpa_s->manual_scan_id);
9377 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9378 wpa_s->manual_scan_id);
9379 }
9380 } else {
9381 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
9382 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9383 }
9384
9385 done:
9386 os_free(manual_scan_freqs);
9387 os_free(ssid);
9388 }
9389
9390
9391 #ifdef CONFIG_TESTING_OPTIONS
9392
wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant * wpa_s,unsigned int freq,const u8 * dst,const u8 * src,const u8 * bssid,const u8 * data,size_t data_len,enum offchannel_send_action_result result)9393 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
9394 unsigned int freq, const u8 *dst,
9395 const u8 *src, const u8 *bssid,
9396 const u8 *data, size_t data_len,
9397 enum offchannel_send_action_result
9398 result)
9399 {
9400 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
9401 " src=" MACSTR " bssid=" MACSTR " result=%s",
9402 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
9403 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
9404 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
9405 "NO_ACK" : "FAILED"));
9406 }
9407
9408
wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant * wpa_s,char * cmd)9409 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
9410 {
9411 char *pos, *param;
9412 size_t len;
9413 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
9414 int res, used;
9415 int freq = 0, no_cck = 0, wait_time = 0;
9416
9417 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
9418 * <action=Action frame payload> */
9419
9420 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
9421
9422 pos = cmd;
9423 used = hwaddr_aton2(pos, da);
9424 if (used < 0)
9425 return -1;
9426 pos += used;
9427 while (*pos == ' ')
9428 pos++;
9429 used = hwaddr_aton2(pos, bssid);
9430 if (used < 0)
9431 return -1;
9432 pos += used;
9433
9434 param = os_strstr(pos, " freq=");
9435 if (param) {
9436 param += 6;
9437 freq = atoi(param);
9438 }
9439
9440 param = os_strstr(pos, " no_cck=");
9441 if (param) {
9442 param += 8;
9443 no_cck = atoi(param);
9444 }
9445
9446 param = os_strstr(pos, " wait_time=");
9447 if (param) {
9448 param += 11;
9449 wait_time = atoi(param);
9450 }
9451
9452 param = os_strstr(pos, " action=");
9453 if (param == NULL)
9454 return -1;
9455 param += 8;
9456
9457 len = os_strlen(param);
9458 if (len & 1)
9459 return -1;
9460 len /= 2;
9461
9462 buf = os_malloc(len);
9463 if (buf == NULL)
9464 return -1;
9465
9466 if (hexstr2bin(param, buf, len) < 0) {
9467 os_free(buf);
9468 return -1;
9469 }
9470
9471 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
9472 buf, len, wait_time,
9473 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
9474 os_free(buf);
9475 return res;
9476 }
9477
9478
wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant * wpa_s)9479 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
9480 {
9481 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
9482 offchannel_send_action_done(wpa_s);
9483 }
9484
9485
wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant * wpa_s,char * cmd)9486 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
9487 char *cmd)
9488 {
9489 char *pos, *param;
9490 size_t len;
9491 u8 *buf;
9492 int freq = 0, datarate = 0, ssi_signal = 0;
9493 union wpa_event_data event;
9494
9495 if (!wpa_s->ext_mgmt_frame_handling)
9496 return -1;
9497
9498 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
9499
9500 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
9501
9502 pos = cmd;
9503 param = os_strstr(pos, "freq=");
9504 if (param) {
9505 param += 5;
9506 freq = atoi(param);
9507 }
9508
9509 param = os_strstr(pos, " datarate=");
9510 if (param) {
9511 param += 10;
9512 datarate = atoi(param);
9513 }
9514
9515 param = os_strstr(pos, " ssi_signal=");
9516 if (param) {
9517 param += 12;
9518 ssi_signal = atoi(param);
9519 }
9520
9521 param = os_strstr(pos, " frame=");
9522 if (param == NULL)
9523 return -1;
9524 param += 7;
9525
9526 len = os_strlen(param);
9527 if (len & 1)
9528 return -1;
9529 len /= 2;
9530
9531 buf = os_malloc(len);
9532 if (buf == NULL)
9533 return -1;
9534
9535 if (hexstr2bin(param, buf, len) < 0) {
9536 os_free(buf);
9537 return -1;
9538 }
9539
9540 os_memset(&event, 0, sizeof(event));
9541 event.rx_mgmt.freq = freq;
9542 event.rx_mgmt.frame = buf;
9543 event.rx_mgmt.frame_len = len;
9544 event.rx_mgmt.ssi_signal = ssi_signal;
9545 event.rx_mgmt.datarate = datarate;
9546 wpa_s->ext_mgmt_frame_handling = 0;
9547 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
9548 wpa_s->ext_mgmt_frame_handling = 1;
9549
9550 os_free(buf);
9551
9552 return 0;
9553 }
9554
9555
wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant * wpa_s,char * param)9556 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
9557 char *param)
9558 {
9559 struct wpa_scan_res *res;
9560 struct os_reltime now;
9561 char *pos, *end;
9562 int ret = -1;
9563
9564 if (!param)
9565 return -1;
9566
9567 if (os_strcmp(param, "START") == 0) {
9568 wpa_bss_update_start(wpa_s);
9569 return 0;
9570 }
9571
9572 if (os_strcmp(param, "END") == 0) {
9573 wpa_bss_update_end(wpa_s, NULL, 1);
9574 return 0;
9575 }
9576
9577 if (os_strncmp(param, "BSS ", 4) != 0)
9578 return -1;
9579 param += 3;
9580
9581 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
9582 if (!res)
9583 return -1;
9584
9585 pos = os_strstr(param, " flags=");
9586 if (pos)
9587 res->flags = strtol(pos + 7, NULL, 16);
9588
9589 pos = os_strstr(param, " bssid=");
9590 if (pos && hwaddr_aton(pos + 7, res->bssid))
9591 goto fail;
9592
9593 pos = os_strstr(param, " freq=");
9594 if (pos)
9595 res->freq = atoi(pos + 6);
9596
9597 pos = os_strstr(param, " beacon_int=");
9598 if (pos)
9599 res->beacon_int = atoi(pos + 12);
9600
9601 pos = os_strstr(param, " caps=");
9602 if (pos)
9603 res->caps = strtol(pos + 6, NULL, 16);
9604
9605 pos = os_strstr(param, " qual=");
9606 if (pos)
9607 res->qual = atoi(pos + 6);
9608
9609 pos = os_strstr(param, " noise=");
9610 if (pos)
9611 res->noise = atoi(pos + 7);
9612
9613 pos = os_strstr(param, " level=");
9614 if (pos)
9615 res->level = atoi(pos + 7);
9616
9617 pos = os_strstr(param, " tsf=");
9618 if (pos)
9619 res->tsf = strtoll(pos + 5, NULL, 16);
9620
9621 pos = os_strstr(param, " age=");
9622 if (pos)
9623 res->age = atoi(pos + 5);
9624
9625 pos = os_strstr(param, " est_throughput=");
9626 if (pos)
9627 res->est_throughput = atoi(pos + 16);
9628
9629 pos = os_strstr(param, " snr=");
9630 if (pos)
9631 res->snr = atoi(pos + 5);
9632
9633 pos = os_strstr(param, " parent_tsf=");
9634 if (pos)
9635 res->parent_tsf = strtoll(pos + 7, NULL, 16);
9636
9637 pos = os_strstr(param, " tsf_bssid=");
9638 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
9639 goto fail;
9640
9641 pos = os_strstr(param, " ie=");
9642 if (pos) {
9643 pos += 4;
9644 end = os_strchr(pos, ' ');
9645 if (!end)
9646 end = pos + os_strlen(pos);
9647 res->ie_len = (end - pos) / 2;
9648 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
9649 goto fail;
9650 }
9651
9652 pos = os_strstr(param, " beacon_ie=");
9653 if (pos) {
9654 pos += 11;
9655 end = os_strchr(pos, ' ');
9656 if (!end)
9657 end = pos + os_strlen(pos);
9658 res->beacon_ie_len = (end - pos) / 2;
9659 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
9660 res->beacon_ie_len))
9661 goto fail;
9662 }
9663
9664 os_get_reltime(&now);
9665 wpa_bss_update_scan_res(wpa_s, res, &now);
9666 ret = 0;
9667 fail:
9668 os_free(res);
9669
9670 return ret;
9671 }
9672
9673
wpas_ctrl_iface_driver_event_assoc(struct wpa_supplicant * wpa_s,char * param)9674 static int wpas_ctrl_iface_driver_event_assoc(struct wpa_supplicant *wpa_s,
9675 char *param)
9676 {
9677 union wpa_event_data event;
9678 struct assoc_info *ai;
9679 char *ctx = NULL;
9680 int ret = -1;
9681 struct wpabuf *req_ies = NULL;
9682 struct wpabuf *resp_ies = NULL;
9683 struct wpabuf *resp_frame = NULL;
9684 struct wpabuf *beacon_ies = NULL;
9685 struct wpabuf *key_replay_ctr = NULL;
9686 struct wpabuf *ptk_kck = NULL;
9687 struct wpabuf *ptk_kek = NULL;
9688 struct wpabuf *fils_pmk = NULL;
9689 char *str, *pos;
9690 u8 addr[ETH_ALEN];
9691 u8 fils_pmkid[PMKID_LEN];
9692
9693 os_memset(&event, 0, sizeof(event));
9694 ai = &event.assoc_info;
9695
9696 while ((str = str_token(param, " ", &ctx))) {
9697 pos = os_strchr(str, '=');
9698 if (!pos)
9699 goto fail;
9700 *pos++ = '\0';
9701
9702 if (os_strcmp(str, "reassoc") == 0) {
9703 ai->reassoc = atoi(pos);
9704 } else if (os_strcmp(str, "req_ies") == 0) {
9705 wpabuf_free(req_ies);
9706 req_ies = wpabuf_parse_bin(pos);
9707 if (!req_ies)
9708 goto fail;
9709 ai->req_ies = wpabuf_head(req_ies);
9710 ai->req_ies_len = wpabuf_len(req_ies);
9711 } else if (os_strcmp(str, "resp_ies") == 0) {
9712 wpabuf_free(resp_ies);
9713 resp_ies = wpabuf_parse_bin(pos);
9714 if (!resp_ies)
9715 goto fail;
9716 ai->resp_ies = wpabuf_head(resp_ies);
9717 ai->resp_ies_len = wpabuf_len(resp_ies);
9718 } else if (os_strcmp(str, "resp_frame") == 0) {
9719 wpabuf_free(resp_frame);
9720 resp_frame = wpabuf_parse_bin(pos);
9721 if (!resp_frame)
9722 goto fail;
9723 ai->resp_frame = wpabuf_head(resp_frame);
9724 ai->resp_frame_len = wpabuf_len(resp_frame);
9725 } else if (os_strcmp(str, "beacon_ies") == 0) {
9726 wpabuf_free(beacon_ies);
9727 beacon_ies = wpabuf_parse_bin(pos);
9728 if (!beacon_ies)
9729 goto fail;
9730 ai->beacon_ies = wpabuf_head(beacon_ies);
9731 ai->beacon_ies_len = wpabuf_len(beacon_ies);
9732 } else if (os_strcmp(str, "freq") == 0) {
9733 ai->freq = atoi(pos);
9734 } else if (os_strcmp(str, "wmm::info_bitmap") == 0) {
9735 ai->wmm_params.info_bitmap = atoi(pos);
9736 } else if (os_strcmp(str, "wmm::uapsd_queues") == 0) {
9737 ai->wmm_params.uapsd_queues = atoi(pos);
9738 } else if (os_strcmp(str, "addr") == 0) {
9739 if (hwaddr_aton(pos, addr))
9740 goto fail;
9741 ai->addr = addr;
9742 } else if (os_strcmp(str, "authorized") == 0) {
9743 ai->authorized = atoi(pos);
9744 } else if (os_strcmp(str, "key_replay_ctr") == 0) {
9745 wpabuf_free(key_replay_ctr);
9746 key_replay_ctr = wpabuf_parse_bin(pos);
9747 if (!key_replay_ctr)
9748 goto fail;
9749 ai->key_replay_ctr = wpabuf_head(key_replay_ctr);
9750 ai->key_replay_ctr_len = wpabuf_len(key_replay_ctr);
9751 } else if (os_strcmp(str, "ptk_kck") == 0) {
9752 wpabuf_free(ptk_kck);
9753 ptk_kck = wpabuf_parse_bin(pos);
9754 if (!ptk_kck)
9755 goto fail;
9756 ai->ptk_kck = wpabuf_head(ptk_kck);
9757 ai->ptk_kck_len = wpabuf_len(ptk_kck);
9758 } else if (os_strcmp(str, "ptk_kek") == 0) {
9759 wpabuf_free(ptk_kek);
9760 ptk_kek = wpabuf_parse_bin(pos);
9761 if (!ptk_kek)
9762 goto fail;
9763 ai->ptk_kek = wpabuf_head(ptk_kek);
9764 ai->ptk_kek_len = wpabuf_len(ptk_kek);
9765 } else if (os_strcmp(str, "subnet_status") == 0) {
9766 ai->subnet_status = atoi(pos);
9767 } else if (os_strcmp(str, "fils_erp_next_seq_num") == 0) {
9768 ai->fils_erp_next_seq_num = atoi(pos);
9769 } else if (os_strcmp(str, "fils_pmk") == 0) {
9770 wpabuf_free(fils_pmk);
9771 fils_pmk = wpabuf_parse_bin(pos);
9772 if (!fils_pmk)
9773 goto fail;
9774 ai->fils_pmk = wpabuf_head(fils_pmk);
9775 ai->fils_pmk_len = wpabuf_len(fils_pmk);
9776 } else if (os_strcmp(str, "fils_pmkid") == 0) {
9777 if (hexstr2bin(pos, fils_pmkid, PMKID_LEN) < 0)
9778 goto fail;
9779 ai->fils_pmkid = fils_pmkid;
9780 } else {
9781 goto fail;
9782 }
9783 }
9784
9785 wpa_supplicant_event(wpa_s, EVENT_ASSOC, &event);
9786 ret = 0;
9787 fail:
9788 wpabuf_free(req_ies);
9789 wpabuf_free(resp_ies);
9790 wpabuf_free(resp_frame);
9791 wpabuf_free(beacon_ies);
9792 wpabuf_free(key_replay_ctr);
9793 wpabuf_free(ptk_kck);
9794 wpabuf_free(ptk_kek);
9795 wpabuf_free(fils_pmk);
9796 return ret;
9797 }
9798
9799
wpas_ctrl_iface_driver_event(struct wpa_supplicant * wpa_s,char * cmd)9800 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
9801 {
9802 char *pos, *param;
9803 union wpa_event_data event;
9804 enum wpa_event_type ev;
9805
9806 /* <event name> [parameters..] */
9807
9808 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
9809
9810 pos = cmd;
9811 param = os_strchr(pos, ' ');
9812 if (param)
9813 *param++ = '\0';
9814
9815 os_memset(&event, 0, sizeof(event));
9816
9817 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
9818 ev = EVENT_INTERFACE_ENABLED;
9819 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
9820 ev = EVENT_INTERFACE_DISABLED;
9821 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
9822 ev = EVENT_AVOID_FREQUENCIES;
9823 if (param == NULL)
9824 param = "";
9825 if (freq_range_list_parse(&event.freq_range, param) < 0)
9826 return -1;
9827 wpa_supplicant_event(wpa_s, ev, &event);
9828 os_free(event.freq_range.range);
9829 return 0;
9830 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
9831 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
9832 } else if (os_strcmp(cmd, "ASSOC") == 0) {
9833 return wpas_ctrl_iface_driver_event_assoc(wpa_s, param);
9834 } else {
9835 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
9836 cmd);
9837 return -1;
9838 }
9839
9840 wpa_supplicant_event(wpa_s, ev, &event);
9841
9842 return 0;
9843 }
9844
9845
wpas_ctrl_iface_eapol_rx(struct wpa_supplicant * wpa_s,char * cmd)9846 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
9847 {
9848 char *pos;
9849 u8 src[ETH_ALEN], *buf;
9850 int used;
9851 size_t len;
9852
9853 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
9854
9855 pos = cmd;
9856 used = hwaddr_aton2(pos, src);
9857 if (used < 0)
9858 return -1;
9859 pos += used;
9860 while (*pos == ' ')
9861 pos++;
9862
9863 len = os_strlen(pos);
9864 if (len & 1)
9865 return -1;
9866 len /= 2;
9867
9868 buf = os_malloc(len);
9869 if (buf == NULL)
9870 return -1;
9871
9872 if (hexstr2bin(pos, buf, len) < 0) {
9873 os_free(buf);
9874 return -1;
9875 }
9876
9877 wpa_supplicant_rx_eapol(wpa_s, src, buf, len, FRAME_ENCRYPTION_UNKNOWN);
9878 os_free(buf);
9879
9880 return 0;
9881 }
9882
9883
wpas_ctrl_iface_eapol_tx(struct wpa_supplicant * wpa_s,char * cmd)9884 static int wpas_ctrl_iface_eapol_tx(struct wpa_supplicant *wpa_s, char *cmd)
9885 {
9886 char *pos;
9887 u8 dst[ETH_ALEN], *buf;
9888 int used, ret;
9889 size_t len;
9890 unsigned int prev;
9891
9892 wpa_printf(MSG_DEBUG, "External EAPOL TX: %s", cmd);
9893
9894 pos = cmd;
9895 used = hwaddr_aton2(pos, dst);
9896 if (used < 0)
9897 return -1;
9898 pos += used;
9899 while (*pos == ' ')
9900 pos++;
9901
9902 len = os_strlen(pos);
9903 if (len & 1)
9904 return -1;
9905 len /= 2;
9906
9907 buf = os_malloc(len);
9908 if (!buf || hexstr2bin(pos, buf, len) < 0) {
9909 os_free(buf);
9910 return -1;
9911 }
9912
9913 prev = wpa_s->ext_eapol_frame_io;
9914 wpa_s->ext_eapol_frame_io = 0;
9915 ret = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, buf, len);
9916 wpa_s->ext_eapol_frame_io = prev;
9917 os_free(buf);
9918
9919 return ret;
9920 }
9921
9922
ipv4_hdr_checksum(const void * buf,size_t len)9923 static u16 ipv4_hdr_checksum(const void *buf, size_t len)
9924 {
9925 size_t i;
9926 u32 sum = 0;
9927 const u16 *pos = buf;
9928
9929 for (i = 0; i < len / 2; i++)
9930 sum += *pos++;
9931
9932 while (sum >> 16)
9933 sum = (sum & 0xffff) + (sum >> 16);
9934
9935 return sum ^ 0xffff;
9936 }
9937
9938
9939 #define HWSIM_PACKETLEN 1500
9940 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
9941
wpas_data_test_rx(void * ctx,const u8 * src_addr,const u8 * buf,size_t len)9942 static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
9943 size_t len)
9944 {
9945 struct wpa_supplicant *wpa_s = ctx;
9946 const struct ether_header *eth;
9947 struct ip ip;
9948 const u8 *pos;
9949 unsigned int i;
9950 char extra[30];
9951
9952 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
9953 wpa_printf(MSG_DEBUG,
9954 "test data: RX - ignore unexpected length %d",
9955 (int) len);
9956 return;
9957 }
9958
9959 eth = (const struct ether_header *) buf;
9960 os_memcpy(&ip, eth + 1, sizeof(ip));
9961 pos = &buf[sizeof(*eth) + sizeof(ip)];
9962
9963 if (ip.ip_hl != 5 || ip.ip_v != 4 || ntohs(ip.ip_len) > HWSIM_IP_LEN) {
9964 wpa_printf(MSG_DEBUG,
9965 "test data: RX - ignore unexpected IP header");
9966 return;
9967 }
9968
9969 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
9970 if (*pos != (u8) i) {
9971 wpa_printf(MSG_DEBUG,
9972 "test data: RX - ignore mismatching payload");
9973 return;
9974 }
9975 pos++;
9976 }
9977 extra[0] = '\0';
9978 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
9979 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
9980 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
9981 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
9982 }
9983
9984
wpas_ctrl_iface_data_test_config(struct wpa_supplicant * wpa_s,char * cmd)9985 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
9986 char *cmd)
9987 {
9988 int enabled = atoi(cmd);
9989 char *pos;
9990 const char *ifname;
9991
9992 if (!enabled) {
9993 if (wpa_s->l2_test) {
9994 l2_packet_deinit(wpa_s->l2_test);
9995 wpa_s->l2_test = NULL;
9996 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
9997 }
9998 return 0;
9999 }
10000
10001 if (wpa_s->l2_test)
10002 return 0;
10003
10004 pos = os_strstr(cmd, " ifname=");
10005 if (pos)
10006 ifname = pos + 8;
10007 else
10008 ifname = wpa_s->ifname;
10009
10010 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
10011 ETHERTYPE_IP, wpas_data_test_rx,
10012 wpa_s, 1);
10013 if (wpa_s->l2_test == NULL)
10014 return -1;
10015
10016 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
10017
10018 return 0;
10019 }
10020
10021
wpas_ctrl_iface_data_test_tx(struct wpa_supplicant * wpa_s,char * cmd)10022 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
10023 {
10024 u8 dst[ETH_ALEN], src[ETH_ALEN];
10025 char *pos, *pos2;
10026 int used;
10027 long int val;
10028 u8 tos;
10029 u8 buf[2 + HWSIM_PACKETLEN];
10030 struct ether_header *eth;
10031 struct ip *ip;
10032 u8 *dpos;
10033 unsigned int i;
10034 size_t send_len = HWSIM_IP_LEN;
10035
10036 if (wpa_s->l2_test == NULL)
10037 return -1;
10038
10039 /* format: <dst> <src> <tos> [len=<length>] */
10040
10041 pos = cmd;
10042 used = hwaddr_aton2(pos, dst);
10043 if (used < 0)
10044 return -1;
10045 pos += used;
10046 while (*pos == ' ')
10047 pos++;
10048 used = hwaddr_aton2(pos, src);
10049 if (used < 0)
10050 return -1;
10051 pos += used;
10052
10053 val = strtol(pos, &pos2, 0);
10054 if (val < 0 || val > 0xff)
10055 return -1;
10056 tos = val;
10057
10058 pos = os_strstr(pos2, " len=");
10059 if (pos) {
10060 i = atoi(pos + 5);
10061 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
10062 return -1;
10063 send_len = i;
10064 }
10065
10066 eth = (struct ether_header *) &buf[2];
10067 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
10068 os_memcpy(eth->ether_shost, src, ETH_ALEN);
10069 eth->ether_type = htons(ETHERTYPE_IP);
10070 ip = (struct ip *) (eth + 1);
10071 os_memset(ip, 0, sizeof(*ip));
10072 ip->ip_hl = 5;
10073 ip->ip_v = 4;
10074 ip->ip_ttl = 64;
10075 ip->ip_tos = tos;
10076 ip->ip_len = htons(send_len);
10077 ip->ip_p = 1;
10078 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
10079 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
10080 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
10081 dpos = (u8 *) (ip + 1);
10082 for (i = 0; i < send_len - sizeof(*ip); i++)
10083 *dpos++ = i;
10084
10085 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
10086 sizeof(struct ether_header) + send_len) < 0)
10087 return -1;
10088
10089 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
10090 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
10091
10092 return 0;
10093 }
10094
10095
wpas_ctrl_iface_data_test_frame(struct wpa_supplicant * wpa_s,char * cmd)10096 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
10097 char *cmd)
10098 {
10099 u8 *buf;
10100 struct ether_header *eth;
10101 struct l2_packet_data *l2 = NULL;
10102 size_t len;
10103 u16 ethertype;
10104 int res = -1;
10105
10106 len = os_strlen(cmd);
10107 if (len & 1 || len < ETH_HLEN * 2)
10108 return -1;
10109 len /= 2;
10110
10111 buf = os_malloc(len);
10112 if (buf == NULL)
10113 return -1;
10114
10115 if (hexstr2bin(cmd, buf, len) < 0)
10116 goto done;
10117
10118 eth = (struct ether_header *) buf;
10119 ethertype = ntohs(eth->ether_type);
10120
10121 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
10122 wpas_data_test_rx, wpa_s, 1);
10123 if (l2 == NULL)
10124 goto done;
10125
10126 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
10127 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
10128 done:
10129 if (l2)
10130 l2_packet_deinit(l2);
10131 os_free(buf);
10132
10133 return res < 0 ? -1 : 0;
10134 }
10135
10136
wpas_ctrl_test_alloc_fail(struct wpa_supplicant * wpa_s,char * cmd)10137 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
10138 {
10139 #ifdef WPA_TRACE_BFD
10140 char *pos;
10141
10142 wpa_trace_fail_after = atoi(cmd);
10143 pos = os_strchr(cmd, ':');
10144 if (pos) {
10145 pos++;
10146 os_strlcpy(wpa_trace_fail_func, pos,
10147 sizeof(wpa_trace_fail_func));
10148 } else {
10149 wpa_trace_fail_after = 0;
10150 }
10151 return 0;
10152 #else /* WPA_TRACE_BFD */
10153 return -1;
10154 #endif /* WPA_TRACE_BFD */
10155 }
10156
10157
wpas_ctrl_get_alloc_fail(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)10158 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
10159 char *buf, size_t buflen)
10160 {
10161 #ifdef WPA_TRACE_BFD
10162 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
10163 wpa_trace_fail_func);
10164 #else /* WPA_TRACE_BFD */
10165 return -1;
10166 #endif /* WPA_TRACE_BFD */
10167 }
10168
10169
wpas_ctrl_test_fail(struct wpa_supplicant * wpa_s,char * cmd)10170 static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
10171 {
10172 #ifdef WPA_TRACE_BFD
10173 char *pos;
10174
10175 wpa_trace_test_fail_after = atoi(cmd);
10176 pos = os_strchr(cmd, ':');
10177 if (pos) {
10178 pos++;
10179 os_strlcpy(wpa_trace_test_fail_func, pos,
10180 sizeof(wpa_trace_test_fail_func));
10181 } else {
10182 wpa_trace_test_fail_after = 0;
10183 }
10184 return 0;
10185 #else /* WPA_TRACE_BFD */
10186 return -1;
10187 #endif /* WPA_TRACE_BFD */
10188 }
10189
10190
wpas_ctrl_get_fail(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)10191 static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
10192 char *buf, size_t buflen)
10193 {
10194 #ifdef WPA_TRACE_BFD
10195 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
10196 wpa_trace_test_fail_func);
10197 #else /* WPA_TRACE_BFD */
10198 return -1;
10199 #endif /* WPA_TRACE_BFD */
10200 }
10201
10202
wpas_ctrl_event_test_cb(void * eloop_ctx,void * timeout_ctx)10203 static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
10204 {
10205 struct wpa_supplicant *wpa_s = eloop_ctx;
10206 int i, count = (intptr_t) timeout_ctx;
10207
10208 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
10209 count);
10210 for (i = 0; i < count; i++) {
10211 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
10212 i + 1, count);
10213 }
10214 }
10215
10216
wpas_ctrl_event_test(struct wpa_supplicant * wpa_s,const char * cmd)10217 static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
10218 {
10219 int count;
10220
10221 count = atoi(cmd);
10222 if (count <= 0)
10223 return -1;
10224
10225 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
10226 (void *) (intptr_t) count);
10227 }
10228
10229
wpas_ctrl_test_assoc_ie(struct wpa_supplicant * wpa_s,const char * cmd)10230 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
10231 const char *cmd)
10232 {
10233 struct wpabuf *buf;
10234 size_t len;
10235
10236 len = os_strlen(cmd);
10237 if (len & 1)
10238 return -1;
10239 len /= 2;
10240
10241 if (len == 0) {
10242 buf = NULL;
10243 } else {
10244 buf = wpabuf_alloc(len);
10245 if (buf == NULL)
10246 return -1;
10247
10248 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
10249 wpabuf_free(buf);
10250 return -1;
10251 }
10252 }
10253
10254 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
10255 return 0;
10256 }
10257
10258
wpas_ctrl_reset_pn(struct wpa_supplicant * wpa_s)10259 static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
10260 {
10261 u8 zero[WPA_TK_MAX_LEN];
10262
10263 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
10264 return -1;
10265
10266 wpa_printf(MSG_INFO, "TESTING: Reset PN");
10267 os_memset(zero, 0, sizeof(zero));
10268
10269 /* First, use a zero key to avoid any possible duplicate key avoidance
10270 * in the driver. */
10271 if (wpa_drv_set_key(wpa_s, -1, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
10272 wpa_s->last_tk_key_idx, 1, zero, 6,
10273 zero, wpa_s->last_tk_len,
10274 KEY_FLAG_PAIRWISE_RX_TX) < 0)
10275 return -1;
10276
10277 /* Set the previously configured key to reset its TSC/RSC */
10278 return wpa_drv_set_key(wpa_s, -1, wpa_s->last_tk_alg,
10279 wpa_s->last_tk_addr,
10280 wpa_s->last_tk_key_idx, 1, zero, 6,
10281 wpa_s->last_tk, wpa_s->last_tk_len,
10282 KEY_FLAG_PAIRWISE_RX_TX);
10283 }
10284
10285
wpas_ctrl_key_request(struct wpa_supplicant * wpa_s,const char * cmd)10286 static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
10287 {
10288 const char *pos = cmd;
10289 int error, pairwise;
10290
10291 error = atoi(pos);
10292 pos = os_strchr(pos, ' ');
10293 if (!pos)
10294 return -1;
10295 pairwise = atoi(pos);
10296 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
10297 return 0;
10298 }
10299
10300
wpas_ctrl_resend_assoc(struct wpa_supplicant * wpa_s)10301 static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
10302 {
10303 #ifdef CONFIG_SME
10304 struct wpa_driver_associate_params params;
10305 int ret;
10306
10307 os_memset(¶ms, 0, sizeof(params));
10308 params.bssid = wpa_s->bssid;
10309 params.ssid = wpa_s->sme.ssid;
10310 params.ssid_len = wpa_s->sme.ssid_len;
10311 params.freq.freq = wpa_s->sme.freq;
10312 if (wpa_s->last_assoc_req_wpa_ie) {
10313 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
10314 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
10315 }
10316 params.pairwise_suite = wpa_s->pairwise_cipher;
10317 params.group_suite = wpa_s->group_cipher;
10318 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
10319 params.key_mgmt_suite = wpa_s->key_mgmt;
10320 params.wpa_proto = wpa_s->wpa_proto;
10321 params.mgmt_frame_protection = wpa_s->sme.mfp;
10322 params.rrm_used = wpa_s->rrm.rrm_used;
10323 if (wpa_s->sme.prev_bssid_set)
10324 params.prev_bssid = wpa_s->sme.prev_bssid;
10325 wpa_printf(MSG_INFO, "TESTING: Resend association request");
10326 ret = wpa_drv_associate(wpa_s, ¶ms);
10327 wpa_s->testing_resend_assoc = 1;
10328 return ret;
10329 #else /* CONFIG_SME */
10330 return -1;
10331 #endif /* CONFIG_SME */
10332 }
10333
10334
wpas_ctrl_iface_send_twt_setup(struct wpa_supplicant * wpa_s,const char * cmd)10335 static int wpas_ctrl_iface_send_twt_setup(struct wpa_supplicant *wpa_s,
10336 const char *cmd)
10337 {
10338 u8 dtok = 1;
10339 int exponent = 10;
10340 int mantissa = 8192;
10341 u8 min_twt = 255;
10342 unsigned long long twt = 0;
10343 bool requestor = true;
10344 int setup_cmd = 0;
10345 bool trigger = true;
10346 bool implicit = true;
10347 bool flow_type = true;
10348 int flow_id = 0;
10349 bool protection = false;
10350 u8 twt_channel = 0;
10351 u8 control = BIT(4); /* Control field (IEEE Std 802.11ax-2021,
10352 * Figure 9-687 - Control field format):
10353 * B4 = TWT Information Frame Disabled */
10354 const char *tok_s;
10355
10356 tok_s = os_strstr(cmd, " dialog=");
10357 if (tok_s)
10358 dtok = atoi(tok_s + os_strlen(" dialog="));
10359
10360 tok_s = os_strstr(cmd, " exponent=");
10361 if (tok_s)
10362 exponent = atoi(tok_s + os_strlen(" exponent="));
10363
10364 tok_s = os_strstr(cmd, " mantissa=");
10365 if (tok_s)
10366 mantissa = atoi(tok_s + os_strlen(" mantissa="));
10367
10368 tok_s = os_strstr(cmd, " min_twt=");
10369 if (tok_s)
10370 min_twt = atoi(tok_s + os_strlen(" min_twt="));
10371
10372 tok_s = os_strstr(cmd, " setup_cmd=");
10373 if (tok_s)
10374 setup_cmd = atoi(tok_s + os_strlen(" setup_cmd="));
10375
10376 tok_s = os_strstr(cmd, " twt=");
10377 if (tok_s &&
10378 sscanf(tok_s + os_strlen(" twt="), "%llu", &twt) != 1)
10379 return -1;
10380
10381 tok_s = os_strstr(cmd, " requestor=");
10382 if (tok_s)
10383 requestor = atoi(tok_s + os_strlen(" requestor="));
10384
10385 tok_s = os_strstr(cmd, " trigger=");
10386 if (tok_s)
10387 trigger = atoi(tok_s + os_strlen(" trigger="));
10388
10389 tok_s = os_strstr(cmd, " implicit=");
10390 if (tok_s)
10391 implicit = atoi(tok_s + os_strlen(" implicit="));
10392
10393 tok_s = os_strstr(cmd, " flow_type=");
10394 if (tok_s)
10395 flow_type = atoi(tok_s + os_strlen(" flow_type="));
10396
10397 tok_s = os_strstr(cmd, " flow_id=");
10398 if (tok_s)
10399 flow_id = atoi(tok_s + os_strlen(" flow_id="));
10400
10401 tok_s = os_strstr(cmd, " protection=");
10402 if (tok_s)
10403 protection = atoi(tok_s + os_strlen(" protection="));
10404
10405 tok_s = os_strstr(cmd, " twt_channel=");
10406 if (tok_s)
10407 twt_channel = atoi(tok_s + os_strlen(" twt_channel="));
10408
10409 tok_s = os_strstr(cmd, " control=");
10410 if (tok_s)
10411 control = atoi(tok_s + os_strlen(" control="));
10412
10413 return wpas_twt_send_setup(wpa_s, dtok, exponent, mantissa, min_twt,
10414 setup_cmd, twt, requestor, trigger, implicit,
10415 flow_type, flow_id, protection, twt_channel,
10416 control);
10417 }
10418
10419
wpas_ctrl_iface_send_twt_teardown(struct wpa_supplicant * wpa_s,const char * cmd)10420 static int wpas_ctrl_iface_send_twt_teardown(struct wpa_supplicant *wpa_s,
10421 const char *cmd)
10422 {
10423 u8 flags = 0x1;
10424 const char *tok_s;
10425
10426 tok_s = os_strstr(cmd, " flags=");
10427 if (tok_s)
10428 flags = atoi(tok_s + os_strlen(" flags="));
10429
10430 return wpas_twt_send_teardown(wpa_s, flags);
10431 }
10432
10433 #endif /* CONFIG_TESTING_OPTIONS */
10434
10435
wpas_ctrl_vendor_elem_add(struct wpa_supplicant * wpa_s,char * cmd)10436 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
10437 {
10438 char *pos = cmd;
10439 int frame;
10440 size_t len;
10441 struct wpabuf *buf;
10442 struct ieee802_11_elems elems;
10443
10444 frame = atoi(pos);
10445 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10446 return -1;
10447 wpa_s = wpas_vendor_elem(wpa_s, frame);
10448
10449 pos = os_strchr(pos, ' ');
10450 if (pos == NULL)
10451 return -1;
10452 pos++;
10453
10454 len = os_strlen(pos);
10455 if (len == 0)
10456 return 0;
10457 if (len & 1)
10458 return -1;
10459 len /= 2;
10460
10461 buf = wpabuf_alloc(len);
10462 if (buf == NULL)
10463 return -1;
10464
10465 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
10466 wpabuf_free(buf);
10467 return -1;
10468 }
10469
10470 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
10471 ParseFailed) {
10472 wpabuf_free(buf);
10473 return -1;
10474 }
10475
10476 if (wpa_s->vendor_elem[frame] == NULL) {
10477 wpa_s->vendor_elem[frame] = buf;
10478 goto update_ies;
10479 }
10480
10481 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
10482 wpabuf_free(buf);
10483 return -1;
10484 }
10485
10486 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
10487 wpabuf_free(buf);
10488
10489 update_ies:
10490 wpas_vendor_elem_update(wpa_s);
10491
10492 if (frame == VENDOR_ELEM_PROBE_REQ ||
10493 frame == VENDOR_ELEM_PROBE_REQ_P2P)
10494 wpa_supplicant_set_default_scan_ies(wpa_s);
10495
10496 return 0;
10497 }
10498
10499
wpas_ctrl_vendor_elem_get(struct wpa_supplicant * wpa_s,char * cmd,char * buf,size_t buflen)10500 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
10501 char *buf, size_t buflen)
10502 {
10503 int frame = atoi(cmd);
10504
10505 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10506 return -1;
10507 wpa_s = wpas_vendor_elem(wpa_s, frame);
10508
10509 if (wpa_s->vendor_elem[frame] == NULL)
10510 return 0;
10511
10512 return wpa_snprintf_hex(buf, buflen,
10513 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
10514 wpabuf_len(wpa_s->vendor_elem[frame]));
10515 }
10516
10517
wpas_ctrl_vendor_elem_remove(struct wpa_supplicant * wpa_s,char * cmd)10518 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
10519 {
10520 char *pos = cmd;
10521 int frame;
10522 size_t len;
10523 u8 *buf;
10524 struct ieee802_11_elems elems;
10525 int res;
10526
10527 frame = atoi(pos);
10528 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10529 return -1;
10530 wpa_s = wpas_vendor_elem(wpa_s, frame);
10531
10532 pos = os_strchr(pos, ' ');
10533 if (pos == NULL)
10534 return -1;
10535 pos++;
10536
10537 if (*pos == '*') {
10538 wpabuf_free(wpa_s->vendor_elem[frame]);
10539 wpa_s->vendor_elem[frame] = NULL;
10540 wpas_vendor_elem_update(wpa_s);
10541 return 0;
10542 }
10543
10544 if (wpa_s->vendor_elem[frame] == NULL)
10545 return -1;
10546
10547 len = os_strlen(pos);
10548 if (len == 0)
10549 return 0;
10550 if (len & 1)
10551 return -1;
10552 len /= 2;
10553
10554 buf = os_malloc(len);
10555 if (buf == NULL)
10556 return -1;
10557
10558 if (hexstr2bin(pos, buf, len) < 0) {
10559 os_free(buf);
10560 return -1;
10561 }
10562
10563 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
10564 os_free(buf);
10565 return -1;
10566 }
10567
10568 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
10569 os_free(buf);
10570 return res;
10571 }
10572
10573
wpas_ctrl_neighbor_rep_cb(void * ctx,struct wpabuf * neighbor_rep)10574 static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
10575 {
10576 struct wpa_supplicant *wpa_s = ctx;
10577 size_t len;
10578 const u8 *data;
10579
10580 /*
10581 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
10582 * BSSID[6]
10583 * BSSID Information[4]
10584 * Operating Class[1]
10585 * Channel Number[1]
10586 * PHY Type[1]
10587 * Optional Subelements[variable]
10588 */
10589 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
10590
10591 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
10592 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
10593 goto out;
10594 }
10595
10596 data = wpabuf_head_u8(neighbor_rep);
10597 len = wpabuf_len(neighbor_rep);
10598
10599 while (len >= 2 + NR_IE_MIN_LEN) {
10600 const u8 *nr;
10601 char lci[256 * 2 + 1];
10602 char civic[256 * 2 + 1];
10603 u8 nr_len = data[1];
10604 const u8 *pos = data, *end;
10605
10606 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
10607 nr_len < NR_IE_MIN_LEN) {
10608 wpa_dbg(wpa_s, MSG_DEBUG,
10609 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
10610 data[0], nr_len);
10611 goto out;
10612 }
10613
10614 if (2U + nr_len > len) {
10615 wpa_dbg(wpa_s, MSG_DEBUG,
10616 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
10617 data[0], len, nr_len);
10618 goto out;
10619 }
10620 pos += 2;
10621 end = pos + nr_len;
10622
10623 nr = pos;
10624 pos += NR_IE_MIN_LEN;
10625
10626 lci[0] = '\0';
10627 civic[0] = '\0';
10628 while (end - pos > 2) {
10629 u8 s_id, s_len;
10630
10631 s_id = *pos++;
10632 s_len = *pos++;
10633 if (s_len > end - pos)
10634 goto out;
10635 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
10636 /* Measurement Token[1] */
10637 /* Measurement Report Mode[1] */
10638 /* Measurement Type[1] */
10639 /* Measurement Report[variable] */
10640 switch (pos[2]) {
10641 case MEASURE_TYPE_LCI:
10642 if (lci[0])
10643 break;
10644 wpa_snprintf_hex(lci, sizeof(lci),
10645 pos, s_len);
10646 break;
10647 case MEASURE_TYPE_LOCATION_CIVIC:
10648 if (civic[0])
10649 break;
10650 wpa_snprintf_hex(civic, sizeof(civic),
10651 pos, s_len);
10652 break;
10653 }
10654 }
10655
10656 pos += s_len;
10657 }
10658
10659 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
10660 "bssid=" MACSTR
10661 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
10662 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
10663 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
10664 nr[ETH_ALEN + 6],
10665 lci[0] ? " lci=" : "", lci,
10666 civic[0] ? " civic=" : "", civic);
10667
10668 data = end;
10669 len -= 2 + nr_len;
10670 }
10671
10672 out:
10673 wpabuf_free(neighbor_rep);
10674 }
10675
10676
wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant * wpa_s,char * cmd)10677 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
10678 char *cmd)
10679 {
10680 struct wpa_ssid_value ssid, *ssid_p = NULL;
10681 int ret, lci = 0, civic = 0;
10682 char *ssid_s;
10683
10684 ssid_s = os_strstr(cmd, "ssid=");
10685 if (ssid_s) {
10686 if (ssid_parse(ssid_s + 5, &ssid)) {
10687 wpa_msg(wpa_s, MSG_INFO,
10688 "CTRL: Send Neighbor Report: bad SSID");
10689 return -1;
10690 }
10691
10692 ssid_p = &ssid;
10693
10694 /*
10695 * Move cmd after the SSID text that may include "lci" or
10696 * "civic".
10697 */
10698 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
10699 if (cmd)
10700 cmd++;
10701
10702 }
10703
10704 if (cmd && os_strstr(cmd, "lci"))
10705 lci = 1;
10706
10707 if (cmd && os_strstr(cmd, "civic"))
10708 civic = 1;
10709
10710 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
10711 wpas_ctrl_neighbor_rep_cb,
10712 wpa_s);
10713
10714 return ret;
10715 }
10716
10717
wpas_ctrl_iface_erp_flush(struct wpa_supplicant * wpa_s)10718 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
10719 {
10720 eapol_sm_erp_flush(wpa_s->eapol);
10721 return 0;
10722 }
10723
10724
wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant * wpa_s,char * cmd)10725 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
10726 char *cmd)
10727 {
10728 char *token, *context = NULL;
10729 unsigned int enable = ~0, type = 0;
10730 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
10731 u8 *addr = NULL, *mask = NULL;
10732
10733 while ((token = str_token(cmd, " ", &context))) {
10734 if (os_strcasecmp(token, "scan") == 0) {
10735 type |= MAC_ADDR_RAND_SCAN;
10736 } else if (os_strcasecmp(token, "sched") == 0) {
10737 type |= MAC_ADDR_RAND_SCHED_SCAN;
10738 } else if (os_strcasecmp(token, "pno") == 0) {
10739 type |= MAC_ADDR_RAND_PNO;
10740 } else if (os_strcasecmp(token, "all") == 0) {
10741 type = wpa_s->mac_addr_rand_supported;
10742 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
10743 enable = atoi(token + 7);
10744 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
10745 addr = _addr;
10746 if (hwaddr_aton(token + 5, addr)) {
10747 wpa_printf(MSG_INFO,
10748 "CTRL: Invalid MAC address: %s",
10749 token);
10750 return -1;
10751 }
10752 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
10753 mask = _mask;
10754 if (hwaddr_aton(token + 5, mask)) {
10755 wpa_printf(MSG_INFO,
10756 "CTRL: Invalid MAC address mask: %s",
10757 token);
10758 return -1;
10759 }
10760 } else {
10761 wpa_printf(MSG_INFO,
10762 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
10763 token);
10764 return -1;
10765 }
10766 }
10767
10768 if (!type) {
10769 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
10770 return -1;
10771 }
10772
10773 if (enable > 1) {
10774 wpa_printf(MSG_INFO,
10775 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
10776 return -1;
10777 }
10778
10779 if (!enable)
10780 return wpas_disable_mac_addr_randomization(wpa_s, type);
10781
10782 return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask);
10783 }
10784
10785
wpas_ctrl_iface_pmksa(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)10786 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
10787 char *buf, size_t buflen)
10788 {
10789 size_t reply_len;
10790
10791 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
10792 #ifdef CONFIG_AP
10793 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
10794 buflen - reply_len);
10795 #endif /* CONFIG_AP */
10796 return reply_len;
10797 }
10798
10799
wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant * wpa_s)10800 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
10801 {
10802 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
10803 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
10804 #ifdef CONFIG_AP
10805 wpas_ap_pmksa_cache_flush(wpa_s);
10806 #endif /* CONFIG_AP */
10807 }
10808
10809
10810 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10811
wpas_ctrl_iface_pmksa_get(struct wpa_supplicant * wpa_s,const char * cmd,char * buf,size_t buflen)10812 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
10813 const char *cmd, char *buf, size_t buflen)
10814 {
10815 struct rsn_pmksa_cache_entry *entry;
10816 struct wpa_ssid *ssid;
10817 char *pos, *pos2, *end;
10818 int ret;
10819 struct os_reltime now;
10820
10821 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10822 if (!ssid)
10823 return -1;
10824
10825 pos = buf;
10826 end = buf + buflen;
10827
10828 os_get_reltime(&now);
10829
10830 /*
10831 * Entry format:
10832 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10833 * <expiration in seconds> <akmp> <opportunistic>
10834 * [FILS Cache Identifier]
10835 */
10836
10837 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
10838 entry = entry->next) {
10839 if (entry->network_ctx != ssid)
10840 continue;
10841
10842 pos2 = pos;
10843 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
10844 MAC2STR(entry->aa));
10845 if (os_snprintf_error(end - pos2, ret))
10846 break;
10847 pos2 += ret;
10848
10849 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
10850 PMKID_LEN);
10851
10852 ret = os_snprintf(pos2, end - pos2, " ");
10853 if (os_snprintf_error(end - pos2, ret))
10854 break;
10855 pos2 += ret;
10856
10857 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
10858 entry->pmk_len);
10859
10860 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
10861 (int) (entry->reauth_time - now.sec),
10862 (int) (entry->expiration - now.sec),
10863 entry->akmp,
10864 entry->opportunistic);
10865 if (os_snprintf_error(end - pos2, ret))
10866 break;
10867 pos2 += ret;
10868
10869 if (entry->fils_cache_id_set) {
10870 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
10871 entry->fils_cache_id[0],
10872 entry->fils_cache_id[1]);
10873 if (os_snprintf_error(end - pos2, ret))
10874 break;
10875 pos2 += ret;
10876 }
10877
10878 ret = os_snprintf(pos2, end - pos2, "\n");
10879 if (os_snprintf_error(end - pos2, ret))
10880 break;
10881 pos2 += ret;
10882
10883 pos = pos2;
10884 }
10885
10886 return pos - buf;
10887 }
10888
10889
wpas_ctrl_iface_pmksa_add(struct wpa_supplicant * wpa_s,char * cmd)10890 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
10891 char *cmd)
10892 {
10893 struct rsn_pmksa_cache_entry *entry;
10894 struct wpa_ssid *ssid;
10895 char *pos, *pos2;
10896 int ret = -1;
10897 struct os_reltime now;
10898 int reauth_time = 0, expiration = 0, i;
10899
10900 /*
10901 * Entry format:
10902 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10903 * <expiration in seconds> <akmp> <opportunistic>
10904 * [FILS Cache Identifier]
10905 */
10906
10907 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10908 if (!ssid)
10909 return -1;
10910
10911 pos = os_strchr(cmd, ' ');
10912 if (!pos)
10913 return -1;
10914 pos++;
10915
10916 entry = os_zalloc(sizeof(*entry));
10917 if (!entry)
10918 return -1;
10919
10920 if (hwaddr_aton(pos, entry->aa))
10921 goto fail;
10922
10923 pos = os_strchr(pos, ' ');
10924 if (!pos)
10925 goto fail;
10926 pos++;
10927
10928 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
10929 goto fail;
10930
10931 pos = os_strchr(pos, ' ');
10932 if (!pos)
10933 goto fail;
10934 pos++;
10935
10936 pos2 = os_strchr(pos, ' ');
10937 if (!pos2)
10938 goto fail;
10939 entry->pmk_len = (pos2 - pos) / 2;
10940 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
10941 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
10942 goto fail;
10943
10944 pos = os_strchr(pos, ' ');
10945 if (!pos)
10946 goto fail;
10947 pos++;
10948
10949 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
10950 &entry->akmp, &entry->opportunistic) != 4)
10951 goto fail;
10952 if (reauth_time > expiration)
10953 goto fail;
10954 for (i = 0; i < 4; i++) {
10955 pos = os_strchr(pos, ' ');
10956 if (!pos) {
10957 if (i < 3)
10958 goto fail;
10959 break;
10960 }
10961 pos++;
10962 }
10963 if (pos) {
10964 if (hexstr2bin(pos, entry->fils_cache_id,
10965 FILS_CACHE_ID_LEN) < 0)
10966 goto fail;
10967 entry->fils_cache_id_set = 1;
10968 }
10969 os_get_reltime(&now);
10970 entry->expiration = now.sec + expiration;
10971 entry->reauth_time = now.sec + reauth_time;
10972
10973 entry->network_ctx = ssid;
10974 os_memcpy(entry->spa, wpa_s->own_addr, ETH_ALEN);
10975
10976 entry->external = true;
10977
10978 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
10979 entry = NULL;
10980 ret = 0;
10981 fail:
10982 os_free(entry);
10983 return ret;
10984 }
10985
10986
10987 #ifdef CONFIG_MESH
10988
wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant * wpa_s,const char * cmd,char * buf,size_t buflen)10989 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
10990 const char *cmd, char *buf,
10991 size_t buflen)
10992 {
10993 u8 spa[ETH_ALEN];
10994
10995 if (!wpa_s->ifmsh)
10996 return -1;
10997
10998 if (os_strcasecmp(cmd, "any") == 0)
10999 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
11000
11001 if (hwaddr_aton(cmd, spa))
11002 return -1;
11003
11004 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
11005 }
11006
11007
wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant * wpa_s,char * cmd)11008 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
11009 char *cmd)
11010 {
11011 /*
11012 * We do not check mesh interface existence because PMKSA should be
11013 * stored before wpa_s->ifmsh creation to suppress commit message
11014 * creation.
11015 */
11016 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
11017 }
11018
11019 #endif /* CONFIG_MESH */
11020 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
11021
11022
11023 #ifdef CONFIG_FILS
wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant * wpa_s,const char * cmd)11024 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
11025 const char *cmd)
11026 {
11027 struct fils_hlp_req *req;
11028 const char *pos;
11029
11030 /* format: <dst> <packet starting from ethertype> */
11031
11032 req = os_zalloc(sizeof(*req));
11033 if (!req)
11034 return -1;
11035
11036 if (hwaddr_aton(cmd, req->dst))
11037 goto fail;
11038
11039 pos = os_strchr(cmd, ' ');
11040 if (!pos)
11041 goto fail;
11042 pos++;
11043 req->pkt = wpabuf_parse_bin(pos);
11044 if (!req->pkt)
11045 goto fail;
11046
11047 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
11048 return 0;
11049 fail:
11050 wpabuf_free(req->pkt);
11051 os_free(req);
11052 return -1;
11053 }
11054 #endif /* CONFIG_FILS */
11055
11056
wpas_ctrl_cmd_debug_level(const char * cmd)11057 int wpas_ctrl_cmd_debug_level(const char *cmd)
11058 {
11059 if (os_strcmp(cmd, "PING") == 0 ||
11060 os_strncmp(cmd, "BSS ", 4) == 0 ||
11061 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
11062 os_strncmp(cmd, "STATUS", 6) == 0 ||
11063 os_strncmp(cmd, "STA ", 4) == 0 ||
11064 os_strncmp(cmd, "STA-", 4) == 0)
11065 return MSG_EXCESSIVE;
11066 return MSG_DEBUG;
11067 }
11068
11069
wpas_ctrl_iface_configure_mscs(struct wpa_supplicant * wpa_s,const char * cmd)11070 static int wpas_ctrl_iface_configure_mscs(struct wpa_supplicant *wpa_s,
11071 const char *cmd)
11072 {
11073 size_t frame_classifier_len;
11074 const char *pos, *end;
11075 struct robust_av_data *robust_av = &wpa_s->robust_av;
11076 int val;
11077
11078 /*
11079 * format:
11080 * <add|remove|change> [up_bitmap=<hex byte>] [up_limit=<integer>]
11081 * [stream_timeout=<in TUs>] [frame_classifier=<hex bytes>]
11082 */
11083 os_memset(robust_av, 0, sizeof(struct robust_av_data));
11084 if (os_strncmp(cmd, "add ", 4) == 0) {
11085 robust_av->request_type = SCS_REQ_ADD;
11086 } else if (os_strcmp(cmd, "remove") == 0) {
11087 robust_av->request_type = SCS_REQ_REMOVE;
11088 robust_av->valid_config = false;
11089 return wpas_send_mscs_req(wpa_s);
11090 } else if (os_strncmp(cmd, "change ", 7) == 0) {
11091 robust_av->request_type = SCS_REQ_CHANGE;
11092 } else {
11093 return -1;
11094 }
11095
11096 pos = os_strstr(cmd, "up_bitmap=");
11097 if (!pos)
11098 return -1;
11099
11100 val = hex2byte(pos + 10);
11101 if (val < 0)
11102 return -1;
11103 robust_av->up_bitmap = val;
11104
11105 pos = os_strstr(cmd, "up_limit=");
11106 if (!pos)
11107 return -1;
11108
11109 robust_av->up_limit = atoi(pos + 9);
11110
11111 pos = os_strstr(cmd, "stream_timeout=");
11112 if (!pos)
11113 return -1;
11114
11115 robust_av->stream_timeout = atoi(pos + 15);
11116 if (robust_av->stream_timeout == 0)
11117 return -1;
11118
11119 pos = os_strstr(cmd, "frame_classifier=");
11120 if (!pos)
11121 return -1;
11122
11123 pos += 17;
11124 end = os_strchr(pos, ' ');
11125 if (!end)
11126 end = pos + os_strlen(pos);
11127
11128 frame_classifier_len = (end - pos) / 2;
11129 if (frame_classifier_len > sizeof(robust_av->frame_classifier) ||
11130 hexstr2bin(pos, robust_av->frame_classifier, frame_classifier_len))
11131 return -1;
11132
11133 robust_av->frame_classifier_len = frame_classifier_len;
11134 robust_av->valid_config = true;
11135
11136 return wpas_send_mscs_req(wpa_s);
11137 }
11138
11139
11140 #ifdef CONFIG_PASN
wpas_ctrl_iface_pasn_start(struct wpa_supplicant * wpa_s,char * cmd)11141 static int wpas_ctrl_iface_pasn_start(struct wpa_supplicant *wpa_s, char *cmd)
11142 {
11143 char *token, *context = NULL;
11144 u8 bssid[ETH_ALEN];
11145 int akmp = -1, cipher = -1, got_bssid = 0;
11146 u16 group = 0xFFFF;
11147 u8 *comeback = NULL;
11148 size_t comeback_len = 0;
11149 int id = 0, ret = -1;
11150
11151 /*
11152 * Entry format: bssid=<BSSID> akmp=<AKMP> cipher=<CIPHER> group=<group>
11153 * [comeback=<hexdump>]
11154 */
11155 while ((token = str_token(cmd, " ", &context))) {
11156 if (os_strncmp(token, "bssid=", 6) == 0) {
11157 if (hwaddr_aton(token + 6, bssid))
11158 goto out;
11159 got_bssid = 1;
11160 } else if (os_strcmp(token, "akmp=PASN") == 0) {
11161 akmp = WPA_KEY_MGMT_PASN;
11162 #ifdef CONFIG_IEEE80211R
11163 } else if (os_strcmp(token, "akmp=FT-PSK") == 0) {
11164 akmp = WPA_KEY_MGMT_FT_PSK;
11165 } else if (os_strcmp(token, "akmp=FT-EAP-SHA384") == 0) {
11166 akmp = WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
11167 } else if (os_strcmp(token, "akmp=FT-EAP") == 0) {
11168 akmp = WPA_KEY_MGMT_FT_IEEE8021X;
11169 #endif /* CONFIG_IEEE80211R */
11170 #ifdef CONFIG_SAE
11171 } else if (os_strcmp(token, "akmp=SAE") == 0) {
11172 akmp = WPA_KEY_MGMT_SAE;
11173 } else if (os_strcmp(token, "akmp=SAE-EXT-KEY") == 0) {
11174 akmp = WPA_KEY_MGMT_SAE_EXT_KEY;
11175 #endif /* CONFIG_SAE */
11176 #ifdef CONFIG_FILS
11177 } else if (os_strcmp(token, "akmp=FILS-SHA256") == 0) {
11178 akmp = WPA_KEY_MGMT_FILS_SHA256;
11179 } else if (os_strcmp(token, "akmp=FILS-SHA384") == 0) {
11180 akmp = WPA_KEY_MGMT_FILS_SHA384;
11181 #endif /* CONFIG_FILS */
11182 } else if (os_strcmp(token, "cipher=CCMP-256") == 0) {
11183 cipher = WPA_CIPHER_CCMP_256;
11184 } else if (os_strcmp(token, "cipher=GCMP-256") == 0) {
11185 cipher = WPA_CIPHER_GCMP_256;
11186 } else if (os_strcmp(token, "cipher=CCMP") == 0) {
11187 cipher = WPA_CIPHER_CCMP;
11188 } else if (os_strcmp(token, "cipher=GCMP") == 0) {
11189 cipher = WPA_CIPHER_GCMP;
11190 } else if (os_strncmp(token, "group=", 6) == 0) {
11191 group = atoi(token + 6);
11192 } else if (os_strncmp(token, "nid=", 4) == 0) {
11193 id = atoi(token + 4);
11194 } else if (os_strncmp(token, "comeback=", 9) == 0) {
11195 comeback_len = os_strlen(token + 9);
11196 if (comeback || !comeback_len || comeback_len % 2)
11197 goto out;
11198
11199 comeback_len /= 2;
11200 comeback = os_malloc(comeback_len);
11201 if (!comeback ||
11202 hexstr2bin(token + 9, comeback, comeback_len))
11203 goto out;
11204 } else {
11205 wpa_printf(MSG_DEBUG,
11206 "CTRL: PASN Invalid parameter: '%s'",
11207 token);
11208 goto out;
11209 }
11210 }
11211
11212 if (!got_bssid || akmp == -1 || cipher == -1 || group == 0xFFFF) {
11213 wpa_printf(MSG_DEBUG,"CTRL: PASN missing parameter");
11214 goto out;
11215 }
11216
11217 ret = wpas_pasn_auth_start(wpa_s, wpa_s->own_addr, bssid, akmp, cipher,
11218 group, id, comeback, comeback_len);
11219 out:
11220 os_free(comeback);
11221 return ret;
11222 }
11223
11224
wpas_ctrl_iface_pasn_deauthenticate(struct wpa_supplicant * wpa_s,const char * cmd)11225 static int wpas_ctrl_iface_pasn_deauthenticate(struct wpa_supplicant *wpa_s,
11226 const char *cmd)
11227 {
11228 u8 bssid[ETH_ALEN];
11229
11230 if (os_strncmp(cmd, "bssid=", 6) != 0 || hwaddr_aton(cmd + 6, bssid)) {
11231 wpa_printf(MSG_DEBUG,
11232 "CTRL: PASN_DEAUTH without valid BSSID");
11233 return -1;
11234 }
11235
11236 return wpas_pasn_deauthenticate(wpa_s, wpa_s->own_addr, bssid);
11237 }
11238
11239 #endif /* CONFIG_PASN */
11240
11241
set_type4_frame_classifier(const char * cmd,struct type4_params * param)11242 static int set_type4_frame_classifier(const char *cmd,
11243 struct type4_params *param)
11244 {
11245 const char *pos, *end;
11246 u8 classifier_mask = 0;
11247 int ret;
11248 char addr[INET6_ADDRSTRLEN];
11249 size_t alen;
11250
11251 if (os_strstr(cmd, "ip_version=ipv4")) {
11252 param->ip_version = IPV4;
11253 } else if (os_strstr(cmd, "ip_version=ipv6")) {
11254 param->ip_version = IPV6;
11255 } else {
11256 wpa_printf(MSG_ERROR, "IP version missing/invalid");
11257 return -1;
11258 }
11259
11260 classifier_mask |= BIT(0);
11261
11262 pos = os_strstr(cmd, "src_ip=");
11263 if (pos) {
11264 pos += 7;
11265 end = os_strchr(pos, ' ');
11266 if (!end)
11267 end = pos + os_strlen(pos);
11268
11269 alen = end - pos;
11270 if (alen >= INET6_ADDRSTRLEN)
11271 return -1;
11272 os_memcpy(addr, pos, alen);
11273 addr[alen] = '\0';
11274 if (param->ip_version == IPV4)
11275 ret = inet_pton(AF_INET, addr,
11276 ¶m->ip_params.v4.src_ip);
11277 else
11278 ret = inet_pton(AF_INET6, addr,
11279 ¶m->ip_params.v6.src_ip);
11280
11281 if (ret != 1) {
11282 wpa_printf(MSG_ERROR,
11283 "Error converting src IP address to binary ret=%d",
11284 ret);
11285 return -1;
11286 }
11287
11288 classifier_mask |= BIT(1);
11289 }
11290
11291 pos = os_strstr(cmd, "dst_ip=");
11292 if (pos) {
11293 pos += 7;
11294 end = os_strchr(pos, ' ');
11295 if (!end)
11296 end = pos + os_strlen(pos);
11297
11298 alen = end - pos;
11299 if (alen >= INET6_ADDRSTRLEN)
11300 return -1;
11301 os_memcpy(addr, pos, alen);
11302 addr[alen] = '\0';
11303 if (param->ip_version == IPV4)
11304 ret = inet_pton(AF_INET, addr,
11305 ¶m->ip_params.v4.dst_ip);
11306 else
11307 ret = inet_pton(AF_INET6, addr,
11308 ¶m->ip_params.v6.dst_ip);
11309
11310 if (ret != 1) {
11311 wpa_printf(MSG_ERROR,
11312 "Error converting dst IP address to binary ret=%d",
11313 ret);
11314 return -1;
11315 }
11316
11317 classifier_mask |= BIT(2);
11318 }
11319
11320 pos = os_strstr(cmd, "src_port=");
11321 if (pos && atoi(pos + 9) > 0) {
11322 if (param->ip_version == IPV4)
11323 param->ip_params.v4.src_port = atoi(pos + 9);
11324 else
11325 param->ip_params.v6.src_port = atoi(pos + 9);
11326 classifier_mask |= BIT(3);
11327 }
11328
11329 pos = os_strstr(cmd, "dst_port=");
11330 if (pos && atoi(pos + 9) > 0) {
11331 if (param->ip_version == IPV4)
11332 param->ip_params.v4.dst_port = atoi(pos + 9);
11333 else
11334 param->ip_params.v6.dst_port = atoi(pos + 9);
11335 classifier_mask |= BIT(4);
11336 }
11337
11338 pos = os_strstr(cmd, "dscp=");
11339 if (pos && atoi(pos + 5) > 0) {
11340 if (param->ip_version == IPV4)
11341 param->ip_params.v4.dscp = atoi(pos + 5);
11342 else
11343 param->ip_params.v6.dscp = atoi(pos + 5);
11344 classifier_mask |= BIT(5);
11345 }
11346
11347 if (param->ip_version == IPV4) {
11348 pos = os_strstr(cmd, "protocol=");
11349 if (pos) {
11350 if (os_strstr(pos, "udp")) {
11351 param->ip_params.v4.protocol = 17;
11352 } else if (os_strstr(pos, "tcp")) {
11353 param->ip_params.v4.protocol = 6;
11354 } else if (os_strstr(pos, "esp")) {
11355 param->ip_params.v4.protocol = 50;
11356 } else {
11357 wpa_printf(MSG_ERROR, "Invalid protocol");
11358 return -1;
11359 }
11360 classifier_mask |= BIT(6);
11361 }
11362 } else {
11363 pos = os_strstr(cmd, "next_header=");
11364 if (pos) {
11365 if (os_strstr(pos, "udp")) {
11366 param->ip_params.v6.next_header = 17;
11367 } else if (os_strstr(pos, "tcp")) {
11368 param->ip_params.v6.next_header = 6;
11369 } else if (os_strstr(pos, "esp")) {
11370 param->ip_params.v6.next_header = 50;
11371 } else {
11372 wpa_printf(MSG_ERROR, "Invalid next header");
11373 return -1;
11374 }
11375
11376 classifier_mask |= BIT(6);
11377 }
11378
11379 pos = os_strstr(cmd, "flow_label=");
11380 if (pos) {
11381 pos += 11;
11382 end = os_strchr(pos, ' ');
11383 if (!end)
11384 end = pos + os_strlen(pos);
11385
11386 if (end - pos != 6 ||
11387 hexstr2bin(pos, param->ip_params.v6.flow_label,
11388 3) ||
11389 param->ip_params.v6.flow_label[0] > 0x0F) {
11390 wpa_printf(MSG_ERROR, "Invalid flow label");
11391 return -1;
11392 }
11393
11394 classifier_mask |= BIT(7);
11395 }
11396 }
11397
11398 param->classifier_mask = classifier_mask;
11399 return 0;
11400 }
11401
11402
set_type10_frame_classifier(const char * cmd,struct type10_params * param)11403 static int set_type10_frame_classifier(const char *cmd,
11404 struct type10_params *param)
11405 {
11406 const char *pos, *end;
11407 size_t filter_len;
11408
11409 pos = os_strstr(cmd, "prot_instance=");
11410 if (!pos) {
11411 wpa_printf(MSG_ERROR, "Protocol instance missing");
11412 return -1;
11413 }
11414 param->prot_instance = atoi(pos + 14);
11415
11416 pos = os_strstr(cmd, "prot_number=");
11417 if (!pos) {
11418 wpa_printf(MSG_ERROR, "Protocol number missing");
11419 return -1;
11420 }
11421 if (os_strstr(pos, "udp")) {
11422 param->prot_number = 17;
11423 } else if (os_strstr(pos, "tcp")) {
11424 param->prot_number = 6;
11425 } else if (os_strstr(pos, "esp")) {
11426 param->prot_number = 50;
11427 } else {
11428 wpa_printf(MSG_ERROR, "Invalid protocol number");
11429 return -1;
11430 }
11431
11432 pos = os_strstr(cmd, "filter_value=");
11433 if (!pos) {
11434 wpa_printf(MSG_ERROR,
11435 "Classifier parameter filter_value missing");
11436 return -1;
11437 }
11438
11439 pos += 13;
11440 end = os_strchr(pos, ' ');
11441 if (!end)
11442 end = pos + os_strlen(pos);
11443
11444 filter_len = (end - pos) / 2;
11445 param->filter_value = os_malloc(filter_len);
11446 if (!param->filter_value)
11447 return -1;
11448
11449 if (hexstr2bin(pos, param->filter_value, filter_len)) {
11450 wpa_printf(MSG_ERROR, "Invalid filter_value %s", pos);
11451 goto free;
11452 }
11453
11454 pos = os_strstr(cmd, "filter_mask=");
11455 if (!pos) {
11456 wpa_printf(MSG_ERROR,
11457 "Classifier parameter filter_mask missing");
11458 goto free;
11459 }
11460
11461 pos += 12;
11462 end = os_strchr(pos, ' ');
11463 if (!end)
11464 end = pos + os_strlen(pos);
11465
11466 if (filter_len != (size_t) (end - pos) / 2) {
11467 wpa_printf(MSG_ERROR,
11468 "Filter mask length mismatch expected=%zu received=%zu",
11469 filter_len, (size_t) (end - pos) / 2);
11470 goto free;
11471 }
11472
11473 param->filter_mask = os_malloc(filter_len);
11474 if (!param->filter_mask)
11475 goto free;
11476
11477 if (hexstr2bin(pos, param->filter_mask, filter_len)) {
11478 wpa_printf(MSG_ERROR, "Invalid filter mask %s", pos);
11479 os_free(param->filter_mask);
11480 param->filter_mask = NULL;
11481 goto free;
11482 }
11483
11484 param->filter_len = filter_len;
11485 return 0;
11486 free:
11487 os_free(param->filter_value);
11488 param->filter_value = NULL;
11489 return -1;
11490 }
11491
11492
scs_parse_type4(struct tclas_element * elem,const char * pos)11493 static int scs_parse_type4(struct tclas_element *elem, const char *pos)
11494 {
11495 struct type4_params type4_param = { 0 };
11496
11497 if (set_type4_frame_classifier(pos, &type4_param) == -1) {
11498 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 4");
11499 return -1;
11500 }
11501
11502 os_memcpy(&elem->frame_classifier.type4_param,
11503 &type4_param, sizeof(struct type4_params));
11504 return 0;
11505 }
11506
11507
scs_parse_type10(struct tclas_element * elem,const char * pos)11508 static int scs_parse_type10(struct tclas_element *elem, const char *pos)
11509 {
11510 struct type10_params type10_param = { 0 };
11511
11512 if (set_type10_frame_classifier(pos, &type10_param) == -1) {
11513 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 10");
11514 return -1;
11515 }
11516
11517 os_memcpy(&elem->frame_classifier.type10_param,
11518 &type10_param, sizeof(struct type10_params));
11519 return 0;
11520 }
11521
11522
wpas_ctrl_iface_configure_scs(struct wpa_supplicant * wpa_s,char * cmd)11523 static int wpas_ctrl_iface_configure_scs(struct wpa_supplicant *wpa_s,
11524 char *cmd)
11525 {
11526 char *pos1, *pos;
11527 struct scs_robust_av_data *scs_data = &wpa_s->scs_robust_av_req;
11528 struct scs_desc_elem desc_elem = { 0 };
11529 int val;
11530 unsigned int num_scs_desc = 0;
11531
11532 if (wpa_s->ongoing_scs_req) {
11533 wpa_printf(MSG_ERROR, "%s: SCS Request already in queue",
11534 __func__);
11535 return -1;
11536 }
11537
11538 /**
11539 * format:
11540 * [scs_id=<decimal number>] <add|remove|change> [scs_up=<0-7>]
11541 * [classifier_type=<4|10>]
11542 * [classifier params based on classifier type]
11543 * [tclas_processing=<0|1>]
11544 * [qos_characteristics] <up/down/direct> [min_si=<decimal number>]
11545 * [max_si=<decimal number>] [min_data_rate=<decimal number>]
11546 * [delay_bound=<decimal number>] [max_msdu=<decimal number>]
11547 * [service_start_time=<decimal number>]
11548 * [service_start_time_link_id=<decimal number>]
11549 * [mean_data_rate=<decimal number>] [burst_size=<decimal number>]
11550 * [msdu_lifetime=<decimal number>]
11551 * [msdu_delivery_info=<decimal number>] [medium_time=<decimal number>]
11552 * [scs_id=<decimal number>] ...
11553 */
11554 pos1 = os_strstr(cmd, "scs_id=");
11555 if (!pos1) {
11556 wpa_printf(MSG_ERROR, "SCSID not present");
11557 return -1;
11558 }
11559
11560 free_up_scs_desc(scs_data);
11561
11562 while (pos1) {
11563 struct scs_desc_elem *n1;
11564 struct active_scs_elem *active_scs_desc;
11565 char *next_scs_desc, *pos2;
11566 unsigned int num_tclas_elem = 0;
11567 bool scsid_active = false, tclas_present = false;
11568 struct qos_characteristics *qos_elem = &desc_elem.qos_char_elem;
11569
11570 desc_elem.scs_id = atoi(pos1 + 7);
11571 pos1 += 7;
11572
11573 next_scs_desc = os_strstr(pos1, "scs_id=");
11574 if (next_scs_desc) {
11575 char temp[20];
11576
11577 os_snprintf(temp, sizeof(temp), "scs_id=%d ",
11578 desc_elem.scs_id);
11579 if (os_strstr(next_scs_desc, temp)) {
11580 wpa_printf(MSG_ERROR,
11581 "Multiple SCS descriptors configured with same SCSID(=%d)",
11582 desc_elem.scs_id);
11583 goto free_scs_desc;
11584 }
11585 pos1[next_scs_desc - pos1 - 1] = '\0';
11586 }
11587
11588 dl_list_for_each(active_scs_desc, &wpa_s->active_scs_ids,
11589 struct active_scs_elem, list) {
11590 if (desc_elem.scs_id == active_scs_desc->scs_id) {
11591 scsid_active = true;
11592 break;
11593 }
11594 }
11595
11596 if (os_strstr(pos1, "add ")) {
11597 desc_elem.request_type = SCS_REQ_ADD;
11598 if (scsid_active) {
11599 wpa_printf(MSG_ERROR, "SCSID %d already active",
11600 desc_elem.scs_id);
11601 return -1;
11602 }
11603 } else if (os_strstr(pos1, "remove")) {
11604 desc_elem.request_type = SCS_REQ_REMOVE;
11605 if (!scsid_active) {
11606 wpa_printf(MSG_ERROR, "SCSID %d not active",
11607 desc_elem.scs_id);
11608 return -1;
11609 }
11610 goto scs_desc_end;
11611 } else if (os_strstr(pos1, "change ")) {
11612 desc_elem.request_type = SCS_REQ_CHANGE;
11613 if (!scsid_active) {
11614 wpa_printf(MSG_ERROR, "SCSID %d not active",
11615 desc_elem.scs_id);
11616 return -1;
11617 }
11618 } else {
11619 wpa_printf(MSG_ERROR, "SCS Request type invalid");
11620 goto free_scs_desc;
11621 }
11622
11623 pos1 = os_strstr(pos1, "scs_up=");
11624 if (!pos1) {
11625 wpa_printf(MSG_ERROR,
11626 "Intra-Access user priority not present");
11627 goto free_scs_desc;
11628 }
11629
11630 val = atoi(pos1 + 7);
11631 if (val < 0 || val > 7) {
11632 wpa_printf(MSG_ERROR,
11633 "Intra-Access user priority invalid %d",
11634 val);
11635 goto free_scs_desc;
11636 }
11637
11638 desc_elem.intra_access_priority = val;
11639 desc_elem.scs_up_avail = true;
11640
11641 pos = os_strstr(pos1, "classifier_type=");
11642 if (!pos) {
11643 wpa_printf(MSG_ERROR, "classifier type empty");
11644 goto qos_characteristics;
11645 }
11646 tclas_present = true;
11647
11648 while (pos) {
11649 struct tclas_element elem = { 0 }, *n;
11650 char *next_tclas_elem;
11651
11652 val = atoi(pos + 16);
11653 if (val != 4 && val != 10) {
11654 wpa_printf(MSG_ERROR,
11655 "classifier type invalid %d", val);
11656 goto free_scs_desc;
11657 }
11658
11659 elem.classifier_type = val;
11660 pos += 16;
11661
11662 next_tclas_elem = os_strstr(pos, "classifier_type=");
11663 if (next_tclas_elem) {
11664 pos1 = next_tclas_elem;
11665 pos[next_tclas_elem - pos - 1] = '\0';
11666 }
11667
11668 switch (val) {
11669 case 4:
11670 if (scs_parse_type4(&elem, pos) < 0)
11671 goto free_scs_desc;
11672 break;
11673 case 10:
11674 if (scs_parse_type10(&elem, pos) < 0)
11675 goto free_scs_desc;
11676 break;
11677 }
11678
11679 n = os_realloc(desc_elem.tclas_elems,
11680 (num_tclas_elem + 1) * sizeof(elem));
11681 if (!n)
11682 goto free_scs_desc;
11683
11684 desc_elem.tclas_elems = n;
11685 os_memcpy((u8 *) desc_elem.tclas_elems +
11686 num_tclas_elem * sizeof(elem),
11687 &elem, sizeof(elem));
11688 num_tclas_elem++;
11689 desc_elem.num_tclas_elem = num_tclas_elem;
11690 pos = next_tclas_elem;
11691 }
11692
11693 if (desc_elem.num_tclas_elem > 1) {
11694 pos1 = os_strstr(pos1, "tclas_processing=");
11695 if (!pos1) {
11696 wpa_printf(MSG_ERROR, "tclas_processing empty");
11697 goto free_scs_desc;
11698 }
11699
11700 val = atoi(pos1 + 17);
11701 if (val != 0 && val != 1) {
11702 wpa_printf(MSG_ERROR,
11703 "tclas_processing invalid");
11704 goto free_scs_desc;
11705 }
11706
11707 desc_elem.tclas_processing = val;
11708 }
11709
11710 qos_characteristics:
11711 pos1 = os_strstr(pos1, "qos_characteristics");
11712 if (!pos1 && !tclas_present)
11713 goto free_scs_desc;
11714 if (!pos1)
11715 goto scs_desc_end;
11716
11717 qos_elem->available = true;
11718 if (os_strstr(pos1, "up ")) {
11719 qos_elem->direction = SCS_DIRECTION_UP;
11720 if (tclas_present) {
11721 wpa_printf(MSG_ERROR,
11722 "TCLAS with direction:UP not allowed");
11723 goto free_scs_desc;
11724 }
11725 } else if (os_strstr(pos1, "down ")) {
11726 qos_elem->direction = SCS_DIRECTION_DOWN;
11727 } else if (os_strstr(pos1, "direct ")) {
11728 qos_elem->direction = SCS_DIRECTION_DIRECT;
11729 }
11730
11731 pos1 = os_strstr(pos1, "min_si=");
11732 if (!pos1) {
11733 wpa_printf(MSG_ERROR, "Min SI is required");
11734 goto free_scs_desc;
11735 }
11736 qos_elem->min_si = atoi(pos1 + 7);
11737
11738 pos1 = os_strstr(pos1, "max_si=");
11739 if (!pos1) {
11740 wpa_printf(MSG_ERROR, "Max SI is required");
11741 goto free_scs_desc;
11742 }
11743 qos_elem->max_si = atoi(pos1 + 7);
11744
11745 if (qos_elem->min_si && qos_elem->max_si &&
11746 qos_elem->max_si < qos_elem->min_si) {
11747 wpa_printf(MSG_ERROR, "Invalid Max SI");
11748 goto free_scs_desc;
11749 }
11750
11751 pos1 = os_strstr(pos1, "min_data_rate=");
11752 if (!pos1) {
11753 wpa_printf(MSG_ERROR, "Min data rate is required");
11754 goto free_scs_desc;
11755 }
11756 qos_elem->min_data_rate = atoi(pos1 + 14);
11757
11758 pos1 = os_strstr(pos1, "delay_bound=");
11759 if (!pos1) {
11760 wpa_printf(MSG_ERROR, "Delay Bound is required");
11761 goto free_scs_desc;
11762 }
11763 qos_elem->delay_bound = atoi(pos1 + 12);
11764
11765 if (qos_elem->min_data_rate >= BIT(24) ||
11766 qos_elem->delay_bound >= BIT(24)) {
11767 wpa_printf(MSG_ERROR,
11768 "Invalid min_data_rate or delay_bound");
11769 goto free_scs_desc;
11770 }
11771
11772 pos2 = os_strstr(pos1, "max_msdu=");
11773 if (pos2) {
11774 qos_elem->max_msdu_size = atoi(pos2 + 9);
11775 qos_elem->mask |= SCS_QOS_BIT_MAX_MSDU_SIZE;
11776 }
11777
11778 pos2 = os_strstr(pos1, "service_start_time=");
11779 if (pos2) {
11780 qos_elem->service_start_time = atoi(pos2 + 19);
11781 qos_elem->mask |= SCS_QOS_BIT_SERVICE_START_TIME;
11782 }
11783
11784 pos2 = os_strstr(pos1, "service_start_time_link_id=");
11785 if (pos2) {
11786 qos_elem->service_start_time_link_id = atoi(pos2 + 27);
11787 qos_elem->mask |= SCS_QOS_BIT_SERVICE_START_TIME_LINKID;
11788 }
11789
11790 pos2 = os_strstr(pos1, "mean_data_rate=");
11791 if (pos2) {
11792 qos_elem->mean_data_rate = atoi(pos2 + 15);
11793 qos_elem->mask |= SCS_QOS_BIT_MEAN_DATA_RATE;
11794 }
11795
11796 pos2 = os_strstr(pos1, "burst_size=");
11797 if (pos2) {
11798 qos_elem->burst_size = atoi(pos2 + 11);
11799 qos_elem->mask |=
11800 SCS_QOS_BIT_DELAYED_BOUNDED_BURST_SIZE;
11801 }
11802
11803 pos2 = os_strstr(pos1, "msdu_lifetime=");
11804 if (pos2) {
11805 qos_elem->msdu_lifetime = atoi(pos2 + 14);
11806 qos_elem->mask |= SCS_QOS_BIT_MSDU_LIFETIME;
11807 }
11808
11809 pos2 = os_strstr(pos1, "msdu_delivery_info=");
11810 if (pos2) {
11811 qos_elem->msdu_delivery_info = atoi(pos2 + 19);
11812 qos_elem->mask |= SCS_QOS_BIT_MSDU_DELIVERY_INFO;
11813 }
11814
11815 pos2 = os_strstr(pos1, "medium_time=");
11816 if (pos2) {
11817 qos_elem->medium_time = atoi(pos2 + 12);
11818 qos_elem->mask |= SCS_QOS_BIT_MEDIUM_TIME;
11819 }
11820
11821 scs_desc_end:
11822 n1 = os_realloc(scs_data->scs_desc_elems, (num_scs_desc + 1) *
11823 sizeof(struct scs_desc_elem));
11824 if (!n1)
11825 goto free_scs_desc;
11826
11827 scs_data->scs_desc_elems = n1;
11828 os_memcpy((u8 *) scs_data->scs_desc_elems + num_scs_desc *
11829 sizeof(desc_elem), &desc_elem, sizeof(desc_elem));
11830 num_scs_desc++;
11831 scs_data->num_scs_desc = num_scs_desc;
11832 pos1 = next_scs_desc;
11833 os_memset(&desc_elem, 0, sizeof(desc_elem));
11834 }
11835
11836 return wpas_send_scs_req(wpa_s);
11837
11838 free_scs_desc:
11839 free_up_tclas_elem(&desc_elem);
11840 free_up_scs_desc(scs_data);
11841 return -1;
11842 }
11843
11844
wpas_ctrl_iface_send_dscp_resp(struct wpa_supplicant * wpa_s,const char * cmd)11845 static int wpas_ctrl_iface_send_dscp_resp(struct wpa_supplicant *wpa_s,
11846 const char *cmd)
11847 {
11848 char *pos;
11849 struct dscp_policy_status *policy = NULL, *n;
11850 int num_policies = 0, ret = -1;
11851 struct dscp_resp_data resp_data;
11852
11853 /*
11854 * format:
11855 * <[reset]>/<[solicited] [policy_id=1 status=0...]> [more]
11856 */
11857
11858 os_memset(&resp_data, 0, sizeof(resp_data));
11859
11860 resp_data.more = os_strstr(cmd, "more") != NULL;
11861
11862 if (os_strstr(cmd, "reset")) {
11863 resp_data.reset = true;
11864 resp_data.solicited = false;
11865 goto send_resp;
11866 }
11867
11868 resp_data.solicited = os_strstr(cmd, "solicited") != NULL;
11869
11870 pos = os_strstr(cmd, "policy_id=");
11871 while (pos) {
11872 n = os_realloc(policy, (num_policies + 1) * sizeof(*policy));
11873 if (!n)
11874 goto fail;
11875
11876 policy = n;
11877 pos += 10;
11878 policy[num_policies].id = atoi(pos);
11879 if (policy[num_policies].id == 0) {
11880 wpa_printf(MSG_ERROR, "DSCP: Invalid policy id");
11881 goto fail;
11882 }
11883
11884 pos = os_strstr(pos, "status=");
11885 if (!pos) {
11886 wpa_printf(MSG_ERROR,
11887 "DSCP: Status is not found for a policy");
11888 goto fail;
11889 }
11890
11891 pos += 7;
11892 policy[num_policies].status = atoi(pos);
11893 num_policies++;
11894
11895 pos = os_strstr(pos, "policy_id");
11896 }
11897
11898 resp_data.policy = policy;
11899 resp_data.num_policies = num_policies;
11900 send_resp:
11901 ret = wpas_send_dscp_response(wpa_s, &resp_data);
11902 if (ret)
11903 wpa_printf(MSG_ERROR, "DSCP: Failed to send DSCP response");
11904 fail:
11905 os_free(policy);
11906 return ret;
11907 }
11908
11909
wpas_ctrl_iface_send_dscp_query(struct wpa_supplicant * wpa_s,const char * cmd)11910 static int wpas_ctrl_iface_send_dscp_query(struct wpa_supplicant *wpa_s,
11911 const char *cmd)
11912 {
11913 char *pos;
11914
11915 /*
11916 * format:
11917 * Wildcard DSCP query
11918 * <wildcard>
11919 *
11920 * DSCP query with a domain name attribute:
11921 * [domain_name=<string>]
11922 */
11923
11924 if (os_strstr(cmd, "wildcard")) {
11925 wpa_printf(MSG_DEBUG, "QM: Send wildcard DSCP policy query");
11926 return wpas_send_dscp_query(wpa_s, NULL, 0);
11927 }
11928
11929 pos = os_strstr(cmd, "domain_name=");
11930 if (!pos || !os_strlen(pos + 12)) {
11931 wpa_printf(MSG_ERROR, "QM: Domain name not preset");
11932 return -1;
11933 }
11934
11935 return wpas_send_dscp_query(wpa_s, pos + 12, os_strlen(pos + 12));
11936 }
11937
11938
wpas_ctrl_iface_mlo_signal_poll(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)11939 static int wpas_ctrl_iface_mlo_signal_poll(struct wpa_supplicant *wpa_s,
11940 char *buf, size_t buflen)
11941 {
11942 int ret, i;
11943 char *pos, *end;
11944 struct wpa_mlo_signal_info mlo_si;
11945
11946 if (!wpa_s->valid_links)
11947 return -1;
11948
11949 ret = wpa_drv_mlo_signal_poll(wpa_s, &mlo_si);
11950 if (ret)
11951 return -1;
11952
11953 pos = buf;
11954 end = buf + buflen;
11955
11956 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
11957 if (!(mlo_si.valid_links & BIT(i)))
11958 continue;
11959
11960 ret = os_snprintf(pos, end - pos,
11961 "LINK_ID=%d\nRSSI=%d\nLINKSPEED=%lu\n"
11962 "NOISE=%d\nFREQUENCY=%u\n",
11963 i, mlo_si.links[i].data.signal,
11964 mlo_si.links[i].data.current_tx_rate / 1000,
11965 mlo_si.links[i].current_noise,
11966 mlo_si.links[i].frequency);
11967 if (os_snprintf_error(end - pos, ret))
11968 return -1;
11969 pos += ret;
11970
11971 if (mlo_si.links[i].chanwidth != CHAN_WIDTH_UNKNOWN) {
11972 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
11973 channel_width_to_string(
11974 mlo_si.links[i].chanwidth));
11975 if (os_snprintf_error(end - pos, ret))
11976 return -1;
11977 pos += ret;
11978 }
11979
11980 if (mlo_si.links[i].center_frq1 > 0) {
11981 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
11982 mlo_si.links[i].center_frq1);
11983 if (os_snprintf_error(end - pos, ret))
11984 return -1;
11985 pos += ret;
11986 }
11987
11988 if (mlo_si.links[i].center_frq2 > 0) {
11989 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
11990 mlo_si.links[i].center_frq2);
11991 if (os_snprintf_error(end - pos, ret))
11992 return -1;
11993 pos += ret;
11994 }
11995
11996 if (mlo_si.links[i].data.avg_signal) {
11997 ret = os_snprintf(pos, end - pos,
11998 "AVG_RSSI=%d\n",
11999 mlo_si.links[i].data.avg_signal);
12000 if (os_snprintf_error(end - pos, ret))
12001 return -1;
12002 pos += ret;
12003 }
12004
12005 if (mlo_si.links[i].data.avg_beacon_signal) {
12006 ret = os_snprintf(
12007 pos, end - pos, "AVG_BEACON_RSSI=%d\n",
12008 mlo_si.links[i].data.avg_beacon_signal);
12009 if (os_snprintf_error(end - pos, ret))
12010 return -1;
12011 pos += ret;
12012 }
12013 }
12014
12015 return pos - buf;
12016 }
12017
12018
wpas_ctrl_iface_mlo_status(struct wpa_supplicant * wpa_s,char * buf,size_t buflen)12019 static int wpas_ctrl_iface_mlo_status(struct wpa_supplicant *wpa_s,
12020 char *buf, size_t buflen)
12021 {
12022 int ret, i;
12023 char *pos, *end;
12024
12025 if (!wpa_s->valid_links)
12026 return -1;
12027
12028 pos = buf;
12029 end = buf + buflen;
12030
12031 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
12032 if (!(wpa_s->valid_links & BIT(i)))
12033 continue;
12034
12035 ret = os_snprintf(pos, end - pos, "link_id=%d\nfreq=%u\n"
12036 "ap_link_addr=" MACSTR
12037 "\nsta_link_addr=" MACSTR "\n",
12038 i, wpa_s->links[i].freq,
12039 MAC2STR(wpa_s->links[i].bssid),
12040 MAC2STR(wpa_s->links[i].addr));
12041 if (os_snprintf_error(end - pos, ret))
12042 return pos - buf;
12043 pos += ret;
12044 }
12045
12046 return pos - buf;
12047 }
12048
12049
12050 #ifdef CONFIG_TESTING_OPTIONS
wpas_ctrl_ml_probe(struct wpa_supplicant * wpa_s,char * cmd)12051 static int wpas_ctrl_ml_probe(struct wpa_supplicant *wpa_s, char *cmd)
12052 {
12053 char *token, *context = NULL;
12054 u8 bssid[ETH_ALEN];
12055 int mld_id = -1, link_id = -1;
12056 struct wpa_bss *bss;
12057 int *freqs;
12058
12059 os_memset(bssid, 0, sizeof(bssid));
12060
12061 while ((token = str_token(cmd, " ", &context))) {
12062 if (os_strncmp(token, "bssid=", 6) == 0) {
12063 if (hwaddr_aton(token + 6, bssid))
12064 return -1;
12065 } else if (os_strncmp(token, "mld_id=", 7) == 0) {
12066 mld_id = atoi(token + 7);
12067 } else if (os_strncmp(token, "link_id=", 8) == 0) {
12068 link_id = atoi(token + 8);
12069 }
12070 }
12071
12072 if (mld_id < 0 || is_zero_ether_addr(bssid)) {
12073 wpa_printf(MSG_DEBUG,
12074 "MLD: Failed parsing ML probe request arguments");
12075 return -1;
12076 }
12077
12078 bss = wpa_bss_get_bssid(wpa_s, bssid);
12079 if (!bss) {
12080 wpa_printf(MSG_DEBUG,
12081 "MLD: Unknown BSS for " MACSTR, MAC2STR(bssid));
12082 return -1;
12083 }
12084
12085 if (wpa_s->sched_scanning || wpa_s->scanning ||
12086 (wpa_s->wpa_state > WPA_SCANNING &&
12087 wpa_s->wpa_state != WPA_COMPLETED)) {
12088 wpa_printf(MSG_DEBUG,
12089 "MLO: Ongoing scan: Reject ML probe request");
12090 return -1;
12091 }
12092
12093 freqs = os_malloc(sizeof(int) * 2);
12094 if (!freqs)
12095 return -1;
12096
12097 freqs[0] = bss->freq;
12098 freqs[1] = 0;
12099
12100 wpa_s->manual_scan_passive = 0;
12101 wpa_s->manual_scan_use_id = 0;
12102 wpa_s->manual_scan_only_new = 0;
12103 wpa_s->scan_id_count = 0;
12104 wpa_s->scan_res_handler = scan_only_handler;
12105 os_free(wpa_s->manual_scan_freqs);
12106 wpa_s->manual_scan_freqs = freqs;
12107
12108 os_memcpy(wpa_s->ml_probe_bssid, bssid, ETH_ALEN);
12109 wpa_s->ml_probe_mld_id = mld_id;
12110 if (link_id >= 0)
12111 wpa_s->ml_probe_links = BIT(link_id);
12112
12113 wpa_s->normal_scans = 0;
12114 wpa_s->scan_req = MANUAL_SCAN_REQ;
12115 wpa_s->after_wps = 0;
12116 wpa_s->known_wps_freq = 0;
12117 wpa_supplicant_req_scan(wpa_s, 0, 0);
12118
12119 return 0;
12120 }
12121 #endif /* CONFIG_TESTING_OPTIONS */
12122
12123
wpa_supplicant_ctrl_iface_process(struct wpa_supplicant * wpa_s,char * buf,size_t * resp_len)12124 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
12125 char *buf, size_t *resp_len)
12126 {
12127 char *reply;
12128 const int reply_size = 4096;
12129 int reply_len;
12130
12131 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
12132 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
12133 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
12134 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
12135 if (wpa_debug_show_keys)
12136 wpa_dbg(wpa_s, MSG_DEBUG,
12137 "Control interface command '%s'", buf);
12138 else
12139 wpa_dbg(wpa_s, MSG_DEBUG,
12140 "Control interface command '%s [REMOVED]'",
12141 os_strncmp(buf, WPA_CTRL_RSP,
12142 os_strlen(WPA_CTRL_RSP)) == 0 ?
12143 WPA_CTRL_RSP :
12144 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
12145 "SET_NETWORK" : "key-add"));
12146 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
12147 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
12148 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
12149 (const u8 *) buf, os_strlen(buf));
12150 } else {
12151 int level = wpas_ctrl_cmd_debug_level(buf);
12152 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
12153 }
12154
12155 reply = os_malloc(reply_size);
12156 if (reply == NULL) {
12157 *resp_len = 1;
12158 return NULL;
12159 }
12160
12161 os_memcpy(reply, "OK\n", 3);
12162 reply_len = 3;
12163
12164 if (os_strcmp(buf, "PING") == 0) {
12165 os_memcpy(reply, "PONG\n", 5);
12166 reply_len = 5;
12167 } else if (os_strcmp(buf, "IFNAME") == 0) {
12168 reply_len = os_strlen(wpa_s->ifname);
12169 os_memcpy(reply, wpa_s->ifname, reply_len);
12170 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
12171 if (wpa_debug_reopen_file() < 0)
12172 reply_len = -1;
12173 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
12174 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
12175 } else if (os_strcmp(buf, "MIB") == 0) {
12176 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
12177 if (reply_len >= 0) {
12178 reply_len += eapol_sm_get_mib(wpa_s->eapol,
12179 reply + reply_len,
12180 reply_size - reply_len);
12181 #ifdef CONFIG_MACSEC
12182 reply_len += ieee802_1x_kay_get_mib(
12183 wpa_s->kay, reply + reply_len,
12184 reply_size - reply_len);
12185 #endif /* CONFIG_MACSEC */
12186 }
12187 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
12188 reply_len = wpa_supplicant_ctrl_iface_status(
12189 wpa_s, buf + 6, reply, reply_size);
12190 } else if (os_strcmp(buf, "PMKSA") == 0) {
12191 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
12192 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
12193 wpas_ctrl_iface_pmksa_flush(wpa_s);
12194 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
12195 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
12196 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
12197 reply, reply_size);
12198 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
12199 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
12200 reply_len = -1;
12201 #ifdef CONFIG_MESH
12202 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
12203 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
12204 reply, reply_size);
12205 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
12206 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
12207 reply_len = -1;
12208 #endif /* CONFIG_MESH */
12209 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
12210 } else if (os_strncmp(buf, "SET ", 4) == 0) {
12211 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
12212 reply_len = -1;
12213 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
12214 reply_len = wpa_config_dump_values(wpa_s->conf,
12215 reply, reply_size);
12216 } else if (os_strncmp(buf, "GET ", 4) == 0) {
12217 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
12218 reply, reply_size);
12219 } else if (os_strcmp(buf, "LOGON") == 0) {
12220 eapol_sm_notify_logoff(wpa_s->eapol, false);
12221 } else if (os_strcmp(buf, "LOGOFF") == 0) {
12222 eapol_sm_notify_logoff(wpa_s->eapol, true);
12223 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
12224 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
12225 reply_len = -1;
12226 else
12227 wpas_request_connection(wpa_s);
12228 } else if (os_strcmp(buf, "REATTACH") == 0) {
12229 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
12230 !wpa_s->current_ssid)
12231 reply_len = -1;
12232 else {
12233 wpa_s->reattach = 1;
12234 wpas_request_connection(wpa_s);
12235 }
12236 } else if (os_strcmp(buf, "RECONNECT") == 0) {
12237 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
12238 reply_len = -1;
12239 else if (wpa_s->disconnected)
12240 wpas_request_connection(wpa_s);
12241 #ifdef IEEE8021X_EAPOL
12242 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
12243 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
12244 reply_len = -1;
12245 #endif /* IEEE8021X_EAPOL */
12246 #ifdef CONFIG_IEEE80211R
12247 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
12248 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
12249 reply_len = -1;
12250 #endif /* CONFIG_IEEE80211R */
12251 #ifdef CONFIG_WPS
12252 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
12253 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
12254 if (res == -2) {
12255 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12256 reply_len = 17;
12257 } else if (res)
12258 reply_len = -1;
12259 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
12260 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
12261 if (res == -2) {
12262 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12263 reply_len = 17;
12264 } else if (res)
12265 reply_len = -1;
12266 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
12267 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
12268 reply,
12269 reply_size);
12270 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
12271 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
12272 wpa_s, buf + 14, reply, reply_size);
12273 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
12274 if (wpas_wps_cancel(wpa_s))
12275 reply_len = -1;
12276 #ifdef CONFIG_WPS_NFC
12277 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
12278 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
12279 reply_len = -1;
12280 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
12281 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
12282 reply_len = -1;
12283 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
12284 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
12285 wpa_s, buf + 21, reply, reply_size);
12286 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
12287 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
12288 wpa_s, buf + 14, reply, reply_size);
12289 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
12290 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
12291 buf + 17))
12292 reply_len = -1;
12293 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
12294 reply_len = wpas_ctrl_nfc_get_handover_req(
12295 wpa_s, buf + 21, reply, reply_size);
12296 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
12297 reply_len = wpas_ctrl_nfc_get_handover_sel(
12298 wpa_s, buf + 21, reply, reply_size);
12299 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
12300 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
12301 reply_len = -1;
12302 #endif /* CONFIG_WPS_NFC */
12303 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
12304 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
12305 reply_len = -1;
12306 #ifdef CONFIG_AP
12307 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
12308 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
12309 wpa_s, buf + 11, reply, reply_size);
12310 #endif /* CONFIG_AP */
12311 #ifdef CONFIG_WPS_ER
12312 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
12313 if (wpas_wps_er_start(wpa_s, NULL))
12314 reply_len = -1;
12315 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
12316 if (wpas_wps_er_start(wpa_s, buf + 13))
12317 reply_len = -1;
12318 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
12319 wpas_wps_er_stop(wpa_s);
12320 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
12321 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
12322 reply_len = -1;
12323 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
12324 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
12325 if (ret == -2) {
12326 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12327 reply_len = 17;
12328 } else if (ret == -3) {
12329 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
12330 reply_len = 18;
12331 } else if (ret == -4) {
12332 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
12333 reply_len = 20;
12334 } else if (ret)
12335 reply_len = -1;
12336 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
12337 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
12338 reply_len = -1;
12339 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
12340 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
12341 buf + 18))
12342 reply_len = -1;
12343 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
12344 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
12345 reply_len = -1;
12346 #ifdef CONFIG_WPS_NFC
12347 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
12348 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
12349 wpa_s, buf + 24, reply, reply_size);
12350 #endif /* CONFIG_WPS_NFC */
12351 #endif /* CONFIG_WPS_ER */
12352 #endif /* CONFIG_WPS */
12353 #ifdef CONFIG_IBSS_RSN
12354 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
12355 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
12356 reply_len = -1;
12357 #endif /* CONFIG_IBSS_RSN */
12358 #ifdef CONFIG_MESH
12359 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
12360 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
12361 wpa_s, buf + 19, reply, reply_size);
12362 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
12363 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
12364 wpa_s, "", reply, reply_size);
12365 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
12366 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
12367 reply_len = -1;
12368 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
12369 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
12370 buf + 18))
12371 reply_len = -1;
12372 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
12373 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
12374 reply_len = -1;
12375 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
12376 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
12377 reply_len = -1;
12378 } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) {
12379 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16))
12380 reply_len = -1;
12381 #endif /* CONFIG_MESH */
12382 #ifdef CONFIG_P2P
12383 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
12384 if (p2p_ctrl_find(wpa_s, buf + 8))
12385 reply_len = -1;
12386 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
12387 if (p2p_ctrl_find(wpa_s, ""))
12388 reply_len = -1;
12389 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
12390 wpas_p2p_stop_find(wpa_s);
12391 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
12392 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
12393 reply_len = -1;
12394 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
12395 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
12396 reply_len = -1;
12397 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
12398 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
12399 reply_size);
12400 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
12401 if (p2p_ctrl_listen(wpa_s, buf + 11))
12402 reply_len = -1;
12403 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
12404 if (p2p_ctrl_listen(wpa_s, ""))
12405 reply_len = -1;
12406 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
12407 if (wpas_p2p_group_remove(wpa_s, buf + 17))
12408 reply_len = -1;
12409 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
12410 if (p2p_ctrl_group_add(wpa_s, ""))
12411 reply_len = -1;
12412 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
12413 if (p2p_ctrl_group_add(wpa_s, buf + 14))
12414 reply_len = -1;
12415 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
12416 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
12417 reply_size);
12418 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
12419 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
12420 reply_len = -1;
12421 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
12422 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
12423 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
12424 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
12425 reply_size);
12426 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
12427 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
12428 reply_len = -1;
12429 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
12430 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
12431 reply_len = -1;
12432 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
12433 wpas_p2p_sd_service_update(wpa_s);
12434 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
12435 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
12436 reply_len = -1;
12437 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
12438 wpas_p2p_service_flush(wpa_s);
12439 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
12440 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
12441 reply_len = -1;
12442 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
12443 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
12444 reply_len = -1;
12445 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
12446 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
12447 reply_len = -1;
12448 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
12449 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
12450 reply_len = -1;
12451 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
12452 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
12453 reply_len = -1;
12454 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
12455 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
12456 reply_size);
12457 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
12458 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
12459 reply_len = -1;
12460 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
12461 p2p_ctrl_flush(wpa_s);
12462 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
12463 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
12464 reply_len = -1;
12465 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
12466 if (wpas_p2p_cancel(wpa_s))
12467 reply_len = -1;
12468 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
12469 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
12470 reply_len = -1;
12471 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
12472 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
12473 reply_len = -1;
12474 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
12475 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
12476 reply_len = -1;
12477 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
12478 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
12479 reply_len = -1;
12480 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
12481 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
12482 reply_len = -1;
12483 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
12484 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
12485 reply_len = -1;
12486 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
12487 if (wpas_p2p_lo_stop(wpa_s))
12488 reply_len = -1;
12489 #endif /* CONFIG_P2P */
12490 #ifdef CONFIG_WIFI_DISPLAY
12491 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
12492 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
12493 reply_len = -1;
12494 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
12495 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
12496 reply, reply_size);
12497 #endif /* CONFIG_WIFI_DISPLAY */
12498 #ifdef CONFIG_INTERWORKING
12499 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
12500 if (interworking_fetch_anqp(wpa_s) < 0)
12501 reply_len = -1;
12502 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
12503 interworking_stop_fetch_anqp(wpa_s);
12504 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
12505 if (ctrl_interworking_select(wpa_s, NULL) < 0)
12506 reply_len = -1;
12507 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
12508 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
12509 reply_len = -1;
12510 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
12511 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
12512 reply_len = -1;
12513 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
12514 int id;
12515
12516 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
12517 if (id < 0)
12518 reply_len = -1;
12519 else {
12520 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
12521 if (os_snprintf_error(reply_size, reply_len))
12522 reply_len = -1;
12523 }
12524 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
12525 if (get_anqp(wpa_s, buf + 9) < 0)
12526 reply_len = -1;
12527 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
12528 if (gas_request(wpa_s, buf + 12) < 0)
12529 reply_len = -1;
12530 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
12531 reply_len = gas_response_get(wpa_s, buf + 17, reply,
12532 reply_size);
12533 #endif /* CONFIG_INTERWORKING */
12534 #ifdef CONFIG_HS20
12535 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
12536 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
12537 reply_len = -1;
12538 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
12539 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
12540 reply_len = -1;
12541 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
12542 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
12543 reply_len = -1;
12544 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
12545 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
12546 reply_len = -1;
12547 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
12548 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
12549 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
12550 if (del_hs20_icon(wpa_s, buf + 14) < 0)
12551 reply_len = -1;
12552 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
12553 if (hs20_fetch_osu(wpa_s, 0) < 0)
12554 reply_len = -1;
12555 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
12556 if (hs20_fetch_osu(wpa_s, 1) < 0)
12557 reply_len = -1;
12558 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
12559 hs20_cancel_fetch_osu(wpa_s);
12560 #endif /* CONFIG_HS20 */
12561 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
12562 {
12563 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
12564 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
12565 reply_len = -1;
12566 else {
12567 /*
12568 * Notify response from timeout to allow the control
12569 * interface response to be sent first.
12570 */
12571 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
12572 wpa_s, NULL);
12573 }
12574 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
12575 if (wpa_supplicant_reload_configuration(wpa_s))
12576 reply_len = -1;
12577 } else if (os_strcmp(buf, "TERMINATE") == 0) {
12578 wpa_supplicant_terminate_proc(wpa_s->global);
12579 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
12580 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
12581 reply_len = -1;
12582 } else if (os_strncmp(buf, "BSSID_IGNORE", 12) == 0) {
12583 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
12584 wpa_s, buf + 12, reply, reply_size);
12585 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
12586 /* deprecated backwards compatibility alias for BSSID_IGNORE */
12587 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
12588 wpa_s, buf + 9, reply, reply_size);
12589 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
12590 reply_len = wpa_supplicant_ctrl_iface_log_level(
12591 wpa_s, buf + 9, reply, reply_size);
12592 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
12593 reply_len = wpa_supplicant_ctrl_iface_list_networks(
12594 wpa_s, buf + 14, reply, reply_size);
12595 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
12596 reply_len = wpa_supplicant_ctrl_iface_list_networks(
12597 wpa_s, NULL, reply, reply_size);
12598 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
12599 wpas_request_disconnection(wpa_s);
12600 } else if (os_strcmp(buf, "SCAN") == 0) {
12601 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
12602 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
12603 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
12604 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
12605 reply_len = wpa_supplicant_ctrl_iface_scan_results(
12606 wpa_s, reply, reply_size);
12607 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
12608 if (wpas_abort_ongoing_scan(wpa_s) < 0)
12609 reply_len = -1;
12610 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
12611 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
12612 reply_len = -1;
12613 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
12614 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
12615 reply_len = -1;
12616 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
12617 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
12618 reply_len = -1;
12619 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
12620 reply_len = wpa_supplicant_ctrl_iface_add_network(
12621 wpa_s, reply, reply_size);
12622 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
12623 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
12624 reply_len = -1;
12625 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
12626 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
12627 reply_len = -1;
12628 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
12629 reply_len = wpa_supplicant_ctrl_iface_get_network(
12630 wpa_s, buf + 12, reply, reply_size);
12631 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
12632 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
12633 wpa_s))
12634 reply_len = -1;
12635 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
12636 reply_len = wpa_supplicant_ctrl_iface_list_creds(
12637 wpa_s, reply, reply_size);
12638 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
12639 reply_len = wpa_supplicant_ctrl_iface_add_cred(
12640 wpa_s, reply, reply_size);
12641 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
12642 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
12643 reply_len = -1;
12644 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
12645 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
12646 reply_len = -1;
12647 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
12648 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
12649 reply,
12650 reply_size);
12651 #ifndef CONFIG_NO_CONFIG_WRITE
12652 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
12653 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
12654 reply_len = -1;
12655 #endif /* CONFIG_NO_CONFIG_WRITE */
12656 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
12657 reply_len = wpa_supplicant_ctrl_iface_get_capability(
12658 wpa_s, buf + 15, reply, reply_size);
12659 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
12660 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
12661 reply_len = -1;
12662 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
12663 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
12664 reply_len = -1;
12665 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
12666 reply_len = wpa_supplicant_global_iface_list(
12667 wpa_s->global, reply, reply_size);
12668 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
12669 reply_len = wpa_supplicant_global_iface_interfaces(
12670 wpa_s->global, buf + 10, reply, reply_size);
12671 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
12672 reply_len = wpa_supplicant_ctrl_iface_bss(
12673 wpa_s, buf + 4, reply, reply_size);
12674 #ifdef CONFIG_AP
12675 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
12676 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
12677 } else if (os_strncmp(buf, "STA ", 4) == 0) {
12678 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
12679 reply_size);
12680 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
12681 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
12682 reply_size);
12683 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
12684 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
12685 reply_len = -1;
12686 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
12687 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
12688 reply_len = -1;
12689 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
12690 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
12691 reply_len = -1;
12692 } else if (os_strcmp(buf, "STOP_AP") == 0) {
12693 if (wpas_ap_stop_ap(wpa_s))
12694 reply_len = -1;
12695 } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) {
12696 if (wpas_ap_update_beacon(wpa_s))
12697 reply_len = -1;
12698 } else if (os_strncmp(buf, "ACCEPT_ACL ", 11) == 0) {
12699 if (os_strncmp(buf + 11, "ADD_MAC ", 8) == 0) {
12700 if (ap_ctrl_iface_acl_add_mac(wpa_s,
12701 DENY_UNLESS_ACCEPTED,
12702 buf + 19) ||
12703 ap_ctrl_iface_set_acl(wpa_s))
12704 reply_len = -1;
12705 } else if (os_strncmp((buf + 11), "DEL_MAC ", 8) == 0) {
12706 if (ap_ctrl_iface_acl_del_mac(wpa_s,
12707 DENY_UNLESS_ACCEPTED,
12708 buf + 19) ||
12709 ap_ctrl_iface_set_acl(wpa_s) ||
12710 ap_ctrl_iface_disassoc_accept_mac(wpa_s))
12711 reply_len = -1;
12712 } else if (os_strcmp(buf + 11, "SHOW") == 0) {
12713 reply_len = ap_ctrl_iface_acl_show_mac(
12714 wpa_s, DENY_UNLESS_ACCEPTED,
12715 reply, reply_size);
12716 } else if (os_strcmp(buf + 11, "CLEAR") == 0) {
12717 ap_ctrl_iface_acl_clear_list(wpa_s,
12718 DENY_UNLESS_ACCEPTED);
12719 if (ap_ctrl_iface_set_acl(wpa_s) ||
12720 ap_ctrl_iface_disassoc_accept_mac(wpa_s))
12721 reply_len = -1;
12722 } else {
12723 reply_len = -1;
12724 }
12725 } else if (os_strncmp(buf, "DENY_ACL ", 9) == 0) {
12726 if (os_strncmp(buf + 9, "ADD_MAC ", 8) == 0) {
12727 if (ap_ctrl_iface_acl_add_mac(wpa_s,
12728 ACCEPT_UNLESS_DENIED,
12729 buf + 17) ||
12730 ap_ctrl_iface_set_acl(wpa_s) ||
12731 ap_ctrl_iface_disassoc_deny_mac(wpa_s))
12732 reply_len = -1;
12733 } else if (os_strncmp(buf + 9, "DEL_MAC ", 8) == 0) {
12734 if (ap_ctrl_iface_acl_del_mac(wpa_s,
12735 ACCEPT_UNLESS_DENIED,
12736 buf + 17) ||
12737 ap_ctrl_iface_set_acl(wpa_s))
12738 reply_len = -1;
12739 } else if (os_strcmp(buf + 9, "SHOW") == 0) {
12740 reply_len = ap_ctrl_iface_acl_show_mac(
12741 wpa_s, ACCEPT_UNLESS_DENIED, reply, reply_size);
12742 } else if (os_strcmp(buf + 9, "CLEAR") == 0) {
12743 ap_ctrl_iface_acl_clear_list(wpa_s,
12744 ACCEPT_UNLESS_DENIED);
12745 if (ap_ctrl_iface_set_acl(wpa_s))
12746 reply_len = -1;
12747 } else {
12748 reply_len = -1;
12749 }
12750 #endif /* CONFIG_AP */
12751 } else if (os_strcmp(buf, "SUSPEND") == 0) {
12752 wpas_notify_suspend(wpa_s->global);
12753 } else if (os_strcmp(buf, "RESUME") == 0) {
12754 wpas_notify_resume(wpa_s->global);
12755 #ifdef CONFIG_TESTING_OPTIONS
12756 } else if (os_strcmp(buf, "DROP_SA") == 0) {
12757 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
12758 #endif /* CONFIG_TESTING_OPTIONS */
12759 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
12760 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
12761 reply_len = -1;
12762 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
12763 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
12764 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
12765 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
12766 reply_len = -1;
12767 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
12768 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
12769 buf + 17))
12770 reply_len = -1;
12771 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
12772 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
12773 #ifdef CONFIG_TDLS
12774 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
12775 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
12776 reply_len = -1;
12777 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
12778 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
12779 reply_len = -1;
12780 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
12781 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
12782 reply_len = -1;
12783 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
12784 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
12785 buf + 17))
12786 reply_len = -1;
12787 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
12788 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
12789 buf + 24))
12790 reply_len = -1;
12791 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
12792 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
12793 wpa_s, buf + 17, reply, reply_size);
12794 #endif /* CONFIG_TDLS */
12795 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
12796 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
12797 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
12798 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
12799 reply_len = -1;
12800 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
12801 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
12802 reply_len = -1;
12803 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
12804 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
12805 reply_size);
12806 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
12807 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
12808 reply_len = -1;
12809 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
12810 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
12811 reply_size);
12812 #ifdef CONFIG_AUTOSCAN
12813 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
12814 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
12815 reply_len = -1;
12816 #endif /* CONFIG_AUTOSCAN */
12817 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
12818 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
12819 reply_size);
12820 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
12821 reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply,
12822 reply_size);
12823 #ifdef ANDROID
12824 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
12825 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
12826 reply_size);
12827 #endif /* ANDROID */
12828 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
12829 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
12830 reply_size);
12831 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
12832 pmksa_cache_clear_current(wpa_s->wpa);
12833 eapol_sm_request_reauth(wpa_s->eapol);
12834 #ifdef CONFIG_WNM
12835 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
12836 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
12837 reply_len = -1;
12838 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
12839 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
12840 reply_len = -1;
12841 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
12842 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
12843 reply_len = -1;
12844 #endif /* CONFIG_WNM */
12845 #ifdef CONFIG_WNM_AP
12846 } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
12847 if (ap_ctrl_iface_disassoc_imminent(wpa_s, buf + 18))
12848 reply_len = -1;
12849 } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
12850 if (ap_ctrl_iface_ess_disassoc(wpa_s, buf + 13))
12851 reply_len = -1;
12852 } else if (os_strncmp(buf, "BSS_TM_REQ ", 11) == 0) {
12853 if (ap_ctrl_iface_bss_tm_req(wpa_s, buf + 11))
12854 reply_len = -1;
12855 #endif /* CONFIG_WNM_AP */
12856 } else if (os_strcmp(buf, "FLUSH") == 0) {
12857 wpa_supplicant_ctrl_iface_flush(wpa_s);
12858 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
12859 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
12860 reply_size);
12861 #ifdef CONFIG_TESTING_OPTIONS
12862 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
12863 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
12864 reply_len = -1;
12865 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
12866 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
12867 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
12868 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
12869 reply_len = -1;
12870 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
12871 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
12872 reply_len = -1;
12873 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
12874 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
12875 reply_len = -1;
12876 } else if (os_strncmp(buf, "EAPOL_TX ", 9) == 0) {
12877 if (wpas_ctrl_iface_eapol_tx(wpa_s, buf + 9) < 0)
12878 reply_len = -1;
12879 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
12880 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
12881 reply_len = -1;
12882 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
12883 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
12884 reply_len = -1;
12885 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
12886 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
12887 reply_len = -1;
12888 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
12889 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
12890 reply_len = -1;
12891 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
12892 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
12893 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
12894 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
12895 reply_len = -1;
12896 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
12897 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
12898 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
12899 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
12900 reply_len = -1;
12901 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
12902 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
12903 reply_len = -1;
12904 } else if (os_strcmp(buf, "RESET_PN") == 0) {
12905 if (wpas_ctrl_reset_pn(wpa_s) < 0)
12906 reply_len = -1;
12907 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
12908 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
12909 reply_len = -1;
12910 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
12911 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
12912 reply_len = -1;
12913 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
12914 sme_event_unprot_disconnect(
12915 wpa_s, wpa_s->bssid, NULL,
12916 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
12917 } else if (os_strncmp(buf, "TWT_SETUP ", 10) == 0) {
12918 if (wpas_ctrl_iface_send_twt_setup(wpa_s, buf + 9))
12919 reply_len = -1;
12920 } else if (os_strcmp(buf, "TWT_SETUP") == 0) {
12921 if (wpas_ctrl_iface_send_twt_setup(wpa_s, ""))
12922 reply_len = -1;
12923 } else if (os_strncmp(buf, "TWT_TEARDOWN ", 13) == 0) {
12924 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, buf + 12))
12925 reply_len = -1;
12926 } else if (os_strcmp(buf, "TWT_TEARDOWN") == 0) {
12927 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, ""))
12928 reply_len = -1;
12929 } else if (os_strncmp(buf, "ML_PROBE_REQ ", 13) == 0) {
12930 if (wpas_ctrl_ml_probe(wpa_s, buf + 13))
12931 reply_len = -1;
12932 #endif /* CONFIG_TESTING_OPTIONS */
12933 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
12934 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
12935 reply_len = -1;
12936 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
12937 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
12938 reply_size);
12939 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
12940 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
12941 reply_len = -1;
12942 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
12943 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
12944 reply_len = -1;
12945 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
12946 wpas_ctrl_iface_erp_flush(wpa_s);
12947 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
12948 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
12949 reply_len = -1;
12950 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
12951 reply_len = wpas_ctrl_iface_get_pref_freq_list(
12952 wpa_s, buf + 19, reply, reply_size);
12953 #ifdef CONFIG_FILS
12954 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
12955 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
12956 reply_len = -1;
12957 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
12958 wpas_flush_fils_hlp_req(wpa_s);
12959 #endif /* CONFIG_FILS */
12960 #ifdef CONFIG_DPP
12961 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
12962 int res;
12963
12964 res = wpas_dpp_qr_code(wpa_s, buf + 12);
12965 if (res < 0) {
12966 reply_len = -1;
12967 } else {
12968 reply_len = os_snprintf(reply, reply_size, "%d", res);
12969 if (os_snprintf_error(reply_size, reply_len))
12970 reply_len = -1;
12971 }
12972 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
12973 int res;
12974
12975 res = wpas_dpp_nfc_uri(wpa_s, buf + 12);
12976 if (res < 0) {
12977 reply_len = -1;
12978 } else {
12979 reply_len = os_snprintf(reply, reply_size, "%d", res);
12980 if (os_snprintf_error(reply_size, reply_len))
12981 reply_len = -1;
12982 }
12983 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
12984 int res;
12985
12986 res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20);
12987 if (res < 0) {
12988 reply_len = -1;
12989 } else {
12990 reply_len = os_snprintf(reply, reply_size, "%d", res);
12991 if (os_snprintf_error(reply_size, reply_len))
12992 reply_len = -1;
12993 }
12994 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
12995 int res;
12996
12997 res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20);
12998 if (res < 0) {
12999 reply_len = -1;
13000 } else {
13001 reply_len = os_snprintf(reply, reply_size, "%d", res);
13002 if (os_snprintf_error(reply_size, reply_len))
13003 reply_len = -1;
13004 }
13005 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
13006 int res;
13007
13008 res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18);
13009 if (res < 0) {
13010 reply_len = -1;
13011 } else {
13012 reply_len = os_snprintf(reply, reply_size, "%d", res);
13013 if (os_snprintf_error(reply_size, reply_len))
13014 reply_len = -1;
13015 }
13016 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
13017 if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0)
13018 reply_len = -1;
13019 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
13020 const char *uri;
13021
13022 uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22));
13023 if (!uri) {
13024 reply_len = -1;
13025 } else {
13026 reply_len = os_snprintf(reply, reply_size, "%s", uri);
13027 if (os_snprintf_error(reply_size, reply_len))
13028 reply_len = -1;
13029 }
13030 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
13031 reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19),
13032 reply, reply_size);
13033 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
13034 if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18),
13035 os_strchr(buf + 18, ' ')) < 0)
13036 reply_len = -1;
13037 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
13038 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
13039 reply_len = -1;
13040 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
13041 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
13042 reply_len = -1;
13043 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
13044 wpas_dpp_stop(wpa_s);
13045 wpas_dpp_listen_stop(wpa_s);
13046 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
13047 int res;
13048
13049 res = dpp_configurator_add(wpa_s->dpp, buf + 20);
13050 if (res < 0) {
13051 reply_len = -1;
13052 } else {
13053 reply_len = os_snprintf(reply, reply_size, "%d", res);
13054 if (os_snprintf_error(reply_size, reply_len))
13055 reply_len = -1;
13056 }
13057 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SET ", 21) == 0) {
13058 if (dpp_configurator_set(wpa_s->dpp, buf + 20) < 0)
13059 reply_len = -1;
13060 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
13061 if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0)
13062 reply_len = -1;
13063 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
13064 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
13065 reply_len = -1;
13066 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
13067 reply_len = dpp_configurator_get_key_id(wpa_s->dpp,
13068 atoi(buf + 25),
13069 reply, reply_size);
13070 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
13071 int res;
13072
13073 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
13074 if (res < 0) {
13075 reply_len = -1;
13076 } else {
13077 reply_len = os_snprintf(reply, reply_size, "%d", res);
13078 if (os_snprintf_error(reply_size, reply_len))
13079 reply_len = -1;
13080 }
13081 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
13082 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
13083 reply_len = -1;
13084 } else if (os_strncmp(buf, "DPP_CONF_SET ", 13) == 0) {
13085 if (wpas_dpp_conf_set(wpa_s, buf + 12) < 0)
13086 reply_len = -1;
13087 #ifdef CONFIG_DPP2
13088 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
13089 if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0)
13090 reply_len = -1;
13091 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
13092 if (wpas_dpp_controller_start(wpa_s, NULL) < 0)
13093 reply_len = -1;
13094 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
13095 dpp_controller_stop(wpa_s->dpp);
13096 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
13097 if (wpas_dpp_chirp(wpa_s, buf + 9) < 0)
13098 reply_len = -1;
13099 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
13100 wpas_dpp_chirp_stop(wpa_s);
13101 } else if (os_strncmp(buf, "DPP_RECONFIG ", 13) == 0) {
13102 if (wpas_dpp_reconfig(wpa_s, buf + 13) < 0)
13103 reply_len = -1;
13104 } else if (os_strncmp(buf, "DPP_CA_SET ", 11) == 0) {
13105 if (wpas_dpp_ca_set(wpa_s, buf + 10) < 0)
13106 reply_len = -1;
13107 #endif /* CONFIG_DPP2 */
13108 #ifdef CONFIG_DPP3
13109 } else if (os_strcmp(buf, "DPP_PUSH_BUTTON") == 0) {
13110 if (wpas_dpp_push_button(wpa_s, NULL) < 0)
13111 reply_len = -1;
13112 } else if (os_strncmp(buf, "DPP_PUSH_BUTTON ", 16) == 0) {
13113 if (wpas_dpp_push_button(wpa_s, buf + 15) < 0)
13114 reply_len = -1;
13115 #endif /* CONFIG_DPP3 */
13116 #endif /* CONFIG_DPP */
13117 } else if (os_strncmp(buf, "MSCS ", 5) == 0) {
13118 if (wpas_ctrl_iface_configure_mscs(wpa_s, buf + 5))
13119 reply_len = -1;
13120 #ifdef CONFIG_PASN
13121 } else if (os_strncmp(buf, "PASN_START ", 11) == 0) {
13122 if (wpas_ctrl_iface_pasn_start(wpa_s, buf + 11) < 0)
13123 reply_len = -1;
13124 } else if (os_strcmp(buf, "PASN_STOP") == 0) {
13125 wpas_pasn_auth_stop(wpa_s);
13126 } else if (os_strcmp(buf, "PTKSA_CACHE_LIST") == 0) {
13127 reply_len = ptksa_cache_list(wpa_s->ptksa, reply, reply_size);
13128 } else if (os_strncmp(buf, "PASN_DEAUTH ", 12) == 0) {
13129 if (wpas_ctrl_iface_pasn_deauthenticate(wpa_s, buf + 12) < 0)
13130 reply_len = -1;
13131 #endif /* CONFIG_PASN */
13132 } else if (os_strncmp(buf, "SCS ", 4) == 0) {
13133 if (wpas_ctrl_iface_configure_scs(wpa_s, buf + 4))
13134 reply_len = -1;
13135 } else if (os_strncmp(buf, "DSCP_RESP ", 10) == 0) {
13136 if (wpas_ctrl_iface_send_dscp_resp(wpa_s, buf + 10))
13137 reply_len = -1;
13138 } else if (os_strncmp(buf, "DSCP_QUERY ", 11) == 0) {
13139 if (wpas_ctrl_iface_send_dscp_query(wpa_s, buf + 11))
13140 reply_len = -1;
13141 } else if (os_strcmp(buf, "MLO_STATUS") == 0) {
13142 reply_len = wpas_ctrl_iface_mlo_status(wpa_s, reply,
13143 reply_size);
13144 } else if (os_strcmp(buf, "MLO_SIGNAL_POLL") == 0) {
13145 reply_len = wpas_ctrl_iface_mlo_signal_poll(wpa_s, reply,
13146 reply_size);
13147 } else {
13148 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
13149 reply_len = 16;
13150 }
13151
13152 if (reply_len < 0) {
13153 os_memcpy(reply, "FAIL\n", 5);
13154 reply_len = 5;
13155 }
13156
13157 *resp_len = reply_len;
13158 return reply;
13159 }
13160
13161
wpa_supplicant_global_iface_add(struct wpa_global * global,char * cmd)13162 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
13163 char *cmd)
13164 {
13165 struct wpa_interface iface;
13166 char *pos, *extra;
13167 struct wpa_supplicant *wpa_s;
13168 unsigned int create_iface = 0;
13169 u8 mac_addr[ETH_ALEN];
13170 enum wpa_driver_if_type type = WPA_IF_STATION;
13171
13172 /*
13173 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
13174 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
13175 */
13176 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
13177
13178 os_memset(&iface, 0, sizeof(iface));
13179
13180 do {
13181 iface.ifname = pos = cmd;
13182 pos = os_strchr(pos, '\t');
13183 if (pos)
13184 *pos++ = '\0';
13185 if (iface.ifname[0] == '\0')
13186 return -1;
13187 if (pos == NULL)
13188 break;
13189
13190 iface.confname = pos;
13191 pos = os_strchr(pos, '\t');
13192 if (pos)
13193 *pos++ = '\0';
13194 if (iface.confname[0] == '\0')
13195 iface.confname = NULL;
13196 if (pos == NULL)
13197 break;
13198
13199 iface.driver = pos;
13200 pos = os_strchr(pos, '\t');
13201 if (pos)
13202 *pos++ = '\0';
13203 if (iface.driver[0] == '\0')
13204 iface.driver = NULL;
13205 if (pos == NULL)
13206 break;
13207
13208 iface.ctrl_interface = pos;
13209 pos = os_strchr(pos, '\t');
13210 if (pos)
13211 *pos++ = '\0';
13212 if (iface.ctrl_interface[0] == '\0')
13213 iface.ctrl_interface = NULL;
13214 if (pos == NULL)
13215 break;
13216
13217 iface.driver_param = pos;
13218 pos = os_strchr(pos, '\t');
13219 if (pos)
13220 *pos++ = '\0';
13221 if (iface.driver_param[0] == '\0')
13222 iface.driver_param = NULL;
13223 if (pos == NULL)
13224 break;
13225
13226 iface.bridge_ifname = pos;
13227 pos = os_strchr(pos, '\t');
13228 if (pos)
13229 *pos++ = '\0';
13230 if (iface.bridge_ifname[0] == '\0')
13231 iface.bridge_ifname = NULL;
13232 if (pos == NULL)
13233 break;
13234
13235 extra = pos;
13236 pos = os_strchr(pos, '\t');
13237 if (pos)
13238 *pos++ = '\0';
13239 if (!extra[0])
13240 break;
13241
13242 if (os_strcmp(extra, "create") == 0) {
13243 create_iface = 1;
13244 if (!pos)
13245 break;
13246
13247 if (os_strcmp(pos, "sta") == 0) {
13248 type = WPA_IF_STATION;
13249 } else if (os_strcmp(pos, "ap") == 0) {
13250 type = WPA_IF_AP_BSS;
13251 } else {
13252 wpa_printf(MSG_DEBUG,
13253 "INTERFACE_ADD unsupported interface type: '%s'",
13254 pos);
13255 return -1;
13256 }
13257 } else {
13258 wpa_printf(MSG_DEBUG,
13259 "INTERFACE_ADD unsupported extra parameter: '%s'",
13260 extra);
13261 return -1;
13262 }
13263 } while (0);
13264
13265 if (create_iface) {
13266 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
13267 iface.ifname);
13268 if (!global->ifaces)
13269 return -1;
13270 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
13271 NULL, NULL, NULL, mac_addr, NULL) < 0) {
13272 wpa_printf(MSG_ERROR,
13273 "CTRL_IFACE interface creation failed");
13274 return -1;
13275 }
13276
13277 wpa_printf(MSG_DEBUG,
13278 "CTRL_IFACE interface '%s' created with MAC addr: "
13279 MACSTR, iface.ifname, MAC2STR(mac_addr));
13280 }
13281
13282 if (wpa_supplicant_get_iface(global, iface.ifname))
13283 goto fail;
13284
13285 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
13286 if (!wpa_s)
13287 goto fail;
13288 wpa_s->added_vif = create_iface;
13289 return 0;
13290
13291 fail:
13292 if (create_iface) {
13293 /* wpa_supplicant does not create multi-BSS AP, so collapse to
13294 * WPA_IF_STATION to avoid unwanted clean up in the driver. */
13295 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
13296 }
13297 return -1;
13298 }
13299
13300
wpa_supplicant_global_iface_remove(struct wpa_global * global,char * cmd)13301 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
13302 char *cmd)
13303 {
13304 struct wpa_supplicant *wpa_s;
13305 int ret;
13306 unsigned int delete_iface;
13307
13308 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
13309
13310 wpa_s = wpa_supplicant_get_iface(global, cmd);
13311 if (wpa_s == NULL)
13312 return -1;
13313 delete_iface = wpa_s->added_vif;
13314 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
13315 if (!ret && delete_iface) {
13316 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
13317 cmd);
13318 /* wpa_supplicant does not create multi-BSS AP, so collapse to
13319 * WPA_IF_STATION to avoid unwanted clean up in the driver. */
13320 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
13321 }
13322 return ret;
13323 }
13324
13325
wpa_free_iface_info(struct wpa_interface_info * iface)13326 static void wpa_free_iface_info(struct wpa_interface_info *iface)
13327 {
13328 struct wpa_interface_info *prev;
13329
13330 while (iface) {
13331 prev = iface;
13332 iface = iface->next;
13333
13334 os_free(prev->ifname);
13335 os_free(prev->desc);
13336 os_free(prev);
13337 }
13338 }
13339
13340
wpa_supplicant_global_iface_list(struct wpa_global * global,char * buf,int len)13341 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
13342 char *buf, int len)
13343 {
13344 int i, res;
13345 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
13346 char *pos, *end;
13347
13348 for (i = 0; wpa_drivers[i]; i++) {
13349 const struct wpa_driver_ops *drv = wpa_drivers[i];
13350 if (drv->get_interfaces == NULL)
13351 continue;
13352 tmp = drv->get_interfaces(global->drv_priv[i]);
13353 if (tmp == NULL)
13354 continue;
13355
13356 if (last == NULL)
13357 iface = last = tmp;
13358 else
13359 last->next = tmp;
13360 while (last->next)
13361 last = last->next;
13362 }
13363
13364 pos = buf;
13365 end = buf + len;
13366 for (tmp = iface; tmp; tmp = tmp->next) {
13367 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
13368 tmp->drv_name, tmp->ifname,
13369 tmp->desc ? tmp->desc : "");
13370 if (os_snprintf_error(end - pos, res)) {
13371 *pos = '\0';
13372 break;
13373 }
13374 pos += res;
13375 }
13376
13377 wpa_free_iface_info(iface);
13378
13379 return pos - buf;
13380 }
13381
13382
wpa_supplicant_global_iface_interfaces(struct wpa_global * global,const char * input,char * buf,int len)13383 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
13384 const char *input,
13385 char *buf, int len)
13386 {
13387 int res;
13388 char *pos, *end;
13389 struct wpa_supplicant *wpa_s;
13390 int show_ctrl = 0;
13391
13392 if (input)
13393 show_ctrl = !!os_strstr(input, "ctrl");
13394
13395 wpa_s = global->ifaces;
13396 pos = buf;
13397 end = buf + len;
13398
13399 while (wpa_s) {
13400 if (show_ctrl)
13401 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
13402 wpa_s->ifname,
13403 wpa_s->conf->ctrl_interface ?
13404 wpa_s->conf->ctrl_interface : "N/A");
13405 else
13406 res = os_snprintf(pos, end - pos, "%s\n",
13407 wpa_s->ifname);
13408
13409 if (os_snprintf_error(end - pos, res)) {
13410 *pos = '\0';
13411 break;
13412 }
13413 pos += res;
13414 wpa_s = wpa_s->next;
13415 }
13416 return pos - buf;
13417 }
13418
13419
wpas_global_ctrl_iface_ifname(struct wpa_global * global,const char * ifname,char * cmd,size_t * resp_len)13420 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
13421 const char *ifname,
13422 char *cmd, size_t *resp_len)
13423 {
13424 struct wpa_supplicant *wpa_s;
13425
13426 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
13427 if (os_strcmp(ifname, wpa_s->ifname) == 0)
13428 break;
13429 }
13430
13431 if (wpa_s == NULL) {
13432 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
13433 if (resp)
13434 *resp_len = os_strlen(resp);
13435 else
13436 *resp_len = 1;
13437 return resp;
13438 }
13439
13440 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
13441 }
13442
13443
wpas_global_ctrl_iface_redir_p2p(struct wpa_global * global,char * buf,size_t * resp_len)13444 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
13445 char *buf, size_t *resp_len)
13446 {
13447 #ifdef CONFIG_P2P
13448 static const char * cmd[] = {
13449 "LIST_NETWORKS",
13450 "P2P_FIND",
13451 "P2P_STOP_FIND",
13452 "P2P_LISTEN",
13453 "P2P_GROUP_ADD",
13454 "P2P_GET_PASSPHRASE",
13455 "P2P_SERVICE_UPDATE",
13456 "P2P_SERVICE_FLUSH",
13457 "P2P_FLUSH",
13458 "P2P_CANCEL",
13459 "P2P_PRESENCE_REQ",
13460 "P2P_EXT_LISTEN",
13461 #ifdef CONFIG_AP
13462 "STA-FIRST",
13463 #endif /* CONFIG_AP */
13464 NULL
13465 };
13466 static const char * prefix[] = {
13467 #ifdef ANDROID
13468 "DRIVER ",
13469 #endif /* ANDROID */
13470 "GET_CAPABILITY ",
13471 "GET_NETWORK ",
13472 "REMOVE_NETWORK ",
13473 "P2P_FIND ",
13474 "P2P_CONNECT ",
13475 "P2P_LISTEN ",
13476 "P2P_GROUP_REMOVE ",
13477 "P2P_GROUP_ADD ",
13478 "P2P_GROUP_MEMBER ",
13479 "P2P_PROV_DISC ",
13480 "P2P_SERV_DISC_REQ ",
13481 "P2P_SERV_DISC_CANCEL_REQ ",
13482 "P2P_SERV_DISC_RESP ",
13483 "P2P_SERV_DISC_EXTERNAL ",
13484 "P2P_SERVICE_ADD ",
13485 "P2P_SERVICE_DEL ",
13486 "P2P_SERVICE_REP ",
13487 "P2P_REJECT ",
13488 "P2P_INVITE ",
13489 "P2P_PEER ",
13490 "P2P_SET ",
13491 "P2P_UNAUTHORIZE ",
13492 "P2P_PRESENCE_REQ ",
13493 "P2P_EXT_LISTEN ",
13494 "P2P_REMOVE_CLIENT ",
13495 "WPS_NFC_TOKEN ",
13496 "WPS_NFC_TAG_READ ",
13497 "NFC_GET_HANDOVER_SEL ",
13498 "NFC_GET_HANDOVER_REQ ",
13499 "NFC_REPORT_HANDOVER ",
13500 "P2P_ASP_PROVISION ",
13501 "P2P_ASP_PROVISION_RESP ",
13502 #ifdef CONFIG_AP
13503 "STA ",
13504 "STA-NEXT ",
13505 #endif /* CONFIG_AP */
13506 NULL
13507 };
13508 int found = 0;
13509 int i;
13510
13511 if (global->p2p_init_wpa_s == NULL)
13512 return NULL;
13513
13514 for (i = 0; !found && cmd[i]; i++) {
13515 if (os_strcmp(buf, cmd[i]) == 0)
13516 found = 1;
13517 }
13518
13519 for (i = 0; !found && prefix[i]; i++) {
13520 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
13521 found = 1;
13522 }
13523
13524 if (found)
13525 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
13526 buf, resp_len);
13527 #endif /* CONFIG_P2P */
13528 return NULL;
13529 }
13530
13531
wpas_global_ctrl_iface_redir_wfd(struct wpa_global * global,char * buf,size_t * resp_len)13532 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
13533 char *buf, size_t *resp_len)
13534 {
13535 #ifdef CONFIG_WIFI_DISPLAY
13536 if (global->p2p_init_wpa_s == NULL)
13537 return NULL;
13538 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
13539 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
13540 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
13541 buf, resp_len);
13542 #endif /* CONFIG_WIFI_DISPLAY */
13543 return NULL;
13544 }
13545
13546
wpas_global_ctrl_iface_redir(struct wpa_global * global,char * buf,size_t * resp_len)13547 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
13548 char *buf, size_t *resp_len)
13549 {
13550 char *ret;
13551
13552 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
13553 if (ret)
13554 return ret;
13555
13556 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
13557 if (ret)
13558 return ret;
13559
13560 return NULL;
13561 }
13562
13563
wpas_global_ctrl_iface_set(struct wpa_global * global,char * cmd)13564 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
13565 {
13566 char *value;
13567
13568 value = os_strchr(cmd, ' ');
13569 if (value == NULL)
13570 return -1;
13571 *value++ = '\0';
13572
13573 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
13574
13575 #ifdef CONFIG_WIFI_DISPLAY
13576 if (os_strcasecmp(cmd, "wifi_display") == 0) {
13577 wifi_display_enable(global, !!atoi(value));
13578 return 0;
13579 }
13580 #endif /* CONFIG_WIFI_DISPLAY */
13581
13582 /* Restore cmd to its original value to allow redirection */
13583 value[-1] = ' ';
13584
13585 return -1;
13586 }
13587
13588
wpas_global_ctrl_iface_dup_network(struct wpa_global * global,char * cmd)13589 static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
13590 char *cmd)
13591 {
13592 struct wpa_supplicant *wpa_s[2]; /* src, dst */
13593 char *p;
13594 unsigned int i;
13595
13596 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
13597 * <variable name> */
13598
13599 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
13600 p = os_strchr(cmd, ' ');
13601 if (p == NULL)
13602 return -1;
13603 *p = '\0';
13604
13605 wpa_s[i] = global->ifaces;
13606 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
13607 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
13608 break;
13609 }
13610
13611 if (!wpa_s[i]) {
13612 wpa_printf(MSG_DEBUG,
13613 "CTRL_IFACE: Could not find iface=%s", cmd);
13614 return -1;
13615 }
13616
13617 cmd = p + 1;
13618 }
13619
13620 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
13621 }
13622
13623
13624 #ifndef CONFIG_NO_CONFIG_WRITE
wpas_global_ctrl_iface_save_config(struct wpa_global * global)13625 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
13626 {
13627 int ret = 0, saved = 0;
13628 struct wpa_supplicant *wpa_s;
13629
13630 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
13631 if (!wpa_s->conf->update_config) {
13632 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
13633 continue;
13634 }
13635
13636 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
13637 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
13638 ret = 1;
13639 } else {
13640 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
13641 saved++;
13642 }
13643 }
13644
13645 if (!saved && !ret) {
13646 wpa_dbg(wpa_s, MSG_DEBUG,
13647 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
13648 ret = 1;
13649 }
13650
13651 return ret;
13652 }
13653 #endif /* CONFIG_NO_CONFIG_WRITE */
13654
13655
wpas_global_ctrl_iface_status(struct wpa_global * global,char * buf,size_t buflen)13656 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
13657 char *buf, size_t buflen)
13658 {
13659 char *pos, *end;
13660 int ret;
13661 struct wpa_supplicant *wpa_s;
13662
13663 pos = buf;
13664 end = buf + buflen;
13665
13666 #ifdef CONFIG_P2P
13667 if (global->p2p && !global->p2p_disabled) {
13668 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
13669 "\n"
13670 "p2p_state=%s\n",
13671 MAC2STR(global->p2p_dev_addr),
13672 p2p_get_state_txt(global->p2p));
13673 if (os_snprintf_error(end - pos, ret))
13674 return pos - buf;
13675 pos += ret;
13676 } else if (global->p2p) {
13677 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
13678 if (os_snprintf_error(end - pos, ret))
13679 return pos - buf;
13680 pos += ret;
13681 }
13682 #endif /* CONFIG_P2P */
13683
13684 #ifdef CONFIG_WIFI_DISPLAY
13685 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
13686 !!global->wifi_display);
13687 if (os_snprintf_error(end - pos, ret))
13688 return pos - buf;
13689 pos += ret;
13690 #endif /* CONFIG_WIFI_DISPLAY */
13691
13692 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
13693 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
13694 "address=" MACSTR "\n",
13695 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
13696 if (os_snprintf_error(end - pos, ret))
13697 return pos - buf;
13698 pos += ret;
13699 }
13700
13701 return pos - buf;
13702 }
13703
13704
13705 #ifdef CONFIG_FST
13706
wpas_global_ctrl_iface_fst_attach(struct wpa_global * global,char * cmd,char * buf,size_t reply_size)13707 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
13708 char *cmd, char *buf,
13709 size_t reply_size)
13710 {
13711 char ifname[IFNAMSIZ + 1];
13712 struct fst_iface_cfg cfg;
13713 struct wpa_supplicant *wpa_s;
13714 struct fst_wpa_obj iface_obj;
13715
13716 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
13717 wpa_s = wpa_supplicant_get_iface(global, ifname);
13718 if (wpa_s) {
13719 if (wpa_s->fst) {
13720 wpa_printf(MSG_INFO, "FST: Already attached");
13721 return -1;
13722 }
13723 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
13724 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
13725 &iface_obj, &cfg);
13726 if (wpa_s->fst)
13727 return os_snprintf(buf, reply_size, "OK\n");
13728 }
13729 }
13730
13731 return -1;
13732 }
13733
13734
wpas_global_ctrl_iface_fst_detach(struct wpa_global * global,char * cmd,char * buf,size_t reply_size)13735 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
13736 char *cmd, char *buf,
13737 size_t reply_size)
13738 {
13739 char ifname[IFNAMSIZ + 1];
13740 struct wpa_supplicant *wpa_s;
13741
13742 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
13743 wpa_s = wpa_supplicant_get_iface(global, ifname);
13744 if (wpa_s) {
13745 if (!fst_iface_detach(ifname)) {
13746 wpa_s->fst = NULL;
13747 return os_snprintf(buf, reply_size, "OK\n");
13748 }
13749 }
13750 }
13751
13752 return -1;
13753 }
13754
13755 #endif /* CONFIG_FST */
13756
13757
wpa_supplicant_global_ctrl_iface_process(struct wpa_global * global,char * buf,size_t * resp_len)13758 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
13759 char *buf, size_t *resp_len)
13760 {
13761 char *reply;
13762 const int reply_size = 2048;
13763 int reply_len;
13764 int level = MSG_DEBUG;
13765
13766 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
13767 char *pos = os_strchr(buf + 7, ' ');
13768 if (pos) {
13769 *pos++ = '\0';
13770 return wpas_global_ctrl_iface_ifname(global,
13771 buf + 7, pos,
13772 resp_len);
13773 }
13774 }
13775
13776 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
13777 if (reply)
13778 return reply;
13779
13780 if (os_strcmp(buf, "PING") == 0)
13781 level = MSG_EXCESSIVE;
13782 wpa_hexdump_ascii(level, "RX global ctrl_iface",
13783 (const u8 *) buf, os_strlen(buf));
13784
13785 reply = os_malloc(reply_size);
13786 if (reply == NULL) {
13787 *resp_len = 1;
13788 return NULL;
13789 }
13790
13791 os_memcpy(reply, "OK\n", 3);
13792 reply_len = 3;
13793
13794 if (os_strcmp(buf, "PING") == 0) {
13795 os_memcpy(reply, "PONG\n", 5);
13796 reply_len = 5;
13797 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
13798 if (wpa_supplicant_global_iface_add(global, buf + 14))
13799 reply_len = -1;
13800 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
13801 if (wpa_supplicant_global_iface_remove(global, buf + 17))
13802 reply_len = -1;
13803 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
13804 reply_len = wpa_supplicant_global_iface_list(
13805 global, reply, reply_size);
13806 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
13807 reply_len = wpa_supplicant_global_iface_interfaces(
13808 global, buf + 10, reply, reply_size);
13809 #ifdef CONFIG_FST
13810 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
13811 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
13812 reply,
13813 reply_size);
13814 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
13815 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
13816 reply,
13817 reply_size);
13818 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
13819 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
13820 #endif /* CONFIG_FST */
13821 } else if (os_strcmp(buf, "TERMINATE") == 0) {
13822 wpa_supplicant_terminate_proc(global);
13823 } else if (os_strcmp(buf, "SUSPEND") == 0) {
13824 wpas_notify_suspend(global);
13825 } else if (os_strcmp(buf, "RESUME") == 0) {
13826 wpas_notify_resume(global);
13827 } else if (os_strncmp(buf, "SET ", 4) == 0) {
13828 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
13829 #ifdef CONFIG_P2P
13830 if (global->p2p_init_wpa_s) {
13831 os_free(reply);
13832 /* Check if P2P redirection would work for this
13833 * command. */
13834 return wpa_supplicant_ctrl_iface_process(
13835 global->p2p_init_wpa_s,
13836 buf, resp_len);
13837 }
13838 #endif /* CONFIG_P2P */
13839 reply_len = -1;
13840 }
13841 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
13842 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
13843 reply_len = -1;
13844 #ifndef CONFIG_NO_CONFIG_WRITE
13845 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
13846 if (wpas_global_ctrl_iface_save_config(global))
13847 reply_len = -1;
13848 #endif /* CONFIG_NO_CONFIG_WRITE */
13849 } else if (os_strcmp(buf, "STATUS") == 0) {
13850 reply_len = wpas_global_ctrl_iface_status(global, reply,
13851 reply_size);
13852 #ifdef CONFIG_MODULE_TESTS
13853 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
13854 if (wpas_module_tests() < 0)
13855 reply_len = -1;
13856 #endif /* CONFIG_MODULE_TESTS */
13857 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
13858 if (wpa_debug_reopen_file() < 0)
13859 reply_len = -1;
13860 } else {
13861 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
13862 reply_len = 16;
13863 }
13864
13865 if (reply_len < 0) {
13866 os_memcpy(reply, "FAIL\n", 5);
13867 reply_len = 5;
13868 }
13869
13870 *resp_len = reply_len;
13871 return reply;
13872 }
13873