blob: 500f4d1b5ece54fa2b897deb82af8bc422e5f4ad [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant / Control interface (shared code for all backends)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003 * Copyright (c) 2004-2024, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011#include <netinet/ip.h>
12#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013
14#include "utils/common.h"
15#include "utils/eloop.h"
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080016#include "utils/uuid.h"
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -070017#include "utils/module_tests.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include "common/version.h"
19#include "common/ieee802_11_defs.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070020#include "common/ieee802_11_common.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070021#include "common/wpa_ctrl.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070022#ifdef CONFIG_DPP
23#include "common/dpp.h"
24#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +000025#include "common/nan_de.h"
Hai Shalom60840252021-02-19 19:02:11 -080026#include "common/ptksa_cache.h"
Dmitry Shmidtff787d52015-01-12 13:01:47 -080027#include "crypto/tls.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080028#include "ap/hostapd.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070029#include "eap_peer/eap.h"
30#include "eapol_supp/eapol_supp_sm.h"
31#include "rsn_supp/wpa.h"
32#include "rsn_supp/preauth.h"
33#include "rsn_supp/pmksa_cache.h"
34#include "l2_packet/l2_packet.h"
35#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080036#include "fst/fst.h"
37#include "fst/fst_ctrl_iface.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070038#include "config.h"
39#include "wpa_supplicant_i.h"
40#include "driver_i.h"
41#include "wps_supplicant.h"
42#include "ibss_rsn.h"
Hai Shaloma20dcd72022-02-04 13:43:00 -080043#include "wpas_glue.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044#include "ap.h"
45#include "p2p_supplicant.h"
46#include "p2p/p2p.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070047#include "hs20_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070048#include "wifi_display.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070049#include "notify.h"
50#include "bss.h"
51#include "scan.h"
52#include "ctrl_iface.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080053#include "interworking.h"
Hai Shalom60840252021-02-19 19:02:11 -080054#include "bssid_ignore.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070055#include "autoscan.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080056#include "wnm_sta.h"
Dmitry Shmidt818ea482014-03-10 13:15:21 -070057#include "offchannel.h"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070058#include "drivers/driver.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080059#include "mesh.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070060#include "dpp_supplicant.h"
Hai Shalom74f70d42019-02-11 14:42:39 -080061#include "sme.h"
Sunil Ravib0ac25f2024-07-12 01:42:03 +000062#include "nan_usd.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070063
Hai Shalomc3565922019-10-28 11:58:20 -070064#ifdef __NetBSD__
65#include <net/if_ether.h>
66#elif !defined(__CYGWIN__) && !defined(CONFIG_NATIVE_WINDOWS)
67#include <net/ethernet.h>
68#endif
69
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070070static int wpa_supplicant_global_iface_list(struct wpa_global *global,
71 char *buf, int len);
72static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080073 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070074 char *buf, int len);
Dmitry Shmidtd11f0192014-03-24 12:09:47 -070075static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
76 char *val);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070077
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070078
Dmitry Shmidt04949592012-07-19 12:16:46 -070079static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
80{
81 char *pos;
82 u8 addr[ETH_ALEN], *filter = NULL, *n;
83 size_t count = 0;
84
85 pos = val;
86 while (pos) {
87 if (*pos == '\0')
88 break;
89 if (hwaddr_aton(pos, addr)) {
90 os_free(filter);
91 return -1;
92 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070093 n = os_realloc_array(filter, count + 1, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -070094 if (n == NULL) {
95 os_free(filter);
96 return -1;
97 }
98 filter = n;
99 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
100 count++;
101
102 pos = os_strchr(pos, ' ');
103 if (pos)
104 pos++;
105 }
106
107 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
108 os_free(wpa_s->bssid_filter);
109 wpa_s->bssid_filter = filter;
110 wpa_s->bssid_filter_count = count;
111
112 return 0;
113}
114
115
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800116static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
117{
118 char *pos;
119 u8 addr[ETH_ALEN], *bssid = NULL, *n;
120 struct wpa_ssid_value *ssid = NULL, *ns;
121 size_t count = 0, ssid_count = 0;
122 struct wpa_ssid *c;
123
124 /*
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800125 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800126 * SSID_SPEC ::= ssid <SSID_HEX>
127 * BSSID_SPEC ::= bssid <BSSID_HEX>
128 */
129
130 pos = val;
131 while (pos) {
132 if (*pos == '\0')
133 break;
134 if (os_strncmp(pos, "bssid ", 6) == 0) {
135 int res;
136 pos += 6;
137 res = hwaddr_aton2(pos, addr);
138 if (res < 0) {
139 os_free(ssid);
140 os_free(bssid);
141 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
142 "BSSID value '%s'", pos);
143 return -1;
144 }
145 pos += res;
146 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
147 if (n == NULL) {
148 os_free(ssid);
149 os_free(bssid);
150 return -1;
151 }
152 bssid = n;
153 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
154 count++;
155 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
156 char *end;
157 pos += 5;
158
159 end = pos;
160 while (*end) {
161 if (*end == '\0' || *end == ' ')
162 break;
163 end++;
164 }
165
166 ns = os_realloc_array(ssid, ssid_count + 1,
167 sizeof(struct wpa_ssid_value));
168 if (ns == NULL) {
169 os_free(ssid);
170 os_free(bssid);
171 return -1;
172 }
173 ssid = ns;
174
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700175 if ((end - pos) & 0x01 ||
176 end - pos > 2 * SSID_MAX_LEN ||
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800177 hexstr2bin(pos, ssid[ssid_count].ssid,
178 (end - pos) / 2) < 0) {
179 os_free(ssid);
180 os_free(bssid);
181 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
182 "SSID value '%s'", pos);
183 return -1;
184 }
185 ssid[ssid_count].ssid_len = (end - pos) / 2;
186 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
187 ssid[ssid_count].ssid,
188 ssid[ssid_count].ssid_len);
189 ssid_count++;
190 pos = end;
191 } else {
192 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
193 "'%s'", pos);
194 os_free(ssid);
195 os_free(bssid);
196 return -1;
197 }
198
199 pos = os_strchr(pos, ' ');
200 if (pos)
201 pos++;
202 }
203
204 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
205 os_free(wpa_s->disallow_aps_bssid);
206 wpa_s->disallow_aps_bssid = bssid;
207 wpa_s->disallow_aps_bssid_count = count;
208
209 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
210 os_free(wpa_s->disallow_aps_ssid);
211 wpa_s->disallow_aps_ssid = ssid;
212 wpa_s->disallow_aps_ssid_count = ssid_count;
213
214 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
215 return 0;
216
217 c = wpa_s->current_ssid;
218 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
219 return 0;
220
221 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
222 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
223 return 0;
224
225 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
226 "because current AP was marked disallowed");
227
228#ifdef CONFIG_SME
229 wpa_s->sme.prev_bssid_set = 0;
230#endif /* CONFIG_SME */
231 wpa_s->reassociate = 1;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800232 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800233 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
234 wpa_supplicant_req_scan(wpa_s, 0, 0);
235
236 return 0;
237}
238
239
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700240#ifndef CONFIG_NO_CONFIG_BLOBS
241static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
242{
243 char *name = pos;
244 struct wpa_config_blob *blob;
245 size_t len;
246
247 pos = os_strchr(pos, ' ');
248 if (pos == NULL)
249 return -1;
250 *pos++ = '\0';
251 len = os_strlen(pos);
252 if (len & 1)
253 return -1;
254
255 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
256 blob = os_zalloc(sizeof(*blob));
257 if (blob == NULL)
258 return -1;
259 blob->name = os_strdup(name);
260 blob->data = os_malloc(len / 2);
261 if (blob->name == NULL || blob->data == NULL) {
262 wpa_config_free_blob(blob);
263 return -1;
264 }
265
266 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
267 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
268 wpa_config_free_blob(blob);
269 return -1;
270 }
271 blob->len = len / 2;
272
273 wpa_config_set_blob(wpa_s->conf, blob);
274
275 return 0;
276}
277#endif /* CONFIG_NO_CONFIG_BLOBS */
278
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700279
280static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
281{
282 char *params;
283 char *pos;
284 int *freqs = NULL;
285 int ret;
286
287 if (atoi(cmd)) {
288 params = os_strchr(cmd, ' ');
289 os_free(wpa_s->manual_sched_scan_freqs);
290 if (params) {
291 params++;
292 pos = os_strstr(params, "freq=");
293 if (pos)
294 freqs = freq_range_to_channel_list(wpa_s,
295 pos + 5);
296 }
297 wpa_s->manual_sched_scan_freqs = freqs;
298 ret = wpas_start_pno(wpa_s);
299 } else {
300 ret = wpas_stop_pno(wpa_s);
301 }
302 return ret;
303}
304
305
Hai Shalom60840252021-02-19 19:02:11 -0800306static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *bands)
Ravi Joshie6ccb162015-07-16 17:45:41 -0700307{
308 union wpa_event_data event;
Hai Shalom60840252021-02-19 19:02:11 -0800309 u32 setband_mask = WPA_SETBAND_AUTO;
Ravi Joshie6ccb162015-07-16 17:45:41 -0700310
Hai Shalom60840252021-02-19 19:02:11 -0800311 /*
312 * For example:
313 * SET setband 2G,6G
314 * SET setband 5G
315 * SET setband AUTO
316 */
317 if (!os_strstr(bands, "AUTO")) {
318 if (os_strstr(bands, "5G"))
319 setband_mask |= WPA_SETBAND_5G;
320 if (os_strstr(bands, "6G"))
321 setband_mask |= WPA_SETBAND_6G;
322 if (os_strstr(bands, "2G"))
323 setband_mask |= WPA_SETBAND_2G;
324 if (setband_mask == WPA_SETBAND_AUTO)
325 return -1;
326 }
Ravi Joshie6ccb162015-07-16 17:45:41 -0700327
Hai Shalom60840252021-02-19 19:02:11 -0800328 wpa_s->setband_mask = setband_mask;
329 if (wpa_drv_setband(wpa_s, wpa_s->setband_mask) == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700330 os_memset(&event, 0, sizeof(event));
331 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
332 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
333 wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
334 }
335
336 return 0;
337}
338
339
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700340static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s,
341 const char *cmd)
342{
343 struct wpabuf *lci;
344
345 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
346 wpabuf_free(wpa_s->lci);
347 wpa_s->lci = NULL;
348 return 0;
349 }
350
351 lci = wpabuf_parse_bin(cmd);
352 if (!lci)
353 return -1;
354
355 if (os_get_reltime(&wpa_s->lci_time)) {
356 wpabuf_free(lci);
357 return -1;
358 }
359
360 wpabuf_free(wpa_s->lci);
361 wpa_s->lci = lci;
362
363 return 0;
364}
365
366
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800367static int
368wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd)
369{
370 int relative_rssi;
371
372 if (os_strcmp(cmd, "disable") == 0) {
373 wpa_s->srp.relative_rssi_set = 0;
374 return 0;
375 }
376
377 relative_rssi = atoi(cmd);
378 if (relative_rssi < 0 || relative_rssi > 100)
379 return -1;
380 wpa_s->srp.relative_rssi = relative_rssi;
381 wpa_s->srp.relative_rssi_set = 1;
382 return 0;
383}
384
385
386static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s,
387 const char *cmd)
388{
389 char *pos;
390 int adjust_rssi;
391
392 /* <band>:adjust_value */
393 pos = os_strchr(cmd, ':');
394 if (!pos)
395 return -1;
396 pos++;
397 adjust_rssi = atoi(pos);
398 if (adjust_rssi < -100 || adjust_rssi > 100)
399 return -1;
400
401 if (os_strncmp(cmd, "2G", 2) == 0)
402 wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G;
403 else if (os_strncmp(cmd, "5G", 2) == 0)
404 wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G;
405 else
406 return -1;
407
408 wpa_s->srp.relative_adjust_rssi = adjust_rssi;
409
410 return 0;
411}
412
413
414static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s,
415 const char *cmd)
416{
417 struct wpabuf *ric_ies;
418
419 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
420 wpabuf_free(wpa_s->ric_ies);
421 wpa_s->ric_ies = NULL;
422 return 0;
423 }
424
425 ric_ies = wpabuf_parse_bin(cmd);
426 if (!ric_ies)
427 return -1;
428
429 wpabuf_free(wpa_s->ric_ies);
430 wpa_s->ric_ies = ric_ies;
431
432 return 0;
433}
434
435
Hai Shalomfdcde762020-04-02 11:19:20 -0700436#ifdef CONFIG_TESTING_OPTIONS
437static int wpas_ctrl_iface_set_dso(struct wpa_supplicant *wpa_s,
438 const char *val)
439{
440 u8 bssid[ETH_ALEN];
441 const char *pos = val;
442 struct driver_signal_override *dso = NULL, *tmp, parsed;
443
444 if (hwaddr_aton(pos, bssid))
445 return -1;
446 pos = os_strchr(pos, ' ');
447
448 dl_list_for_each(tmp, &wpa_s->drv_signal_override,
449 struct driver_signal_override, list) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000450 if (ether_addr_equal(bssid, tmp->bssid)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700451 dso = tmp;
452 break;
453 }
454 }
455
456 if (!pos) {
457 /* Remove existing entry */
458 if (dso) {
459 dl_list_del(&dso->list);
460 os_free(dso);
461 }
462 return 0;
463 }
464 pos++;
465
466 /* Update an existing entry or add a new one */
467 os_memset(&parsed, 0, sizeof(parsed));
468 if (sscanf(pos, "%d %d %d %d %d",
469 &parsed.si_current_signal,
470 &parsed.si_avg_signal,
471 &parsed.si_avg_beacon_signal,
472 &parsed.si_current_noise,
473 &parsed.scan_level) != 5)
474 return -1;
475
476 if (!dso) {
477 dso = os_zalloc(sizeof(*dso));
478 if (!dso)
479 return -1;
480 os_memcpy(dso->bssid, bssid, ETH_ALEN);
481 dl_list_add(&wpa_s->drv_signal_override, &dso->list);
482 }
483 dso->si_current_signal = parsed.si_current_signal;
484 dso->si_avg_signal = parsed.si_avg_signal;
485 dso->si_avg_beacon_signal = parsed.si_avg_beacon_signal;
486 dso->si_current_noise = parsed.si_current_noise;
487 dso->scan_level = parsed.scan_level;
488
489 return 0;
490}
491#endif /* CONFIG_TESTING_OPTIONS */
492
493
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700494static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
495 char *cmd)
496{
497 char *value;
498 int ret = 0;
499
500 value = os_strchr(cmd, ' ');
501 if (value == NULL)
502 return -1;
503 *value++ = '\0';
504
505 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
506 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
507 eapol_sm_configure(wpa_s->eapol,
508 atoi(value), -1, -1, -1);
509 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
510 eapol_sm_configure(wpa_s->eapol,
511 -1, atoi(value), -1, -1);
512 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
513 eapol_sm_configure(wpa_s->eapol,
514 -1, -1, atoi(value), -1);
515 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
516 eapol_sm_configure(wpa_s->eapol,
517 -1, -1, -1, atoi(value));
Hai Shaloma20dcd72022-02-04 13:43:00 -0800518#ifdef CONFIG_TESTING_OPTIONS
519 } else if (os_strcasecmp(cmd, "EAPOL::portControl") == 0) {
520 if (os_strcmp(value, "Auto") == 0)
521 eapol_sm_notify_portControl(wpa_s->eapol, Auto);
522 else if (os_strcmp(value, "ForceUnauthorized") == 0)
523 eapol_sm_notify_portControl(wpa_s->eapol,
524 ForceUnauthorized);
525 else if (os_strcmp(value, "ForceAuthorized") == 0)
526 eapol_sm_notify_portControl(wpa_s->eapol,
527 ForceAuthorized);
528 else
529 ret = -1;
530#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700531 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
532 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
Paul Stewart092955c2017-02-06 09:13:09 -0800533 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700534 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800535 } else {
536 value[-1] = '=';
537 wpa_config_process_global(wpa_s->conf, cmd, -1);
538 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700539 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
540 0) {
541 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
Paul Stewart092955c2017-02-06 09:13:09 -0800542 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800544 } else {
545 value[-1] = '=';
546 wpa_config_process_global(wpa_s->conf, cmd, -1);
547 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700548 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
Paul Stewart092955c2017-02-06 09:13:09 -0800549 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
550 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700551 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800552 } else {
553 value[-1] = '=';
554 wpa_config_process_global(wpa_s->conf, cmd, -1);
555 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
557 wpa_s->wps_fragment_size = atoi(value);
558#ifdef CONFIG_WPS_TESTING
559 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
560 long int val;
561 val = strtol(value, NULL, 0);
562 if (val < 0 || val > 0xff) {
563 ret = -1;
564 wpa_printf(MSG_DEBUG, "WPS: Invalid "
565 "wps_version_number %ld", val);
566 } else {
567 wps_version_number = val;
568 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
569 "version %u.%u",
570 (wps_version_number & 0xf0) >> 4,
571 wps_version_number & 0x0f);
572 }
Hai Shaloma20dcd72022-02-04 13:43:00 -0800573 } else if (os_strcasecmp(cmd, "wps_testing_stub_cred") == 0) {
574 wps_testing_stub_cred = atoi(value);
575 wpa_printf(MSG_DEBUG, "WPS: Testing - stub_cred=%d",
576 wps_testing_stub_cred);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800577 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
578 wps_corrupt_pkhash = atoi(value);
579 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
580 wps_corrupt_pkhash);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800581 } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
582 if (value[0] == '\0') {
583 wps_force_auth_types_in_use = 0;
584 } else {
585 wps_force_auth_types = strtol(value, NULL, 0);
586 wps_force_auth_types_in_use = 1;
587 }
588 } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
589 if (value[0] == '\0') {
590 wps_force_encr_types_in_use = 0;
591 } else {
592 wps_force_encr_types = strtol(value, NULL, 0);
593 wps_force_encr_types_in_use = 1;
594 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700595#endif /* CONFIG_WPS_TESTING */
596 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
597 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
598 ret = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800599#ifdef CONFIG_TDLS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700600#ifdef CONFIG_TDLS_TESTING
601 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700602 tdls_testing = strtol(value, NULL, 0);
603 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
604#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700605 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
606 int disabled = atoi(value);
607 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
608 if (disabled) {
609 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
610 ret = -1;
611 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
612 ret = -1;
613 wpa_tdls_enable(wpa_s->wpa, !disabled);
614#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800615 } else if (os_strcasecmp(cmd, "pno") == 0) {
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700616 ret = wpas_ctrl_pno(wpa_s, value);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700617 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
618 int disabled = atoi(value);
619 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
620 ret = -1;
621 else if (disabled)
622 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
623 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
624 if (os_strcmp(value, "disable") == 0)
625 wpa_s->set_sta_uapsd = 0;
626 else {
627 int be, bk, vi, vo;
628 char *pos;
629 /* format: BE,BK,VI,VO;max SP Length */
630 be = atoi(value);
631 pos = os_strchr(value, ',');
632 if (pos == NULL)
633 return -1;
634 pos++;
635 bk = atoi(pos);
636 pos = os_strchr(pos, ',');
637 if (pos == NULL)
638 return -1;
639 pos++;
640 vi = atoi(pos);
641 pos = os_strchr(pos, ',');
642 if (pos == NULL)
643 return -1;
644 pos++;
645 vo = atoi(pos);
646 /* ignore max SP Length for now */
647
648 wpa_s->set_sta_uapsd = 1;
649 wpa_s->sta_uapsd = 0;
650 if (be)
651 wpa_s->sta_uapsd |= BIT(0);
652 if (bk)
653 wpa_s->sta_uapsd |= BIT(1);
654 if (vi)
655 wpa_s->sta_uapsd |= BIT(2);
656 if (vo)
657 wpa_s->sta_uapsd |= BIT(3);
658 }
Jouni Malinen21d6bc82012-04-10 16:17:59 -0700659 } else if (os_strcasecmp(cmd, "ps") == 0) {
660 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700661#ifdef CONFIG_WIFI_DISPLAY
662 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800663 int enabled = !!atoi(value);
664 if (enabled && !wpa_s->global->p2p)
665 ret = -1;
666 else
667 wifi_display_enable(wpa_s->global, enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700668#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700669 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
670 ret = set_bssid_filter(wpa_s, value);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800671 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
672 ret = set_disallow_aps(wpa_s, value);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800673 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
674 wpa_s->no_keep_alive = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700675#ifdef CONFIG_DPP
676 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
677 os_free(wpa_s->dpp_configurator_params);
678 wpa_s->dpp_configurator_params = os_strdup(value);
Sunil Ravia04bd252022-05-02 22:54:18 -0700679#ifdef CONFIG_DPP2
680 dpp_controller_set_params(wpa_s->dpp, value);
681#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700682 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
683 wpa_s->dpp_init_max_tries = atoi(value);
684 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
685 wpa_s->dpp_init_retry_time = atoi(value);
686 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
687 wpa_s->dpp_resp_wait_time = atoi(value);
688 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
689 wpa_s->dpp_resp_max_tries = atoi(value);
690 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
691 wpa_s->dpp_resp_retry_time = atoi(value);
692#ifdef CONFIG_TESTING_OPTIONS
693 } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
694 if (hwaddr_aton(value, dpp_pkex_own_mac_override))
695 ret = -1;
696 } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
697 if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
698 ret = -1;
699 } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
700 size_t hex_len = os_strlen(value);
701
702 if (hex_len >
703 2 * sizeof(dpp_pkex_ephemeral_key_override))
704 ret = -1;
705 else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
706 hex_len / 2))
707 ret = -1;
708 else
709 dpp_pkex_ephemeral_key_override_len = hex_len / 2;
710 } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) {
711 size_t hex_len = os_strlen(value);
712
713 if (hex_len > 2 * sizeof(dpp_protocol_key_override))
714 ret = -1;
715 else if (hexstr2bin(value, dpp_protocol_key_override,
716 hex_len / 2))
717 ret = -1;
718 else
719 dpp_protocol_key_override_len = hex_len / 2;
720 } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) {
721 size_t hex_len = os_strlen(value);
722
723 if (hex_len > 2 * sizeof(dpp_nonce_override))
724 ret = -1;
725 else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2))
726 ret = -1;
727 else
728 dpp_nonce_override_len = hex_len / 2;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700729 } else if (os_strcasecmp(cmd, "dpp_version_override") == 0) {
730 dpp_version_override = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700731#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700732#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700733#ifdef CONFIG_TESTING_OPTIONS
734 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
735 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800736 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
737 wpa_s->ext_eapol_frame_io = !!atoi(value);
738#ifdef CONFIG_AP
739 if (wpa_s->ap_iface) {
740 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
741 wpa_s->ext_eapol_frame_io;
742 }
743#endif /* CONFIG_AP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000744 } else if (os_strcasecmp(cmd, "encrypt_eapol_m2") == 0) {
745 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ENCRYPT_EAPOL_M2,
746 !!atoi(value));
747 } else if (os_strcasecmp(cmd, "encrypt_eapol_m4") == 0) {
748 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ENCRYPT_EAPOL_M4,
749 !!atoi(value));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800750 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
751 wpa_s->extra_roc_dur = atoi(value);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800752 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
753 wpa_s->test_failure = atoi(value);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800754 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
755 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700756 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
757 wpa_s->ignore_auth_resp = !!atoi(value);
758 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
759 wpa_s->ignore_assoc_disallow = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700760 wpa_drv_ignore_assoc_disallow(wpa_s,
761 wpa_s->ignore_assoc_disallow);
Hai Shalomfdcde762020-04-02 11:19:20 -0700762 } else if (os_strcasecmp(cmd, "disable_sa_query") == 0) {
763 wpa_s->disable_sa_query = !!atoi(value);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800764 } else if (os_strcasecmp(cmd, "ignore_sae_h2e_only") == 0) {
765 wpa_s->ignore_sae_h2e_only = !!atoi(value);
766 } else if (os_strcasecmp(cmd, "extra_sae_rejected_groups") == 0) {
767 char *pos;
768
769 os_free(wpa_s->extra_sae_rejected_groups);
770 wpa_s->extra_sae_rejected_groups = NULL;
771 pos = value;
772 while (pos && pos[0]) {
773 int group;
774
775 group = atoi(pos);
776 wpa_printf(MSG_DEBUG,
777 "TESTING: Extra rejection of SAE group %d",
778 group);
779 if (group)
780 int_array_add_unique(
781 &wpa_s->extra_sae_rejected_groups,
782 group);
783 pos = os_strchr(pos, ' ');
784 if (!pos)
785 break;
786 pos++;
787 }
Hai Shalomb755a2a2020-04-23 21:49:02 -0700788 } else if (os_strcasecmp(cmd, "ft_rsnxe_used") == 0) {
789 wpa_s->ft_rsnxe_used = atoi(value);
Hai Shalom899fcc72020-10-19 14:38:18 -0700790 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol") == 0) {
791 wpa_s->oci_freq_override_eapol = atoi(value);
792 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_req") == 0) {
793 wpa_s->oci_freq_override_saquery_req = atoi(value);
794 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_resp") == 0) {
795 wpa_s->oci_freq_override_saquery_resp = atoi(value);
796 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol_g2") == 0) {
797 wpa_s->oci_freq_override_eapol_g2 = atoi(value);
798 /* Populate value to wpa_sm if already associated. */
799 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_EAPOL_G2,
800 wpa_s->oci_freq_override_eapol_g2);
801 } else if (os_strcasecmp(cmd, "oci_freq_override_ft_assoc") == 0) {
802 wpa_s->oci_freq_override_ft_assoc = atoi(value);
803 /* Populate value to wpa_sm if already associated. */
804 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_FT_ASSOC,
805 wpa_s->oci_freq_override_ft_assoc);
806 } else if (os_strcasecmp(cmd, "oci_freq_override_fils_assoc") == 0) {
807 wpa_s->oci_freq_override_fils_assoc = atoi(value);
808 } else if (os_strcasecmp(cmd, "oci_freq_override_wnm_sleep") == 0) {
809 wpa_s->oci_freq_override_wnm_sleep = atoi(value);
Hai Shalomfdcde762020-04-02 11:19:20 -0700810 } else if (os_strcasecmp(cmd, "rsne_override_eapol") == 0) {
811 wpabuf_free(wpa_s->rsne_override_eapol);
812 if (os_strcmp(value, "NULL") == 0)
813 wpa_s->rsne_override_eapol = NULL;
814 else
815 wpa_s->rsne_override_eapol = wpabuf_parse_bin(value);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800816 } else if (os_strcasecmp(cmd, "rsnxe_override_assoc") == 0) {
817 wpabuf_free(wpa_s->rsnxe_override_assoc);
818 if (os_strcmp(value, "NULL") == 0)
819 wpa_s->rsnxe_override_assoc = NULL;
820 else
821 wpa_s->rsnxe_override_assoc = wpabuf_parse_bin(value);
822 } else if (os_strcasecmp(cmd, "rsnxe_override_eapol") == 0) {
823 wpabuf_free(wpa_s->rsnxe_override_eapol);
824 if (os_strcmp(value, "NULL") == 0)
825 wpa_s->rsnxe_override_eapol = NULL;
826 else
827 wpa_s->rsnxe_override_eapol = wpabuf_parse_bin(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700828 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
829 wpa_s->reject_btm_req_reason = atoi(value);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800830 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
831 os_free(wpa_s->get_pref_freq_list_override);
832 if (!value[0])
833 wpa_s->get_pref_freq_list_override = NULL;
834 else
835 wpa_s->get_pref_freq_list_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700836 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
837 wpabuf_free(wpa_s->sae_commit_override);
838 if (value[0] == '\0')
839 wpa_s->sae_commit_override = NULL;
840 else
841 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
Hai Shalomfdcde762020-04-02 11:19:20 -0700842 } else if (os_strcasecmp(cmd, "driver_signal_override") == 0) {
843 ret = wpas_ctrl_iface_set_dso(wpa_s, value);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000844#ifndef CONFIG_NO_ROBUST_AV
Hai Shaloma20dcd72022-02-04 13:43:00 -0800845 } else if (os_strcasecmp(cmd, "disable_scs_support") == 0) {
846 wpa_s->disable_scs_support = !!atoi(value);
847 } else if (os_strcasecmp(cmd, "disable_mscs_support") == 0) {
848 wpa_s->disable_mscs_support = !!atoi(value);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000849#endif /* CONFIG_NO_ROBUST_AV */
Sunil Ravia04bd252022-05-02 22:54:18 -0700850 } else if (os_strcasecmp(cmd, "disable_eapol_g2_tx") == 0) {
851 wpa_s->disable_eapol_g2_tx = !!atoi(value);
852 /* Populate value to wpa_sm if already associated. */
853 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DISABLE_EAPOL_G2_TX,
854 wpa_s->disable_eapol_g2_tx);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000855 } else if (os_strcasecmp(cmd, "test_assoc_comeback_type") == 0) {
856 wpa_s->test_assoc_comeback_type = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700857#ifdef CONFIG_DPP
858 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
859 os_free(wpa_s->dpp_config_obj_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700860 if (value[0] == '\0')
861 wpa_s->dpp_config_obj_override = NULL;
862 else
863 wpa_s->dpp_config_obj_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700864 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
865 os_free(wpa_s->dpp_discovery_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700866 if (value[0] == '\0')
867 wpa_s->dpp_discovery_override = NULL;
868 else
869 wpa_s->dpp_discovery_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700870 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
871 os_free(wpa_s->dpp_groups_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700872 if (value[0] == '\0')
873 wpa_s->dpp_groups_override = NULL;
874 else
875 wpa_s->dpp_groups_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700876 } else if (os_strcasecmp(cmd,
877 "dpp_ignore_netaccesskey_mismatch") == 0) {
878 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
Sunil8cd6f4d2022-06-28 18:40:46 +0000879 } else if (os_strcasecmp(cmd, "dpp_discard_public_action") == 0) {
880 wpa_s->dpp_discard_public_action = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700881 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
882 dpp_test = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700883#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700884#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700885#ifdef CONFIG_FILS
886 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
887 wpa_s->disable_fils = !!atoi(value);
888 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
889 wpa_supplicant_set_default_scan_ies(wpa_s);
890#endif /* CONFIG_FILS */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700891#ifndef CONFIG_NO_CONFIG_BLOBS
892 } else if (os_strcmp(cmd, "blob") == 0) {
893 ret = wpas_ctrl_set_blob(wpa_s, value);
894#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800895 } else if (os_strcasecmp(cmd, "setband") == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700896 ret = wpas_ctrl_set_band(wpa_s, value);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800897#ifdef CONFIG_MBO
898 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
899 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
Paul Stewart092955c2017-02-06 09:13:09 -0800900 if (ret == 0) {
901 value[-1] = '=';
902 wpa_config_process_global(wpa_s->conf, cmd, -1);
903 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800904 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
Sunil Ravi88611412024-06-28 17:34:56 +0000905 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700906 } else if (os_strcasecmp(cmd, "oce") == 0) {
Sunil Ravi88611412024-06-28 17:34:56 +0000907 wpa_s->conf->oce = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700908 if (wpa_s->conf->oce) {
909 if ((wpa_s->conf->oce & OCE_STA) &&
910 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
911 wpa_s->enable_oce = OCE_STA;
912
913 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
914 (wpa_s->drv_flags &
915 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
916 /* TODO: Need to add STA-CFON support */
917 wpa_printf(MSG_ERROR,
918 "OCE STA-CFON feature is not yet supported");
919 return -1;
920 }
921 } else {
922 wpa_s->enable_oce = 0;
923 }
924 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800925#endif /* CONFIG_MBO */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700926 } else if (os_strcasecmp(cmd, "lci") == 0) {
927 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800928 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
929 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800930 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
931 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
932 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
933 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
934 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
935 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700936 } else if (os_strcasecmp(cmd, "roaming") == 0) {
937 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800938#ifdef CONFIG_WNM
939 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
940 struct wpabuf *elems;
941
942 elems = wpabuf_parse_bin(value);
943 if (!elems)
944 return -1;
945 wnm_set_coloc_intf_elems(wpa_s, elems);
946#endif /* CONFIG_WNM */
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000947#ifndef CONFIG_NO_ROBUST_AV
Hai Shaloma20dcd72022-02-04 13:43:00 -0800948 } else if (os_strcasecmp(cmd, "enable_dscp_policy_capa") == 0) {
949 wpa_s->enable_dscp_policy_capa = !!atoi(value);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000950#endif /* CONFIG_NO_ROBUST_AV */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951 } else {
952 value[-1] = '=';
953 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
954 if (ret == 0)
955 wpa_supplicant_update_config(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -0700956 else if (ret == 1)
957 ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700958 }
959
960 return ret;
961}
962
963
964static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
965 char *cmd, char *buf, size_t buflen)
966{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700967 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700968
969 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
970
971 if (os_strcmp(cmd, "version") == 0) {
972 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700973 } else if (os_strcasecmp(cmd, "max_command_len") == 0) {
974 res = os_snprintf(buf, buflen, "%u", CTRL_IFACE_MAX_LEN);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700975 } else if (os_strcasecmp(cmd, "country") == 0) {
976 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
977 res = os_snprintf(buf, buflen, "%c%c",
978 wpa_s->conf->country[0],
979 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700980#ifdef CONFIG_WIFI_DISPLAY
981 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800982 int enabled;
983 if (wpa_s->global->p2p == NULL ||
984 wpa_s->global->p2p_disabled)
985 enabled = 0;
986 else
987 enabled = wpa_s->global->wifi_display;
988 res = os_snprintf(buf, buflen, "%d", enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700989#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700990#ifdef CONFIG_TESTING_GET_GTK
991 } else if (os_strcmp(cmd, "gtk") == 0) {
992 if (wpa_s->last_gtk_len == 0)
993 return -1;
994 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
995 wpa_s->last_gtk_len);
996 return res;
997#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800998 } else if (os_strcmp(cmd, "tls_library") == 0) {
999 res = tls_get_library_version(buf, buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001000#ifdef CONFIG_TESTING_OPTIONS
1001 } else if (os_strcmp(cmd, "anonce") == 0) {
1002 return wpa_snprintf_hex(buf, buflen,
1003 wpa_sm_get_anonce(wpa_s->wpa),
1004 WPA_NONCE_LEN);
Hai Shalomfdcde762020-04-02 11:19:20 -07001005 } else if (os_strcasecmp(cmd, "last_tk_key_idx") == 0) {
1006 res = os_snprintf(buf, buflen, "%d", wpa_s->last_tk_key_idx);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001007#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001008 } else {
1009 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001010 }
1011
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001012 if (os_snprintf_error(buflen, res))
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -07001013 return -1;
1014 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001015}
1016
1017
1018#ifdef IEEE8021X_EAPOL
1019static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
1020 char *addr)
1021{
1022 u8 bssid[ETH_ALEN];
1023 struct wpa_ssid *ssid = wpa_s->current_ssid;
1024
1025 if (hwaddr_aton(addr, bssid)) {
1026 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
1027 "'%s'", addr);
1028 return -1;
1029 }
1030
1031 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
1032 rsn_preauth_deinit(wpa_s->wpa);
1033 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
1034 return -1;
1035
1036 return 0;
1037}
1038#endif /* IEEE8021X_EAPOL */
1039
1040
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001041#ifdef CONFIG_TDLS
1042
1043static int wpa_supplicant_ctrl_iface_tdls_discover(
1044 struct wpa_supplicant *wpa_s, char *addr)
1045{
1046 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001047 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001048
1049 if (hwaddr_aton(addr, peer)) {
1050 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
1051 "address '%s'", addr);
1052 return -1;
1053 }
1054
1055 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
1056 MAC2STR(peer));
1057
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001058 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1059 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
1060 else
1061 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
1062
1063 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001064}
1065
1066
1067static int wpa_supplicant_ctrl_iface_tdls_setup(
1068 struct wpa_supplicant *wpa_s, char *addr)
1069{
1070 u8 peer[ETH_ALEN];
1071 int ret;
1072
1073 if (hwaddr_aton(addr, peer)) {
1074 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
1075 "address '%s'", addr);
1076 return -1;
1077 }
1078
1079 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
1080 MAC2STR(peer));
1081
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001082 if ((wpa_s->conf->tdls_external_control) &&
1083 wpa_tdls_is_external_setup(wpa_s->wpa))
1084 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
1085
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001086 wpa_tdls_remove(wpa_s->wpa, peer);
1087
1088 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1089 ret = wpa_tdls_start(wpa_s->wpa, peer);
1090 else
1091 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001092
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001093 return ret;
1094}
1095
1096
1097static int wpa_supplicant_ctrl_iface_tdls_teardown(
1098 struct wpa_supplicant *wpa_s, char *addr)
1099{
1100 u8 peer[ETH_ALEN];
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001101 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001102
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001103 if (os_strcmp(addr, "*") == 0) {
1104 /* remove everyone */
1105 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
1106 wpa_tdls_teardown_peers(wpa_s->wpa);
1107 return 0;
1108 }
1109
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001110 if (hwaddr_aton(addr, peer)) {
1111 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
1112 "address '%s'", addr);
1113 return -1;
1114 }
1115
1116 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
1117 MAC2STR(peer));
1118
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001119 if ((wpa_s->conf->tdls_external_control) &&
1120 wpa_tdls_is_external_setup(wpa_s->wpa))
1121 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1122
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001123 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1124 ret = wpa_tdls_teardown_link(
1125 wpa_s->wpa, peer,
1126 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
1127 else
1128 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1129
1130 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001131}
1132
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001133
1134static int ctrl_iface_get_capability_tdls(
1135 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1136{
1137 int ret;
1138
1139 ret = os_snprintf(buf, buflen, "%s\n",
1140 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
1141 (wpa_s->drv_flags &
1142 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
1143 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001144 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001145 return -1;
1146 return ret;
1147}
1148
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001149
1150static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
1151 struct wpa_supplicant *wpa_s, char *cmd)
1152{
1153 u8 peer[ETH_ALEN];
1154 struct hostapd_freq_params freq_params;
1155 u8 oper_class;
1156 char *pos, *end;
1157
1158 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1159 wpa_printf(MSG_INFO,
1160 "tdls_chanswitch: Only supported with external setup");
1161 return -1;
1162 }
1163
1164 os_memset(&freq_params, 0, sizeof(freq_params));
1165
1166 pos = os_strchr(cmd, ' ');
1167 if (pos == NULL)
1168 return -1;
1169 *pos++ = '\0';
1170
1171 oper_class = strtol(pos, &end, 10);
1172 if (pos == end) {
1173 wpa_printf(MSG_INFO,
1174 "tdls_chanswitch: Invalid op class provided");
1175 return -1;
1176 }
1177
1178 pos = end;
1179 freq_params.freq = atoi(pos);
1180 if (freq_params.freq == 0) {
1181 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
1182 return -1;
1183 }
1184
1185#define SET_FREQ_SETTING(str) \
1186 do { \
1187 const char *pos2 = os_strstr(pos, " " #str "="); \
1188 if (pos2) { \
1189 pos2 += sizeof(" " #str "=") - 1; \
1190 freq_params.str = atoi(pos2); \
1191 } \
1192 } while (0)
1193
1194 SET_FREQ_SETTING(center_freq1);
1195 SET_FREQ_SETTING(center_freq2);
1196 SET_FREQ_SETTING(bandwidth);
1197 SET_FREQ_SETTING(sec_channel_offset);
1198#undef SET_FREQ_SETTING
1199
1200 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1201 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1202
1203 if (hwaddr_aton(cmd, peer)) {
1204 wpa_printf(MSG_DEBUG,
1205 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1206 cmd);
1207 return -1;
1208 }
1209
1210 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1211 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1212 MAC2STR(peer), oper_class, freq_params.freq,
1213 freq_params.center_freq1, freq_params.center_freq2,
1214 freq_params.bandwidth, freq_params.sec_channel_offset,
1215 freq_params.ht_enabled ? " HT" : "",
1216 freq_params.vht_enabled ? " VHT" : "");
1217
1218 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1219 &freq_params);
1220}
1221
1222
1223static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1224 struct wpa_supplicant *wpa_s, char *cmd)
1225{
1226 u8 peer[ETH_ALEN];
1227
1228 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1229 wpa_printf(MSG_INFO,
1230 "tdls_chanswitch: Only supported with external setup");
1231 return -1;
1232 }
1233
1234 if (hwaddr_aton(cmd, peer)) {
1235 wpa_printf(MSG_DEBUG,
1236 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1237 cmd);
1238 return -1;
1239 }
1240
1241 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1242 MAC2STR(peer));
1243
1244 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1245}
1246
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07001247
1248static int wpa_supplicant_ctrl_iface_tdls_link_status(
1249 struct wpa_supplicant *wpa_s, const char *addr,
1250 char *buf, size_t buflen)
1251{
1252 u8 peer[ETH_ALEN];
1253 const char *tdls_status;
1254 int ret;
1255
1256 if (hwaddr_aton(addr, peer)) {
1257 wpa_printf(MSG_DEBUG,
1258 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1259 addr);
1260 return -1;
1261 }
1262 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1263 MAC2STR(peer));
1264
1265 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1266 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1267 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1268 if (os_snprintf_error(buflen, ret))
1269 return -1;
1270
1271 return ret;
1272}
1273
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001274#endif /* CONFIG_TDLS */
1275
1276
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001277#ifndef CONFIG_NO_WMM_AC
1278
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001279static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1280{
1281 char *token, *context = NULL;
1282 struct wmm_ac_ts_setup_params params = {
1283 .tsid = 0xff,
1284 .direction = 0xff,
1285 };
1286
1287 while ((token = str_token(cmd, " ", &context))) {
1288 if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
1289 sscanf(token, "up=%i", &params.user_priority) == 1 ||
1290 sscanf(token, "nominal_msdu_size=%i",
1291 &params.nominal_msdu_size) == 1 ||
1292 sscanf(token, "mean_data_rate=%i",
1293 &params.mean_data_rate) == 1 ||
1294 sscanf(token, "min_phy_rate=%i",
1295 &params.minimum_phy_rate) == 1 ||
1296 sscanf(token, "sba=%i",
1297 &params.surplus_bandwidth_allowance) == 1)
1298 continue;
1299
1300 if (os_strcasecmp(token, "downlink") == 0) {
1301 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1302 } else if (os_strcasecmp(token, "uplink") == 0) {
1303 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1304 } else if (os_strcasecmp(token, "bidi") == 0) {
1305 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1306 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1307 params.fixed_nominal_msdu = 1;
1308 } else {
1309 wpa_printf(MSG_DEBUG,
1310 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1311 token);
1312 return -1;
1313 }
1314
1315 }
1316
1317 return wpas_wmm_ac_addts(wpa_s, &params);
1318}
1319
1320
1321static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1322{
1323 u8 tsid = atoi(cmd);
1324
1325 return wpas_wmm_ac_delts(wpa_s, tsid);
1326}
1327
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001328#endif /* CONFIG_NO_WMM_AC */
1329
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001330
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001331#ifdef CONFIG_IEEE80211R
1332static int wpa_supplicant_ctrl_iface_ft_ds(
1333 struct wpa_supplicant *wpa_s, char *addr)
1334{
1335 u8 target_ap[ETH_ALEN];
1336 struct wpa_bss *bss;
1337 const u8 *mdie;
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00001338 bool force = os_strstr(addr, " force") != NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001339
1340 if (hwaddr_aton(addr, target_ap)) {
1341 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1342 "address '%s'", addr);
1343 return -1;
1344 }
1345
1346 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1347
1348 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1349 if (bss)
1350 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1351 else
1352 mdie = NULL;
1353
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00001354 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie, force);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001355}
1356#endif /* CONFIG_IEEE80211R */
1357
1358
1359#ifdef CONFIG_WPS
1360static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1361 char *cmd)
1362{
1363 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001364#ifdef CONFIG_P2P
1365 u8 p2p_dev_addr[ETH_ALEN];
1366#endif /* CONFIG_P2P */
1367#ifdef CONFIG_AP
1368 u8 *_p2p_dev_addr = NULL;
1369#endif /* CONFIG_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001370 char *pos;
1371 int multi_ap = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001372
Hai Shalom021b0b52019-04-10 11:17:58 -07001373 if (!cmd || os_strcmp(cmd, "any") == 0 ||
1374 os_strncmp(cmd, "any ", 4) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001375 _bssid = NULL;
1376#ifdef CONFIG_P2P
1377 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1378 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1379 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1380 "P2P Device Address '%s'",
1381 cmd + 13);
1382 return -1;
1383 }
1384 _p2p_dev_addr = p2p_dev_addr;
1385#endif /* CONFIG_P2P */
Hai Shalom021b0b52019-04-10 11:17:58 -07001386 } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) {
1387 _bssid = NULL;
1388 multi_ap = atoi(cmd + 9);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001389 } else if (hwaddr_aton(cmd, bssid)) {
1390 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1391 cmd);
1392 return -1;
1393 }
1394
Hai Shalom021b0b52019-04-10 11:17:58 -07001395 if (cmd) {
1396 pos = os_strstr(cmd, " multi_ap=");
1397 if (pos) {
1398 pos += 10;
1399 multi_ap = atoi(pos);
1400 }
1401 }
1402
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001403#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001404 if (wpa_s->ap_iface)
1405 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1406#endif /* CONFIG_AP */
1407
Hai Shalom021b0b52019-04-10 11:17:58 -07001408 return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001409}
1410
1411
1412static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1413 char *cmd, char *buf,
1414 size_t buflen)
1415{
1416 u8 bssid[ETH_ALEN], *_bssid = bssid;
1417 char *pin;
1418 int ret;
1419
1420 pin = os_strchr(cmd, ' ');
1421 if (pin)
1422 *pin++ = '\0';
1423
1424 if (os_strcmp(cmd, "any") == 0)
1425 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001426 else if (os_strcmp(cmd, "get") == 0) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001427 if (wps_generate_pin((unsigned int *) &ret) < 0)
1428 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001429 goto done;
1430 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001431 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1432 cmd);
1433 return -1;
1434 }
1435
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001436#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001437 if (wpa_s->ap_iface) {
1438 int timeout = 0;
1439 char *pos;
1440
1441 if (pin) {
1442 pos = os_strchr(pin, ' ');
1443 if (pos) {
1444 *pos++ = '\0';
1445 timeout = atoi(pos);
1446 }
1447 }
1448
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001449 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001450 buf, buflen, timeout);
1451 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001452#endif /* CONFIG_AP */
1453
1454 if (pin) {
1455 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1456 DEV_PW_DEFAULT);
1457 if (ret < 0)
1458 return -1;
1459 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001460 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001461 return -1;
1462 return ret;
1463 }
1464
1465 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1466 if (ret < 0)
1467 return -1;
1468
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001469done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001470 /* Return the generated PIN */
1471 ret = os_snprintf(buf, buflen, "%08d", ret);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001472 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001473 return -1;
1474 return ret;
1475}
1476
1477
1478static int wpa_supplicant_ctrl_iface_wps_check_pin(
1479 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1480{
1481 char pin[9];
1482 size_t len;
1483 char *pos;
1484 int ret;
1485
1486 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1487 (u8 *) cmd, os_strlen(cmd));
1488 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1489 if (*pos < '0' || *pos > '9')
1490 continue;
1491 pin[len++] = *pos;
1492 if (len == 9) {
1493 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1494 return -1;
1495 }
1496 }
1497 if (len != 4 && len != 8) {
1498 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1499 return -1;
1500 }
1501 pin[len] = '\0';
1502
1503 if (len == 8) {
1504 unsigned int pin_val;
1505 pin_val = atoi(pin);
1506 if (!wps_pin_valid(pin_val)) {
1507 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1508 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001509 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001510 return -1;
1511 return ret;
1512 }
1513 }
1514
1515 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001516 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001517 return -1;
1518
1519 return ret;
1520}
1521
1522
Dmitry Shmidt04949592012-07-19 12:16:46 -07001523#ifdef CONFIG_WPS_NFC
1524
1525static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1526 char *cmd)
1527{
1528 u8 bssid[ETH_ALEN], *_bssid = bssid;
1529
1530 if (cmd == NULL || cmd[0] == '\0')
1531 _bssid = NULL;
1532 else if (hwaddr_aton(cmd, bssid))
1533 return -1;
1534
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001535 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1536 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001537}
1538
1539
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001540static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1541 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1542{
1543 int ndef;
1544 struct wpabuf *buf;
1545 int res;
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001546 char *pos;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001547
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001548 pos = os_strchr(cmd, ' ');
1549 if (pos)
1550 *pos++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001551 if (os_strcmp(cmd, "WPS") == 0)
1552 ndef = 0;
1553 else if (os_strcmp(cmd, "NDEF") == 0)
1554 ndef = 1;
1555 else
1556 return -1;
1557
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001558 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001559 if (buf == NULL)
1560 return -1;
1561
1562 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1563 wpabuf_len(buf));
1564 reply[res++] = '\n';
1565 reply[res] = '\0';
1566
1567 wpabuf_free(buf);
1568
1569 return res;
1570}
1571
1572
Dmitry Shmidt04949592012-07-19 12:16:46 -07001573static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1574 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1575{
1576 int ndef;
1577 struct wpabuf *buf;
1578 int res;
1579
1580 if (os_strcmp(cmd, "WPS") == 0)
1581 ndef = 0;
1582 else if (os_strcmp(cmd, "NDEF") == 0)
1583 ndef = 1;
1584 else
1585 return -1;
1586
1587 buf = wpas_wps_nfc_token(wpa_s, ndef);
1588 if (buf == NULL)
1589 return -1;
1590
1591 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1592 wpabuf_len(buf));
1593 reply[res++] = '\n';
1594 reply[res] = '\0';
1595
1596 wpabuf_free(buf);
1597
1598 return res;
1599}
1600
1601
1602static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1603 struct wpa_supplicant *wpa_s, char *pos)
1604{
1605 size_t len;
1606 struct wpabuf *buf;
1607 int ret;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001608 char *freq;
1609 int forced_freq = 0;
1610
1611 freq = strstr(pos, " freq=");
1612 if (freq) {
1613 *freq = '\0';
1614 freq += 6;
1615 forced_freq = atoi(freq);
1616 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001617
1618 len = os_strlen(pos);
1619 if (len & 0x01)
1620 return -1;
1621 len /= 2;
1622
1623 buf = wpabuf_alloc(len);
1624 if (buf == NULL)
1625 return -1;
1626 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1627 wpabuf_free(buf);
1628 return -1;
1629 }
1630
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001631 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001632 wpabuf_free(buf);
1633
1634 return ret;
1635}
1636
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001637
1638static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001639 char *reply, size_t max_len,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001640 int ndef)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001641{
1642 struct wpabuf *buf;
1643 int res;
1644
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001645 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001646 if (buf == NULL)
1647 return -1;
1648
1649 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1650 wpabuf_len(buf));
1651 reply[res++] = '\n';
1652 reply[res] = '\0';
1653
1654 wpabuf_free(buf);
1655
1656 return res;
1657}
1658
1659
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001660#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001661static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1662 char *reply, size_t max_len,
1663 int ndef)
1664{
1665 struct wpabuf *buf;
1666 int res;
1667
1668 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1669 if (buf == NULL) {
1670 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1671 return -1;
1672 }
1673
1674 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1675 wpabuf_len(buf));
1676 reply[res++] = '\n';
1677 reply[res] = '\0';
1678
1679 wpabuf_free(buf);
1680
1681 return res;
1682}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001683#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001684
1685
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001686static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1687 char *cmd, char *reply,
1688 size_t max_len)
1689{
1690 char *pos;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001691 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001692
1693 pos = os_strchr(cmd, ' ');
1694 if (pos == NULL)
1695 return -1;
1696 *pos++ = '\0';
1697
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001698 if (os_strcmp(cmd, "WPS") == 0)
1699 ndef = 0;
1700 else if (os_strcmp(cmd, "NDEF") == 0)
1701 ndef = 1;
1702 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001703 return -1;
1704
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001705 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001706 if (!ndef)
1707 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001708 return wpas_ctrl_nfc_get_handover_req_wps(
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001709 wpa_s, reply, max_len, ndef);
1710 }
1711
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001712#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001713 if (os_strcmp(pos, "P2P-CR") == 0) {
1714 return wpas_ctrl_nfc_get_handover_req_p2p(
1715 wpa_s, reply, max_len, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001716 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001717#endif /* CONFIG_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001718
1719 return -1;
1720}
1721
1722
1723static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001724 char *reply, size_t max_len,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001725 int ndef, int cr, char *uuid)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001726{
1727 struct wpabuf *buf;
1728 int res;
1729
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001730 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001731 if (buf == NULL)
1732 return -1;
1733
1734 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1735 wpabuf_len(buf));
1736 reply[res++] = '\n';
1737 reply[res] = '\0';
1738
1739 wpabuf_free(buf);
1740
1741 return res;
1742}
1743
1744
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001745#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001746static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1747 char *reply, size_t max_len,
1748 int ndef, int tag)
1749{
1750 struct wpabuf *buf;
1751 int res;
1752
1753 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1754 if (buf == NULL)
1755 return -1;
1756
1757 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1758 wpabuf_len(buf));
1759 reply[res++] = '\n';
1760 reply[res] = '\0';
1761
1762 wpabuf_free(buf);
1763
1764 return res;
1765}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001766#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001767
1768
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001769static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1770 char *cmd, char *reply,
1771 size_t max_len)
1772{
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001773 char *pos, *pos2;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001774 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001775
1776 pos = os_strchr(cmd, ' ');
1777 if (pos == NULL)
1778 return -1;
1779 *pos++ = '\0';
1780
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001781 if (os_strcmp(cmd, "WPS") == 0)
1782 ndef = 0;
1783 else if (os_strcmp(cmd, "NDEF") == 0)
1784 ndef = 1;
1785 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001786 return -1;
1787
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001788 pos2 = os_strchr(pos, ' ');
1789 if (pos2)
1790 *pos2++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001791 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001792 if (!ndef)
1793 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001794 return wpas_ctrl_nfc_get_handover_sel_wps(
1795 wpa_s, reply, max_len, ndef,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001796 os_strcmp(pos, "WPS-CR") == 0, pos2);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001797 }
1798
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001799#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001800 if (os_strcmp(pos, "P2P-CR") == 0) {
1801 return wpas_ctrl_nfc_get_handover_sel_p2p(
1802 wpa_s, reply, max_len, ndef, 0);
1803 }
1804
1805 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1806 return wpas_ctrl_nfc_get_handover_sel_p2p(
1807 wpa_s, reply, max_len, ndef, 1);
1808 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001809#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001810
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001811 return -1;
1812}
1813
1814
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001815static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1816 char *cmd)
1817{
1818 size_t len;
1819 struct wpabuf *req, *sel;
1820 int ret;
1821 char *pos, *role, *type, *pos2;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001822#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001823 char *freq;
1824 int forced_freq = 0;
1825
1826 freq = strstr(cmd, " freq=");
1827 if (freq) {
1828 *freq = '\0';
1829 freq += 6;
1830 forced_freq = atoi(freq);
1831 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001832#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001833
1834 role = cmd;
1835 pos = os_strchr(role, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001836 if (pos == NULL) {
1837 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001838 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001839 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001840 *pos++ = '\0';
1841
1842 type = pos;
1843 pos = os_strchr(type, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001844 if (pos == NULL) {
1845 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001846 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001847 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001848 *pos++ = '\0';
1849
1850 pos2 = os_strchr(pos, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001851 if (pos2 == NULL) {
1852 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001853 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001854 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001855 *pos2++ = '\0';
1856
1857 len = os_strlen(pos);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001858 if (len & 0x01) {
1859 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001860 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001861 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001862 len /= 2;
1863
1864 req = wpabuf_alloc(len);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001865 if (req == NULL) {
1866 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001867 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001868 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001869 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001870 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001871 wpabuf_free(req);
1872 return -1;
1873 }
1874
1875 len = os_strlen(pos2);
1876 if (len & 0x01) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001877 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001878 wpabuf_free(req);
1879 return -1;
1880 }
1881 len /= 2;
1882
1883 sel = wpabuf_alloc(len);
1884 if (sel == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001885 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001886 wpabuf_free(req);
1887 return -1;
1888 }
1889 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001890 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001891 wpabuf_free(req);
1892 wpabuf_free(sel);
1893 return -1;
1894 }
1895
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001896 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1897 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1898
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001899 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1900 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001901#ifdef CONFIG_AP
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001902 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1903 {
1904 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1905 if (ret < 0)
1906 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001907#endif /* CONFIG_AP */
1908#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001909 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1910 {
1911 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1912 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1913 {
1914 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1915 forced_freq);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001916#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001917 } else {
1918 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1919 "reported: role=%s type=%s", role, type);
1920 ret = -1;
1921 }
1922 wpabuf_free(req);
1923 wpabuf_free(sel);
1924
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001925 if (ret)
1926 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1927
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001928 return ret;
1929}
1930
Dmitry Shmidt04949592012-07-19 12:16:46 -07001931#endif /* CONFIG_WPS_NFC */
1932
1933
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001934static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1935 char *cmd)
1936{
1937 u8 bssid[ETH_ALEN];
1938 char *pin;
1939 char *new_ssid;
1940 char *new_auth;
1941 char *new_encr;
1942 char *new_key;
1943 struct wps_new_ap_settings ap;
1944
1945 pin = os_strchr(cmd, ' ');
1946 if (pin == NULL)
1947 return -1;
1948 *pin++ = '\0';
1949
1950 if (hwaddr_aton(cmd, bssid)) {
1951 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1952 cmd);
1953 return -1;
1954 }
1955
1956 new_ssid = os_strchr(pin, ' ');
1957 if (new_ssid == NULL)
1958 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1959 *new_ssid++ = '\0';
1960
1961 new_auth = os_strchr(new_ssid, ' ');
1962 if (new_auth == NULL)
1963 return -1;
1964 *new_auth++ = '\0';
1965
1966 new_encr = os_strchr(new_auth, ' ');
1967 if (new_encr == NULL)
1968 return -1;
1969 *new_encr++ = '\0';
1970
1971 new_key = os_strchr(new_encr, ' ');
1972 if (new_key == NULL)
1973 return -1;
1974 *new_key++ = '\0';
1975
1976 os_memset(&ap, 0, sizeof(ap));
1977 ap.ssid_hex = new_ssid;
1978 ap.auth = new_auth;
1979 ap.encr = new_encr;
1980 ap.key_hex = new_key;
1981 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1982}
1983
1984
1985#ifdef CONFIG_AP
1986static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1987 char *cmd, char *buf,
1988 size_t buflen)
1989{
1990 int timeout = 300;
1991 char *pos;
1992 const char *pin_txt;
1993
1994 if (!wpa_s->ap_iface)
1995 return -1;
1996
1997 pos = os_strchr(cmd, ' ');
1998 if (pos)
1999 *pos++ = '\0';
2000
2001 if (os_strcmp(cmd, "disable") == 0) {
2002 wpas_wps_ap_pin_disable(wpa_s);
2003 return os_snprintf(buf, buflen, "OK\n");
2004 }
2005
2006 if (os_strcmp(cmd, "random") == 0) {
2007 if (pos)
2008 timeout = atoi(pos);
2009 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
2010 if (pin_txt == NULL)
2011 return -1;
2012 return os_snprintf(buf, buflen, "%s", pin_txt);
2013 }
2014
2015 if (os_strcmp(cmd, "get") == 0) {
2016 pin_txt = wpas_wps_ap_pin_get(wpa_s);
2017 if (pin_txt == NULL)
2018 return -1;
2019 return os_snprintf(buf, buflen, "%s", pin_txt);
2020 }
2021
2022 if (os_strcmp(cmd, "set") == 0) {
2023 char *pin;
2024 if (pos == NULL)
2025 return -1;
2026 pin = pos;
2027 pos = os_strchr(pos, ' ');
2028 if (pos) {
2029 *pos++ = '\0';
2030 timeout = atoi(pos);
2031 }
2032 if (os_strlen(pin) > buflen)
2033 return -1;
2034 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
2035 return -1;
2036 return os_snprintf(buf, buflen, "%s", pin);
2037 }
2038
2039 return -1;
2040}
2041#endif /* CONFIG_AP */
2042
2043
2044#ifdef CONFIG_WPS_ER
2045static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
2046 char *cmd)
2047{
2048 char *uuid = cmd, *pin, *pos;
2049 u8 addr_buf[ETH_ALEN], *addr = NULL;
2050 pin = os_strchr(uuid, ' ');
2051 if (pin == NULL)
2052 return -1;
2053 *pin++ = '\0';
2054 pos = os_strchr(pin, ' ');
2055 if (pos) {
2056 *pos++ = '\0';
2057 if (hwaddr_aton(pos, addr_buf) == 0)
2058 addr = addr_buf;
2059 }
2060 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
2061}
2062
2063
2064static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
2065 char *cmd)
2066{
2067 char *uuid = cmd, *pin;
2068 pin = os_strchr(uuid, ' ');
2069 if (pin == NULL)
2070 return -1;
2071 *pin++ = '\0';
2072 return wpas_wps_er_learn(wpa_s, uuid, pin);
2073}
2074
2075
2076static int wpa_supplicant_ctrl_iface_wps_er_set_config(
2077 struct wpa_supplicant *wpa_s, char *cmd)
2078{
2079 char *uuid = cmd, *id;
2080 id = os_strchr(uuid, ' ');
2081 if (id == NULL)
2082 return -1;
2083 *id++ = '\0';
2084 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
2085}
2086
2087
2088static int wpa_supplicant_ctrl_iface_wps_er_config(
2089 struct wpa_supplicant *wpa_s, char *cmd)
2090{
2091 char *pin;
2092 char *new_ssid;
2093 char *new_auth;
2094 char *new_encr;
2095 char *new_key;
2096 struct wps_new_ap_settings ap;
2097
2098 pin = os_strchr(cmd, ' ');
2099 if (pin == NULL)
2100 return -1;
2101 *pin++ = '\0';
2102
2103 new_ssid = os_strchr(pin, ' ');
2104 if (new_ssid == NULL)
2105 return -1;
2106 *new_ssid++ = '\0';
2107
2108 new_auth = os_strchr(new_ssid, ' ');
2109 if (new_auth == NULL)
2110 return -1;
2111 *new_auth++ = '\0';
2112
2113 new_encr = os_strchr(new_auth, ' ');
2114 if (new_encr == NULL)
2115 return -1;
2116 *new_encr++ = '\0';
2117
2118 new_key = os_strchr(new_encr, ' ');
2119 if (new_key == NULL)
2120 return -1;
2121 *new_key++ = '\0';
2122
2123 os_memset(&ap, 0, sizeof(ap));
2124 ap.ssid_hex = new_ssid;
2125 ap.auth = new_auth;
2126 ap.encr = new_encr;
2127 ap.key_hex = new_key;
2128 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
2129}
Dmitry Shmidt04949592012-07-19 12:16:46 -07002130
2131
2132#ifdef CONFIG_WPS_NFC
2133static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
2134 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2135{
2136 int ndef;
2137 struct wpabuf *buf;
2138 int res;
2139 char *uuid;
2140
2141 uuid = os_strchr(cmd, ' ');
2142 if (uuid == NULL)
2143 return -1;
2144 *uuid++ = '\0';
2145
2146 if (os_strcmp(cmd, "WPS") == 0)
2147 ndef = 0;
2148 else if (os_strcmp(cmd, "NDEF") == 0)
2149 ndef = 1;
2150 else
2151 return -1;
2152
2153 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
2154 if (buf == NULL)
2155 return -1;
2156
2157 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
2158 wpabuf_len(buf));
2159 reply[res++] = '\n';
2160 reply[res] = '\0';
2161
2162 wpabuf_free(buf);
2163
2164 return res;
2165}
2166#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002167#endif /* CONFIG_WPS_ER */
2168
2169#endif /* CONFIG_WPS */
2170
2171
2172#ifdef CONFIG_IBSS_RSN
2173static int wpa_supplicant_ctrl_iface_ibss_rsn(
2174 struct wpa_supplicant *wpa_s, char *addr)
2175{
2176 u8 peer[ETH_ALEN];
2177
2178 if (hwaddr_aton(addr, peer)) {
2179 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
2180 "address '%s'", addr);
2181 return -1;
2182 }
2183
2184 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
2185 MAC2STR(peer));
2186
2187 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
2188}
2189#endif /* CONFIG_IBSS_RSN */
2190
2191
2192static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
2193 char *rsp)
2194{
2195#ifdef IEEE8021X_EAPOL
2196 char *pos, *id_pos;
2197 int id;
2198 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002199
2200 pos = os_strchr(rsp, '-');
2201 if (pos == NULL)
2202 return -1;
2203 *pos++ = '\0';
2204 id_pos = pos;
2205 pos = os_strchr(pos, ':');
2206 if (pos == NULL)
2207 return -1;
2208 *pos++ = '\0';
2209 id = atoi(id_pos);
2210 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
2211 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2212 (u8 *) pos, os_strlen(pos));
2213
2214 ssid = wpa_config_get_network(wpa_s->conf, id);
2215 if (ssid == NULL) {
2216 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2217 "to update", id);
2218 return -1;
2219 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002220
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002221 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2222 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002223#else /* IEEE8021X_EAPOL */
2224 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2225 return -1;
2226#endif /* IEEE8021X_EAPOL */
2227}
2228
2229
2230static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2231 const char *params,
2232 char *buf, size_t buflen)
2233{
2234 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002235 int res, verbose, wps, ret;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002236#ifdef CONFIG_HS20
2237 const u8 *hs20;
2238#endif /* CONFIG_HS20 */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002239 const u8 *sess_id;
2240 size_t sess_id_len;
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002241
Dmitry Shmidt56052862013-10-04 10:23:25 -07002242 if (os_strcmp(params, "-DRIVER") == 0)
2243 return wpa_drv_status(wpa_s, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002244 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002245 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002246 pos = buf;
2247 end = buf + buflen;
2248 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2249 struct wpa_ssid *ssid = wpa_s->current_ssid;
2250 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2251 MAC2STR(wpa_s->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002252 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002253 return pos - buf;
2254 pos += ret;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002255 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2256 wpa_s->assoc_freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002257 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002258 return pos - buf;
2259 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002260 if (ssid) {
2261 u8 *_ssid = ssid->ssid;
2262 size_t ssid_len = ssid->ssid_len;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002263 u8 ssid_buf[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002264 if (ssid_len == 0) {
2265 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2266 if (_res < 0)
2267 ssid_len = 0;
2268 else
2269 ssid_len = _res;
2270 _ssid = ssid_buf;
2271 }
2272 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2273 wpa_ssid_txt(_ssid, ssid_len),
2274 ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002275 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002276 return pos - buf;
2277 pos += ret;
2278
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002279 if (wps && ssid->passphrase &&
2280 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2281 (ssid->mode == WPAS_MODE_AP ||
2282 ssid->mode == WPAS_MODE_P2P_GO)) {
2283 ret = os_snprintf(pos, end - pos,
2284 "passphrase=%s\n",
2285 ssid->passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002286 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002287 return pos - buf;
2288 pos += ret;
2289 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002290 if (ssid->id_str) {
2291 ret = os_snprintf(pos, end - pos,
2292 "id_str=%s\n",
2293 ssid->id_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002294 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002295 return pos - buf;
2296 pos += ret;
2297 }
2298
2299 switch (ssid->mode) {
2300 case WPAS_MODE_INFRA:
2301 ret = os_snprintf(pos, end - pos,
2302 "mode=station\n");
2303 break;
2304 case WPAS_MODE_IBSS:
2305 ret = os_snprintf(pos, end - pos,
2306 "mode=IBSS\n");
2307 break;
2308 case WPAS_MODE_AP:
2309 ret = os_snprintf(pos, end - pos,
2310 "mode=AP\n");
2311 break;
2312 case WPAS_MODE_P2P_GO:
2313 ret = os_snprintf(pos, end - pos,
2314 "mode=P2P GO\n");
2315 break;
2316 case WPAS_MODE_P2P_GROUP_FORMATION:
2317 ret = os_snprintf(pos, end - pos,
2318 "mode=P2P GO - group "
2319 "formation\n");
2320 break;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002321 case WPAS_MODE_MESH:
2322 ret = os_snprintf(pos, end - pos,
2323 "mode=mesh\n");
2324 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002325 default:
2326 ret = 0;
2327 break;
2328 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002329 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002330 return pos - buf;
2331 pos += ret;
2332 }
2333
Hai Shalom021b0b52019-04-10 11:17:58 -07002334 if (wpa_s->connection_set &&
2335 (wpa_s->connection_ht || wpa_s->connection_vht ||
Sunil Ravia04bd252022-05-02 22:54:18 -07002336 wpa_s->connection_he || wpa_s->connection_eht)) {
Hai Shalom021b0b52019-04-10 11:17:58 -07002337 ret = os_snprintf(pos, end - pos,
2338 "wifi_generation=%u\n",
Sunil Ravia04bd252022-05-02 22:54:18 -07002339 wpa_s->connection_eht ? 7 :
2340 (wpa_s->connection_he ? 6 :
2341 (wpa_s->connection_vht ? 5 : 4)));
Hai Shalom021b0b52019-04-10 11:17:58 -07002342 if (os_snprintf_error(end - pos, ret))
2343 return pos - buf;
2344 pos += ret;
2345 }
2346
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002347#ifdef CONFIG_AP
2348 if (wpa_s->ap_iface) {
2349 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2350 end - pos,
2351 verbose);
2352 } else
2353#endif /* CONFIG_AP */
2354 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2355 }
Paul Stewart092955c2017-02-06 09:13:09 -08002356#ifdef CONFIG_SME
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002357#ifdef CONFIG_SAE
2358 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002359#ifdef CONFIG_AP
2360 !wpa_s->ap_iface &&
2361#endif /* CONFIG_AP */
2362 wpa_s->sme.sae.state == SAE_ACCEPTED) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002363 ret = os_snprintf(pos, end - pos, "sae_group=%d\n"
2364 "sae_h2e=%d\n"
2365 "sae_pk=%d\n",
2366 wpa_s->sme.sae.group,
2367 wpa_s->sme.sae.h2e,
2368 wpa_s->sme.sae.pk);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002369 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002370 return pos - buf;
2371 pos += ret;
2372 }
2373#endif /* CONFIG_SAE */
Paul Stewart092955c2017-02-06 09:13:09 -08002374#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002375 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2376 wpa_supplicant_state_txt(wpa_s->wpa_state));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002377 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002378 return pos - buf;
2379 pos += ret;
2380
2381 if (wpa_s->l2 &&
2382 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2383 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002384 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002385 return pos - buf;
2386 pos += ret;
2387 }
2388
2389#ifdef CONFIG_P2P
2390 if (wpa_s->global->p2p) {
2391 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2392 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002393 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002394 return pos - buf;
2395 pos += ret;
2396 }
2397#endif /* CONFIG_P2P */
2398
2399 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2400 MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002401 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002402 return pos - buf;
2403 pos += ret;
2404
Sunil Ravi89eba102022-09-13 21:04:37 -07002405 if (wpa_s->valid_links) {
2406 ret = os_snprintf(pos, end - pos, "ap_mld_addr=" MACSTR "\n",
2407 MAC2STR(wpa_s->ap_mld_addr));
2408 if (os_snprintf_error(end - pos, ret))
2409 return pos - buf;
2410 pos += ret;
2411 }
2412
Dmitry Shmidt04949592012-07-19 12:16:46 -07002413#ifdef CONFIG_HS20
2414 if (wpa_s->current_bss &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002415 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2416 HS20_IE_VENDOR_TYPE)) &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002417 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2418 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002419 int release = 1;
2420 if (hs20[1] >= 5) {
2421 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2422 release = rel_num + 1;
2423 }
2424 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002425 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002426 return pos - buf;
2427 pos += ret;
2428 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002429
2430 if (wpa_s->current_ssid) {
2431 struct wpa_cred *cred;
2432 char *type;
2433
2434 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002435 size_t i;
2436
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002437 if (wpa_s->current_ssid->parent_cred != cred)
2438 continue;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002439
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002440 if (cred->provisioning_sp) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002441 ret = os_snprintf(pos, end - pos,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002442 "provisioning_sp=%s\n",
2443 cred->provisioning_sp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002444 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt051af732013-10-22 13:52:46 -07002445 return pos - buf;
2446 pos += ret;
2447 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002448
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002449 if (!cred->domain)
2450 goto no_domain;
2451
2452 i = 0;
2453 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2454 struct wpabuf *names =
2455 wpa_s->current_bss->anqp->domain_name;
2456 for (i = 0; names && i < cred->num_domain; i++)
2457 {
2458 if (domain_name_list_contains(
2459 names, cred->domain[i], 1))
2460 break;
2461 }
2462 if (i == cred->num_domain)
2463 i = 0; /* show first entry by default */
2464 }
2465 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2466 cred->domain[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002467 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002468 return pos - buf;
2469 pos += ret;
2470
2471 no_domain:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002472 if (wpa_s->current_bss == NULL ||
2473 wpa_s->current_bss->anqp == NULL)
2474 res = -1;
2475 else
2476 res = interworking_home_sp_cred(
2477 wpa_s, cred,
2478 wpa_s->current_bss->anqp->domain_name);
2479 if (res > 0)
2480 type = "home";
2481 else if (res == 0)
2482 type = "roaming";
2483 else
2484 type = "unknown";
2485
2486 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002487 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002488 return pos - buf;
2489 pos += ret;
2490
2491 break;
2492 }
2493 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002494#endif /* CONFIG_HS20 */
2495
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002496 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2497 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2498 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2499 verbose);
2500 if (res >= 0)
2501 pos += res;
2502 }
2503
Dmitry Shmidt29333592017-01-09 12:27:11 -08002504#ifdef CONFIG_MACSEC
2505 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2506 if (res > 0)
2507 pos += res;
2508#endif /* CONFIG_MACSEC */
2509
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002510 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2511 if (sess_id) {
2512 char *start = pos;
2513
2514 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2515 if (os_snprintf_error(end - pos, ret))
2516 return start - buf;
2517 pos += ret;
2518 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2519 if (ret <= 0)
2520 return start - buf;
2521 pos += ret;
2522 ret = os_snprintf(pos, end - pos, "\n");
2523 if (os_snprintf_error(end - pos, ret))
2524 return start - buf;
2525 pos += ret;
2526 }
2527
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002528 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2529 if (res >= 0)
2530 pos += res;
2531
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002532#ifdef CONFIG_WPS
2533 {
2534 char uuid_str[100];
2535 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2536 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002537 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002538 return pos - buf;
2539 pos += ret;
2540 }
2541#endif /* CONFIG_WPS */
2542
Roshan Pius3a1667e2018-07-03 15:17:14 -07002543 if (wpa_s->ieee80211ac) {
2544 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2545 if (os_snprintf_error(end - pos, ret))
2546 return pos - buf;
2547 pos += ret;
2548 }
2549
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002550#ifdef ANDROID
vandwalleffc70182014-09-11 11:40:14 -07002551 /*
2552 * Allow using the STATUS command with default behavior, say for debug,
2553 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2554 * events with STATUS-NO_EVENTS.
2555 */
2556 if (os_strcmp(params, "-NO_EVENTS")) {
2557 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2558 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2559 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2560 wpa_s->wpa_state,
2561 MAC2STR(wpa_s->bssid),
2562 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2563 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2564 wpa_s->current_ssid->ssid_len) : "");
2565 if (wpa_s->wpa_state == WPA_COMPLETED) {
2566 struct wpa_ssid *ssid = wpa_s->current_ssid;
Sunil Ravi89eba102022-09-13 21:04:37 -07002567 char mld_addr[50];
2568
2569 mld_addr[0] = '\0';
2570 if (wpa_s->valid_links)
2571 os_snprintf(mld_addr, sizeof(mld_addr),
2572 " ap_mld_addr=" MACSTR,
2573 MAC2STR(wpa_s->ap_mld_addr));
2574
vandwalleffc70182014-09-11 11:40:14 -07002575 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2576 "- connection to " MACSTR
Sunil Ravi89eba102022-09-13 21:04:37 -07002577 " completed %s [id=%d id_str=%s]%s",
vandwalleffc70182014-09-11 11:40:14 -07002578 MAC2STR(wpa_s->bssid), "(auth)",
2579 ssid ? ssid->id : -1,
Sunil Ravi89eba102022-09-13 21:04:37 -07002580 ssid && ssid->id_str ? ssid->id_str : "",
2581 mld_addr);
vandwalleffc70182014-09-11 11:40:14 -07002582 }
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08002583 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002584#endif /* ANDROID */
2585
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002586 return pos - buf;
2587}
2588
2589
2590static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2591 char *cmd)
2592{
2593 char *pos;
2594 int id;
2595 struct wpa_ssid *ssid;
2596 u8 bssid[ETH_ALEN];
2597
2598 /* cmd: "<network id> <BSSID>" */
2599 pos = os_strchr(cmd, ' ');
2600 if (pos == NULL)
2601 return -1;
2602 *pos++ = '\0';
2603 id = atoi(cmd);
2604 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2605 if (hwaddr_aton(pos, bssid)) {
2606 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2607 return -1;
2608 }
2609
2610 ssid = wpa_config_get_network(wpa_s->conf, id);
2611 if (ssid == NULL) {
2612 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2613 "to update", id);
2614 return -1;
2615 }
2616
2617 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2618 ssid->bssid_set = !is_zero_ether_addr(bssid);
2619
2620 return 0;
2621}
2622
2623
Hai Shalom60840252021-02-19 19:02:11 -08002624static int wpa_supplicant_ctrl_iface_bssid_ignore(struct wpa_supplicant *wpa_s,
2625 char *cmd, char *buf,
2626 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002627{
2628 u8 bssid[ETH_ALEN];
Hai Shalom60840252021-02-19 19:02:11 -08002629 struct wpa_bssid_ignore *e;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002630 char *pos, *end;
2631 int ret;
2632
Hai Shalom60840252021-02-19 19:02:11 -08002633 /* cmd: "BSSID_IGNORE [<BSSID>]" */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002634 if (*cmd == '\0') {
2635 pos = buf;
2636 end = buf + buflen;
Hai Shalom60840252021-02-19 19:02:11 -08002637 e = wpa_s->bssid_ignore;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002638 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002639 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2640 MAC2STR(e->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002641 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002642 return pos - buf;
2643 pos += ret;
2644 e = e->next;
2645 }
2646 return pos - buf;
2647 }
2648
2649 cmd++;
2650 if (os_strncmp(cmd, "clear", 5) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -08002651 wpa_bssid_ignore_clear(wpa_s);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002652 os_memcpy(buf, "OK\n", 3);
2653 return 3;
2654 }
2655
Hai Shalom60840252021-02-19 19:02:11 -08002656 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BSSID_IGNORE bssid='%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002657 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002658 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002659 return -1;
2660 }
2661
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002662 /*
2663 * Add the BSSID twice, so its count will be 2, causing it to be
2664 * skipped when processing scan results.
2665 */
Hai Shalom60840252021-02-19 19:02:11 -08002666 ret = wpa_bssid_ignore_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002667 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002668 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002669 ret = wpa_bssid_ignore_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002670 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002671 return -1;
2672 os_memcpy(buf, "OK\n", 3);
2673 return 3;
2674}
2675
2676
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002677static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2678 char *cmd, char *buf,
2679 size_t buflen)
2680{
2681 char *pos, *end, *stamp;
2682 int ret;
2683
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002684 /* cmd: "LOG_LEVEL [<level>]" */
2685 if (*cmd == '\0') {
2686 pos = buf;
2687 end = buf + buflen;
2688 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2689 "Timestamp: %d\n",
2690 debug_level_str(wpa_debug_level),
2691 wpa_debug_timestamp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002692 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002693 ret = 0;
2694
2695 return ret;
2696 }
2697
2698 while (*cmd == ' ')
2699 cmd++;
2700
2701 stamp = os_strchr(cmd, ' ');
2702 if (stamp) {
2703 *stamp++ = '\0';
2704 while (*stamp == ' ') {
2705 stamp++;
2706 }
2707 }
2708
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002709 if (os_strlen(cmd)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002710 int level = str_to_debug_level(cmd);
2711 if (level < 0)
2712 return -1;
2713 wpa_debug_level = level;
2714 }
2715
2716 if (stamp && os_strlen(stamp))
2717 wpa_debug_timestamp = atoi(stamp);
2718
2719 os_memcpy(buf, "OK\n", 3);
2720 return 3;
2721}
2722
2723
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002724static int wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002725 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002726{
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002727 char *pos, *end, *prev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002728 struct wpa_ssid *ssid;
2729 int ret;
2730
2731 pos = buf;
2732 end = buf + buflen;
2733 ret = os_snprintf(pos, end - pos,
2734 "network id / ssid / bssid / flags\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002735 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002736 return pos - buf;
2737 pos += ret;
2738
2739 ssid = wpa_s->conf->ssid;
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002740
2741 /* skip over ssids until we find next one */
2742 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2743 int last_id = atoi(cmd + 8);
2744 if (last_id != -1) {
2745 while (ssid != NULL && ssid->id <= last_id) {
2746 ssid = ssid->next;
2747 }
2748 }
2749 }
2750
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002751 while (ssid) {
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002752 prev = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002753 ret = os_snprintf(pos, end - pos, "%d\t%s",
2754 ssid->id,
2755 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002756 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002757 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002758 pos += ret;
2759 if (ssid->bssid_set) {
2760 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2761 MAC2STR(ssid->bssid));
2762 } else {
2763 ret = os_snprintf(pos, end - pos, "\tany");
2764 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002765 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002766 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002767 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002768 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002769 ssid == wpa_s->current_ssid ?
2770 "[CURRENT]" : "",
2771 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002772 ssid->disabled_until.sec ?
2773 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002774 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2775 "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002776 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002777 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002778 pos += ret;
2779 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002780 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002781 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002782 pos += ret;
2783
2784 ssid = ssid->next;
2785 }
2786
2787 return pos - buf;
2788}
2789
2790
2791static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2792{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002793 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002794 ret = os_snprintf(pos, end - pos, "-");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002795 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002796 return pos;
2797 pos += ret;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002798 ret = wpa_write_ciphers(pos, end, cipher, "+");
2799 if (ret < 0)
2800 return pos;
2801 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002802 return pos;
2803}
2804
2805
2806static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2807 const u8 *ie, size_t ie_len)
2808{
2809 struct wpa_ie_data data;
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002810 char *start;
2811 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002812
2813 ret = os_snprintf(pos, end - pos, "[%s-", proto);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002814 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002815 return pos;
2816 pos += ret;
2817
2818 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2819 ret = os_snprintf(pos, end - pos, "?]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002820 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002821 return pos;
2822 pos += ret;
2823 return pos;
2824 }
2825
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002826 start = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002827 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002828 ret = os_snprintf(pos, end - pos, "%sEAP",
2829 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002830 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002831 return pos;
2832 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002833 }
2834 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002835 ret = os_snprintf(pos, end - pos, "%sPSK",
2836 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002837 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002838 return pos;
2839 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002840 }
2841 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002842 ret = os_snprintf(pos, end - pos, "%sNone",
2843 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002844 if (os_snprintf_error(end - pos, ret))
2845 return pos;
2846 pos += ret;
2847 }
2848 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2849 ret = os_snprintf(pos, end - pos, "%sSAE",
2850 pos == start ? "" : "+");
2851 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002852 return pos;
2853 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002854 }
Sunil Ravi89eba102022-09-13 21:04:37 -07002855 if (data.key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) {
2856 ret = os_snprintf(pos, end - pos, "%sSAE-EXT-KEY",
2857 pos == start ? "" : "+");
2858 if (os_snprintf_error(end - pos, ret))
2859 return pos;
2860 pos += ret;
2861 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002862#ifdef CONFIG_IEEE80211R
2863 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2864 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002865 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002866 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002867 return pos;
2868 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002869 }
2870 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2871 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002872 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002873 if (os_snprintf_error(end - pos, ret))
2874 return pos;
2875 pos += ret;
2876 }
2877 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2878 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2879 pos == start ? "" : "+");
2880 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002881 return pos;
2882 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002883 }
Sunil Ravi89eba102022-09-13 21:04:37 -07002884 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE_EXT_KEY) {
2885 ret = os_snprintf(pos, end - pos, "%sFT/SAE-EXT-KEY",
2886 pos == start ? "" : "+");
2887 if (os_snprintf_error(end - pos, ret))
2888 return pos;
2889 pos += ret;
2890 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002891#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002892 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2893 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002894 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002895 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002896 return pos;
2897 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002898 }
2899 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2900 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002901 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002902 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002903 return pos;
2904 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002905 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002906
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002907#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002908 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2909 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2910 pos == start ? "" : "+");
2911 if (os_snprintf_error(end - pos, ret))
2912 return pos;
2913 pos += ret;
2914 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002915#endif /* CONFIG_SUITEB */
2916
2917#ifdef CONFIG_SUITEB192
2918 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2919 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2920 pos == start ? "" : "+");
2921 if (os_snprintf_error(end - pos, ret))
2922 return pos;
2923 pos += ret;
2924 }
2925#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002926
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002927#ifdef CONFIG_FILS
2928 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2929 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2930 pos == start ? "" : "+");
2931 if (os_snprintf_error(end - pos, ret))
2932 return pos;
2933 pos += ret;
2934 }
2935 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2936 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2937 pos == start ? "" : "+");
2938 if (os_snprintf_error(end - pos, ret))
2939 return pos;
2940 pos += ret;
2941 }
2942#ifdef CONFIG_IEEE80211R
2943 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2944 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2945 pos == start ? "" : "+");
2946 if (os_snprintf_error(end - pos, ret))
2947 return pos;
2948 pos += ret;
2949 }
2950 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2951 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2952 pos == start ? "" : "+");
2953 if (os_snprintf_error(end - pos, ret))
2954 return pos;
2955 pos += ret;
2956 }
2957#endif /* CONFIG_IEEE80211R */
2958#endif /* CONFIG_FILS */
2959
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002960#ifdef CONFIG_OWE
2961 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2962 ret = os_snprintf(pos, end - pos, "%sOWE",
2963 pos == start ? "" : "+");
2964 if (os_snprintf_error(end - pos, ret))
2965 return pos;
2966 pos += ret;
2967 }
2968#endif /* CONFIG_OWE */
2969
2970#ifdef CONFIG_DPP
2971 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
2972 ret = os_snprintf(pos, end - pos, "%sDPP",
2973 pos == start ? "" : "+");
2974 if (os_snprintf_error(end - pos, ret))
2975 return pos;
2976 pos += ret;
2977 }
2978#endif /* CONFIG_DPP */
2979
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002980 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2981 ret = os_snprintf(pos, end - pos, "%sOSEN",
2982 pos == start ? "" : "+");
2983 if (os_snprintf_error(end - pos, ret))
2984 return pos;
2985 pos += ret;
2986 }
2987
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002988#ifdef CONFIG_SHA384
2989 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA384) {
2990 ret = os_snprintf(pos, end - pos, "%sEAP-SHA384",
2991 pos == start ? "" : "+");
2992 if (os_snprintf_error(end - pos, ret))
2993 return pos;
2994 pos += ret;
2995 }
2996#endif /* CONFIG_SHA384 */
2997
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002998 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2999
3000 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
3001 ret = os_snprintf(pos, end - pos, "-preauth");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003002 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003003 return pos;
3004 pos += ret;
3005 }
3006
3007 ret = os_snprintf(pos, end - pos, "]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003008 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003009 return pos;
3010 pos += ret;
3011
3012 return pos;
3013}
3014
3015
3016#ifdef CONFIG_WPS
3017static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
3018 char *pos, char *end,
3019 struct wpabuf *wps_ie)
3020{
3021 int ret;
3022 const char *txt;
3023
3024 if (wps_ie == NULL)
3025 return pos;
3026 if (wps_is_selected_pbc_registrar(wps_ie))
3027 txt = "[WPS-PBC]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003028 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
3029 txt = "[WPS-AUTH]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003030 else if (wps_is_selected_pin_registrar(wps_ie))
3031 txt = "[WPS-PIN]";
3032 else
3033 txt = "[WPS]";
3034
3035 ret = os_snprintf(pos, end - pos, "%s", txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003036 if (!os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003037 pos += ret;
3038 wpabuf_free(wps_ie);
3039 return pos;
3040}
3041#endif /* CONFIG_WPS */
3042
3043
3044static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
3045 char *pos, char *end,
3046 const struct wpa_bss *bss)
3047{
3048#ifdef CONFIG_WPS
3049 struct wpabuf *wps_ie;
3050 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
3051 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
3052#else /* CONFIG_WPS */
3053 return pos;
3054#endif /* CONFIG_WPS */
3055}
3056
3057
3058/* Format one result on one text line into a buffer. */
3059static int wpa_supplicant_ctrl_iface_scan_result(
3060 struct wpa_supplicant *wpa_s,
3061 const struct wpa_bss *bss, char *buf, size_t buflen)
3062{
3063 char *pos, *end;
3064 int ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07003065 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe, *rsnxe;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003066
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003067 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003068 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07003069 if (!p2p)
3070 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003071 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
3072 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
3073 0)
3074 return 0; /* Do not show P2P listen discovery results here */
3075
3076 pos = buf;
3077 end = buf + buflen;
3078
3079 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
3080 MAC2STR(bss->bssid), bss->freq, bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003081 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003082 return -1;
3083 pos += ret;
3084 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3085 if (ie)
3086 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
3087 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003088 if (ie2) {
3089 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
3090 ie2, 2 + ie2[1]);
3091 }
Hai Shalom899fcc72020-10-19 14:38:18 -07003092 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003093 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
3094 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
3095 if (os_snprintf_error(end - pos, ret))
3096 return -1;
3097 pos += ret;
3098 }
3099 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
3100 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
3101 if (os_snprintf_error(end - pos, ret))
3102 return -1;
3103 pos += ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07003104 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003105 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
3106 if (osen_ie)
3107 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
3108 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003109 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
3110 if (owe) {
3111 ret = os_snprintf(pos, end - pos,
3112 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
3113 if (os_snprintf_error(end - pos, ret))
3114 return -1;
3115 pos += ret;
3116 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003117 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003118 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003119 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003120 if (os_snprintf_error(end - pos, ret))
3121 return -1;
3122 pos += ret;
3123 }
3124 if (mesh) {
3125 ret = os_snprintf(pos, end - pos, "[MESH]");
3126 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003127 return -1;
3128 pos += ret;
3129 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003130 if (bss_is_dmg(bss)) {
3131 const char *s;
Hai Shalomc3565922019-10-28 11:58:20 -07003132
Hai Shalom60840252021-02-19 19:02:11 -08003133 if (wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_EDMG_OPERATION)) {
Hai Shalomc3565922019-10-28 11:58:20 -07003134 ret = os_snprintf(pos, end - pos, "[EDMG]");
3135 if (os_snprintf_error(end - pos, ret))
3136 return -1;
3137 pos += ret;
3138 }
3139
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003140 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003141 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003142 return -1;
3143 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003144 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3145 case IEEE80211_CAP_DMG_IBSS:
3146 s = "[IBSS]";
3147 break;
3148 case IEEE80211_CAP_DMG_AP:
3149 s = "[ESS]";
3150 break;
3151 case IEEE80211_CAP_DMG_PBSS:
3152 s = "[PBSS]";
3153 break;
3154 default:
3155 s = "";
3156 break;
3157 }
3158 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003159 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003160 return -1;
3161 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003162 } else {
3163 if (bss->caps & IEEE80211_CAP_IBSS) {
3164 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003165 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003166 return -1;
3167 pos += ret;
3168 }
3169 if (bss->caps & IEEE80211_CAP_ESS) {
3170 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003171 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003172 return -1;
3173 pos += ret;
3174 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003175 }
3176 if (p2p) {
3177 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003178 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003179 return -1;
3180 pos += ret;
3181 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003182#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003183 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003184 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003185 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003186 return -1;
3187 pos += ret;
3188 }
3189#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003190#ifdef CONFIG_FILS
3191 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
3192 ret = os_snprintf(pos, end - pos, "[FILS]");
3193 if (os_snprintf_error(end - pos, ret))
3194 return -1;
3195 pos += ret;
3196 }
3197#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003198#ifdef CONFIG_FST
3199 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
3200 ret = os_snprintf(pos, end - pos, "[FST]");
3201 if (os_snprintf_error(end - pos, ret))
3202 return -1;
3203 pos += ret;
3204 }
3205#endif /* CONFIG_FST */
Hai Shalom74f70d42019-02-11 14:42:39 -08003206 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
3207 ret = os_snprintf(pos, end - pos, "[UTF-8]");
3208 if (os_snprintf_error(end - pos, ret))
3209 return -1;
3210 pos += ret;
3211 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003212
3213 ret = os_snprintf(pos, end - pos, "\t%s",
3214 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003215 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003216 return -1;
3217 pos += ret;
3218
3219 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003220 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003221 return -1;
3222 pos += ret;
3223
3224 return pos - buf;
3225}
3226
3227
3228static int wpa_supplicant_ctrl_iface_scan_results(
3229 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3230{
3231 char *pos, *end;
3232 struct wpa_bss *bss;
3233 int ret;
3234
3235 pos = buf;
3236 end = buf + buflen;
3237 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
3238 "flags / ssid\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003239 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003240 return pos - buf;
3241 pos += ret;
3242
3243 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3244 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
3245 end - pos);
3246 if (ret < 0 || ret >= end - pos)
3247 return pos - buf;
3248 pos += ret;
3249 }
3250
3251 return pos - buf;
3252}
3253
3254
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003255#ifdef CONFIG_MESH
3256
3257static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3258 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
3259{
3260 char *pos, ifname[IFNAMSIZ + 1];
3261
3262 ifname[0] = '\0';
3263
3264 pos = os_strstr(cmd, "ifname=");
3265 if (pos) {
3266 pos += 7;
3267 os_strlcpy(ifname, pos, sizeof(ifname));
3268 }
3269
3270 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
3271 return -1;
3272
3273 os_strlcpy(reply, ifname, max_len);
3274 return os_strlen(ifname);
3275}
3276
3277
3278static int wpa_supplicant_ctrl_iface_mesh_group_add(
3279 struct wpa_supplicant *wpa_s, char *cmd)
3280{
3281 int id;
3282 struct wpa_ssid *ssid;
3283
3284 id = atoi(cmd);
3285 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
3286
3287 ssid = wpa_config_get_network(wpa_s->conf, id);
3288 if (ssid == NULL) {
3289 wpa_printf(MSG_DEBUG,
3290 "CTRL_IFACE: Could not find network id=%d", id);
3291 return -1;
3292 }
3293 if (ssid->mode != WPAS_MODE_MESH) {
3294 wpa_printf(MSG_DEBUG,
3295 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3296 return -1;
3297 }
3298 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
Sunil Ravi89eba102022-09-13 21:04:37 -07003299 ssid->key_mgmt != WPA_KEY_MGMT_SAE &&
3300 ssid->key_mgmt != WPA_KEY_MGMT_SAE_EXT_KEY) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003301 wpa_printf(MSG_ERROR,
3302 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3303 return -1;
3304 }
3305
3306 /*
3307 * TODO: If necessary write our own group_add function,
3308 * for now we can reuse select_network
3309 */
3310 wpa_supplicant_select_network(wpa_s, ssid);
3311
3312 return 0;
3313}
3314
3315
3316static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3317 struct wpa_supplicant *wpa_s, char *cmd)
3318{
3319 struct wpa_supplicant *orig;
3320 struct wpa_global *global;
3321 int found = 0;
3322
3323 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3324
3325 global = wpa_s->global;
3326 orig = wpa_s;
3327
3328 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3329 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3330 found = 1;
3331 break;
3332 }
3333 }
3334 if (!found) {
3335 wpa_printf(MSG_ERROR,
3336 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3337 cmd);
3338 return -1;
3339 }
3340 if (wpa_s->mesh_if_created && wpa_s == orig) {
3341 wpa_printf(MSG_ERROR,
3342 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3343 return -1;
3344 }
3345
3346 wpa_s->reassociate = 0;
3347 wpa_s->disconnected = 1;
3348 wpa_supplicant_cancel_sched_scan(wpa_s);
3349 wpa_supplicant_cancel_scan(wpa_s);
3350
3351 /*
3352 * TODO: If necessary write our own group_remove function,
3353 * for now we can reuse deauthenticate
3354 */
3355 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3356
3357 if (wpa_s->mesh_if_created)
3358 wpa_supplicant_remove_iface(global, wpa_s, 0);
3359
3360 return 0;
3361}
3362
Dmitry Shmidte4663042016-04-04 10:07:49 -07003363
3364static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3365 struct wpa_supplicant *wpa_s, char *cmd)
3366{
3367 u8 addr[ETH_ALEN];
3368
3369 if (hwaddr_aton(cmd, addr) < 0)
3370 return -1;
3371
3372 return wpas_mesh_peer_remove(wpa_s, addr);
3373}
3374
3375
3376static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3377 struct wpa_supplicant *wpa_s, char *cmd)
3378{
3379 u8 addr[ETH_ALEN];
3380 int duration;
3381 char *pos;
3382
3383 pos = os_strstr(cmd, " duration=");
3384 if (pos) {
3385 *pos = '\0';
3386 duration = atoi(pos + 10);
3387 } else {
3388 duration = -1;
3389 }
3390
3391 if (hwaddr_aton(cmd, addr))
3392 return -1;
3393
3394 return wpas_mesh_peer_add(wpa_s, addr, duration);
3395}
3396
Hai Shalom81f62d82019-07-22 12:10:00 -07003397
3398static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3399 struct wpa_supplicant *wpa_s, char *cmd)
3400{
3401 struct ether_header *eth;
3402 u8 addr[ETH_ALEN];
3403 u8 *buf;
3404 char *pos;
3405 size_t payload_len = 0, len;
3406 int ret = -1;
3407
3408 if (hwaddr_aton(cmd, addr))
3409 return -1;
3410
3411 pos = os_strstr(cmd, " payload=");
3412 if (pos) {
3413 pos = pos + 9;
3414 payload_len = os_strlen(pos);
3415 if (payload_len & 1)
3416 return -1;
3417
3418 payload_len /= 2;
3419 }
3420
3421 len = ETH_HLEN + payload_len;
3422 buf = os_malloc(len);
3423 if (!buf)
3424 return -1;
3425
3426 eth = (struct ether_header *) buf;
3427 os_memcpy(eth->ether_dhost, addr, ETH_ALEN);
3428 os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN);
3429 eth->ether_type = htons(ETH_P_802_3);
3430
3431 if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0)
3432 goto fail;
3433
3434 ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len);
3435fail:
3436 os_free(buf);
3437 return -ret;
3438}
3439
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003440#endif /* CONFIG_MESH */
3441
3442
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003443static int wpa_supplicant_ctrl_iface_select_network(
3444 struct wpa_supplicant *wpa_s, char *cmd)
3445{
3446 int id;
3447 struct wpa_ssid *ssid;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003448 char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003449
3450 /* cmd: "<network id>" or "any" */
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003451 if (os_strncmp(cmd, "any", 3) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003452 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3453 ssid = NULL;
3454 } else {
3455 id = atoi(cmd);
3456 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3457
3458 ssid = wpa_config_get_network(wpa_s->conf, id);
3459 if (ssid == NULL) {
3460 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3461 "network id=%d", id);
3462 return -1;
3463 }
3464 if (ssid->disabled == 2) {
3465 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3466 "SELECT_NETWORK with persistent P2P group");
3467 return -1;
3468 }
3469 }
3470
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003471 pos = os_strstr(cmd, " freq=");
3472 if (pos) {
3473 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3474 if (freqs) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003475 os_free(wpa_s->select_network_scan_freqs);
3476 wpa_s->select_network_scan_freqs = freqs;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003477 }
3478 }
3479
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003480 wpa_s->scan_min_time.sec = 0;
3481 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003482 wpa_supplicant_select_network(wpa_s, ssid);
3483
3484 return 0;
3485}
3486
3487
3488static int wpa_supplicant_ctrl_iface_enable_network(
3489 struct wpa_supplicant *wpa_s, char *cmd)
3490{
3491 int id;
3492 struct wpa_ssid *ssid;
3493
3494 /* cmd: "<network id>" or "all" */
3495 if (os_strcmp(cmd, "all") == 0) {
3496 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3497 ssid = NULL;
3498 } else {
3499 id = atoi(cmd);
3500 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3501
3502 ssid = wpa_config_get_network(wpa_s->conf, id);
3503 if (ssid == NULL) {
3504 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3505 "network id=%d", id);
3506 return -1;
3507 }
3508 if (ssid->disabled == 2) {
3509 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3510 "ENABLE_NETWORK with persistent P2P group");
3511 return -1;
3512 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003513
3514 if (os_strstr(cmd, " no-connect")) {
3515 ssid->disabled = 0;
3516 return 0;
3517 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003518 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003519 wpa_s->scan_min_time.sec = 0;
3520 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003521 wpa_supplicant_enable_network(wpa_s, ssid);
3522
3523 return 0;
3524}
3525
3526
3527static int wpa_supplicant_ctrl_iface_disable_network(
3528 struct wpa_supplicant *wpa_s, char *cmd)
3529{
3530 int id;
3531 struct wpa_ssid *ssid;
3532
3533 /* cmd: "<network id>" or "all" */
3534 if (os_strcmp(cmd, "all") == 0) {
3535 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3536 ssid = NULL;
3537 } else {
3538 id = atoi(cmd);
3539 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3540
3541 ssid = wpa_config_get_network(wpa_s->conf, id);
3542 if (ssid == NULL) {
3543 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3544 "network id=%d", id);
3545 return -1;
3546 }
3547 if (ssid->disabled == 2) {
3548 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3549 "DISABLE_NETWORK with persistent P2P "
3550 "group");
3551 return -1;
3552 }
3553 }
3554 wpa_supplicant_disable_network(wpa_s, ssid);
3555
3556 return 0;
3557}
3558
3559
3560static int wpa_supplicant_ctrl_iface_add_network(
3561 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3562{
3563 struct wpa_ssid *ssid;
3564 int ret;
3565
3566 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3567
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003568 ssid = wpa_supplicant_add_network(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003569 if (ssid == NULL)
3570 return -1;
3571
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003572 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003573 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003574 return -1;
3575 return ret;
3576}
3577
3578
3579static int wpa_supplicant_ctrl_iface_remove_network(
3580 struct wpa_supplicant *wpa_s, char *cmd)
3581{
3582 int id;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003583 int result;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003584
3585 /* cmd: "<network id>" or "all" */
3586 if (os_strcmp(cmd, "all") == 0) {
3587 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Hai Shalom899fcc72020-10-19 14:38:18 -07003588 return wpa_supplicant_remove_all_networks(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003589 }
3590
3591 id = atoi(cmd);
3592 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3593
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003594 result = wpa_supplicant_remove_network(wpa_s, id);
3595 if (result == -1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003596 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3597 "id=%d", id);
3598 return -1;
3599 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003600 if (result == -2) {
Deepthi Gowria831d782012-09-03 11:55:38 +03003601 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3602 "network id=%d", id);
3603 return -1;
3604 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003605 return 0;
3606}
3607
3608
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003609static int wpa_supplicant_ctrl_iface_update_network(
3610 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3611 char *name, char *value)
3612{
Dmitry Shmidte4663042016-04-04 10:07:49 -07003613 int ret;
3614
3615 ret = wpa_config_set(ssid, name, value, 0);
3616 if (ret < 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003617 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3618 "variable '%s'", name);
3619 return -1;
3620 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07003621 if (ret == 1)
3622 return 0; /* No change to the previously configured value */
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003623
Hai Shalom899fcc72020-10-19 14:38:18 -07003624#ifdef CONFIG_BGSCAN
3625 if (os_strcmp(name, "bgscan") == 0) {
3626 /*
3627 * Reset the bgscan parameters for the current network and
3628 * return. There's no need to flush caches for bgscan parameter
3629 * changes.
3630 */
3631 if (wpa_s->current_ssid == ssid &&
3632 wpa_s->wpa_state == WPA_COMPLETED)
3633 wpa_supplicant_reset_bgscan(wpa_s);
3634 return 0;
3635 }
3636#endif /* CONFIG_BGSCAN */
3637
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003638 if (os_strcmp(name, "bssid") != 0 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003639 os_strncmp(name, "bssid_", 6) != 0 &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003640 os_strcmp(name, "scan_freq") != 0 &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003641 os_strcmp(name, "priority") != 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003642 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3643
Dmitry Shmidte4663042016-04-04 10:07:49 -07003644 if (wpa_s->current_ssid == ssid ||
3645 wpa_s->current_ssid == NULL) {
3646 /*
3647 * Invalidate the EAP session cache if anything in the
3648 * current or previously used configuration changes.
3649 */
3650 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3651 }
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003652 }
3653
3654 if ((os_strcmp(name, "psk") == 0 &&
3655 value[0] == '"' && ssid->ssid_len) ||
3656 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3657 wpa_config_update_psk(ssid);
3658 else if (os_strcmp(name, "priority") == 0)
3659 wpa_config_update_prio_list(wpa_s->conf);
3660
3661 return 0;
3662}
3663
3664
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003665static int wpa_supplicant_ctrl_iface_set_network(
3666 struct wpa_supplicant *wpa_s, char *cmd)
3667{
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003668 int id, ret, prev_bssid_set, prev_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003669 struct wpa_ssid *ssid;
3670 char *name, *value;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003671 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003672
3673 /* cmd: "<network id> <variable name> <value>" */
3674 name = os_strchr(cmd, ' ');
3675 if (name == NULL)
3676 return -1;
3677 *name++ = '\0';
3678
3679 value = os_strchr(name, ' ');
3680 if (value == NULL)
3681 return -1;
3682 *value++ = '\0';
3683
3684 id = atoi(cmd);
3685 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3686 id, name);
3687 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3688 (u8 *) value, os_strlen(value));
3689
3690 ssid = wpa_config_get_network(wpa_s->conf, id);
3691 if (ssid == NULL) {
3692 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3693 "id=%d", id);
3694 return -1;
3695 }
3696
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003697 prev_bssid_set = ssid->bssid_set;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003698 prev_disabled = ssid->disabled;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003699 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3700 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3701 value);
3702 if (ret == 0 &&
3703 (ssid->bssid_set != prev_bssid_set ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003704 !ether_addr_equal(ssid->bssid, prev_bssid)))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003705 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003706
3707 if (prev_disabled != ssid->disabled &&
3708 (prev_disabled == 2 || ssid->disabled == 2))
3709 wpas_notify_network_type_changed(wpa_s, ssid);
3710
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003711 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003712}
3713
3714
3715static int wpa_supplicant_ctrl_iface_get_network(
3716 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3717{
3718 int id;
3719 size_t res;
3720 struct wpa_ssid *ssid;
3721 char *name, *value;
3722
3723 /* cmd: "<network id> <variable name>" */
3724 name = os_strchr(cmd, ' ');
3725 if (name == NULL || buflen == 0)
3726 return -1;
3727 *name++ = '\0';
3728
3729 id = atoi(cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003730 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003731 id, name);
3732
3733 ssid = wpa_config_get_network(wpa_s->conf, id);
3734 if (ssid == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003735 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003736 "id=%d", id);
3737 return -1;
3738 }
3739
3740 value = wpa_config_get_no_key(ssid, name);
3741 if (value == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003742 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003743 "variable '%s'", name);
3744 return -1;
3745 }
3746
3747 res = os_strlcpy(buf, value, buflen);
3748 if (res >= buflen) {
3749 os_free(value);
3750 return -1;
3751 }
3752
3753 os_free(value);
3754
3755 return res;
3756}
3757
3758
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003759static int wpa_supplicant_ctrl_iface_dup_network(
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003760 struct wpa_supplicant *wpa_s, char *cmd,
3761 struct wpa_supplicant *dst_wpa_s)
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003762{
3763 struct wpa_ssid *ssid_s, *ssid_d;
3764 char *name, *id, *value;
3765 int id_s, id_d, ret;
3766
3767 /* cmd: "<src network id> <dst network id> <variable name>" */
3768 id = os_strchr(cmd, ' ');
3769 if (id == NULL)
3770 return -1;
3771 *id++ = '\0';
3772
3773 name = os_strchr(id, ' ');
3774 if (name == NULL)
3775 return -1;
3776 *name++ = '\0';
3777
3778 id_s = atoi(cmd);
3779 id_d = atoi(id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003780
3781 wpa_printf(MSG_DEBUG,
3782 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3783 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003784
3785 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3786 if (ssid_s == NULL) {
3787 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3788 "network id=%d", id_s);
3789 return -1;
3790 }
3791
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003792 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003793 if (ssid_d == NULL) {
3794 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003795 "network id=%d", id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003796 return -1;
3797 }
3798
3799 value = wpa_config_get(ssid_s, name);
3800 if (value == NULL) {
3801 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3802 "variable '%s'", name);
3803 return -1;
3804 }
3805
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003806 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003807 value);
3808
3809 os_free(value);
3810
3811 return ret;
3812}
3813
3814
Dmitry Shmidt04949592012-07-19 12:16:46 -07003815static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3816 char *buf, size_t buflen)
3817{
3818 char *pos, *end;
3819 struct wpa_cred *cred;
3820 int ret;
3821
3822 pos = buf;
3823 end = buf + buflen;
3824 ret = os_snprintf(pos, end - pos,
3825 "cred id / realm / username / domain / imsi\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003826 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003827 return pos - buf;
3828 pos += ret;
3829
3830 cred = wpa_s->conf->cred;
3831 while (cred) {
3832 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3833 cred->id, cred->realm ? cred->realm : "",
3834 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07003835 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003836 cred->imsi ? cred->imsi : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003837 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003838 return pos - buf;
3839 pos += ret;
3840
3841 cred = cred->next;
3842 }
3843
3844 return pos - buf;
3845}
3846
3847
3848static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3849 char *buf, size_t buflen)
3850{
3851 struct wpa_cred *cred;
3852 int ret;
3853
3854 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3855
3856 cred = wpa_config_add_cred(wpa_s->conf);
3857 if (cred == NULL)
3858 return -1;
3859
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003860 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3861
Dmitry Shmidt04949592012-07-19 12:16:46 -07003862 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003863 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003864 return -1;
3865 return ret;
3866}
3867
3868
3869static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3870 char *cmd)
3871{
3872 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003873 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003874
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003875 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3876 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003877 if (os_strcmp(cmd, "all") == 0) {
3878 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
Hai Shaloma20dcd72022-02-04 13:43:00 -08003879 return wpas_remove_all_creds(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003880 }
3881
3882 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3883 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3884 cmd + 8);
3885 cred = wpa_s->conf->cred;
3886 while (cred) {
3887 prev = cred;
3888 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003889 if (prev->domain) {
3890 size_t i;
3891 for (i = 0; i < prev->num_domain; i++) {
3892 if (os_strcmp(prev->domain[i], cmd + 8)
3893 != 0)
3894 continue;
Hai Shaloma20dcd72022-02-04 13:43:00 -08003895 wpas_remove_cred(wpa_s, prev);
Dmitry Shmidt051af732013-10-22 13:52:46 -07003896 break;
3897 }
3898 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003899 }
3900 return 0;
3901 }
3902
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003903 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3904 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3905 cmd + 16);
3906 cred = wpa_s->conf->cred;
3907 while (cred) {
3908 prev = cred;
3909 cred = cred->next;
3910 if (prev->provisioning_sp &&
3911 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
Hai Shaloma20dcd72022-02-04 13:43:00 -08003912 wpas_remove_cred(wpa_s, prev);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003913 }
3914 return 0;
3915 }
3916
Dmitry Shmidt04949592012-07-19 12:16:46 -07003917 id = atoi(cmd);
3918 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3919
3920 cred = wpa_config_get_cred(wpa_s->conf, id);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003921 return wpas_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003922}
3923
3924
3925static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3926 char *cmd)
3927{
3928 int id;
3929 struct wpa_cred *cred;
3930 char *name, *value;
3931
3932 /* cmd: "<cred id> <variable name> <value>" */
3933 name = os_strchr(cmd, ' ');
3934 if (name == NULL)
3935 return -1;
3936 *name++ = '\0';
3937
3938 value = os_strchr(name, ' ');
3939 if (value == NULL)
3940 return -1;
3941 *value++ = '\0';
3942
3943 id = atoi(cmd);
3944 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3945 id, name);
3946 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3947 (u8 *) value, os_strlen(value));
3948
3949 cred = wpa_config_get_cred(wpa_s->conf, id);
3950 if (cred == NULL) {
3951 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3952 id);
3953 return -1;
3954 }
3955
3956 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3957 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3958 "variable '%s'", name);
3959 return -1;
3960 }
3961
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003962 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3963
Dmitry Shmidt04949592012-07-19 12:16:46 -07003964 return 0;
3965}
3966
3967
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003968static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3969 char *cmd, char *buf,
3970 size_t buflen)
3971{
3972 int id;
3973 size_t res;
3974 struct wpa_cred *cred;
3975 char *name, *value;
3976
3977 /* cmd: "<cred id> <variable name>" */
3978 name = os_strchr(cmd, ' ');
3979 if (name == NULL)
3980 return -1;
3981 *name++ = '\0';
3982
3983 id = atoi(cmd);
3984 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3985 id, name);
3986
3987 cred = wpa_config_get_cred(wpa_s->conf, id);
3988 if (cred == NULL) {
3989 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3990 id);
3991 return -1;
3992 }
3993
3994 value = wpa_config_get_cred_no_key(cred, name);
3995 if (value == NULL) {
3996 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3997 name);
3998 return -1;
3999 }
4000
4001 res = os_strlcpy(buf, value, buflen);
4002 if (res >= buflen) {
4003 os_free(value);
4004 return -1;
4005 }
4006
4007 os_free(value);
4008
4009 return res;
4010}
4011
4012
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004013#ifndef CONFIG_NO_CONFIG_WRITE
4014static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
4015{
4016 int ret;
4017
4018 if (!wpa_s->conf->update_config) {
4019 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
4020 "to update configuration (update_config=0)");
4021 return -1;
4022 }
4023
4024 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
4025 if (ret) {
4026 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
4027 "update configuration");
4028 } else {
4029 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
4030 " updated");
4031 }
4032
4033 return ret;
4034}
4035#endif /* CONFIG_NO_CONFIG_WRITE */
4036
4037
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004038struct cipher_info {
4039 unsigned int capa;
4040 const char *name;
4041 int group_only;
4042};
4043
4044static const struct cipher_info ciphers[] = {
4045 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
4046 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
4047 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
4048 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07004049#ifndef CONFIG_NO_TKIP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004050 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07004051#endif /* CONFIG_NO_TKIP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004052 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
Hai Shalomfdcde762020-04-02 11:19:20 -07004053#ifdef CONFIG_WEP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004054 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
4055 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004056#endif /* CONFIG_WEP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004057};
4058
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004059static const struct cipher_info ciphers_group_mgmt[] = {
4060 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
4061 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
4062 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
4063 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
4064};
4065
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004066
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004067static int ctrl_iface_get_capability_pairwise(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004068 struct wpa_driver_capa *capa,
4069 char *buf, size_t buflen)
4070{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004071 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004072 char *pos, *end;
4073 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004074 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004075
4076 pos = buf;
4077 end = pos + buflen;
4078
4079 if (res < 0) {
4080 if (strict)
4081 return 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07004082#ifdef CONFIG_NO_TKIP
4083 len = os_strlcpy(buf, "CCMP NONE", buflen);
4084#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004085 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004086#endif /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004087 if (len >= buflen)
4088 return -1;
4089 return len;
4090 }
4091
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004092 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4093 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
4094 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004095 pos == buf ? "" : " ",
4096 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004097 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004098 return pos - buf;
4099 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004100 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004101 }
4102
4103 return pos - buf;
4104}
4105
4106
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004107static int ctrl_iface_get_capability_group(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004108 struct wpa_driver_capa *capa,
4109 char *buf, size_t buflen)
4110{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004111 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004112 char *pos, *end;
4113 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004114 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004115
4116 pos = buf;
4117 end = pos + buflen;
4118
4119 if (res < 0) {
4120 if (strict)
4121 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07004122#ifdef CONFIG_WEP
Hai Shalomb755a2a2020-04-23 21:49:02 -07004123#ifdef CONFIG_NO_TKIP
4124 len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen);
4125#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004126 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004127#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004128#else /* CONFIG_WEP */
Hai Shalomb755a2a2020-04-23 21:49:02 -07004129#ifdef CONFIG_NO_TKIP
4130 len = os_strlcpy(buf, "CCMP", buflen);
4131#else /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004132 len = os_strlcpy(buf, "CCMP TKIP", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004133#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004134#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004135 if (len >= buflen)
4136 return -1;
4137 return len;
4138 }
4139
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004140 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4141 if (capa->enc & ciphers[i].capa) {
4142 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004143 pos == buf ? "" : " ",
4144 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004145 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004146 return pos - buf;
4147 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004148 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004149 }
4150
4151 return pos - buf;
4152}
4153
4154
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004155static int ctrl_iface_get_capability_group_mgmt(int res, bool strict,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004156 struct wpa_driver_capa *capa,
4157 char *buf, size_t buflen)
4158{
4159 int ret;
4160 char *pos, *end;
4161 unsigned int i;
4162
4163 pos = buf;
4164 end = pos + buflen;
4165
4166 if (res < 0)
4167 return 0;
4168
4169 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
4170 if (capa->enc & ciphers_group_mgmt[i].capa) {
4171 ret = os_snprintf(pos, end - pos, "%s%s",
4172 pos == buf ? "" : " ",
4173 ciphers_group_mgmt[i].name);
4174 if (os_snprintf_error(end - pos, ret))
4175 return pos - buf;
4176 pos += ret;
4177 }
4178 }
4179
4180 return pos - buf;
4181}
4182
4183
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004184static int iftype_str_to_index(const char *iftype_str)
4185{
4186 if (!iftype_str)
4187 return WPA_IF_MAX;
4188
4189 if (os_strcmp(iftype_str, "STATION") == 0)
4190 return WPA_IF_STATION;
4191
4192 if (os_strcmp(iftype_str, "AP_VLAN") == 0)
4193 return WPA_IF_AP_VLAN;
4194
4195 if (os_strcmp(iftype_str, "AP") == 0)
4196 return WPA_IF_AP_BSS;
4197
4198 if (os_strcmp(iftype_str, "P2P_GO") == 0)
4199 return WPA_IF_P2P_GO;
4200
4201 if (os_strcmp(iftype_str, "P2P_CLIENT") == 0)
4202 return WPA_IF_P2P_CLIENT;
4203
4204 if (os_strcmp(iftype_str, "P2P_DEVICE") == 0)
4205 return WPA_IF_P2P_DEVICE;
4206
4207 if (os_strcmp(iftype_str, "MESH") == 0)
4208 return WPA_IF_MESH;
4209
4210 if (os_strcmp(iftype_str, "IBSS") == 0)
4211 return WPA_IF_IBSS;
4212
4213 if (os_strcmp(iftype_str, "NAN") == 0)
4214 return WPA_IF_NAN;
4215
4216 return WPA_IF_MAX;
4217}
4218
4219
4220static int ctrl_iface_get_capability_key_mgmt(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004221 struct wpa_driver_capa *capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004222 const char *iftype_str,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004223 char *buf, size_t buflen)
4224{
4225 int ret;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004226 unsigned int key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004227 char *pos, *end;
4228 size_t len;
4229
4230 pos = buf;
4231 end = pos + buflen;
4232
4233 if (res < 0) {
4234 if (strict)
4235 return 0;
4236 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4237 "NONE", buflen);
4238 if (len >= buflen)
4239 return -1;
4240 return len;
4241 }
4242
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004243 if (iftype_str) {
4244 enum wpa_driver_if_type iftype;
4245
4246 iftype = iftype_str_to_index(iftype_str);
4247 if (iftype == WPA_IF_MAX)
4248 return -1;
4249 key_mgmt = capa->key_mgmt_iftype[iftype];
4250 } else {
4251 key_mgmt = capa->key_mgmt;
4252 }
4253
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004254 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004255 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004256 return pos - buf;
4257 pos += ret;
4258
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004259 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4260 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004261 ret = os_snprintf(pos, end - pos, " WPA-EAP");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004262 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004263 return pos - buf;
4264 pos += ret;
4265 }
4266
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004267 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
4268 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004269 ret = os_snprintf(pos, end - pos, " WPA-PSK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004270 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004271 return pos - buf;
4272 pos += ret;
4273 }
4274
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004275 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004276 ret = os_snprintf(pos, end - pos, " WPA-NONE");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004277 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004278 return pos - buf;
4279 pos += ret;
4280 }
4281
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304282 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WAPI_PSK) {
4283 ret = os_snprintf(pos, end - pos, " WAPI-PSK");
4284 if (os_snprintf_error(end - pos, ret))
4285 return pos - buf;
4286 pos += ret;
4287 }
4288
4289 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE) {
4290 ret = os_snprintf(pos, end - pos, " TPK-HANDSHAKE");
4291 if (os_snprintf_error(end - pos, ret))
4292 return pos - buf;
4293 pos += ret;
4294 }
4295
4296 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_CCKM) {
4297 ret = os_snprintf(pos, end - pos, " CCKM");
4298 if (os_snprintf_error(end - pos, ret))
4299 return pos - buf;
4300 pos += ret;
4301 }
4302
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004303#ifdef CONFIG_SUITEB
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004304 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004305 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
4306 if (os_snprintf_error(end - pos, ret))
4307 return pos - buf;
4308 pos += ret;
4309 }
4310#endif /* CONFIG_SUITEB */
4311#ifdef CONFIG_SUITEB192
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004312 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004313 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
4314 if (os_snprintf_error(end - pos, ret))
4315 return pos - buf;
4316 pos += ret;
4317 }
4318#endif /* CONFIG_SUITEB192 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004319#ifdef CONFIG_OWE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004320 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004321 ret = os_snprintf(pos, end - pos, " OWE");
4322 if (os_snprintf_error(end - pos, ret))
4323 return pos - buf;
4324 pos += ret;
4325 }
4326#endif /* CONFIG_OWE */
4327#ifdef CONFIG_DPP
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004328 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004329 ret = os_snprintf(pos, end - pos, " DPP");
4330 if (os_snprintf_error(end - pos, ret))
4331 return pos - buf;
4332 pos += ret;
4333 }
4334#endif /* CONFIG_DPP */
4335#ifdef CONFIG_FILS
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004336 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004337 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
4338 if (os_snprintf_error(end - pos, ret))
4339 return pos - buf;
4340 pos += ret;
4341 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004342 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004343 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
4344 if (os_snprintf_error(end - pos, ret))
4345 return pos - buf;
4346 pos += ret;
4347 }
4348#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004349 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004350 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
4351 if (os_snprintf_error(end - pos, ret))
4352 return pos - buf;
4353 pos += ret;
4354 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004355 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004356 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
4357 if (os_snprintf_error(end - pos, ret))
4358 return pos - buf;
4359 pos += ret;
4360 }
4361#endif /* CONFIG_IEEE80211R */
4362#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08004363#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004364 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004365 ret = os_snprintf(pos, end - pos, " FT-PSK");
4366 if (os_snprintf_error(end - pos, ret))
4367 return pos - buf;
4368 pos += ret;
4369 }
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304370 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) {
4371 ret = os_snprintf(pos, end - pos, " FT-EAP");
4372 if (os_snprintf_error(end - pos, ret))
4373 return pos - buf;
4374 pos += ret;
4375 }
4376#ifdef CONFIG_SAE
4377 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE) {
4378 ret = os_snprintf(pos, end - pos, " FT-SAE");
4379 if (os_snprintf_error(end - pos, ret))
4380 return pos - buf;
4381 pos += ret;
4382 }
Sunil Ravi89eba102022-09-13 21:04:37 -07004383 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE_EXT_KEY) {
4384 ret = os_snprintf(pos, end - pos, " FT-SAE-EXT-KEY");
4385 if (os_snprintf_error(end - pos, ret))
4386 return pos - buf;
4387 pos += ret;
4388 }
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304389#endif /* CONFIG_SAE */
4390#ifdef CONFIG_SHA384
4391 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384) {
4392 ret = os_snprintf(pos, end - pos, " FT-EAP-SHA384");
4393 if (os_snprintf_error(end - pos, ret))
4394 return pos - buf;
4395 pos += ret;
4396 }
4397#endif /* CONFIG_SHA384 */
Hai Shalom74f70d42019-02-11 14:42:39 -08004398#endif /* CONFIG_IEEE80211R */
4399#ifdef CONFIG_SAE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004400 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004401 ret = os_snprintf(pos, end - pos, " SAE");
4402 if (os_snprintf_error(end - pos, ret))
4403 return pos - buf;
4404 pos += ret;
4405 }
Sunil Ravi89eba102022-09-13 21:04:37 -07004406 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE_EXT_KEY) {
4407 ret = os_snprintf(pos, end - pos, " SAE-EXT-KEY");
4408 if (os_snprintf_error(end - pos, ret))
4409 return pos - buf;
4410 pos += ret;
4411 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004412#endif /* CONFIG_SAE */
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304413#ifdef CONFIG_SHA256
4414 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256) {
4415 ret = os_snprintf(pos, end - pos, " WPA-EAP-SHA256");
4416 if (os_snprintf_error(end - pos, ret))
4417 return pos - buf;
4418 pos += ret;
4419 }
4420
4421 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256) {
4422 ret = os_snprintf(pos, end - pos, " WPA-PSK-SHA256");
4423 if (os_snprintf_error(end - pos, ret))
4424 return pos - buf;
4425 pos += ret;
4426 }
4427#endif /* CONFIG_SHA256 */
4428#ifdef CONFIG_HS20
4429 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OSEN) {
4430 ret = os_snprintf(pos, end - pos, " OSEN");
4431 if (os_snprintf_error(end - pos, ret))
4432 return pos - buf;
4433 pos += ret;
4434 }
4435#endif /* CONFIG_HS20 */
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004436
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004437 return pos - buf;
4438}
4439
4440
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004441static int ctrl_iface_get_capability_proto(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004442 struct wpa_driver_capa *capa,
4443 char *buf, size_t buflen)
4444{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004445 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004446 char *pos, *end;
4447 size_t len;
4448
4449 pos = buf;
4450 end = pos + buflen;
4451
4452 if (res < 0) {
4453 if (strict)
4454 return 0;
4455 len = os_strlcpy(buf, "RSN WPA", buflen);
4456 if (len >= buflen)
4457 return -1;
4458 return len;
4459 }
4460
4461 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4462 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004463 ret = os_snprintf(pos, end - pos, "%sRSN",
4464 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004465 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004466 return pos - buf;
4467 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004468 }
4469
4470 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4471 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004472 ret = os_snprintf(pos, end - pos, "%sWPA",
4473 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004474 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004475 return pos - buf;
4476 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004477 }
4478
4479 return pos - buf;
4480}
4481
4482
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004483static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004484 int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004485 struct wpa_driver_capa *capa,
4486 char *buf, size_t buflen)
4487{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004488 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004489 char *pos, *end;
4490 size_t len;
4491
4492 pos = buf;
4493 end = pos + buflen;
4494
4495 if (res < 0) {
4496 if (strict)
4497 return 0;
4498 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4499 if (len >= buflen)
4500 return -1;
4501 return len;
4502 }
4503
4504 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004505 ret = os_snprintf(pos, end - pos, "%sOPEN",
4506 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004507 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004508 return pos - buf;
4509 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004510 }
4511
4512 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4513 ret = os_snprintf(pos, end - pos, "%sSHARED",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004514 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004515 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004516 return pos - buf;
4517 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004518 }
4519
4520 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004521 ret = os_snprintf(pos, end - pos, "%sLEAP",
4522 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004523 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004524 return pos - buf;
4525 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004526 }
4527
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004528#ifdef CONFIG_SAE
4529 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4530 ret = os_snprintf(pos, end - pos, "%sSAE",
4531 pos == buf ? "" : " ");
4532 if (os_snprintf_error(end - pos, ret))
4533 return pos - buf;
4534 pos += ret;
4535 }
4536#endif /* CONFIG_SAE */
4537
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004538#ifdef CONFIG_FILS
4539 if (wpa_is_fils_supported(wpa_s)) {
4540 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4541 pos == buf ? "" : " ");
4542 if (os_snprintf_error(end - pos, ret))
4543 return pos - buf;
4544 pos += ret;
4545 }
4546
4547#ifdef CONFIG_FILS_SK_PFS
4548 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4549 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4550 pos == buf ? "" : " ");
4551 if (os_snprintf_error(end - pos, ret))
4552 return pos - buf;
4553 pos += ret;
4554 }
4555#endif /* CONFIG_FILS_SK_PFS */
4556#endif /* CONFIG_FILS */
4557
Hai Shalom60840252021-02-19 19:02:11 -08004558#ifdef CONFIG_PASN
4559 ret = os_snprintf(pos, end - pos, "%sPASN",
4560 pos == buf ? "" : " ");
4561 if (os_snprintf_error(end - pos, ret))
4562 return pos - buf;
4563 pos += ret;
4564
4565#endif /* CONFIG_PASN */
4566
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004567 return pos - buf;
4568}
4569
4570
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004571static int ctrl_iface_get_capability_modes(int res, bool strict,
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004572 struct wpa_driver_capa *capa,
4573 char *buf, size_t buflen)
4574{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004575 int ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004576 char *pos, *end;
4577 size_t len;
4578
4579 pos = buf;
4580 end = pos + buflen;
4581
4582 if (res < 0) {
4583 if (strict)
4584 return 0;
4585 len = os_strlcpy(buf, "IBSS AP", buflen);
4586 if (len >= buflen)
4587 return -1;
4588 return len;
4589 }
4590
4591 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004592 ret = os_snprintf(pos, end - pos, "%sIBSS",
4593 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004594 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004595 return pos - buf;
4596 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004597 }
4598
4599 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004600 ret = os_snprintf(pos, end - pos, "%sAP",
4601 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004602 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004603 return pos - buf;
4604 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004605 }
4606
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004607#ifdef CONFIG_MESH
4608 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4609 ret = os_snprintf(pos, end - pos, "%sMESH",
4610 pos == buf ? "" : " ");
4611 if (os_snprintf_error(end - pos, ret))
4612 return pos - buf;
4613 pos += ret;
4614 }
4615#endif /* CONFIG_MESH */
4616
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004617 return pos - buf;
4618}
4619
4620
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004621static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4622 char *buf, size_t buflen)
4623{
4624 struct hostapd_channel_data *chnl;
4625 int ret, i, j;
4626 char *pos, *end, *hmode;
4627
4628 pos = buf;
4629 end = pos + buflen;
4630
4631 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4632 switch (wpa_s->hw.modes[j].mode) {
4633 case HOSTAPD_MODE_IEEE80211B:
4634 hmode = "B";
4635 break;
4636 case HOSTAPD_MODE_IEEE80211G:
4637 hmode = "G";
4638 break;
4639 case HOSTAPD_MODE_IEEE80211A:
4640 hmode = "A";
4641 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004642 case HOSTAPD_MODE_IEEE80211AD:
4643 hmode = "AD";
4644 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004645 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004646 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004647 }
4648 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004649 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004650 return pos - buf;
4651 pos += ret;
4652 chnl = wpa_s->hw.modes[j].channels;
4653 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004654 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4655 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004656 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004657 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004658 return pos - buf;
4659 pos += ret;
4660 }
4661 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004662 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004663 return pos - buf;
4664 pos += ret;
4665 }
4666
4667 return pos - buf;
4668}
4669
4670
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004671static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4672 char *buf, size_t buflen)
4673{
4674 struct hostapd_channel_data *chnl;
4675 int ret, i, j;
4676 char *pos, *end, *hmode;
4677
4678 pos = buf;
4679 end = pos + buflen;
4680
4681 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4682 switch (wpa_s->hw.modes[j].mode) {
4683 case HOSTAPD_MODE_IEEE80211B:
4684 hmode = "B";
4685 break;
4686 case HOSTAPD_MODE_IEEE80211G:
4687 hmode = "G";
4688 break;
4689 case HOSTAPD_MODE_IEEE80211A:
4690 hmode = "A";
4691 break;
4692 case HOSTAPD_MODE_IEEE80211AD:
4693 hmode = "AD";
4694 break;
4695 default:
4696 continue;
4697 }
4698 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4699 hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004700 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004701 return pos - buf;
4702 pos += ret;
4703 chnl = wpa_s->hw.modes[j].channels;
4704 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4705 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4706 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004707 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004708 chnl[i].chan, chnl[i].freq,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004709 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4710 " (NO_IR)" : "",
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004711 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4712 " (DFS)" : "");
4713
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004714 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004715 return pos - buf;
4716 pos += ret;
4717 }
4718 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004719 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004720 return pos - buf;
4721 pos += ret;
4722 }
4723
4724 return pos - buf;
4725}
4726
4727
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004728static int wpa_supplicant_ctrl_iface_get_capability(
4729 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4730 size_t buflen)
4731{
4732 struct wpa_driver_capa capa;
4733 int res;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004734 char *next_param, *curr_param, *iftype = NULL;
4735 bool strict = false;
4736 char field[50];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004737 size_t len;
4738
4739 /* Determine whether or not strict checking was requested */
4740 len = os_strlcpy(field, _field, sizeof(field));
4741 if (len >= sizeof(field))
4742 return -1;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004743
4744 next_param = os_strchr(field, ' ');
4745 while (next_param) {
4746 *next_param++ = '\0';
4747 curr_param = next_param;
4748 next_param = os_strchr(next_param, ' ');
4749
4750 if (next_param)
4751 *next_param = '\0';
4752
4753 if (os_strcmp(curr_param, "strict") == 0)
4754 strict = true;
4755 else if (os_strncmp(curr_param, "iftype=", 7) == 0)
4756 iftype = curr_param + 7;
4757 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004758 return -1;
4759 }
4760
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004761 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'%s%s%s",
4762 field, iftype ? " iftype=" : "", iftype ? iftype : "",
4763 strict ? " strict" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004764
4765 if (os_strcmp(field, "eap") == 0) {
4766 return eap_get_names(buf, buflen);
4767 }
4768
4769 res = wpa_drv_get_capa(wpa_s, &capa);
4770
4771 if (os_strcmp(field, "pairwise") == 0)
4772 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4773 buf, buflen);
4774
4775 if (os_strcmp(field, "group") == 0)
4776 return ctrl_iface_get_capability_group(res, strict, &capa,
4777 buf, buflen);
4778
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004779 if (os_strcmp(field, "group_mgmt") == 0)
4780 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4781 buf, buflen);
4782
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004783 if (os_strcmp(field, "key_mgmt") == 0)
4784 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004785 iftype, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004786
4787 if (os_strcmp(field, "proto") == 0)
4788 return ctrl_iface_get_capability_proto(res, strict, &capa,
4789 buf, buflen);
4790
4791 if (os_strcmp(field, "auth_alg") == 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004792 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4793 &capa, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004794
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004795 if (os_strcmp(field, "modes") == 0)
4796 return ctrl_iface_get_capability_modes(res, strict, &capa,
4797 buf, buflen);
4798
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004799 if (os_strcmp(field, "channels") == 0)
4800 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4801
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004802 if (os_strcmp(field, "freq") == 0)
4803 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4804
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004805#ifdef CONFIG_TDLS
4806 if (os_strcmp(field, "tdls") == 0)
4807 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4808#endif /* CONFIG_TDLS */
4809
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004810#ifdef CONFIG_ERP
4811 if (os_strcmp(field, "erp") == 0) {
4812 res = os_snprintf(buf, buflen, "ERP");
4813 if (os_snprintf_error(buflen, res))
4814 return -1;
4815 return res;
4816 }
4817#endif /* CONFIG_EPR */
4818
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004819#ifdef CONFIG_FIPS
4820 if (os_strcmp(field, "fips") == 0) {
4821 res = os_snprintf(buf, buflen, "FIPS");
4822 if (os_snprintf_error(buflen, res))
4823 return -1;
4824 return res;
4825 }
4826#endif /* CONFIG_FIPS */
4827
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004828#ifdef CONFIG_ACS
4829 if (os_strcmp(field, "acs") == 0) {
4830 res = os_snprintf(buf, buflen, "ACS");
4831 if (os_snprintf_error(buflen, res))
4832 return -1;
4833 return res;
4834 }
4835#endif /* CONFIG_ACS */
4836
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004837#ifdef CONFIG_FILS
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004838 if (os_strcmp(field, "fils") == 0) {
4839#ifdef CONFIG_FILS_SK_PFS
4840 if (wpa_is_fils_supported(wpa_s) &&
4841 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4842 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4843 if (os_snprintf_error(buflen, res))
4844 return -1;
4845 return res;
4846 }
4847#endif /* CONFIG_FILS_SK_PFS */
4848
4849 if (wpa_is_fils_supported(wpa_s)) {
4850 res = os_snprintf(buf, buflen, "FILS");
4851 if (os_snprintf_error(buflen, res))
4852 return -1;
4853 return res;
4854 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004855 }
4856#endif /* CONFIG_FILS */
4857
Hai Shalom74f70d42019-02-11 14:42:39 -08004858 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
4859 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
4860 if (os_snprintf_error(buflen, res))
4861 return -1;
4862 return res;
4863 }
4864
Hai Shalom021b0b52019-04-10 11:17:58 -07004865#ifdef CONFIG_DPP
4866 if (os_strcmp(field, "dpp") == 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08004867#ifdef CONFIG_DPP3
4868 res = os_snprintf(buf, buflen, "DPP=3");
4869#elif defined(CONFIG_DPP2)
Hai Shalom021b0b52019-04-10 11:17:58 -07004870 res = os_snprintf(buf, buflen, "DPP=2");
4871#else /* CONFIG_DPP2 */
4872 res = os_snprintf(buf, buflen, "DPP=1");
4873#endif /* CONFIG_DPP2 */
4874 if (os_snprintf_error(buflen, res))
4875 return -1;
4876 return res;
4877 }
4878#endif /* CONFIG_DPP */
4879
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004880#ifdef CONFIG_NAN_USD
4881 if (os_strcmp(field, "nan") == 0) {
4882 res = os_snprintf(buf, buflen, "USD");
4883 if (os_snprintf_error(buflen, res))
4884 return -1;
4885 return res;
4886 }
4887#endif /* CONFIG_NAN_USD */
4888
Hai Shalom899fcc72020-10-19 14:38:18 -07004889#ifdef CONFIG_SAE
4890 if (os_strcmp(field, "sae") == 0 &&
4891 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4892#ifdef CONFIG_SAE_PK
4893 res = os_snprintf(buf, buflen, "H2E PK");
4894#else /* CONFIG_SAE_PK */
4895 res = os_snprintf(buf, buflen, "H2E");
4896#endif /* CONFIG_SAE_PK */
4897 if (os_snprintf_error(buflen, res))
4898 return -1;
4899 return res;
4900 }
4901#endif /* CONFIG_SAE */
4902
Hai Shalom60840252021-02-19 19:02:11 -08004903#ifdef CONFIG_OCV
4904 if (os_strcmp(field, "ocv") == 0) {
4905 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
4906 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV))
4907 res = os_snprintf(buf, buflen, "supported");
4908 else
4909 res = os_snprintf(buf, buflen, "not supported");
4910 if (os_snprintf_error(buflen, res))
4911 return -1;
4912 return res;
4913 }
4914#endif /* CONFIG_OCV */
4915
4916 if (os_strcmp(field, "beacon_prot") == 0) {
4917 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) ||
4918 (wpa_s->drv_flags2 &
4919 WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT))
4920 res = os_snprintf(buf, buflen, "supported");
4921 else
4922 res = os_snprintf(buf, buflen, "not supported");
4923 if (os_snprintf_error(buflen, res))
4924 return -1;
4925 return res;
4926 }
4927
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004928 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4929 field);
4930
4931 return -1;
4932}
4933
4934
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004935#ifdef CONFIG_INTERWORKING
4936static char * anqp_add_hex(char *pos, char *end, const char *title,
4937 struct wpabuf *data)
4938{
4939 char *start = pos;
4940 size_t i;
4941 int ret;
4942 const u8 *d;
4943
4944 if (data == NULL)
4945 return start;
4946
4947 ret = os_snprintf(pos, end - pos, "%s=", title);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004948 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004949 return start;
4950 pos += ret;
4951
4952 d = wpabuf_head_u8(data);
4953 for (i = 0; i < wpabuf_len(data); i++) {
4954 ret = os_snprintf(pos, end - pos, "%02x", *d++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004955 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004956 return start;
4957 pos += ret;
4958 }
4959
4960 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004961 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004962 return start;
4963 pos += ret;
4964
4965 return pos;
4966}
4967#endif /* CONFIG_INTERWORKING */
4968
4969
Dmitry Shmidt29333592017-01-09 12:27:11 -08004970#ifdef CONFIG_FILS
4971static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4972{
4973 char *start = pos;
4974 const u8 *ie, *ie_end;
4975 u16 info, realms;
4976 int ret;
4977
4978 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4979 if (!ie)
4980 return 0;
4981 ie_end = ie + 2 + ie[1];
4982 ie += 2;
4983 if (ie_end - ie < 2)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004984 return 0;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004985
4986 info = WPA_GET_LE16(ie);
4987 ie += 2;
4988 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4989 if (os_snprintf_error(end - pos, ret))
4990 return 0;
4991 pos += ret;
4992
4993 if (info & BIT(7)) {
4994 /* Cache Identifier Included */
4995 if (ie_end - ie < 2)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004996 return 0;
Dmitry Shmidt29333592017-01-09 12:27:11 -08004997 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4998 ie[0], ie[1]);
4999 if (os_snprintf_error(end - pos, ret))
5000 return 0;
5001 pos += ret;
5002 ie += 2;
5003 }
5004
5005 if (info & BIT(8)) {
5006 /* HESSID Included */
5007 if (ie_end - ie < ETH_ALEN)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005008 return 0;
Dmitry Shmidt29333592017-01-09 12:27:11 -08005009 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
5010 MAC2STR(ie));
5011 if (os_snprintf_error(end - pos, ret))
5012 return 0;
5013 pos += ret;
5014 ie += ETH_ALEN;
5015 }
5016
5017 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
5018 if (realms) {
5019 if (ie_end - ie < realms * 2)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005020 return 0;
Dmitry Shmidt29333592017-01-09 12:27:11 -08005021 ret = os_snprintf(pos, end - pos, "fils_realms=");
5022 if (os_snprintf_error(end - pos, ret))
5023 return 0;
5024 pos += ret;
5025
5026 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
5027 if (ret <= 0)
5028 return 0;
5029 pos += ret;
5030 ie += realms * 2;
5031 ret = os_snprintf(pos, end - pos, "\n");
5032 if (os_snprintf_error(end - pos, ret))
5033 return 0;
5034 pos += ret;
5035 }
5036
5037 return pos - start;
5038}
5039#endif /* CONFIG_FILS */
5040
5041
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005042static int print_rnr(struct wpa_bss *bss, char *pos, char *end)
5043{
5044 char *start = pos;
5045 const u8 *ie, *ie_end;
5046 unsigned int n = 0;
5047 int ret;
5048
5049 ie = wpa_bss_get_ie(bss, WLAN_EID_REDUCED_NEIGHBOR_REPORT);
5050 if (!ie)
5051 return 0;
5052
5053 ie_end = ie + 2 + ie[1];
5054 ie += 2;
5055
5056 while (ie < ie_end) {
5057 const struct ieee80211_neighbor_ap_info *info =
5058 (const struct ieee80211_neighbor_ap_info *) ie;
5059 const u8 *tbtt_start;
5060 size_t left = ie_end - ie;
5061
5062 if (left < sizeof(struct ieee80211_neighbor_ap_info))
5063 return 0;
5064
5065 left -= sizeof(struct ieee80211_neighbor_ap_info);
5066 if (left < info->tbtt_info_len)
5067 return 0;
5068
5069 ret = os_snprintf(pos, end - pos,
5070 "ap_info[%u]: tbtt_info: hdr=0x%x, len=%u, op_c=%u, channel=%u, ",
5071 n, *ie, info->tbtt_info_len,
5072 info->op_class, info->channel);
5073 if (os_snprintf_error(end - pos, ret))
5074 return 0;
5075 pos += ret;
5076
5077 ie += sizeof(struct ieee80211_neighbor_ap_info);
5078 tbtt_start = ie;
5079 if (info->tbtt_info_len >= 1) {
5080 ret = os_snprintf(pos, end - pos,
5081 "tbtt_offset=%u, ", *ie);
5082 if (os_snprintf_error(end - pos, ret))
5083 return 0;
5084
5085 ie++;
5086 pos += ret;
5087 }
5088
5089 if (info->tbtt_info_len >= 7) {
5090 ret = os_snprintf(pos, end - pos,
5091 "bssid=" MACSTR ", ",
5092 MAC2STR(ie));
5093 if (os_snprintf_error(end - pos, ret))
5094 return 0;
5095
5096 ie += ETH_ALEN;
5097 pos += ret;
5098 }
5099
5100 if (info->tbtt_info_len >= 11) {
5101 ret = os_snprintf(pos, end - pos,
5102 "short SSID=0x%x, ",
5103 WPA_GET_LE32(ie));
5104 if (os_snprintf_error(end - pos, ret))
5105 return 0;
5106
5107 ie += 4;
5108 pos += ret;
5109 }
5110
5111 if (info->tbtt_info_len >= 12) {
5112 ret = os_snprintf(pos, end - pos,
5113 "bss_params=0x%x, ", *ie);
5114 if (os_snprintf_error(end - pos, ret))
5115 return 0;
5116
5117 ie++;
5118 pos += ret;
5119 }
5120
5121 if (info->tbtt_info_len >= 13) {
5122 ret = os_snprintf(pos, end - pos,
5123 "PSD=0x%x, ", *ie);
5124 if (os_snprintf_error(end - pos, ret))
5125 return 0;
5126
5127 ie++;
5128 pos += ret;
5129 }
5130
5131 if (info->tbtt_info_len >= 16) {
5132 ret = os_snprintf(pos, end - pos,
5133 "mld ID=%u, link ID=%u",
5134 *ie, *(ie + 1) & 0xF);
5135 if (os_snprintf_error(end - pos, ret))
5136 return 0;
5137
5138 ie += 3;
5139 pos += ret;
5140 }
5141
5142 ie = tbtt_start + info->tbtt_info_len;
5143
5144 ret = os_snprintf(pos, end - pos, "\n");
5145 if (os_snprintf_error(end - pos, ret))
5146 return 0;
5147 pos += ret;
5148
5149 n++;
5150 }
5151
5152 return pos - start;
5153}
5154
5155
5156static int print_ml(struct wpa_bss *bss, char *pos, char *end)
5157{
5158 const struct ieee80211_eht_ml *ml;
5159 char *start = pos;
5160 const u8 *ie, *ie_end;
5161 u16 ml_control;
5162 u8 common_info_length;
5163 int ret;
5164
5165 ie = get_ml_ie(wpa_bss_ie_ptr(bss), bss->ie_len,
5166 MULTI_LINK_CONTROL_TYPE_BASIC);
5167 if (!ie)
5168 return 0;
5169
5170 ie_end = ie + 2 + ie[1];
5171 ie += 3;
5172 ml = (const struct ieee80211_eht_ml *) ie;
5173
5174 /* control + common info length + MLD MAC Address */
5175 if (ie_end - ie < 2 + 1 + ETH_ALEN)
5176 return 0;
5177
5178 ml_control = le_to_host16(ml->ml_control);
5179
5180 common_info_length = *(ie + 2);
5181 ret = os_snprintf(pos, end - pos,
5182 "multi-link: control=0x%x, common info len=%u",
5183 ml_control, common_info_length);
5184 if (os_snprintf_error(end - pos, ret))
5185 return 0;
5186 pos += ret;
5187
5188 ie += 2;
5189 if (ie_end - ie < common_info_length)
5190 return 0;
5191
5192 ie++;
5193 common_info_length--;
5194
5195 if (common_info_length < ETH_ALEN)
5196 return 0;
5197
5198 ret = os_snprintf(pos, end - pos, ", MLD addr=" MACSTR, MAC2STR(ie));
5199 if (os_snprintf_error(end - pos, ret))
5200 return 0;
5201 pos += ret;
5202
5203 ie += ETH_ALEN;
5204 common_info_length -= ETH_ALEN;
5205
5206 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_LINK_ID) {
5207 if (common_info_length < 1)
5208 return 0;
5209
5210 ret = os_snprintf(pos, end - pos, ", link ID=%u", *ie & 0x0f);
5211 if (os_snprintf_error(end - pos, ret))
5212 return 0;
5213 pos += ret;
5214 ie++;
5215 common_info_length--;
5216 }
5217
5218 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT) {
5219 if (common_info_length < 1)
5220 return 0;
5221
5222 ret = os_snprintf(pos, end - pos,
5223 ", BSS change parameters=0x%x", *ie);
5224 if (os_snprintf_error(end - pos, ret))
5225 return 0;
5226 pos += ret;
5227 ie++;
5228 common_info_length--;
5229 }
5230
5231 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
5232 if (common_info_length < 2)
5233 return 0;
5234
5235 ret = os_snprintf(pos, end - pos, ", MSD Info=0x%x",
5236 WPA_GET_LE16(ie));
5237 if (os_snprintf_error(end - pos, ret))
5238 return 0;
5239 pos += ret;
5240 ie += 2;
5241 common_info_length -= 2;
5242 }
5243
5244 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
5245 if (common_info_length < 2)
5246 return 0;
5247
5248 ret = os_snprintf(pos, end - pos, ", EML capabilities=0x%x",
5249 WPA_GET_LE16(ie));
5250 if (os_snprintf_error(end - pos, ret))
5251 return 0;
5252 pos += ret;
5253 ie += 2;
5254 common_info_length -= 2;
5255 }
5256
5257 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
5258 if (common_info_length < 2)
5259 return 0;
5260
5261 ret = os_snprintf(pos, end - pos, ", MLD capabilities=0x%x",
5262 WPA_GET_LE16(ie));
5263 if (os_snprintf_error(end - pos, ret))
5264 return 0;
5265 pos += ret;
5266 ie += 2;
5267 common_info_length -= 2;
5268 }
5269
5270 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
5271 if (common_info_length < 1)
5272 return 0;
5273
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005274 ret = os_snprintf(pos, end - pos, ", MLD ID=0x%x", *ie);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005275 if (os_snprintf_error(end - pos, ret))
5276 return 0;
5277 pos += ret;
5278 ie += 1;
5279 common_info_length--;
5280 }
5281
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005282 ret = os_snprintf(pos, end - pos, "\n");
5283 if (os_snprintf_error(end - pos, ret))
5284 return 0;
5285 pos += ret;
5286
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005287 return pos - start;
5288}
5289
5290
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005291static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
5292 unsigned long mask, char *buf, size_t buflen)
5293{
5294 size_t i;
5295 int ret;
5296 char *pos, *end;
Hai Shalom899fcc72020-10-19 14:38:18 -07005297 const u8 *ie, *ie2, *osen_ie, *mesh, *owe, *rsnxe;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005298
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005299 pos = buf;
5300 end = buf + buflen;
5301
5302 if (mask & WPA_BSS_MASK_ID) {
5303 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005304 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005305 return 0;
5306 pos += ret;
5307 }
5308
5309 if (mask & WPA_BSS_MASK_BSSID) {
5310 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
5311 MAC2STR(bss->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005312 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005313 return 0;
5314 pos += ret;
5315 }
5316
5317 if (mask & WPA_BSS_MASK_FREQ) {
5318 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005319 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005320 return 0;
5321 pos += ret;
5322 }
5323
5324 if (mask & WPA_BSS_MASK_BEACON_INT) {
5325 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
5326 bss->beacon_int);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005327 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005328 return 0;
5329 pos += ret;
5330 }
5331
5332 if (mask & WPA_BSS_MASK_CAPABILITIES) {
5333 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
5334 bss->caps);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005335 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005336 return 0;
5337 pos += ret;
5338 }
5339
5340 if (mask & WPA_BSS_MASK_QUAL) {
5341 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005342 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005343 return 0;
5344 pos += ret;
5345 }
5346
5347 if (mask & WPA_BSS_MASK_NOISE) {
5348 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005349 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005350 return 0;
5351 pos += ret;
5352 }
5353
5354 if (mask & WPA_BSS_MASK_LEVEL) {
5355 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005356 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005357 return 0;
5358 pos += ret;
5359 }
5360
5361 if (mask & WPA_BSS_MASK_TSF) {
5362 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
5363 (unsigned long long) bss->tsf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005364 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005365 return 0;
5366 pos += ret;
5367 }
5368
5369 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005370 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005371
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005372 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005373 ret = os_snprintf(pos, end - pos, "age=%d\n",
5374 (int) (now.sec - bss->last_update.sec));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005375 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005376 return 0;
5377 pos += ret;
5378 }
5379
5380 if (mask & WPA_BSS_MASK_IE) {
5381 ret = os_snprintf(pos, end - pos, "ie=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005382 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005383 return 0;
5384 pos += ret;
5385
Hai Shalom60840252021-02-19 19:02:11 -08005386 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005387 for (i = 0; i < bss->ie_len; i++) {
5388 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005389 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005390 return 0;
5391 pos += ret;
5392 }
5393
5394 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005395 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005396 return 0;
5397 pos += ret;
5398 }
5399
5400 if (mask & WPA_BSS_MASK_FLAGS) {
5401 ret = os_snprintf(pos, end - pos, "flags=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005402 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005403 return 0;
5404 pos += ret;
5405
Dmitry Shmidt29333592017-01-09 12:27:11 -08005406 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
5407
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005408 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
5409 if (ie)
5410 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
5411 2 + ie[1]);
5412 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
5413 if (ie2)
Dmitry Shmidt29333592017-01-09 12:27:11 -08005414 pos = wpa_supplicant_ie_txt(pos, end,
5415 mesh ? "RSN" : "WPA2", ie2,
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005416 2 + ie2[1]);
Hai Shalom899fcc72020-10-19 14:38:18 -07005417 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shaloma20dcd72022-02-04 13:43:00 -08005418 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
5419 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
5420 if (os_snprintf_error(end - pos, ret))
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005421 return 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08005422 pos += ret;
5423 }
5424 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
5425 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
5426 if (os_snprintf_error(end - pos, ret))
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005427 return 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08005428 pos += ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07005429 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005430 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
5431 if (osen_ie)
5432 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
5433 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005434 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
5435 if (owe) {
5436 ret = os_snprintf(
5437 pos, end - pos,
5438 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
5439 if (os_snprintf_error(end - pos, ret))
5440 return 0;
5441 pos += ret;
5442 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005443 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005444 if (!ie && !ie2 && !osen_ie &&
5445 (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005446 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005447 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005448 return 0;
5449 pos += ret;
5450 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005451
5452 if (mesh) {
5453 ret = os_snprintf(pos, end - pos, "[MESH]");
5454 if (os_snprintf_error(end - pos, ret))
5455 return 0;
5456 pos += ret;
5457 }
5458
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005459 if (bss_is_dmg(bss)) {
5460 const char *s;
5461 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005462 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005463 return 0;
5464 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005465 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
5466 case IEEE80211_CAP_DMG_IBSS:
5467 s = "[IBSS]";
5468 break;
5469 case IEEE80211_CAP_DMG_AP:
5470 s = "[ESS]";
5471 break;
5472 case IEEE80211_CAP_DMG_PBSS:
5473 s = "[PBSS]";
5474 break;
5475 default:
5476 s = "";
5477 break;
5478 }
5479 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005480 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005481 return 0;
5482 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005483 } else {
5484 if (bss->caps & IEEE80211_CAP_IBSS) {
5485 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005486 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005487 return 0;
5488 pos += ret;
5489 }
5490 if (bss->caps & IEEE80211_CAP_ESS) {
5491 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005492 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005493 return 0;
5494 pos += ret;
5495 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005496 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07005497 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
5498 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005499 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005500 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005501 return 0;
5502 pos += ret;
5503 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005504#ifdef CONFIG_HS20
5505 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
5506 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005507 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005508 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005509 pos += ret;
5510 }
5511#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005512#ifdef CONFIG_FILS
5513 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
5514 ret = os_snprintf(pos, end - pos, "[FILS]");
5515 if (os_snprintf_error(end - pos, ret))
5516 return 0;
5517 pos += ret;
5518 }
5519#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08005520#ifdef CONFIG_FST
5521 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
5522 ret = os_snprintf(pos, end - pos, "[FST]");
5523 if (os_snprintf_error(end - pos, ret))
5524 return 0;
5525 pos += ret;
5526 }
5527#endif /* CONFIG_FST */
5528 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
5529 ret = os_snprintf(pos, end - pos, "[UTF-8]");
5530 if (os_snprintf_error(end - pos, ret))
5531 return 0;
5532 pos += ret;
5533 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005534
5535 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005536 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005537 return 0;
5538 pos += ret;
5539 }
5540
5541 if (mask & WPA_BSS_MASK_SSID) {
5542 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
5543 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005544 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005545 return 0;
5546 pos += ret;
5547 }
5548
5549#ifdef CONFIG_WPS
5550 if (mask & WPA_BSS_MASK_WPS_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005551 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005552 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005553 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005554 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005555 if (ret > 0)
5556 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005557 }
5558#endif /* CONFIG_WPS */
5559
5560#ifdef CONFIG_P2P
5561 if (mask & WPA_BSS_MASK_P2P_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005562 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005563 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005564 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005565 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005566 if (ret > 0)
5567 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005568 }
5569#endif /* CONFIG_P2P */
5570
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005571#ifdef CONFIG_WIFI_DISPLAY
5572 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
5573 struct wpabuf *wfd;
Hai Shalom60840252021-02-19 19:02:11 -08005574
5575 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005576 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
5577 WFD_IE_VENDOR_TYPE);
5578 if (wfd) {
5579 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005580 if (os_snprintf_error(end - pos, ret)) {
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005581 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005582 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005583 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005584 pos += ret;
5585
5586 pos += wpa_snprintf_hex(pos, end - pos,
5587 wpabuf_head(wfd),
5588 wpabuf_len(wfd));
5589 wpabuf_free(wfd);
5590
5591 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005592 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005593 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005594 pos += ret;
5595 }
5596 }
5597#endif /* CONFIG_WIFI_DISPLAY */
5598
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005599#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005600 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
5601 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005602 struct wpa_bss_anqp_elem *elem;
5603
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005604 pos = anqp_add_hex(pos, end, "anqp_capability_list",
5605 anqp->capability_list);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005606 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005607 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005608 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005609 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005610 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005611 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005612 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005613 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005614 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005615 anqp->nai_realm);
5616 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005617 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005618 anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005619 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
5620 anqp->fils_realm_info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005621#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005622 pos = anqp_add_hex(pos, end, "hs20_capability_list",
5623 anqp->hs20_capability_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005624 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005625 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005626 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005627 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005628 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005629 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005630 pos = anqp_add_hex(pos, end, "hs20_operating_class",
5631 anqp->hs20_operating_class);
5632 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
5633 anqp->hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005634 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
5635 anqp->hs20_operator_icon_metadata);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005636 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
5637 anqp->hs20_osu_providers_nai_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005638#endif /* CONFIG_HS20 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005639
5640 dl_list_for_each(elem, &anqp->anqp_elems,
5641 struct wpa_bss_anqp_elem, list) {
5642 char title[20];
5643
5644 os_snprintf(title, sizeof(title), "anqp[%u]",
5645 elem->infoid);
5646 pos = anqp_add_hex(pos, end, title, elem->payload);
Hai Shalom60840252021-02-19 19:02:11 -08005647 if (elem->protected_response) {
5648 ret = os_snprintf(pos, end - pos,
5649 "protected-anqp-info[%u]=1\n",
5650 elem->infoid);
5651 if (os_snprintf_error(end - pos, ret))
5652 return 0;
5653 pos += ret;
5654 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005655 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005656 }
5657#endif /* CONFIG_INTERWORKING */
5658
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005659#ifdef CONFIG_MESH
5660 if (mask & WPA_BSS_MASK_MESH_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005661 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005662 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005663 if (ret >= end - pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005664 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005665 if (ret > 0)
5666 pos += ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005667 }
5668#endif /* CONFIG_MESH */
5669
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005670 if (mask & WPA_BSS_MASK_SNR) {
5671 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
5672 if (os_snprintf_error(end - pos, ret))
5673 return 0;
5674 pos += ret;
5675 }
5676
5677 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
5678 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
5679 bss->est_throughput);
5680 if (os_snprintf_error(end - pos, ret))
5681 return 0;
5682 pos += ret;
5683 }
5684
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005685#ifdef CONFIG_FST
5686 if (mask & WPA_BSS_MASK_FST) {
5687 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
5688 if (ret < 0 || ret >= end - pos)
5689 return 0;
5690 pos += ret;
5691 }
5692#endif /* CONFIG_FST */
5693
Dmitry Shmidt29333592017-01-09 12:27:11 -08005694 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
5695 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
5696 bss->last_update_idx);
5697 if (os_snprintf_error(end - pos, ret))
5698 return 0;
5699 pos += ret;
5700 }
5701
5702 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
5703 ret = os_snprintf(pos, end - pos, "beacon_ie=");
5704 if (os_snprintf_error(end - pos, ret))
5705 return 0;
5706 pos += ret;
5707
Hai Shalom60840252021-02-19 19:02:11 -08005708 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005709 ie += bss->ie_len;
5710 for (i = 0; i < bss->beacon_ie_len; i++) {
5711 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
5712 if (os_snprintf_error(end - pos, ret))
5713 return 0;
5714 pos += ret;
5715 }
5716
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#ifdef CONFIG_FILS
5724 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
5725 ret = print_fils_indication(bss, pos, end);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005726 pos += ret;
5727 }
5728#endif /* CONFIG_FILS */
5729
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005730 if (!is_zero_ether_addr(bss->mld_addr) &&
5731 (mask & WPA_BSS_MASK_AP_MLD_ADDR)) {
Sunil Ravi89eba102022-09-13 21:04:37 -07005732 ret = os_snprintf(pos, end - pos,
5733 "ap_mld_addr=" MACSTR "\n",
5734 MAC2STR(bss->mld_addr));
5735 if (os_snprintf_error(end - pos, ret))
5736 return 0;
5737 pos += ret;
5738 }
5739
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005740 if (mask & WPA_BSS_MASK_RNR)
5741 pos += print_rnr(bss, pos, end);
5742
5743 if (mask & WPA_BSS_MASK_ML)
5744 pos += print_ml(bss, pos, end);
5745
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005746 if (mask & WPA_BSS_MASK_DELIM) {
5747 ret = os_snprintf(pos, end - pos, "====\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005748 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005749 return 0;
5750 pos += ret;
5751 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07005752
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005753 return pos - buf;
5754}
5755
Dmitry Shmidt04949592012-07-19 12:16:46 -07005756
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005757static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
5758 const char *cmd, char *buf,
5759 size_t buflen)
5760{
5761 u8 bssid[ETH_ALEN];
5762 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005763 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005764 struct wpa_bss *bsslast = NULL;
5765 struct dl_list *next;
5766 int ret = 0;
5767 int len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005768 char *ctmp, *end = buf + buflen;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005769 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005770
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005771 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
5772 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
5773 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005774 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005775 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
5776 list_id);
5777 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005778 unsigned int id1, id2;
5779
5780 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
5781 wpa_printf(MSG_INFO, "Wrong BSS range "
5782 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005783 return 0;
5784 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005785
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005786 if (*(cmd + 6) == '-')
5787 id1 = 0;
5788 else
5789 id1 = atoi(cmd + 6);
5790 ctmp++;
5791 if (*ctmp >= '0' && *ctmp <= '9')
5792 id2 = atoi(ctmp);
5793 else
5794 id2 = (unsigned int) -1;
5795 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
5796 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005797 bsslast = dl_list_last(&wpa_s->bss_id,
5798 struct wpa_bss,
5799 list_id);
5800 else {
5801 bsslast = wpa_bss_get_id(wpa_s, id2);
5802 if (bsslast == NULL && bss && id2 > id1) {
5803 struct wpa_bss *tmp = bss;
5804 for (;;) {
5805 next = tmp->list_id.next;
5806 if (next == &wpa_s->bss_id)
5807 break;
5808 tmp = dl_list_entry(
5809 next, struct wpa_bss,
5810 list_id);
5811 if (tmp->id > id2)
5812 break;
5813 bsslast = tmp;
5814 }
5815 }
5816 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005817 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005818 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005819 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005820 else if (os_strncmp(cmd, "LAST", 4) == 0)
5821 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005822 else if (os_strncmp(cmd, "ID-", 3) == 0) {
5823 i = atoi(cmd + 3);
5824 bss = wpa_bss_get_id(wpa_s, i);
5825 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5826 i = atoi(cmd + 5);
5827 bss = wpa_bss_get_id(wpa_s, i);
5828 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005829 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005830 if (next == &wpa_s->bss_id)
5831 bss = NULL;
5832 else
5833 bss = dl_list_entry(next, struct wpa_bss,
5834 list_id);
5835 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005836 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5837 bss = wpa_s->current_bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005838#ifdef CONFIG_P2P
5839 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5840 if (hwaddr_aton(cmd + 13, bssid) == 0)
5841 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5842 else
5843 bss = NULL;
5844#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005845 } else if (hwaddr_aton(cmd, bssid) == 0)
5846 bss = wpa_bss_get_bssid(wpa_s, bssid);
5847 else {
5848 struct wpa_bss *tmp;
5849 i = atoi(cmd);
5850 bss = NULL;
5851 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5852 {
Hai Shalom021b0b52019-04-10 11:17:58 -07005853 if (i == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005854 bss = tmp;
5855 break;
5856 }
Hai Shalom021b0b52019-04-10 11:17:58 -07005857 i--;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005858 }
5859 }
5860
Dmitry Shmidt04949592012-07-19 12:16:46 -07005861 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5862 mask = strtoul(ctmp + 5, NULL, 0x10);
5863 if (mask == 0)
5864 mask = WPA_BSS_MASK_ALL;
5865 }
5866
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005867 if (bss == NULL)
5868 return 0;
5869
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005870 if (bsslast == NULL)
5871 bsslast = bss;
5872 do {
5873 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5874 ret += len;
5875 buf += len;
5876 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005877 if (bss == bsslast) {
5878 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5879 (bss == dl_list_last(&wpa_s->bss_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005880 struct wpa_bss, list_id))) {
5881 int res;
5882
5883 res = os_snprintf(buf - 5, end - buf + 5,
5884 "####\n");
5885 if (os_snprintf_error(end - buf + 5, res)) {
5886 wpa_printf(MSG_DEBUG,
5887 "Could not add end delim");
5888 }
5889 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005890 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005891 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005892 next = bss->list_id.next;
5893 if (next == &wpa_s->bss_id)
5894 break;
5895 bss = dl_list_entry(next, struct wpa_bss, list_id);
5896 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005897
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005898 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005899}
5900
5901
5902static int wpa_supplicant_ctrl_iface_ap_scan(
5903 struct wpa_supplicant *wpa_s, char *cmd)
5904{
5905 int ap_scan = atoi(cmd);
5906 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5907}
5908
5909
5910static int wpa_supplicant_ctrl_iface_scan_interval(
5911 struct wpa_supplicant *wpa_s, char *cmd)
5912{
5913 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005914 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005915}
5916
5917
5918static int wpa_supplicant_ctrl_iface_bss_expire_age(
5919 struct wpa_supplicant *wpa_s, char *cmd)
5920{
5921 int expire_age = atoi(cmd);
5922 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5923}
5924
5925
5926static int wpa_supplicant_ctrl_iface_bss_expire_count(
5927 struct wpa_supplicant *wpa_s, char *cmd)
5928{
5929 int expire_count = atoi(cmd);
5930 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5931}
5932
5933
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005934static void wpa_supplicant_ctrl_iface_bss_flush(
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005935 struct wpa_supplicant *wpa_s, char *cmd)
5936{
5937 int flush_age = atoi(cmd);
5938
5939 if (flush_age == 0)
5940 wpa_bss_flush(wpa_s);
5941 else
5942 wpa_bss_flush_by_age(wpa_s, flush_age);
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005943}
5944
5945
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005946#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005947static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5948{
5949 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5950 /* MLME-DELETEKEYS.request */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005951 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005952 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005953 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005954 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005955 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005956 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005957 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005958 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005959 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005960 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005961 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005962 0, KEY_FLAG_GROUP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005963
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005964 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0,
5965 NULL, 0, KEY_FLAG_PAIRWISE);
Hai Shalomfdcde762020-04-02 11:19:20 -07005966 if (wpa_sm_ext_key_id(wpa_s->wpa))
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005967 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, wpa_s->bssid, 1, 0,
Hai Shalomfdcde762020-04-02 11:19:20 -07005968 NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005969 /* MLME-SETPROTECTION.request(None) */
5970 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5971 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5972 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5973 wpa_sm_drop_sa(wpa_s->wpa);
5974}
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005975#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005976
5977
5978static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5979 char *addr)
5980{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005981#ifdef CONFIG_NO_SCAN_PROCESSING
5982 return -1;
5983#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005984 u8 bssid[ETH_ALEN];
5985 struct wpa_bss *bss;
5986 struct wpa_ssid *ssid = wpa_s->current_ssid;
Hai Shaloma20dcd72022-02-04 13:43:00 -08005987 struct wpa_radio_work *already_connecting;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005988
5989 if (hwaddr_aton(addr, bssid)) {
5990 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5991 "address '%s'", addr);
5992 return -1;
5993 }
5994
5995 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5996
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005997 if (!ssid) {
5998 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5999 "configuration known for the target AP");
6000 return -1;
6001 }
6002
6003 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006004 if (!bss) {
6005 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
6006 "from BSS table");
6007 return -1;
6008 }
6009
6010 /*
6011 * TODO: Find best network configuration block from configuration to
6012 * allow roaming to other networks
6013 */
6014
Hai Shaloma20dcd72022-02-04 13:43:00 -08006015 already_connecting = radio_work_pending(wpa_s, "sme-connect");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006016 wpa_s->reassociate = 1;
6017 wpa_supplicant_connect(wpa_s, bss, ssid);
6018
Hai Shaloma20dcd72022-02-04 13:43:00 -08006019 /*
6020 * Indicate that an explicitly requested roam is in progress so scan
6021 * results that come in before the 'sme-connect' radio work gets
6022 * executed do not override the original connection attempt.
6023 */
6024 if (!already_connecting && radio_work_pending(wpa_s, "sme-connect"))
6025 wpa_s->roam_in_progress = true;
6026
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006027 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006028#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006029}
6030
6031
6032#ifdef CONFIG_P2P
6033static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
6034{
6035 unsigned int timeout = atoi(cmd);
6036 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006037 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08006038 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006039 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006040 unsigned int search_delay;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006041 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006042 u8 seek_count = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006043 int freq = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006044 bool include_6ghz = false;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006045
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006046 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6047 wpa_dbg(wpa_s, MSG_INFO,
6048 "Reject P2P_FIND since interface is disabled");
6049 return -1;
6050 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08006051
6052 if (os_strstr(cmd, " include_6ghz"))
6053 include_6ghz = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006054 if (os_strstr(cmd, "type=social"))
6055 type = P2P_FIND_ONLY_SOCIAL;
6056 else if (os_strstr(cmd, "type=progressive"))
6057 type = P2P_FIND_PROGRESSIVE;
6058
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006059 pos = os_strstr(cmd, "dev_id=");
6060 if (pos) {
6061 pos += 7;
6062 if (hwaddr_aton(pos, dev_id))
6063 return -1;
6064 _dev_id = dev_id;
6065 }
6066
Dmitry Shmidt344abd32014-01-14 13:17:00 -08006067 pos = os_strstr(cmd, "dev_type=");
6068 if (pos) {
6069 pos += 9;
6070 if (wps_dev_type_str2bin(pos, dev_type) < 0)
6071 return -1;
6072 _dev_type = dev_type;
6073 }
6074
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006075 pos = os_strstr(cmd, "delay=");
6076 if (pos) {
6077 pos += 6;
6078 search_delay = atoi(pos);
6079 } else
6080 search_delay = wpas_p2p_search_delay(wpa_s);
6081
Dmitry Shmidt41712582015-06-29 11:02:15 -07006082 pos = os_strstr(cmd, "freq=");
6083 if (pos) {
6084 pos += 5;
6085 freq = atoi(pos);
6086 if (freq <= 0)
6087 return -1;
6088 }
6089
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006090 /* Must be searched for last, because it adds nul termination */
6091 pos = os_strstr(cmd, " seek=");
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006092 if (pos)
6093 pos += 6;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006094 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
6095 char *term;
6096
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006097 _seek[seek_count++] = pos;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006098 seek = _seek;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006099 term = os_strchr(pos, ' ');
6100 if (!term)
6101 break;
6102 *term = '\0';
6103 pos = os_strstr(term + 1, "seek=");
6104 if (pos)
6105 pos += 5;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006106 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006107 if (seek_count > P2P_MAX_QUERY_HASH) {
6108 seek[0] = NULL;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006109 seek_count = 1;
6110 }
6111
Dmitry Shmidt344abd32014-01-14 13:17:00 -08006112 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006113 _dev_id, search_delay, seek_count, seek, freq,
6114 include_6ghz);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006115}
6116
6117
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006118static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
6119{
6120 const char *last = NULL;
6121 const char *token;
6122 long int token_len;
6123 unsigned int i;
6124
6125 /* Expected predefined CPT names delimited by ':' */
6126 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
6127 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
6128 wpa_printf(MSG_ERROR,
6129 "P2PS: CPT name list is too long, expected up to %d names",
6130 P2PS_FEATURE_CAPAB_CPT_MAX);
6131 cpt[0] = 0;
6132 return -1;
6133 }
6134
6135 token_len = last - token;
6136
6137 if (token_len == 3 &&
6138 os_memcmp(token, "UDP", token_len) == 0) {
6139 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6140 } else if (token_len == 3 &&
6141 os_memcmp(token, "MAC", token_len) == 0) {
6142 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
6143 } else {
6144 wpa_printf(MSG_ERROR,
6145 "P2PS: Unsupported CPT name '%s'", token);
6146 cpt[0] = 0;
6147 return -1;
6148 }
6149
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006150 if (isblank((unsigned char) *last)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006151 i++;
6152 break;
6153 }
6154 }
6155 cpt[i] = 0;
6156 return 0;
6157}
6158
6159
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006160static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
6161{
6162 struct p2ps_provision *p2ps_prov;
6163 char *pos;
6164 size_t info_len = 0;
6165 char *info = NULL;
6166 u8 role = P2PS_SETUP_NONE;
6167 long long unsigned val;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006168 int i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006169
6170 pos = os_strstr(cmd, "info=");
6171 if (pos) {
6172 pos += 5;
6173 info_len = os_strlen(pos);
6174
6175 if (info_len) {
6176 info = os_malloc(info_len + 1);
6177 if (info) {
6178 info_len = utf8_unescape(pos, info_len,
6179 info, info_len + 1);
6180 } else
6181 info_len = 0;
6182 }
6183 }
6184
6185 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
6186 if (p2ps_prov == NULL) {
6187 os_free(info);
6188 return NULL;
6189 }
6190
6191 if (info) {
6192 os_memcpy(p2ps_prov->info, info, info_len);
6193 p2ps_prov->info[info_len] = '\0';
6194 os_free(info);
6195 }
6196
6197 pos = os_strstr(cmd, "status=");
6198 if (pos)
6199 p2ps_prov->status = atoi(pos + 7);
6200 else
6201 p2ps_prov->status = -1;
6202
6203 pos = os_strstr(cmd, "adv_id=");
6204 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
6205 goto invalid_args;
6206 p2ps_prov->adv_id = val;
6207
6208 pos = os_strstr(cmd, "method=");
6209 if (pos)
6210 p2ps_prov->method = strtol(pos + 7, NULL, 16);
6211 else
6212 p2ps_prov->method = 0;
6213
6214 pos = os_strstr(cmd, "session=");
6215 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
6216 goto invalid_args;
6217 p2ps_prov->session_id = val;
6218
6219 pos = os_strstr(cmd, "adv_mac=");
6220 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
6221 goto invalid_args;
6222
6223 pos = os_strstr(cmd, "session_mac=");
6224 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
6225 goto invalid_args;
6226
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006227 pos = os_strstr(cmd, "cpt=");
6228 if (pos) {
6229 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
6230 p2ps_prov->cpt_priority))
6231 goto invalid_args;
6232 } else {
6233 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6234 }
6235
6236 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
6237 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
6238
Hai Shaloma20dcd72022-02-04 13:43:00 -08006239 /* force conncap with tstCap (no validity checks) */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006240 pos = os_strstr(cmd, "tstCap=");
6241 if (pos) {
6242 role = strtol(pos + 7, NULL, 16);
6243 } else {
6244 pos = os_strstr(cmd, "role=");
6245 if (pos) {
6246 role = strtol(pos + 5, NULL, 16);
6247 if (role != P2PS_SETUP_CLIENT &&
6248 role != P2PS_SETUP_GROUP_OWNER)
6249 role = P2PS_SETUP_NONE;
6250 }
6251 }
6252 p2ps_prov->role = role;
6253
6254 return p2ps_prov;
6255
6256invalid_args:
6257 os_free(p2ps_prov);
6258 return NULL;
6259}
6260
6261
6262static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
6263{
6264 u8 addr[ETH_ALEN];
6265 struct p2ps_provision *p2ps_prov;
6266 char *pos;
6267
6268 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
6269
6270 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
6271
6272 if (hwaddr_aton(cmd, addr))
6273 return -1;
6274
6275 pos = cmd + 17;
6276 if (*pos != ' ')
6277 return -1;
6278
6279 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
6280 if (!p2ps_prov)
6281 return -1;
6282
6283 if (p2ps_prov->status < 0) {
6284 os_free(p2ps_prov);
6285 return -1;
6286 }
6287
6288 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
6289 p2ps_prov);
6290}
6291
6292
6293static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
6294{
6295 u8 addr[ETH_ALEN];
6296 struct p2ps_provision *p2ps_prov;
6297 char *pos;
6298
6299 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
6300 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
6301 */
6302
6303 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
6304 if (hwaddr_aton(cmd, addr))
6305 return -1;
6306
6307 pos = cmd + 17;
6308 if (*pos != ' ')
6309 return -1;
6310
6311 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
6312 if (!p2ps_prov)
6313 return -1;
6314
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006315 p2ps_prov->pd_seeker = 1;
6316
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006317 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
6318 p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006319}
6320
6321
6322static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
6323 char *buf, size_t buflen)
6324{
6325 u8 addr[ETH_ALEN];
6326 char *pos, *pos2;
6327 char *pin = NULL;
6328 enum p2p_wps_method wps_method;
6329 int new_pin;
6330 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006331 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006332 int join;
6333 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006334 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006335 int go_intent = -1;
6336 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006337 int pd;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006338 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006339 int edmg;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006340 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
6341 size_t group_ssid_len = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08006342 int he;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006343 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006344
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006345 if (!wpa_s->global->p2p_init_wpa_s)
6346 return -1;
6347 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
6348 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
6349 wpa_s->global->p2p_init_wpa_s->ifname);
6350 wpa_s = wpa_s->global->p2p_init_wpa_s;
6351 }
6352
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006353 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
Dmitry Shmidt04949592012-07-19 12:16:46 -07006354 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006355 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006356 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006357
6358 if (hwaddr_aton(cmd, addr))
6359 return -1;
6360
6361 pos = cmd + 17;
6362 if (*pos != ' ')
6363 return -1;
6364 pos++;
6365
6366 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006367 pos2 = os_strstr(pos, " persistent=");
6368 if (pos2) {
6369 struct wpa_ssid *ssid;
6370 persistent_id = atoi(pos2 + 12);
6371 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
6372 if (ssid == NULL || ssid->disabled != 2 ||
6373 ssid->mode != WPAS_MODE_P2P_GO) {
6374 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
6375 "SSID id=%d for persistent P2P group (GO)",
6376 persistent_id);
6377 return -1;
6378 }
6379 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006380 join = os_strstr(pos, " join") != NULL;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006381 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006382 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006383 automatic = os_strstr(pos, " auto") != NULL;
6384 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006385 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6386 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6387 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006388 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006389 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006390
6391 pos2 = os_strstr(pos, " go_intent=");
6392 if (pos2) {
6393 pos2 += 11;
6394 go_intent = atoi(pos2);
6395 if (go_intent < 0 || go_intent > 15)
6396 return -1;
6397 }
6398
6399 pos2 = os_strstr(pos, " freq=");
6400 if (pos2) {
6401 pos2 += 6;
6402 freq = atoi(pos2);
6403 if (freq <= 0)
6404 return -1;
6405 }
6406
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006407 pos2 = os_strstr(pos, " freq2=");
6408 if (pos2)
6409 freq2 = atoi(pos2 + 7);
6410
6411 pos2 = os_strstr(pos, " max_oper_chwidth=");
6412 if (pos2)
6413 chwidth = atoi(pos2 + 18);
6414
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006415 max_oper_chwidth = chwidth_freq2_to_ch_width(chwidth, freq2);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006416 if (max_oper_chwidth < 0)
6417 return -1;
6418
Hai Shaloma20dcd72022-02-04 13:43:00 -08006419 if (allow_6ghz && chwidth == 40)
Sunil8cd6f4d2022-06-28 18:40:46 +00006420 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006421
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006422 pos2 = os_strstr(pos, " ssid=");
6423 if (pos2) {
6424 char *end;
6425
6426 pos2 += 6;
6427 end = os_strchr(pos2, ' ');
6428 if (!end)
6429 group_ssid_len = os_strlen(pos2) / 2;
6430 else
6431 group_ssid_len = (end - pos2) / 2;
6432 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
6433 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
6434 return -1;
6435 group_ssid = _group_ssid;
6436 }
6437
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006438 if (os_strncmp(pos, "pin", 3) == 0) {
6439 /* Request random PIN (to be displayed) and enable the PIN */
6440 wps_method = WPS_PIN_DISPLAY;
6441 } else if (os_strncmp(pos, "pbc", 3) == 0) {
6442 wps_method = WPS_PBC;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006443 } else if (os_strstr(pos, "p2ps") != NULL) {
6444 wps_method = WPS_P2PS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006445 } else {
6446 pin = pos;
6447 pos = os_strchr(pin, ' ');
6448 wps_method = WPS_PIN_KEYPAD;
6449 if (pos) {
6450 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006451 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006452 wps_method = WPS_PIN_DISPLAY;
6453 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006454 if (!wps_pin_str_valid(pin)) {
6455 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
6456 return 17;
6457 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006458 }
6459
6460 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006461 persistent_group, automatic, join,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006462 auth, go_intent, freq, freq2, persistent_id,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006463 pd, ht40, vht, max_oper_chwidth, he, edmg,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006464 group_ssid, group_ssid_len, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006465 if (new_pin == -2) {
6466 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
6467 return 25;
6468 }
6469 if (new_pin == -3) {
6470 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
6471 return 25;
6472 }
6473 if (new_pin < 0)
6474 return -1;
6475 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
6476 ret = os_snprintf(buf, buflen, "%08d", new_pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006477 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006478 return -1;
6479 return ret;
6480 }
6481
6482 os_memcpy(buf, "OK\n", 3);
6483 return 3;
6484}
6485
6486
6487static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
6488{
6489 unsigned int timeout = atoi(cmd);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006490 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6491 wpa_dbg(wpa_s, MSG_INFO,
6492 "Reject P2P_LISTEN since interface is disabled");
6493 return -1;
6494 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006495 return wpas_p2p_listen(wpa_s, timeout);
6496}
6497
6498
6499static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
6500{
6501 u8 addr[ETH_ALEN];
6502 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006503 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006504
Dmitry Shmidt04949592012-07-19 12:16:46 -07006505 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006506
6507 if (hwaddr_aton(cmd, addr))
6508 return -1;
6509
6510 pos = cmd + 17;
6511 if (*pos != ' ')
6512 return -1;
6513 pos++;
6514
Dmitry Shmidt04949592012-07-19 12:16:46 -07006515 if (os_strstr(pos, " join") != NULL)
6516 use = WPAS_P2P_PD_FOR_JOIN;
6517 else if (os_strstr(pos, " auto") != NULL)
6518 use = WPAS_P2P_PD_AUTO;
6519
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006520 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006521}
6522
6523
6524static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
6525 size_t buflen)
6526{
6527 struct wpa_ssid *ssid = wpa_s->current_ssid;
6528
6529 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
6530 ssid->passphrase == NULL)
6531 return -1;
6532
6533 os_strlcpy(buf, ssid->passphrase, buflen);
6534 return os_strlen(buf);
6535}
6536
6537
6538static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
6539 char *buf, size_t buflen)
6540{
6541 u64 ref;
6542 int res;
6543 u8 dst_buf[ETH_ALEN], *dst;
6544 struct wpabuf *tlvs;
6545 char *pos;
6546 size_t len;
6547
6548 if (hwaddr_aton(cmd, dst_buf))
6549 return -1;
6550 dst = dst_buf;
6551 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
6552 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
6553 dst = NULL;
6554 pos = cmd + 17;
6555 if (*pos != ' ')
6556 return -1;
6557 pos++;
6558
6559 if (os_strncmp(pos, "upnp ", 5) == 0) {
6560 u8 version;
6561 pos += 5;
6562 if (hexstr2bin(pos, &version, 1) < 0)
6563 return -1;
6564 pos += 2;
6565 if (*pos != ' ')
6566 return -1;
6567 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006568 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006569#ifdef CONFIG_WIFI_DISPLAY
6570 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
6571 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
6572#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006573 } else if (os_strncmp(pos, "asp ", 4) == 0) {
6574 char *svc_str;
6575 char *svc_info = NULL;
6576 u32 id;
6577
6578 pos += 4;
6579 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
6580 return -1;
6581
6582 pos = os_strchr(pos, ' ');
6583 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
6584 return -1;
6585
6586 svc_str = pos + 1;
6587
6588 pos = os_strchr(svc_str, ' ');
6589
6590 if (pos)
6591 *pos++ = '\0';
6592
6593 /* All remaining data is the svc_info string */
6594 if (pos && pos[0] && pos[0] != ' ') {
6595 len = os_strlen(pos);
6596
6597 /* Unescape in place */
6598 len = utf8_unescape(pos, len, pos, len);
6599 if (len > 0xff)
6600 return -1;
6601
6602 svc_info = pos;
6603 }
6604
6605 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
6606 svc_str, svc_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006607 } else {
6608 len = os_strlen(pos);
6609 if (len & 1)
6610 return -1;
6611 len /= 2;
6612 tlvs = wpabuf_alloc(len);
6613 if (tlvs == NULL)
6614 return -1;
6615 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
6616 wpabuf_free(tlvs);
6617 return -1;
6618 }
6619
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006620 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006621 wpabuf_free(tlvs);
6622 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006623 if (ref == 0)
6624 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006625 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006626 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006627 return -1;
6628 return res;
6629}
6630
6631
6632static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
6633 char *cmd)
6634{
6635 long long unsigned val;
6636 u64 req;
6637 if (sscanf(cmd, "%llx", &val) != 1)
6638 return -1;
6639 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006640 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006641}
6642
6643
6644static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
6645{
6646 int freq;
6647 u8 dst[ETH_ALEN];
6648 u8 dialog_token;
6649 struct wpabuf *resp_tlvs;
6650 char *pos, *pos2;
6651 size_t len;
6652
6653 pos = os_strchr(cmd, ' ');
6654 if (pos == NULL)
6655 return -1;
6656 *pos++ = '\0';
6657 freq = atoi(cmd);
6658 if (freq == 0)
6659 return -1;
6660
6661 if (hwaddr_aton(pos, dst))
6662 return -1;
6663 pos += 17;
6664 if (*pos != ' ')
6665 return -1;
6666 pos++;
6667
6668 pos2 = os_strchr(pos, ' ');
6669 if (pos2 == NULL)
6670 return -1;
6671 *pos2++ = '\0';
6672 dialog_token = atoi(pos);
6673
6674 len = os_strlen(pos2);
6675 if (len & 1)
6676 return -1;
6677 len /= 2;
6678 resp_tlvs = wpabuf_alloc(len);
6679 if (resp_tlvs == NULL)
6680 return -1;
6681 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
6682 wpabuf_free(resp_tlvs);
6683 return -1;
6684 }
6685
6686 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
6687 wpabuf_free(resp_tlvs);
6688 return 0;
6689}
6690
6691
6692static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
6693 char *cmd)
6694{
Dmitry Shmidt04949592012-07-19 12:16:46 -07006695 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
6696 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006697 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
6698 return 0;
6699}
6700
6701
6702static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
6703 char *cmd)
6704{
6705 char *pos;
6706 size_t len;
6707 struct wpabuf *query, *resp;
6708
6709 pos = os_strchr(cmd, ' ');
6710 if (pos == NULL)
6711 return -1;
6712 *pos++ = '\0';
6713
6714 len = os_strlen(cmd);
6715 if (len & 1)
6716 return -1;
6717 len /= 2;
6718 query = wpabuf_alloc(len);
6719 if (query == NULL)
6720 return -1;
6721 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6722 wpabuf_free(query);
6723 return -1;
6724 }
6725
6726 len = os_strlen(pos);
6727 if (len & 1) {
6728 wpabuf_free(query);
6729 return -1;
6730 }
6731 len /= 2;
6732 resp = wpabuf_alloc(len);
6733 if (resp == NULL) {
6734 wpabuf_free(query);
6735 return -1;
6736 }
6737 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
6738 wpabuf_free(query);
6739 wpabuf_free(resp);
6740 return -1;
6741 }
6742
6743 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
6744 wpabuf_free(query);
6745 wpabuf_free(resp);
6746 return -1;
6747 }
6748 return 0;
6749}
6750
6751
6752static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6753{
6754 char *pos;
6755 u8 version;
6756
6757 pos = os_strchr(cmd, ' ');
6758 if (pos == NULL)
6759 return -1;
6760 *pos++ = '\0';
6761
6762 if (hexstr2bin(cmd, &version, 1) < 0)
6763 return -1;
6764
6765 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
6766}
6767
6768
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006769static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
6770 u8 replace, char *cmd)
6771{
6772 char *pos;
6773 char *adv_str;
6774 u32 auto_accept, adv_id, svc_state, config_methods;
6775 char *svc_info = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006776 char *cpt_prio_str;
6777 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006778
6779 pos = os_strchr(cmd, ' ');
6780 if (pos == NULL)
6781 return -1;
6782 *pos++ = '\0';
6783
6784 /* Auto-Accept value is mandatory, and must be one of the
6785 * single values (0, 1, 2, 4) */
6786 auto_accept = atoi(cmd);
6787 switch (auto_accept) {
6788 case P2PS_SETUP_NONE: /* No auto-accept */
6789 case P2PS_SETUP_NEW:
6790 case P2PS_SETUP_CLIENT:
6791 case P2PS_SETUP_GROUP_OWNER:
6792 break;
6793 default:
6794 return -1;
6795 }
6796
6797 /* Advertisement ID is mandatory */
6798 cmd = pos;
6799 pos = os_strchr(cmd, ' ');
6800 if (pos == NULL)
6801 return -1;
6802 *pos++ = '\0';
6803
6804 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6805 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
6806 return -1;
6807
6808 /* Only allow replacements if exist, and adds if not */
6809 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
6810 if (!replace)
6811 return -1;
6812 } else {
6813 if (replace)
6814 return -1;
6815 }
6816
6817 /* svc_state between 0 - 0xff is mandatory */
6818 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
6819 return -1;
6820
6821 pos = os_strchr(pos, ' ');
6822 if (pos == NULL)
6823 return -1;
6824
6825 /* config_methods is mandatory */
6826 pos++;
6827 if (sscanf(pos, "%x", &config_methods) != 1)
6828 return -1;
6829
6830 if (!(config_methods &
6831 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
6832 return -1;
6833
6834 pos = os_strchr(pos, ' ');
6835 if (pos == NULL)
6836 return -1;
6837
6838 pos++;
6839 adv_str = pos;
6840
6841 /* Advertisement string is mandatory */
6842 if (!pos[0] || pos[0] == ' ')
6843 return -1;
6844
6845 /* Terminate svc string */
6846 pos = os_strchr(pos, ' ');
6847 if (pos != NULL)
6848 *pos++ = '\0';
6849
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006850 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6851 if (cpt_prio_str) {
6852 pos = os_strchr(pos, ' ');
6853 if (pos != NULL)
6854 *pos++ = '\0';
6855
6856 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6857 return -1;
6858 } else {
6859 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6860 cpt_prio[1] = 0;
6861 }
6862
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006863 /* Service and Response Information are optional */
6864 if (pos && pos[0]) {
6865 size_t len;
6866
6867 /* Note the bare ' included, which cannot exist legally
6868 * in unescaped string. */
6869 svc_info = os_strstr(pos, "svc_info='");
6870
6871 if (svc_info) {
6872 svc_info += 9;
6873 len = os_strlen(svc_info);
6874 utf8_unescape(svc_info, len, svc_info, len);
6875 }
6876 }
6877
6878 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6879 (u8) svc_state, (u16) config_methods,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006880 svc_info, cpt_prio);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006881}
6882
6883
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006884static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6885{
6886 char *pos;
6887
6888 pos = os_strchr(cmd, ' ');
6889 if (pos == NULL)
6890 return -1;
6891 *pos++ = '\0';
6892
6893 if (os_strcmp(cmd, "bonjour") == 0)
6894 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6895 if (os_strcmp(cmd, "upnp") == 0)
6896 return p2p_ctrl_service_add_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006897 if (os_strcmp(cmd, "asp") == 0)
6898 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006899 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6900 return -1;
6901}
6902
6903
6904static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6905 char *cmd)
6906{
6907 size_t len;
6908 struct wpabuf *query;
6909 int ret;
6910
6911 len = os_strlen(cmd);
6912 if (len & 1)
6913 return -1;
6914 len /= 2;
6915 query = wpabuf_alloc(len);
6916 if (query == NULL)
6917 return -1;
6918 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6919 wpabuf_free(query);
6920 return -1;
6921 }
6922
6923 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6924 wpabuf_free(query);
6925 return ret;
6926}
6927
6928
6929static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6930{
6931 char *pos;
6932 u8 version;
6933
6934 pos = os_strchr(cmd, ' ');
6935 if (pos == NULL)
6936 return -1;
6937 *pos++ = '\0';
6938
6939 if (hexstr2bin(cmd, &version, 1) < 0)
6940 return -1;
6941
6942 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6943}
6944
6945
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006946static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6947{
6948 u32 adv_id;
6949
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07006950 if (os_strcmp(cmd, "all") == 0) {
6951 wpas_p2p_service_flush_asp(wpa_s);
6952 return 0;
6953 }
6954
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006955 if (sscanf(cmd, "%x", &adv_id) != 1)
6956 return -1;
6957
6958 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6959}
6960
6961
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006962static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6963{
6964 char *pos;
6965
6966 pos = os_strchr(cmd, ' ');
6967 if (pos == NULL)
6968 return -1;
6969 *pos++ = '\0';
6970
6971 if (os_strcmp(cmd, "bonjour") == 0)
6972 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6973 if (os_strcmp(cmd, "upnp") == 0)
6974 return p2p_ctrl_service_del_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006975 if (os_strcmp(cmd, "asp") == 0)
6976 return p2p_ctrl_service_del_asp(wpa_s, pos);
6977 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6978 return -1;
6979}
6980
6981
6982static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6983{
6984 char *pos;
6985
6986 pos = os_strchr(cmd, ' ');
6987 if (pos == NULL)
6988 return -1;
6989 *pos++ = '\0';
6990
6991 if (os_strcmp(cmd, "asp") == 0)
6992 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6993
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006994 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6995 return -1;
6996}
6997
6998
6999static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
7000{
7001 u8 addr[ETH_ALEN];
7002
7003 /* <addr> */
7004
7005 if (hwaddr_aton(cmd, addr))
7006 return -1;
7007
7008 return wpas_p2p_reject(wpa_s, addr);
7009}
7010
7011
7012static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
7013{
7014 char *pos;
7015 int id;
7016 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007017 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08007018 int freq = 0, pref_freq = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08007019 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007020 int edmg;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007021 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007022
7023 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007024 pos = os_strstr(cmd, " peer=");
7025 if (pos) {
7026 pos += 6;
7027 if (hwaddr_aton(pos, peer))
7028 return -1;
7029 _peer = peer;
7030 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007031 ssid = wpa_config_get_network(wpa_s->conf, id);
7032 if (ssid == NULL || ssid->disabled != 2) {
7033 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
7034 "for persistent P2P group",
7035 id);
7036 return -1;
7037 }
7038
Jouni Malinen31be0a42012-08-31 21:20:51 +03007039 pos = os_strstr(cmd, " freq=");
7040 if (pos) {
7041 pos += 6;
7042 freq = atoi(pos);
7043 if (freq <= 0)
7044 return -1;
7045 }
7046
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08007047 pos = os_strstr(cmd, " pref=");
7048 if (pos) {
7049 pos += 6;
7050 pref_freq = atoi(pos);
7051 if (pref_freq <= 0)
7052 return -1;
7053 }
7054
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007055 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
7056 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
7057 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08007058 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007059 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Jouni Malinen31be0a42012-08-31 21:20:51 +03007060
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007061 pos = os_strstr(cmd, "freq2=");
7062 if (pos)
7063 freq2 = atoi(pos + 6);
7064
7065 pos = os_strstr(cmd, " max_oper_chwidth=");
7066 if (pos)
7067 chwidth = atoi(pos + 18);
7068
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007069 max_oper_chwidth = chwidth_freq2_to_ch_width(chwidth, freq2);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007070 if (max_oper_chwidth < 0)
7071 return -1;
7072
Hai Shaloma20dcd72022-02-04 13:43:00 -08007073 allow_6ghz = os_strstr(cmd, " allow_6ghz") != NULL;
7074
7075 if (allow_6ghz && chwidth == 40)
Sunil8cd6f4d2022-06-28 18:40:46 +00007076 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007077
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007078 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
Hai Shaloma20dcd72022-02-04 13:43:00 -08007079 max_oper_chwidth, pref_freq, he, edmg,
7080 allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007081}
7082
7083
7084static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
7085{
7086 char *pos;
7087 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007088 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007089
7090 pos = os_strstr(cmd, " peer=");
7091 if (!pos)
7092 return -1;
7093
7094 *pos = '\0';
7095 pos += 6;
7096 if (hwaddr_aton(pos, peer)) {
7097 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
7098 return -1;
7099 }
7100
Hai Shaloma20dcd72022-02-04 13:43:00 -08007101 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
7102
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007103 pos = os_strstr(pos, " go_dev_addr=");
7104 if (pos) {
7105 pos += 13;
7106 if (hwaddr_aton(pos, go_dev_addr)) {
7107 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
7108 pos);
7109 return -1;
7110 }
7111 go_dev = go_dev_addr;
7112 }
7113
Hai Shaloma20dcd72022-02-04 13:43:00 -08007114 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007115}
7116
7117
7118static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
7119{
7120 if (os_strncmp(cmd, "persistent=", 11) == 0)
7121 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
7122 if (os_strncmp(cmd, "group=", 6) == 0)
7123 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
7124
7125 return -1;
7126}
7127
7128
7129static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007130 int id, int freq, int vht_center_freq2,
Hai Shalom74f70d42019-02-11 14:42:39 -08007131 int ht40, int vht, int vht_chwidth,
Sunil Raviaf8751c2023-03-29 11:35:17 -07007132 int he, int edmg, bool allow_6ghz,
7133 const u8 *go_bssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007134{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007135 struct wpa_ssid *ssid;
7136
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007137 ssid = wpa_config_get_network(wpa_s->conf, id);
7138 if (ssid == NULL || ssid->disabled != 2) {
7139 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
7140 "for persistent P2P group",
7141 id);
7142 return -1;
7143 }
7144
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007145 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0,
7146 vht_center_freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007147 vht_chwidth, he, edmg,
Sunil Raviaf8751c2023-03-29 11:35:17 -07007148 NULL, 0, 0, allow_6ghz, 0,
7149 go_bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007150}
7151
7152
7153static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
7154{
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007155 int freq = 0, persistent = 0, group_id = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007156 bool allow_6ghz = false;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007157 int vht = wpa_s->conf->p2p_go_vht;
7158 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08007159 int he = wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007160 int edmg = wpa_s->conf->p2p_go_edmg;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007161 int max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007162 char *token, *context = NULL;
Sunil Raviaf8751c2023-03-29 11:35:17 -07007163 u8 go_bssid_buf[ETH_ALEN], *go_bssid = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007164#ifdef CONFIG_ACS
7165 int acs = 0;
7166#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007167
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007168 while ((token = str_token(cmd, " ", &context))) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07007169 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007170 sscanf(token, "persistent=%d", &group_id) == 1 ||
7171 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007172 continue;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007173#ifdef CONFIG_ACS
7174 } else if (os_strcmp(token, "freq=acs") == 0) {
7175 acs = 1;
7176#endif /* CONFIG_ACS */
7177 } else if (sscanf(token, "freq=%d", &freq) == 1) {
7178 continue;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007179 } else if (os_strcmp(token, "ht40") == 0) {
7180 ht40 = 1;
7181 } else if (os_strcmp(token, "vht") == 0) {
7182 vht = 1;
7183 ht40 = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08007184 } else if (os_strcmp(token, "he") == 0) {
7185 he = 1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007186 } else if (os_strcmp(token, "edmg") == 0) {
7187 edmg = 1;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007188 } else if (os_strcmp(token, "persistent") == 0) {
7189 persistent = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007190 } else if (os_strcmp(token, "allow_6ghz") == 0) {
7191 allow_6ghz = true;
Sunil Raviaf8751c2023-03-29 11:35:17 -07007192 } else if (os_strncmp(token, "go_bssid=", 9) == 0) {
7193 if (hwaddr_aton(token + 9, go_bssid_buf))
7194 return -1;
7195 go_bssid = go_bssid_buf;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007196 } else {
7197 wpa_printf(MSG_DEBUG,
7198 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
7199 token);
7200 return -1;
7201 }
7202 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007203
Roshan Pius3a1667e2018-07-03 15:17:14 -07007204#ifdef CONFIG_ACS
7205 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
7206 (acs || freq == 2 || freq == 5)) {
7207 if (freq == 2 && wpa_s->best_24_freq <= 0) {
7208 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
7209 wpa_s->p2p_go_do_acs = 1;
7210 freq = 0;
7211 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
7212 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
7213 wpa_s->p2p_go_do_acs = 1;
7214 freq = 0;
7215 } else {
7216 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
7217 wpa_s->p2p_go_do_acs = 1;
7218 }
Hai Shalom021b0b52019-04-10 11:17:58 -07007219 } else {
7220 wpa_s->p2p_go_do_acs = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007221 }
7222#endif /* CONFIG_ACS */
7223
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007224 max_oper_chwidth = chwidth_freq2_to_ch_width(chwidth, freq2);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007225 if (max_oper_chwidth < 0)
7226 return -1;
7227
Hai Shaloma20dcd72022-02-04 13:43:00 -08007228 if (allow_6ghz && chwidth == 40)
Sunil8cd6f4d2022-06-28 18:40:46 +00007229 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007230
7231 /* Allow DFS to be used for Autonomous GO */
7232 wpa_s->p2p_go_allow_dfs = !!(wpa_s->drv_flags &
7233 WPA_DRIVER_FLAGS_DFS_OFFLOAD);
7234
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007235 if (group_id >= 0)
7236 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007237 freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007238 max_oper_chwidth, he,
Sunil Raviaf8751c2023-03-29 11:35:17 -07007239 edmg, allow_6ghz,
7240 go_bssid);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007241
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007242 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
Hai Shaloma20dcd72022-02-04 13:43:00 -08007243 max_oper_chwidth, he, edmg, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007244}
7245
7246
Dmitry Shmidt849734c2016-05-27 09:59:01 -07007247static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
7248 char *buf, size_t buflen)
7249{
7250 u8 dev_addr[ETH_ALEN];
7251 struct wpa_ssid *ssid;
7252 int res;
7253 const u8 *iaddr;
7254
7255 ssid = wpa_s->current_ssid;
7256 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
7257 hwaddr_aton(cmd, dev_addr))
7258 return -1;
7259
7260 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
7261 if (!iaddr)
7262 return -1;
7263 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
7264 if (os_snprintf_error(buflen, res))
7265 return -1;
7266 return res;
7267}
7268
7269
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007270static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
7271 const u8 *p2p_dev_addr)
7272{
7273 struct wpa_supplicant *wpa_s;
7274
7275 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7276 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
7277 return 1;
7278 }
7279
7280 return 0;
7281}
7282
7283
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007284static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
7285 char *buf, size_t buflen)
7286{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007287 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007288 int next, res;
7289 const struct p2p_peer_info *info;
7290 char *pos, *end;
7291 char devtype[WPS_DEV_TYPE_BUFSIZE];
7292 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007293 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007294
7295 if (!wpa_s->global->p2p)
7296 return -1;
7297
7298 if (os_strcmp(cmd, "FIRST") == 0) {
7299 addr_ptr = NULL;
7300 next = 0;
7301 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
7302 if (hwaddr_aton(cmd + 5, addr) < 0)
7303 return -1;
7304 addr_ptr = addr;
7305 next = 1;
7306 } else {
7307 if (hwaddr_aton(cmd, addr) < 0)
7308 return -1;
7309 addr_ptr = addr;
7310 next = 0;
7311 }
7312
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007313 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
7314 if (info == NULL)
7315 return -1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007316 group_capab = info->group_capab;
7317
7318 if (group_capab &&
7319 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
7320 wpa_printf(MSG_DEBUG,
7321 "P2P: Could not find any BSS with p2p_dev_addr "
7322 MACSTR ", hence override group_capab from 0x%x to 0",
7323 MAC2STR(info->p2p_device_addr), group_capab);
7324 group_capab = 0;
7325 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007326
7327 pos = buf;
7328 end = buf + buflen;
7329
7330 res = os_snprintf(pos, end - pos, MACSTR "\n"
7331 "pri_dev_type=%s\n"
7332 "device_name=%s\n"
7333 "manufacturer=%s\n"
7334 "model_name=%s\n"
7335 "model_number=%s\n"
7336 "serial_number=%s\n"
7337 "config_methods=0x%x\n"
7338 "dev_capab=0x%x\n"
7339 "group_capab=0x%x\n"
7340 "level=%d\n",
7341 MAC2STR(info->p2p_device_addr),
7342 wps_dev_type_bin2str(info->pri_dev_type,
7343 devtype, sizeof(devtype)),
7344 info->device_name,
7345 info->manufacturer,
7346 info->model_name,
7347 info->model_number,
7348 info->serial_number,
7349 info->config_methods,
7350 info->dev_capab,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007351 group_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007352 info->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007353 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007354 return pos - buf;
7355 pos += res;
7356
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007357 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
7358 {
7359 const u8 *t;
7360 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
7361 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
7362 wps_dev_type_bin2str(t, devtype,
7363 sizeof(devtype)));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007364 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007365 return pos - buf;
7366 pos += res;
7367 }
7368
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007369 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007370 if (ssid) {
7371 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007372 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007373 return pos - buf;
7374 pos += res;
7375 }
7376
7377 res = p2p_get_peer_info_txt(info, pos, end - pos);
7378 if (res < 0)
7379 return pos - buf;
7380 pos += res;
7381
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007382 if (info->vendor_elems) {
7383 res = os_snprintf(pos, end - pos, "vendor_elems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007384 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007385 return pos - buf;
7386 pos += res;
7387
7388 pos += wpa_snprintf_hex(pos, end - pos,
7389 wpabuf_head(info->vendor_elems),
7390 wpabuf_len(info->vendor_elems));
7391
7392 res = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007393 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007394 return pos - buf;
7395 pos += res;
7396 }
7397
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007398 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007399}
7400
7401
Dmitry Shmidt04949592012-07-19 12:16:46 -07007402static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
7403 const char *param)
7404{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007405 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007406
7407 if (wpa_s->global->p2p == NULL)
7408 return -1;
7409
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007410 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
7411 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007412
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007413 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
7414 struct wpa_freq_range *freq;
7415 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07007416 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007417 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007418 }
7419
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007420 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007421 return 0;
7422}
7423
7424
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007425static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
7426{
7427 char *param;
7428
7429 if (wpa_s->global->p2p == NULL)
7430 return -1;
7431
7432 param = os_strchr(cmd, ' ');
7433 if (param == NULL)
7434 return -1;
7435 *param++ = '\0';
7436
7437 if (os_strcmp(cmd, "discoverability") == 0) {
7438 p2p_set_client_discoverability(wpa_s->global->p2p,
7439 atoi(param));
7440 return 0;
7441 }
7442
7443 if (os_strcmp(cmd, "managed") == 0) {
7444 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
7445 return 0;
7446 }
7447
7448 if (os_strcmp(cmd, "listen_channel") == 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08007449 char *pos;
7450 u8 channel, op_class;
7451
7452 channel = atoi(param);
7453 pos = os_strchr(param, ' ');
7454 op_class = pos ? atoi(pos) : 81;
7455
7456 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
7457 channel, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007458 }
7459
7460 if (os_strcmp(cmd, "ssid_postfix") == 0) {
7461 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
7462 os_strlen(param));
7463 }
7464
7465 if (os_strcmp(cmd, "noa") == 0) {
7466 char *pos;
7467 int count, start, duration;
7468 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
7469 count = atoi(param);
7470 pos = os_strchr(param, ',');
7471 if (pos == NULL)
7472 return -1;
7473 pos++;
7474 start = atoi(pos);
7475 pos = os_strchr(pos, ',');
7476 if (pos == NULL)
7477 return -1;
7478 pos++;
7479 duration = atoi(pos);
7480 if (count < 0 || count > 255 || start < 0 || duration < 0)
7481 return -1;
7482 if (count == 0 && duration > 0)
7483 return -1;
7484 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
7485 "start=%d duration=%d", count, start, duration);
7486 return wpas_p2p_set_noa(wpa_s, count, start, duration);
7487 }
7488
7489 if (os_strcmp(cmd, "ps") == 0)
7490 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
7491
7492 if (os_strcmp(cmd, "oppps") == 0)
7493 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
7494
7495 if (os_strcmp(cmd, "ctwindow") == 0)
7496 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
7497
7498 if (os_strcmp(cmd, "disabled") == 0) {
7499 wpa_s->global->p2p_disabled = atoi(param);
7500 wpa_printf(MSG_DEBUG, "P2P functionality %s",
7501 wpa_s->global->p2p_disabled ?
7502 "disabled" : "enabled");
7503 if (wpa_s->global->p2p_disabled) {
7504 wpas_p2p_stop_find(wpa_s);
7505 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7506 p2p_flush(wpa_s->global->p2p);
7507 }
7508 return 0;
7509 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007510
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007511 if (os_strcmp(cmd, "conc_pref") == 0) {
7512 if (os_strcmp(param, "sta") == 0)
7513 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
7514 else if (os_strcmp(param, "p2p") == 0)
7515 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007516 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007517 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007518 return -1;
7519 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007520 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07007521 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007522 return 0;
7523 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007524
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007525 if (os_strcmp(cmd, "force_long_sd") == 0) {
7526 wpa_s->force_long_sd = atoi(param);
7527 return 0;
7528 }
7529
7530 if (os_strcmp(cmd, "peer_filter") == 0) {
7531 u8 addr[ETH_ALEN];
7532 if (hwaddr_aton(param, addr))
7533 return -1;
7534 p2p_set_peer_filter(wpa_s->global->p2p, addr);
7535 return 0;
7536 }
7537
7538 if (os_strcmp(cmd, "cross_connect") == 0)
7539 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
7540
7541 if (os_strcmp(cmd, "go_apsd") == 0) {
7542 if (os_strcmp(param, "disable") == 0)
7543 wpa_s->set_ap_uapsd = 0;
7544 else {
7545 wpa_s->set_ap_uapsd = 1;
7546 wpa_s->ap_uapsd = atoi(param);
7547 }
7548 return 0;
7549 }
7550
7551 if (os_strcmp(cmd, "client_apsd") == 0) {
7552 if (os_strcmp(param, "disable") == 0)
7553 wpa_s->set_sta_uapsd = 0;
7554 else {
7555 int be, bk, vi, vo;
7556 char *pos;
7557 /* format: BE,BK,VI,VO;max SP Length */
7558 be = atoi(param);
7559 pos = os_strchr(param, ',');
7560 if (pos == NULL)
7561 return -1;
7562 pos++;
7563 bk = atoi(pos);
7564 pos = os_strchr(pos, ',');
7565 if (pos == NULL)
7566 return -1;
7567 pos++;
7568 vi = atoi(pos);
7569 pos = os_strchr(pos, ',');
7570 if (pos == NULL)
7571 return -1;
7572 pos++;
7573 vo = atoi(pos);
7574 /* ignore max SP Length for now */
7575
7576 wpa_s->set_sta_uapsd = 1;
7577 wpa_s->sta_uapsd = 0;
7578 if (be)
7579 wpa_s->sta_uapsd |= BIT(0);
7580 if (bk)
7581 wpa_s->sta_uapsd |= BIT(1);
7582 if (vi)
7583 wpa_s->sta_uapsd |= BIT(2);
7584 if (vo)
7585 wpa_s->sta_uapsd |= BIT(3);
7586 }
7587 return 0;
7588 }
7589
Dmitry Shmidt04949592012-07-19 12:16:46 -07007590 if (os_strcmp(cmd, "disallow_freq") == 0)
7591 return p2p_ctrl_disallow_freq(wpa_s, param);
7592
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007593 if (os_strcmp(cmd, "disc_int") == 0) {
7594 int min_disc_int, max_disc_int, max_disc_tu;
7595 char *pos;
7596
7597 pos = param;
7598
7599 min_disc_int = atoi(pos);
7600 pos = os_strchr(pos, ' ');
7601 if (pos == NULL)
7602 return -1;
7603 *pos++ = '\0';
7604
7605 max_disc_int = atoi(pos);
7606 pos = os_strchr(pos, ' ');
7607 if (pos == NULL)
7608 return -1;
7609 *pos++ = '\0';
7610
7611 max_disc_tu = atoi(pos);
7612
7613 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
7614 max_disc_int, max_disc_tu);
7615 }
7616
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007617 if (os_strcmp(cmd, "per_sta_psk") == 0) {
7618 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
7619 return 0;
7620 }
7621
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007622#ifdef CONFIG_WPS_NFC
7623 if (os_strcmp(cmd, "nfc_tag") == 0)
7624 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
7625#endif /* CONFIG_WPS_NFC */
7626
7627 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
7628 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
7629 return 0;
7630 }
7631
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007632 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
7633 int op_class, chan;
7634
7635 op_class = atoi(param);
7636 param = os_strchr(param, ':');
7637 if (!param)
7638 return -1;
7639 param++;
7640 chan = atoi(param);
7641 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
7642 chan);
7643 return 0;
7644 }
7645
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007646 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
7647 cmd);
7648
7649 return -1;
7650}
7651
7652
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007653static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
7654{
7655 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7656 wpa_s->force_long_sd = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007657
7658#ifdef CONFIG_TESTING_OPTIONS
7659 os_free(wpa_s->get_pref_freq_list_override);
7660 wpa_s->get_pref_freq_list_override = NULL;
7661#endif /* CONFIG_TESTING_OPTIONS */
7662
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007663 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007664 wpa_s->parent->p2ps_method_config_any = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007665 if (wpa_s->global->p2p)
7666 p2p_flush(wpa_s->global->p2p);
7667}
7668
7669
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007670static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
7671{
7672 char *pos, *pos2;
7673 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
7674
7675 if (cmd[0]) {
7676 pos = os_strchr(cmd, ' ');
7677 if (pos == NULL)
7678 return -1;
7679 *pos++ = '\0';
7680 dur1 = atoi(cmd);
7681
7682 pos2 = os_strchr(pos, ' ');
7683 if (pos2)
7684 *pos2++ = '\0';
7685 int1 = atoi(pos);
7686 } else
7687 pos2 = NULL;
7688
7689 if (pos2) {
7690 pos = os_strchr(pos2, ' ');
7691 if (pos == NULL)
7692 return -1;
7693 *pos++ = '\0';
7694 dur2 = atoi(pos2);
7695 int2 = atoi(pos);
7696 }
7697
7698 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
7699}
7700
7701
7702static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
7703{
7704 char *pos;
7705 unsigned int period = 0, interval = 0;
7706
7707 if (cmd[0]) {
7708 pos = os_strchr(cmd, ' ');
7709 if (pos == NULL)
7710 return -1;
7711 *pos++ = '\0';
7712 period = atoi(cmd);
7713 interval = atoi(pos);
7714 }
7715
7716 return wpas_p2p_ext_listen(wpa_s, period, interval);
7717}
7718
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007719
7720static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
7721{
7722 const char *pos;
7723 u8 peer[ETH_ALEN];
7724 int iface_addr = 0;
7725
7726 pos = cmd;
7727 if (os_strncmp(pos, "iface=", 6) == 0) {
7728 iface_addr = 1;
7729 pos += 6;
7730 }
7731 if (hwaddr_aton(pos, peer))
7732 return -1;
7733
7734 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
7735 return 0;
7736}
7737
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007738
7739static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
7740{
7741 int freq = 0, period = 0, interval = 0, count = 0;
7742
7743 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
7744 {
7745 wpa_printf(MSG_DEBUG,
7746 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
7747 return -1;
7748 }
7749
7750 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
7751}
7752
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007753#endif /* CONFIG_P2P */
7754
7755
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007756static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
7757{
7758 struct wpa_freq_range_list ranges;
7759 int *freqs = NULL;
7760 struct hostapd_hw_modes *mode;
7761 u16 i;
7762
7763 if (wpa_s->hw.modes == NULL)
7764 return NULL;
7765
7766 os_memset(&ranges, 0, sizeof(ranges));
7767 if (freq_range_list_parse(&ranges, val) < 0)
7768 return NULL;
7769
7770 for (i = 0; i < wpa_s->hw.num_modes; i++) {
7771 int j;
7772
7773 mode = &wpa_s->hw.modes[i];
7774 for (j = 0; j < mode->num_channels; j++) {
7775 unsigned int freq;
7776
7777 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
7778 continue;
7779
7780 freq = mode->channels[j].freq;
7781 if (!freq_range_list_includes(&ranges, freq))
7782 continue;
7783
7784 int_array_add_unique(&freqs, freq);
7785 }
7786 }
7787
7788 os_free(ranges.range);
7789 return freqs;
7790}
7791
7792
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007793#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007794
7795static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
7796{
7797 int auto_sel = 0;
7798 int *freqs = NULL;
7799
7800 if (param) {
7801 char *pos;
7802
7803 auto_sel = os_strstr(param, "auto") != NULL;
7804
7805 pos = os_strstr(param, "freq=");
7806 if (pos) {
7807 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
7808 if (freqs == NULL)
7809 return -1;
7810 }
7811
7812 }
7813
7814 return interworking_select(wpa_s, auto_sel, freqs);
7815}
7816
7817
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007818static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
7819 int only_add)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007820{
7821 u8 bssid[ETH_ALEN];
7822 struct wpa_bss *bss;
7823
7824 if (hwaddr_aton(dst, bssid)) {
7825 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
7826 return -1;
7827 }
7828
Hai Shalomfdcde762020-04-02 11:19:20 -07007829 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007830 if (bss == NULL) {
7831 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
7832 MAC2STR(bssid));
7833 return -1;
7834 }
7835
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007836 if (bss->ssid_len == 0) {
7837 int found = 0;
7838
7839 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
7840 " does not have SSID information", MAC2STR(bssid));
7841
7842 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
7843 list) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007844 if (ether_addr_equal(bss->bssid, bssid) &&
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007845 bss->ssid_len > 0) {
7846 found = 1;
7847 break;
7848 }
7849 }
7850
7851 if (!found)
7852 return -1;
7853 wpa_printf(MSG_DEBUG,
7854 "Found another matching BSS entry with SSID");
7855 }
7856
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007857 return interworking_connect(wpa_s, bss, only_add);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007858}
7859
7860
7861static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
7862{
7863 u8 dst_addr[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07007864 int used, freq = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007865 char *pos;
7866#define MAX_ANQP_INFO_ID 100
7867 u16 id[MAX_ANQP_INFO_ID];
7868 size_t num_id = 0;
Dmitry Shmidt15907092014-03-25 10:42:57 -07007869 u32 subtypes = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007870 u32 mbo_subtypes = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007871
7872 used = hwaddr_aton2(dst, dst_addr);
7873 if (used < 0)
7874 return -1;
7875 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007876 if (*pos == ' ')
7877 pos++;
Hai Shalom899fcc72020-10-19 14:38:18 -07007878
7879 if (os_strncmp(pos, "freq=", 5) == 0) {
7880 freq = atoi(pos + 5);
7881 pos = os_strchr(pos, ' ');
7882 if (!pos)
7883 return -1;
7884 pos++;
7885 }
7886
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007887 while (num_id < MAX_ANQP_INFO_ID) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07007888 if (os_strncmp(pos, "hs20:", 5) == 0) {
7889#ifdef CONFIG_HS20
7890 int num = atoi(pos + 5);
7891 if (num <= 0 || num > 31)
7892 return -1;
7893 subtypes |= BIT(num);
7894#else /* CONFIG_HS20 */
7895 return -1;
7896#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007897 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7898#ifdef CONFIG_MBO
7899 int num = atoi(pos + 4);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007900
7901 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007902 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007903 mbo_subtypes |= BIT(num);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007904#else /* CONFIG_MBO */
7905 return -1;
7906#endif /* CONFIG_MBO */
Dmitry Shmidt15907092014-03-25 10:42:57 -07007907 } else {
7908 id[num_id] = atoi(pos);
7909 if (id[num_id])
7910 num_id++;
7911 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007912 pos = os_strchr(pos + 1, ',');
7913 if (pos == NULL)
7914 break;
7915 pos++;
7916 }
7917
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007918 if (num_id == 0 && !subtypes && !mbo_subtypes)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007919 return -1;
7920
Hai Shalom899fcc72020-10-19 14:38:18 -07007921 return anqp_send_req(wpa_s, dst_addr, freq, id, num_id, subtypes,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007922 mbo_subtypes);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007923}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007924
7925
7926static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7927{
7928 u8 dst_addr[ETH_ALEN];
7929 struct wpabuf *advproto, *query = NULL;
7930 int used, ret = -1;
7931 char *pos, *end;
7932 size_t len;
7933
7934 used = hwaddr_aton2(cmd, dst_addr);
7935 if (used < 0)
7936 return -1;
7937
7938 pos = cmd + used;
7939 while (*pos == ' ')
7940 pos++;
7941
7942 /* Advertisement Protocol ID */
7943 end = os_strchr(pos, ' ');
7944 if (end)
7945 len = end - pos;
7946 else
7947 len = os_strlen(pos);
7948 if (len & 0x01)
7949 return -1;
7950 len /= 2;
7951 if (len == 0)
7952 return -1;
7953 advproto = wpabuf_alloc(len);
7954 if (advproto == NULL)
7955 return -1;
7956 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7957 goto fail;
7958
7959 if (end) {
7960 /* Optional Query Request */
7961 pos = end + 1;
7962 while (*pos == ' ')
7963 pos++;
7964
7965 len = os_strlen(pos);
7966 if (len) {
7967 if (len & 0x01)
7968 goto fail;
7969 len /= 2;
7970 if (len == 0)
7971 goto fail;
7972 query = wpabuf_alloc(len);
7973 if (query == NULL)
7974 goto fail;
7975 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7976 goto fail;
7977 }
7978 }
7979
7980 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7981
7982fail:
7983 wpabuf_free(advproto);
7984 wpabuf_free(query);
7985
7986 return ret;
7987}
7988
7989
7990static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7991 size_t buflen)
7992{
7993 u8 addr[ETH_ALEN];
7994 int dialog_token;
7995 int used;
7996 char *pos;
7997 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007998 struct wpabuf *resp;
7999 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008000
8001 used = hwaddr_aton2(cmd, addr);
8002 if (used < 0)
8003 return -1;
8004
8005 pos = cmd + used;
8006 while (*pos == ' ')
8007 pos++;
8008 dialog_token = atoi(pos);
8009
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008010 if (wpa_s->last_gas_resp &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008011 ether_addr_equal(addr, wpa_s->last_gas_addr) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008012 dialog_token == wpa_s->last_gas_dialog_token)
8013 resp = wpa_s->last_gas_resp;
8014 else if (wpa_s->prev_gas_resp &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008015 ether_addr_equal(addr, wpa_s->prev_gas_addr) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008016 dialog_token == wpa_s->prev_gas_dialog_token)
8017 resp = wpa_s->prev_gas_resp;
8018 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008019 return -1;
8020
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008021 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008022 start = 0;
8023 requested_len = resp_len;
8024
8025 pos = os_strchr(pos, ' ');
8026 if (pos) {
8027 start = atoi(pos);
8028 if (start > resp_len)
8029 return os_snprintf(buf, buflen, "FAIL-Invalid range");
8030 pos = os_strchr(pos, ',');
8031 if (pos == NULL)
8032 return -1;
8033 pos++;
8034 requested_len = atoi(pos);
8035 if (start + requested_len > resp_len)
8036 return os_snprintf(buf, buflen, "FAIL-Invalid range");
8037 }
8038
8039 if (requested_len * 2 + 1 > buflen)
8040 return os_snprintf(buf, buflen, "FAIL-Too long response");
8041
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008042 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
8043 requested_len);
8044
8045 if (start + requested_len == resp_len) {
8046 /*
8047 * Free memory by dropping the response after it has been
8048 * fetched.
8049 */
8050 if (resp == wpa_s->prev_gas_resp) {
8051 wpabuf_free(wpa_s->prev_gas_resp);
8052 wpa_s->prev_gas_resp = NULL;
8053 } else {
8054 wpabuf_free(wpa_s->last_gas_resp);
8055 wpa_s->last_gas_resp = NULL;
8056 }
8057 }
8058
8059 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008060}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008061#endif /* CONFIG_INTERWORKING */
8062
8063
Dmitry Shmidt04949592012-07-19 12:16:46 -07008064#ifdef CONFIG_HS20
8065
8066static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
8067{
8068 u8 dst_addr[ETH_ALEN];
8069 int used;
8070 char *pos;
8071 u32 subtypes = 0;
8072
8073 used = hwaddr_aton2(dst, dst_addr);
8074 if (used < 0)
8075 return -1;
8076 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008077 if (*pos == ' ')
8078 pos++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07008079 for (;;) {
8080 int num = atoi(pos);
8081 if (num <= 0 || num > 31)
8082 return -1;
8083 subtypes |= BIT(num);
8084 pos = os_strchr(pos + 1, ',');
8085 if (pos == NULL)
8086 break;
8087 pos++;
8088 }
8089
8090 if (subtypes == 0)
8091 return -1;
8092
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008093 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008094}
8095
8096
8097static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
8098 const u8 *addr, const char *realm)
8099{
8100 u8 *buf;
8101 size_t rlen, len;
8102 int ret;
8103
8104 rlen = os_strlen(realm);
8105 len = 3 + rlen;
8106 buf = os_malloc(len);
8107 if (buf == NULL)
8108 return -1;
8109 buf[0] = 1; /* NAI Home Realm Count */
8110 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
8111 buf[2] = rlen;
8112 os_memcpy(buf + 3, realm, rlen);
8113
8114 ret = hs20_anqp_send_req(wpa_s, addr,
8115 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008116 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008117
8118 os_free(buf);
8119
8120 return ret;
8121}
8122
8123
8124static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
8125 char *dst)
8126{
8127 struct wpa_cred *cred = wpa_s->conf->cred;
8128 u8 dst_addr[ETH_ALEN];
8129 int used;
8130 u8 *buf;
8131 size_t len;
8132 int ret;
8133
8134 used = hwaddr_aton2(dst, dst_addr);
8135 if (used < 0)
8136 return -1;
8137
8138 while (dst[used] == ' ')
8139 used++;
8140 if (os_strncmp(dst + used, "realm=", 6) == 0)
8141 return hs20_nai_home_realm_list(wpa_s, dst_addr,
8142 dst + used + 6);
8143
8144 len = os_strlen(dst + used);
8145
8146 if (len == 0 && cred && cred->realm)
8147 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
8148
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07008149 if (len & 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07008150 return -1;
8151 len /= 2;
8152 buf = os_malloc(len);
8153 if (buf == NULL)
8154 return -1;
8155 if (hexstr2bin(dst + used, buf, len) < 0) {
8156 os_free(buf);
8157 return -1;
8158 }
8159
8160 ret = hs20_anqp_send_req(wpa_s, dst_addr,
8161 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008162 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008163 os_free(buf);
8164
8165 return ret;
8166}
8167
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008168
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008169static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
8170 int buflen)
8171{
8172 u8 dst_addr[ETH_ALEN];
8173 int used;
8174 char *ctx = NULL, *icon, *poffset, *psize;
8175
8176 used = hwaddr_aton2(cmd, dst_addr);
8177 if (used < 0)
8178 return -1;
8179 cmd += used;
8180
8181 icon = str_token(cmd, " ", &ctx);
8182 poffset = str_token(cmd, " ", &ctx);
8183 psize = str_token(cmd, " ", &ctx);
8184 if (!icon || !poffset || !psize)
8185 return -1;
8186
8187 wpa_s->fetch_osu_icon_in_progress = 0;
8188 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
8189 reply, buflen);
8190}
8191
8192
8193static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
8194{
8195 u8 dst_addr[ETH_ALEN];
8196 int used;
8197 char *icon;
8198
8199 if (!cmd[0])
8200 return hs20_del_icon(wpa_s, NULL, NULL);
8201
8202 used = hwaddr_aton2(cmd, dst_addr);
8203 if (used < 0)
8204 return -1;
8205
8206 while (cmd[used] == ' ')
8207 used++;
8208 icon = cmd[used] ? &cmd[used] : NULL;
8209
8210 return hs20_del_icon(wpa_s, dst_addr, icon);
8211}
8212
8213
8214static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008215{
8216 u8 dst_addr[ETH_ALEN];
8217 int used;
8218 char *icon;
8219
8220 used = hwaddr_aton2(cmd, dst_addr);
8221 if (used < 0)
8222 return -1;
8223
8224 while (cmd[used] == ' ')
8225 used++;
8226 icon = &cmd[used];
8227
8228 wpa_s->fetch_osu_icon_in_progress = 0;
8229 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008230 (u8 *) icon, os_strlen(icon), inmem);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008231}
8232
Dmitry Shmidt04949592012-07-19 12:16:46 -07008233#endif /* CONFIG_HS20 */
8234
8235
Dmitry Shmidt04949592012-07-19 12:16:46 -07008236#ifdef CONFIG_AUTOSCAN
8237
8238static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
8239 char *cmd)
8240{
8241 enum wpa_states state = wpa_s->wpa_state;
8242 char *new_params = NULL;
8243
8244 if (os_strlen(cmd) > 0) {
8245 new_params = os_strdup(cmd);
8246 if (new_params == NULL)
8247 return -1;
8248 }
8249
8250 os_free(wpa_s->conf->autoscan);
8251 wpa_s->conf->autoscan = new_params;
8252
8253 if (wpa_s->conf->autoscan == NULL)
8254 autoscan_deinit(wpa_s);
8255 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
8256 autoscan_init(wpa_s, 1);
8257 else if (state == WPA_SCANNING)
8258 wpa_supplicant_reinit_autoscan(wpa_s);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08008259 else
8260 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
8261 wpa_supplicant_state_txt(state));
Dmitry Shmidt04949592012-07-19 12:16:46 -07008262
8263 return 0;
8264}
8265
8266#endif /* CONFIG_AUTOSCAN */
8267
8268
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08008269#ifdef CONFIG_WNM
8270
8271static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
8272{
8273 int enter;
8274 int intval = 0;
8275 char *pos;
8276 int ret;
8277 struct wpabuf *tfs_req = NULL;
8278
8279 if (os_strncmp(cmd, "enter", 5) == 0)
8280 enter = 1;
8281 else if (os_strncmp(cmd, "exit", 4) == 0)
8282 enter = 0;
8283 else
8284 return -1;
8285
8286 pos = os_strstr(cmd, " interval=");
8287 if (pos)
8288 intval = atoi(pos + 10);
8289
8290 pos = os_strstr(cmd, " tfs_req=");
8291 if (pos) {
8292 char *end;
8293 size_t len;
8294 pos += 9;
8295 end = os_strchr(pos, ' ');
8296 if (end)
8297 len = end - pos;
8298 else
8299 len = os_strlen(pos);
8300 if (len & 1)
8301 return -1;
8302 len /= 2;
8303 tfs_req = wpabuf_alloc(len);
8304 if (tfs_req == NULL)
8305 return -1;
8306 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
8307 wpabuf_free(tfs_req);
8308 return -1;
8309 }
8310 }
8311
8312 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
8313 WNM_SLEEP_MODE_EXIT, intval,
8314 tfs_req);
8315 wpabuf_free(tfs_req);
8316
8317 return ret;
8318}
8319
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008320
8321static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
8322{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008323 int query_reason, list = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008324 char *btm_candidates = NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008325
8326 query_reason = atoi(cmd);
8327
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008328 cmd = os_strchr(cmd, ' ');
8329 if (cmd) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008330 if (os_strncmp(cmd, " list", 5) == 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008331 list = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008332 else
8333 btm_candidates = cmd;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008334 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008335
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008336 wpa_printf(MSG_DEBUG,
8337 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
8338 query_reason, list ? " candidate list" : "");
8339
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008340 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
8341 btm_candidates,
8342 list);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008343}
8344
Hai Shalom39ba6fc2019-01-22 12:40:38 -08008345
8346static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
8347 char *cmd)
8348{
8349 struct wpabuf *elems;
8350 int ret;
8351
8352 elems = wpabuf_parse_bin(cmd);
8353 if (!elems)
8354 return -1;
8355
8356 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
8357 wpabuf_free(elems);
8358 return ret;
8359}
8360
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08008361#endif /* CONFIG_WNM */
8362
8363
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008364static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
8365 size_t buflen)
8366{
8367 struct wpa_signal_info si;
8368 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008369 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008370
8371 ret = wpa_drv_signal_poll(wpa_s, &si);
8372 if (ret)
8373 return -1;
8374
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008375 pos = buf;
8376 end = buf + buflen;
8377
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008378 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%lu\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008379 "NOISE=%d\nFREQUENCY=%u\n",
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008380 si.data.signal, si.data.current_tx_rate / 1000,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008381 si.current_noise, si.frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008382 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008383 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008384 pos += ret;
8385
8386 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
8387 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008388 channel_width_to_string(si.chanwidth));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008389 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008390 return -1;
8391 pos += ret;
8392 }
8393
Roshan Pius3a1667e2018-07-03 15:17:14 -07008394 if (si.center_frq1 > 0) {
8395 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
8396 si.center_frq1);
8397 if (os_snprintf_error(end - pos, ret))
8398 return -1;
8399 pos += ret;
8400 }
8401
8402 if (si.center_frq2 > 0) {
8403 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
8404 si.center_frq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008405 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008406 return -1;
8407 pos += ret;
8408 }
8409
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008410 if (si.data.avg_signal) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008411 ret = os_snprintf(pos, end - pos,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008412 "AVG_RSSI=%d\n", si.data.avg_signal);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008413 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008414 return -1;
8415 pos += ret;
8416 }
8417
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008418 if (si.data.avg_beacon_signal) {
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07008419 ret = os_snprintf(pos, end - pos,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008420 "AVG_BEACON_RSSI=%d\n",
8421 si.data.avg_beacon_signal);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07008422 if (os_snprintf_error(end - pos, ret))
8423 return -1;
8424 pos += ret;
8425 }
8426
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008427 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008428}
8429
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008430
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008431static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
8432 const char *cmd)
8433{
8434 const char *pos;
8435 int threshold = 0;
8436 int hysteresis = 0;
8437
8438 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
8439 wpa_printf(MSG_DEBUG,
8440 "Reject SIGNAL_MONITOR command - bgscan is active");
8441 return -1;
8442 }
8443 pos = os_strstr(cmd, "THRESHOLD=");
8444 if (pos)
8445 threshold = atoi(pos + 10);
8446 pos = os_strstr(cmd, "HYSTERESIS=");
8447 if (pos)
8448 hysteresis = atoi(pos + 11);
8449 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
8450}
8451
8452
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008453#ifdef CONFIG_TESTING_OPTIONS
8454int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
8455 enum wpa_driver_if_type if_type,
8456 unsigned int *num,
Sunil8cd6f4d2022-06-28 18:40:46 +00008457 struct weighted_pcl *freq_list)
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008458{
8459 char *pos = wpa_s->get_pref_freq_list_override;
8460 char *end;
8461 unsigned int count = 0;
8462
8463 /* Override string format:
8464 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
8465
8466 while (pos) {
8467 if (atoi(pos) == (int) if_type)
8468 break;
8469 pos = os_strchr(pos, ' ');
8470 if (pos)
8471 pos++;
8472 }
8473 if (!pos)
8474 return -1;
8475 pos = os_strchr(pos, ':');
8476 if (!pos)
8477 return -1;
8478 pos++;
8479 end = os_strchr(pos, ' ');
8480 while (pos && (!end || pos < end) && count < *num) {
Sunil8cd6f4d2022-06-28 18:40:46 +00008481 freq_list[count].freq = atoi(pos);
8482 freq_list[count++].flag = WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008483 pos = os_strchr(pos, ',');
8484 if (pos)
8485 pos++;
8486 }
8487
8488 *num = count;
8489 return 0;
8490}
8491#endif /* CONFIG_TESTING_OPTIONS */
8492
8493
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008494static int wpas_ctrl_iface_get_pref_freq_list(
8495 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
8496{
Sunil8cd6f4d2022-06-28 18:40:46 +00008497 unsigned int num = 100, i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008498 int ret;
8499 enum wpa_driver_if_type iface_type;
8500 char *pos, *end;
Sunil8cd6f4d2022-06-28 18:40:46 +00008501 struct weighted_pcl freq_list[100];
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008502
8503 pos = buf;
8504 end = buf + buflen;
8505
8506 /* buf: "<interface_type>" */
8507 if (os_strcmp(cmd, "STATION") == 0)
8508 iface_type = WPA_IF_STATION;
8509 else if (os_strcmp(cmd, "AP") == 0)
8510 iface_type = WPA_IF_AP_BSS;
8511 else if (os_strcmp(cmd, "P2P_GO") == 0)
8512 iface_type = WPA_IF_P2P_GO;
8513 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
8514 iface_type = WPA_IF_P2P_CLIENT;
8515 else if (os_strcmp(cmd, "IBSS") == 0)
8516 iface_type = WPA_IF_IBSS;
8517 else if (os_strcmp(cmd, "TDLS") == 0)
8518 iface_type = WPA_IF_TDLS;
8519 else
8520 return -1;
8521
8522 wpa_printf(MSG_DEBUG,
8523 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
Hai Shalom5f92bc92019-04-18 11:54:11 -07008524 iface_type, cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008525
8526 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
8527 if (ret)
8528 return -1;
8529
8530 for (i = 0; i < num; i++) {
8531 ret = os_snprintf(pos, end - pos, "%s%u",
Sunil8cd6f4d2022-06-28 18:40:46 +00008532 i > 0 ? "," : "", freq_list[i].freq);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008533 if (os_snprintf_error(end - pos, ret))
8534 return -1;
8535 pos += ret;
8536 }
8537
8538 return pos - buf;
8539}
8540
8541
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008542static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
8543 char *buf, size_t buflen)
8544{
8545 int ret, i;
8546 char *pos, *end;
8547
8548 ret = os_snprintf(buf, buflen, "%016llX:\n",
8549 (long long unsigned) wpa_s->drv_flags);
8550 if (os_snprintf_error(buflen, ret))
8551 return -1;
8552
8553 pos = buf + ret;
8554 end = buf + buflen;
8555
8556 for (i = 0; i < 64; i++) {
8557 if (wpa_s->drv_flags & (1LLU << i)) {
8558 ret = os_snprintf(pos, end - pos, "%s\n",
8559 driver_flag_to_string(1LLU << i));
8560 if (os_snprintf_error(end - pos, ret))
8561 return -1;
8562 pos += ret;
8563 }
8564 }
8565
8566 return pos - buf;
8567}
8568
8569
Hai Shalomb755a2a2020-04-23 21:49:02 -07008570static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s,
8571 char *buf, size_t buflen)
8572{
8573 int ret, i;
8574 char *pos, *end;
8575
8576 ret = os_snprintf(buf, buflen, "%016llX:\n",
8577 (long long unsigned) wpa_s->drv_flags2);
8578 if (os_snprintf_error(buflen, ret))
8579 return -1;
8580
8581 pos = buf + ret;
8582 end = buf + buflen;
8583
8584 for (i = 0; i < 64; i++) {
8585 if (wpa_s->drv_flags2 & (1LLU << i)) {
8586 ret = os_snprintf(pos, end - pos, "%s\n",
8587 driver_flag2_to_string(1LLU << i));
8588 if (os_snprintf_error(end - pos, ret))
8589 return -1;
8590 pos += ret;
8591 }
8592 }
8593
8594 return pos - buf;
8595}
8596
8597
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008598static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
8599 size_t buflen)
8600{
8601 struct hostap_sta_driver_data sta;
8602 int ret;
8603
8604 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
8605 if (ret)
8606 return -1;
8607
8608 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008609 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008610 if (os_snprintf_error(buflen, ret))
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008611 return -1;
8612 return ret;
8613}
8614
8615
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008616#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008617static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8618 char *buf, size_t buflen)
8619{
8620 int ret;
8621
8622 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008623 if (ret == 0) {
8624 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
8625 struct p2p_data *p2p = wpa_s->global->p2p;
8626 if (p2p) {
8627 char country[3];
8628 country[0] = cmd[8];
8629 country[1] = cmd[9];
8630 country[2] = 0x04;
8631 p2p_set_country(p2p, country);
8632 }
8633 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008634 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008635 if (os_snprintf_error(buflen, ret))
8636 ret = -1;
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008637 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008638 return ret;
8639}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008640#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008641
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07008642
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008643static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8644 char *buf, size_t buflen)
8645{
8646 int ret;
Hai Shalom60840252021-02-19 19:02:11 -08008647 char *pos, *temp = NULL;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008648 u8 *data = NULL;
8649 unsigned int vendor_id, subcmd;
Hai Shalom60840252021-02-19 19:02:11 -08008650 enum nested_attr nested_attr_flag = NESTED_ATTR_UNSPECIFIED;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008651 struct wpabuf *reply;
8652 size_t data_len = 0;
8653
Hai Shalom60840252021-02-19 19:02:11 -08008654 /**
8655 * cmd: <vendor id> <subcommand id> [<hex formatted data>]
8656 * [nested=<0|1>]
8657 */
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008658 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008659 if (!isblank((unsigned char) *pos))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008660 return -EINVAL;
8661
8662 subcmd = strtoul(pos, &pos, 10);
8663
8664 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008665 if (!isblank((unsigned char) *pos++))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008666 return -EINVAL;
Hai Shalom60840252021-02-19 19:02:11 -08008667
8668 temp = os_strchr(pos, ' ');
8669 data_len = temp ? (size_t) (temp - pos) : os_strlen(pos);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008670 }
8671
8672 if (data_len) {
8673 data_len /= 2;
8674 data = os_malloc(data_len);
8675 if (!data)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008676 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008677
8678 if (hexstr2bin(pos, data, data_len)) {
8679 wpa_printf(MSG_DEBUG,
8680 "Vendor command: wrong parameter format");
8681 os_free(data);
8682 return -EINVAL;
8683 }
8684 }
8685
Hai Shalom60840252021-02-19 19:02:11 -08008686 pos = os_strstr(cmd, "nested=");
8687 if (pos)
8688 nested_attr_flag = atoi(pos + 7) ? NESTED_ATTR_USED :
8689 NESTED_ATTR_NOT_USED;
8690
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008691 reply = wpabuf_alloc((buflen - 1) / 2);
8692 if (!reply) {
8693 os_free(data);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008694 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008695 }
8696
8697 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
Hai Shalom60840252021-02-19 19:02:11 -08008698 nested_attr_flag, reply);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008699
8700 if (ret == 0)
8701 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
8702 wpabuf_len(reply));
8703
8704 wpabuf_free(reply);
8705 os_free(data);
8706
8707 return ret;
8708}
8709
8710
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008711static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
8712{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008713#ifdef CONFIG_P2P
8714 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
8715 wpa_s->global->p2p_init_wpa_s : wpa_s;
8716#endif /* CONFIG_P2P */
8717
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008718 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
8719
Dmitry Shmidt29333592017-01-09 12:27:11 -08008720 if (wpas_abort_ongoing_scan(wpa_s) == 0)
8721 wpa_s->ignore_post_flush_scan_res = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008722
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008723 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
8724 /*
8725 * Avoid possible auto connect re-connection on getting
8726 * disconnected due to state flush.
8727 */
8728 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
8729 }
8730
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008731#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008732 wpas_p2p_group_remove(p2p_wpa_s, "*");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008733 wpas_p2p_cancel(p2p_wpa_s);
8734 p2p_ctrl_flush(p2p_wpa_s);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008735 wpas_p2p_service_flush(p2p_wpa_s);
8736 p2p_wpa_s->global->p2p_disabled = 0;
8737 p2p_wpa_s->global->p2p_per_sta_psk = 0;
8738 p2p_wpa_s->conf->num_sec_device_types = 0;
8739 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
8740 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
8741 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008742 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08008743 p2p_wpa_s->global->pending_p2ps_group = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008744 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008745#endif /* CONFIG_P2P */
8746
8747#ifdef CONFIG_WPS_TESTING
8748 wps_version_number = 0x20;
Hai Shaloma20dcd72022-02-04 13:43:00 -08008749 wps_testing_stub_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08008750 wps_corrupt_pkhash = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008751 wps_force_auth_types_in_use = 0;
8752 wps_force_encr_types_in_use = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008753#endif /* CONFIG_WPS_TESTING */
8754#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008755 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008756 wpas_wps_cancel(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008757 wps_registrar_flush(wpa_s->wps->registrar);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008758#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07008759 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008760 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008761
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008762#ifdef CONFIG_DPP
8763 wpas_dpp_deinit(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07008764 wpa_s->dpp_init_max_tries = 0;
8765 wpa_s->dpp_init_retry_time = 0;
8766 wpa_s->dpp_resp_wait_time = 0;
8767 wpa_s->dpp_resp_max_tries = 0;
8768 wpa_s->dpp_resp_retry_time = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008769#ifdef CONFIG_DPP2
8770 wpas_dpp_chirp_stop(wpa_s);
8771 wpa_s->dpp_pfs_fallback = 0;
8772#endif /* CONFIG_DPP2 */
Sunil Ravi89eba102022-09-13 21:04:37 -07008773#ifdef CONFIG_DPP3
8774 {
8775 int i;
8776
8777 for (i = 0; i < DPP_PB_INFO_COUNT; i++) {
8778 struct dpp_pb_info *info;
8779
8780 info = &wpa_s->dpp_pb[i];
8781 info->rx_time.sec = 0;
8782 info->rx_time.usec = 0;
8783 }
8784 }
8785#endif /* CONFIG_DPP3 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008786#ifdef CONFIG_TESTING_OPTIONS
8787 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
8788 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
8789 dpp_pkex_ephemeral_key_override_len = 0;
8790 dpp_protocol_key_override_len = 0;
8791 dpp_nonce_override_len = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08008792#ifdef CONFIG_DPP3
8793 dpp_version_override = 3;
8794#elif defined(CONFIG_DPP2)
Hai Shalom4fbc08f2020-05-18 12:37:00 -07008795 dpp_version_override = 2;
8796#else /* CONFIG_DPP2 */
8797 dpp_version_override = 1;
8798#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008799#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008800#endif /* CONFIG_DPP */
8801
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008802#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008803#ifdef CONFIG_TDLS_TESTING
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008804 tdls_testing = 0;
8805#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008806 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
8807 wpa_tdls_enable(wpa_s->wpa, 1);
8808#endif /* CONFIG_TDLS */
8809
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008810 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
8811 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07008812 wpa_s->last_michael_mic_error.sec = 0;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008813
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008814 wpa_s->no_keep_alive = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08008815 wpa_s->own_disconnect_req = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008816 wpa_s->own_reconnect_req = 0;
8817 wpa_s->deny_ptk0_rekey = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008818
8819 os_free(wpa_s->disallow_aps_bssid);
8820 wpa_s->disallow_aps_bssid = NULL;
8821 wpa_s->disallow_aps_bssid_count = 0;
8822 os_free(wpa_s->disallow_aps_ssid);
8823 wpa_s->disallow_aps_ssid = NULL;
8824 wpa_s->disallow_aps_ssid_count = 0;
8825
8826 wpa_s->set_sta_uapsd = 0;
8827 wpa_s->sta_uapsd = 0;
8828
Hai Shalom899fcc72020-10-19 14:38:18 -07008829 wpa_s->consecutive_conn_failures = 0;
8830
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008831 wpa_drv_radio_disable(wpa_s, 0);
Hai Shalom60840252021-02-19 19:02:11 -08008832 wpa_bssid_ignore_clear(wpa_s);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008833 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
8834 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08008835 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08008836 wpa_s->conf->auto_interworking = 0;
8837 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008838
Hai Shalom60840252021-02-19 19:02:11 -08008839 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008840 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
8841 rsn_preauth_deinit(wpa_s->wpa);
8842
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008843 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
8844 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
8845 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
Hai Shalome21d4e82020-04-29 16:34:06 -07008846 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008847
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008848 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008849 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008850
8851 wpa_s->next_ssid = NULL;
8852
8853#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008854#ifdef CONFIG_HS20
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008855 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008856 hs20_del_icon(wpa_s, NULL, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008857#endif /* CONFIG_HS20 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008858#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008859
8860 wpa_s->ext_mgmt_frame_handling = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008861 wpa_s->ext_eapol_frame_io = 0;
8862#ifdef CONFIG_TESTING_OPTIONS
8863 wpa_s->extra_roc_dur = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008864 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008865 wpa_s->p2p_go_csa_on_inv = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008866 wpa_s->ignore_auth_resp = 0;
8867 wpa_s->ignore_assoc_disallow = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008868 wpa_s->disable_sa_query = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008869 wpa_s->testing_resend_assoc = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008870 wpa_s->ignore_sae_h2e_only = 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07008871 wpa_s->ft_rsnxe_used = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008872 wpa_s->reject_btm_req_reason = 0;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008873 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008874 wpa_sm_set_test_eapol_m2_elems(wpa_s->wpa, NULL);
8875 wpa_sm_set_test_eapol_m4_elems(wpa_s->wpa, NULL);
8876 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ENCRYPT_EAPOL_M2, 0);
8877 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ENCRYPT_EAPOL_M4, 0);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008878 os_free(wpa_s->get_pref_freq_list_override);
8879 wpa_s->get_pref_freq_list_override = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008880 wpabuf_free(wpa_s->sae_commit_override);
8881 wpa_s->sae_commit_override = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008882 os_free(wpa_s->extra_sae_rejected_groups);
8883 wpa_s->extra_sae_rejected_groups = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008884 wpabuf_free(wpa_s->rsne_override_eapol);
8885 wpa_s->rsne_override_eapol = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008886 wpabuf_free(wpa_s->rsnxe_override_assoc);
8887 wpa_s->rsnxe_override_assoc = NULL;
8888 wpabuf_free(wpa_s->rsnxe_override_eapol);
8889 wpa_s->rsnxe_override_eapol = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008890 wpas_clear_driver_signal_override(wpa_s);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008891#ifndef CONFIG_NO_ROBUST_AV
Hai Shaloma20dcd72022-02-04 13:43:00 -08008892 wpa_s->disable_scs_support = 0;
8893 wpa_s->disable_mscs_support = 0;
8894 wpa_s->enable_dscp_policy_capa = 0;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008895#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalom899fcc72020-10-19 14:38:18 -07008896 wpa_s->oci_freq_override_eapol = 0;
8897 wpa_s->oci_freq_override_saquery_req = 0;
8898 wpa_s->oci_freq_override_saquery_resp = 0;
8899 wpa_s->oci_freq_override_eapol_g2 = 0;
8900 wpa_s->oci_freq_override_ft_assoc = 0;
8901 wpa_s->oci_freq_override_fils_assoc = 0;
8902 wpa_s->oci_freq_override_wnm_sleep = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -07008903 wpa_s->disable_eapol_g2_tx = 0;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008904 wpa_s->test_assoc_comeback_type = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008905#ifdef CONFIG_DPP
8906 os_free(wpa_s->dpp_config_obj_override);
8907 wpa_s->dpp_config_obj_override = NULL;
8908 os_free(wpa_s->dpp_discovery_override);
8909 wpa_s->dpp_discovery_override = NULL;
8910 os_free(wpa_s->dpp_groups_override);
8911 wpa_s->dpp_groups_override = NULL;
Sunil8cd6f4d2022-06-28 18:40:46 +00008912 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
8913 wpa_s->dpp_discard_public_action = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008914 dpp_test = DPP_TEST_DISABLED;
8915#endif /* CONFIG_DPP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008916#endif /* CONFIG_TESTING_OPTIONS */
8917
8918 wpa_s->disconnected = 0;
8919 os_free(wpa_s->next_scan_freqs);
8920 wpa_s->next_scan_freqs = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008921 os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN);
8922 wpa_s->next_scan_bssid_wildcard_ssid = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008923 os_free(wpa_s->select_network_scan_freqs);
8924 wpa_s->select_network_scan_freqs = NULL;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008925#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07008926 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008927#endif /* CONFIG_NO_ROBUST_AV */
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008928
8929 wpa_bss_flush(wpa_s);
8930 if (!dl_list_empty(&wpa_s->bss)) {
8931 wpa_printf(MSG_DEBUG,
8932 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8933 MACSTR " pending_bssid=" MACSTR,
8934 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
8935 MAC2STR(wpa_s->bssid),
8936 MAC2STR(wpa_s->pending_bssid));
8937 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008938
8939 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -08008940 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008941
8942#ifdef CONFIG_SME
8943 wpa_s->sme.last_unprot_disconnect.sec = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008944 wpa_s->sme.auth_alg = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008945#endif /* CONFIG_SME */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008946
8947 wpabuf_free(wpa_s->ric_ies);
8948 wpa_s->ric_ies = NULL;
Hai Shalom74f70d42019-02-11 14:42:39 -08008949
8950 wpa_supplicant_update_channel_list(wpa_s, NULL);
8951
8952 free_bss_tmp_disallowed(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -07008953
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008954#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07008955 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008956#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalom60840252021-02-19 19:02:11 -08008957
8958#ifdef CONFIG_PASN
8959 wpas_pasn_auth_stop(wpa_s);
8960#endif /* CONFIG_PASN */
8961
8962 if (wpa_s->mac_addr_changed && wpa_s->conf->mac_addr == 0)
8963 wpas_restore_permanent_mac_addr(wpa_s);
Sunil Ravia04bd252022-05-02 22:54:18 -07008964
8965 wpa_s->conf->ignore_old_scan_res = 0;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008966
8967#ifdef CONFIG_NAN_USD
8968 wpas_nan_usd_flush(wpa_s);
8969#endif /* CONFIG_NAN_USD */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008970}
8971
8972
8973static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
8974 char *buf, size_t buflen)
8975{
8976 struct wpa_radio_work *work;
8977 char *pos, *end;
8978 struct os_reltime now, diff;
8979
8980 pos = buf;
8981 end = buf + buflen;
8982
8983 os_get_reltime(&now);
8984
8985 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8986 {
8987 int ret;
8988
8989 os_reltime_sub(&now, &work->time, &diff);
8990 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
8991 work->type, work->wpa_s->ifname, work->freq,
8992 work->started, diff.sec, diff.usec);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008993 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008994 break;
8995 pos += ret;
8996 }
8997
8998 return pos - buf;
8999}
9000
9001
9002static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
9003{
9004 struct wpa_radio_work *work = eloop_ctx;
9005 struct wpa_external_work *ework = work->ctx;
9006
9007 wpa_dbg(work->wpa_s, MSG_DEBUG,
9008 "Timing out external radio work %u (%s)",
9009 ework->id, work->type);
9010 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009011 work->wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009012 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07009013 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009014}
9015
9016
9017static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
9018{
9019 struct wpa_external_work *ework = work->ctx;
9020
9021 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08009022 if (work->started)
9023 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
9024 work, NULL);
9025
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009026 /*
9027 * work->type points to a buffer in ework, so need to replace
9028 * that here with a fixed string to avoid use of freed memory
9029 * in debug prints.
9030 */
9031 work->type = "freed-ext-work";
9032 work->ctx = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009033 os_free(ework);
9034 return;
9035 }
9036
9037 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
9038 ework->id, ework->type);
9039 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009040 work->wpa_s->ext_work_in_progress = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009041 if (!ework->timeout)
9042 ework->timeout = 10;
9043 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
9044 work, NULL);
9045}
9046
9047
9048static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
9049 char *buf, size_t buflen)
9050{
9051 struct wpa_external_work *ework;
9052 char *pos, *pos2;
9053 size_t type_len;
9054 int ret;
9055 unsigned int freq = 0;
9056
9057 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
9058
9059 ework = os_zalloc(sizeof(*ework));
9060 if (ework == NULL)
9061 return -1;
9062
9063 pos = os_strchr(cmd, ' ');
9064 if (pos) {
9065 type_len = pos - cmd;
9066 pos++;
9067
9068 pos2 = os_strstr(pos, "freq=");
9069 if (pos2)
9070 freq = atoi(pos2 + 5);
9071
9072 pos2 = os_strstr(pos, "timeout=");
9073 if (pos2)
9074 ework->timeout = atoi(pos2 + 8);
9075 } else {
9076 type_len = os_strlen(cmd);
9077 }
9078 if (4 + type_len >= sizeof(ework->type))
9079 type_len = sizeof(ework->type) - 4 - 1;
9080 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
9081 os_memcpy(ework->type + 4, cmd, type_len);
9082 ework->type[4 + type_len] = '\0';
9083
9084 wpa_s->ext_work_id++;
9085 if (wpa_s->ext_work_id == 0)
9086 wpa_s->ext_work_id++;
9087 ework->id = wpa_s->ext_work_id;
9088
9089 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
9090 ework) < 0) {
9091 os_free(ework);
9092 return -1;
9093 }
9094
9095 ret = os_snprintf(buf, buflen, "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009096 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009097 return -1;
9098 return ret;
9099}
9100
9101
9102static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
9103{
9104 struct wpa_radio_work *work;
9105 unsigned int id = atoi(cmd);
9106
9107 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
9108 {
9109 struct wpa_external_work *ework;
9110
9111 if (os_strncmp(work->type, "ext:", 4) != 0)
9112 continue;
9113 ework = work->ctx;
9114 if (id && ework->id != id)
9115 continue;
9116 wpa_dbg(wpa_s, MSG_DEBUG,
9117 "Completed external radio work %u (%s)",
9118 ework->id, ework->type);
9119 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009120 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009121 radio_work_done(work);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07009122 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009123 return 3; /* "OK\n" */
9124 }
9125
9126 return -1;
9127}
9128
9129
9130static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
9131 char *buf, size_t buflen)
9132{
9133 if (os_strcmp(cmd, "show") == 0)
9134 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
9135 if (os_strncmp(cmd, "add ", 4) == 0)
9136 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
9137 if (os_strncmp(cmd, "done ", 5) == 0)
9138 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
9139 return -1;
9140}
9141
9142
9143void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
9144{
9145 struct wpa_radio_work *work, *tmp;
9146
Dmitry Shmidt18463232014-01-24 12:29:41 -08009147 if (!wpa_s || !wpa_s->radio)
9148 return;
9149
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009150 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
9151 struct wpa_radio_work, list) {
9152 struct wpa_external_work *ework;
9153
9154 if (os_strncmp(work->type, "ext:", 4) != 0)
9155 continue;
9156 ework = work->ctx;
9157 wpa_dbg(wpa_s, MSG_DEBUG,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07009158 "Flushing%s external radio work %u (%s)",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009159 work->started ? " started" : "", ework->id,
9160 ework->type);
9161 if (work->started)
9162 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
9163 work, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009164 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07009165 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009166 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07009167}
9168
9169
Dmitry Shmidt051af732013-10-22 13:52:46 -07009170static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
9171{
9172 struct wpa_supplicant *wpa_s = eloop_ctx;
9173 eapol_sm_notify_ctrl_response(wpa_s->eapol);
9174}
9175
9176
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009177static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
9178 unsigned int *scan_id_count, int scan_id[])
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009179{
9180 const char *pos = value;
9181
9182 while (pos) {
9183 if (*pos == ' ' || *pos == '\0')
9184 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009185 if (*scan_id_count == MAX_SCAN_ID)
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009186 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009187 scan_id[(*scan_id_count)++] = atoi(pos);
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009188 pos = os_strchr(pos, ',');
9189 if (pos)
9190 pos++;
9191 }
9192
9193 return 0;
9194}
9195
9196
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009197static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
9198 char *reply, int reply_size, int *reply_len)
9199{
9200 char *pos;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009201 unsigned int manual_scan_passive = 0;
9202 unsigned int manual_scan_use_id = 0;
9203 unsigned int manual_scan_only_new = 0;
9204 unsigned int scan_only = 0;
9205 unsigned int scan_id_count = 0;
Sunil8cd6f4d2022-06-28 18:40:46 +00009206 unsigned int manual_non_coloc_6ghz = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009207 int scan_id[MAX_SCAN_ID];
9208 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
9209 struct wpa_scan_results *scan_res);
9210 int *manual_scan_freqs = NULL;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009211 struct wpa_ssid_value *ssid = NULL, *ns;
9212 unsigned int ssid_count = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009213
9214 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
9215 *reply_len = -1;
9216 return;
9217 }
9218
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009219 if (radio_work_pending(wpa_s, "scan")) {
9220 wpa_printf(MSG_DEBUG,
9221 "Pending scan scheduled - reject new request");
9222 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9223 return;
9224 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009225
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07009226#ifdef CONFIG_INTERWORKING
9227 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
9228 wpa_printf(MSG_DEBUG,
9229 "Interworking select in progress - reject new scan");
9230 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9231 return;
9232 }
9233#endif /* CONFIG_INTERWORKING */
9234
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009235 if (params) {
9236 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009237 scan_only = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009238
9239 pos = os_strstr(params, "freq=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009240 if (pos) {
9241 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
9242 pos + 5);
9243 if (manual_scan_freqs == NULL) {
9244 *reply_len = -1;
9245 goto done;
9246 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009247 }
9248
9249 pos = os_strstr(params, "passive=");
9250 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009251 manual_scan_passive = !!atoi(pos + 8);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009252
9253 pos = os_strstr(params, "use_id=");
9254 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009255 manual_scan_use_id = atoi(pos + 7);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009256
9257 pos = os_strstr(params, "only_new=1");
9258 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009259 manual_scan_only_new = 1;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009260
9261 pos = os_strstr(params, "scan_id=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009262 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
9263 scan_id) < 0) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009264 *reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009265 goto done;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009266 }
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009267
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009268 pos = os_strstr(params, "bssid=");
9269 if (pos) {
9270 u8 bssid[ETH_ALEN];
9271
9272 pos += 6;
9273 if (hwaddr_aton(pos, bssid)) {
9274 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
9275 *reply_len = -1;
9276 goto done;
9277 }
9278 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
Hai Shalomfdcde762020-04-02 11:19:20 -07009279
9280 wpa_s->next_scan_bssid_wildcard_ssid =
9281 os_strstr(params, "wildcard_ssid=1") != NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009282 }
9283
Sunil8cd6f4d2022-06-28 18:40:46 +00009284 pos = os_strstr(params, "non_coloc_6ghz=");
9285 if (pos)
9286 manual_non_coloc_6ghz = !!atoi(pos + 15);
9287
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009288 pos = params;
9289 while (pos && *pos != '\0') {
9290 if (os_strncmp(pos, "ssid ", 5) == 0) {
9291 char *end;
9292
9293 pos += 5;
9294 end = pos;
9295 while (*end) {
9296 if (*end == '\0' || *end == ' ')
9297 break;
9298 end++;
9299 }
9300
9301 ns = os_realloc_array(
9302 ssid, ssid_count + 1,
9303 sizeof(struct wpa_ssid_value));
9304 if (ns == NULL) {
9305 *reply_len = -1;
9306 goto done;
9307 }
9308 ssid = ns;
9309
9310 if ((end - pos) & 0x01 ||
9311 end - pos > 2 * SSID_MAX_LEN ||
9312 hexstr2bin(pos, ssid[ssid_count].ssid,
9313 (end - pos) / 2) < 0) {
9314 wpa_printf(MSG_DEBUG,
9315 "Invalid SSID value '%s'",
9316 pos);
9317 *reply_len = -1;
9318 goto done;
9319 }
9320 ssid[ssid_count].ssid_len = (end - pos) / 2;
9321 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
9322 ssid[ssid_count].ssid,
9323 ssid[ssid_count].ssid_len);
9324 ssid_count++;
9325 pos = end;
9326 }
9327
9328 pos = os_strchr(pos, ' ');
9329 if (pos)
9330 pos++;
9331 }
9332 }
9333
9334 wpa_s->num_ssids_from_scan_req = ssid_count;
9335 os_free(wpa_s->ssids_from_scan_req);
9336 if (ssid_count) {
9337 wpa_s->ssids_from_scan_req = ssid;
9338 ssid = NULL;
9339 } else {
9340 wpa_s->ssids_from_scan_req = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009341 }
9342
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009343 if (scan_only)
9344 scan_res_handler = scan_only_handler;
9345 else if (wpa_s->scan_res_handler == scan_only_handler)
9346 scan_res_handler = NULL;
9347 else
9348 scan_res_handler = wpa_s->scan_res_handler;
9349
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009350 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
9351 ((wpa_s->wpa_state <= WPA_SCANNING) ||
9352 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009353 wpa_s->manual_scan_passive = manual_scan_passive;
9354 wpa_s->manual_scan_use_id = manual_scan_use_id;
9355 wpa_s->manual_scan_only_new = manual_scan_only_new;
9356 wpa_s->scan_id_count = scan_id_count;
Sunil8cd6f4d2022-06-28 18:40:46 +00009357 wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009358 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9359 wpa_s->scan_res_handler = scan_res_handler;
9360 os_free(wpa_s->manual_scan_freqs);
9361 wpa_s->manual_scan_freqs = manual_scan_freqs;
9362 manual_scan_freqs = NULL;
9363
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009364 wpa_s->normal_scans = 0;
9365 wpa_s->scan_req = MANUAL_SCAN_REQ;
9366 wpa_s->after_wps = 0;
9367 wpa_s->known_wps_freq = 0;
9368 wpa_supplicant_req_scan(wpa_s, 0, 0);
9369 if (wpa_s->manual_scan_use_id) {
9370 wpa_s->manual_scan_id++;
9371 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9372 wpa_s->manual_scan_id);
9373 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9374 wpa_s->manual_scan_id);
9375 }
9376 } else if (wpa_s->sched_scanning) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009377 wpa_s->manual_scan_passive = manual_scan_passive;
9378 wpa_s->manual_scan_use_id = manual_scan_use_id;
9379 wpa_s->manual_scan_only_new = manual_scan_only_new;
9380 wpa_s->scan_id_count = scan_id_count;
Sunil8cd6f4d2022-06-28 18:40:46 +00009381 wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009382 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9383 wpa_s->scan_res_handler = scan_res_handler;
9384 os_free(wpa_s->manual_scan_freqs);
9385 wpa_s->manual_scan_freqs = manual_scan_freqs;
9386 manual_scan_freqs = NULL;
9387
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009388 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
9389 wpa_supplicant_cancel_sched_scan(wpa_s);
9390 wpa_s->scan_req = MANUAL_SCAN_REQ;
9391 wpa_supplicant_req_scan(wpa_s, 0, 0);
9392 if (wpa_s->manual_scan_use_id) {
9393 wpa_s->manual_scan_id++;
9394 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9395 wpa_s->manual_scan_id);
9396 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9397 wpa_s->manual_scan_id);
9398 }
9399 } else {
9400 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
9401 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9402 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009403
9404done:
9405 os_free(manual_scan_freqs);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009406 os_free(ssid);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009407}
9408
9409
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009410#ifdef CONFIG_TESTING_OPTIONS
9411
9412static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
9413 unsigned int freq, const u8 *dst,
9414 const u8 *src, const u8 *bssid,
9415 const u8 *data, size_t data_len,
9416 enum offchannel_send_action_result
9417 result)
9418{
9419 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
9420 " src=" MACSTR " bssid=" MACSTR " result=%s",
9421 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
9422 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
9423 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
9424 "NO_ACK" : "FAILED"));
9425}
9426
9427
9428static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
9429{
9430 char *pos, *param;
9431 size_t len;
9432 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
9433 int res, used;
9434 int freq = 0, no_cck = 0, wait_time = 0;
9435
9436 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
9437 * <action=Action frame payload> */
9438
9439 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
9440
9441 pos = cmd;
9442 used = hwaddr_aton2(pos, da);
9443 if (used < 0)
9444 return -1;
9445 pos += used;
9446 while (*pos == ' ')
9447 pos++;
9448 used = hwaddr_aton2(pos, bssid);
9449 if (used < 0)
9450 return -1;
9451 pos += used;
9452
9453 param = os_strstr(pos, " freq=");
9454 if (param) {
9455 param += 6;
9456 freq = atoi(param);
9457 }
9458
9459 param = os_strstr(pos, " no_cck=");
9460 if (param) {
9461 param += 8;
9462 no_cck = atoi(param);
9463 }
9464
9465 param = os_strstr(pos, " wait_time=");
9466 if (param) {
9467 param += 11;
9468 wait_time = atoi(param);
9469 }
9470
9471 param = os_strstr(pos, " action=");
9472 if (param == NULL)
9473 return -1;
9474 param += 8;
9475
9476 len = os_strlen(param);
9477 if (len & 1)
9478 return -1;
9479 len /= 2;
9480
9481 buf = os_malloc(len);
9482 if (buf == NULL)
9483 return -1;
9484
9485 if (hexstr2bin(param, buf, len) < 0) {
9486 os_free(buf);
9487 return -1;
9488 }
9489
9490 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
9491 buf, len, wait_time,
9492 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
9493 os_free(buf);
9494 return res;
9495}
9496
9497
9498static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
9499{
9500 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
9501 offchannel_send_action_done(wpa_s);
9502}
9503
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009504
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009505static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
9506 char *cmd)
9507{
9508 char *pos, *param;
9509 size_t len;
9510 u8 *buf;
9511 int freq = 0, datarate = 0, ssi_signal = 0;
9512 union wpa_event_data event;
9513
9514 if (!wpa_s->ext_mgmt_frame_handling)
9515 return -1;
9516
9517 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
9518
9519 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
9520
9521 pos = cmd;
9522 param = os_strstr(pos, "freq=");
9523 if (param) {
9524 param += 5;
9525 freq = atoi(param);
9526 }
9527
9528 param = os_strstr(pos, " datarate=");
9529 if (param) {
9530 param += 10;
9531 datarate = atoi(param);
9532 }
9533
9534 param = os_strstr(pos, " ssi_signal=");
9535 if (param) {
9536 param += 12;
9537 ssi_signal = atoi(param);
9538 }
9539
9540 param = os_strstr(pos, " frame=");
9541 if (param == NULL)
9542 return -1;
9543 param += 7;
9544
9545 len = os_strlen(param);
9546 if (len & 1)
9547 return -1;
9548 len /= 2;
9549
9550 buf = os_malloc(len);
9551 if (buf == NULL)
9552 return -1;
9553
9554 if (hexstr2bin(param, buf, len) < 0) {
9555 os_free(buf);
9556 return -1;
9557 }
9558
9559 os_memset(&event, 0, sizeof(event));
9560 event.rx_mgmt.freq = freq;
9561 event.rx_mgmt.frame = buf;
9562 event.rx_mgmt.frame_len = len;
9563 event.rx_mgmt.ssi_signal = ssi_signal;
9564 event.rx_mgmt.datarate = datarate;
9565 wpa_s->ext_mgmt_frame_handling = 0;
9566 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
9567 wpa_s->ext_mgmt_frame_handling = 1;
9568
9569 os_free(buf);
9570
9571 return 0;
9572}
9573
9574
Paul Stewart092955c2017-02-06 09:13:09 -08009575static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
9576 char *param)
9577{
9578 struct wpa_scan_res *res;
9579 struct os_reltime now;
9580 char *pos, *end;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009581 int ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08009582
9583 if (!param)
9584 return -1;
9585
9586 if (os_strcmp(param, "START") == 0) {
9587 wpa_bss_update_start(wpa_s);
9588 return 0;
9589 }
9590
9591 if (os_strcmp(param, "END") == 0) {
9592 wpa_bss_update_end(wpa_s, NULL, 1);
9593 return 0;
9594 }
9595
9596 if (os_strncmp(param, "BSS ", 4) != 0)
9597 return -1;
9598 param += 3;
9599
9600 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
9601 if (!res)
9602 return -1;
9603
9604 pos = os_strstr(param, " flags=");
9605 if (pos)
9606 res->flags = strtol(pos + 7, NULL, 16);
9607
9608 pos = os_strstr(param, " bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009609 if (pos && hwaddr_aton(pos + 7, res->bssid))
9610 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009611
9612 pos = os_strstr(param, " freq=");
9613 if (pos)
9614 res->freq = atoi(pos + 6);
9615
9616 pos = os_strstr(param, " beacon_int=");
9617 if (pos)
9618 res->beacon_int = atoi(pos + 12);
9619
9620 pos = os_strstr(param, " caps=");
9621 if (pos)
9622 res->caps = strtol(pos + 6, NULL, 16);
9623
9624 pos = os_strstr(param, " qual=");
9625 if (pos)
9626 res->qual = atoi(pos + 6);
9627
9628 pos = os_strstr(param, " noise=");
9629 if (pos)
9630 res->noise = atoi(pos + 7);
9631
9632 pos = os_strstr(param, " level=");
9633 if (pos)
9634 res->level = atoi(pos + 7);
9635
9636 pos = os_strstr(param, " tsf=");
9637 if (pos)
9638 res->tsf = strtoll(pos + 5, NULL, 16);
9639
9640 pos = os_strstr(param, " age=");
9641 if (pos)
9642 res->age = atoi(pos + 5);
9643
9644 pos = os_strstr(param, " est_throughput=");
9645 if (pos)
9646 res->est_throughput = atoi(pos + 16);
9647
9648 pos = os_strstr(param, " snr=");
9649 if (pos)
9650 res->snr = atoi(pos + 5);
9651
9652 pos = os_strstr(param, " parent_tsf=");
9653 if (pos)
9654 res->parent_tsf = strtoll(pos + 7, NULL, 16);
9655
9656 pos = os_strstr(param, " tsf_bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009657 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
9658 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009659
9660 pos = os_strstr(param, " ie=");
9661 if (pos) {
9662 pos += 4;
9663 end = os_strchr(pos, ' ');
9664 if (!end)
9665 end = pos + os_strlen(pos);
9666 res->ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009667 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
9668 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009669 }
9670
9671 pos = os_strstr(param, " beacon_ie=");
9672 if (pos) {
9673 pos += 11;
9674 end = os_strchr(pos, ' ');
9675 if (!end)
9676 end = pos + os_strlen(pos);
9677 res->beacon_ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009678 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
9679 res->beacon_ie_len))
9680 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009681 }
9682
9683 os_get_reltime(&now);
9684 wpa_bss_update_scan_res(wpa_s, res, &now);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009685 ret = 0;
9686fail:
Paul Stewart092955c2017-02-06 09:13:09 -08009687 os_free(res);
9688
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009689 return ret;
Paul Stewart092955c2017-02-06 09:13:09 -08009690}
9691
9692
Hai Shaloma20dcd72022-02-04 13:43:00 -08009693static int wpas_ctrl_iface_driver_event_assoc(struct wpa_supplicant *wpa_s,
9694 char *param)
9695{
9696 union wpa_event_data event;
9697 struct assoc_info *ai;
9698 char *ctx = NULL;
9699 int ret = -1;
9700 struct wpabuf *req_ies = NULL;
9701 struct wpabuf *resp_ies = NULL;
9702 struct wpabuf *resp_frame = NULL;
9703 struct wpabuf *beacon_ies = NULL;
9704 struct wpabuf *key_replay_ctr = NULL;
9705 struct wpabuf *ptk_kck = NULL;
9706 struct wpabuf *ptk_kek = NULL;
9707 struct wpabuf *fils_pmk = NULL;
9708 char *str, *pos;
9709 u8 addr[ETH_ALEN];
9710 u8 fils_pmkid[PMKID_LEN];
9711
9712 os_memset(&event, 0, sizeof(event));
9713 ai = &event.assoc_info;
9714
9715 while ((str = str_token(param, " ", &ctx))) {
9716 pos = os_strchr(str, '=');
9717 if (!pos)
9718 goto fail;
9719 *pos++ = '\0';
9720
9721 if (os_strcmp(str, "reassoc") == 0) {
9722 ai->reassoc = atoi(pos);
9723 } else if (os_strcmp(str, "req_ies") == 0) {
9724 wpabuf_free(req_ies);
9725 req_ies = wpabuf_parse_bin(pos);
9726 if (!req_ies)
9727 goto fail;
9728 ai->req_ies = wpabuf_head(req_ies);
9729 ai->req_ies_len = wpabuf_len(req_ies);
9730 } else if (os_strcmp(str, "resp_ies") == 0) {
9731 wpabuf_free(resp_ies);
9732 resp_ies = wpabuf_parse_bin(pos);
9733 if (!resp_ies)
9734 goto fail;
9735 ai->resp_ies = wpabuf_head(resp_ies);
9736 ai->resp_ies_len = wpabuf_len(resp_ies);
9737 } else if (os_strcmp(str, "resp_frame") == 0) {
9738 wpabuf_free(resp_frame);
9739 resp_frame = wpabuf_parse_bin(pos);
9740 if (!resp_frame)
9741 goto fail;
9742 ai->resp_frame = wpabuf_head(resp_frame);
9743 ai->resp_frame_len = wpabuf_len(resp_frame);
9744 } else if (os_strcmp(str, "beacon_ies") == 0) {
9745 wpabuf_free(beacon_ies);
9746 beacon_ies = wpabuf_parse_bin(pos);
9747 if (!beacon_ies)
9748 goto fail;
9749 ai->beacon_ies = wpabuf_head(beacon_ies);
9750 ai->beacon_ies_len = wpabuf_len(beacon_ies);
9751 } else if (os_strcmp(str, "freq") == 0) {
9752 ai->freq = atoi(pos);
9753 } else if (os_strcmp(str, "wmm::info_bitmap") == 0) {
9754 ai->wmm_params.info_bitmap = atoi(pos);
9755 } else if (os_strcmp(str, "wmm::uapsd_queues") == 0) {
9756 ai->wmm_params.uapsd_queues = atoi(pos);
9757 } else if (os_strcmp(str, "addr") == 0) {
9758 if (hwaddr_aton(pos, addr))
9759 goto fail;
9760 ai->addr = addr;
9761 } else if (os_strcmp(str, "authorized") == 0) {
9762 ai->authorized = atoi(pos);
9763 } else if (os_strcmp(str, "key_replay_ctr") == 0) {
9764 wpabuf_free(key_replay_ctr);
9765 key_replay_ctr = wpabuf_parse_bin(pos);
9766 if (!key_replay_ctr)
9767 goto fail;
9768 ai->key_replay_ctr = wpabuf_head(key_replay_ctr);
9769 ai->key_replay_ctr_len = wpabuf_len(key_replay_ctr);
9770 } else if (os_strcmp(str, "ptk_kck") == 0) {
9771 wpabuf_free(ptk_kck);
9772 ptk_kck = wpabuf_parse_bin(pos);
9773 if (!ptk_kck)
9774 goto fail;
9775 ai->ptk_kck = wpabuf_head(ptk_kck);
9776 ai->ptk_kck_len = wpabuf_len(ptk_kck);
9777 } else if (os_strcmp(str, "ptk_kek") == 0) {
9778 wpabuf_free(ptk_kek);
9779 ptk_kek = wpabuf_parse_bin(pos);
9780 if (!ptk_kek)
9781 goto fail;
9782 ai->ptk_kek = wpabuf_head(ptk_kek);
9783 ai->ptk_kek_len = wpabuf_len(ptk_kek);
9784 } else if (os_strcmp(str, "subnet_status") == 0) {
9785 ai->subnet_status = atoi(pos);
9786 } else if (os_strcmp(str, "fils_erp_next_seq_num") == 0) {
9787 ai->fils_erp_next_seq_num = atoi(pos);
9788 } else if (os_strcmp(str, "fils_pmk") == 0) {
9789 wpabuf_free(fils_pmk);
9790 fils_pmk = wpabuf_parse_bin(pos);
9791 if (!fils_pmk)
9792 goto fail;
9793 ai->fils_pmk = wpabuf_head(fils_pmk);
9794 ai->fils_pmk_len = wpabuf_len(fils_pmk);
9795 } else if (os_strcmp(str, "fils_pmkid") == 0) {
9796 if (hexstr2bin(pos, fils_pmkid, PMKID_LEN) < 0)
9797 goto fail;
9798 ai->fils_pmkid = fils_pmkid;
9799 } else {
9800 goto fail;
9801 }
9802 }
9803
9804 wpa_supplicant_event(wpa_s, EVENT_ASSOC, &event);
9805 ret = 0;
9806fail:
9807 wpabuf_free(req_ies);
9808 wpabuf_free(resp_ies);
9809 wpabuf_free(resp_frame);
9810 wpabuf_free(beacon_ies);
9811 wpabuf_free(key_replay_ctr);
9812 wpabuf_free(ptk_kck);
9813 wpabuf_free(ptk_kek);
9814 wpabuf_free(fils_pmk);
9815 return ret;
9816}
9817
9818
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009819static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
9820{
9821 char *pos, *param;
9822 union wpa_event_data event;
9823 enum wpa_event_type ev;
9824
9825 /* <event name> [parameters..] */
9826
9827 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
9828
9829 pos = cmd;
9830 param = os_strchr(pos, ' ');
9831 if (param)
9832 *param++ = '\0';
9833
9834 os_memset(&event, 0, sizeof(event));
9835
9836 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
9837 ev = EVENT_INTERFACE_ENABLED;
9838 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
9839 ev = EVENT_INTERFACE_DISABLED;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07009840 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
9841 ev = EVENT_AVOID_FREQUENCIES;
9842 if (param == NULL)
9843 param = "";
9844 if (freq_range_list_parse(&event.freq_range, param) < 0)
9845 return -1;
9846 wpa_supplicant_event(wpa_s, ev, &event);
9847 os_free(event.freq_range.range);
9848 return 0;
Paul Stewart092955c2017-02-06 09:13:09 -08009849 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
9850 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
Hai Shaloma20dcd72022-02-04 13:43:00 -08009851 } else if (os_strcmp(cmd, "ASSOC") == 0) {
9852 return wpas_ctrl_iface_driver_event_assoc(wpa_s, param);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009853 } else {
9854 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
9855 cmd);
9856 return -1;
9857 }
9858
9859 wpa_supplicant_event(wpa_s, ev, &event);
9860
9861 return 0;
9862}
9863
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009864
9865static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
9866{
9867 char *pos;
9868 u8 src[ETH_ALEN], *buf;
9869 int used;
9870 size_t len;
9871
9872 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
9873
9874 pos = cmd;
9875 used = hwaddr_aton2(pos, src);
9876 if (used < 0)
9877 return -1;
9878 pos += used;
9879 while (*pos == ' ')
9880 pos++;
9881
9882 len = os_strlen(pos);
9883 if (len & 1)
9884 return -1;
9885 len /= 2;
9886
9887 buf = os_malloc(len);
9888 if (buf == NULL)
9889 return -1;
9890
9891 if (hexstr2bin(pos, buf, len) < 0) {
9892 os_free(buf);
9893 return -1;
9894 }
9895
Sunil8cd6f4d2022-06-28 18:40:46 +00009896 wpa_supplicant_rx_eapol(wpa_s, src, buf, len, FRAME_ENCRYPTION_UNKNOWN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009897 os_free(buf);
9898
9899 return 0;
9900}
9901
9902
Hai Shaloma20dcd72022-02-04 13:43:00 -08009903static int wpas_ctrl_iface_eapol_tx(struct wpa_supplicant *wpa_s, char *cmd)
9904{
9905 char *pos;
9906 u8 dst[ETH_ALEN], *buf;
9907 int used, ret;
9908 size_t len;
9909 unsigned int prev;
9910
9911 wpa_printf(MSG_DEBUG, "External EAPOL TX: %s", cmd);
9912
9913 pos = cmd;
9914 used = hwaddr_aton2(pos, dst);
9915 if (used < 0)
9916 return -1;
9917 pos += used;
9918 while (*pos == ' ')
9919 pos++;
9920
9921 len = os_strlen(pos);
9922 if (len & 1)
9923 return -1;
9924 len /= 2;
9925
9926 buf = os_malloc(len);
9927 if (!buf || hexstr2bin(pos, buf, len) < 0) {
9928 os_free(buf);
9929 return -1;
9930 }
9931
9932 prev = wpa_s->ext_eapol_frame_io;
9933 wpa_s->ext_eapol_frame_io = 0;
9934 ret = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, buf, len);
9935 wpa_s->ext_eapol_frame_io = prev;
9936 os_free(buf);
9937
9938 return ret;
9939}
9940
9941
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009942static u16 ipv4_hdr_checksum(const void *buf, size_t len)
9943{
9944 size_t i;
9945 u32 sum = 0;
9946 const u16 *pos = buf;
9947
9948 for (i = 0; i < len / 2; i++)
9949 sum += *pos++;
9950
9951 while (sum >> 16)
9952 sum = (sum & 0xffff) + (sum >> 16);
9953
9954 return sum ^ 0xffff;
9955}
9956
9957
9958#define HWSIM_PACKETLEN 1500
9959#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
9960
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07009961static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
9962 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009963{
9964 struct wpa_supplicant *wpa_s = ctx;
9965 const struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07009966 struct ip ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009967 const u8 *pos;
9968 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08009969 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009970
Hai Shalom74f70d42019-02-11 14:42:39 -08009971 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
9972 wpa_printf(MSG_DEBUG,
9973 "test data: RX - ignore unexpected length %d",
9974 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009975 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08009976 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009977
9978 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009979 os_memcpy(&ip, eth + 1, sizeof(ip));
9980 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009981
Hai Shalomfdcde762020-04-02 11:19:20 -07009982 if (ip.ip_hl != 5 || ip.ip_v != 4 || ntohs(ip.ip_len) > HWSIM_IP_LEN) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009983 wpa_printf(MSG_DEBUG,
Hai Shalom899fcc72020-10-19 14:38:18 -07009984 "test data: RX - ignore unexpected IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009985 return;
Hai Shalom39bc25d2019-02-06 16:32:13 -08009986 }
Hai Shalombf6e0ba2019-02-11 12:01:50 -08009987
Hai Shalomfdcde762020-04-02 11:19:20 -07009988 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009989 if (*pos != (u8) i) {
9990 wpa_printf(MSG_DEBUG,
9991 "test data: RX - ignore mismatching payload");
9992 return;
9993 }
9994 pos++;
9995 }
9996 extra[0] = '\0';
Hai Shalomfdcde762020-04-02 11:19:20 -07009997 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
9998 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
Hai Shalom74f70d42019-02-11 14:42:39 -08009999 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
10000 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010001}
10002
10003
10004static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
10005 char *cmd)
10006{
10007 int enabled = atoi(cmd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080010008 char *pos;
10009 const char *ifname;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010010
10011 if (!enabled) {
10012 if (wpa_s->l2_test) {
10013 l2_packet_deinit(wpa_s->l2_test);
10014 wpa_s->l2_test = NULL;
10015 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
10016 }
10017 return 0;
10018 }
10019
10020 if (wpa_s->l2_test)
10021 return 0;
10022
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080010023 pos = os_strstr(cmd, " ifname=");
10024 if (pos)
10025 ifname = pos + 8;
10026 else
10027 ifname = wpa_s->ifname;
10028
10029 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010030 ETHERTYPE_IP, wpas_data_test_rx,
10031 wpa_s, 1);
10032 if (wpa_s->l2_test == NULL)
10033 return -1;
10034
10035 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
10036
10037 return 0;
10038}
10039
10040
10041static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
10042{
10043 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom74f70d42019-02-11 14:42:39 -080010044 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010045 int used;
10046 long int val;
10047 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010048 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010049 struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -070010050 struct ip *ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010051 u8 *dpos;
10052 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -080010053 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010054
10055 if (wpa_s->l2_test == NULL)
10056 return -1;
10057
Hai Shalom74f70d42019-02-11 14:42:39 -080010058 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010059
10060 pos = cmd;
10061 used = hwaddr_aton2(pos, dst);
10062 if (used < 0)
10063 return -1;
10064 pos += used;
10065 while (*pos == ' ')
10066 pos++;
10067 used = hwaddr_aton2(pos, src);
10068 if (used < 0)
10069 return -1;
10070 pos += used;
10071
Hai Shalom74f70d42019-02-11 14:42:39 -080010072 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010073 if (val < 0 || val > 0xff)
10074 return -1;
10075 tos = val;
10076
Hai Shalom74f70d42019-02-11 14:42:39 -080010077 pos = os_strstr(pos2, " len=");
10078 if (pos) {
10079 i = atoi(pos + 5);
10080 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
10081 return -1;
10082 send_len = i;
10083 }
10084
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010085 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010086 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
10087 os_memcpy(eth->ether_shost, src, ETH_ALEN);
10088 eth->ether_type = htons(ETHERTYPE_IP);
Hai Shalomfdcde762020-04-02 11:19:20 -070010089 ip = (struct ip *) (eth + 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010090 os_memset(ip, 0, sizeof(*ip));
Hai Shalomfdcde762020-04-02 11:19:20 -070010091 ip->ip_hl = 5;
10092 ip->ip_v = 4;
10093 ip->ip_ttl = 64;
10094 ip->ip_tos = tos;
10095 ip->ip_len = htons(send_len);
10096 ip->ip_p = 1;
10097 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
10098 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
10099 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010100 dpos = (u8 *) (ip + 1);
Hai Shalom74f70d42019-02-11 14:42:39 -080010101 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010102 *dpos++ = i;
10103
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010104 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom74f70d42019-02-11 14:42:39 -080010105 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010106 return -1;
10107
10108 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
10109 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
10110
10111 return 0;
10112}
10113
10114
10115static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
10116 char *cmd)
10117{
10118 u8 *buf;
10119 struct ether_header *eth;
10120 struct l2_packet_data *l2 = NULL;
10121 size_t len;
10122 u16 ethertype;
10123 int res = -1;
10124
10125 len = os_strlen(cmd);
10126 if (len & 1 || len < ETH_HLEN * 2)
10127 return -1;
10128 len /= 2;
10129
10130 buf = os_malloc(len);
10131 if (buf == NULL)
10132 return -1;
10133
10134 if (hexstr2bin(cmd, buf, len) < 0)
10135 goto done;
10136
10137 eth = (struct ether_header *) buf;
10138 ethertype = ntohs(eth->ether_type);
10139
10140 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
10141 wpas_data_test_rx, wpa_s, 1);
10142 if (l2 == NULL)
10143 goto done;
10144
10145 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
10146 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
10147done:
10148 if (l2)
10149 l2_packet_deinit(l2);
10150 os_free(buf);
10151
10152 return res < 0 ? -1 : 0;
10153}
10154
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010155
Jouni Malinenc4818362015-10-04 11:45:13 +030010156static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
10157{
10158 struct wpa_supplicant *wpa_s = eloop_ctx;
10159 int i, count = (intptr_t) timeout_ctx;
10160
10161 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
10162 count);
10163 for (i = 0; i < count; i++) {
10164 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
10165 i + 1, count);
10166 }
10167}
10168
10169
10170static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
10171{
10172 int count;
10173
10174 count = atoi(cmd);
10175 if (count <= 0)
10176 return -1;
10177
10178 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
10179 (void *) (intptr_t) count);
10180}
10181
Dmitry Shmidt818ea482014-03-10 13:15:21 -070010182
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010183static int wpas_get_hex_buf(const char *val, struct wpabuf **ret)
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010184{
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010185 struct wpabuf *buf;
10186 size_t len;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010187
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010188 len = os_strlen(val);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010189 if (len & 1)
10190 return -1;
10191 len /= 2;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010192
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010193 if (len == 0) {
10194 buf = NULL;
10195 } else {
10196 buf = wpabuf_alloc(len);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010197 if (!buf)
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010198 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010199
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010200 if (hexstr2bin(val, wpabuf_put(buf, len), len) < 0) {
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010201 wpabuf_free(buf);
10202 return -1;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010203 }
10204 }
10205
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010206 *ret = buf;
10207 return 0;
10208}
10209
10210
10211static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
10212 const char *cmd)
10213{
10214 struct wpabuf *buf;
10215
10216 if (wpas_get_hex_buf(cmd, &buf) < 0)
10217 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010218 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
10219 return 0;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010220}
10221
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010222
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010223static int wpas_ctrl_test_eapol_m2_elems(struct wpa_supplicant *wpa_s,
10224 const char *cmd)
10225{
10226 struct wpabuf *buf;
10227
10228 if (wpas_get_hex_buf(cmd, &buf) < 0)
10229 return -1;
10230 wpa_sm_set_test_eapol_m2_elems(wpa_s->wpa, buf);
10231 return 0;
10232}
10233
10234
10235static int wpas_ctrl_test_eapol_m4_elems(struct wpa_supplicant *wpa_s,
10236 const char *cmd)
10237{
10238 struct wpabuf *buf;
10239
10240 if (wpas_get_hex_buf(cmd, &buf) < 0)
10241 return -1;
10242 wpa_sm_set_test_eapol_m4_elems(wpa_s->wpa, buf);
10243 return 0;
10244}
10245
10246
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010247static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
10248{
10249 u8 zero[WPA_TK_MAX_LEN];
10250
10251 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
10252 return -1;
10253
10254 wpa_printf(MSG_INFO, "TESTING: Reset PN");
10255 os_memset(zero, 0, sizeof(zero));
10256
10257 /* First, use a zero key to avoid any possible duplicate key avoidance
10258 * in the driver. */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000010259 if (wpa_drv_set_key(wpa_s, -1, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010260 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -070010261 zero, wpa_s->last_tk_len,
10262 KEY_FLAG_PAIRWISE_RX_TX) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010263 return -1;
10264
10265 /* Set the previously configured key to reset its TSC/RSC */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000010266 return wpa_drv_set_key(wpa_s, -1, wpa_s->last_tk_alg,
10267 wpa_s->last_tk_addr,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010268 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -070010269 wpa_s->last_tk, wpa_s->last_tk_len,
10270 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010271}
10272
10273
10274static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
10275{
10276 const char *pos = cmd;
10277 int error, pairwise;
10278
10279 error = atoi(pos);
10280 pos = os_strchr(pos, ' ');
10281 if (!pos)
10282 return -1;
10283 pairwise = atoi(pos);
10284 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
10285 return 0;
10286}
10287
10288
10289static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
10290{
10291#ifdef CONFIG_SME
10292 struct wpa_driver_associate_params params;
10293 int ret;
10294
10295 os_memset(&params, 0, sizeof(params));
10296 params.bssid = wpa_s->bssid;
10297 params.ssid = wpa_s->sme.ssid;
10298 params.ssid_len = wpa_s->sme.ssid_len;
10299 params.freq.freq = wpa_s->sme.freq;
10300 if (wpa_s->last_assoc_req_wpa_ie) {
10301 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
10302 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
10303 }
10304 params.pairwise_suite = wpa_s->pairwise_cipher;
10305 params.group_suite = wpa_s->group_cipher;
10306 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
10307 params.key_mgmt_suite = wpa_s->key_mgmt;
10308 params.wpa_proto = wpa_s->wpa_proto;
10309 params.mgmt_frame_protection = wpa_s->sme.mfp;
10310 params.rrm_used = wpa_s->rrm.rrm_used;
10311 if (wpa_s->sme.prev_bssid_set)
10312 params.prev_bssid = wpa_s->sme.prev_bssid;
10313 wpa_printf(MSG_INFO, "TESTING: Resend association request");
10314 ret = wpa_drv_associate(wpa_s, &params);
10315 wpa_s->testing_resend_assoc = 1;
10316 return ret;
10317#else /* CONFIG_SME */
10318 return -1;
10319#endif /* CONFIG_SME */
10320}
10321
Hai Shaloma20dcd72022-02-04 13:43:00 -080010322
10323static int wpas_ctrl_iface_send_twt_setup(struct wpa_supplicant *wpa_s,
10324 const char *cmd)
10325{
10326 u8 dtok = 1;
10327 int exponent = 10;
10328 int mantissa = 8192;
10329 u8 min_twt = 255;
10330 unsigned long long twt = 0;
10331 bool requestor = true;
10332 int setup_cmd = 0;
10333 bool trigger = true;
10334 bool implicit = true;
10335 bool flow_type = true;
10336 int flow_id = 0;
10337 bool protection = false;
10338 u8 twt_channel = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -070010339 u8 control = BIT(4); /* Control field (IEEE Std 802.11ax-2021,
10340 * Figure 9-687 - Control field format):
10341 * B4 = TWT Information Frame Disabled */
Hai Shaloma20dcd72022-02-04 13:43:00 -080010342 const char *tok_s;
10343
10344 tok_s = os_strstr(cmd, " dialog=");
10345 if (tok_s)
10346 dtok = atoi(tok_s + os_strlen(" dialog="));
10347
10348 tok_s = os_strstr(cmd, " exponent=");
10349 if (tok_s)
10350 exponent = atoi(tok_s + os_strlen(" exponent="));
10351
10352 tok_s = os_strstr(cmd, " mantissa=");
10353 if (tok_s)
10354 mantissa = atoi(tok_s + os_strlen(" mantissa="));
10355
10356 tok_s = os_strstr(cmd, " min_twt=");
10357 if (tok_s)
10358 min_twt = atoi(tok_s + os_strlen(" min_twt="));
10359
10360 tok_s = os_strstr(cmd, " setup_cmd=");
10361 if (tok_s)
10362 setup_cmd = atoi(tok_s + os_strlen(" setup_cmd="));
10363
10364 tok_s = os_strstr(cmd, " twt=");
Sunil8cd6f4d2022-06-28 18:40:46 +000010365 if (tok_s &&
10366 sscanf(tok_s + os_strlen(" twt="), "%llu", &twt) != 1)
10367 return -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080010368
10369 tok_s = os_strstr(cmd, " requestor=");
10370 if (tok_s)
10371 requestor = atoi(tok_s + os_strlen(" requestor="));
10372
10373 tok_s = os_strstr(cmd, " trigger=");
10374 if (tok_s)
10375 trigger = atoi(tok_s + os_strlen(" trigger="));
10376
10377 tok_s = os_strstr(cmd, " implicit=");
10378 if (tok_s)
10379 implicit = atoi(tok_s + os_strlen(" implicit="));
10380
10381 tok_s = os_strstr(cmd, " flow_type=");
10382 if (tok_s)
10383 flow_type = atoi(tok_s + os_strlen(" flow_type="));
10384
10385 tok_s = os_strstr(cmd, " flow_id=");
10386 if (tok_s)
10387 flow_id = atoi(tok_s + os_strlen(" flow_id="));
10388
10389 tok_s = os_strstr(cmd, " protection=");
10390 if (tok_s)
10391 protection = atoi(tok_s + os_strlen(" protection="));
10392
10393 tok_s = os_strstr(cmd, " twt_channel=");
10394 if (tok_s)
10395 twt_channel = atoi(tok_s + os_strlen(" twt_channel="));
10396
10397 tok_s = os_strstr(cmd, " control=");
10398 if (tok_s)
10399 control = atoi(tok_s + os_strlen(" control="));
10400
10401 return wpas_twt_send_setup(wpa_s, dtok, exponent, mantissa, min_twt,
10402 setup_cmd, twt, requestor, trigger, implicit,
10403 flow_type, flow_id, protection, twt_channel,
10404 control);
10405}
10406
10407
10408static int wpas_ctrl_iface_send_twt_teardown(struct wpa_supplicant *wpa_s,
10409 const char *cmd)
10410{
10411 u8 flags = 0x1;
10412 const char *tok_s;
10413
10414 tok_s = os_strstr(cmd, " flags=");
10415 if (tok_s)
10416 flags = atoi(tok_s + os_strlen(" flags="));
10417
10418 return wpas_twt_send_teardown(wpa_s, flags);
10419}
10420
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010421#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010422
10423
10424static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
10425{
10426 char *pos = cmd;
10427 int frame;
10428 size_t len;
10429 struct wpabuf *buf;
10430 struct ieee802_11_elems elems;
10431
10432 frame = atoi(pos);
10433 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10434 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010435 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010436
10437 pos = os_strchr(pos, ' ');
10438 if (pos == NULL)
10439 return -1;
10440 pos++;
10441
10442 len = os_strlen(pos);
10443 if (len == 0)
10444 return 0;
10445 if (len & 1)
10446 return -1;
10447 len /= 2;
10448
10449 buf = wpabuf_alloc(len);
10450 if (buf == NULL)
10451 return -1;
10452
10453 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
10454 wpabuf_free(buf);
10455 return -1;
10456 }
10457
10458 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
10459 ParseFailed) {
10460 wpabuf_free(buf);
10461 return -1;
10462 }
10463
10464 if (wpa_s->vendor_elem[frame] == NULL) {
10465 wpa_s->vendor_elem[frame] = buf;
Hai Shalom60840252021-02-19 19:02:11 -080010466 goto update_ies;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010467 }
10468
10469 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
10470 wpabuf_free(buf);
10471 return -1;
10472 }
10473
10474 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
10475 wpabuf_free(buf);
Hai Shalom60840252021-02-19 19:02:11 -080010476
10477update_ies:
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010478 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010479
Hai Shalom60840252021-02-19 19:02:11 -080010480 if (frame == VENDOR_ELEM_PROBE_REQ ||
10481 frame == VENDOR_ELEM_PROBE_REQ_P2P)
10482 wpa_supplicant_set_default_scan_ies(wpa_s);
10483
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010484 return 0;
10485}
10486
10487
10488static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
10489 char *buf, size_t buflen)
10490{
10491 int frame = atoi(cmd);
10492
10493 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10494 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010495 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010496
10497 if (wpa_s->vendor_elem[frame] == NULL)
10498 return 0;
10499
10500 return wpa_snprintf_hex(buf, buflen,
10501 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
10502 wpabuf_len(wpa_s->vendor_elem[frame]));
10503}
10504
10505
10506static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
10507{
10508 char *pos = cmd;
10509 int frame;
10510 size_t len;
10511 u8 *buf;
10512 struct ieee802_11_elems elems;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010513 int res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010514
10515 frame = atoi(pos);
10516 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10517 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010518 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010519
10520 pos = os_strchr(pos, ' ');
10521 if (pos == NULL)
10522 return -1;
10523 pos++;
10524
10525 if (*pos == '*') {
10526 wpabuf_free(wpa_s->vendor_elem[frame]);
10527 wpa_s->vendor_elem[frame] = NULL;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010528 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010529 return 0;
10530 }
10531
10532 if (wpa_s->vendor_elem[frame] == NULL)
10533 return -1;
10534
10535 len = os_strlen(pos);
10536 if (len == 0)
10537 return 0;
10538 if (len & 1)
10539 return -1;
10540 len /= 2;
10541
10542 buf = os_malloc(len);
10543 if (buf == NULL)
10544 return -1;
10545
10546 if (hexstr2bin(pos, buf, len) < 0) {
10547 os_free(buf);
10548 return -1;
10549 }
10550
10551 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
10552 os_free(buf);
10553 return -1;
10554 }
10555
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010556 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010557 os_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010558 return res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010559}
10560
10561
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010562#ifndef CONFIG_NO_RRM
10563
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010564static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
10565{
10566 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010567 size_t len;
10568 const u8 *data;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010569
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010570 /*
10571 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
10572 * BSSID[6]
10573 * BSSID Information[4]
10574 * Operating Class[1]
10575 * Channel Number[1]
10576 * PHY Type[1]
10577 * Optional Subelements[variable]
10578 */
10579#define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
10580
10581 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010582 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010583 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010584 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010585
10586 data = wpabuf_head_u8(neighbor_rep);
10587 len = wpabuf_len(neighbor_rep);
10588
10589 while (len >= 2 + NR_IE_MIN_LEN) {
10590 const u8 *nr;
10591 char lci[256 * 2 + 1];
10592 char civic[256 * 2 + 1];
10593 u8 nr_len = data[1];
10594 const u8 *pos = data, *end;
10595
10596 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
10597 nr_len < NR_IE_MIN_LEN) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010598 wpa_dbg(wpa_s, MSG_DEBUG,
10599 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
10600 data[0], nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010601 goto out;
10602 }
10603
10604 if (2U + nr_len > len) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010605 wpa_dbg(wpa_s, MSG_DEBUG,
10606 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
10607 data[0], len, nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010608 goto out;
10609 }
10610 pos += 2;
10611 end = pos + nr_len;
10612
10613 nr = pos;
10614 pos += NR_IE_MIN_LEN;
10615
10616 lci[0] = '\0';
10617 civic[0] = '\0';
10618 while (end - pos > 2) {
10619 u8 s_id, s_len;
10620
10621 s_id = *pos++;
10622 s_len = *pos++;
10623 if (s_len > end - pos)
10624 goto out;
10625 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
10626 /* Measurement Token[1] */
10627 /* Measurement Report Mode[1] */
10628 /* Measurement Type[1] */
10629 /* Measurement Report[variable] */
10630 switch (pos[2]) {
10631 case MEASURE_TYPE_LCI:
10632 if (lci[0])
10633 break;
10634 wpa_snprintf_hex(lci, sizeof(lci),
10635 pos, s_len);
10636 break;
10637 case MEASURE_TYPE_LOCATION_CIVIC:
10638 if (civic[0])
10639 break;
10640 wpa_snprintf_hex(civic, sizeof(civic),
10641 pos, s_len);
10642 break;
10643 }
10644 }
10645
10646 pos += s_len;
10647 }
10648
10649 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
10650 "bssid=" MACSTR
10651 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
10652 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
10653 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
10654 nr[ETH_ALEN + 6],
10655 lci[0] ? " lci=" : "", lci,
10656 civic[0] ? " civic=" : "", civic);
10657
10658 data = end;
10659 len -= 2 + nr_len;
10660 }
10661
10662out:
10663 wpabuf_free(neighbor_rep);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010664}
10665
10666
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010667static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
10668 char *cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010669{
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010670 struct wpa_ssid_value ssid, *ssid_p = NULL;
10671 int ret, lci = 0, civic = 0;
10672 char *ssid_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010673
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010674 ssid_s = os_strstr(cmd, "ssid=");
10675 if (ssid_s) {
10676 if (ssid_parse(ssid_s + 5, &ssid)) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010677 wpa_msg(wpa_s, MSG_INFO,
10678 "CTRL: Send Neighbor Report: bad SSID");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010679 return -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010680 }
10681
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010682 ssid_p = &ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010683
10684 /*
10685 * Move cmd after the SSID text that may include "lci" or
10686 * "civic".
10687 */
10688 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
10689 if (cmd)
10690 cmd++;
10691
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010692 }
10693
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010694 if (cmd && os_strstr(cmd, "lci"))
10695 lci = 1;
10696
10697 if (cmd && os_strstr(cmd, "civic"))
10698 civic = 1;
10699
10700 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010701 wpas_ctrl_neighbor_rep_cb,
10702 wpa_s);
10703
10704 return ret;
10705}
10706
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010707#endif /* CONFIG_NO_RRM */
10708
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010709
10710static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
10711{
10712 eapol_sm_erp_flush(wpa_s->eapol);
10713 return 0;
10714}
10715
10716
10717static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
10718 char *cmd)
10719{
10720 char *token, *context = NULL;
10721 unsigned int enable = ~0, type = 0;
10722 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
10723 u8 *addr = NULL, *mask = NULL;
10724
10725 while ((token = str_token(cmd, " ", &context))) {
10726 if (os_strcasecmp(token, "scan") == 0) {
10727 type |= MAC_ADDR_RAND_SCAN;
10728 } else if (os_strcasecmp(token, "sched") == 0) {
10729 type |= MAC_ADDR_RAND_SCHED_SCAN;
10730 } else if (os_strcasecmp(token, "pno") == 0) {
10731 type |= MAC_ADDR_RAND_PNO;
10732 } else if (os_strcasecmp(token, "all") == 0) {
10733 type = wpa_s->mac_addr_rand_supported;
10734 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
10735 enable = atoi(token + 7);
10736 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
10737 addr = _addr;
10738 if (hwaddr_aton(token + 5, addr)) {
10739 wpa_printf(MSG_INFO,
10740 "CTRL: Invalid MAC address: %s",
10741 token);
10742 return -1;
10743 }
10744 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
10745 mask = _mask;
10746 if (hwaddr_aton(token + 5, mask)) {
10747 wpa_printf(MSG_INFO,
10748 "CTRL: Invalid MAC address mask: %s",
10749 token);
10750 return -1;
10751 }
10752 } else {
10753 wpa_printf(MSG_INFO,
10754 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
10755 token);
10756 return -1;
10757 }
10758 }
10759
10760 if (!type) {
10761 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
10762 return -1;
10763 }
10764
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010765 if (enable > 1) {
10766 wpa_printf(MSG_INFO,
10767 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
10768 return -1;
10769 }
10770
Hai Shalom81f62d82019-07-22 12:10:00 -070010771 if (!enable)
10772 return wpas_disable_mac_addr_randomization(wpa_s, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010773
Hai Shalom81f62d82019-07-22 12:10:00 -070010774 return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010775}
10776
10777
Dmitry Shmidte4663042016-04-04 10:07:49 -070010778static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
10779 char *buf, size_t buflen)
10780{
10781 size_t reply_len;
10782
10783 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
10784#ifdef CONFIG_AP
10785 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
10786 buflen - reply_len);
10787#endif /* CONFIG_AP */
10788 return reply_len;
10789}
10790
10791
10792static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
10793{
Hai Shalom60840252021-02-19 19:02:11 -080010794 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
Dmitry Shmidte4663042016-04-04 10:07:49 -070010795 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
10796#ifdef CONFIG_AP
10797 wpas_ap_pmksa_cache_flush(wpa_s);
10798#endif /* CONFIG_AP */
10799}
10800
10801
Dmitry Shmidt29333592017-01-09 12:27:11 -080010802#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10803
10804static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
10805 const char *cmd, char *buf, size_t buflen)
10806{
10807 struct rsn_pmksa_cache_entry *entry;
10808 struct wpa_ssid *ssid;
10809 char *pos, *pos2, *end;
10810 int ret;
10811 struct os_reltime now;
10812
10813 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10814 if (!ssid)
10815 return -1;
10816
10817 pos = buf;
10818 end = buf + buflen;
10819
10820 os_get_reltime(&now);
10821
10822 /*
10823 * Entry format:
10824 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10825 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010826 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010827 */
10828
10829 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
10830 entry = entry->next) {
10831 if (entry->network_ctx != ssid)
10832 continue;
10833
10834 pos2 = pos;
10835 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
10836 MAC2STR(entry->aa));
10837 if (os_snprintf_error(end - pos2, ret))
10838 break;
10839 pos2 += ret;
10840
10841 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
10842 PMKID_LEN);
10843
10844 ret = os_snprintf(pos2, end - pos2, " ");
10845 if (os_snprintf_error(end - pos2, ret))
10846 break;
10847 pos2 += ret;
10848
10849 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
10850 entry->pmk_len);
10851
10852 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
10853 (int) (entry->reauth_time - now.sec),
10854 (int) (entry->expiration - now.sec),
10855 entry->akmp,
10856 entry->opportunistic);
10857 if (os_snprintf_error(end - pos2, ret))
10858 break;
10859 pos2 += ret;
10860
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010861 if (entry->fils_cache_id_set) {
10862 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
10863 entry->fils_cache_id[0],
10864 entry->fils_cache_id[1]);
10865 if (os_snprintf_error(end - pos2, ret))
10866 break;
10867 pos2 += ret;
10868 }
10869
Dmitry Shmidt29333592017-01-09 12:27:11 -080010870 ret = os_snprintf(pos2, end - pos2, "\n");
10871 if (os_snprintf_error(end - pos2, ret))
10872 break;
10873 pos2 += ret;
10874
10875 pos = pos2;
10876 }
10877
10878 return pos - buf;
10879}
10880
10881
10882static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
10883 char *cmd)
10884{
10885 struct rsn_pmksa_cache_entry *entry;
10886 struct wpa_ssid *ssid;
10887 char *pos, *pos2;
10888 int ret = -1;
10889 struct os_reltime now;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010890 int reauth_time = 0, expiration = 0, i;
Dmitry Shmidt29333592017-01-09 12:27:11 -080010891
10892 /*
10893 * Entry format:
10894 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10895 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010896 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010897 */
10898
10899 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10900 if (!ssid)
10901 return -1;
10902
10903 pos = os_strchr(cmd, ' ');
10904 if (!pos)
10905 return -1;
10906 pos++;
10907
10908 entry = os_zalloc(sizeof(*entry));
10909 if (!entry)
10910 return -1;
10911
10912 if (hwaddr_aton(pos, entry->aa))
10913 goto fail;
10914
10915 pos = os_strchr(pos, ' ');
10916 if (!pos)
10917 goto fail;
10918 pos++;
10919
10920 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
10921 goto fail;
10922
10923 pos = os_strchr(pos, ' ');
10924 if (!pos)
10925 goto fail;
10926 pos++;
10927
10928 pos2 = os_strchr(pos, ' ');
10929 if (!pos2)
10930 goto fail;
10931 entry->pmk_len = (pos2 - pos) / 2;
10932 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
10933 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
10934 goto fail;
10935
10936 pos = os_strchr(pos, ' ');
10937 if (!pos)
10938 goto fail;
10939 pos++;
10940
10941 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
10942 &entry->akmp, &entry->opportunistic) != 4)
10943 goto fail;
Hai Shaloma20dcd72022-02-04 13:43:00 -080010944 if (reauth_time > expiration)
10945 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010946 for (i = 0; i < 4; i++) {
10947 pos = os_strchr(pos, ' ');
10948 if (!pos) {
10949 if (i < 3)
10950 goto fail;
10951 break;
10952 }
10953 pos++;
10954 }
10955 if (pos) {
10956 if (hexstr2bin(pos, entry->fils_cache_id,
10957 FILS_CACHE_ID_LEN) < 0)
10958 goto fail;
10959 entry->fils_cache_id_set = 1;
10960 }
Dmitry Shmidt29333592017-01-09 12:27:11 -080010961 os_get_reltime(&now);
10962 entry->expiration = now.sec + expiration;
10963 entry->reauth_time = now.sec + reauth_time;
10964
10965 entry->network_ctx = ssid;
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000010966 os_memcpy(entry->spa, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt29333592017-01-09 12:27:11 -080010967
Hai Shaloma20dcd72022-02-04 13:43:00 -080010968 entry->external = true;
10969
Dmitry Shmidt29333592017-01-09 12:27:11 -080010970 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
10971 entry = NULL;
10972 ret = 0;
10973fail:
10974 os_free(entry);
10975 return ret;
10976}
10977
Paul Stewart092955c2017-02-06 09:13:09 -080010978
10979#ifdef CONFIG_MESH
10980
10981static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
10982 const char *cmd, char *buf,
10983 size_t buflen)
10984{
10985 u8 spa[ETH_ALEN];
10986
10987 if (!wpa_s->ifmsh)
10988 return -1;
10989
10990 if (os_strcasecmp(cmd, "any") == 0)
10991 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
10992
10993 if (hwaddr_aton(cmd, spa))
10994 return -1;
10995
10996 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
10997}
10998
10999
11000static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
11001 char *cmd)
11002{
11003 /*
Hai Shalom60840252021-02-19 19:02:11 -080011004 * We do not check mesh interface existence because PMKSA should be
Paul Stewart092955c2017-02-06 09:13:09 -080011005 * stored before wpa_s->ifmsh creation to suppress commit message
11006 * creation.
11007 */
11008 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
11009}
11010
11011#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080011012#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
11013
11014
Paul Stewart092955c2017-02-06 09:13:09 -080011015#ifdef CONFIG_FILS
11016static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
11017 const char *cmd)
11018{
11019 struct fils_hlp_req *req;
11020 const char *pos;
11021
11022 /* format: <dst> <packet starting from ethertype> */
11023
11024 req = os_zalloc(sizeof(*req));
11025 if (!req)
11026 return -1;
11027
11028 if (hwaddr_aton(cmd, req->dst))
11029 goto fail;
11030
11031 pos = os_strchr(cmd, ' ');
11032 if (!pos)
11033 goto fail;
11034 pos++;
11035 req->pkt = wpabuf_parse_bin(pos);
11036 if (!req->pkt)
11037 goto fail;
11038
11039 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
11040 return 0;
11041fail:
11042 wpabuf_free(req->pkt);
11043 os_free(req);
11044 return -1;
11045}
11046#endif /* CONFIG_FILS */
11047
11048
Sunil Ravia04bd252022-05-02 22:54:18 -070011049int wpas_ctrl_cmd_debug_level(const char *cmd)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011050{
11051 if (os_strcmp(cmd, "PING") == 0 ||
11052 os_strncmp(cmd, "BSS ", 4) == 0 ||
11053 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
11054 os_strncmp(cmd, "STATUS", 6) == 0 ||
11055 os_strncmp(cmd, "STA ", 4) == 0 ||
11056 os_strncmp(cmd, "STA-", 4) == 0)
11057 return MSG_EXCESSIVE;
11058 return MSG_DEBUG;
11059}
11060
11061
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011062#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -070011063static int wpas_ctrl_iface_configure_mscs(struct wpa_supplicant *wpa_s,
11064 const char *cmd)
11065{
11066 size_t frame_classifier_len;
11067 const char *pos, *end;
11068 struct robust_av_data *robust_av = &wpa_s->robust_av;
11069 int val;
11070
11071 /*
11072 * format:
11073 * <add|remove|change> [up_bitmap=<hex byte>] [up_limit=<integer>]
11074 * [stream_timeout=<in TUs>] [frame_classifier=<hex bytes>]
11075 */
11076 os_memset(robust_av, 0, sizeof(struct robust_av_data));
11077 if (os_strncmp(cmd, "add ", 4) == 0) {
11078 robust_av->request_type = SCS_REQ_ADD;
11079 } else if (os_strcmp(cmd, "remove") == 0) {
11080 robust_av->request_type = SCS_REQ_REMOVE;
11081 robust_av->valid_config = false;
11082 return wpas_send_mscs_req(wpa_s);
11083 } else if (os_strncmp(cmd, "change ", 7) == 0) {
11084 robust_av->request_type = SCS_REQ_CHANGE;
11085 } else {
11086 return -1;
11087 }
11088
11089 pos = os_strstr(cmd, "up_bitmap=");
11090 if (!pos)
11091 return -1;
11092
11093 val = hex2byte(pos + 10);
11094 if (val < 0)
11095 return -1;
11096 robust_av->up_bitmap = val;
11097
11098 pos = os_strstr(cmd, "up_limit=");
11099 if (!pos)
11100 return -1;
11101
11102 robust_av->up_limit = atoi(pos + 9);
11103
11104 pos = os_strstr(cmd, "stream_timeout=");
11105 if (!pos)
11106 return -1;
11107
11108 robust_av->stream_timeout = atoi(pos + 15);
11109 if (robust_av->stream_timeout == 0)
11110 return -1;
11111
11112 pos = os_strstr(cmd, "frame_classifier=");
11113 if (!pos)
11114 return -1;
11115
11116 pos += 17;
11117 end = os_strchr(pos, ' ');
11118 if (!end)
11119 end = pos + os_strlen(pos);
11120
11121 frame_classifier_len = (end - pos) / 2;
11122 if (frame_classifier_len > sizeof(robust_av->frame_classifier) ||
11123 hexstr2bin(pos, robust_av->frame_classifier, frame_classifier_len))
11124 return -1;
11125
11126 robust_av->frame_classifier_len = frame_classifier_len;
11127 robust_av->valid_config = true;
11128
11129 return wpas_send_mscs_req(wpa_s);
11130}
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011131#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalom899fcc72020-10-19 14:38:18 -070011132
11133
Hai Shalom60840252021-02-19 19:02:11 -080011134#ifdef CONFIG_PASN
11135static int wpas_ctrl_iface_pasn_start(struct wpa_supplicant *wpa_s, char *cmd)
11136{
11137 char *token, *context = NULL;
11138 u8 bssid[ETH_ALEN];
11139 int akmp = -1, cipher = -1, got_bssid = 0;
11140 u16 group = 0xFFFF;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011141 u8 *comeback = NULL;
11142 size_t comeback_len = 0;
11143 int id = 0, ret = -1;
Hai Shalom60840252021-02-19 19:02:11 -080011144
11145 /*
11146 * Entry format: bssid=<BSSID> akmp=<AKMP> cipher=<CIPHER> group=<group>
Hai Shaloma20dcd72022-02-04 13:43:00 -080011147 * [comeback=<hexdump>]
Hai Shalom60840252021-02-19 19:02:11 -080011148 */
11149 while ((token = str_token(cmd, " ", &context))) {
11150 if (os_strncmp(token, "bssid=", 6) == 0) {
11151 if (hwaddr_aton(token + 6, bssid))
Hai Shaloma20dcd72022-02-04 13:43:00 -080011152 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080011153 got_bssid = 1;
11154 } else if (os_strcmp(token, "akmp=PASN") == 0) {
11155 akmp = WPA_KEY_MGMT_PASN;
11156#ifdef CONFIG_IEEE80211R
11157 } else if (os_strcmp(token, "akmp=FT-PSK") == 0) {
11158 akmp = WPA_KEY_MGMT_FT_PSK;
11159 } else if (os_strcmp(token, "akmp=FT-EAP-SHA384") == 0) {
11160 akmp = WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
11161 } else if (os_strcmp(token, "akmp=FT-EAP") == 0) {
11162 akmp = WPA_KEY_MGMT_FT_IEEE8021X;
11163#endif /* CONFIG_IEEE80211R */
11164#ifdef CONFIG_SAE
11165 } else if (os_strcmp(token, "akmp=SAE") == 0) {
11166 akmp = WPA_KEY_MGMT_SAE;
Sunil Ravi89eba102022-09-13 21:04:37 -070011167 } else if (os_strcmp(token, "akmp=SAE-EXT-KEY") == 0) {
11168 akmp = WPA_KEY_MGMT_SAE_EXT_KEY;
Hai Shalom60840252021-02-19 19:02:11 -080011169#endif /* CONFIG_SAE */
11170#ifdef CONFIG_FILS
11171 } else if (os_strcmp(token, "akmp=FILS-SHA256") == 0) {
11172 akmp = WPA_KEY_MGMT_FILS_SHA256;
11173 } else if (os_strcmp(token, "akmp=FILS-SHA384") == 0) {
11174 akmp = WPA_KEY_MGMT_FILS_SHA384;
11175#endif /* CONFIG_FILS */
11176 } else if (os_strcmp(token, "cipher=CCMP-256") == 0) {
11177 cipher = WPA_CIPHER_CCMP_256;
11178 } else if (os_strcmp(token, "cipher=GCMP-256") == 0) {
11179 cipher = WPA_CIPHER_GCMP_256;
11180 } else if (os_strcmp(token, "cipher=CCMP") == 0) {
11181 cipher = WPA_CIPHER_CCMP;
11182 } else if (os_strcmp(token, "cipher=GCMP") == 0) {
11183 cipher = WPA_CIPHER_GCMP;
11184 } else if (os_strncmp(token, "group=", 6) == 0) {
11185 group = atoi(token + 6);
11186 } else if (os_strncmp(token, "nid=", 4) == 0) {
11187 id = atoi(token + 4);
Hai Shaloma20dcd72022-02-04 13:43:00 -080011188 } else if (os_strncmp(token, "comeback=", 9) == 0) {
11189 comeback_len = os_strlen(token + 9);
11190 if (comeback || !comeback_len || comeback_len % 2)
11191 goto out;
11192
11193 comeback_len /= 2;
11194 comeback = os_malloc(comeback_len);
11195 if (!comeback ||
11196 hexstr2bin(token + 9, comeback, comeback_len))
11197 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080011198 } else {
11199 wpa_printf(MSG_DEBUG,
11200 "CTRL: PASN Invalid parameter: '%s'",
11201 token);
Hai Shaloma20dcd72022-02-04 13:43:00 -080011202 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080011203 }
11204 }
11205
11206 if (!got_bssid || akmp == -1 || cipher == -1 || group == 0xFFFF) {
11207 wpa_printf(MSG_DEBUG,"CTRL: PASN missing parameter");
Hai Shaloma20dcd72022-02-04 13:43:00 -080011208 goto out;
11209 }
11210
Sunil Ravi89eba102022-09-13 21:04:37 -070011211 ret = wpas_pasn_auth_start(wpa_s, wpa_s->own_addr, bssid, akmp, cipher,
11212 group, id, comeback, comeback_len);
Hai Shaloma20dcd72022-02-04 13:43:00 -080011213out:
11214 os_free(comeback);
11215 return ret;
11216}
11217
11218
11219static int wpas_ctrl_iface_pasn_deauthenticate(struct wpa_supplicant *wpa_s,
11220 const char *cmd)
11221{
11222 u8 bssid[ETH_ALEN];
11223
11224 if (os_strncmp(cmd, "bssid=", 6) != 0 || hwaddr_aton(cmd + 6, bssid)) {
11225 wpa_printf(MSG_DEBUG,
11226 "CTRL: PASN_DEAUTH without valid BSSID");
Hai Shalom60840252021-02-19 19:02:11 -080011227 return -1;
11228 }
11229
Sunil Ravi89eba102022-09-13 21:04:37 -070011230 return wpas_pasn_deauthenticate(wpa_s, wpa_s->own_addr, bssid);
Hai Shalom60840252021-02-19 19:02:11 -080011231}
Hai Shaloma20dcd72022-02-04 13:43:00 -080011232
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011233
11234#ifdef CONFIG_TESTING_OPTIONS
11235static int wpas_ctrl_iface_pasn_driver(struct wpa_supplicant *wpa_s,
11236 const char *cmd)
11237{
11238 union wpa_event_data event;
11239 const char *pos = cmd;
11240 u8 addr[ETH_ALEN];
11241
11242 os_memset(&event, 0, sizeof(event));
11243
11244 if (os_strncmp(pos, "auth ", 5) == 0)
11245 event.pasn_auth.action = PASN_ACTION_AUTH;
11246 else if (os_strncmp(pos, "del ", 4) == 0)
11247 event.pasn_auth.action =
11248 PASN_ACTION_DELETE_SECURE_RANGING_CONTEXT;
11249 else
11250 return -1;
11251
11252 pos = os_strchr(pos, ' ');
11253 if (!pos)
11254 return -1;
11255 pos++;
11256 while (hwaddr_aton(pos, addr) == 0) {
11257 struct pasn_peer *peer;
11258
11259 if (event.pasn_auth.num_peers == WPAS_MAX_PASN_PEERS)
11260 return -1;
11261 peer = &event.pasn_auth.peer[event.pasn_auth.num_peers];
11262 os_memcpy(peer->own_addr, wpa_s->own_addr, ETH_ALEN);
11263 os_memcpy(peer->peer_addr, addr, ETH_ALEN);
11264 event.pasn_auth.num_peers++;
11265
11266 pos = os_strchr(pos, ' ');
11267 if (!pos)
11268 break;
11269 pos++;
11270 }
11271
11272 wpa_supplicant_event(wpa_s, EVENT_PASN_AUTH, &event);
11273 return 0;
11274}
11275#endif /* CONFIG_TESTING_OPTIONS */
11276
Hai Shalom60840252021-02-19 19:02:11 -080011277#endif /* CONFIG_PASN */
11278
11279
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011280#ifndef CONFIG_NO_ROBUST_AV
11281
Hai Shaloma20dcd72022-02-04 13:43:00 -080011282static int set_type4_frame_classifier(const char *cmd,
11283 struct type4_params *param)
11284{
11285 const char *pos, *end;
11286 u8 classifier_mask = 0;
11287 int ret;
11288 char addr[INET6_ADDRSTRLEN];
11289 size_t alen;
11290
11291 if (os_strstr(cmd, "ip_version=ipv4")) {
11292 param->ip_version = IPV4;
11293 } else if (os_strstr(cmd, "ip_version=ipv6")) {
11294 param->ip_version = IPV6;
11295 } else {
11296 wpa_printf(MSG_ERROR, "IP version missing/invalid");
11297 return -1;
11298 }
11299
11300 classifier_mask |= BIT(0);
11301
11302 pos = os_strstr(cmd, "src_ip=");
11303 if (pos) {
11304 pos += 7;
11305 end = os_strchr(pos, ' ');
11306 if (!end)
11307 end = pos + os_strlen(pos);
11308
11309 alen = end - pos;
11310 if (alen >= INET6_ADDRSTRLEN)
11311 return -1;
11312 os_memcpy(addr, pos, alen);
11313 addr[alen] = '\0';
11314 if (param->ip_version == IPV4)
11315 ret = inet_pton(AF_INET, addr,
11316 &param->ip_params.v4.src_ip);
11317 else
11318 ret = inet_pton(AF_INET6, addr,
11319 &param->ip_params.v6.src_ip);
11320
11321 if (ret != 1) {
11322 wpa_printf(MSG_ERROR,
11323 "Error converting src IP address to binary ret=%d",
11324 ret);
11325 return -1;
11326 }
11327
11328 classifier_mask |= BIT(1);
11329 }
11330
11331 pos = os_strstr(cmd, "dst_ip=");
11332 if (pos) {
11333 pos += 7;
11334 end = os_strchr(pos, ' ');
11335 if (!end)
11336 end = pos + os_strlen(pos);
11337
11338 alen = end - pos;
11339 if (alen >= INET6_ADDRSTRLEN)
11340 return -1;
11341 os_memcpy(addr, pos, alen);
11342 addr[alen] = '\0';
11343 if (param->ip_version == IPV4)
11344 ret = inet_pton(AF_INET, addr,
11345 &param->ip_params.v4.dst_ip);
11346 else
11347 ret = inet_pton(AF_INET6, addr,
11348 &param->ip_params.v6.dst_ip);
11349
11350 if (ret != 1) {
11351 wpa_printf(MSG_ERROR,
11352 "Error converting dst IP address to binary ret=%d",
11353 ret);
11354 return -1;
11355 }
11356
11357 classifier_mask |= BIT(2);
11358 }
11359
11360 pos = os_strstr(cmd, "src_port=");
11361 if (pos && atoi(pos + 9) > 0) {
11362 if (param->ip_version == IPV4)
11363 param->ip_params.v4.src_port = atoi(pos + 9);
11364 else
11365 param->ip_params.v6.src_port = atoi(pos + 9);
11366 classifier_mask |= BIT(3);
11367 }
11368
11369 pos = os_strstr(cmd, "dst_port=");
11370 if (pos && atoi(pos + 9) > 0) {
11371 if (param->ip_version == IPV4)
11372 param->ip_params.v4.dst_port = atoi(pos + 9);
11373 else
11374 param->ip_params.v6.dst_port = atoi(pos + 9);
11375 classifier_mask |= BIT(4);
11376 }
11377
11378 pos = os_strstr(cmd, "dscp=");
11379 if (pos && atoi(pos + 5) > 0) {
11380 if (param->ip_version == IPV4)
11381 param->ip_params.v4.dscp = atoi(pos + 5);
11382 else
11383 param->ip_params.v6.dscp = atoi(pos + 5);
11384 classifier_mask |= BIT(5);
11385 }
11386
11387 if (param->ip_version == IPV4) {
11388 pos = os_strstr(cmd, "protocol=");
11389 if (pos) {
11390 if (os_strstr(pos, "udp")) {
11391 param->ip_params.v4.protocol = 17;
11392 } else if (os_strstr(pos, "tcp")) {
11393 param->ip_params.v4.protocol = 6;
11394 } else if (os_strstr(pos, "esp")) {
11395 param->ip_params.v4.protocol = 50;
11396 } else {
11397 wpa_printf(MSG_ERROR, "Invalid protocol");
11398 return -1;
11399 }
11400 classifier_mask |= BIT(6);
11401 }
11402 } else {
11403 pos = os_strstr(cmd, "next_header=");
11404 if (pos) {
11405 if (os_strstr(pos, "udp")) {
11406 param->ip_params.v6.next_header = 17;
11407 } else if (os_strstr(pos, "tcp")) {
11408 param->ip_params.v6.next_header = 6;
11409 } else if (os_strstr(pos, "esp")) {
11410 param->ip_params.v6.next_header = 50;
11411 } else {
11412 wpa_printf(MSG_ERROR, "Invalid next header");
11413 return -1;
11414 }
11415
11416 classifier_mask |= BIT(6);
11417 }
11418
11419 pos = os_strstr(cmd, "flow_label=");
11420 if (pos) {
11421 pos += 11;
11422 end = os_strchr(pos, ' ');
11423 if (!end)
11424 end = pos + os_strlen(pos);
11425
11426 if (end - pos != 6 ||
11427 hexstr2bin(pos, param->ip_params.v6.flow_label,
11428 3) ||
11429 param->ip_params.v6.flow_label[0] > 0x0F) {
11430 wpa_printf(MSG_ERROR, "Invalid flow label");
11431 return -1;
11432 }
11433
11434 classifier_mask |= BIT(7);
11435 }
11436 }
11437
11438 param->classifier_mask = classifier_mask;
11439 return 0;
11440}
11441
11442
11443static int set_type10_frame_classifier(const char *cmd,
11444 struct type10_params *param)
11445{
11446 const char *pos, *end;
11447 size_t filter_len;
11448
11449 pos = os_strstr(cmd, "prot_instance=");
11450 if (!pos) {
11451 wpa_printf(MSG_ERROR, "Protocol instance missing");
11452 return -1;
11453 }
11454 param->prot_instance = atoi(pos + 14);
11455
11456 pos = os_strstr(cmd, "prot_number=");
11457 if (!pos) {
11458 wpa_printf(MSG_ERROR, "Protocol number missing");
11459 return -1;
11460 }
11461 if (os_strstr(pos, "udp")) {
11462 param->prot_number = 17;
11463 } else if (os_strstr(pos, "tcp")) {
11464 param->prot_number = 6;
11465 } else if (os_strstr(pos, "esp")) {
11466 param->prot_number = 50;
11467 } else {
11468 wpa_printf(MSG_ERROR, "Invalid protocol number");
11469 return -1;
11470 }
11471
11472 pos = os_strstr(cmd, "filter_value=");
11473 if (!pos) {
11474 wpa_printf(MSG_ERROR,
11475 "Classifier parameter filter_value missing");
11476 return -1;
11477 }
11478
11479 pos += 13;
11480 end = os_strchr(pos, ' ');
11481 if (!end)
11482 end = pos + os_strlen(pos);
11483
11484 filter_len = (end - pos) / 2;
11485 param->filter_value = os_malloc(filter_len);
11486 if (!param->filter_value)
11487 return -1;
11488
11489 if (hexstr2bin(pos, param->filter_value, filter_len)) {
11490 wpa_printf(MSG_ERROR, "Invalid filter_value %s", pos);
11491 goto free;
11492 }
11493
11494 pos = os_strstr(cmd, "filter_mask=");
11495 if (!pos) {
11496 wpa_printf(MSG_ERROR,
11497 "Classifier parameter filter_mask missing");
11498 goto free;
11499 }
11500
11501 pos += 12;
11502 end = os_strchr(pos, ' ');
11503 if (!end)
11504 end = pos + os_strlen(pos);
11505
11506 if (filter_len != (size_t) (end - pos) / 2) {
11507 wpa_printf(MSG_ERROR,
11508 "Filter mask length mismatch expected=%zu received=%zu",
11509 filter_len, (size_t) (end - pos) / 2);
11510 goto free;
11511 }
11512
11513 param->filter_mask = os_malloc(filter_len);
11514 if (!param->filter_mask)
11515 goto free;
11516
11517 if (hexstr2bin(pos, param->filter_mask, filter_len)) {
11518 wpa_printf(MSG_ERROR, "Invalid filter mask %s", pos);
11519 os_free(param->filter_mask);
11520 param->filter_mask = NULL;
11521 goto free;
11522 }
11523
11524 param->filter_len = filter_len;
11525 return 0;
11526free:
11527 os_free(param->filter_value);
11528 param->filter_value = NULL;
11529 return -1;
11530}
11531
11532
11533static int scs_parse_type4(struct tclas_element *elem, const char *pos)
11534{
11535 struct type4_params type4_param = { 0 };
11536
11537 if (set_type4_frame_classifier(pos, &type4_param) == -1) {
11538 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 4");
11539 return -1;
11540 }
11541
11542 os_memcpy(&elem->frame_classifier.type4_param,
11543 &type4_param, sizeof(struct type4_params));
11544 return 0;
11545}
11546
11547
11548static int scs_parse_type10(struct tclas_element *elem, const char *pos)
11549{
11550 struct type10_params type10_param = { 0 };
11551
11552 if (set_type10_frame_classifier(pos, &type10_param) == -1) {
11553 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 10");
11554 return -1;
11555 }
11556
11557 os_memcpy(&elem->frame_classifier.type10_param,
11558 &type10_param, sizeof(struct type10_params));
11559 return 0;
11560}
11561
11562
11563static int wpas_ctrl_iface_configure_scs(struct wpa_supplicant *wpa_s,
11564 char *cmd)
11565{
11566 char *pos1, *pos;
11567 struct scs_robust_av_data *scs_data = &wpa_s->scs_robust_av_req;
11568 struct scs_desc_elem desc_elem = { 0 };
11569 int val;
11570 unsigned int num_scs_desc = 0;
11571
11572 if (wpa_s->ongoing_scs_req) {
11573 wpa_printf(MSG_ERROR, "%s: SCS Request already in queue",
11574 __func__);
11575 return -1;
11576 }
11577
11578 /**
11579 * format:
11580 * [scs_id=<decimal number>] <add|remove|change> [scs_up=<0-7>]
11581 * [classifier_type=<4|10>]
11582 * [classifier params based on classifier type]
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011583 * [tclas_processing=<0|1>]
11584 * [qos_characteristics] <up/down/direct> [min_si=<decimal number>]
11585 * [max_si=<decimal number>] [min_data_rate=<decimal number>]
11586 * [delay_bound=<decimal number>] [max_msdu=<decimal number>]
11587 * [service_start_time=<decimal number>]
11588 * [service_start_time_link_id=<decimal number>]
11589 * [mean_data_rate=<decimal number>] [burst_size=<decimal number>]
11590 * [msdu_lifetime=<decimal number>]
11591 * [msdu_delivery_info=<decimal number>] [medium_time=<decimal number>]
11592 * [scs_id=<decimal number>] ...
Hai Shaloma20dcd72022-02-04 13:43:00 -080011593 */
11594 pos1 = os_strstr(cmd, "scs_id=");
11595 if (!pos1) {
11596 wpa_printf(MSG_ERROR, "SCSID not present");
11597 return -1;
11598 }
11599
11600 free_up_scs_desc(scs_data);
11601
11602 while (pos1) {
11603 struct scs_desc_elem *n1;
11604 struct active_scs_elem *active_scs_desc;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011605 char *next_scs_desc, *pos2;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011606 unsigned int num_tclas_elem = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011607 bool scsid_active = false, tclas_present = false;
11608 struct qos_characteristics *qos_elem = &desc_elem.qos_char_elem;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011609
11610 desc_elem.scs_id = atoi(pos1 + 7);
11611 pos1 += 7;
11612
11613 next_scs_desc = os_strstr(pos1, "scs_id=");
11614 if (next_scs_desc) {
11615 char temp[20];
11616
11617 os_snprintf(temp, sizeof(temp), "scs_id=%d ",
11618 desc_elem.scs_id);
11619 if (os_strstr(next_scs_desc, temp)) {
11620 wpa_printf(MSG_ERROR,
11621 "Multiple SCS descriptors configured with same SCSID(=%d)",
11622 desc_elem.scs_id);
11623 goto free_scs_desc;
11624 }
11625 pos1[next_scs_desc - pos1 - 1] = '\0';
11626 }
11627
11628 dl_list_for_each(active_scs_desc, &wpa_s->active_scs_ids,
11629 struct active_scs_elem, list) {
11630 if (desc_elem.scs_id == active_scs_desc->scs_id) {
11631 scsid_active = true;
11632 break;
11633 }
11634 }
11635
11636 if (os_strstr(pos1, "add ")) {
11637 desc_elem.request_type = SCS_REQ_ADD;
11638 if (scsid_active) {
11639 wpa_printf(MSG_ERROR, "SCSID %d already active",
11640 desc_elem.scs_id);
11641 return -1;
11642 }
11643 } else if (os_strstr(pos1, "remove")) {
11644 desc_elem.request_type = SCS_REQ_REMOVE;
11645 if (!scsid_active) {
11646 wpa_printf(MSG_ERROR, "SCSID %d not active",
11647 desc_elem.scs_id);
11648 return -1;
11649 }
11650 goto scs_desc_end;
11651 } else if (os_strstr(pos1, "change ")) {
11652 desc_elem.request_type = SCS_REQ_CHANGE;
11653 if (!scsid_active) {
11654 wpa_printf(MSG_ERROR, "SCSID %d not active",
11655 desc_elem.scs_id);
11656 return -1;
11657 }
11658 } else {
11659 wpa_printf(MSG_ERROR, "SCS Request type invalid");
11660 goto free_scs_desc;
11661 }
11662
11663 pos1 = os_strstr(pos1, "scs_up=");
11664 if (!pos1) {
11665 wpa_printf(MSG_ERROR,
11666 "Intra-Access user priority not present");
11667 goto free_scs_desc;
11668 }
11669
11670 val = atoi(pos1 + 7);
11671 if (val < 0 || val > 7) {
11672 wpa_printf(MSG_ERROR,
11673 "Intra-Access user priority invalid %d",
11674 val);
11675 goto free_scs_desc;
11676 }
11677
11678 desc_elem.intra_access_priority = val;
11679 desc_elem.scs_up_avail = true;
11680
11681 pos = os_strstr(pos1, "classifier_type=");
11682 if (!pos) {
11683 wpa_printf(MSG_ERROR, "classifier type empty");
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011684 goto qos_characteristics;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011685 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011686 tclas_present = true;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011687
11688 while (pos) {
11689 struct tclas_element elem = { 0 }, *n;
11690 char *next_tclas_elem;
11691
11692 val = atoi(pos + 16);
11693 if (val != 4 && val != 10) {
11694 wpa_printf(MSG_ERROR,
11695 "classifier type invalid %d", val);
11696 goto free_scs_desc;
11697 }
11698
11699 elem.classifier_type = val;
11700 pos += 16;
11701
11702 next_tclas_elem = os_strstr(pos, "classifier_type=");
11703 if (next_tclas_elem) {
11704 pos1 = next_tclas_elem;
11705 pos[next_tclas_elem - pos - 1] = '\0';
11706 }
11707
11708 switch (val) {
11709 case 4:
11710 if (scs_parse_type4(&elem, pos) < 0)
11711 goto free_scs_desc;
11712 break;
11713 case 10:
11714 if (scs_parse_type10(&elem, pos) < 0)
11715 goto free_scs_desc;
11716 break;
11717 }
11718
11719 n = os_realloc(desc_elem.tclas_elems,
11720 (num_tclas_elem + 1) * sizeof(elem));
11721 if (!n)
11722 goto free_scs_desc;
11723
11724 desc_elem.tclas_elems = n;
11725 os_memcpy((u8 *) desc_elem.tclas_elems +
11726 num_tclas_elem * sizeof(elem),
11727 &elem, sizeof(elem));
11728 num_tclas_elem++;
11729 desc_elem.num_tclas_elem = num_tclas_elem;
11730 pos = next_tclas_elem;
11731 }
11732
11733 if (desc_elem.num_tclas_elem > 1) {
11734 pos1 = os_strstr(pos1, "tclas_processing=");
11735 if (!pos1) {
11736 wpa_printf(MSG_ERROR, "tclas_processing empty");
11737 goto free_scs_desc;
11738 }
11739
11740 val = atoi(pos1 + 17);
11741 if (val != 0 && val != 1) {
11742 wpa_printf(MSG_ERROR,
11743 "tclas_processing invalid");
11744 goto free_scs_desc;
11745 }
11746
11747 desc_elem.tclas_processing = val;
11748 }
11749
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011750 qos_characteristics:
11751 pos1 = os_strstr(pos1, "qos_characteristics");
11752 if (!pos1 && !tclas_present)
11753 goto free_scs_desc;
11754 if (!pos1)
11755 goto scs_desc_end;
11756
11757 qos_elem->available = true;
11758 if (os_strstr(pos1, "up ")) {
11759 qos_elem->direction = SCS_DIRECTION_UP;
11760 if (tclas_present) {
11761 wpa_printf(MSG_ERROR,
11762 "TCLAS with direction:UP not allowed");
11763 goto free_scs_desc;
11764 }
11765 } else if (os_strstr(pos1, "down ")) {
11766 qos_elem->direction = SCS_DIRECTION_DOWN;
11767 } else if (os_strstr(pos1, "direct ")) {
11768 qos_elem->direction = SCS_DIRECTION_DIRECT;
11769 }
11770
11771 pos1 = os_strstr(pos1, "min_si=");
11772 if (!pos1) {
11773 wpa_printf(MSG_ERROR, "Min SI is required");
11774 goto free_scs_desc;
11775 }
11776 qos_elem->min_si = atoi(pos1 + 7);
11777
11778 pos1 = os_strstr(pos1, "max_si=");
11779 if (!pos1) {
11780 wpa_printf(MSG_ERROR, "Max SI is required");
11781 goto free_scs_desc;
11782 }
11783 qos_elem->max_si = atoi(pos1 + 7);
11784
11785 if (qos_elem->min_si && qos_elem->max_si &&
11786 qos_elem->max_si < qos_elem->min_si) {
11787 wpa_printf(MSG_ERROR, "Invalid Max SI");
11788 goto free_scs_desc;
11789 }
11790
11791 pos1 = os_strstr(pos1, "min_data_rate=");
11792 if (!pos1) {
11793 wpa_printf(MSG_ERROR, "Min data rate is required");
11794 goto free_scs_desc;
11795 }
11796 qos_elem->min_data_rate = atoi(pos1 + 14);
11797
11798 pos1 = os_strstr(pos1, "delay_bound=");
11799 if (!pos1) {
11800 wpa_printf(MSG_ERROR, "Delay Bound is required");
11801 goto free_scs_desc;
11802 }
11803 qos_elem->delay_bound = atoi(pos1 + 12);
11804
11805 if (qos_elem->min_data_rate >= BIT(24) ||
11806 qos_elem->delay_bound >= BIT(24)) {
11807 wpa_printf(MSG_ERROR,
11808 "Invalid min_data_rate or delay_bound");
11809 goto free_scs_desc;
11810 }
11811
11812 pos2 = os_strstr(pos1, "max_msdu=");
11813 if (pos2) {
11814 qos_elem->max_msdu_size = atoi(pos2 + 9);
11815 qos_elem->mask |= SCS_QOS_BIT_MAX_MSDU_SIZE;
11816 }
11817
11818 pos2 = os_strstr(pos1, "service_start_time=");
11819 if (pos2) {
11820 qos_elem->service_start_time = atoi(pos2 + 19);
11821 qos_elem->mask |= SCS_QOS_BIT_SERVICE_START_TIME;
11822 }
11823
11824 pos2 = os_strstr(pos1, "service_start_time_link_id=");
11825 if (pos2) {
11826 qos_elem->service_start_time_link_id = atoi(pos2 + 27);
11827 qos_elem->mask |= SCS_QOS_BIT_SERVICE_START_TIME_LINKID;
11828 }
11829
11830 pos2 = os_strstr(pos1, "mean_data_rate=");
11831 if (pos2) {
11832 qos_elem->mean_data_rate = atoi(pos2 + 15);
11833 qos_elem->mask |= SCS_QOS_BIT_MEAN_DATA_RATE;
11834 }
11835
11836 pos2 = os_strstr(pos1, "burst_size=");
11837 if (pos2) {
11838 qos_elem->burst_size = atoi(pos2 + 11);
11839 qos_elem->mask |=
11840 SCS_QOS_BIT_DELAYED_BOUNDED_BURST_SIZE;
11841 }
11842
11843 pos2 = os_strstr(pos1, "msdu_lifetime=");
11844 if (pos2) {
11845 qos_elem->msdu_lifetime = atoi(pos2 + 14);
11846 qos_elem->mask |= SCS_QOS_BIT_MSDU_LIFETIME;
11847 }
11848
11849 pos2 = os_strstr(pos1, "msdu_delivery_info=");
11850 if (pos2) {
11851 qos_elem->msdu_delivery_info = atoi(pos2 + 19);
11852 qos_elem->mask |= SCS_QOS_BIT_MSDU_DELIVERY_INFO;
11853 }
11854
11855 pos2 = os_strstr(pos1, "medium_time=");
11856 if (pos2) {
11857 qos_elem->medium_time = atoi(pos2 + 12);
11858 qos_elem->mask |= SCS_QOS_BIT_MEDIUM_TIME;
11859 }
11860
Hai Shaloma20dcd72022-02-04 13:43:00 -080011861scs_desc_end:
11862 n1 = os_realloc(scs_data->scs_desc_elems, (num_scs_desc + 1) *
11863 sizeof(struct scs_desc_elem));
11864 if (!n1)
11865 goto free_scs_desc;
11866
11867 scs_data->scs_desc_elems = n1;
11868 os_memcpy((u8 *) scs_data->scs_desc_elems + num_scs_desc *
11869 sizeof(desc_elem), &desc_elem, sizeof(desc_elem));
11870 num_scs_desc++;
11871 scs_data->num_scs_desc = num_scs_desc;
11872 pos1 = next_scs_desc;
11873 os_memset(&desc_elem, 0, sizeof(desc_elem));
11874 }
11875
11876 return wpas_send_scs_req(wpa_s);
11877
11878free_scs_desc:
11879 free_up_tclas_elem(&desc_elem);
11880 free_up_scs_desc(scs_data);
11881 return -1;
11882}
11883
11884
11885static int wpas_ctrl_iface_send_dscp_resp(struct wpa_supplicant *wpa_s,
11886 const char *cmd)
11887{
11888 char *pos;
11889 struct dscp_policy_status *policy = NULL, *n;
11890 int num_policies = 0, ret = -1;
11891 struct dscp_resp_data resp_data;
11892
11893 /*
11894 * format:
11895 * <[reset]>/<[solicited] [policy_id=1 status=0...]> [more]
11896 */
11897
11898 os_memset(&resp_data, 0, sizeof(resp_data));
11899
11900 resp_data.more = os_strstr(cmd, "more") != NULL;
11901
11902 if (os_strstr(cmd, "reset")) {
11903 resp_data.reset = true;
11904 resp_data.solicited = false;
11905 goto send_resp;
11906 }
11907
11908 resp_data.solicited = os_strstr(cmd, "solicited") != NULL;
11909
11910 pos = os_strstr(cmd, "policy_id=");
11911 while (pos) {
11912 n = os_realloc(policy, (num_policies + 1) * sizeof(*policy));
11913 if (!n)
11914 goto fail;
11915
11916 policy = n;
11917 pos += 10;
11918 policy[num_policies].id = atoi(pos);
11919 if (policy[num_policies].id == 0) {
11920 wpa_printf(MSG_ERROR, "DSCP: Invalid policy id");
11921 goto fail;
11922 }
11923
11924 pos = os_strstr(pos, "status=");
11925 if (!pos) {
11926 wpa_printf(MSG_ERROR,
11927 "DSCP: Status is not found for a policy");
11928 goto fail;
11929 }
11930
11931 pos += 7;
11932 policy[num_policies].status = atoi(pos);
11933 num_policies++;
11934
11935 pos = os_strstr(pos, "policy_id");
11936 }
11937
11938 resp_data.policy = policy;
11939 resp_data.num_policies = num_policies;
11940send_resp:
11941 ret = wpas_send_dscp_response(wpa_s, &resp_data);
11942 if (ret)
11943 wpa_printf(MSG_ERROR, "DSCP: Failed to send DSCP response");
11944fail:
11945 os_free(policy);
11946 return ret;
11947}
11948
11949
11950static int wpas_ctrl_iface_send_dscp_query(struct wpa_supplicant *wpa_s,
11951 const char *cmd)
11952{
11953 char *pos;
11954
11955 /*
11956 * format:
11957 * Wildcard DSCP query
11958 * <wildcard>
11959 *
11960 * DSCP query with a domain name attribute:
11961 * [domain_name=<string>]
11962 */
11963
11964 if (os_strstr(cmd, "wildcard")) {
11965 wpa_printf(MSG_DEBUG, "QM: Send wildcard DSCP policy query");
11966 return wpas_send_dscp_query(wpa_s, NULL, 0);
11967 }
11968
11969 pos = os_strstr(cmd, "domain_name=");
11970 if (!pos || !os_strlen(pos + 12)) {
11971 wpa_printf(MSG_ERROR, "QM: Domain name not preset");
11972 return -1;
11973 }
11974
11975 return wpas_send_dscp_query(wpa_s, pos + 12, os_strlen(pos + 12));
11976}
11977
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011978#endif /* CONFIG_NO_ROBUST_AV */
11979
Hai Shaloma20dcd72022-02-04 13:43:00 -080011980
Sunil Ravi89eba102022-09-13 21:04:37 -070011981static int wpas_ctrl_iface_mlo_signal_poll(struct wpa_supplicant *wpa_s,
11982 char *buf, size_t buflen)
11983{
11984 int ret, i;
11985 char *pos, *end;
11986 struct wpa_mlo_signal_info mlo_si;
11987
11988 if (!wpa_s->valid_links)
11989 return -1;
11990
11991 ret = wpa_drv_mlo_signal_poll(wpa_s, &mlo_si);
11992 if (ret)
11993 return -1;
11994
11995 pos = buf;
11996 end = buf + buflen;
11997
Sunil Ravi88611412024-06-28 17:34:56 +000011998 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
11999 if (!(mlo_si.valid_links & BIT(i)))
12000 continue;
12001
Sunil Ravi89eba102022-09-13 21:04:37 -070012002 ret = os_snprintf(pos, end - pos,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000012003 "LINK_ID=%d\nRSSI=%d\nLINKSPEED=%lu\n"
Sunil Ravi89eba102022-09-13 21:04:37 -070012004 "NOISE=%d\nFREQUENCY=%u\n",
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000012005 i, mlo_si.links[i].data.signal,
12006 mlo_si.links[i].data.current_tx_rate / 1000,
Sunil Ravi89eba102022-09-13 21:04:37 -070012007 mlo_si.links[i].current_noise,
12008 mlo_si.links[i].frequency);
12009 if (os_snprintf_error(end - pos, ret))
12010 return -1;
12011 pos += ret;
12012
12013 if (mlo_si.links[i].chanwidth != CHAN_WIDTH_UNKNOWN) {
12014 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
12015 channel_width_to_string(
12016 mlo_si.links[i].chanwidth));
12017 if (os_snprintf_error(end - pos, ret))
12018 return -1;
12019 pos += ret;
12020 }
12021
12022 if (mlo_si.links[i].center_frq1 > 0) {
12023 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
12024 mlo_si.links[i].center_frq1);
12025 if (os_snprintf_error(end - pos, ret))
12026 return -1;
12027 pos += ret;
12028 }
12029
12030 if (mlo_si.links[i].center_frq2 > 0) {
12031 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
12032 mlo_si.links[i].center_frq2);
12033 if (os_snprintf_error(end - pos, ret))
12034 return -1;
12035 pos += ret;
12036 }
12037
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000012038 if (mlo_si.links[i].data.avg_signal) {
Sunil Ravi89eba102022-09-13 21:04:37 -070012039 ret = os_snprintf(pos, end - pos,
12040 "AVG_RSSI=%d\n",
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000012041 mlo_si.links[i].data.avg_signal);
Sunil Ravi89eba102022-09-13 21:04:37 -070012042 if (os_snprintf_error(end - pos, ret))
12043 return -1;
12044 pos += ret;
12045 }
12046
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000012047 if (mlo_si.links[i].data.avg_beacon_signal) {
12048 ret = os_snprintf(
12049 pos, end - pos, "AVG_BEACON_RSSI=%d\n",
12050 mlo_si.links[i].data.avg_beacon_signal);
Sunil Ravi89eba102022-09-13 21:04:37 -070012051 if (os_snprintf_error(end - pos, ret))
12052 return -1;
12053 pos += ret;
12054 }
12055 }
12056
12057 return pos - buf;
12058}
12059
12060
12061static int wpas_ctrl_iface_mlo_status(struct wpa_supplicant *wpa_s,
12062 char *buf, size_t buflen)
12063{
12064 int ret, i;
12065 char *pos, *end;
12066
12067 if (!wpa_s->valid_links)
12068 return -1;
12069
12070 pos = buf;
12071 end = buf + buflen;
12072
Sunil Ravi88611412024-06-28 17:34:56 +000012073 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
12074 if (!(wpa_s->valid_links & BIT(i)))
12075 continue;
12076
Sunil Ravi89eba102022-09-13 21:04:37 -070012077 ret = os_snprintf(pos, end - pos, "link_id=%d\nfreq=%u\n"
12078 "ap_link_addr=" MACSTR
12079 "\nsta_link_addr=" MACSTR "\n",
12080 i, wpa_s->links[i].freq,
12081 MAC2STR(wpa_s->links[i].bssid),
12082 MAC2STR(wpa_s->links[i].addr));
12083 if (os_snprintf_error(end - pos, ret))
12084 return pos - buf;
12085 pos += ret;
12086 }
12087
12088 return pos - buf;
12089}
12090
12091
Sunil Ravi2a14cf12023-11-21 00:54:38 +000012092#ifdef CONFIG_TESTING_OPTIONS
12093static int wpas_ctrl_ml_probe(struct wpa_supplicant *wpa_s, char *cmd)
12094{
12095 char *token, *context = NULL;
12096 u8 bssid[ETH_ALEN];
12097 int mld_id = -1, link_id = -1;
12098 struct wpa_bss *bss;
12099 int *freqs;
12100
12101 os_memset(bssid, 0, sizeof(bssid));
12102
12103 while ((token = str_token(cmd, " ", &context))) {
12104 if (os_strncmp(token, "bssid=", 6) == 0) {
12105 if (hwaddr_aton(token + 6, bssid))
12106 return -1;
12107 } else if (os_strncmp(token, "mld_id=", 7) == 0) {
12108 mld_id = atoi(token + 7);
12109 } else if (os_strncmp(token, "link_id=", 8) == 0) {
12110 link_id = atoi(token + 8);
12111 }
12112 }
12113
12114 if (mld_id < 0 || is_zero_ether_addr(bssid)) {
12115 wpa_printf(MSG_DEBUG,
12116 "MLD: Failed parsing ML probe request arguments");
12117 return -1;
12118 }
12119
12120 bss = wpa_bss_get_bssid(wpa_s, bssid);
12121 if (!bss) {
12122 wpa_printf(MSG_DEBUG,
12123 "MLD: Unknown BSS for " MACSTR, MAC2STR(bssid));
12124 return -1;
12125 }
12126
12127 if (wpa_s->sched_scanning || wpa_s->scanning ||
12128 (wpa_s->wpa_state > WPA_SCANNING &&
12129 wpa_s->wpa_state != WPA_COMPLETED)) {
12130 wpa_printf(MSG_DEBUG,
12131 "MLO: Ongoing scan: Reject ML probe request");
12132 return -1;
12133 }
12134
12135 freqs = os_malloc(sizeof(int) * 2);
12136 if (!freqs)
12137 return -1;
12138
12139 freqs[0] = bss->freq;
12140 freqs[1] = 0;
12141
12142 wpa_s->manual_scan_passive = 0;
12143 wpa_s->manual_scan_use_id = 0;
12144 wpa_s->manual_scan_only_new = 0;
12145 wpa_s->scan_id_count = 0;
12146 wpa_s->scan_res_handler = scan_only_handler;
12147 os_free(wpa_s->manual_scan_freqs);
12148 wpa_s->manual_scan_freqs = freqs;
12149
12150 os_memcpy(wpa_s->ml_probe_bssid, bssid, ETH_ALEN);
12151 wpa_s->ml_probe_mld_id = mld_id;
12152 if (link_id >= 0)
12153 wpa_s->ml_probe_links = BIT(link_id);
12154
12155 wpa_s->normal_scans = 0;
12156 wpa_s->scan_req = MANUAL_SCAN_REQ;
12157 wpa_s->after_wps = 0;
12158 wpa_s->known_wps_freq = 0;
12159 wpa_supplicant_req_scan(wpa_s, 0, 0);
12160
12161 return 0;
12162}
12163#endif /* CONFIG_TESTING_OPTIONS */
12164
12165
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012166#ifdef CONFIG_NAN_USD
12167
12168static int wpas_ctrl_nan_publish(struct wpa_supplicant *wpa_s, char *cmd,
12169 char *buf, size_t buflen)
12170{
12171 char *token, *context = NULL;
12172 int publish_id;
12173 struct nan_publish_params params;
12174 const char *service_name = NULL;
12175 struct wpabuf *ssi = NULL;
12176 int ret = -1;
12177 enum nan_service_protocol_type srv_proto_type = 0;
12178 int *freq_list = NULL;
12179
12180 os_memset(&params, 0, sizeof(params));
12181 /* USD shall use both solicited and unsolicited transmissions */
12182 params.unsolicited = true;
12183 params.solicited = true;
12184 /* USD shall require FSD without GAS */
12185 params.fsd = true;
12186 params.freq = NAN_USD_DEFAULT_FREQ;
12187
12188 while ((token = str_token(cmd, " ", &context))) {
12189 if (os_strncmp(token, "service_name=", 13) == 0) {
12190 service_name = token + 13;
12191 continue;
12192 }
12193
12194 if (os_strncmp(token, "ttl=", 4) == 0) {
12195 params.ttl = atoi(token + 4);
12196 continue;
12197 }
12198
12199 if (os_strncmp(token, "freq=", 5) == 0) {
12200 params.freq = atoi(token + 5);
12201 continue;
12202 }
12203
12204 if (os_strncmp(token, "freq_list=", 10) == 0) {
12205 char *pos = token + 10;
12206
12207 if (os_strcmp(pos, "all") == 0) {
12208 os_free(freq_list);
12209 freq_list = wpas_nan_usd_all_freqs(wpa_s);
12210 params.freq_list = freq_list;
12211 continue;
12212 }
12213
12214 while (pos && pos[0]) {
12215 int_array_add_unique(&freq_list, atoi(pos));
12216 pos = os_strchr(pos, ',');
12217 if (pos)
12218 pos++;
12219 }
12220
12221 params.freq_list = freq_list;
12222 continue;
12223 }
12224
12225 if (os_strncmp(token, "srv_proto_type=", 15) == 0) {
12226 srv_proto_type = atoi(token + 15);
12227 continue;
12228 }
12229
12230 if (os_strncmp(token, "ssi=", 4) == 0) {
12231 if (ssi)
12232 goto fail;
12233 ssi = wpabuf_parse_bin(token + 4);
12234 if (!ssi)
12235 goto fail;
12236 continue;
12237 }
12238
12239 if (os_strcmp(token, "solicited=0") == 0) {
12240 params.solicited = false;
12241 continue;
12242 }
12243
12244 if (os_strcmp(token, "unsolicited=0") == 0) {
12245 params.unsolicited = false;
12246 continue;
12247 }
12248
12249 if (os_strcmp(token, "fsd=0") == 0) {
12250 params.fsd = false;
12251 continue;
12252 }
12253
12254 wpa_printf(MSG_INFO, "CTRL: Invalid NAN_PUBLISH parameter: %s",
12255 token);
12256 goto fail;
12257 }
12258
12259 publish_id = wpas_nan_usd_publish(wpa_s, service_name, srv_proto_type,
12260 ssi, &params);
12261 if (publish_id > 0)
12262 ret = os_snprintf(buf, buflen, "%d", publish_id);
12263fail:
12264 wpabuf_free(ssi);
12265 os_free(freq_list);
12266 return ret;
12267}
12268
12269
12270static int wpas_ctrl_nan_cancel_publish(struct wpa_supplicant *wpa_s,
12271 char *cmd)
12272{
12273 char *token, *context = NULL;
12274 int publish_id = 0;
12275
12276 while ((token = str_token(cmd, " ", &context))) {
12277 if (sscanf(token, "publish_id=%i", &publish_id) == 1)
12278 continue;
12279 wpa_printf(MSG_INFO,
12280 "CTRL: Invalid NAN_CANCEL_PUBLISH parameter: %s",
12281 token);
12282 return -1;
12283 }
12284
12285 if (publish_id <= 0) {
12286 wpa_printf(MSG_INFO,
12287 "CTRL: Invalid or missing NAN_CANCEL_PUBLISH publish_id");
12288 return -1;
12289 }
12290
12291 wpas_nan_usd_cancel_publish(wpa_s, publish_id);
12292 return 0;
12293}
12294
12295
12296static int wpas_ctrl_nan_update_publish(struct wpa_supplicant *wpa_s,
12297 char *cmd)
12298{
12299 char *token, *context = NULL;
12300 int publish_id = 0;
12301 struct wpabuf *ssi = NULL;
12302 int ret = -1;
12303
12304 while ((token = str_token(cmd, " ", &context))) {
12305 if (sscanf(token, "publish_id=%i", &publish_id) == 1)
12306 continue;
12307 if (os_strncmp(token, "ssi=", 4) == 0) {
12308 if (ssi)
12309 goto fail;
12310 ssi = wpabuf_parse_bin(token + 4);
12311 if (!ssi)
12312 goto fail;
12313 continue;
12314 }
12315 wpa_printf(MSG_INFO,
12316 "CTRL: Invalid NAN_UPDATE_PUBLISH parameter: %s",
12317 token);
12318 goto fail;
12319 }
12320
12321 if (publish_id <= 0) {
12322 wpa_printf(MSG_INFO,
12323 "CTRL: Invalid or missing NAN_UPDATE_PUBLISH publish_id");
12324 goto fail;
12325 }
12326
12327 ret = wpas_nan_usd_update_publish(wpa_s, publish_id, ssi);
12328fail:
12329 wpabuf_free(ssi);
12330 return ret;
12331}
12332
12333
12334static int wpas_ctrl_nan_subscribe(struct wpa_supplicant *wpa_s, char *cmd,
12335 char *buf, size_t buflen)
12336{
12337 char *token, *context = NULL;
12338 int subscribe_id;
12339 struct nan_subscribe_params params;
12340 const char *service_name = NULL;
12341 struct wpabuf *ssi = NULL;
12342 int ret = -1;
12343 enum nan_service_protocol_type srv_proto_type = 0;
12344
12345 os_memset(&params, 0, sizeof(params));
12346 params.freq = NAN_USD_DEFAULT_FREQ;
12347
12348 while ((token = str_token(cmd, " ", &context))) {
12349 if (os_strncmp(token, "service_name=", 13) == 0) {
12350 service_name = token + 13;
12351 continue;
12352 }
12353
12354 if (os_strcmp(token, "active=1") == 0) {
12355 params.active = true;
12356 continue;
12357 }
12358
12359 if (os_strncmp(token, "ttl=", 4) == 0) {
12360 params.ttl = atoi(token + 4);
12361 continue;
12362 }
12363
12364 if (os_strncmp(token, "freq=", 5) == 0) {
12365 params.freq = atoi(token + 5);
12366 continue;
12367 }
12368
12369 if (os_strncmp(token, "srv_proto_type=", 15) == 0) {
12370 srv_proto_type = atoi(token + 15);
12371 continue;
12372 }
12373
12374 if (os_strncmp(token, "ssi=", 4) == 0) {
12375 if (ssi)
12376 goto fail;
12377 ssi = wpabuf_parse_bin(token + 4);
12378 if (!ssi)
12379 goto fail;
12380 continue;
12381 }
12382
12383 wpa_printf(MSG_INFO,
12384 "CTRL: Invalid NAN_SUBSCRIBE parameter: %s",
12385 token);
12386 goto fail;
12387 }
12388
12389 subscribe_id = wpas_nan_usd_subscribe(wpa_s, service_name,
12390 srv_proto_type, ssi,
12391 &params);
12392 if (subscribe_id > 0)
12393 ret = os_snprintf(buf, buflen, "%d", subscribe_id);
12394fail:
12395 wpabuf_free(ssi);
12396 return ret;
12397}
12398
12399
12400static int wpas_ctrl_nan_cancel_subscribe(struct wpa_supplicant *wpa_s,
12401 char *cmd)
12402{
12403 char *token, *context = NULL;
12404 int subscribe_id = 0;
12405
12406 while ((token = str_token(cmd, " ", &context))) {
12407 if (sscanf(token, "subscribe_id=%i", &subscribe_id) == 1)
12408 continue;
12409 wpa_printf(MSG_INFO,
12410 "CTRL: Invalid NAN_CANCEL_SUBSCRIBE parameter: %s",
12411 token);
12412 return -1;
12413 }
12414
12415 if (subscribe_id <= 0) {
12416 wpa_printf(MSG_INFO,
12417 "CTRL: Invalid or missing NAN_CANCEL_SUBSCRIBE subscribe_id");
12418 return -1;
12419 }
12420
12421 wpas_nan_usd_cancel_subscribe(wpa_s, subscribe_id);
12422 return 0;
12423}
12424
12425
12426static int wpas_ctrl_nan_transmit(struct wpa_supplicant *wpa_s, char *cmd)
12427{
12428 char *token, *context = NULL;
12429 int handle = 0;
12430 int req_instance_id = 0;
12431 struct wpabuf *ssi = NULL;
12432 u8 peer_addr[ETH_ALEN];
12433 int ret = -1;
12434
12435 os_memset(peer_addr, 0, ETH_ALEN);
12436
12437 while ((token = str_token(cmd, " ", &context))) {
12438 if (sscanf(token, "handle=%i", &handle) == 1)
12439 continue;
12440
12441 if (sscanf(token, "req_instance_id=%i", &req_instance_id) == 1)
12442 continue;
12443
12444 if (os_strncmp(token, "address=", 8) == 0) {
12445 if (hwaddr_aton(token + 8, peer_addr) < 0)
12446 return -1;
12447 continue;
12448 }
12449
12450 if (os_strncmp(token, "ssi=", 4) == 0) {
12451 if (ssi)
12452 goto fail;
12453 ssi = wpabuf_parse_bin(token + 4);
12454 if (!ssi)
12455 goto fail;
12456 continue;
12457 }
12458
12459 wpa_printf(MSG_INFO,
12460 "CTRL: Invalid NAN_TRANSMIT parameter: %s",
12461 token);
12462 goto fail;
12463 }
12464
12465 if (handle <= 0) {
12466 wpa_printf(MSG_INFO,
12467 "CTRL: Invalid or missing NAN_TRANSMIT handle");
12468 goto fail;
12469 }
12470
12471 if (is_zero_ether_addr(peer_addr)) {
12472 wpa_printf(MSG_INFO,
12473 "CTRL: Invalid or missing NAN_TRANSMIT address");
12474 goto fail;
12475 }
12476
12477 ret = wpas_nan_usd_transmit(wpa_s, handle, ssi, NULL, peer_addr,
12478 req_instance_id);
12479fail:
12480 wpabuf_free(ssi);
12481 return ret;
12482}
12483
12484#endif /* CONFIG_NAN_USD */
12485
12486
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012487char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
12488 char *buf, size_t *resp_len)
12489{
12490 char *reply;
12491 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012492 int reply_len;
12493
12494 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012495 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
12496 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
12497 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012498 if (wpa_debug_show_keys)
12499 wpa_dbg(wpa_s, MSG_DEBUG,
12500 "Control interface command '%s'", buf);
12501 else
12502 wpa_dbg(wpa_s, MSG_DEBUG,
12503 "Control interface command '%s [REMOVED]'",
12504 os_strncmp(buf, WPA_CTRL_RSP,
12505 os_strlen(WPA_CTRL_RSP)) == 0 ?
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012506 WPA_CTRL_RSP :
12507 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
12508 "SET_NETWORK" : "key-add"));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012509 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
Dmitry Shmidt21de2142014-04-08 10:50:52 -070012510 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012511 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
12512 (const u8 *) buf, os_strlen(buf));
12513 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012514 int level = wpas_ctrl_cmd_debug_level(buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -070012515 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012516 }
12517
12518 reply = os_malloc(reply_size);
12519 if (reply == NULL) {
12520 *resp_len = 1;
12521 return NULL;
12522 }
12523
12524 os_memcpy(reply, "OK\n", 3);
12525 reply_len = 3;
12526
12527 if (os_strcmp(buf, "PING") == 0) {
12528 os_memcpy(reply, "PONG\n", 5);
12529 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070012530 } else if (os_strcmp(buf, "IFNAME") == 0) {
12531 reply_len = os_strlen(wpa_s->ifname);
12532 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012533 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
12534 if (wpa_debug_reopen_file() < 0)
12535 reply_len = -1;
12536 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
12537 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
12538 } else if (os_strcmp(buf, "MIB") == 0) {
12539 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
12540 if (reply_len >= 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012541 reply_len += eapol_sm_get_mib(wpa_s->eapol,
12542 reply + reply_len,
12543 reply_size - reply_len);
Hai Shalom74f70d42019-02-11 14:42:39 -080012544#ifdef CONFIG_MACSEC
12545 reply_len += ieee802_1x_kay_get_mib(
12546 wpa_s->kay, reply + reply_len,
12547 reply_size - reply_len);
12548#endif /* CONFIG_MACSEC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012549 }
12550 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
12551 reply_len = wpa_supplicant_ctrl_iface_status(
12552 wpa_s, buf + 6, reply, reply_size);
12553 } else if (os_strcmp(buf, "PMKSA") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070012554 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070012555 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070012556 wpas_ctrl_iface_pmksa_flush(wpa_s);
Dmitry Shmidt29333592017-01-09 12:27:11 -080012557#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
12558 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
12559 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
12560 reply, reply_size);
12561 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
12562 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
12563 reply_len = -1;
Paul Stewart092955c2017-02-06 09:13:09 -080012564#ifdef CONFIG_MESH
12565 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
12566 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
12567 reply, reply_size);
12568 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
12569 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
12570 reply_len = -1;
12571#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080012572#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012573 } else if (os_strncmp(buf, "SET ", 4) == 0) {
12574 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
12575 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012576 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
12577 reply_len = wpa_config_dump_values(wpa_s->conf,
12578 reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012579 } else if (os_strncmp(buf, "GET ", 4) == 0) {
12580 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
12581 reply, reply_size);
12582 } else if (os_strcmp(buf, "LOGON") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070012583 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012584 } else if (os_strcmp(buf, "LOGOFF") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070012585 eapol_sm_notify_logoff(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012586 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
12587 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
12588 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012589 else
12590 wpas_request_connection(wpa_s);
Dmitry Shmidt98660862014-03-11 17:26:21 -070012591 } else if (os_strcmp(buf, "REATTACH") == 0) {
12592 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
12593 !wpa_s->current_ssid)
12594 reply_len = -1;
12595 else {
12596 wpa_s->reattach = 1;
12597 wpas_request_connection(wpa_s);
12598 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012599 } else if (os_strcmp(buf, "RECONNECT") == 0) {
12600 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
12601 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012602 else if (wpa_s->disconnected)
12603 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012604#ifdef IEEE8021X_EAPOL
12605 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
12606 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
12607 reply_len = -1;
12608#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012609#ifdef CONFIG_IEEE80211R
12610 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
12611 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
12612 reply_len = -1;
12613#endif /* CONFIG_IEEE80211R */
12614#ifdef CONFIG_WPS
12615 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
12616 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
12617 if (res == -2) {
12618 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12619 reply_len = 17;
12620 } else if (res)
12621 reply_len = -1;
12622 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
12623 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
12624 if (res == -2) {
12625 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12626 reply_len = 17;
12627 } else if (res)
12628 reply_len = -1;
12629 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
12630 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
12631 reply,
12632 reply_size);
12633 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
12634 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
12635 wpa_s, buf + 14, reply, reply_size);
12636 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
12637 if (wpas_wps_cancel(wpa_s))
12638 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012639#ifdef CONFIG_WPS_NFC
12640 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
12641 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
12642 reply_len = -1;
12643 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
12644 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
12645 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -080012646 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
12647 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
12648 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012649 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
12650 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
12651 wpa_s, buf + 14, reply, reply_size);
12652 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
12653 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
12654 buf + 17))
12655 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012656 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
12657 reply_len = wpas_ctrl_nfc_get_handover_req(
12658 wpa_s, buf + 21, reply, reply_size);
12659 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
12660 reply_len = wpas_ctrl_nfc_get_handover_sel(
12661 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -080012662 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
12663 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
12664 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012665#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012666 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
12667 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
12668 reply_len = -1;
12669#ifdef CONFIG_AP
12670 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
12671 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
12672 wpa_s, buf + 11, reply, reply_size);
12673#endif /* CONFIG_AP */
12674#ifdef CONFIG_WPS_ER
12675 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
12676 if (wpas_wps_er_start(wpa_s, NULL))
12677 reply_len = -1;
12678 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
12679 if (wpas_wps_er_start(wpa_s, buf + 13))
12680 reply_len = -1;
12681 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012682 wpas_wps_er_stop(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012683 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
12684 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
12685 reply_len = -1;
12686 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
12687 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
12688 if (ret == -2) {
12689 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12690 reply_len = 17;
12691 } else if (ret == -3) {
12692 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
12693 reply_len = 18;
12694 } else if (ret == -4) {
12695 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
12696 reply_len = 20;
12697 } else if (ret)
12698 reply_len = -1;
12699 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
12700 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
12701 reply_len = -1;
12702 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
12703 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
12704 buf + 18))
12705 reply_len = -1;
12706 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
12707 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
12708 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012709#ifdef CONFIG_WPS_NFC
12710 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
12711 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
12712 wpa_s, buf + 24, reply, reply_size);
12713#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012714#endif /* CONFIG_WPS_ER */
12715#endif /* CONFIG_WPS */
12716#ifdef CONFIG_IBSS_RSN
12717 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
12718 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
12719 reply_len = -1;
12720#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012721#ifdef CONFIG_MESH
12722 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
12723 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
12724 wpa_s, buf + 19, reply, reply_size);
12725 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
12726 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
12727 wpa_s, "", reply, reply_size);
12728 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
12729 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
12730 reply_len = -1;
12731 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
12732 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
12733 buf + 18))
12734 reply_len = -1;
Dmitry Shmidte4663042016-04-04 10:07:49 -070012735 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
12736 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
12737 reply_len = -1;
12738 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
12739 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
12740 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070012741 } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) {
12742 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16))
12743 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012744#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012745#ifdef CONFIG_P2P
12746 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012747 if (p2p_ctrl_find(wpa_s, buf + 8))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012748 reply_len = -1;
12749 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
12750 if (p2p_ctrl_find(wpa_s, ""))
12751 reply_len = -1;
12752 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
12753 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012754 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
12755 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
12756 reply_len = -1;
12757 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
12758 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
12759 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012760 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
12761 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
12762 reply_size);
12763 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
12764 if (p2p_ctrl_listen(wpa_s, buf + 11))
12765 reply_len = -1;
12766 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
12767 if (p2p_ctrl_listen(wpa_s, ""))
12768 reply_len = -1;
12769 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
12770 if (wpas_p2p_group_remove(wpa_s, buf + 17))
12771 reply_len = -1;
12772 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070012773 if (p2p_ctrl_group_add(wpa_s, ""))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012774 reply_len = -1;
12775 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
12776 if (p2p_ctrl_group_add(wpa_s, buf + 14))
12777 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070012778 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
12779 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
12780 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012781 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
12782 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
12783 reply_len = -1;
12784 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
12785 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
12786 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
12787 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
12788 reply_size);
12789 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
12790 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
12791 reply_len = -1;
12792 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
12793 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
12794 reply_len = -1;
12795 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
12796 wpas_p2p_sd_service_update(wpa_s);
12797 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
12798 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
12799 reply_len = -1;
12800 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
12801 wpas_p2p_service_flush(wpa_s);
12802 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
12803 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
12804 reply_len = -1;
12805 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
12806 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
12807 reply_len = -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012808 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
12809 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
12810 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012811 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
12812 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
12813 reply_len = -1;
12814 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
12815 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
12816 reply_len = -1;
12817 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
12818 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
12819 reply_size);
12820 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
12821 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
12822 reply_len = -1;
12823 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -070012824 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012825 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
12826 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
12827 reply_len = -1;
12828 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
12829 if (wpas_p2p_cancel(wpa_s))
12830 reply_len = -1;
12831 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
12832 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
12833 reply_len = -1;
12834 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
12835 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
12836 reply_len = -1;
12837 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
12838 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
12839 reply_len = -1;
12840 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
12841 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
12842 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070012843 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
12844 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
12845 reply_len = -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070012846 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
12847 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
12848 reply_len = -1;
12849 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
12850 if (wpas_p2p_lo_stop(wpa_s))
12851 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012852#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070012853#ifdef CONFIG_WIFI_DISPLAY
12854 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
12855 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
12856 reply_len = -1;
12857 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
12858 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
12859 reply, reply_size);
12860#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012861#ifdef CONFIG_INTERWORKING
12862 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
12863 if (interworking_fetch_anqp(wpa_s) < 0)
12864 reply_len = -1;
12865 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
12866 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012867 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
12868 if (ctrl_interworking_select(wpa_s, NULL) < 0)
12869 reply_len = -1;
12870 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
12871 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012872 reply_len = -1;
12873 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012874 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012875 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012876 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
12877 int id;
12878
12879 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
12880 if (id < 0)
12881 reply_len = -1;
12882 else {
12883 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
12884 if (os_snprintf_error(reply_size, reply_len))
12885 reply_len = -1;
12886 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012887 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
12888 if (get_anqp(wpa_s, buf + 9) < 0)
12889 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070012890 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
12891 if (gas_request(wpa_s, buf + 12) < 0)
12892 reply_len = -1;
12893 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
12894 reply_len = gas_response_get(wpa_s, buf + 17, reply,
12895 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012896#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -070012897#ifdef CONFIG_HS20
12898 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
12899 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
12900 reply_len = -1;
12901 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
12902 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
12903 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080012904 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080012905 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
12906 reply_len = -1;
12907 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
12908 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
12909 reply_len = -1;
12910 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
12911 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
12912 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
12913 if (del_hs20_icon(wpa_s, buf + 14) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080012914 reply_len = -1;
12915 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070012916 if (hs20_fetch_osu(wpa_s, 0) < 0)
12917 reply_len = -1;
12918 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
12919 if (hs20_fetch_osu(wpa_s, 1) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080012920 reply_len = -1;
12921 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
12922 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012923#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012924 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
12925 {
12926 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
12927 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
12928 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -070012929 else {
12930 /*
12931 * Notify response from timeout to allow the control
12932 * interface response to be sent first.
12933 */
12934 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
12935 wpa_s, NULL);
12936 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012937 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
12938 if (wpa_supplicant_reload_configuration(wpa_s))
12939 reply_len = -1;
12940 } else if (os_strcmp(buf, "TERMINATE") == 0) {
12941 wpa_supplicant_terminate_proc(wpa_s->global);
12942 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
12943 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
12944 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080012945 } else if (os_strncmp(buf, "BSSID_IGNORE", 12) == 0) {
12946 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
12947 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidte19501d2011-03-16 14:32:18 -070012948 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -080012949 /* deprecated backwards compatibility alias for BSSID_IGNORE */
12950 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012951 wpa_s, buf + 9, reply, reply_size);
12952 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
12953 reply_len = wpa_supplicant_ctrl_iface_log_level(
12954 wpa_s, buf + 9, reply, reply_size);
Vinit Deshpandeda134e92014-12-02 10:59:29 -080012955 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
12956 reply_len = wpa_supplicant_ctrl_iface_list_networks(
12957 wpa_s, buf + 14, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012958 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
12959 reply_len = wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -080012960 wpa_s, NULL, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012961 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070012962 wpas_request_disconnection(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012963 } else if (os_strcmp(buf, "SCAN") == 0) {
12964 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
12965 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
12966 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012967 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
12968 reply_len = wpa_supplicant_ctrl_iface_scan_results(
12969 wpa_s, reply, reply_size);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080012970 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
12971 if (wpas_abort_ongoing_scan(wpa_s) < 0)
12972 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012973 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
12974 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
12975 reply_len = -1;
12976 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
12977 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
12978 reply_len = -1;
12979 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
12980 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
12981 reply_len = -1;
12982 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
12983 reply_len = wpa_supplicant_ctrl_iface_add_network(
12984 wpa_s, reply, reply_size);
12985 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
12986 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
12987 reply_len = -1;
12988 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
12989 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
12990 reply_len = -1;
12991 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
12992 reply_len = wpa_supplicant_ctrl_iface_get_network(
12993 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt684785c2014-05-12 13:34:29 -070012994 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012995 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
12996 wpa_s))
Dmitry Shmidt684785c2014-05-12 13:34:29 -070012997 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012998 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
12999 reply_len = wpa_supplicant_ctrl_iface_list_creds(
13000 wpa_s, reply, reply_size);
13001 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
13002 reply_len = wpa_supplicant_ctrl_iface_add_cred(
13003 wpa_s, reply, reply_size);
13004 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
13005 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
13006 reply_len = -1;
13007 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
13008 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
13009 reply_len = -1;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -070013010 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
13011 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
13012 reply,
13013 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013014#ifndef CONFIG_NO_CONFIG_WRITE
13015 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
13016 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
13017 reply_len = -1;
13018#endif /* CONFIG_NO_CONFIG_WRITE */
13019 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
13020 reply_len = wpa_supplicant_ctrl_iface_get_capability(
13021 wpa_s, buf + 15, reply, reply_size);
13022 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
13023 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
13024 reply_len = -1;
13025 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
13026 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
13027 reply_len = -1;
13028 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
13029 reply_len = wpa_supplicant_global_iface_list(
13030 wpa_s->global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013031 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013032 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013033 wpa_s->global, buf + 10, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013034 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
13035 reply_len = wpa_supplicant_ctrl_iface_bss(
13036 wpa_s, buf + 4, reply, reply_size);
13037#ifdef CONFIG_AP
13038 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
13039 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
13040 } else if (os_strncmp(buf, "STA ", 4) == 0) {
13041 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
13042 reply_size);
13043 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
13044 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
13045 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070013046 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
13047 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
13048 reply_len = -1;
13049 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
13050 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
13051 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080013052 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
13053 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
13054 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080013055 } else if (os_strcmp(buf, "STOP_AP") == 0) {
13056 if (wpas_ap_stop_ap(wpa_s))
13057 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080013058 } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) {
13059 if (wpas_ap_update_beacon(wpa_s))
13060 reply_len = -1;
Sunil Ravia04bd252022-05-02 22:54:18 -070013061 } else if (os_strncmp(buf, "ACCEPT_ACL ", 11) == 0) {
13062 if (os_strncmp(buf + 11, "ADD_MAC ", 8) == 0) {
13063 if (ap_ctrl_iface_acl_add_mac(wpa_s,
13064 DENY_UNLESS_ACCEPTED,
13065 buf + 19) ||
13066 ap_ctrl_iface_set_acl(wpa_s))
13067 reply_len = -1;
13068 } else if (os_strncmp((buf + 11), "DEL_MAC ", 8) == 0) {
13069 if (ap_ctrl_iface_acl_del_mac(wpa_s,
13070 DENY_UNLESS_ACCEPTED,
13071 buf + 19) ||
13072 ap_ctrl_iface_set_acl(wpa_s) ||
13073 ap_ctrl_iface_disassoc_accept_mac(wpa_s))
13074 reply_len = -1;
13075 } else if (os_strcmp(buf + 11, "SHOW") == 0) {
13076 reply_len = ap_ctrl_iface_acl_show_mac(
13077 wpa_s, DENY_UNLESS_ACCEPTED,
13078 reply, reply_size);
13079 } else if (os_strcmp(buf + 11, "CLEAR") == 0) {
13080 ap_ctrl_iface_acl_clear_list(wpa_s,
13081 DENY_UNLESS_ACCEPTED);
13082 if (ap_ctrl_iface_set_acl(wpa_s) ||
13083 ap_ctrl_iface_disassoc_accept_mac(wpa_s))
13084 reply_len = -1;
13085 } else {
13086 reply_len = -1;
13087 }
13088 } else if (os_strncmp(buf, "DENY_ACL ", 9) == 0) {
13089 if (os_strncmp(buf + 9, "ADD_MAC ", 8) == 0) {
13090 if (ap_ctrl_iface_acl_add_mac(wpa_s,
13091 ACCEPT_UNLESS_DENIED,
13092 buf + 17) ||
13093 ap_ctrl_iface_set_acl(wpa_s) ||
13094 ap_ctrl_iface_disassoc_deny_mac(wpa_s))
13095 reply_len = -1;
13096 } else if (os_strncmp(buf + 9, "DEL_MAC ", 8) == 0) {
13097 if (ap_ctrl_iface_acl_del_mac(wpa_s,
13098 ACCEPT_UNLESS_DENIED,
13099 buf + 17) ||
13100 ap_ctrl_iface_set_acl(wpa_s))
13101 reply_len = -1;
13102 } else if (os_strcmp(buf + 9, "SHOW") == 0) {
13103 reply_len = ap_ctrl_iface_acl_show_mac(
13104 wpa_s, ACCEPT_UNLESS_DENIED, reply, reply_size);
13105 } else if (os_strcmp(buf + 9, "CLEAR") == 0) {
13106 ap_ctrl_iface_acl_clear_list(wpa_s,
13107 ACCEPT_UNLESS_DENIED);
13108 if (ap_ctrl_iface_set_acl(wpa_s))
13109 reply_len = -1;
13110 } else {
13111 reply_len = -1;
13112 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013113#endif /* CONFIG_AP */
13114 } else if (os_strcmp(buf, "SUSPEND") == 0) {
13115 wpas_notify_suspend(wpa_s->global);
13116 } else if (os_strcmp(buf, "RESUME") == 0) {
13117 wpas_notify_resume(wpa_s->global);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070013118#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013119 } else if (os_strcmp(buf, "DROP_SA") == 0) {
13120 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070013121#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013122 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
13123 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
13124 reply_len = -1;
13125 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013126 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013127 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
13128 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
13129 reply_len = -1;
13130 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
13131 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
13132 buf + 17))
13133 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -070013134 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013135 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013136#ifdef CONFIG_TDLS
13137 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
13138 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
13139 reply_len = -1;
13140 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
13141 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
13142 reply_len = -1;
13143 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
13144 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
13145 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013146 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
13147 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
13148 buf + 17))
13149 reply_len = -1;
13150 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
13151 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
13152 buf + 24))
13153 reply_len = -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -070013154 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
13155 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
13156 wpa_s, buf + 17, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013157#endif /* CONFIG_TDLS */
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013158#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013159 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
13160 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
13161 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
13162 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
13163 reply_len = -1;
13164 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
13165 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
13166 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013167#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013168 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
13169 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
13170 reply_size);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080013171 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
13172 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
13173 reply_len = -1;
Yuhao Zhengfcd6f212012-07-27 10:37:52 -070013174 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
13175 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
13176 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070013177#ifdef CONFIG_AUTOSCAN
13178 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
13179 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
13180 reply_len = -1;
13181#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070013182 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
13183 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
13184 reply_size);
Hai Shalomb755a2a2020-04-23 21:49:02 -070013185 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
13186 reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply,
13187 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080013188#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -070013189 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
13190 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
13191 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080013192#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080013193 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
13194 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
13195 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080013196 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080013197 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080013198 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080013199#ifdef CONFIG_WNM
13200 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
13201 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
13202 reply_len = -1;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080013203 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
13204 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
Dmitry Shmidt44c95782013-05-17 09:51:35 -070013205 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -080013206 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
13207 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
13208 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080013209#endif /* CONFIG_WNM */
Sunil Ravia04bd252022-05-02 22:54:18 -070013210#ifdef CONFIG_WNM_AP
13211 } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
13212 if (ap_ctrl_iface_disassoc_imminent(wpa_s, buf + 18))
13213 reply_len = -1;
13214 } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
13215 if (ap_ctrl_iface_ess_disassoc(wpa_s, buf + 13))
13216 reply_len = -1;
13217 } else if (os_strncmp(buf, "BSS_TM_REQ ", 11) == 0) {
13218 if (ap_ctrl_iface_bss_tm_req(wpa_s, buf + 11))
13219 reply_len = -1;
13220#endif /* CONFIG_WNM_AP */
Dmitry Shmidt444d5672013-04-01 13:08:44 -070013221 } else if (os_strcmp(buf, "FLUSH") == 0) {
13222 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080013223 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
13224 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
13225 reply_size);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070013226#ifdef CONFIG_TESTING_OPTIONS
13227 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
13228 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
13229 reply_len = -1;
13230 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
13231 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013232 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
13233 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
13234 reply_len = -1;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -070013235 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
13236 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
13237 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013238 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
13239 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
13240 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080013241 } else if (os_strncmp(buf, "EAPOL_TX ", 9) == 0) {
13242 if (wpas_ctrl_iface_eapol_tx(wpa_s, buf + 9) < 0)
13243 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013244 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
13245 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
13246 reply_len = -1;
13247 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
13248 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
13249 reply_len = -1;
13250 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
13251 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
13252 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -080013253 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013254 if (testing_set_fail_pattern(true, buf + 16) < 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -080013255 reply_len = -1;
13256 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013257 reply_len = testing_get_fail_pattern(true, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013258 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013259 if (testing_set_fail_pattern(false, buf + 10) < 0)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013260 reply_len = -1;
13261 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013262 reply_len = testing_get_fail_pattern(false, reply, reply_size);
Jouni Malinenc4818362015-10-04 11:45:13 +030013263 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
13264 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
13265 reply_len = -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080013266 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
13267 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
13268 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013269 } else if (os_strncmp(buf, "TEST_EAPOL_M2_ELEMS ", 20) == 0) {
13270 if (wpas_ctrl_test_eapol_m2_elems(wpa_s, buf + 20) < 0)
13271 reply_len = -1;
13272 } else if (os_strncmp(buf, "TEST_EAPOL_M4_ELEMS ", 20) == 0) {
13273 if (wpas_ctrl_test_eapol_m4_elems(wpa_s, buf + 20) < 0)
13274 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013275 } else if (os_strcmp(buf, "RESET_PN") == 0) {
13276 if (wpas_ctrl_reset_pn(wpa_s) < 0)
13277 reply_len = -1;
13278 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
13279 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
13280 reply_len = -1;
13281 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
13282 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
13283 reply_len = -1;
Hai Shalom74f70d42019-02-11 14:42:39 -080013284 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
13285 sme_event_unprot_disconnect(
13286 wpa_s, wpa_s->bssid, NULL,
13287 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
Hai Shaloma20dcd72022-02-04 13:43:00 -080013288 } else if (os_strncmp(buf, "TWT_SETUP ", 10) == 0) {
13289 if (wpas_ctrl_iface_send_twt_setup(wpa_s, buf + 9))
13290 reply_len = -1;
13291 } else if (os_strcmp(buf, "TWT_SETUP") == 0) {
13292 if (wpas_ctrl_iface_send_twt_setup(wpa_s, ""))
13293 reply_len = -1;
13294 } else if (os_strncmp(buf, "TWT_TEARDOWN ", 13) == 0) {
13295 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, buf + 12))
13296 reply_len = -1;
13297 } else if (os_strcmp(buf, "TWT_TEARDOWN") == 0) {
13298 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, ""))
13299 reply_len = -1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000013300 } else if (os_strncmp(buf, "ML_PROBE_REQ ", 13) == 0) {
13301 if (wpas_ctrl_ml_probe(wpa_s, buf + 13))
13302 reply_len = -1;
Dmitry Shmidt818ea482014-03-10 13:15:21 -070013303#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070013304 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
13305 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
13306 reply_len = -1;
13307 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
13308 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
13309 reply_size);
13310 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
13311 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
13312 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013313#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013314 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013315 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013316 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013317#endif /* CONFIG_NO_RRM */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013318 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
13319 wpas_ctrl_iface_erp_flush(wpa_s);
13320 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
13321 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
13322 reply_len = -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013323 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
13324 reply_len = wpas_ctrl_iface_get_pref_freq_list(
13325 wpa_s, buf + 19, reply, reply_size);
Paul Stewart092955c2017-02-06 09:13:09 -080013326#ifdef CONFIG_FILS
13327 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
13328 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
13329 reply_len = -1;
13330 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
13331 wpas_flush_fils_hlp_req(wpa_s);
13332#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013333#ifdef CONFIG_DPP
13334 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
13335 int res;
13336
13337 res = wpas_dpp_qr_code(wpa_s, buf + 12);
13338 if (res < 0) {
13339 reply_len = -1;
13340 } else {
13341 reply_len = os_snprintf(reply, reply_size, "%d", res);
13342 if (os_snprintf_error(reply_size, reply_len))
13343 reply_len = -1;
13344 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080013345 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
13346 int res;
13347
13348 res = wpas_dpp_nfc_uri(wpa_s, buf + 12);
13349 if (res < 0) {
13350 reply_len = -1;
13351 } else {
13352 reply_len = os_snprintf(reply, reply_size, "%d", res);
13353 if (os_snprintf_error(reply_size, reply_len))
13354 reply_len = -1;
13355 }
Hai Shalomfdcde762020-04-02 11:19:20 -070013356 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
13357 int res;
13358
13359 res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20);
13360 if (res < 0) {
13361 reply_len = -1;
13362 } else {
13363 reply_len = os_snprintf(reply, reply_size, "%d", res);
13364 if (os_snprintf_error(reply_size, reply_len))
13365 reply_len = -1;
13366 }
13367 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
13368 int res;
13369
13370 res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20);
13371 if (res < 0) {
13372 reply_len = -1;
13373 } else {
13374 reply_len = os_snprintf(reply, reply_size, "%d", res);
13375 if (os_snprintf_error(reply_size, reply_len))
13376 reply_len = -1;
13377 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013378 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
13379 int res;
13380
Hai Shalom021b0b52019-04-10 11:17:58 -070013381 res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013382 if (res < 0) {
13383 reply_len = -1;
13384 } else {
13385 reply_len = os_snprintf(reply, reply_size, "%d", res);
13386 if (os_snprintf_error(reply_size, reply_len))
13387 reply_len = -1;
13388 }
13389 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070013390 if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013391 reply_len = -1;
13392 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
13393 const char *uri;
13394
Hai Shalom021b0b52019-04-10 11:17:58 -070013395 uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013396 if (!uri) {
13397 reply_len = -1;
13398 } else {
13399 reply_len = os_snprintf(reply, reply_size, "%s", uri);
13400 if (os_snprintf_error(reply_size, reply_len))
13401 reply_len = -1;
13402 }
13403 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070013404 reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19),
13405 reply, reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -070013406 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
13407 if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18),
13408 os_strchr(buf + 18, ' ')) < 0)
13409 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013410 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
13411 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
13412 reply_len = -1;
13413 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
13414 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
13415 reply_len = -1;
13416 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -070013417 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013418 wpas_dpp_listen_stop(wpa_s);
13419 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
13420 int res;
13421
Hai Shalom021b0b52019-04-10 11:17:58 -070013422 res = dpp_configurator_add(wpa_s->dpp, buf + 20);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013423 if (res < 0) {
13424 reply_len = -1;
13425 } else {
13426 reply_len = os_snprintf(reply, reply_size, "%d", res);
13427 if (os_snprintf_error(reply_size, reply_len))
13428 reply_len = -1;
13429 }
Sunil Ravia04bd252022-05-02 22:54:18 -070013430 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SET ", 21) == 0) {
13431 if (dpp_configurator_set(wpa_s->dpp, buf + 20) < 0)
13432 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013433 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070013434 if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013435 reply_len = -1;
13436 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -080013437 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013438 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -070013439 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070013440 reply_len = dpp_configurator_get_key_id(wpa_s->dpp,
13441 atoi(buf + 25),
13442 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013443 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
13444 int res;
13445
13446 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
13447 if (res < 0) {
13448 reply_len = -1;
13449 } else {
13450 reply_len = os_snprintf(reply, reply_size, "%d", res);
13451 if (os_snprintf_error(reply_size, reply_len))
13452 reply_len = -1;
13453 }
13454 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
13455 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
13456 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080013457 } else if (os_strncmp(buf, "DPP_CONF_SET ", 13) == 0) {
13458 if (wpas_dpp_conf_set(wpa_s, buf + 12) < 0)
13459 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070013460#ifdef CONFIG_DPP2
13461 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
13462 if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0)
13463 reply_len = -1;
13464 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
13465 if (wpas_dpp_controller_start(wpa_s, NULL) < 0)
13466 reply_len = -1;
13467 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
13468 dpp_controller_stop(wpa_s->dpp);
Hai Shalomfdcde762020-04-02 11:19:20 -070013469 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
13470 if (wpas_dpp_chirp(wpa_s, buf + 9) < 0)
13471 reply_len = -1;
13472 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
13473 wpas_dpp_chirp_stop(wpa_s);
Hai Shalom4fbc08f2020-05-18 12:37:00 -070013474 } else if (os_strncmp(buf, "DPP_RECONFIG ", 13) == 0) {
Hai Shalom899fcc72020-10-19 14:38:18 -070013475 if (wpas_dpp_reconfig(wpa_s, buf + 13) < 0)
13476 reply_len = -1;
13477 } else if (os_strncmp(buf, "DPP_CA_SET ", 11) == 0) {
13478 if (wpas_dpp_ca_set(wpa_s, buf + 10) < 0)
Hai Shalom4fbc08f2020-05-18 12:37:00 -070013479 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070013480#endif /* CONFIG_DPP2 */
Sunil Ravi89eba102022-09-13 21:04:37 -070013481#ifdef CONFIG_DPP3
13482 } else if (os_strcmp(buf, "DPP_PUSH_BUTTON") == 0) {
13483 if (wpas_dpp_push_button(wpa_s, NULL) < 0)
13484 reply_len = -1;
13485 } else if (os_strncmp(buf, "DPP_PUSH_BUTTON ", 16) == 0) {
13486 if (wpas_dpp_push_button(wpa_s, buf + 15) < 0)
13487 reply_len = -1;
13488#endif /* CONFIG_DPP3 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013489#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013490#ifdef CONFIG_NAN_USD
13491 } else if (os_strncmp(buf, "NAN_PUBLISH ", 12) == 0) {
13492 reply_len = wpas_ctrl_nan_publish(wpa_s, buf + 12, reply,
13493 reply_size);
13494 } else if (os_strncmp(buf, "NAN_CANCEL_PUBLISH ", 19) == 0) {
13495 if (wpas_ctrl_nan_cancel_publish(wpa_s, buf + 19) < 0)
Hai Shalom899fcc72020-10-19 14:38:18 -070013496 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013497 } else if (os_strncmp(buf, "NAN_UPDATE_PUBLISH ", 19) == 0) {
13498 if (wpas_ctrl_nan_update_publish(wpa_s, buf + 19) < 0)
13499 reply_len = -1;
13500 } else if (os_strncmp(buf, "NAN_SUBSCRIBE ", 14) == 0) {
13501 reply_len = wpas_ctrl_nan_subscribe(wpa_s, buf + 14, reply,
13502 reply_size);
13503 } else if (os_strncmp(buf, "NAN_CANCEL_SUBSCRIBE ", 21) == 0) {
13504 if (wpas_ctrl_nan_cancel_subscribe(wpa_s, buf + 21) < 0)
13505 reply_len = -1;
13506 } else if (os_strncmp(buf, "NAN_TRANSMIT ", 13) == 0) {
13507 if (wpas_ctrl_nan_transmit(wpa_s, buf + 13) < 0)
13508 reply_len = -1;
13509#endif /* CONFIG_NAN_USD */
Hai Shalom60840252021-02-19 19:02:11 -080013510#ifdef CONFIG_PASN
13511 } else if (os_strncmp(buf, "PASN_START ", 11) == 0) {
13512 if (wpas_ctrl_iface_pasn_start(wpa_s, buf + 11) < 0)
13513 reply_len = -1;
13514 } else if (os_strcmp(buf, "PASN_STOP") == 0) {
13515 wpas_pasn_auth_stop(wpa_s);
13516 } else if (os_strcmp(buf, "PTKSA_CACHE_LIST") == 0) {
13517 reply_len = ptksa_cache_list(wpa_s->ptksa, reply, reply_size);
Hai Shaloma20dcd72022-02-04 13:43:00 -080013518 } else if (os_strncmp(buf, "PASN_DEAUTH ", 12) == 0) {
13519 if (wpas_ctrl_iface_pasn_deauthenticate(wpa_s, buf + 12) < 0)
13520 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013521#ifdef CONFIG_TESTING_OPTIONS
13522 } else if (os_strncmp(buf, "PASN_DRIVER ", 12) == 0) {
13523 if (wpas_ctrl_iface_pasn_driver(wpa_s, buf + 12) < 0)
13524 reply_len = -1;
13525#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom60840252021-02-19 19:02:11 -080013526#endif /* CONFIG_PASN */
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013527#ifndef CONFIG_NO_ROBUST_AV
13528 } else if (os_strncmp(buf, "MSCS ", 5) == 0) {
13529 if (wpas_ctrl_iface_configure_mscs(wpa_s, buf + 5))
13530 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080013531 } else if (os_strncmp(buf, "SCS ", 4) == 0) {
13532 if (wpas_ctrl_iface_configure_scs(wpa_s, buf + 4))
13533 reply_len = -1;
13534 } else if (os_strncmp(buf, "DSCP_RESP ", 10) == 0) {
13535 if (wpas_ctrl_iface_send_dscp_resp(wpa_s, buf + 10))
13536 reply_len = -1;
13537 } else if (os_strncmp(buf, "DSCP_QUERY ", 11) == 0) {
13538 if (wpas_ctrl_iface_send_dscp_query(wpa_s, buf + 11))
13539 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013540#endif /* CONFIG_NO_ROBUST_AV */
Sunil Ravi89eba102022-09-13 21:04:37 -070013541 } else if (os_strcmp(buf, "MLO_STATUS") == 0) {
13542 reply_len = wpas_ctrl_iface_mlo_status(wpa_s, reply,
13543 reply_size);
13544 } else if (os_strcmp(buf, "MLO_SIGNAL_POLL") == 0) {
13545 reply_len = wpas_ctrl_iface_mlo_signal_poll(wpa_s, reply,
13546 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013547 } else {
13548 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
13549 reply_len = 16;
13550 }
13551
13552 if (reply_len < 0) {
13553 os_memcpy(reply, "FAIL\n", 5);
13554 reply_len = 5;
13555 }
13556
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013557 *resp_len = reply_len;
13558 return reply;
13559}
13560
13561
13562static int wpa_supplicant_global_iface_add(struct wpa_global *global,
13563 char *cmd)
13564{
13565 struct wpa_interface iface;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013566 char *pos, *extra;
13567 struct wpa_supplicant *wpa_s;
13568 unsigned int create_iface = 0;
13569 u8 mac_addr[ETH_ALEN];
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013570 enum wpa_driver_if_type type = WPA_IF_STATION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013571
13572 /*
13573 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013574 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013575 */
13576 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
13577
13578 os_memset(&iface, 0, sizeof(iface));
13579
13580 do {
13581 iface.ifname = pos = cmd;
13582 pos = os_strchr(pos, '\t');
13583 if (pos)
13584 *pos++ = '\0';
13585 if (iface.ifname[0] == '\0')
13586 return -1;
13587 if (pos == NULL)
13588 break;
13589
13590 iface.confname = pos;
13591 pos = os_strchr(pos, '\t');
13592 if (pos)
13593 *pos++ = '\0';
13594 if (iface.confname[0] == '\0')
13595 iface.confname = NULL;
13596 if (pos == NULL)
13597 break;
13598
13599 iface.driver = pos;
13600 pos = os_strchr(pos, '\t');
13601 if (pos)
13602 *pos++ = '\0';
13603 if (iface.driver[0] == '\0')
13604 iface.driver = NULL;
13605 if (pos == NULL)
13606 break;
13607
13608 iface.ctrl_interface = pos;
13609 pos = os_strchr(pos, '\t');
13610 if (pos)
13611 *pos++ = '\0';
13612 if (iface.ctrl_interface[0] == '\0')
13613 iface.ctrl_interface = NULL;
13614 if (pos == NULL)
13615 break;
13616
13617 iface.driver_param = pos;
13618 pos = os_strchr(pos, '\t');
13619 if (pos)
13620 *pos++ = '\0';
13621 if (iface.driver_param[0] == '\0')
13622 iface.driver_param = NULL;
13623 if (pos == NULL)
13624 break;
13625
13626 iface.bridge_ifname = pos;
13627 pos = os_strchr(pos, '\t');
13628 if (pos)
13629 *pos++ = '\0';
13630 if (iface.bridge_ifname[0] == '\0')
13631 iface.bridge_ifname = NULL;
13632 if (pos == NULL)
13633 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013634
13635 extra = pos;
13636 pos = os_strchr(pos, '\t');
13637 if (pos)
13638 *pos++ = '\0';
Dmitry Shmidt83474442015-04-15 13:47:09 -070013639 if (!extra[0])
13640 break;
13641
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013642 if (os_strcmp(extra, "create") == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013643 create_iface = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013644 if (!pos)
13645 break;
13646
13647 if (os_strcmp(pos, "sta") == 0) {
13648 type = WPA_IF_STATION;
13649 } else if (os_strcmp(pos, "ap") == 0) {
13650 type = WPA_IF_AP_BSS;
13651 } else {
13652 wpa_printf(MSG_DEBUG,
13653 "INTERFACE_ADD unsupported interface type: '%s'",
13654 pos);
13655 return -1;
13656 }
13657 } else {
Dmitry Shmidt83474442015-04-15 13:47:09 -070013658 wpa_printf(MSG_DEBUG,
13659 "INTERFACE_ADD unsupported extra parameter: '%s'",
13660 extra);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013661 return -1;
Dmitry Shmidt83474442015-04-15 13:47:09 -070013662 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013663 } while (0);
13664
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013665 if (create_iface) {
13666 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
13667 iface.ifname);
13668 if (!global->ifaces)
13669 return -1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013670 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013671 NULL, NULL, NULL, mac_addr, NULL) < 0) {
13672 wpa_printf(MSG_ERROR,
13673 "CTRL_IFACE interface creation failed");
13674 return -1;
13675 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013676
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013677 wpa_printf(MSG_DEBUG,
13678 "CTRL_IFACE interface '%s' created with MAC addr: "
13679 MACSTR, iface.ifname, MAC2STR(mac_addr));
13680 }
13681
13682 if (wpa_supplicant_get_iface(global, iface.ifname))
13683 goto fail;
13684
13685 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
13686 if (!wpa_s)
13687 goto fail;
13688 wpa_s->added_vif = create_iface;
13689 return 0;
13690
13691fail:
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000013692 if (create_iface) {
13693 /* wpa_supplicant does not create multi-BSS AP, so collapse to
13694 * WPA_IF_STATION to avoid unwanted clean up in the driver. */
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013695 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000013696 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013697 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013698}
13699
13700
13701static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
13702 char *cmd)
13703{
13704 struct wpa_supplicant *wpa_s;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013705 int ret;
13706 unsigned int delete_iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013707
13708 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
13709
13710 wpa_s = wpa_supplicant_get_iface(global, cmd);
13711 if (wpa_s == NULL)
13712 return -1;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013713 delete_iface = wpa_s->added_vif;
13714 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
13715 if (!ret && delete_iface) {
13716 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
13717 cmd);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000013718 /* wpa_supplicant does not create multi-BSS AP, so collapse to
13719 * WPA_IF_STATION to avoid unwanted clean up in the driver. */
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013720 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
13721 }
13722 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013723}
13724
13725
13726static void wpa_free_iface_info(struct wpa_interface_info *iface)
13727{
13728 struct wpa_interface_info *prev;
13729
13730 while (iface) {
13731 prev = iface;
13732 iface = iface->next;
13733
13734 os_free(prev->ifname);
13735 os_free(prev->desc);
13736 os_free(prev);
13737 }
13738}
13739
13740
13741static int wpa_supplicant_global_iface_list(struct wpa_global *global,
13742 char *buf, int len)
13743{
13744 int i, res;
13745 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
13746 char *pos, *end;
13747
13748 for (i = 0; wpa_drivers[i]; i++) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070013749 const struct wpa_driver_ops *drv = wpa_drivers[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013750 if (drv->get_interfaces == NULL)
13751 continue;
13752 tmp = drv->get_interfaces(global->drv_priv[i]);
13753 if (tmp == NULL)
13754 continue;
13755
13756 if (last == NULL)
13757 iface = last = tmp;
13758 else
13759 last->next = tmp;
13760 while (last->next)
13761 last = last->next;
13762 }
13763
13764 pos = buf;
13765 end = buf + len;
13766 for (tmp = iface; tmp; tmp = tmp->next) {
13767 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
13768 tmp->drv_name, tmp->ifname,
13769 tmp->desc ? tmp->desc : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013770 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013771 *pos = '\0';
13772 break;
13773 }
13774 pos += res;
13775 }
13776
13777 wpa_free_iface_info(iface);
13778
13779 return pos - buf;
13780}
13781
13782
13783static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013784 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013785 char *buf, int len)
13786{
13787 int res;
13788 char *pos, *end;
13789 struct wpa_supplicant *wpa_s;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013790 int show_ctrl = 0;
13791
13792 if (input)
13793 show_ctrl = !!os_strstr(input, "ctrl");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013794
13795 wpa_s = global->ifaces;
13796 pos = buf;
13797 end = buf + len;
13798
13799 while (wpa_s) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013800 if (show_ctrl)
13801 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
13802 wpa_s->ifname,
13803 wpa_s->conf->ctrl_interface ?
13804 wpa_s->conf->ctrl_interface : "N/A");
13805 else
13806 res = os_snprintf(pos, end - pos, "%s\n",
13807 wpa_s->ifname);
13808
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013809 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013810 *pos = '\0';
13811 break;
13812 }
13813 pos += res;
13814 wpa_s = wpa_s->next;
13815 }
13816 return pos - buf;
13817}
13818
13819
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013820static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
13821 const char *ifname,
13822 char *cmd, size_t *resp_len)
13823{
13824 struct wpa_supplicant *wpa_s;
13825
13826 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
13827 if (os_strcmp(ifname, wpa_s->ifname) == 0)
13828 break;
13829 }
13830
13831 if (wpa_s == NULL) {
13832 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
13833 if (resp)
13834 *resp_len = os_strlen(resp);
13835 else
13836 *resp_len = 1;
13837 return resp;
13838 }
13839
13840 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
13841}
13842
13843
13844static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
13845 char *buf, size_t *resp_len)
13846{
13847#ifdef CONFIG_P2P
13848 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070013849 "LIST_NETWORKS",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013850 "P2P_FIND",
13851 "P2P_STOP_FIND",
13852 "P2P_LISTEN",
13853 "P2P_GROUP_ADD",
13854 "P2P_GET_PASSPHRASE",
13855 "P2P_SERVICE_UPDATE",
13856 "P2P_SERVICE_FLUSH",
13857 "P2P_FLUSH",
13858 "P2P_CANCEL",
13859 "P2P_PRESENCE_REQ",
13860 "P2P_EXT_LISTEN",
Paul Stewart092955c2017-02-06 09:13:09 -080013861#ifdef CONFIG_AP
13862 "STA-FIRST",
13863#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013864 NULL
13865 };
13866 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080013867#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070013868 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080013869#endif /* ANDROID */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013870 "GET_CAPABILITY ",
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070013871 "GET_NETWORK ",
13872 "REMOVE_NETWORK ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013873 "P2P_FIND ",
13874 "P2P_CONNECT ",
13875 "P2P_LISTEN ",
13876 "P2P_GROUP_REMOVE ",
13877 "P2P_GROUP_ADD ",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013878 "P2P_GROUP_MEMBER ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013879 "P2P_PROV_DISC ",
13880 "P2P_SERV_DISC_REQ ",
13881 "P2P_SERV_DISC_CANCEL_REQ ",
13882 "P2P_SERV_DISC_RESP ",
13883 "P2P_SERV_DISC_EXTERNAL ",
13884 "P2P_SERVICE_ADD ",
13885 "P2P_SERVICE_DEL ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080013886 "P2P_SERVICE_REP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013887 "P2P_REJECT ",
13888 "P2P_INVITE ",
13889 "P2P_PEER ",
13890 "P2P_SET ",
13891 "P2P_UNAUTHORIZE ",
13892 "P2P_PRESENCE_REQ ",
13893 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070013894 "P2P_REMOVE_CLIENT ",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080013895 "WPS_NFC_TOKEN ",
13896 "WPS_NFC_TAG_READ ",
Dmitry Shmidt413dde72014-04-11 10:23:22 -070013897 "NFC_GET_HANDOVER_SEL ",
13898 "NFC_GET_HANDOVER_REQ ",
13899 "NFC_REPORT_HANDOVER ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080013900 "P2P_ASP_PROVISION ",
13901 "P2P_ASP_PROVISION_RESP ",
Paul Stewart092955c2017-02-06 09:13:09 -080013902#ifdef CONFIG_AP
13903 "STA ",
13904 "STA-NEXT ",
13905#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013906 NULL
13907 };
13908 int found = 0;
13909 int i;
13910
13911 if (global->p2p_init_wpa_s == NULL)
13912 return NULL;
13913
13914 for (i = 0; !found && cmd[i]; i++) {
13915 if (os_strcmp(buf, cmd[i]) == 0)
13916 found = 1;
13917 }
13918
13919 for (i = 0; !found && prefix[i]; i++) {
13920 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
13921 found = 1;
13922 }
13923
13924 if (found)
13925 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
13926 buf, resp_len);
13927#endif /* CONFIG_P2P */
13928 return NULL;
13929}
13930
13931
13932static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
13933 char *buf, size_t *resp_len)
13934{
13935#ifdef CONFIG_WIFI_DISPLAY
13936 if (global->p2p_init_wpa_s == NULL)
13937 return NULL;
13938 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
13939 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
13940 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
13941 buf, resp_len);
13942#endif /* CONFIG_WIFI_DISPLAY */
13943 return NULL;
13944}
13945
13946
13947static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
13948 char *buf, size_t *resp_len)
13949{
13950 char *ret;
13951
13952 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
13953 if (ret)
13954 return ret;
13955
13956 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
13957 if (ret)
13958 return ret;
13959
13960 return NULL;
13961}
13962
13963
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013964static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
13965{
13966 char *value;
13967
13968 value = os_strchr(cmd, ' ');
13969 if (value == NULL)
13970 return -1;
13971 *value++ = '\0';
13972
13973 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
13974
13975#ifdef CONFIG_WIFI_DISPLAY
13976 if (os_strcasecmp(cmd, "wifi_display") == 0) {
13977 wifi_display_enable(global, !!atoi(value));
13978 return 0;
13979 }
13980#endif /* CONFIG_WIFI_DISPLAY */
13981
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013982 /* Restore cmd to its original value to allow redirection */
13983 value[-1] = ' ';
13984
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013985 return -1;
13986}
13987
13988
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013989static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
13990 char *cmd)
13991{
13992 struct wpa_supplicant *wpa_s[2]; /* src, dst */
13993 char *p;
13994 unsigned int i;
13995
13996 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
13997 * <variable name> */
13998
13999 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
14000 p = os_strchr(cmd, ' ');
14001 if (p == NULL)
14002 return -1;
14003 *p = '\0';
14004
14005 wpa_s[i] = global->ifaces;
14006 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
14007 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
14008 break;
14009 }
14010
14011 if (!wpa_s[i]) {
14012 wpa_printf(MSG_DEBUG,
14013 "CTRL_IFACE: Could not find iface=%s", cmd);
14014 return -1;
14015 }
14016
14017 cmd = p + 1;
14018 }
14019
14020 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
14021}
14022
14023
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014024#ifndef CONFIG_NO_CONFIG_WRITE
14025static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
14026{
Dmitry Shmidt61593f02014-04-21 16:27:35 -070014027 int ret = 0, saved = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014028 struct wpa_supplicant *wpa_s;
14029
14030 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
14031 if (!wpa_s->conf->update_config) {
14032 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
14033 continue;
14034 }
14035
14036 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
14037 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
14038 ret = 1;
14039 } else {
14040 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
Dmitry Shmidt61593f02014-04-21 16:27:35 -070014041 saved++;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014042 }
14043 }
14044
Dmitry Shmidt61593f02014-04-21 16:27:35 -070014045 if (!saved && !ret) {
14046 wpa_dbg(wpa_s, MSG_DEBUG,
14047 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
14048 ret = 1;
14049 }
14050
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014051 return ret;
14052}
14053#endif /* CONFIG_NO_CONFIG_WRITE */
14054
14055
14056static int wpas_global_ctrl_iface_status(struct wpa_global *global,
14057 char *buf, size_t buflen)
14058{
14059 char *pos, *end;
14060 int ret;
14061 struct wpa_supplicant *wpa_s;
14062
14063 pos = buf;
14064 end = buf + buflen;
14065
14066#ifdef CONFIG_P2P
14067 if (global->p2p && !global->p2p_disabled) {
14068 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
14069 "\n"
14070 "p2p_state=%s\n",
14071 MAC2STR(global->p2p_dev_addr),
14072 p2p_get_state_txt(global->p2p));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014073 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014074 return pos - buf;
14075 pos += ret;
14076 } else if (global->p2p) {
14077 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014078 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014079 return pos - buf;
14080 pos += ret;
14081 }
14082#endif /* CONFIG_P2P */
14083
14084#ifdef CONFIG_WIFI_DISPLAY
14085 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
14086 !!global->wifi_display);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014087 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014088 return pos - buf;
14089 pos += ret;
14090#endif /* CONFIG_WIFI_DISPLAY */
14091
14092 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
14093 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
14094 "address=" MACSTR "\n",
14095 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014096 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014097 return pos - buf;
14098 pos += ret;
14099 }
14100
14101 return pos - buf;
14102}
14103
14104
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080014105#ifdef CONFIG_FST
14106
14107static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
14108 char *cmd, char *buf,
14109 size_t reply_size)
14110{
14111 char ifname[IFNAMSIZ + 1];
14112 struct fst_iface_cfg cfg;
14113 struct wpa_supplicant *wpa_s;
14114 struct fst_wpa_obj iface_obj;
14115
14116 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
14117 wpa_s = wpa_supplicant_get_iface(global, ifname);
14118 if (wpa_s) {
14119 if (wpa_s->fst) {
14120 wpa_printf(MSG_INFO, "FST: Already attached");
14121 return -1;
14122 }
14123 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
14124 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
14125 &iface_obj, &cfg);
14126 if (wpa_s->fst)
14127 return os_snprintf(buf, reply_size, "OK\n");
14128 }
14129 }
14130
14131 return -1;
14132}
14133
14134
14135static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
14136 char *cmd, char *buf,
14137 size_t reply_size)
14138{
14139 char ifname[IFNAMSIZ + 1];
14140 struct wpa_supplicant *wpa_s;
14141
14142 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
14143 wpa_s = wpa_supplicant_get_iface(global, ifname);
14144 if (wpa_s) {
14145 if (!fst_iface_detach(ifname)) {
14146 wpa_s->fst = NULL;
14147 return os_snprintf(buf, reply_size, "OK\n");
14148 }
14149 }
14150 }
14151
14152 return -1;
14153}
14154
14155#endif /* CONFIG_FST */
14156
14157
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014158char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
14159 char *buf, size_t *resp_len)
14160{
14161 char *reply;
14162 const int reply_size = 2048;
14163 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014164 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014165
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070014166 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
14167 char *pos = os_strchr(buf + 7, ' ');
14168 if (pos) {
14169 *pos++ = '\0';
14170 return wpas_global_ctrl_iface_ifname(global,
14171 buf + 7, pos,
14172 resp_len);
14173 }
14174 }
14175
14176 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
14177 if (reply)
14178 return reply;
14179
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014180 if (os_strcmp(buf, "PING") == 0)
14181 level = MSG_EXCESSIVE;
14182 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014183 (const u8 *) buf, os_strlen(buf));
14184
14185 reply = os_malloc(reply_size);
14186 if (reply == NULL) {
14187 *resp_len = 1;
14188 return NULL;
14189 }
14190
14191 os_memcpy(reply, "OK\n", 3);
14192 reply_len = 3;
14193
14194 if (os_strcmp(buf, "PING") == 0) {
14195 os_memcpy(reply, "PONG\n", 5);
14196 reply_len = 5;
14197 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
14198 if (wpa_supplicant_global_iface_add(global, buf + 14))
14199 reply_len = -1;
14200 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
14201 if (wpa_supplicant_global_iface_remove(global, buf + 17))
14202 reply_len = -1;
14203 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
14204 reply_len = wpa_supplicant_global_iface_list(
14205 global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080014206 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014207 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080014208 global, buf + 10, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080014209#ifdef CONFIG_FST
14210 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
14211 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
14212 reply,
14213 reply_size);
14214 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
14215 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
14216 reply,
14217 reply_size);
14218 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
14219 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
14220#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014221 } else if (os_strcmp(buf, "TERMINATE") == 0) {
14222 wpa_supplicant_terminate_proc(global);
14223 } else if (os_strcmp(buf, "SUSPEND") == 0) {
14224 wpas_notify_suspend(global);
14225 } else if (os_strcmp(buf, "RESUME") == 0) {
14226 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014227 } else if (os_strncmp(buf, "SET ", 4) == 0) {
Dmitry Shmidt61593f02014-04-21 16:27:35 -070014228 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
14229#ifdef CONFIG_P2P
14230 if (global->p2p_init_wpa_s) {
14231 os_free(reply);
14232 /* Check if P2P redirection would work for this
14233 * command. */
14234 return wpa_supplicant_ctrl_iface_process(
14235 global->p2p_init_wpa_s,
14236 buf, resp_len);
14237 }
14238#endif /* CONFIG_P2P */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014239 reply_len = -1;
Dmitry Shmidt61593f02014-04-21 16:27:35 -070014240 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080014241 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
14242 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
14243 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014244#ifndef CONFIG_NO_CONFIG_WRITE
14245 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
14246 if (wpas_global_ctrl_iface_save_config(global))
14247 reply_len = -1;
14248#endif /* CONFIG_NO_CONFIG_WRITE */
14249 } else if (os_strcmp(buf, "STATUS") == 0) {
14250 reply_len = wpas_global_ctrl_iface_status(global, reply,
14251 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080014252#ifdef CONFIG_MODULE_TESTS
14253 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080014254 if (wpas_module_tests() < 0)
14255 reply_len = -1;
14256#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014257 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
14258 if (wpa_debug_reopen_file() < 0)
14259 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014260 } else {
14261 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
14262 reply_len = 16;
14263 }
14264
14265 if (reply_len < 0) {
14266 os_memcpy(reply, "FAIL\n", 5);
14267 reply_len = 5;
14268 }
14269
14270 *resp_len = reply_len;
14271 return reply;
14272}