blob: 6dba46898d505f04e232f8eadf790235d907622b [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 Ravi99c035e2024-07-12 01:42:03 +0000905 int val = atoi(value);
906
907 if (val < MBO_CELL_CAPA_AVAILABLE ||
908 val > MBO_CELL_CAPA_NOT_SUPPORTED)
909 return -1;
910
911 wpas_mbo_update_cell_capa(wpa_s, val);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700912 } else if (os_strcasecmp(cmd, "oce") == 0) {
Sunil Ravi99c035e2024-07-12 01:42:03 +0000913 int val = atoi(value);
914
915 if (val < 0 || val > 3)
916 return -1;
917
918 wpa_s->conf->oce = val;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700919 if (wpa_s->conf->oce) {
920 if ((wpa_s->conf->oce & OCE_STA) &&
921 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
922 wpa_s->enable_oce = OCE_STA;
923
924 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
925 (wpa_s->drv_flags &
926 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
927 /* TODO: Need to add STA-CFON support */
928 wpa_printf(MSG_ERROR,
929 "OCE STA-CFON feature is not yet supported");
930 return -1;
931 }
932 } else {
933 wpa_s->enable_oce = 0;
934 }
935 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800936#endif /* CONFIG_MBO */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700937 } else if (os_strcasecmp(cmd, "lci") == 0) {
938 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800939 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
940 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800941 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
942 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
943 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
944 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
945 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
946 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700947 } else if (os_strcasecmp(cmd, "roaming") == 0) {
948 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800949#ifdef CONFIG_WNM
950 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
951 struct wpabuf *elems;
952
953 elems = wpabuf_parse_bin(value);
954 if (!elems)
955 return -1;
956 wnm_set_coloc_intf_elems(wpa_s, elems);
957#endif /* CONFIG_WNM */
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000958#ifndef CONFIG_NO_ROBUST_AV
Hai Shaloma20dcd72022-02-04 13:43:00 -0800959 } else if (os_strcasecmp(cmd, "enable_dscp_policy_capa") == 0) {
960 wpa_s->enable_dscp_policy_capa = !!atoi(value);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000961#endif /* CONFIG_NO_ROBUST_AV */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962 } else {
963 value[-1] = '=';
964 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
965 if (ret == 0)
966 wpa_supplicant_update_config(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -0700967 else if (ret == 1)
968 ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700969 }
970
971 return ret;
972}
973
974
975static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
976 char *cmd, char *buf, size_t buflen)
977{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700978 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700979
980 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
981
982 if (os_strcmp(cmd, "version") == 0) {
983 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700984 } else if (os_strcasecmp(cmd, "max_command_len") == 0) {
985 res = os_snprintf(buf, buflen, "%u", CTRL_IFACE_MAX_LEN);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700986 } else if (os_strcasecmp(cmd, "country") == 0) {
987 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
988 res = os_snprintf(buf, buflen, "%c%c",
989 wpa_s->conf->country[0],
990 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700991#ifdef CONFIG_WIFI_DISPLAY
992 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800993 int enabled;
994 if (wpa_s->global->p2p == NULL ||
995 wpa_s->global->p2p_disabled)
996 enabled = 0;
997 else
998 enabled = wpa_s->global->wifi_display;
999 res = os_snprintf(buf, buflen, "%d", enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001000#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001001#ifdef CONFIG_TESTING_GET_GTK
1002 } else if (os_strcmp(cmd, "gtk") == 0) {
1003 if (wpa_s->last_gtk_len == 0)
1004 return -1;
1005 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
1006 wpa_s->last_gtk_len);
1007 return res;
1008#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001009 } else if (os_strcmp(cmd, "tls_library") == 0) {
1010 res = tls_get_library_version(buf, buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001011#ifdef CONFIG_TESTING_OPTIONS
1012 } else if (os_strcmp(cmd, "anonce") == 0) {
1013 return wpa_snprintf_hex(buf, buflen,
1014 wpa_sm_get_anonce(wpa_s->wpa),
1015 WPA_NONCE_LEN);
Hai Shalomfdcde762020-04-02 11:19:20 -07001016 } else if (os_strcasecmp(cmd, "last_tk_key_idx") == 0) {
1017 res = os_snprintf(buf, buflen, "%d", wpa_s->last_tk_key_idx);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001018#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001019 } else {
1020 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001021 }
1022
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001023 if (os_snprintf_error(buflen, res))
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -07001024 return -1;
1025 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001026}
1027
1028
1029#ifdef IEEE8021X_EAPOL
1030static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
1031 char *addr)
1032{
1033 u8 bssid[ETH_ALEN];
1034 struct wpa_ssid *ssid = wpa_s->current_ssid;
1035
1036 if (hwaddr_aton(addr, bssid)) {
1037 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
1038 "'%s'", addr);
1039 return -1;
1040 }
1041
1042 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
1043 rsn_preauth_deinit(wpa_s->wpa);
1044 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
1045 return -1;
1046
1047 return 0;
1048}
1049#endif /* IEEE8021X_EAPOL */
1050
1051
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001052#ifdef CONFIG_TDLS
1053
1054static int wpa_supplicant_ctrl_iface_tdls_discover(
1055 struct wpa_supplicant *wpa_s, char *addr)
1056{
1057 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001058 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001059
1060 if (hwaddr_aton(addr, peer)) {
1061 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
1062 "address '%s'", addr);
1063 return -1;
1064 }
1065
1066 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
1067 MAC2STR(peer));
1068
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001069 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1070 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
1071 else
1072 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
1073
1074 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001075}
1076
1077
1078static int wpa_supplicant_ctrl_iface_tdls_setup(
1079 struct wpa_supplicant *wpa_s, char *addr)
1080{
1081 u8 peer[ETH_ALEN];
1082 int ret;
1083
1084 if (hwaddr_aton(addr, peer)) {
1085 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
1086 "address '%s'", addr);
1087 return -1;
1088 }
1089
1090 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
1091 MAC2STR(peer));
1092
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001093 if ((wpa_s->conf->tdls_external_control) &&
1094 wpa_tdls_is_external_setup(wpa_s->wpa))
1095 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
1096
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001097 wpa_tdls_remove(wpa_s->wpa, peer);
1098
1099 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1100 ret = wpa_tdls_start(wpa_s->wpa, peer);
1101 else
1102 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001103
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001104 return ret;
1105}
1106
1107
1108static int wpa_supplicant_ctrl_iface_tdls_teardown(
1109 struct wpa_supplicant *wpa_s, char *addr)
1110{
1111 u8 peer[ETH_ALEN];
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001112 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001114 if (os_strcmp(addr, "*") == 0) {
1115 /* remove everyone */
1116 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
1117 wpa_tdls_teardown_peers(wpa_s->wpa);
1118 return 0;
1119 }
1120
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121 if (hwaddr_aton(addr, peer)) {
1122 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
1123 "address '%s'", addr);
1124 return -1;
1125 }
1126
1127 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
1128 MAC2STR(peer));
1129
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001130 if ((wpa_s->conf->tdls_external_control) &&
1131 wpa_tdls_is_external_setup(wpa_s->wpa))
1132 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1133
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001134 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1135 ret = wpa_tdls_teardown_link(
1136 wpa_s->wpa, peer,
1137 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
1138 else
1139 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1140
1141 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001142}
1143
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001144
1145static int ctrl_iface_get_capability_tdls(
1146 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1147{
1148 int ret;
1149
1150 ret = os_snprintf(buf, buflen, "%s\n",
1151 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
1152 (wpa_s->drv_flags &
1153 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
1154 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001155 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001156 return -1;
1157 return ret;
1158}
1159
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001160
1161static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
1162 struct wpa_supplicant *wpa_s, char *cmd)
1163{
1164 u8 peer[ETH_ALEN];
1165 struct hostapd_freq_params freq_params;
1166 u8 oper_class;
1167 char *pos, *end;
1168
1169 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1170 wpa_printf(MSG_INFO,
1171 "tdls_chanswitch: Only supported with external setup");
1172 return -1;
1173 }
1174
1175 os_memset(&freq_params, 0, sizeof(freq_params));
1176
1177 pos = os_strchr(cmd, ' ');
1178 if (pos == NULL)
1179 return -1;
1180 *pos++ = '\0';
1181
1182 oper_class = strtol(pos, &end, 10);
1183 if (pos == end) {
1184 wpa_printf(MSG_INFO,
1185 "tdls_chanswitch: Invalid op class provided");
1186 return -1;
1187 }
1188
1189 pos = end;
1190 freq_params.freq = atoi(pos);
1191 if (freq_params.freq == 0) {
1192 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
1193 return -1;
1194 }
1195
1196#define SET_FREQ_SETTING(str) \
1197 do { \
1198 const char *pos2 = os_strstr(pos, " " #str "="); \
1199 if (pos2) { \
1200 pos2 += sizeof(" " #str "=") - 1; \
1201 freq_params.str = atoi(pos2); \
1202 } \
1203 } while (0)
1204
1205 SET_FREQ_SETTING(center_freq1);
1206 SET_FREQ_SETTING(center_freq2);
1207 SET_FREQ_SETTING(bandwidth);
1208 SET_FREQ_SETTING(sec_channel_offset);
1209#undef SET_FREQ_SETTING
1210
1211 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1212 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1213
1214 if (hwaddr_aton(cmd, peer)) {
1215 wpa_printf(MSG_DEBUG,
1216 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1217 cmd);
1218 return -1;
1219 }
1220
1221 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1222 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1223 MAC2STR(peer), oper_class, freq_params.freq,
1224 freq_params.center_freq1, freq_params.center_freq2,
1225 freq_params.bandwidth, freq_params.sec_channel_offset,
1226 freq_params.ht_enabled ? " HT" : "",
1227 freq_params.vht_enabled ? " VHT" : "");
1228
1229 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1230 &freq_params);
1231}
1232
1233
1234static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1235 struct wpa_supplicant *wpa_s, char *cmd)
1236{
1237 u8 peer[ETH_ALEN];
1238
1239 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1240 wpa_printf(MSG_INFO,
1241 "tdls_chanswitch: Only supported with external setup");
1242 return -1;
1243 }
1244
1245 if (hwaddr_aton(cmd, peer)) {
1246 wpa_printf(MSG_DEBUG,
1247 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1248 cmd);
1249 return -1;
1250 }
1251
1252 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1253 MAC2STR(peer));
1254
1255 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1256}
1257
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07001258
1259static int wpa_supplicant_ctrl_iface_tdls_link_status(
1260 struct wpa_supplicant *wpa_s, const char *addr,
1261 char *buf, size_t buflen)
1262{
1263 u8 peer[ETH_ALEN];
1264 const char *tdls_status;
1265 int ret;
1266
1267 if (hwaddr_aton(addr, peer)) {
1268 wpa_printf(MSG_DEBUG,
1269 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1270 addr);
1271 return -1;
1272 }
1273 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1274 MAC2STR(peer));
1275
1276 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1277 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1278 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1279 if (os_snprintf_error(buflen, ret))
1280 return -1;
1281
1282 return ret;
1283}
1284
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001285#endif /* CONFIG_TDLS */
1286
1287
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001288#ifndef CONFIG_NO_WMM_AC
1289
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001290static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1291{
1292 char *token, *context = NULL;
1293 struct wmm_ac_ts_setup_params params = {
1294 .tsid = 0xff,
1295 .direction = 0xff,
1296 };
1297
1298 while ((token = str_token(cmd, " ", &context))) {
1299 if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
1300 sscanf(token, "up=%i", &params.user_priority) == 1 ||
1301 sscanf(token, "nominal_msdu_size=%i",
1302 &params.nominal_msdu_size) == 1 ||
1303 sscanf(token, "mean_data_rate=%i",
1304 &params.mean_data_rate) == 1 ||
1305 sscanf(token, "min_phy_rate=%i",
1306 &params.minimum_phy_rate) == 1 ||
1307 sscanf(token, "sba=%i",
1308 &params.surplus_bandwidth_allowance) == 1)
1309 continue;
1310
1311 if (os_strcasecmp(token, "downlink") == 0) {
1312 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1313 } else if (os_strcasecmp(token, "uplink") == 0) {
1314 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1315 } else if (os_strcasecmp(token, "bidi") == 0) {
1316 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1317 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1318 params.fixed_nominal_msdu = 1;
1319 } else {
1320 wpa_printf(MSG_DEBUG,
1321 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1322 token);
1323 return -1;
1324 }
1325
1326 }
1327
1328 return wpas_wmm_ac_addts(wpa_s, &params);
1329}
1330
1331
1332static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1333{
1334 u8 tsid = atoi(cmd);
1335
1336 return wpas_wmm_ac_delts(wpa_s, tsid);
1337}
1338
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001339#endif /* CONFIG_NO_WMM_AC */
1340
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001341
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001342#ifdef CONFIG_IEEE80211R
1343static int wpa_supplicant_ctrl_iface_ft_ds(
1344 struct wpa_supplicant *wpa_s, char *addr)
1345{
1346 u8 target_ap[ETH_ALEN];
1347 struct wpa_bss *bss;
1348 const u8 *mdie;
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00001349 bool force = os_strstr(addr, " force") != NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001350
1351 if (hwaddr_aton(addr, target_ap)) {
1352 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1353 "address '%s'", addr);
1354 return -1;
1355 }
1356
1357 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1358
1359 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1360 if (bss)
1361 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1362 else
1363 mdie = NULL;
1364
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00001365 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie, force);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001366}
1367#endif /* CONFIG_IEEE80211R */
1368
1369
1370#ifdef CONFIG_WPS
1371static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1372 char *cmd)
1373{
1374 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001375#ifdef CONFIG_P2P
1376 u8 p2p_dev_addr[ETH_ALEN];
1377#endif /* CONFIG_P2P */
1378#ifdef CONFIG_AP
1379 u8 *_p2p_dev_addr = NULL;
1380#endif /* CONFIG_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001381 char *pos;
1382 int multi_ap = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001383
Hai Shalom021b0b52019-04-10 11:17:58 -07001384 if (!cmd || os_strcmp(cmd, "any") == 0 ||
1385 os_strncmp(cmd, "any ", 4) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001386 _bssid = NULL;
1387#ifdef CONFIG_P2P
1388 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1389 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1390 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1391 "P2P Device Address '%s'",
1392 cmd + 13);
1393 return -1;
1394 }
1395 _p2p_dev_addr = p2p_dev_addr;
1396#endif /* CONFIG_P2P */
Hai Shalom021b0b52019-04-10 11:17:58 -07001397 } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) {
1398 _bssid = NULL;
1399 multi_ap = atoi(cmd + 9);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001400 } else if (hwaddr_aton(cmd, bssid)) {
1401 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1402 cmd);
1403 return -1;
1404 }
1405
Hai Shalom021b0b52019-04-10 11:17:58 -07001406 if (cmd) {
1407 pos = os_strstr(cmd, " multi_ap=");
1408 if (pos) {
1409 pos += 10;
1410 multi_ap = atoi(pos);
1411 }
1412 }
1413
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001414#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001415 if (wpa_s->ap_iface)
1416 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1417#endif /* CONFIG_AP */
1418
Hai Shalom021b0b52019-04-10 11:17:58 -07001419 return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001420}
1421
1422
1423static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1424 char *cmd, char *buf,
1425 size_t buflen)
1426{
1427 u8 bssid[ETH_ALEN], *_bssid = bssid;
1428 char *pin;
1429 int ret;
1430
1431 pin = os_strchr(cmd, ' ');
1432 if (pin)
1433 *pin++ = '\0';
1434
1435 if (os_strcmp(cmd, "any") == 0)
1436 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001437 else if (os_strcmp(cmd, "get") == 0) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001438 if (wps_generate_pin((unsigned int *) &ret) < 0)
1439 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001440 goto done;
1441 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001442 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1443 cmd);
1444 return -1;
1445 }
1446
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001447#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001448 if (wpa_s->ap_iface) {
1449 int timeout = 0;
1450 char *pos;
1451
1452 if (pin) {
1453 pos = os_strchr(pin, ' ');
1454 if (pos) {
1455 *pos++ = '\0';
1456 timeout = atoi(pos);
1457 }
1458 }
1459
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001460 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001461 buf, buflen, timeout);
1462 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001463#endif /* CONFIG_AP */
1464
1465 if (pin) {
1466 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1467 DEV_PW_DEFAULT);
1468 if (ret < 0)
1469 return -1;
1470 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001471 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001472 return -1;
1473 return ret;
1474 }
1475
1476 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1477 if (ret < 0)
1478 return -1;
1479
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001480done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001481 /* Return the generated PIN */
1482 ret = os_snprintf(buf, buflen, "%08d", ret);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001483 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001484 return -1;
1485 return ret;
1486}
1487
1488
1489static int wpa_supplicant_ctrl_iface_wps_check_pin(
1490 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1491{
1492 char pin[9];
1493 size_t len;
1494 char *pos;
1495 int ret;
1496
1497 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1498 (u8 *) cmd, os_strlen(cmd));
1499 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1500 if (*pos < '0' || *pos > '9')
1501 continue;
1502 pin[len++] = *pos;
1503 if (len == 9) {
1504 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1505 return -1;
1506 }
1507 }
1508 if (len != 4 && len != 8) {
1509 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1510 return -1;
1511 }
1512 pin[len] = '\0';
1513
1514 if (len == 8) {
1515 unsigned int pin_val;
1516 pin_val = atoi(pin);
1517 if (!wps_pin_valid(pin_val)) {
1518 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1519 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001520 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001521 return -1;
1522 return ret;
1523 }
1524 }
1525
1526 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001527 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001528 return -1;
1529
1530 return ret;
1531}
1532
1533
Dmitry Shmidt04949592012-07-19 12:16:46 -07001534#ifdef CONFIG_WPS_NFC
1535
1536static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1537 char *cmd)
1538{
1539 u8 bssid[ETH_ALEN], *_bssid = bssid;
1540
1541 if (cmd == NULL || cmd[0] == '\0')
1542 _bssid = NULL;
1543 else if (hwaddr_aton(cmd, bssid))
1544 return -1;
1545
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001546 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1547 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001548}
1549
1550
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001551static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1552 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1553{
1554 int ndef;
1555 struct wpabuf *buf;
1556 int res;
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001557 char *pos;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001558
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001559 pos = os_strchr(cmd, ' ');
1560 if (pos)
1561 *pos++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001562 if (os_strcmp(cmd, "WPS") == 0)
1563 ndef = 0;
1564 else if (os_strcmp(cmd, "NDEF") == 0)
1565 ndef = 1;
1566 else
1567 return -1;
1568
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001569 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001570 if (buf == NULL)
1571 return -1;
1572
1573 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1574 wpabuf_len(buf));
1575 reply[res++] = '\n';
1576 reply[res] = '\0';
1577
1578 wpabuf_free(buf);
1579
1580 return res;
1581}
1582
1583
Dmitry Shmidt04949592012-07-19 12:16:46 -07001584static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1585 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1586{
1587 int ndef;
1588 struct wpabuf *buf;
1589 int res;
1590
1591 if (os_strcmp(cmd, "WPS") == 0)
1592 ndef = 0;
1593 else if (os_strcmp(cmd, "NDEF") == 0)
1594 ndef = 1;
1595 else
1596 return -1;
1597
1598 buf = wpas_wps_nfc_token(wpa_s, ndef);
1599 if (buf == NULL)
1600 return -1;
1601
1602 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1603 wpabuf_len(buf));
1604 reply[res++] = '\n';
1605 reply[res] = '\0';
1606
1607 wpabuf_free(buf);
1608
1609 return res;
1610}
1611
1612
1613static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1614 struct wpa_supplicant *wpa_s, char *pos)
1615{
1616 size_t len;
1617 struct wpabuf *buf;
1618 int ret;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001619 char *freq;
1620 int forced_freq = 0;
1621
1622 freq = strstr(pos, " freq=");
1623 if (freq) {
1624 *freq = '\0';
1625 freq += 6;
1626 forced_freq = atoi(freq);
1627 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001628
1629 len = os_strlen(pos);
1630 if (len & 0x01)
1631 return -1;
1632 len /= 2;
1633
1634 buf = wpabuf_alloc(len);
1635 if (buf == NULL)
1636 return -1;
1637 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1638 wpabuf_free(buf);
1639 return -1;
1640 }
1641
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001642 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001643 wpabuf_free(buf);
1644
1645 return ret;
1646}
1647
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001648
1649static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001650 char *reply, size_t max_len,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001651 int ndef)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001652{
1653 struct wpabuf *buf;
1654 int res;
1655
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001656 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001657 if (buf == NULL)
1658 return -1;
1659
1660 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1661 wpabuf_len(buf));
1662 reply[res++] = '\n';
1663 reply[res] = '\0';
1664
1665 wpabuf_free(buf);
1666
1667 return res;
1668}
1669
1670
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001671#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001672static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1673 char *reply, size_t max_len,
1674 int ndef)
1675{
1676 struct wpabuf *buf;
1677 int res;
1678
1679 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1680 if (buf == NULL) {
1681 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1682 return -1;
1683 }
1684
1685 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1686 wpabuf_len(buf));
1687 reply[res++] = '\n';
1688 reply[res] = '\0';
1689
1690 wpabuf_free(buf);
1691
1692 return res;
1693}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001694#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001695
1696
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001697static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1698 char *cmd, char *reply,
1699 size_t max_len)
1700{
1701 char *pos;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001702 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001703
1704 pos = os_strchr(cmd, ' ');
1705 if (pos == NULL)
1706 return -1;
1707 *pos++ = '\0';
1708
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001709 if (os_strcmp(cmd, "WPS") == 0)
1710 ndef = 0;
1711 else if (os_strcmp(cmd, "NDEF") == 0)
1712 ndef = 1;
1713 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001714 return -1;
1715
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001716 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001717 if (!ndef)
1718 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001719 return wpas_ctrl_nfc_get_handover_req_wps(
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001720 wpa_s, reply, max_len, ndef);
1721 }
1722
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001723#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001724 if (os_strcmp(pos, "P2P-CR") == 0) {
1725 return wpas_ctrl_nfc_get_handover_req_p2p(
1726 wpa_s, reply, max_len, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001727 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001728#endif /* CONFIG_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001729
1730 return -1;
1731}
1732
1733
1734static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001735 char *reply, size_t max_len,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001736 int ndef, int cr, char *uuid)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001737{
1738 struct wpabuf *buf;
1739 int res;
1740
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001741 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001742 if (buf == NULL)
1743 return -1;
1744
1745 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1746 wpabuf_len(buf));
1747 reply[res++] = '\n';
1748 reply[res] = '\0';
1749
1750 wpabuf_free(buf);
1751
1752 return res;
1753}
1754
1755
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001756#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001757static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1758 char *reply, size_t max_len,
1759 int ndef, int tag)
1760{
1761 struct wpabuf *buf;
1762 int res;
1763
1764 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1765 if (buf == NULL)
1766 return -1;
1767
1768 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1769 wpabuf_len(buf));
1770 reply[res++] = '\n';
1771 reply[res] = '\0';
1772
1773 wpabuf_free(buf);
1774
1775 return res;
1776}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001777#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001778
1779
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001780static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1781 char *cmd, char *reply,
1782 size_t max_len)
1783{
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001784 char *pos, *pos2;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001785 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001786
1787 pos = os_strchr(cmd, ' ');
1788 if (pos == NULL)
1789 return -1;
1790 *pos++ = '\0';
1791
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001792 if (os_strcmp(cmd, "WPS") == 0)
1793 ndef = 0;
1794 else if (os_strcmp(cmd, "NDEF") == 0)
1795 ndef = 1;
1796 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001797 return -1;
1798
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001799 pos2 = os_strchr(pos, ' ');
1800 if (pos2)
1801 *pos2++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001802 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001803 if (!ndef)
1804 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001805 return wpas_ctrl_nfc_get_handover_sel_wps(
1806 wpa_s, reply, max_len, ndef,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001807 os_strcmp(pos, "WPS-CR") == 0, pos2);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001808 }
1809
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001810#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001811 if (os_strcmp(pos, "P2P-CR") == 0) {
1812 return wpas_ctrl_nfc_get_handover_sel_p2p(
1813 wpa_s, reply, max_len, ndef, 0);
1814 }
1815
1816 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1817 return wpas_ctrl_nfc_get_handover_sel_p2p(
1818 wpa_s, reply, max_len, ndef, 1);
1819 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001820#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001821
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001822 return -1;
1823}
1824
1825
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001826static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1827 char *cmd)
1828{
1829 size_t len;
1830 struct wpabuf *req, *sel;
1831 int ret;
1832 char *pos, *role, *type, *pos2;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001833#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001834 char *freq;
1835 int forced_freq = 0;
1836
1837 freq = strstr(cmd, " freq=");
1838 if (freq) {
1839 *freq = '\0';
1840 freq += 6;
1841 forced_freq = atoi(freq);
1842 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001843#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001844
1845 role = cmd;
1846 pos = os_strchr(role, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001847 if (pos == NULL) {
1848 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001849 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001850 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001851 *pos++ = '\0';
1852
1853 type = pos;
1854 pos = os_strchr(type, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001855 if (pos == NULL) {
1856 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001857 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001858 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001859 *pos++ = '\0';
1860
1861 pos2 = os_strchr(pos, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001862 if (pos2 == NULL) {
1863 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001864 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001865 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001866 *pos2++ = '\0';
1867
1868 len = os_strlen(pos);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001869 if (len & 0x01) {
1870 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001871 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001872 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001873 len /= 2;
1874
1875 req = wpabuf_alloc(len);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001876 if (req == NULL) {
1877 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001878 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001879 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001880 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001881 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001882 wpabuf_free(req);
1883 return -1;
1884 }
1885
1886 len = os_strlen(pos2);
1887 if (len & 0x01) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001888 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001889 wpabuf_free(req);
1890 return -1;
1891 }
1892 len /= 2;
1893
1894 sel = wpabuf_alloc(len);
1895 if (sel == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001896 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001897 wpabuf_free(req);
1898 return -1;
1899 }
1900 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001901 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001902 wpabuf_free(req);
1903 wpabuf_free(sel);
1904 return -1;
1905 }
1906
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001907 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1908 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1909
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001910 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1911 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001912#ifdef CONFIG_AP
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001913 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1914 {
1915 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1916 if (ret < 0)
1917 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001918#endif /* CONFIG_AP */
1919#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001920 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1921 {
1922 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1923 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1924 {
1925 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1926 forced_freq);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001927#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001928 } else {
1929 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1930 "reported: role=%s type=%s", role, type);
1931 ret = -1;
1932 }
1933 wpabuf_free(req);
1934 wpabuf_free(sel);
1935
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001936 if (ret)
1937 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1938
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001939 return ret;
1940}
1941
Dmitry Shmidt04949592012-07-19 12:16:46 -07001942#endif /* CONFIG_WPS_NFC */
1943
1944
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001945static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1946 char *cmd)
1947{
1948 u8 bssid[ETH_ALEN];
1949 char *pin;
1950 char *new_ssid;
1951 char *new_auth;
1952 char *new_encr;
1953 char *new_key;
1954 struct wps_new_ap_settings ap;
1955
1956 pin = os_strchr(cmd, ' ');
1957 if (pin == NULL)
1958 return -1;
1959 *pin++ = '\0';
1960
1961 if (hwaddr_aton(cmd, bssid)) {
1962 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1963 cmd);
1964 return -1;
1965 }
1966
1967 new_ssid = os_strchr(pin, ' ');
1968 if (new_ssid == NULL)
1969 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1970 *new_ssid++ = '\0';
1971
1972 new_auth = os_strchr(new_ssid, ' ');
1973 if (new_auth == NULL)
1974 return -1;
1975 *new_auth++ = '\0';
1976
1977 new_encr = os_strchr(new_auth, ' ');
1978 if (new_encr == NULL)
1979 return -1;
1980 *new_encr++ = '\0';
1981
1982 new_key = os_strchr(new_encr, ' ');
1983 if (new_key == NULL)
1984 return -1;
1985 *new_key++ = '\0';
1986
1987 os_memset(&ap, 0, sizeof(ap));
1988 ap.ssid_hex = new_ssid;
1989 ap.auth = new_auth;
1990 ap.encr = new_encr;
1991 ap.key_hex = new_key;
1992 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1993}
1994
1995
1996#ifdef CONFIG_AP
1997static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1998 char *cmd, char *buf,
1999 size_t buflen)
2000{
2001 int timeout = 300;
2002 char *pos;
2003 const char *pin_txt;
2004
2005 if (!wpa_s->ap_iface)
2006 return -1;
2007
2008 pos = os_strchr(cmd, ' ');
2009 if (pos)
2010 *pos++ = '\0';
2011
2012 if (os_strcmp(cmd, "disable") == 0) {
2013 wpas_wps_ap_pin_disable(wpa_s);
2014 return os_snprintf(buf, buflen, "OK\n");
2015 }
2016
2017 if (os_strcmp(cmd, "random") == 0) {
2018 if (pos)
2019 timeout = atoi(pos);
2020 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
2021 if (pin_txt == NULL)
2022 return -1;
2023 return os_snprintf(buf, buflen, "%s", pin_txt);
2024 }
2025
2026 if (os_strcmp(cmd, "get") == 0) {
2027 pin_txt = wpas_wps_ap_pin_get(wpa_s);
2028 if (pin_txt == NULL)
2029 return -1;
2030 return os_snprintf(buf, buflen, "%s", pin_txt);
2031 }
2032
2033 if (os_strcmp(cmd, "set") == 0) {
2034 char *pin;
2035 if (pos == NULL)
2036 return -1;
2037 pin = pos;
2038 pos = os_strchr(pos, ' ');
2039 if (pos) {
2040 *pos++ = '\0';
2041 timeout = atoi(pos);
2042 }
2043 if (os_strlen(pin) > buflen)
2044 return -1;
2045 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
2046 return -1;
2047 return os_snprintf(buf, buflen, "%s", pin);
2048 }
2049
2050 return -1;
2051}
2052#endif /* CONFIG_AP */
2053
2054
2055#ifdef CONFIG_WPS_ER
2056static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
2057 char *cmd)
2058{
2059 char *uuid = cmd, *pin, *pos;
2060 u8 addr_buf[ETH_ALEN], *addr = NULL;
2061 pin = os_strchr(uuid, ' ');
2062 if (pin == NULL)
2063 return -1;
2064 *pin++ = '\0';
2065 pos = os_strchr(pin, ' ');
2066 if (pos) {
2067 *pos++ = '\0';
2068 if (hwaddr_aton(pos, addr_buf) == 0)
2069 addr = addr_buf;
2070 }
2071 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
2072}
2073
2074
2075static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
2076 char *cmd)
2077{
2078 char *uuid = cmd, *pin;
2079 pin = os_strchr(uuid, ' ');
2080 if (pin == NULL)
2081 return -1;
2082 *pin++ = '\0';
2083 return wpas_wps_er_learn(wpa_s, uuid, pin);
2084}
2085
2086
2087static int wpa_supplicant_ctrl_iface_wps_er_set_config(
2088 struct wpa_supplicant *wpa_s, char *cmd)
2089{
2090 char *uuid = cmd, *id;
2091 id = os_strchr(uuid, ' ');
2092 if (id == NULL)
2093 return -1;
2094 *id++ = '\0';
2095 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
2096}
2097
2098
2099static int wpa_supplicant_ctrl_iface_wps_er_config(
2100 struct wpa_supplicant *wpa_s, char *cmd)
2101{
2102 char *pin;
2103 char *new_ssid;
2104 char *new_auth;
2105 char *new_encr;
2106 char *new_key;
2107 struct wps_new_ap_settings ap;
2108
2109 pin = os_strchr(cmd, ' ');
2110 if (pin == NULL)
2111 return -1;
2112 *pin++ = '\0';
2113
2114 new_ssid = os_strchr(pin, ' ');
2115 if (new_ssid == NULL)
2116 return -1;
2117 *new_ssid++ = '\0';
2118
2119 new_auth = os_strchr(new_ssid, ' ');
2120 if (new_auth == NULL)
2121 return -1;
2122 *new_auth++ = '\0';
2123
2124 new_encr = os_strchr(new_auth, ' ');
2125 if (new_encr == NULL)
2126 return -1;
2127 *new_encr++ = '\0';
2128
2129 new_key = os_strchr(new_encr, ' ');
2130 if (new_key == NULL)
2131 return -1;
2132 *new_key++ = '\0';
2133
2134 os_memset(&ap, 0, sizeof(ap));
2135 ap.ssid_hex = new_ssid;
2136 ap.auth = new_auth;
2137 ap.encr = new_encr;
2138 ap.key_hex = new_key;
2139 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
2140}
Dmitry Shmidt04949592012-07-19 12:16:46 -07002141
2142
2143#ifdef CONFIG_WPS_NFC
2144static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
2145 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2146{
2147 int ndef;
2148 struct wpabuf *buf;
2149 int res;
2150 char *uuid;
2151
2152 uuid = os_strchr(cmd, ' ');
2153 if (uuid == NULL)
2154 return -1;
2155 *uuid++ = '\0';
2156
2157 if (os_strcmp(cmd, "WPS") == 0)
2158 ndef = 0;
2159 else if (os_strcmp(cmd, "NDEF") == 0)
2160 ndef = 1;
2161 else
2162 return -1;
2163
2164 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
2165 if (buf == NULL)
2166 return -1;
2167
2168 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
2169 wpabuf_len(buf));
2170 reply[res++] = '\n';
2171 reply[res] = '\0';
2172
2173 wpabuf_free(buf);
2174
2175 return res;
2176}
2177#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002178#endif /* CONFIG_WPS_ER */
2179
2180#endif /* CONFIG_WPS */
2181
2182
2183#ifdef CONFIG_IBSS_RSN
2184static int wpa_supplicant_ctrl_iface_ibss_rsn(
2185 struct wpa_supplicant *wpa_s, char *addr)
2186{
2187 u8 peer[ETH_ALEN];
2188
2189 if (hwaddr_aton(addr, peer)) {
2190 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
2191 "address '%s'", addr);
2192 return -1;
2193 }
2194
2195 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
2196 MAC2STR(peer));
2197
2198 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
2199}
2200#endif /* CONFIG_IBSS_RSN */
2201
2202
2203static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
2204 char *rsp)
2205{
2206#ifdef IEEE8021X_EAPOL
2207 char *pos, *id_pos;
2208 int id;
2209 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002210
2211 pos = os_strchr(rsp, '-');
2212 if (pos == NULL)
2213 return -1;
2214 *pos++ = '\0';
2215 id_pos = pos;
2216 pos = os_strchr(pos, ':');
2217 if (pos == NULL)
2218 return -1;
2219 *pos++ = '\0';
2220 id = atoi(id_pos);
2221 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
2222 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2223 (u8 *) pos, os_strlen(pos));
2224
2225 ssid = wpa_config_get_network(wpa_s->conf, id);
2226 if (ssid == NULL) {
2227 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2228 "to update", id);
2229 return -1;
2230 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002231
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002232 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2233 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002234#else /* IEEE8021X_EAPOL */
2235 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2236 return -1;
2237#endif /* IEEE8021X_EAPOL */
2238}
2239
2240
2241static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2242 const char *params,
2243 char *buf, size_t buflen)
2244{
2245 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002246 int res, verbose, wps, ret;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002247#ifdef CONFIG_HS20
2248 const u8 *hs20;
2249#endif /* CONFIG_HS20 */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002250 const u8 *sess_id;
2251 size_t sess_id_len;
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002252
Dmitry Shmidt56052862013-10-04 10:23:25 -07002253 if (os_strcmp(params, "-DRIVER") == 0)
2254 return wpa_drv_status(wpa_s, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002255 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002256 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002257 pos = buf;
2258 end = buf + buflen;
2259 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2260 struct wpa_ssid *ssid = wpa_s->current_ssid;
2261 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2262 MAC2STR(wpa_s->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002263 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002264 return pos - buf;
2265 pos += ret;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002266 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2267 wpa_s->assoc_freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002268 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002269 return pos - buf;
2270 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002271 if (ssid) {
2272 u8 *_ssid = ssid->ssid;
2273 size_t ssid_len = ssid->ssid_len;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002274 u8 ssid_buf[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002275 if (ssid_len == 0) {
2276 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2277 if (_res < 0)
2278 ssid_len = 0;
2279 else
2280 ssid_len = _res;
2281 _ssid = ssid_buf;
2282 }
2283 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2284 wpa_ssid_txt(_ssid, ssid_len),
2285 ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002286 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002287 return pos - buf;
2288 pos += ret;
2289
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002290 if (wps && ssid->passphrase &&
2291 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2292 (ssid->mode == WPAS_MODE_AP ||
2293 ssid->mode == WPAS_MODE_P2P_GO)) {
2294 ret = os_snprintf(pos, end - pos,
2295 "passphrase=%s\n",
2296 ssid->passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002297 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002298 return pos - buf;
2299 pos += ret;
2300 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002301 if (ssid->id_str) {
2302 ret = os_snprintf(pos, end - pos,
2303 "id_str=%s\n",
2304 ssid->id_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002305 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002306 return pos - buf;
2307 pos += ret;
2308 }
2309
2310 switch (ssid->mode) {
2311 case WPAS_MODE_INFRA:
2312 ret = os_snprintf(pos, end - pos,
2313 "mode=station\n");
2314 break;
2315 case WPAS_MODE_IBSS:
2316 ret = os_snprintf(pos, end - pos,
2317 "mode=IBSS\n");
2318 break;
2319 case WPAS_MODE_AP:
2320 ret = os_snprintf(pos, end - pos,
2321 "mode=AP\n");
2322 break;
2323 case WPAS_MODE_P2P_GO:
2324 ret = os_snprintf(pos, end - pos,
2325 "mode=P2P GO\n");
2326 break;
2327 case WPAS_MODE_P2P_GROUP_FORMATION:
2328 ret = os_snprintf(pos, end - pos,
2329 "mode=P2P GO - group "
2330 "formation\n");
2331 break;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002332 case WPAS_MODE_MESH:
2333 ret = os_snprintf(pos, end - pos,
2334 "mode=mesh\n");
2335 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002336 default:
2337 ret = 0;
2338 break;
2339 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002340 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002341 return pos - buf;
2342 pos += ret;
2343 }
2344
Hai Shalom021b0b52019-04-10 11:17:58 -07002345 if (wpa_s->connection_set &&
2346 (wpa_s->connection_ht || wpa_s->connection_vht ||
Sunil Ravia04bd252022-05-02 22:54:18 -07002347 wpa_s->connection_he || wpa_s->connection_eht)) {
Hai Shalom021b0b52019-04-10 11:17:58 -07002348 ret = os_snprintf(pos, end - pos,
2349 "wifi_generation=%u\n",
Sunil Ravia04bd252022-05-02 22:54:18 -07002350 wpa_s->connection_eht ? 7 :
2351 (wpa_s->connection_he ? 6 :
2352 (wpa_s->connection_vht ? 5 : 4)));
Hai Shalom021b0b52019-04-10 11:17:58 -07002353 if (os_snprintf_error(end - pos, ret))
2354 return pos - buf;
2355 pos += ret;
2356 }
2357
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002358#ifdef CONFIG_AP
2359 if (wpa_s->ap_iface) {
2360 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2361 end - pos,
2362 verbose);
2363 } else
2364#endif /* CONFIG_AP */
2365 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2366 }
Paul Stewart092955c2017-02-06 09:13:09 -08002367#ifdef CONFIG_SME
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002368#ifdef CONFIG_SAE
2369 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002370#ifdef CONFIG_AP
2371 !wpa_s->ap_iface &&
2372#endif /* CONFIG_AP */
2373 wpa_s->sme.sae.state == SAE_ACCEPTED) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002374 ret = os_snprintf(pos, end - pos, "sae_group=%d\n"
2375 "sae_h2e=%d\n"
2376 "sae_pk=%d\n",
2377 wpa_s->sme.sae.group,
2378 wpa_s->sme.sae.h2e,
2379 wpa_s->sme.sae.pk);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002380 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002381 return pos - buf;
2382 pos += ret;
2383 }
2384#endif /* CONFIG_SAE */
Paul Stewart092955c2017-02-06 09:13:09 -08002385#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002386 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2387 wpa_supplicant_state_txt(wpa_s->wpa_state));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002388 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002389 return pos - buf;
2390 pos += ret;
2391
2392 if (wpa_s->l2 &&
2393 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2394 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002395 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002396 return pos - buf;
2397 pos += ret;
2398 }
2399
2400#ifdef CONFIG_P2P
2401 if (wpa_s->global->p2p) {
2402 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2403 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002404 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002405 return pos - buf;
2406 pos += ret;
2407 }
2408#endif /* CONFIG_P2P */
2409
2410 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2411 MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002412 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002413 return pos - buf;
2414 pos += ret;
2415
Sunil Ravi89eba102022-09-13 21:04:37 -07002416 if (wpa_s->valid_links) {
2417 ret = os_snprintf(pos, end - pos, "ap_mld_addr=" MACSTR "\n",
2418 MAC2STR(wpa_s->ap_mld_addr));
2419 if (os_snprintf_error(end - pos, ret))
2420 return pos - buf;
2421 pos += ret;
2422 }
2423
Dmitry Shmidt04949592012-07-19 12:16:46 -07002424#ifdef CONFIG_HS20
2425 if (wpa_s->current_bss &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002426 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2427 HS20_IE_VENDOR_TYPE)) &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002428 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2429 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002430 int release = 1;
2431 if (hs20[1] >= 5) {
2432 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2433 release = rel_num + 1;
2434 }
2435 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002436 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002437 return pos - buf;
2438 pos += ret;
2439 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002440
2441 if (wpa_s->current_ssid) {
2442 struct wpa_cred *cred;
2443 char *type;
2444
2445 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002446 size_t i;
2447
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002448 if (wpa_s->current_ssid->parent_cred != cred)
2449 continue;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002450
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002451 if (cred->provisioning_sp) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002452 ret = os_snprintf(pos, end - pos,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002453 "provisioning_sp=%s\n",
2454 cred->provisioning_sp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002455 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt051af732013-10-22 13:52:46 -07002456 return pos - buf;
2457 pos += ret;
2458 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002459
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002460 if (!cred->domain)
2461 goto no_domain;
2462
2463 i = 0;
2464 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2465 struct wpabuf *names =
2466 wpa_s->current_bss->anqp->domain_name;
2467 for (i = 0; names && i < cred->num_domain; i++)
2468 {
2469 if (domain_name_list_contains(
2470 names, cred->domain[i], 1))
2471 break;
2472 }
2473 if (i == cred->num_domain)
2474 i = 0; /* show first entry by default */
2475 }
2476 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2477 cred->domain[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002478 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002479 return pos - buf;
2480 pos += ret;
2481
2482 no_domain:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002483 if (wpa_s->current_bss == NULL ||
2484 wpa_s->current_bss->anqp == NULL)
2485 res = -1;
2486 else
2487 res = interworking_home_sp_cred(
2488 wpa_s, cred,
2489 wpa_s->current_bss->anqp->domain_name);
2490 if (res > 0)
2491 type = "home";
2492 else if (res == 0)
2493 type = "roaming";
2494 else
2495 type = "unknown";
2496
2497 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002498 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002499 return pos - buf;
2500 pos += ret;
2501
2502 break;
2503 }
2504 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002505#endif /* CONFIG_HS20 */
2506
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002507 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2508 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2509 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2510 verbose);
2511 if (res >= 0)
2512 pos += res;
2513 }
2514
Dmitry Shmidt29333592017-01-09 12:27:11 -08002515#ifdef CONFIG_MACSEC
2516 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2517 if (res > 0)
2518 pos += res;
2519#endif /* CONFIG_MACSEC */
2520
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002521 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2522 if (sess_id) {
2523 char *start = pos;
2524
2525 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2526 if (os_snprintf_error(end - pos, ret))
2527 return start - buf;
2528 pos += ret;
2529 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2530 if (ret <= 0)
2531 return start - buf;
2532 pos += ret;
2533 ret = os_snprintf(pos, end - pos, "\n");
2534 if (os_snprintf_error(end - pos, ret))
2535 return start - buf;
2536 pos += ret;
2537 }
2538
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002539 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2540 if (res >= 0)
2541 pos += res;
2542
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002543#ifdef CONFIG_WPS
2544 {
2545 char uuid_str[100];
2546 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2547 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002548 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002549 return pos - buf;
2550 pos += ret;
2551 }
2552#endif /* CONFIG_WPS */
2553
Roshan Pius3a1667e2018-07-03 15:17:14 -07002554 if (wpa_s->ieee80211ac) {
2555 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2556 if (os_snprintf_error(end - pos, ret))
2557 return pos - buf;
2558 pos += ret;
2559 }
2560
Sunil Ravi7f769292024-07-23 22:21:32 +00002561#ifdef CONFIG_SME
2562 if (wpa_s->sme.bss_max_idle_period) {
2563 ret = os_snprintf(pos, end - pos, "bss_max_idle_period=%d\n",
2564 wpa_s->sme.bss_max_idle_period);
2565 if (os_snprintf_error(end - pos, ret))
2566 return pos - buf;
2567 pos += ret;
2568 }
2569#endif /* CONFIG_SME */
2570
2571 if (wpa_s->ssid_verified) {
2572 ret = os_snprintf(pos, end - pos, "ssid_verified=1\n");
2573 if (os_snprintf_error(end - pos, ret))
2574 return pos - buf;
2575 pos += ret;
2576 }
2577
2578 if (wpa_s->bigtk_set) {
2579 ret = os_snprintf(pos, end - pos, "bigtk_set=1\n");
2580 if (os_snprintf_error(end - pos, ret))
2581 return pos - buf;
2582 pos += ret;
2583 }
2584
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002585#ifdef ANDROID
vandwalleffc70182014-09-11 11:40:14 -07002586 /*
2587 * Allow using the STATUS command with default behavior, say for debug,
2588 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2589 * events with STATUS-NO_EVENTS.
2590 */
2591 if (os_strcmp(params, "-NO_EVENTS")) {
2592 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2593 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2594 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2595 wpa_s->wpa_state,
2596 MAC2STR(wpa_s->bssid),
2597 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2598 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2599 wpa_s->current_ssid->ssid_len) : "");
2600 if (wpa_s->wpa_state == WPA_COMPLETED) {
2601 struct wpa_ssid *ssid = wpa_s->current_ssid;
Sunil Ravi89eba102022-09-13 21:04:37 -07002602 char mld_addr[50];
2603
2604 mld_addr[0] = '\0';
2605 if (wpa_s->valid_links)
2606 os_snprintf(mld_addr, sizeof(mld_addr),
2607 " ap_mld_addr=" MACSTR,
2608 MAC2STR(wpa_s->ap_mld_addr));
2609
vandwalleffc70182014-09-11 11:40:14 -07002610 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2611 "- connection to " MACSTR
Sunil Ravi89eba102022-09-13 21:04:37 -07002612 " completed %s [id=%d id_str=%s]%s",
vandwalleffc70182014-09-11 11:40:14 -07002613 MAC2STR(wpa_s->bssid), "(auth)",
2614 ssid ? ssid->id : -1,
Sunil Ravi89eba102022-09-13 21:04:37 -07002615 ssid && ssid->id_str ? ssid->id_str : "",
2616 mld_addr);
vandwalleffc70182014-09-11 11:40:14 -07002617 }
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08002618 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002619#endif /* ANDROID */
2620
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002621 return pos - buf;
2622}
2623
2624
2625static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2626 char *cmd)
2627{
2628 char *pos;
2629 int id;
2630 struct wpa_ssid *ssid;
2631 u8 bssid[ETH_ALEN];
2632
2633 /* cmd: "<network id> <BSSID>" */
2634 pos = os_strchr(cmd, ' ');
2635 if (pos == NULL)
2636 return -1;
2637 *pos++ = '\0';
2638 id = atoi(cmd);
2639 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2640 if (hwaddr_aton(pos, bssid)) {
2641 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2642 return -1;
2643 }
2644
2645 ssid = wpa_config_get_network(wpa_s->conf, id);
2646 if (ssid == NULL) {
2647 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2648 "to update", id);
2649 return -1;
2650 }
2651
2652 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2653 ssid->bssid_set = !is_zero_ether_addr(bssid);
2654
2655 return 0;
2656}
2657
2658
Hai Shalom60840252021-02-19 19:02:11 -08002659static int wpa_supplicant_ctrl_iface_bssid_ignore(struct wpa_supplicant *wpa_s,
2660 char *cmd, char *buf,
2661 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002662{
2663 u8 bssid[ETH_ALEN];
Hai Shalom60840252021-02-19 19:02:11 -08002664 struct wpa_bssid_ignore *e;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002665 char *pos, *end;
2666 int ret;
2667
Hai Shalom60840252021-02-19 19:02:11 -08002668 /* cmd: "BSSID_IGNORE [<BSSID>]" */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002669 if (*cmd == '\0') {
2670 pos = buf;
2671 end = buf + buflen;
Hai Shalom60840252021-02-19 19:02:11 -08002672 e = wpa_s->bssid_ignore;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002673 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002674 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2675 MAC2STR(e->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002676 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002677 return pos - buf;
2678 pos += ret;
2679 e = e->next;
2680 }
2681 return pos - buf;
2682 }
2683
2684 cmd++;
2685 if (os_strncmp(cmd, "clear", 5) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -08002686 wpa_bssid_ignore_clear(wpa_s);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002687 os_memcpy(buf, "OK\n", 3);
2688 return 3;
2689 }
2690
Hai Shalom60840252021-02-19 19:02:11 -08002691 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BSSID_IGNORE bssid='%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002692 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002693 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002694 return -1;
2695 }
2696
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002697 /*
2698 * Add the BSSID twice, so its count will be 2, causing it to be
2699 * skipped when processing scan results.
2700 */
Hai Shalom60840252021-02-19 19:02:11 -08002701 ret = wpa_bssid_ignore_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002702 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002703 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002704 ret = wpa_bssid_ignore_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002705 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002706 return -1;
2707 os_memcpy(buf, "OK\n", 3);
2708 return 3;
2709}
2710
2711
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002712static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2713 char *cmd, char *buf,
2714 size_t buflen)
2715{
2716 char *pos, *end, *stamp;
2717 int ret;
2718
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002719 /* cmd: "LOG_LEVEL [<level>]" */
2720 if (*cmd == '\0') {
2721 pos = buf;
2722 end = buf + buflen;
2723 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2724 "Timestamp: %d\n",
2725 debug_level_str(wpa_debug_level),
2726 wpa_debug_timestamp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002727 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002728 ret = 0;
2729
2730 return ret;
2731 }
2732
2733 while (*cmd == ' ')
2734 cmd++;
2735
2736 stamp = os_strchr(cmd, ' ');
2737 if (stamp) {
2738 *stamp++ = '\0';
2739 while (*stamp == ' ') {
2740 stamp++;
2741 }
2742 }
2743
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002744 if (os_strlen(cmd)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002745 int level = str_to_debug_level(cmd);
2746 if (level < 0)
2747 return -1;
2748 wpa_debug_level = level;
2749 }
2750
2751 if (stamp && os_strlen(stamp))
2752 wpa_debug_timestamp = atoi(stamp);
2753
2754 os_memcpy(buf, "OK\n", 3);
2755 return 3;
2756}
2757
2758
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002759static int wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002760 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002761{
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002762 char *pos, *end, *prev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002763 struct wpa_ssid *ssid;
2764 int ret;
2765
2766 pos = buf;
2767 end = buf + buflen;
2768 ret = os_snprintf(pos, end - pos,
2769 "network id / ssid / bssid / flags\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002770 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002771 return pos - buf;
2772 pos += ret;
2773
2774 ssid = wpa_s->conf->ssid;
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002775
2776 /* skip over ssids until we find next one */
2777 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2778 int last_id = atoi(cmd + 8);
2779 if (last_id != -1) {
2780 while (ssid != NULL && ssid->id <= last_id) {
2781 ssid = ssid->next;
2782 }
2783 }
2784 }
2785
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002786 while (ssid) {
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002787 prev = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002788 ret = os_snprintf(pos, end - pos, "%d\t%s",
2789 ssid->id,
2790 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002791 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002792 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002793 pos += ret;
2794 if (ssid->bssid_set) {
2795 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2796 MAC2STR(ssid->bssid));
2797 } else {
2798 ret = os_snprintf(pos, end - pos, "\tany");
2799 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002800 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002801 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002802 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002803 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002804 ssid == wpa_s->current_ssid ?
2805 "[CURRENT]" : "",
2806 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002807 ssid->disabled_until.sec ?
2808 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002809 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2810 "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002811 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002812 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002813 pos += ret;
2814 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002815 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002816 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002817 pos += ret;
2818
2819 ssid = ssid->next;
2820 }
2821
2822 return pos - buf;
2823}
2824
2825
2826static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2827{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002828 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002829 ret = os_snprintf(pos, end - pos, "-");
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 Shmidta54fa5f2013-01-15 13:53:35 -08002833 ret = wpa_write_ciphers(pos, end, cipher, "+");
2834 if (ret < 0)
2835 return pos;
2836 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002837 return pos;
2838}
2839
2840
2841static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2842 const u8 *ie, size_t ie_len)
2843{
2844 struct wpa_ie_data data;
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002845 char *start;
2846 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002847
2848 ret = os_snprintf(pos, end - pos, "[%s-", proto);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002849 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002850 return pos;
2851 pos += ret;
2852
2853 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2854 ret = os_snprintf(pos, end - pos, "?]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002855 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002856 return pos;
2857 pos += ret;
2858 return pos;
2859 }
2860
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002861 start = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002862 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002863 ret = os_snprintf(pos, end - pos, "%sEAP",
2864 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002865 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002866 return pos;
2867 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002868 }
2869 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002870 ret = os_snprintf(pos, end - pos, "%sPSK",
2871 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002872 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002873 return pos;
2874 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002875 }
2876 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002877 ret = os_snprintf(pos, end - pos, "%sNone",
2878 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002879 if (os_snprintf_error(end - pos, ret))
2880 return pos;
2881 pos += ret;
2882 }
2883 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2884 ret = os_snprintf(pos, end - pos, "%sSAE",
2885 pos == start ? "" : "+");
2886 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002887 return pos;
2888 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002889 }
Sunil Ravi89eba102022-09-13 21:04:37 -07002890 if (data.key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) {
2891 ret = os_snprintf(pos, end - pos, "%sSAE-EXT-KEY",
2892 pos == start ? "" : "+");
2893 if (os_snprintf_error(end - pos, ret))
2894 return pos;
2895 pos += ret;
2896 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002897#ifdef CONFIG_IEEE80211R
2898 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2899 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002900 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002901 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002902 return pos;
2903 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002904 }
2905 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2906 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002907 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002908 if (os_snprintf_error(end - pos, ret))
2909 return pos;
2910 pos += ret;
2911 }
2912 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2913 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2914 pos == start ? "" : "+");
2915 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002916 return pos;
2917 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002918 }
Sunil Ravi89eba102022-09-13 21:04:37 -07002919 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE_EXT_KEY) {
2920 ret = os_snprintf(pos, end - pos, "%sFT/SAE-EXT-KEY",
2921 pos == start ? "" : "+");
2922 if (os_snprintf_error(end - pos, ret))
2923 return pos;
2924 pos += ret;
2925 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002926#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002927 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2928 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002929 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002930 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002931 return pos;
2932 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002933 }
2934 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2935 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002936 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002937 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002938 return pos;
2939 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002940 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002941
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002942#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002943 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2944 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2945 pos == start ? "" : "+");
2946 if (os_snprintf_error(end - pos, ret))
2947 return pos;
2948 pos += ret;
2949 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002950#endif /* CONFIG_SUITEB */
2951
2952#ifdef CONFIG_SUITEB192
2953 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2954 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2955 pos == start ? "" : "+");
2956 if (os_snprintf_error(end - pos, ret))
2957 return pos;
2958 pos += ret;
2959 }
2960#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002961
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002962#ifdef CONFIG_FILS
2963 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2964 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2965 pos == start ? "" : "+");
2966 if (os_snprintf_error(end - pos, ret))
2967 return pos;
2968 pos += ret;
2969 }
2970 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2971 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2972 pos == start ? "" : "+");
2973 if (os_snprintf_error(end - pos, ret))
2974 return pos;
2975 pos += ret;
2976 }
2977#ifdef CONFIG_IEEE80211R
2978 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2979 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2980 pos == start ? "" : "+");
2981 if (os_snprintf_error(end - pos, ret))
2982 return pos;
2983 pos += ret;
2984 }
2985 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2986 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2987 pos == start ? "" : "+");
2988 if (os_snprintf_error(end - pos, ret))
2989 return pos;
2990 pos += ret;
2991 }
2992#endif /* CONFIG_IEEE80211R */
2993#endif /* CONFIG_FILS */
2994
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002995#ifdef CONFIG_OWE
2996 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2997 ret = os_snprintf(pos, end - pos, "%sOWE",
2998 pos == start ? "" : "+");
2999 if (os_snprintf_error(end - pos, ret))
3000 return pos;
3001 pos += ret;
3002 }
3003#endif /* CONFIG_OWE */
3004
3005#ifdef CONFIG_DPP
3006 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
3007 ret = os_snprintf(pos, end - pos, "%sDPP",
3008 pos == start ? "" : "+");
3009 if (os_snprintf_error(end - pos, ret))
3010 return pos;
3011 pos += ret;
3012 }
3013#endif /* CONFIG_DPP */
3014
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003015 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
3016 ret = os_snprintf(pos, end - pos, "%sOSEN",
3017 pos == start ? "" : "+");
3018 if (os_snprintf_error(end - pos, ret))
3019 return pos;
3020 pos += ret;
3021 }
3022
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003023#ifdef CONFIG_SHA384
3024 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA384) {
3025 ret = os_snprintf(pos, end - pos, "%sEAP-SHA384",
3026 pos == start ? "" : "+");
3027 if (os_snprintf_error(end - pos, ret))
3028 return pos;
3029 pos += ret;
3030 }
3031#endif /* CONFIG_SHA384 */
3032
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003033 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
3034
3035 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
3036 ret = os_snprintf(pos, end - pos, "-preauth");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003037 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003038 return pos;
3039 pos += ret;
3040 }
3041
3042 ret = os_snprintf(pos, end - pos, "]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003043 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003044 return pos;
3045 pos += ret;
3046
3047 return pos;
3048}
3049
3050
3051#ifdef CONFIG_WPS
3052static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
3053 char *pos, char *end,
3054 struct wpabuf *wps_ie)
3055{
3056 int ret;
3057 const char *txt;
3058
3059 if (wps_ie == NULL)
3060 return pos;
3061 if (wps_is_selected_pbc_registrar(wps_ie))
3062 txt = "[WPS-PBC]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003063 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
3064 txt = "[WPS-AUTH]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003065 else if (wps_is_selected_pin_registrar(wps_ie))
3066 txt = "[WPS-PIN]";
3067 else
3068 txt = "[WPS]";
3069
3070 ret = os_snprintf(pos, end - pos, "%s", txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003071 if (!os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003072 pos += ret;
3073 wpabuf_free(wps_ie);
3074 return pos;
3075}
3076#endif /* CONFIG_WPS */
3077
3078
3079static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
3080 char *pos, char *end,
3081 const struct wpa_bss *bss)
3082{
3083#ifdef CONFIG_WPS
3084 struct wpabuf *wps_ie;
3085 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
3086 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
3087#else /* CONFIG_WPS */
3088 return pos;
3089#endif /* CONFIG_WPS */
3090}
3091
3092
3093/* Format one result on one text line into a buffer. */
3094static int wpa_supplicant_ctrl_iface_scan_result(
3095 struct wpa_supplicant *wpa_s,
3096 const struct wpa_bss *bss, char *buf, size_t buflen)
3097{
3098 char *pos, *end;
3099 int ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07003100 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe, *rsnxe;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003101
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003102 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003103 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07003104 if (!p2p)
3105 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003106 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
3107 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
3108 0)
3109 return 0; /* Do not show P2P listen discovery results here */
3110
3111 pos = buf;
3112 end = buf + buflen;
3113
3114 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
3115 MAC2STR(bss->bssid), bss->freq, bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003116 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003117 return -1;
3118 pos += ret;
3119 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3120 if (ie)
3121 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
Sunil Ravi7f769292024-07-23 22:21:32 +00003122 ie2 = wpa_bss_get_rsne(wpa_s, bss, NULL, false);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003123 if (ie2) {
3124 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
3125 ie2, 2 + ie2[1]);
3126 }
Sunil Ravi7f769292024-07-23 22:21:32 +00003127 rsnxe = wpa_bss_get_rsnxe(wpa_s, bss, NULL, false);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003128 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
3129 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
3130 if (os_snprintf_error(end - pos, ret))
3131 return -1;
3132 pos += ret;
3133 }
3134 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
3135 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
3136 if (os_snprintf_error(end - pos, ret))
3137 return -1;
3138 pos += ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07003139 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003140 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
3141 if (osen_ie)
3142 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
3143 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003144 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
3145 if (owe) {
3146 ret = os_snprintf(pos, end - pos,
3147 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
3148 if (os_snprintf_error(end - pos, ret))
3149 return -1;
3150 pos += ret;
3151 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003152 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003153 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003154 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003155 if (os_snprintf_error(end - pos, ret))
3156 return -1;
3157 pos += ret;
3158 }
3159 if (mesh) {
3160 ret = os_snprintf(pos, end - pos, "[MESH]");
3161 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003162 return -1;
3163 pos += ret;
3164 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003165 if (bss_is_dmg(bss)) {
3166 const char *s;
Hai Shalomc3565922019-10-28 11:58:20 -07003167
Hai Shalom60840252021-02-19 19:02:11 -08003168 if (wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_EDMG_OPERATION)) {
Hai Shalomc3565922019-10-28 11:58:20 -07003169 ret = os_snprintf(pos, end - pos, "[EDMG]");
3170 if (os_snprintf_error(end - pos, ret))
3171 return -1;
3172 pos += ret;
3173 }
3174
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003175 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003176 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003177 return -1;
3178 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003179 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3180 case IEEE80211_CAP_DMG_IBSS:
3181 s = "[IBSS]";
3182 break;
3183 case IEEE80211_CAP_DMG_AP:
3184 s = "[ESS]";
3185 break;
3186 case IEEE80211_CAP_DMG_PBSS:
3187 s = "[PBSS]";
3188 break;
3189 default:
3190 s = "";
3191 break;
3192 }
3193 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003194 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003195 return -1;
3196 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003197 } else {
3198 if (bss->caps & IEEE80211_CAP_IBSS) {
3199 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003200 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003201 return -1;
3202 pos += ret;
3203 }
3204 if (bss->caps & IEEE80211_CAP_ESS) {
3205 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003206 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003207 return -1;
3208 pos += ret;
3209 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003210 }
3211 if (p2p) {
3212 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003213 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003214 return -1;
3215 pos += ret;
3216 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003217#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003218 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003219 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003220 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003221 return -1;
3222 pos += ret;
3223 }
3224#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003225#ifdef CONFIG_FILS
3226 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
3227 ret = os_snprintf(pos, end - pos, "[FILS]");
3228 if (os_snprintf_error(end - pos, ret))
3229 return -1;
3230 pos += ret;
3231 }
3232#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003233#ifdef CONFIG_FST
3234 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
3235 ret = os_snprintf(pos, end - pos, "[FST]");
3236 if (os_snprintf_error(end - pos, ret))
3237 return -1;
3238 pos += ret;
3239 }
3240#endif /* CONFIG_FST */
Hai Shalom74f70d42019-02-11 14:42:39 -08003241 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
3242 ret = os_snprintf(pos, end - pos, "[UTF-8]");
3243 if (os_snprintf_error(end - pos, ret))
3244 return -1;
3245 pos += ret;
3246 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003247
3248 ret = os_snprintf(pos, end - pos, "\t%s",
3249 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003250 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003251 return -1;
3252 pos += ret;
3253
3254 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003255 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003256 return -1;
3257 pos += ret;
3258
3259 return pos - buf;
3260}
3261
3262
3263static int wpa_supplicant_ctrl_iface_scan_results(
3264 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3265{
3266 char *pos, *end;
3267 struct wpa_bss *bss;
3268 int ret;
3269
3270 pos = buf;
3271 end = buf + buflen;
3272 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
3273 "flags / ssid\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003274 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003275 return pos - buf;
3276 pos += ret;
3277
3278 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3279 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
3280 end - pos);
3281 if (ret < 0 || ret >= end - pos)
3282 return pos - buf;
3283 pos += ret;
3284 }
3285
3286 return pos - buf;
3287}
3288
3289
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003290#ifdef CONFIG_MESH
3291
3292static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3293 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
3294{
3295 char *pos, ifname[IFNAMSIZ + 1];
3296
3297 ifname[0] = '\0';
3298
3299 pos = os_strstr(cmd, "ifname=");
3300 if (pos) {
3301 pos += 7;
3302 os_strlcpy(ifname, pos, sizeof(ifname));
3303 }
3304
3305 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
3306 return -1;
3307
3308 os_strlcpy(reply, ifname, max_len);
3309 return os_strlen(ifname);
3310}
3311
3312
3313static int wpa_supplicant_ctrl_iface_mesh_group_add(
3314 struct wpa_supplicant *wpa_s, char *cmd)
3315{
3316 int id;
3317 struct wpa_ssid *ssid;
3318
3319 id = atoi(cmd);
3320 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
3321
3322 ssid = wpa_config_get_network(wpa_s->conf, id);
3323 if (ssid == NULL) {
3324 wpa_printf(MSG_DEBUG,
3325 "CTRL_IFACE: Could not find network id=%d", id);
3326 return -1;
3327 }
3328 if (ssid->mode != WPAS_MODE_MESH) {
3329 wpa_printf(MSG_DEBUG,
3330 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3331 return -1;
3332 }
3333 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
Sunil Ravi89eba102022-09-13 21:04:37 -07003334 ssid->key_mgmt != WPA_KEY_MGMT_SAE &&
3335 ssid->key_mgmt != WPA_KEY_MGMT_SAE_EXT_KEY) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003336 wpa_printf(MSG_ERROR,
3337 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3338 return -1;
3339 }
3340
3341 /*
3342 * TODO: If necessary write our own group_add function,
3343 * for now we can reuse select_network
3344 */
3345 wpa_supplicant_select_network(wpa_s, ssid);
3346
3347 return 0;
3348}
3349
3350
3351static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3352 struct wpa_supplicant *wpa_s, char *cmd)
3353{
3354 struct wpa_supplicant *orig;
3355 struct wpa_global *global;
3356 int found = 0;
3357
3358 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3359
3360 global = wpa_s->global;
3361 orig = wpa_s;
3362
3363 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3364 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3365 found = 1;
3366 break;
3367 }
3368 }
3369 if (!found) {
3370 wpa_printf(MSG_ERROR,
3371 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3372 cmd);
3373 return -1;
3374 }
3375 if (wpa_s->mesh_if_created && wpa_s == orig) {
3376 wpa_printf(MSG_ERROR,
3377 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3378 return -1;
3379 }
3380
3381 wpa_s->reassociate = 0;
3382 wpa_s->disconnected = 1;
3383 wpa_supplicant_cancel_sched_scan(wpa_s);
3384 wpa_supplicant_cancel_scan(wpa_s);
3385
3386 /*
3387 * TODO: If necessary write our own group_remove function,
3388 * for now we can reuse deauthenticate
3389 */
3390 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3391
3392 if (wpa_s->mesh_if_created)
3393 wpa_supplicant_remove_iface(global, wpa_s, 0);
3394
3395 return 0;
3396}
3397
Dmitry Shmidte4663042016-04-04 10:07:49 -07003398
3399static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3400 struct wpa_supplicant *wpa_s, char *cmd)
3401{
3402 u8 addr[ETH_ALEN];
3403
3404 if (hwaddr_aton(cmd, addr) < 0)
3405 return -1;
3406
3407 return wpas_mesh_peer_remove(wpa_s, addr);
3408}
3409
3410
3411static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3412 struct wpa_supplicant *wpa_s, char *cmd)
3413{
3414 u8 addr[ETH_ALEN];
3415 int duration;
3416 char *pos;
3417
3418 pos = os_strstr(cmd, " duration=");
3419 if (pos) {
3420 *pos = '\0';
3421 duration = atoi(pos + 10);
3422 } else {
3423 duration = -1;
3424 }
3425
3426 if (hwaddr_aton(cmd, addr))
3427 return -1;
3428
3429 return wpas_mesh_peer_add(wpa_s, addr, duration);
3430}
3431
Hai Shalom81f62d82019-07-22 12:10:00 -07003432
3433static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3434 struct wpa_supplicant *wpa_s, char *cmd)
3435{
3436 struct ether_header *eth;
3437 u8 addr[ETH_ALEN];
3438 u8 *buf;
3439 char *pos;
3440 size_t payload_len = 0, len;
3441 int ret = -1;
3442
3443 if (hwaddr_aton(cmd, addr))
3444 return -1;
3445
3446 pos = os_strstr(cmd, " payload=");
3447 if (pos) {
3448 pos = pos + 9;
3449 payload_len = os_strlen(pos);
3450 if (payload_len & 1)
3451 return -1;
3452
3453 payload_len /= 2;
3454 }
3455
3456 len = ETH_HLEN + payload_len;
3457 buf = os_malloc(len);
3458 if (!buf)
3459 return -1;
3460
3461 eth = (struct ether_header *) buf;
3462 os_memcpy(eth->ether_dhost, addr, ETH_ALEN);
3463 os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN);
3464 eth->ether_type = htons(ETH_P_802_3);
3465
3466 if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0)
3467 goto fail;
3468
3469 ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len);
3470fail:
3471 os_free(buf);
3472 return -ret;
3473}
3474
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003475#endif /* CONFIG_MESH */
3476
3477
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003478static int wpa_supplicant_ctrl_iface_select_network(
3479 struct wpa_supplicant *wpa_s, char *cmd)
3480{
3481 int id;
3482 struct wpa_ssid *ssid;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003483 char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003484
3485 /* cmd: "<network id>" or "any" */
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003486 if (os_strncmp(cmd, "any", 3) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003487 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3488 ssid = NULL;
3489 } else {
3490 id = atoi(cmd);
3491 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3492
3493 ssid = wpa_config_get_network(wpa_s->conf, id);
3494 if (ssid == NULL) {
3495 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3496 "network id=%d", id);
3497 return -1;
3498 }
3499 if (ssid->disabled == 2) {
3500 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3501 "SELECT_NETWORK with persistent P2P group");
3502 return -1;
3503 }
3504 }
3505
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003506 pos = os_strstr(cmd, " freq=");
3507 if (pos) {
3508 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3509 if (freqs) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003510 os_free(wpa_s->select_network_scan_freqs);
3511 wpa_s->select_network_scan_freqs = freqs;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003512 }
3513 }
3514
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003515 wpa_s->scan_min_time.sec = 0;
3516 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003517 wpa_supplicant_select_network(wpa_s, ssid);
3518
3519 return 0;
3520}
3521
3522
3523static int wpa_supplicant_ctrl_iface_enable_network(
3524 struct wpa_supplicant *wpa_s, char *cmd)
3525{
3526 int id;
3527 struct wpa_ssid *ssid;
3528
3529 /* cmd: "<network id>" or "all" */
3530 if (os_strcmp(cmd, "all") == 0) {
3531 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3532 ssid = NULL;
3533 } else {
3534 id = atoi(cmd);
3535 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3536
3537 ssid = wpa_config_get_network(wpa_s->conf, id);
3538 if (ssid == NULL) {
3539 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3540 "network id=%d", id);
3541 return -1;
3542 }
3543 if (ssid->disabled == 2) {
3544 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3545 "ENABLE_NETWORK with persistent P2P group");
3546 return -1;
3547 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003548
3549 if (os_strstr(cmd, " no-connect")) {
3550 ssid->disabled = 0;
3551 return 0;
3552 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003553 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003554 wpa_s->scan_min_time.sec = 0;
3555 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003556 wpa_supplicant_enable_network(wpa_s, ssid);
3557
3558 return 0;
3559}
3560
3561
3562static int wpa_supplicant_ctrl_iface_disable_network(
3563 struct wpa_supplicant *wpa_s, char *cmd)
3564{
3565 int id;
3566 struct wpa_ssid *ssid;
3567
3568 /* cmd: "<network id>" or "all" */
3569 if (os_strcmp(cmd, "all") == 0) {
3570 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3571 ssid = NULL;
3572 } else {
3573 id = atoi(cmd);
3574 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3575
3576 ssid = wpa_config_get_network(wpa_s->conf, id);
3577 if (ssid == NULL) {
3578 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3579 "network id=%d", id);
3580 return -1;
3581 }
3582 if (ssid->disabled == 2) {
3583 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3584 "DISABLE_NETWORK with persistent P2P "
3585 "group");
3586 return -1;
3587 }
3588 }
3589 wpa_supplicant_disable_network(wpa_s, ssid);
3590
3591 return 0;
3592}
3593
3594
3595static int wpa_supplicant_ctrl_iface_add_network(
3596 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3597{
3598 struct wpa_ssid *ssid;
3599 int ret;
3600
3601 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3602
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003603 ssid = wpa_supplicant_add_network(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003604 if (ssid == NULL)
3605 return -1;
3606
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003607 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003608 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003609 return -1;
3610 return ret;
3611}
3612
3613
3614static int wpa_supplicant_ctrl_iface_remove_network(
3615 struct wpa_supplicant *wpa_s, char *cmd)
3616{
3617 int id;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003618 int result;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003619
3620 /* cmd: "<network id>" or "all" */
3621 if (os_strcmp(cmd, "all") == 0) {
3622 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Hai Shalom899fcc72020-10-19 14:38:18 -07003623 return wpa_supplicant_remove_all_networks(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003624 }
3625
3626 id = atoi(cmd);
3627 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3628
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003629 result = wpa_supplicant_remove_network(wpa_s, id);
3630 if (result == -1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003631 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3632 "id=%d", id);
3633 return -1;
3634 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003635 if (result == -2) {
Deepthi Gowria831d782012-09-03 11:55:38 +03003636 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3637 "network id=%d", id);
3638 return -1;
3639 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003640 return 0;
3641}
3642
3643
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003644static int wpa_supplicant_ctrl_iface_update_network(
3645 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3646 char *name, char *value)
3647{
Dmitry Shmidte4663042016-04-04 10:07:49 -07003648 int ret;
3649
3650 ret = wpa_config_set(ssid, name, value, 0);
3651 if (ret < 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003652 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3653 "variable '%s'", name);
3654 return -1;
3655 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07003656 if (ret == 1)
3657 return 0; /* No change to the previously configured value */
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003658
Hai Shalom899fcc72020-10-19 14:38:18 -07003659#ifdef CONFIG_BGSCAN
3660 if (os_strcmp(name, "bgscan") == 0) {
3661 /*
3662 * Reset the bgscan parameters for the current network and
3663 * return. There's no need to flush caches for bgscan parameter
3664 * changes.
3665 */
3666 if (wpa_s->current_ssid == ssid &&
3667 wpa_s->wpa_state == WPA_COMPLETED)
3668 wpa_supplicant_reset_bgscan(wpa_s);
3669 return 0;
3670 }
3671#endif /* CONFIG_BGSCAN */
3672
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003673 if (os_strcmp(name, "bssid") != 0 &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003674 os_strncmp(name, "bssid_", 6) != 0 &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003675 os_strcmp(name, "scan_freq") != 0 &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003676 os_strcmp(name, "priority") != 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003677 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3678
Dmitry Shmidte4663042016-04-04 10:07:49 -07003679 if (wpa_s->current_ssid == ssid ||
3680 wpa_s->current_ssid == NULL) {
3681 /*
3682 * Invalidate the EAP session cache if anything in the
3683 * current or previously used configuration changes.
3684 */
3685 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3686 }
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003687 }
3688
3689 if ((os_strcmp(name, "psk") == 0 &&
3690 value[0] == '"' && ssid->ssid_len) ||
3691 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3692 wpa_config_update_psk(ssid);
3693 else if (os_strcmp(name, "priority") == 0)
3694 wpa_config_update_prio_list(wpa_s->conf);
3695
3696 return 0;
3697}
3698
3699
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003700static int wpa_supplicant_ctrl_iface_set_network(
3701 struct wpa_supplicant *wpa_s, char *cmd)
3702{
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003703 int id, ret, prev_bssid_set, prev_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003704 struct wpa_ssid *ssid;
3705 char *name, *value;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003706 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003707
3708 /* cmd: "<network id> <variable name> <value>" */
3709 name = os_strchr(cmd, ' ');
3710 if (name == NULL)
3711 return -1;
3712 *name++ = '\0';
3713
3714 value = os_strchr(name, ' ');
3715 if (value == NULL)
3716 return -1;
3717 *value++ = '\0';
3718
3719 id = atoi(cmd);
3720 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3721 id, name);
3722 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3723 (u8 *) value, os_strlen(value));
3724
3725 ssid = wpa_config_get_network(wpa_s->conf, id);
3726 if (ssid == NULL) {
3727 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3728 "id=%d", id);
3729 return -1;
3730 }
3731
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003732 prev_bssid_set = ssid->bssid_set;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003733 prev_disabled = ssid->disabled;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003734 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3735 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3736 value);
3737 if (ret == 0 &&
3738 (ssid->bssid_set != prev_bssid_set ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003739 !ether_addr_equal(ssid->bssid, prev_bssid)))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003740 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003741
3742 if (prev_disabled != ssid->disabled &&
3743 (prev_disabled == 2 || ssid->disabled == 2))
3744 wpas_notify_network_type_changed(wpa_s, ssid);
3745
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003746 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003747}
3748
3749
3750static int wpa_supplicant_ctrl_iface_get_network(
3751 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3752{
3753 int id;
3754 size_t res;
3755 struct wpa_ssid *ssid;
3756 char *name, *value;
3757
3758 /* cmd: "<network id> <variable name>" */
3759 name = os_strchr(cmd, ' ');
3760 if (name == NULL || buflen == 0)
3761 return -1;
3762 *name++ = '\0';
3763
3764 id = atoi(cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003765 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003766 id, name);
3767
3768 ssid = wpa_config_get_network(wpa_s->conf, id);
3769 if (ssid == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003770 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003771 "id=%d", id);
3772 return -1;
3773 }
3774
3775 value = wpa_config_get_no_key(ssid, name);
3776 if (value == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003777 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003778 "variable '%s'", name);
3779 return -1;
3780 }
3781
3782 res = os_strlcpy(buf, value, buflen);
3783 if (res >= buflen) {
3784 os_free(value);
3785 return -1;
3786 }
3787
3788 os_free(value);
3789
3790 return res;
3791}
3792
3793
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003794static int wpa_supplicant_ctrl_iface_dup_network(
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003795 struct wpa_supplicant *wpa_s, char *cmd,
3796 struct wpa_supplicant *dst_wpa_s)
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003797{
3798 struct wpa_ssid *ssid_s, *ssid_d;
3799 char *name, *id, *value;
3800 int id_s, id_d, ret;
3801
3802 /* cmd: "<src network id> <dst network id> <variable name>" */
3803 id = os_strchr(cmd, ' ');
3804 if (id == NULL)
3805 return -1;
3806 *id++ = '\0';
3807
3808 name = os_strchr(id, ' ');
3809 if (name == NULL)
3810 return -1;
3811 *name++ = '\0';
3812
3813 id_s = atoi(cmd);
3814 id_d = atoi(id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003815
3816 wpa_printf(MSG_DEBUG,
3817 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3818 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003819
3820 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3821 if (ssid_s == NULL) {
3822 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3823 "network id=%d", id_s);
3824 return -1;
3825 }
3826
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003827 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003828 if (ssid_d == NULL) {
3829 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003830 "network id=%d", id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003831 return -1;
3832 }
3833
3834 value = wpa_config_get(ssid_s, name);
3835 if (value == NULL) {
3836 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3837 "variable '%s'", name);
3838 return -1;
3839 }
3840
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003841 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003842 value);
3843
3844 os_free(value);
3845
3846 return ret;
3847}
3848
3849
Dmitry Shmidt04949592012-07-19 12:16:46 -07003850static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3851 char *buf, size_t buflen)
3852{
3853 char *pos, *end;
3854 struct wpa_cred *cred;
3855 int ret;
3856
3857 pos = buf;
3858 end = buf + buflen;
3859 ret = os_snprintf(pos, end - pos,
3860 "cred id / realm / username / domain / imsi\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003861 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003862 return pos - buf;
3863 pos += ret;
3864
3865 cred = wpa_s->conf->cred;
3866 while (cred) {
3867 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3868 cred->id, cred->realm ? cred->realm : "",
3869 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07003870 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003871 cred->imsi ? cred->imsi : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003872 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003873 return pos - buf;
3874 pos += ret;
3875
3876 cred = cred->next;
3877 }
3878
3879 return pos - buf;
3880}
3881
3882
3883static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3884 char *buf, size_t buflen)
3885{
3886 struct wpa_cred *cred;
3887 int ret;
3888
3889 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3890
3891 cred = wpa_config_add_cred(wpa_s->conf);
3892 if (cred == NULL)
3893 return -1;
3894
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003895 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3896
Dmitry Shmidt04949592012-07-19 12:16:46 -07003897 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003898 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003899 return -1;
3900 return ret;
3901}
3902
3903
3904static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3905 char *cmd)
3906{
3907 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003908 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003909
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003910 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3911 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003912 if (os_strcmp(cmd, "all") == 0) {
3913 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
Hai Shaloma20dcd72022-02-04 13:43:00 -08003914 return wpas_remove_all_creds(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003915 }
3916
3917 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3918 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3919 cmd + 8);
3920 cred = wpa_s->conf->cred;
3921 while (cred) {
3922 prev = cred;
3923 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003924 if (prev->domain) {
3925 size_t i;
3926 for (i = 0; i < prev->num_domain; i++) {
3927 if (os_strcmp(prev->domain[i], cmd + 8)
3928 != 0)
3929 continue;
Hai Shaloma20dcd72022-02-04 13:43:00 -08003930 wpas_remove_cred(wpa_s, prev);
Dmitry Shmidt051af732013-10-22 13:52:46 -07003931 break;
3932 }
3933 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003934 }
3935 return 0;
3936 }
3937
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003938 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3939 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3940 cmd + 16);
3941 cred = wpa_s->conf->cred;
3942 while (cred) {
3943 prev = cred;
3944 cred = cred->next;
3945 if (prev->provisioning_sp &&
3946 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
Hai Shaloma20dcd72022-02-04 13:43:00 -08003947 wpas_remove_cred(wpa_s, prev);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003948 }
3949 return 0;
3950 }
3951
Dmitry Shmidt04949592012-07-19 12:16:46 -07003952 id = atoi(cmd);
3953 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3954
3955 cred = wpa_config_get_cred(wpa_s->conf, id);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003956 return wpas_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003957}
3958
3959
3960static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3961 char *cmd)
3962{
3963 int id;
3964 struct wpa_cred *cred;
3965 char *name, *value;
3966
3967 /* cmd: "<cred id> <variable name> <value>" */
3968 name = os_strchr(cmd, ' ');
3969 if (name == NULL)
3970 return -1;
3971 *name++ = '\0';
3972
3973 value = os_strchr(name, ' ');
3974 if (value == NULL)
3975 return -1;
3976 *value++ = '\0';
3977
3978 id = atoi(cmd);
3979 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3980 id, name);
3981 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3982 (u8 *) value, os_strlen(value));
3983
3984 cred = wpa_config_get_cred(wpa_s->conf, id);
3985 if (cred == NULL) {
3986 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3987 id);
3988 return -1;
3989 }
3990
3991 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3992 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3993 "variable '%s'", name);
3994 return -1;
3995 }
3996
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003997 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3998
Dmitry Shmidt04949592012-07-19 12:16:46 -07003999 return 0;
4000}
4001
4002
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07004003static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
4004 char *cmd, char *buf,
4005 size_t buflen)
4006{
4007 int id;
4008 size_t res;
4009 struct wpa_cred *cred;
4010 char *name, *value;
4011
4012 /* cmd: "<cred id> <variable name>" */
4013 name = os_strchr(cmd, ' ');
4014 if (name == NULL)
4015 return -1;
4016 *name++ = '\0';
4017
4018 id = atoi(cmd);
4019 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
4020 id, name);
4021
4022 cred = wpa_config_get_cred(wpa_s->conf, id);
4023 if (cred == NULL) {
4024 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
4025 id);
4026 return -1;
4027 }
4028
4029 value = wpa_config_get_cred_no_key(cred, name);
4030 if (value == NULL) {
4031 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
4032 name);
4033 return -1;
4034 }
4035
4036 res = os_strlcpy(buf, value, buflen);
4037 if (res >= buflen) {
4038 os_free(value);
4039 return -1;
4040 }
4041
4042 os_free(value);
4043
4044 return res;
4045}
4046
4047
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004048#ifndef CONFIG_NO_CONFIG_WRITE
4049static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
4050{
4051 int ret;
4052
4053 if (!wpa_s->conf->update_config) {
4054 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
4055 "to update configuration (update_config=0)");
4056 return -1;
4057 }
4058
4059 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
4060 if (ret) {
4061 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
4062 "update configuration");
4063 } else {
4064 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
4065 " updated");
4066 }
4067
4068 return ret;
4069}
4070#endif /* CONFIG_NO_CONFIG_WRITE */
4071
4072
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004073struct cipher_info {
4074 unsigned int capa;
4075 const char *name;
4076 int group_only;
4077};
4078
4079static const struct cipher_info ciphers[] = {
4080 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
4081 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
4082 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
4083 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07004084#ifndef CONFIG_NO_TKIP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004085 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07004086#endif /* CONFIG_NO_TKIP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004087 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
Hai Shalomfdcde762020-04-02 11:19:20 -07004088#ifdef CONFIG_WEP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004089 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
4090 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004091#endif /* CONFIG_WEP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004092};
4093
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004094static const struct cipher_info ciphers_group_mgmt[] = {
4095 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
4096 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
4097 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
4098 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
4099};
4100
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004101
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004102static int ctrl_iface_get_capability_pairwise(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004103 struct wpa_driver_capa *capa,
4104 char *buf, size_t buflen)
4105{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004106 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004107 char *pos, *end;
4108 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004109 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004110
4111 pos = buf;
4112 end = pos + buflen;
4113
4114 if (res < 0) {
4115 if (strict)
4116 return 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07004117#ifdef CONFIG_NO_TKIP
4118 len = os_strlcpy(buf, "CCMP NONE", buflen);
4119#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004120 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004121#endif /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004122 if (len >= buflen)
4123 return -1;
4124 return len;
4125 }
4126
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004127 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4128 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
4129 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004130 pos == buf ? "" : " ",
4131 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004132 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004133 return pos - buf;
4134 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004135 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004136 }
4137
4138 return pos - buf;
4139}
4140
4141
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004142static int ctrl_iface_get_capability_group(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004143 struct wpa_driver_capa *capa,
4144 char *buf, size_t buflen)
4145{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004146 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004147 char *pos, *end;
4148 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004149 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004150
4151 pos = buf;
4152 end = pos + buflen;
4153
4154 if (res < 0) {
4155 if (strict)
4156 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07004157#ifdef CONFIG_WEP
Hai Shalomb755a2a2020-04-23 21:49:02 -07004158#ifdef CONFIG_NO_TKIP
4159 len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen);
4160#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004161 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004162#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004163#else /* CONFIG_WEP */
Hai Shalomb755a2a2020-04-23 21:49:02 -07004164#ifdef CONFIG_NO_TKIP
4165 len = os_strlcpy(buf, "CCMP", buflen);
4166#else /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004167 len = os_strlcpy(buf, "CCMP TKIP", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004168#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004169#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004170 if (len >= buflen)
4171 return -1;
4172 return len;
4173 }
4174
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004175 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4176 if (capa->enc & ciphers[i].capa) {
4177 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004178 pos == buf ? "" : " ",
4179 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004180 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004181 return pos - buf;
4182 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004183 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004184 }
4185
4186 return pos - buf;
4187}
4188
4189
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004190static int ctrl_iface_get_capability_group_mgmt(int res, bool strict,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004191 struct wpa_driver_capa *capa,
4192 char *buf, size_t buflen)
4193{
4194 int ret;
4195 char *pos, *end;
4196 unsigned int i;
4197
4198 pos = buf;
4199 end = pos + buflen;
4200
4201 if (res < 0)
4202 return 0;
4203
4204 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
4205 if (capa->enc & ciphers_group_mgmt[i].capa) {
4206 ret = os_snprintf(pos, end - pos, "%s%s",
4207 pos == buf ? "" : " ",
4208 ciphers_group_mgmt[i].name);
4209 if (os_snprintf_error(end - pos, ret))
4210 return pos - buf;
4211 pos += ret;
4212 }
4213 }
4214
4215 return pos - buf;
4216}
4217
4218
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004219static int iftype_str_to_index(const char *iftype_str)
4220{
4221 if (!iftype_str)
4222 return WPA_IF_MAX;
4223
4224 if (os_strcmp(iftype_str, "STATION") == 0)
4225 return WPA_IF_STATION;
4226
4227 if (os_strcmp(iftype_str, "AP_VLAN") == 0)
4228 return WPA_IF_AP_VLAN;
4229
4230 if (os_strcmp(iftype_str, "AP") == 0)
4231 return WPA_IF_AP_BSS;
4232
4233 if (os_strcmp(iftype_str, "P2P_GO") == 0)
4234 return WPA_IF_P2P_GO;
4235
4236 if (os_strcmp(iftype_str, "P2P_CLIENT") == 0)
4237 return WPA_IF_P2P_CLIENT;
4238
4239 if (os_strcmp(iftype_str, "P2P_DEVICE") == 0)
4240 return WPA_IF_P2P_DEVICE;
4241
4242 if (os_strcmp(iftype_str, "MESH") == 0)
4243 return WPA_IF_MESH;
4244
4245 if (os_strcmp(iftype_str, "IBSS") == 0)
4246 return WPA_IF_IBSS;
4247
4248 if (os_strcmp(iftype_str, "NAN") == 0)
4249 return WPA_IF_NAN;
4250
4251 return WPA_IF_MAX;
4252}
4253
4254
4255static int ctrl_iface_get_capability_key_mgmt(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004256 struct wpa_driver_capa *capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004257 const char *iftype_str,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004258 char *buf, size_t buflen)
4259{
4260 int ret;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004261 unsigned int key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004262 char *pos, *end;
4263 size_t len;
4264
4265 pos = buf;
4266 end = pos + buflen;
4267
4268 if (res < 0) {
4269 if (strict)
4270 return 0;
4271 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4272 "NONE", buflen);
4273 if (len >= buflen)
4274 return -1;
4275 return len;
4276 }
4277
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004278 if (iftype_str) {
4279 enum wpa_driver_if_type iftype;
4280
4281 iftype = iftype_str_to_index(iftype_str);
4282 if (iftype == WPA_IF_MAX)
4283 return -1;
4284 key_mgmt = capa->key_mgmt_iftype[iftype];
4285 } else {
4286 key_mgmt = capa->key_mgmt;
4287 }
4288
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004289 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004290 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004291 return pos - buf;
4292 pos += ret;
4293
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004294 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4295 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004296 ret = os_snprintf(pos, end - pos, " WPA-EAP");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004297 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004298 return pos - buf;
4299 pos += ret;
4300 }
4301
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004302 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
4303 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004304 ret = os_snprintf(pos, end - pos, " WPA-PSK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004305 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004306 return pos - buf;
4307 pos += ret;
4308 }
4309
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004310 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004311 ret = os_snprintf(pos, end - pos, " WPA-NONE");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004312 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004313 return pos - buf;
4314 pos += ret;
4315 }
4316
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304317 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WAPI_PSK) {
4318 ret = os_snprintf(pos, end - pos, " WAPI-PSK");
4319 if (os_snprintf_error(end - pos, ret))
4320 return pos - buf;
4321 pos += ret;
4322 }
4323
4324 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE) {
4325 ret = os_snprintf(pos, end - pos, " TPK-HANDSHAKE");
4326 if (os_snprintf_error(end - pos, ret))
4327 return pos - buf;
4328 pos += ret;
4329 }
4330
4331 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_CCKM) {
4332 ret = os_snprintf(pos, end - pos, " CCKM");
4333 if (os_snprintf_error(end - pos, ret))
4334 return pos - buf;
4335 pos += ret;
4336 }
4337
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004338#ifdef CONFIG_SUITEB
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004339 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004340 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
4341 if (os_snprintf_error(end - pos, ret))
4342 return pos - buf;
4343 pos += ret;
4344 }
4345#endif /* CONFIG_SUITEB */
4346#ifdef CONFIG_SUITEB192
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004347 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004348 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
4349 if (os_snprintf_error(end - pos, ret))
4350 return pos - buf;
4351 pos += ret;
4352 }
4353#endif /* CONFIG_SUITEB192 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004354#ifdef CONFIG_OWE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004355 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004356 ret = os_snprintf(pos, end - pos, " OWE");
4357 if (os_snprintf_error(end - pos, ret))
4358 return pos - buf;
4359 pos += ret;
4360 }
4361#endif /* CONFIG_OWE */
4362#ifdef CONFIG_DPP
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004363 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004364 ret = os_snprintf(pos, end - pos, " DPP");
4365 if (os_snprintf_error(end - pos, ret))
4366 return pos - buf;
4367 pos += ret;
4368 }
4369#endif /* CONFIG_DPP */
4370#ifdef CONFIG_FILS
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004371 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004372 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
4373 if (os_snprintf_error(end - pos, ret))
4374 return pos - buf;
4375 pos += ret;
4376 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004377 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004378 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
4379 if (os_snprintf_error(end - pos, ret))
4380 return pos - buf;
4381 pos += ret;
4382 }
4383#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004384 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004385 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
4386 if (os_snprintf_error(end - pos, ret))
4387 return pos - buf;
4388 pos += ret;
4389 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004390 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004391 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
4392 if (os_snprintf_error(end - pos, ret))
4393 return pos - buf;
4394 pos += ret;
4395 }
4396#endif /* CONFIG_IEEE80211R */
4397#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08004398#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004399 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004400 ret = os_snprintf(pos, end - pos, " FT-PSK");
4401 if (os_snprintf_error(end - pos, ret))
4402 return pos - buf;
4403 pos += ret;
4404 }
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304405 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) {
4406 ret = os_snprintf(pos, end - pos, " FT-EAP");
4407 if (os_snprintf_error(end - pos, ret))
4408 return pos - buf;
4409 pos += ret;
4410 }
4411#ifdef CONFIG_SAE
4412 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE) {
4413 ret = os_snprintf(pos, end - pos, " FT-SAE");
4414 if (os_snprintf_error(end - pos, ret))
4415 return pos - buf;
4416 pos += ret;
4417 }
Sunil Ravi89eba102022-09-13 21:04:37 -07004418 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE_EXT_KEY) {
4419 ret = os_snprintf(pos, end - pos, " FT-SAE-EXT-KEY");
4420 if (os_snprintf_error(end - pos, ret))
4421 return pos - buf;
4422 pos += ret;
4423 }
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304424#endif /* CONFIG_SAE */
4425#ifdef CONFIG_SHA384
4426 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384) {
4427 ret = os_snprintf(pos, end - pos, " FT-EAP-SHA384");
4428 if (os_snprintf_error(end - pos, ret))
4429 return pos - buf;
4430 pos += ret;
4431 }
4432#endif /* CONFIG_SHA384 */
Hai Shalom74f70d42019-02-11 14:42:39 -08004433#endif /* CONFIG_IEEE80211R */
4434#ifdef CONFIG_SAE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004435 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004436 ret = os_snprintf(pos, end - pos, " SAE");
4437 if (os_snprintf_error(end - pos, ret))
4438 return pos - buf;
4439 pos += ret;
4440 }
Sunil Ravi89eba102022-09-13 21:04:37 -07004441 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE_EXT_KEY) {
4442 ret = os_snprintf(pos, end - pos, " SAE-EXT-KEY");
4443 if (os_snprintf_error(end - pos, ret))
4444 return pos - buf;
4445 pos += ret;
4446 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004447#endif /* CONFIG_SAE */
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304448#ifdef CONFIG_SHA256
4449 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256) {
4450 ret = os_snprintf(pos, end - pos, " WPA-EAP-SHA256");
4451 if (os_snprintf_error(end - pos, ret))
4452 return pos - buf;
4453 pos += ret;
4454 }
4455
4456 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256) {
4457 ret = os_snprintf(pos, end - pos, " WPA-PSK-SHA256");
4458 if (os_snprintf_error(end - pos, ret))
4459 return pos - buf;
4460 pos += ret;
4461 }
4462#endif /* CONFIG_SHA256 */
4463#ifdef CONFIG_HS20
4464 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OSEN) {
4465 ret = os_snprintf(pos, end - pos, " OSEN");
4466 if (os_snprintf_error(end - pos, ret))
4467 return pos - buf;
4468 pos += ret;
4469 }
4470#endif /* CONFIG_HS20 */
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004471
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004472 return pos - buf;
4473}
4474
4475
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004476static int ctrl_iface_get_capability_proto(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004477 struct wpa_driver_capa *capa,
4478 char *buf, size_t buflen)
4479{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004480 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004481 char *pos, *end;
4482 size_t len;
4483
4484 pos = buf;
4485 end = pos + buflen;
4486
4487 if (res < 0) {
4488 if (strict)
4489 return 0;
4490 len = os_strlcpy(buf, "RSN WPA", buflen);
4491 if (len >= buflen)
4492 return -1;
4493 return len;
4494 }
4495
4496 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4497 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004498 ret = os_snprintf(pos, end - pos, "%sRSN",
4499 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004500 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004501 return pos - buf;
4502 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004503 }
4504
4505 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4506 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004507 ret = os_snprintf(pos, end - pos, "%sWPA",
4508 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004509 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004510 return pos - buf;
4511 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004512 }
4513
4514 return pos - buf;
4515}
4516
4517
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004518static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004519 int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004520 struct wpa_driver_capa *capa,
4521 char *buf, size_t buflen)
4522{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004523 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004524 char *pos, *end;
4525 size_t len;
4526
4527 pos = buf;
4528 end = pos + buflen;
4529
4530 if (res < 0) {
4531 if (strict)
4532 return 0;
4533 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4534 if (len >= buflen)
4535 return -1;
4536 return len;
4537 }
4538
4539 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004540 ret = os_snprintf(pos, end - pos, "%sOPEN",
4541 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004542 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004543 return pos - buf;
4544 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004545 }
4546
4547 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4548 ret = os_snprintf(pos, end - pos, "%sSHARED",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004549 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004550 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004551 return pos - buf;
4552 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004553 }
4554
4555 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004556 ret = os_snprintf(pos, end - pos, "%sLEAP",
4557 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004558 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004559 return pos - buf;
4560 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004561 }
4562
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004563#ifdef CONFIG_SAE
4564 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4565 ret = os_snprintf(pos, end - pos, "%sSAE",
4566 pos == buf ? "" : " ");
4567 if (os_snprintf_error(end - pos, ret))
4568 return pos - buf;
4569 pos += ret;
4570 }
4571#endif /* CONFIG_SAE */
4572
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004573#ifdef CONFIG_FILS
4574 if (wpa_is_fils_supported(wpa_s)) {
4575 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4576 pos == buf ? "" : " ");
4577 if (os_snprintf_error(end - pos, ret))
4578 return pos - buf;
4579 pos += ret;
4580 }
4581
4582#ifdef CONFIG_FILS_SK_PFS
4583 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4584 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4585 pos == buf ? "" : " ");
4586 if (os_snprintf_error(end - pos, ret))
4587 return pos - buf;
4588 pos += ret;
4589 }
4590#endif /* CONFIG_FILS_SK_PFS */
4591#endif /* CONFIG_FILS */
4592
Hai Shalom60840252021-02-19 19:02:11 -08004593#ifdef CONFIG_PASN
4594 ret = os_snprintf(pos, end - pos, "%sPASN",
4595 pos == buf ? "" : " ");
4596 if (os_snprintf_error(end - pos, ret))
4597 return pos - buf;
4598 pos += ret;
4599
4600#endif /* CONFIG_PASN */
4601
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004602 return pos - buf;
4603}
4604
4605
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004606static int ctrl_iface_get_capability_modes(int res, bool strict,
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004607 struct wpa_driver_capa *capa,
4608 char *buf, size_t buflen)
4609{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004610 int ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004611 char *pos, *end;
4612 size_t len;
4613
4614 pos = buf;
4615 end = pos + buflen;
4616
4617 if (res < 0) {
4618 if (strict)
4619 return 0;
4620 len = os_strlcpy(buf, "IBSS AP", buflen);
4621 if (len >= buflen)
4622 return -1;
4623 return len;
4624 }
4625
4626 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004627 ret = os_snprintf(pos, end - pos, "%sIBSS",
4628 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004629 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004630 return pos - buf;
4631 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004632 }
4633
4634 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004635 ret = os_snprintf(pos, end - pos, "%sAP",
4636 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004637 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004638 return pos - buf;
4639 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004640 }
4641
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004642#ifdef CONFIG_MESH
4643 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4644 ret = os_snprintf(pos, end - pos, "%sMESH",
4645 pos == buf ? "" : " ");
4646 if (os_snprintf_error(end - pos, ret))
4647 return pos - buf;
4648 pos += ret;
4649 }
4650#endif /* CONFIG_MESH */
4651
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004652 return pos - buf;
4653}
4654
4655
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004656static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4657 char *buf, size_t buflen)
4658{
4659 struct hostapd_channel_data *chnl;
4660 int ret, i, j;
4661 char *pos, *end, *hmode;
4662
4663 pos = buf;
4664 end = pos + buflen;
4665
4666 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4667 switch (wpa_s->hw.modes[j].mode) {
4668 case HOSTAPD_MODE_IEEE80211B:
4669 hmode = "B";
4670 break;
4671 case HOSTAPD_MODE_IEEE80211G:
4672 hmode = "G";
4673 break;
4674 case HOSTAPD_MODE_IEEE80211A:
4675 hmode = "A";
4676 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004677 case HOSTAPD_MODE_IEEE80211AD:
4678 hmode = "AD";
4679 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004680 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004681 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004682 }
4683 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004684 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004685 return pos - buf;
4686 pos += ret;
4687 chnl = wpa_s->hw.modes[j].channels;
4688 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004689 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4690 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004691 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004692 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004693 return pos - buf;
4694 pos += ret;
4695 }
4696 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004697 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004698 return pos - buf;
4699 pos += ret;
4700 }
4701
4702 return pos - buf;
4703}
4704
4705
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004706static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4707 char *buf, size_t buflen)
4708{
4709 struct hostapd_channel_data *chnl;
4710 int ret, i, j;
4711 char *pos, *end, *hmode;
4712
4713 pos = buf;
4714 end = pos + buflen;
4715
4716 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4717 switch (wpa_s->hw.modes[j].mode) {
4718 case HOSTAPD_MODE_IEEE80211B:
4719 hmode = "B";
4720 break;
4721 case HOSTAPD_MODE_IEEE80211G:
4722 hmode = "G";
4723 break;
4724 case HOSTAPD_MODE_IEEE80211A:
4725 hmode = "A";
4726 break;
4727 case HOSTAPD_MODE_IEEE80211AD:
4728 hmode = "AD";
4729 break;
4730 default:
4731 continue;
4732 }
4733 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4734 hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004735 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004736 return pos - buf;
4737 pos += ret;
4738 chnl = wpa_s->hw.modes[j].channels;
4739 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4740 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4741 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004742 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004743 chnl[i].chan, chnl[i].freq,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004744 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4745 " (NO_IR)" : "",
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004746 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4747 " (DFS)" : "");
4748
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004749 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004750 return pos - buf;
4751 pos += ret;
4752 }
4753 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004754 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004755 return pos - buf;
4756 pos += ret;
4757 }
4758
4759 return pos - buf;
4760}
4761
4762
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004763static int wpa_supplicant_ctrl_iface_get_capability(
4764 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4765 size_t buflen)
4766{
4767 struct wpa_driver_capa capa;
4768 int res;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004769 char *next_param, *curr_param, *iftype = NULL;
4770 bool strict = false;
4771 char field[50];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004772 size_t len;
4773
4774 /* Determine whether or not strict checking was requested */
4775 len = os_strlcpy(field, _field, sizeof(field));
4776 if (len >= sizeof(field))
4777 return -1;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004778
4779 next_param = os_strchr(field, ' ');
4780 while (next_param) {
4781 *next_param++ = '\0';
4782 curr_param = next_param;
4783 next_param = os_strchr(next_param, ' ');
4784
4785 if (next_param)
4786 *next_param = '\0';
4787
4788 if (os_strcmp(curr_param, "strict") == 0)
4789 strict = true;
4790 else if (os_strncmp(curr_param, "iftype=", 7) == 0)
4791 iftype = curr_param + 7;
4792 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004793 return -1;
4794 }
4795
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004796 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'%s%s%s",
4797 field, iftype ? " iftype=" : "", iftype ? iftype : "",
4798 strict ? " strict" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004799
4800 if (os_strcmp(field, "eap") == 0) {
4801 return eap_get_names(buf, buflen);
4802 }
4803
4804 res = wpa_drv_get_capa(wpa_s, &capa);
4805
4806 if (os_strcmp(field, "pairwise") == 0)
4807 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4808 buf, buflen);
4809
4810 if (os_strcmp(field, "group") == 0)
4811 return ctrl_iface_get_capability_group(res, strict, &capa,
4812 buf, buflen);
4813
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004814 if (os_strcmp(field, "group_mgmt") == 0)
4815 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4816 buf, buflen);
4817
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004818 if (os_strcmp(field, "key_mgmt") == 0)
4819 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004820 iftype, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004821
4822 if (os_strcmp(field, "proto") == 0)
4823 return ctrl_iface_get_capability_proto(res, strict, &capa,
4824 buf, buflen);
4825
4826 if (os_strcmp(field, "auth_alg") == 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004827 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4828 &capa, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004829
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004830 if (os_strcmp(field, "modes") == 0)
4831 return ctrl_iface_get_capability_modes(res, strict, &capa,
4832 buf, buflen);
4833
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004834 if (os_strcmp(field, "channels") == 0)
4835 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4836
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004837 if (os_strcmp(field, "freq") == 0)
4838 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4839
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004840#ifdef CONFIG_TDLS
4841 if (os_strcmp(field, "tdls") == 0)
4842 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4843#endif /* CONFIG_TDLS */
4844
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004845#ifdef CONFIG_ERP
4846 if (os_strcmp(field, "erp") == 0) {
4847 res = os_snprintf(buf, buflen, "ERP");
4848 if (os_snprintf_error(buflen, res))
4849 return -1;
4850 return res;
4851 }
4852#endif /* CONFIG_EPR */
4853
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004854#ifdef CONFIG_FIPS
4855 if (os_strcmp(field, "fips") == 0) {
4856 res = os_snprintf(buf, buflen, "FIPS");
4857 if (os_snprintf_error(buflen, res))
4858 return -1;
4859 return res;
4860 }
4861#endif /* CONFIG_FIPS */
4862
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004863#ifdef CONFIG_ACS
4864 if (os_strcmp(field, "acs") == 0) {
4865 res = os_snprintf(buf, buflen, "ACS");
4866 if (os_snprintf_error(buflen, res))
4867 return -1;
4868 return res;
4869 }
4870#endif /* CONFIG_ACS */
4871
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004872#ifdef CONFIG_FILS
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004873 if (os_strcmp(field, "fils") == 0) {
4874#ifdef CONFIG_FILS_SK_PFS
4875 if (wpa_is_fils_supported(wpa_s) &&
4876 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4877 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4878 if (os_snprintf_error(buflen, res))
4879 return -1;
4880 return res;
4881 }
4882#endif /* CONFIG_FILS_SK_PFS */
4883
4884 if (wpa_is_fils_supported(wpa_s)) {
4885 res = os_snprintf(buf, buflen, "FILS");
4886 if (os_snprintf_error(buflen, res))
4887 return -1;
4888 return res;
4889 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004890 }
4891#endif /* CONFIG_FILS */
4892
Hai Shalom74f70d42019-02-11 14:42:39 -08004893 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
4894 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
4895 if (os_snprintf_error(buflen, res))
4896 return -1;
4897 return res;
4898 }
4899
Hai Shalom021b0b52019-04-10 11:17:58 -07004900#ifdef CONFIG_DPP
4901 if (os_strcmp(field, "dpp") == 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08004902#ifdef CONFIG_DPP3
4903 res = os_snprintf(buf, buflen, "DPP=3");
4904#elif defined(CONFIG_DPP2)
Hai Shalom021b0b52019-04-10 11:17:58 -07004905 res = os_snprintf(buf, buflen, "DPP=2");
4906#else /* CONFIG_DPP2 */
4907 res = os_snprintf(buf, buflen, "DPP=1");
4908#endif /* CONFIG_DPP2 */
4909 if (os_snprintf_error(buflen, res))
4910 return -1;
4911 return res;
4912 }
4913#endif /* CONFIG_DPP */
4914
Sunil Ravib0ac25f2024-07-12 01:42:03 +00004915#ifdef CONFIG_NAN_USD
4916 if (os_strcmp(field, "nan") == 0) {
4917 res = os_snprintf(buf, buflen, "USD");
4918 if (os_snprintf_error(buflen, res))
4919 return -1;
4920 return res;
4921 }
4922#endif /* CONFIG_NAN_USD */
4923
Hai Shalom899fcc72020-10-19 14:38:18 -07004924#ifdef CONFIG_SAE
4925 if (os_strcmp(field, "sae") == 0 &&
4926 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4927#ifdef CONFIG_SAE_PK
4928 res = os_snprintf(buf, buflen, "H2E PK");
4929#else /* CONFIG_SAE_PK */
4930 res = os_snprintf(buf, buflen, "H2E");
4931#endif /* CONFIG_SAE_PK */
4932 if (os_snprintf_error(buflen, res))
4933 return -1;
4934 return res;
4935 }
4936#endif /* CONFIG_SAE */
4937
Hai Shalom60840252021-02-19 19:02:11 -08004938#ifdef CONFIG_OCV
4939 if (os_strcmp(field, "ocv") == 0) {
4940 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
4941 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV))
4942 res = os_snprintf(buf, buflen, "supported");
4943 else
4944 res = os_snprintf(buf, buflen, "not supported");
4945 if (os_snprintf_error(buflen, res))
4946 return -1;
4947 return res;
4948 }
4949#endif /* CONFIG_OCV */
4950
4951 if (os_strcmp(field, "beacon_prot") == 0) {
4952 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) ||
4953 (wpa_s->drv_flags2 &
4954 WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT))
4955 res = os_snprintf(buf, buflen, "supported");
4956 else
4957 res = os_snprintf(buf, buflen, "not supported");
4958 if (os_snprintf_error(buflen, res))
4959 return -1;
4960 return res;
4961 }
4962
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004963 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4964 field);
4965
4966 return -1;
4967}
4968
4969
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004970#ifdef CONFIG_INTERWORKING
4971static char * anqp_add_hex(char *pos, char *end, const char *title,
4972 struct wpabuf *data)
4973{
4974 char *start = pos;
4975 size_t i;
4976 int ret;
4977 const u8 *d;
4978
4979 if (data == NULL)
4980 return start;
4981
4982 ret = os_snprintf(pos, end - pos, "%s=", title);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004983 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004984 return start;
4985 pos += ret;
4986
4987 d = wpabuf_head_u8(data);
4988 for (i = 0; i < wpabuf_len(data); i++) {
4989 ret = os_snprintf(pos, end - pos, "%02x", *d++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004990 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004991 return start;
4992 pos += ret;
4993 }
4994
4995 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004996 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004997 return start;
4998 pos += ret;
4999
5000 return pos;
5001}
5002#endif /* CONFIG_INTERWORKING */
5003
5004
Dmitry Shmidt29333592017-01-09 12:27:11 -08005005#ifdef CONFIG_FILS
5006static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
5007{
5008 char *start = pos;
5009 const u8 *ie, *ie_end;
5010 u16 info, realms;
5011 int ret;
5012
5013 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
5014 if (!ie)
5015 return 0;
5016 ie_end = ie + 2 + ie[1];
5017 ie += 2;
5018 if (ie_end - ie < 2)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005019 return 0;
Dmitry Shmidt29333592017-01-09 12:27:11 -08005020
5021 info = WPA_GET_LE16(ie);
5022 ie += 2;
5023 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
5024 if (os_snprintf_error(end - pos, ret))
5025 return 0;
5026 pos += ret;
5027
5028 if (info & BIT(7)) {
5029 /* Cache Identifier Included */
5030 if (ie_end - ie < 2)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005031 return 0;
Dmitry Shmidt29333592017-01-09 12:27:11 -08005032 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
5033 ie[0], ie[1]);
5034 if (os_snprintf_error(end - pos, ret))
5035 return 0;
5036 pos += ret;
5037 ie += 2;
5038 }
5039
5040 if (info & BIT(8)) {
5041 /* HESSID Included */
5042 if (ie_end - ie < ETH_ALEN)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005043 return 0;
Dmitry Shmidt29333592017-01-09 12:27:11 -08005044 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
5045 MAC2STR(ie));
5046 if (os_snprintf_error(end - pos, ret))
5047 return 0;
5048 pos += ret;
5049 ie += ETH_ALEN;
5050 }
5051
5052 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
5053 if (realms) {
5054 if (ie_end - ie < realms * 2)
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005055 return 0;
Dmitry Shmidt29333592017-01-09 12:27:11 -08005056 ret = os_snprintf(pos, end - pos, "fils_realms=");
5057 if (os_snprintf_error(end - pos, ret))
5058 return 0;
5059 pos += ret;
5060
5061 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
5062 if (ret <= 0)
5063 return 0;
5064 pos += ret;
5065 ie += realms * 2;
5066 ret = os_snprintf(pos, end - pos, "\n");
5067 if (os_snprintf_error(end - pos, ret))
5068 return 0;
5069 pos += ret;
5070 }
5071
5072 return pos - start;
5073}
5074#endif /* CONFIG_FILS */
5075
5076
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005077static int print_rnr(struct wpa_bss *bss, char *pos, char *end)
5078{
5079 char *start = pos;
5080 const u8 *ie, *ie_end;
5081 unsigned int n = 0;
5082 int ret;
5083
5084 ie = wpa_bss_get_ie(bss, WLAN_EID_REDUCED_NEIGHBOR_REPORT);
5085 if (!ie)
5086 return 0;
5087
5088 ie_end = ie + 2 + ie[1];
5089 ie += 2;
5090
5091 while (ie < ie_end) {
5092 const struct ieee80211_neighbor_ap_info *info =
5093 (const struct ieee80211_neighbor_ap_info *) ie;
5094 const u8 *tbtt_start;
5095 size_t left = ie_end - ie;
5096
5097 if (left < sizeof(struct ieee80211_neighbor_ap_info))
5098 return 0;
5099
5100 left -= sizeof(struct ieee80211_neighbor_ap_info);
5101 if (left < info->tbtt_info_len)
5102 return 0;
5103
5104 ret = os_snprintf(pos, end - pos,
5105 "ap_info[%u]: tbtt_info: hdr=0x%x, len=%u, op_c=%u, channel=%u, ",
5106 n, *ie, info->tbtt_info_len,
5107 info->op_class, info->channel);
5108 if (os_snprintf_error(end - pos, ret))
5109 return 0;
5110 pos += ret;
5111
5112 ie += sizeof(struct ieee80211_neighbor_ap_info);
5113 tbtt_start = ie;
5114 if (info->tbtt_info_len >= 1) {
5115 ret = os_snprintf(pos, end - pos,
5116 "tbtt_offset=%u, ", *ie);
5117 if (os_snprintf_error(end - pos, ret))
5118 return 0;
5119
5120 ie++;
5121 pos += ret;
5122 }
5123
5124 if (info->tbtt_info_len >= 7) {
5125 ret = os_snprintf(pos, end - pos,
5126 "bssid=" MACSTR ", ",
5127 MAC2STR(ie));
5128 if (os_snprintf_error(end - pos, ret))
5129 return 0;
5130
5131 ie += ETH_ALEN;
5132 pos += ret;
5133 }
5134
5135 if (info->tbtt_info_len >= 11) {
5136 ret = os_snprintf(pos, end - pos,
5137 "short SSID=0x%x, ",
5138 WPA_GET_LE32(ie));
5139 if (os_snprintf_error(end - pos, ret))
5140 return 0;
5141
5142 ie += 4;
5143 pos += ret;
5144 }
5145
5146 if (info->tbtt_info_len >= 12) {
5147 ret = os_snprintf(pos, end - pos,
5148 "bss_params=0x%x, ", *ie);
5149 if (os_snprintf_error(end - pos, ret))
5150 return 0;
5151
5152 ie++;
5153 pos += ret;
5154 }
5155
5156 if (info->tbtt_info_len >= 13) {
5157 ret = os_snprintf(pos, end - pos,
5158 "PSD=0x%x, ", *ie);
5159 if (os_snprintf_error(end - pos, ret))
5160 return 0;
5161
5162 ie++;
5163 pos += ret;
5164 }
5165
5166 if (info->tbtt_info_len >= 16) {
5167 ret = os_snprintf(pos, end - pos,
5168 "mld ID=%u, link ID=%u",
5169 *ie, *(ie + 1) & 0xF);
5170 if (os_snprintf_error(end - pos, ret))
5171 return 0;
5172
5173 ie += 3;
5174 pos += ret;
5175 }
5176
5177 ie = tbtt_start + info->tbtt_info_len;
5178
5179 ret = os_snprintf(pos, end - pos, "\n");
5180 if (os_snprintf_error(end - pos, ret))
5181 return 0;
5182 pos += ret;
5183
5184 n++;
5185 }
5186
5187 return pos - start;
5188}
5189
5190
5191static int print_ml(struct wpa_bss *bss, char *pos, char *end)
5192{
5193 const struct ieee80211_eht_ml *ml;
5194 char *start = pos;
5195 const u8 *ie, *ie_end;
5196 u16 ml_control;
5197 u8 common_info_length;
5198 int ret;
5199
5200 ie = get_ml_ie(wpa_bss_ie_ptr(bss), bss->ie_len,
5201 MULTI_LINK_CONTROL_TYPE_BASIC);
5202 if (!ie)
5203 return 0;
5204
5205 ie_end = ie + 2 + ie[1];
5206 ie += 3;
5207 ml = (const struct ieee80211_eht_ml *) ie;
5208
5209 /* control + common info length + MLD MAC Address */
5210 if (ie_end - ie < 2 + 1 + ETH_ALEN)
5211 return 0;
5212
5213 ml_control = le_to_host16(ml->ml_control);
5214
5215 common_info_length = *(ie + 2);
5216 ret = os_snprintf(pos, end - pos,
5217 "multi-link: control=0x%x, common info len=%u",
5218 ml_control, common_info_length);
5219 if (os_snprintf_error(end - pos, ret))
5220 return 0;
5221 pos += ret;
5222
5223 ie += 2;
5224 if (ie_end - ie < common_info_length)
5225 return 0;
5226
5227 ie++;
5228 common_info_length--;
5229
5230 if (common_info_length < ETH_ALEN)
5231 return 0;
5232
5233 ret = os_snprintf(pos, end - pos, ", MLD addr=" MACSTR, MAC2STR(ie));
5234 if (os_snprintf_error(end - pos, ret))
5235 return 0;
5236 pos += ret;
5237
5238 ie += ETH_ALEN;
5239 common_info_length -= ETH_ALEN;
5240
5241 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_LINK_ID) {
5242 if (common_info_length < 1)
5243 return 0;
5244
5245 ret = os_snprintf(pos, end - pos, ", link ID=%u", *ie & 0x0f);
5246 if (os_snprintf_error(end - pos, ret))
5247 return 0;
5248 pos += ret;
5249 ie++;
5250 common_info_length--;
5251 }
5252
5253 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT) {
5254 if (common_info_length < 1)
5255 return 0;
5256
5257 ret = os_snprintf(pos, end - pos,
5258 ", BSS change parameters=0x%x", *ie);
5259 if (os_snprintf_error(end - pos, ret))
5260 return 0;
5261 pos += ret;
5262 ie++;
5263 common_info_length--;
5264 }
5265
5266 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
5267 if (common_info_length < 2)
5268 return 0;
5269
5270 ret = os_snprintf(pos, end - pos, ", MSD Info=0x%x",
5271 WPA_GET_LE16(ie));
5272 if (os_snprintf_error(end - pos, ret))
5273 return 0;
5274 pos += ret;
5275 ie += 2;
5276 common_info_length -= 2;
5277 }
5278
5279 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
5280 if (common_info_length < 2)
5281 return 0;
5282
5283 ret = os_snprintf(pos, end - pos, ", EML capabilities=0x%x",
5284 WPA_GET_LE16(ie));
5285 if (os_snprintf_error(end - pos, ret))
5286 return 0;
5287 pos += ret;
5288 ie += 2;
5289 common_info_length -= 2;
5290 }
5291
5292 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
5293 if (common_info_length < 2)
5294 return 0;
5295
5296 ret = os_snprintf(pos, end - pos, ", MLD capabilities=0x%x",
5297 WPA_GET_LE16(ie));
5298 if (os_snprintf_error(end - pos, ret))
5299 return 0;
5300 pos += ret;
5301 ie += 2;
5302 common_info_length -= 2;
5303 }
5304
5305 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
5306 if (common_info_length < 1)
5307 return 0;
5308
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005309 ret = os_snprintf(pos, end - pos, ", MLD ID=0x%x", *ie);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005310 if (os_snprintf_error(end - pos, ret))
5311 return 0;
5312 pos += ret;
5313 ie += 1;
5314 common_info_length--;
5315 }
5316
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005317 ret = os_snprintf(pos, end - pos, "\n");
5318 if (os_snprintf_error(end - pos, ret))
5319 return 0;
5320 pos += ret;
5321
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005322 return pos - start;
5323}
5324
5325
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005326static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
5327 unsigned long mask, char *buf, size_t buflen)
5328{
5329 size_t i;
5330 int ret;
5331 char *pos, *end;
Hai Shalom899fcc72020-10-19 14:38:18 -07005332 const u8 *ie, *ie2, *osen_ie, *mesh, *owe, *rsnxe;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005333
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005334 pos = buf;
5335 end = buf + buflen;
5336
5337 if (mask & WPA_BSS_MASK_ID) {
5338 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005339 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005340 return 0;
5341 pos += ret;
5342 }
5343
5344 if (mask & WPA_BSS_MASK_BSSID) {
5345 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
5346 MAC2STR(bss->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005347 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005348 return 0;
5349 pos += ret;
5350 }
5351
5352 if (mask & WPA_BSS_MASK_FREQ) {
5353 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005354 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005355 return 0;
5356 pos += ret;
5357 }
5358
5359 if (mask & WPA_BSS_MASK_BEACON_INT) {
5360 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
5361 bss->beacon_int);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005362 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005363 return 0;
5364 pos += ret;
5365 }
5366
5367 if (mask & WPA_BSS_MASK_CAPABILITIES) {
5368 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
5369 bss->caps);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005370 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005371 return 0;
5372 pos += ret;
5373 }
5374
5375 if (mask & WPA_BSS_MASK_QUAL) {
5376 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005377 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005378 return 0;
5379 pos += ret;
5380 }
5381
5382 if (mask & WPA_BSS_MASK_NOISE) {
5383 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005384 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005385 return 0;
5386 pos += ret;
5387 }
5388
5389 if (mask & WPA_BSS_MASK_LEVEL) {
5390 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005391 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005392 return 0;
5393 pos += ret;
5394 }
5395
5396 if (mask & WPA_BSS_MASK_TSF) {
5397 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
5398 (unsigned long long) bss->tsf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005399 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005400 return 0;
5401 pos += ret;
5402 }
5403
5404 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005405 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005406
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005407 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005408 ret = os_snprintf(pos, end - pos, "age=%d\n",
5409 (int) (now.sec - bss->last_update.sec));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005410 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005411 return 0;
5412 pos += ret;
5413 }
5414
5415 if (mask & WPA_BSS_MASK_IE) {
5416 ret = os_snprintf(pos, end - pos, "ie=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005417 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005418 return 0;
5419 pos += ret;
5420
Hai Shalom60840252021-02-19 19:02:11 -08005421 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005422 for (i = 0; i < bss->ie_len; i++) {
5423 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005424 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005425 return 0;
5426 pos += ret;
5427 }
5428
5429 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005430 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005431 return 0;
5432 pos += ret;
5433 }
5434
5435 if (mask & WPA_BSS_MASK_FLAGS) {
5436 ret = os_snprintf(pos, end - pos, "flags=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005437 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005438 return 0;
5439 pos += ret;
5440
Dmitry Shmidt29333592017-01-09 12:27:11 -08005441 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
5442
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005443 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
5444 if (ie)
5445 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
5446 2 + ie[1]);
Sunil Ravi7f769292024-07-23 22:21:32 +00005447 ie2 = wpa_bss_get_rsne(wpa_s, bss, NULL, false);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005448 if (ie2)
Dmitry Shmidt29333592017-01-09 12:27:11 -08005449 pos = wpa_supplicant_ie_txt(pos, end,
5450 mesh ? "RSN" : "WPA2", ie2,
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005451 2 + ie2[1]);
Sunil Ravi7f769292024-07-23 22:21:32 +00005452 rsnxe = wpa_bss_get_rsnxe(wpa_s, bss, NULL, false);
Hai Shaloma20dcd72022-02-04 13:43:00 -08005453 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
5454 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
5455 if (os_snprintf_error(end - pos, ret))
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005456 return 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08005457 pos += ret;
5458 }
5459 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
5460 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
5461 if (os_snprintf_error(end - pos, ret))
Sunil Ravib0ac25f2024-07-12 01:42:03 +00005462 return 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08005463 pos += ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07005464 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005465 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
5466 if (osen_ie)
5467 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
5468 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005469 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
5470 if (owe) {
5471 ret = os_snprintf(
5472 pos, end - pos,
5473 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
5474 if (os_snprintf_error(end - pos, ret))
5475 return 0;
5476 pos += ret;
5477 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005478 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005479 if (!ie && !ie2 && !osen_ie &&
5480 (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005481 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005482 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005483 return 0;
5484 pos += ret;
5485 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005486
5487 if (mesh) {
5488 ret = os_snprintf(pos, end - pos, "[MESH]");
5489 if (os_snprintf_error(end - pos, ret))
5490 return 0;
5491 pos += ret;
5492 }
5493
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005494 if (bss_is_dmg(bss)) {
5495 const char *s;
5496 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005497 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005498 return 0;
5499 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005500 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
5501 case IEEE80211_CAP_DMG_IBSS:
5502 s = "[IBSS]";
5503 break;
5504 case IEEE80211_CAP_DMG_AP:
5505 s = "[ESS]";
5506 break;
5507 case IEEE80211_CAP_DMG_PBSS:
5508 s = "[PBSS]";
5509 break;
5510 default:
5511 s = "";
5512 break;
5513 }
5514 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005515 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005516 return 0;
5517 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005518 } else {
5519 if (bss->caps & IEEE80211_CAP_IBSS) {
5520 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005521 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005522 return 0;
5523 pos += ret;
5524 }
5525 if (bss->caps & IEEE80211_CAP_ESS) {
5526 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005527 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005528 return 0;
5529 pos += ret;
5530 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005531 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07005532 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
5533 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005534 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005535 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005536 return 0;
5537 pos += ret;
5538 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005539#ifdef CONFIG_HS20
5540 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
5541 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005542 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005543 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005544 pos += ret;
5545 }
5546#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005547#ifdef CONFIG_FILS
5548 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
5549 ret = os_snprintf(pos, end - pos, "[FILS]");
5550 if (os_snprintf_error(end - pos, ret))
5551 return 0;
5552 pos += ret;
5553 }
5554#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08005555#ifdef CONFIG_FST
5556 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
5557 ret = os_snprintf(pos, end - pos, "[FST]");
5558 if (os_snprintf_error(end - pos, ret))
5559 return 0;
5560 pos += ret;
5561 }
5562#endif /* CONFIG_FST */
5563 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
5564 ret = os_snprintf(pos, end - pos, "[UTF-8]");
5565 if (os_snprintf_error(end - pos, ret))
5566 return 0;
5567 pos += ret;
5568 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005569
5570 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005571 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005572 return 0;
5573 pos += ret;
5574 }
5575
5576 if (mask & WPA_BSS_MASK_SSID) {
5577 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
5578 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005579 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005580 return 0;
5581 pos += ret;
5582 }
5583
5584#ifdef CONFIG_WPS
5585 if (mask & WPA_BSS_MASK_WPS_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005586 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005587 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005588 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005589 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005590 if (ret > 0)
5591 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005592 }
5593#endif /* CONFIG_WPS */
5594
5595#ifdef CONFIG_P2P
5596 if (mask & WPA_BSS_MASK_P2P_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005597 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005598 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005599 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005600 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005601 if (ret > 0)
5602 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005603 }
5604#endif /* CONFIG_P2P */
5605
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005606#ifdef CONFIG_WIFI_DISPLAY
5607 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
5608 struct wpabuf *wfd;
Hai Shalom60840252021-02-19 19:02:11 -08005609
5610 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005611 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
5612 WFD_IE_VENDOR_TYPE);
5613 if (wfd) {
5614 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005615 if (os_snprintf_error(end - pos, ret)) {
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005616 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005617 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005618 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005619 pos += ret;
5620
5621 pos += wpa_snprintf_hex(pos, end - pos,
5622 wpabuf_head(wfd),
5623 wpabuf_len(wfd));
5624 wpabuf_free(wfd);
5625
5626 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005627 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005628 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005629 pos += ret;
5630 }
5631 }
5632#endif /* CONFIG_WIFI_DISPLAY */
5633
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005634#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005635 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
5636 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005637 struct wpa_bss_anqp_elem *elem;
5638
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005639 pos = anqp_add_hex(pos, end, "anqp_capability_list",
5640 anqp->capability_list);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005641 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005642 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005643 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005644 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005645 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005646 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005647 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005648 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005649 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005650 anqp->nai_realm);
5651 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005652 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005653 anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005654 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
5655 anqp->fils_realm_info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005656#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005657 pos = anqp_add_hex(pos, end, "hs20_capability_list",
5658 anqp->hs20_capability_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005659 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005660 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005661 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005662 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005663 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005664 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005665 pos = anqp_add_hex(pos, end, "hs20_operating_class",
5666 anqp->hs20_operating_class);
5667 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
5668 anqp->hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005669 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
5670 anqp->hs20_operator_icon_metadata);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005671 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
5672 anqp->hs20_osu_providers_nai_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005673#endif /* CONFIG_HS20 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005674
5675 dl_list_for_each(elem, &anqp->anqp_elems,
5676 struct wpa_bss_anqp_elem, list) {
5677 char title[20];
5678
5679 os_snprintf(title, sizeof(title), "anqp[%u]",
5680 elem->infoid);
5681 pos = anqp_add_hex(pos, end, title, elem->payload);
Hai Shalom60840252021-02-19 19:02:11 -08005682 if (elem->protected_response) {
5683 ret = os_snprintf(pos, end - pos,
5684 "protected-anqp-info[%u]=1\n",
5685 elem->infoid);
5686 if (os_snprintf_error(end - pos, ret))
5687 return 0;
5688 pos += ret;
5689 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005690 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005691 }
5692#endif /* CONFIG_INTERWORKING */
5693
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005694#ifdef CONFIG_MESH
5695 if (mask & WPA_BSS_MASK_MESH_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005696 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005697 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005698 if (ret >= end - pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005699 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005700 if (ret > 0)
5701 pos += ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005702 }
5703#endif /* CONFIG_MESH */
5704
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005705 if (mask & WPA_BSS_MASK_SNR) {
5706 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
5707 if (os_snprintf_error(end - pos, ret))
5708 return 0;
5709 pos += ret;
5710 }
5711
5712 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
5713 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
5714 bss->est_throughput);
5715 if (os_snprintf_error(end - pos, ret))
5716 return 0;
5717 pos += ret;
5718 }
5719
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005720#ifdef CONFIG_FST
5721 if (mask & WPA_BSS_MASK_FST) {
5722 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
5723 if (ret < 0 || ret >= end - pos)
5724 return 0;
5725 pos += ret;
5726 }
5727#endif /* CONFIG_FST */
5728
Dmitry Shmidt29333592017-01-09 12:27:11 -08005729 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
5730 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
5731 bss->last_update_idx);
5732 if (os_snprintf_error(end - pos, ret))
5733 return 0;
5734 pos += ret;
5735 }
5736
5737 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
5738 ret = os_snprintf(pos, end - pos, "beacon_ie=");
5739 if (os_snprintf_error(end - pos, ret))
5740 return 0;
5741 pos += ret;
5742
Hai Shalom60840252021-02-19 19:02:11 -08005743 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005744 ie += bss->ie_len;
5745 for (i = 0; i < bss->beacon_ie_len; i++) {
5746 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
5747 if (os_snprintf_error(end - pos, ret))
5748 return 0;
5749 pos += ret;
5750 }
5751
5752 ret = os_snprintf(pos, end - pos, "\n");
5753 if (os_snprintf_error(end - pos, ret))
5754 return 0;
5755 pos += ret;
5756 }
5757
5758#ifdef CONFIG_FILS
5759 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
5760 ret = print_fils_indication(bss, pos, end);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005761 pos += ret;
5762 }
5763#endif /* CONFIG_FILS */
5764
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005765 if (!is_zero_ether_addr(bss->mld_addr) &&
5766 (mask & WPA_BSS_MASK_AP_MLD_ADDR)) {
Sunil Ravi89eba102022-09-13 21:04:37 -07005767 ret = os_snprintf(pos, end - pos,
5768 "ap_mld_addr=" MACSTR "\n",
5769 MAC2STR(bss->mld_addr));
5770 if (os_snprintf_error(end - pos, ret))
5771 return 0;
5772 pos += ret;
5773 }
5774
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005775 if (mask & WPA_BSS_MASK_RNR)
5776 pos += print_rnr(bss, pos, end);
5777
5778 if (mask & WPA_BSS_MASK_ML)
5779 pos += print_ml(bss, pos, end);
5780
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005781 if (mask & WPA_BSS_MASK_DELIM) {
5782 ret = os_snprintf(pos, end - pos, "====\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005783 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005784 return 0;
5785 pos += ret;
5786 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07005787
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005788 return pos - buf;
5789}
5790
Dmitry Shmidt04949592012-07-19 12:16:46 -07005791
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005792static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
5793 const char *cmd, char *buf,
5794 size_t buflen)
5795{
5796 u8 bssid[ETH_ALEN];
5797 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005798 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005799 struct wpa_bss *bsslast = NULL;
5800 struct dl_list *next;
5801 int ret = 0;
5802 int len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005803 char *ctmp, *end = buf + buflen;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005804 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005805
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005806 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
5807 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
5808 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005809 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005810 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
5811 list_id);
5812 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005813 unsigned int id1, id2;
5814
5815 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
5816 wpa_printf(MSG_INFO, "Wrong BSS range "
5817 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005818 return 0;
5819 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005820
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005821 if (*(cmd + 6) == '-')
5822 id1 = 0;
5823 else
5824 id1 = atoi(cmd + 6);
5825 ctmp++;
5826 if (*ctmp >= '0' && *ctmp <= '9')
5827 id2 = atoi(ctmp);
5828 else
5829 id2 = (unsigned int) -1;
5830 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
5831 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005832 bsslast = dl_list_last(&wpa_s->bss_id,
5833 struct wpa_bss,
5834 list_id);
5835 else {
5836 bsslast = wpa_bss_get_id(wpa_s, id2);
5837 if (bsslast == NULL && bss && id2 > id1) {
5838 struct wpa_bss *tmp = bss;
5839 for (;;) {
5840 next = tmp->list_id.next;
5841 if (next == &wpa_s->bss_id)
5842 break;
5843 tmp = dl_list_entry(
5844 next, struct wpa_bss,
5845 list_id);
5846 if (tmp->id > id2)
5847 break;
5848 bsslast = tmp;
5849 }
5850 }
5851 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005852 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005853 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005854 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005855 else if (os_strncmp(cmd, "LAST", 4) == 0)
5856 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005857 else if (os_strncmp(cmd, "ID-", 3) == 0) {
5858 i = atoi(cmd + 3);
5859 bss = wpa_bss_get_id(wpa_s, i);
5860 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5861 i = atoi(cmd + 5);
5862 bss = wpa_bss_get_id(wpa_s, i);
5863 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005864 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005865 if (next == &wpa_s->bss_id)
5866 bss = NULL;
5867 else
5868 bss = dl_list_entry(next, struct wpa_bss,
5869 list_id);
5870 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005871 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5872 bss = wpa_s->current_bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005873#ifdef CONFIG_P2P
5874 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5875 if (hwaddr_aton(cmd + 13, bssid) == 0)
5876 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5877 else
5878 bss = NULL;
5879#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005880 } else if (hwaddr_aton(cmd, bssid) == 0)
5881 bss = wpa_bss_get_bssid(wpa_s, bssid);
5882 else {
5883 struct wpa_bss *tmp;
5884 i = atoi(cmd);
5885 bss = NULL;
5886 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5887 {
Hai Shalom021b0b52019-04-10 11:17:58 -07005888 if (i == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005889 bss = tmp;
5890 break;
5891 }
Hai Shalom021b0b52019-04-10 11:17:58 -07005892 i--;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005893 }
5894 }
5895
Dmitry Shmidt04949592012-07-19 12:16:46 -07005896 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5897 mask = strtoul(ctmp + 5, NULL, 0x10);
5898 if (mask == 0)
5899 mask = WPA_BSS_MASK_ALL;
5900 }
5901
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005902 if (bss == NULL)
5903 return 0;
5904
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005905 if (bsslast == NULL)
5906 bsslast = bss;
5907 do {
5908 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5909 ret += len;
5910 buf += len;
5911 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005912 if (bss == bsslast) {
5913 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5914 (bss == dl_list_last(&wpa_s->bss_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005915 struct wpa_bss, list_id))) {
5916 int res;
5917
5918 res = os_snprintf(buf - 5, end - buf + 5,
5919 "####\n");
5920 if (os_snprintf_error(end - buf + 5, res)) {
5921 wpa_printf(MSG_DEBUG,
5922 "Could not add end delim");
5923 }
5924 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005925 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005926 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005927 next = bss->list_id.next;
5928 if (next == &wpa_s->bss_id)
5929 break;
5930 bss = dl_list_entry(next, struct wpa_bss, list_id);
5931 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005932
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005933 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005934}
5935
5936
5937static int wpa_supplicant_ctrl_iface_ap_scan(
5938 struct wpa_supplicant *wpa_s, char *cmd)
5939{
5940 int ap_scan = atoi(cmd);
5941 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5942}
5943
5944
5945static int wpa_supplicant_ctrl_iface_scan_interval(
5946 struct wpa_supplicant *wpa_s, char *cmd)
5947{
5948 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005949 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005950}
5951
5952
5953static int wpa_supplicant_ctrl_iface_bss_expire_age(
5954 struct wpa_supplicant *wpa_s, char *cmd)
5955{
5956 int expire_age = atoi(cmd);
5957 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5958}
5959
5960
5961static int wpa_supplicant_ctrl_iface_bss_expire_count(
5962 struct wpa_supplicant *wpa_s, char *cmd)
5963{
5964 int expire_count = atoi(cmd);
5965 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5966}
5967
5968
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005969static void wpa_supplicant_ctrl_iface_bss_flush(
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005970 struct wpa_supplicant *wpa_s, char *cmd)
5971{
5972 int flush_age = atoi(cmd);
5973
5974 if (flush_age == 0)
5975 wpa_bss_flush(wpa_s);
5976 else
5977 wpa_bss_flush_by_age(wpa_s, flush_age);
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005978}
5979
5980
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005981#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005982static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5983{
5984 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5985 /* MLME-DELETEKEYS.request */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005986 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005987 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005988 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005989 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005990 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005991 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005992 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005993 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005994 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005995 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005996 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005997 0, KEY_FLAG_GROUP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005998
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005999 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0,
6000 NULL, 0, KEY_FLAG_PAIRWISE);
Hai Shalomfdcde762020-04-02 11:19:20 -07006001 if (wpa_sm_ext_key_id(wpa_s->wpa))
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00006002 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, wpa_s->bssid, 1, 0,
Hai Shalomfdcde762020-04-02 11:19:20 -07006003 NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006004 /* MLME-SETPROTECTION.request(None) */
6005 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
6006 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
6007 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
6008 wpa_sm_drop_sa(wpa_s->wpa);
6009}
Dmitry Shmidt21de2142014-04-08 10:50:52 -07006010#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006011
6012
6013static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
6014 char *addr)
6015{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006016#ifdef CONFIG_NO_SCAN_PROCESSING
6017 return -1;
6018#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006019 u8 bssid[ETH_ALEN];
6020 struct wpa_bss *bss;
6021 struct wpa_ssid *ssid = wpa_s->current_ssid;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006022 struct wpa_radio_work *already_connecting;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006023
6024 if (hwaddr_aton(addr, bssid)) {
6025 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
6026 "address '%s'", addr);
6027 return -1;
6028 }
6029
6030 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
6031
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006032 if (!ssid) {
6033 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
6034 "configuration known for the target AP");
6035 return -1;
6036 }
6037
Sunil Ravic0f5d412024-09-11 22:12:49 +00006038 bss = wpa_bss_get_connection(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006039 if (!bss) {
6040 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
6041 "from BSS table");
6042 return -1;
6043 }
6044
6045 /*
6046 * TODO: Find best network configuration block from configuration to
6047 * allow roaming to other networks
6048 */
6049
Hai Shaloma20dcd72022-02-04 13:43:00 -08006050 already_connecting = radio_work_pending(wpa_s, "sme-connect");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006051 wpa_s->reassociate = 1;
6052 wpa_supplicant_connect(wpa_s, bss, ssid);
6053
Hai Shaloma20dcd72022-02-04 13:43:00 -08006054 /*
6055 * Indicate that an explicitly requested roam is in progress so scan
6056 * results that come in before the 'sme-connect' radio work gets
6057 * executed do not override the original connection attempt.
6058 */
6059 if (!already_connecting && radio_work_pending(wpa_s, "sme-connect"))
6060 wpa_s->roam_in_progress = true;
6061
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006062 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006063#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006064}
6065
6066
6067#ifdef CONFIG_P2P
6068static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
6069{
6070 unsigned int timeout = atoi(cmd);
6071 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006072 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08006073 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006074 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006075 unsigned int search_delay;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006076 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006077 u8 seek_count = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006078 int freq = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006079 bool include_6ghz = false;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006080
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006081 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6082 wpa_dbg(wpa_s, MSG_INFO,
6083 "Reject P2P_FIND since interface is disabled");
6084 return -1;
6085 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08006086
6087 if (os_strstr(cmd, " include_6ghz"))
6088 include_6ghz = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006089 if (os_strstr(cmd, "type=social"))
6090 type = P2P_FIND_ONLY_SOCIAL;
6091 else if (os_strstr(cmd, "type=progressive"))
6092 type = P2P_FIND_PROGRESSIVE;
6093
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006094 pos = os_strstr(cmd, "dev_id=");
6095 if (pos) {
6096 pos += 7;
6097 if (hwaddr_aton(pos, dev_id))
6098 return -1;
6099 _dev_id = dev_id;
6100 }
6101
Dmitry Shmidt344abd32014-01-14 13:17:00 -08006102 pos = os_strstr(cmd, "dev_type=");
6103 if (pos) {
6104 pos += 9;
6105 if (wps_dev_type_str2bin(pos, dev_type) < 0)
6106 return -1;
6107 _dev_type = dev_type;
6108 }
6109
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006110 pos = os_strstr(cmd, "delay=");
6111 if (pos) {
6112 pos += 6;
6113 search_delay = atoi(pos);
6114 } else
6115 search_delay = wpas_p2p_search_delay(wpa_s);
6116
Dmitry Shmidt41712582015-06-29 11:02:15 -07006117 pos = os_strstr(cmd, "freq=");
6118 if (pos) {
6119 pos += 5;
6120 freq = atoi(pos);
6121 if (freq <= 0)
6122 return -1;
6123 }
6124
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006125 /* Must be searched for last, because it adds nul termination */
6126 pos = os_strstr(cmd, " seek=");
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006127 if (pos)
6128 pos += 6;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006129 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
6130 char *term;
6131
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006132 _seek[seek_count++] = pos;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006133 seek = _seek;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006134 term = os_strchr(pos, ' ');
6135 if (!term)
6136 break;
6137 *term = '\0';
6138 pos = os_strstr(term + 1, "seek=");
6139 if (pos)
6140 pos += 5;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006141 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006142 if (seek_count > P2P_MAX_QUERY_HASH) {
6143 seek[0] = NULL;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006144 seek_count = 1;
6145 }
6146
Dmitry Shmidt344abd32014-01-14 13:17:00 -08006147 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006148 _dev_id, search_delay, seek_count, seek, freq,
6149 include_6ghz);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006150}
6151
6152
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006153static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
6154{
6155 const char *last = NULL;
6156 const char *token;
6157 long int token_len;
6158 unsigned int i;
6159
6160 /* Expected predefined CPT names delimited by ':' */
6161 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
6162 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
6163 wpa_printf(MSG_ERROR,
6164 "P2PS: CPT name list is too long, expected up to %d names",
6165 P2PS_FEATURE_CAPAB_CPT_MAX);
6166 cpt[0] = 0;
6167 return -1;
6168 }
6169
6170 token_len = last - token;
6171
6172 if (token_len == 3 &&
6173 os_memcmp(token, "UDP", token_len) == 0) {
6174 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6175 } else if (token_len == 3 &&
6176 os_memcmp(token, "MAC", token_len) == 0) {
6177 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
6178 } else {
6179 wpa_printf(MSG_ERROR,
6180 "P2PS: Unsupported CPT name '%s'", token);
6181 cpt[0] = 0;
6182 return -1;
6183 }
6184
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006185 if (isblank((unsigned char) *last)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006186 i++;
6187 break;
6188 }
6189 }
6190 cpt[i] = 0;
6191 return 0;
6192}
6193
6194
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006195static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
6196{
6197 struct p2ps_provision *p2ps_prov;
6198 char *pos;
6199 size_t info_len = 0;
6200 char *info = NULL;
6201 u8 role = P2PS_SETUP_NONE;
6202 long long unsigned val;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006203 int i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006204
6205 pos = os_strstr(cmd, "info=");
6206 if (pos) {
6207 pos += 5;
6208 info_len = os_strlen(pos);
6209
6210 if (info_len) {
6211 info = os_malloc(info_len + 1);
6212 if (info) {
6213 info_len = utf8_unescape(pos, info_len,
6214 info, info_len + 1);
6215 } else
6216 info_len = 0;
6217 }
6218 }
6219
6220 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
6221 if (p2ps_prov == NULL) {
6222 os_free(info);
6223 return NULL;
6224 }
6225
6226 if (info) {
6227 os_memcpy(p2ps_prov->info, info, info_len);
6228 p2ps_prov->info[info_len] = '\0';
6229 os_free(info);
6230 }
6231
6232 pos = os_strstr(cmd, "status=");
6233 if (pos)
6234 p2ps_prov->status = atoi(pos + 7);
6235 else
6236 p2ps_prov->status = -1;
6237
6238 pos = os_strstr(cmd, "adv_id=");
6239 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
6240 goto invalid_args;
6241 p2ps_prov->adv_id = val;
6242
6243 pos = os_strstr(cmd, "method=");
6244 if (pos)
6245 p2ps_prov->method = strtol(pos + 7, NULL, 16);
6246 else
6247 p2ps_prov->method = 0;
6248
6249 pos = os_strstr(cmd, "session=");
6250 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
6251 goto invalid_args;
6252 p2ps_prov->session_id = val;
6253
6254 pos = os_strstr(cmd, "adv_mac=");
6255 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
6256 goto invalid_args;
6257
6258 pos = os_strstr(cmd, "session_mac=");
6259 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
6260 goto invalid_args;
6261
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006262 pos = os_strstr(cmd, "cpt=");
6263 if (pos) {
6264 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
6265 p2ps_prov->cpt_priority))
6266 goto invalid_args;
6267 } else {
6268 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6269 }
6270
6271 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
6272 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
6273
Hai Shaloma20dcd72022-02-04 13:43:00 -08006274 /* force conncap with tstCap (no validity checks) */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006275 pos = os_strstr(cmd, "tstCap=");
6276 if (pos) {
6277 role = strtol(pos + 7, NULL, 16);
6278 } else {
6279 pos = os_strstr(cmd, "role=");
6280 if (pos) {
6281 role = strtol(pos + 5, NULL, 16);
6282 if (role != P2PS_SETUP_CLIENT &&
6283 role != P2PS_SETUP_GROUP_OWNER)
6284 role = P2PS_SETUP_NONE;
6285 }
6286 }
6287 p2ps_prov->role = role;
6288
6289 return p2ps_prov;
6290
6291invalid_args:
6292 os_free(p2ps_prov);
6293 return NULL;
6294}
6295
6296
6297static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
6298{
6299 u8 addr[ETH_ALEN];
6300 struct p2ps_provision *p2ps_prov;
6301 char *pos;
6302
6303 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
6304
6305 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
6306
6307 if (hwaddr_aton(cmd, addr))
6308 return -1;
6309
6310 pos = cmd + 17;
6311 if (*pos != ' ')
6312 return -1;
6313
6314 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
6315 if (!p2ps_prov)
6316 return -1;
6317
6318 if (p2ps_prov->status < 0) {
6319 os_free(p2ps_prov);
6320 return -1;
6321 }
6322
6323 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
6324 p2ps_prov);
6325}
6326
6327
6328static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
6329{
6330 u8 addr[ETH_ALEN];
6331 struct p2ps_provision *p2ps_prov;
6332 char *pos;
6333
6334 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
6335 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
6336 */
6337
6338 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
6339 if (hwaddr_aton(cmd, addr))
6340 return -1;
6341
6342 pos = cmd + 17;
6343 if (*pos != ' ')
6344 return -1;
6345
6346 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
6347 if (!p2ps_prov)
6348 return -1;
6349
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006350 p2ps_prov->pd_seeker = 1;
6351
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006352 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
6353 p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006354}
6355
6356
6357static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
6358 char *buf, size_t buflen)
6359{
6360 u8 addr[ETH_ALEN];
6361 char *pos, *pos2;
6362 char *pin = NULL;
6363 enum p2p_wps_method wps_method;
6364 int new_pin;
6365 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006366 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006367 int join;
6368 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006369 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006370 int go_intent = -1;
6371 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006372 int pd;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006373 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006374 int edmg;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006375 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
6376 size_t group_ssid_len = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08006377 int he;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006378 bool allow_6ghz;
Sunil Ravic0f5d412024-09-11 22:12:49 +00006379 bool p2p2;
6380 u16 bootstrap = 0;
6381 const char *password = NULL;
6382 char *token, *context = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006383
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006384 if (!wpa_s->global->p2p_init_wpa_s)
6385 return -1;
6386 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
6387 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
6388 wpa_s->global->p2p_init_wpa_s->ifname);
6389 wpa_s = wpa_s->global->p2p_init_wpa_s;
6390 }
6391
Sunil Ravic0f5d412024-09-11 22:12:49 +00006392 /* <addr> <"pbc" | "pin" | "pair" | PIN> [label|display|keypad|p2ps]
Dmitry Shmidt04949592012-07-19 12:16:46 -07006393 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006394 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Sunil Ravic0f5d412024-09-11 22:12:49 +00006395 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>]
6396 * [p2p2] [bstrapmethod=<value>] [password=<string>]
6397 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006398
6399 if (hwaddr_aton(cmd, addr))
6400 return -1;
6401
6402 pos = cmd + 17;
6403 if (*pos != ' ')
6404 return -1;
6405 pos++;
6406
6407 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006408 pos2 = os_strstr(pos, " persistent=");
6409 if (pos2) {
6410 struct wpa_ssid *ssid;
6411 persistent_id = atoi(pos2 + 12);
6412 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
6413 if (ssid == NULL || ssid->disabled != 2 ||
6414 ssid->mode != WPAS_MODE_P2P_GO) {
6415 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
6416 "SSID id=%d for persistent P2P group (GO)",
6417 persistent_id);
6418 return -1;
6419 }
6420 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006421 join = os_strstr(pos, " join") != NULL;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006422 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006423 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006424 automatic = os_strstr(pos, " auto") != NULL;
6425 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006426 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6427 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6428 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006429 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006430 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Sunil Ravic0f5d412024-09-11 22:12:49 +00006431 p2p2 = os_strstr(pos, " p2p2") != NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006432
6433 pos2 = os_strstr(pos, " go_intent=");
6434 if (pos2) {
6435 pos2 += 11;
6436 go_intent = atoi(pos2);
6437 if (go_intent < 0 || go_intent > 15)
6438 return -1;
6439 }
6440
6441 pos2 = os_strstr(pos, " freq=");
6442 if (pos2) {
6443 pos2 += 6;
6444 freq = atoi(pos2);
6445 if (freq <= 0)
6446 return -1;
6447 }
6448
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006449 pos2 = os_strstr(pos, " freq2=");
6450 if (pos2)
6451 freq2 = atoi(pos2 + 7);
6452
6453 pos2 = os_strstr(pos, " max_oper_chwidth=");
6454 if (pos2)
6455 chwidth = atoi(pos2 + 18);
6456
Sunil Ravib0ac25f2024-07-12 01:42:03 +00006457 max_oper_chwidth = chwidth_freq2_to_ch_width(chwidth, freq2);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006458 if (max_oper_chwidth < 0)
6459 return -1;
6460
Hai Shaloma20dcd72022-02-04 13:43:00 -08006461 if (allow_6ghz && chwidth == 40)
Sunil8cd6f4d2022-06-28 18:40:46 +00006462 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006463
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006464 pos2 = os_strstr(pos, " ssid=");
6465 if (pos2) {
6466 char *end;
6467
6468 pos2 += 6;
6469 end = os_strchr(pos2, ' ');
6470 if (!end)
6471 group_ssid_len = os_strlen(pos2) / 2;
6472 else
6473 group_ssid_len = (end - pos2) / 2;
6474 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
6475 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
6476 return -1;
6477 group_ssid = _group_ssid;
6478 }
6479
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006480 if (os_strncmp(pos, "pin", 3) == 0) {
6481 /* Request random PIN (to be displayed) and enable the PIN */
6482 wps_method = WPS_PIN_DISPLAY;
6483 } else if (os_strncmp(pos, "pbc", 3) == 0) {
6484 wps_method = WPS_PBC;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006485 } else if (os_strstr(pos, "p2ps") != NULL) {
6486 wps_method = WPS_P2PS;
Sunil Ravic0f5d412024-09-11 22:12:49 +00006487 } else if (os_strncmp(pos, "pair", 4) == 0 && p2p2) {
6488 wps_method = WPS_NOT_READY;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006489 } else {
6490 pin = pos;
6491 pos = os_strchr(pin, ' ');
6492 wps_method = WPS_PIN_KEYPAD;
6493 if (pos) {
6494 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006495 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006496 wps_method = WPS_PIN_DISPLAY;
6497 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006498 if (!wps_pin_str_valid(pin)) {
6499 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
6500 return 17;
6501 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006502 }
6503
Sunil Ravic0f5d412024-09-11 22:12:49 +00006504 pos2 = os_strstr(pos, "bstrapmethod=");
6505 if (pos2) {
6506 pos2 += 13;
6507 bootstrap = atoi(pos2);
6508 pd = true;
6509 }
6510
6511 while ((token = str_token(pos, " ", &context))) {
6512 if (os_strncmp(token, "password=", 9) == 0) {
6513 password = token + 9;
6514 continue;
6515 }
6516 }
6517
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006518 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006519 persistent_group, automatic, join,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006520 auth, go_intent, freq, freq2, persistent_id,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006521 pd, ht40, vht, max_oper_chwidth, he, edmg,
Sunil Ravic0f5d412024-09-11 22:12:49 +00006522 group_ssid, group_ssid_len, allow_6ghz, p2p2,
6523 bootstrap, password);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006524 if (new_pin == -2) {
6525 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
6526 return 25;
6527 }
6528 if (new_pin == -3) {
6529 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
6530 return 25;
6531 }
6532 if (new_pin < 0)
6533 return -1;
6534 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
6535 ret = os_snprintf(buf, buflen, "%08d", new_pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006536 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006537 return -1;
6538 return ret;
6539 }
6540
6541 os_memcpy(buf, "OK\n", 3);
6542 return 3;
6543}
6544
6545
6546static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
6547{
6548 unsigned int timeout = atoi(cmd);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006549 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6550 wpa_dbg(wpa_s, MSG_INFO,
6551 "Reject P2P_LISTEN since interface is disabled");
6552 return -1;
6553 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006554 return wpas_p2p_listen(wpa_s, timeout);
6555}
6556
6557
6558static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
6559{
6560 u8 addr[ETH_ALEN];
6561 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006562 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006563
Dmitry Shmidt04949592012-07-19 12:16:46 -07006564 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006565
6566 if (hwaddr_aton(cmd, addr))
6567 return -1;
6568
6569 pos = cmd + 17;
6570 if (*pos != ' ')
6571 return -1;
6572 pos++;
6573
Dmitry Shmidt04949592012-07-19 12:16:46 -07006574 if (os_strstr(pos, " join") != NULL)
6575 use = WPAS_P2P_PD_FOR_JOIN;
6576 else if (os_strstr(pos, " auto") != NULL)
6577 use = WPAS_P2P_PD_AUTO;
6578
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006579 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006580}
6581
6582
6583static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
6584 size_t buflen)
6585{
6586 struct wpa_ssid *ssid = wpa_s->current_ssid;
6587
6588 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
6589 ssid->passphrase == NULL)
6590 return -1;
6591
6592 os_strlcpy(buf, ssid->passphrase, buflen);
6593 return os_strlen(buf);
6594}
6595
6596
6597static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
6598 char *buf, size_t buflen)
6599{
6600 u64 ref;
6601 int res;
6602 u8 dst_buf[ETH_ALEN], *dst;
6603 struct wpabuf *tlvs;
6604 char *pos;
6605 size_t len;
6606
6607 if (hwaddr_aton(cmd, dst_buf))
6608 return -1;
6609 dst = dst_buf;
6610 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
6611 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
6612 dst = NULL;
6613 pos = cmd + 17;
6614 if (*pos != ' ')
6615 return -1;
6616 pos++;
6617
6618 if (os_strncmp(pos, "upnp ", 5) == 0) {
6619 u8 version;
6620 pos += 5;
6621 if (hexstr2bin(pos, &version, 1) < 0)
6622 return -1;
6623 pos += 2;
6624 if (*pos != ' ')
6625 return -1;
6626 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006627 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006628#ifdef CONFIG_WIFI_DISPLAY
6629 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
6630 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
6631#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006632 } else if (os_strncmp(pos, "asp ", 4) == 0) {
6633 char *svc_str;
6634 char *svc_info = NULL;
6635 u32 id;
6636
6637 pos += 4;
6638 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
6639 return -1;
6640
6641 pos = os_strchr(pos, ' ');
6642 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
6643 return -1;
6644
6645 svc_str = pos + 1;
6646
6647 pos = os_strchr(svc_str, ' ');
6648
6649 if (pos)
6650 *pos++ = '\0';
6651
6652 /* All remaining data is the svc_info string */
6653 if (pos && pos[0] && pos[0] != ' ') {
6654 len = os_strlen(pos);
6655
6656 /* Unescape in place */
6657 len = utf8_unescape(pos, len, pos, len);
6658 if (len > 0xff)
6659 return -1;
6660
6661 svc_info = pos;
6662 }
6663
6664 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
6665 svc_str, svc_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006666 } else {
6667 len = os_strlen(pos);
6668 if (len & 1)
6669 return -1;
6670 len /= 2;
6671 tlvs = wpabuf_alloc(len);
6672 if (tlvs == NULL)
6673 return -1;
6674 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
6675 wpabuf_free(tlvs);
6676 return -1;
6677 }
6678
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006679 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006680 wpabuf_free(tlvs);
6681 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006682 if (ref == 0)
6683 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006684 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006685 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006686 return -1;
6687 return res;
6688}
6689
6690
6691static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
6692 char *cmd)
6693{
6694 long long unsigned val;
6695 u64 req;
6696 if (sscanf(cmd, "%llx", &val) != 1)
6697 return -1;
6698 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006699 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006700}
6701
6702
6703static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
6704{
6705 int freq;
6706 u8 dst[ETH_ALEN];
6707 u8 dialog_token;
6708 struct wpabuf *resp_tlvs;
6709 char *pos, *pos2;
6710 size_t len;
6711
6712 pos = os_strchr(cmd, ' ');
6713 if (pos == NULL)
6714 return -1;
6715 *pos++ = '\0';
6716 freq = atoi(cmd);
6717 if (freq == 0)
6718 return -1;
6719
6720 if (hwaddr_aton(pos, dst))
6721 return -1;
6722 pos += 17;
6723 if (*pos != ' ')
6724 return -1;
6725 pos++;
6726
6727 pos2 = os_strchr(pos, ' ');
6728 if (pos2 == NULL)
6729 return -1;
6730 *pos2++ = '\0';
6731 dialog_token = atoi(pos);
6732
6733 len = os_strlen(pos2);
6734 if (len & 1)
6735 return -1;
6736 len /= 2;
6737 resp_tlvs = wpabuf_alloc(len);
6738 if (resp_tlvs == NULL)
6739 return -1;
6740 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
6741 wpabuf_free(resp_tlvs);
6742 return -1;
6743 }
6744
6745 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
6746 wpabuf_free(resp_tlvs);
6747 return 0;
6748}
6749
6750
6751static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
6752 char *cmd)
6753{
Dmitry Shmidt04949592012-07-19 12:16:46 -07006754 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
6755 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006756 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
6757 return 0;
6758}
6759
6760
6761static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
6762 char *cmd)
6763{
6764 char *pos;
6765 size_t len;
6766 struct wpabuf *query, *resp;
Sunil Ravi7f769292024-07-23 22:21:32 +00006767 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006768
6769 pos = os_strchr(cmd, ' ');
6770 if (pos == NULL)
6771 return -1;
6772 *pos++ = '\0';
6773
6774 len = os_strlen(cmd);
6775 if (len & 1)
6776 return -1;
6777 len /= 2;
6778 query = wpabuf_alloc(len);
6779 if (query == NULL)
6780 return -1;
Sunil Ravi7f769292024-07-23 22:21:32 +00006781 ret = hexstr2bin(cmd, wpabuf_put(query, len), len);
6782 if (ret < 0)
6783 goto err_query;
6784 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006785 len = os_strlen(pos);
Sunil Ravi7f769292024-07-23 22:21:32 +00006786 if (len & 1)
6787 goto err_query;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006788 len /= 2;
6789 resp = wpabuf_alloc(len);
Sunil Ravi7f769292024-07-23 22:21:32 +00006790 if (!resp)
6791 goto err_query;
6792 ret = hexstr2bin(pos, wpabuf_put(resp, len), len);
6793 if (ret < 0)
6794 goto err_resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006795
Sunil Ravi7f769292024-07-23 22:21:32 +00006796 ret = wpas_p2p_service_add_bonjour(wpa_s, query, resp);
6797
6798err_resp:
6799 wpabuf_free(resp);
6800err_query:
6801 wpabuf_free(query);
6802 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006803}
6804
6805
6806static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6807{
6808 char *pos;
6809 u8 version;
6810
6811 pos = os_strchr(cmd, ' ');
6812 if (pos == NULL)
6813 return -1;
6814 *pos++ = '\0';
6815
6816 if (hexstr2bin(cmd, &version, 1) < 0)
6817 return -1;
6818
6819 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
6820}
6821
6822
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006823static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
6824 u8 replace, char *cmd)
6825{
6826 char *pos;
6827 char *adv_str;
6828 u32 auto_accept, adv_id, svc_state, config_methods;
6829 char *svc_info = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006830 char *cpt_prio_str;
6831 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006832
6833 pos = os_strchr(cmd, ' ');
6834 if (pos == NULL)
6835 return -1;
6836 *pos++ = '\0';
6837
6838 /* Auto-Accept value is mandatory, and must be one of the
6839 * single values (0, 1, 2, 4) */
6840 auto_accept = atoi(cmd);
6841 switch (auto_accept) {
6842 case P2PS_SETUP_NONE: /* No auto-accept */
6843 case P2PS_SETUP_NEW:
6844 case P2PS_SETUP_CLIENT:
6845 case P2PS_SETUP_GROUP_OWNER:
6846 break;
6847 default:
6848 return -1;
6849 }
6850
6851 /* Advertisement ID is mandatory */
6852 cmd = pos;
6853 pos = os_strchr(cmd, ' ');
6854 if (pos == NULL)
6855 return -1;
6856 *pos++ = '\0';
6857
6858 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6859 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
6860 return -1;
6861
6862 /* Only allow replacements if exist, and adds if not */
6863 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
6864 if (!replace)
6865 return -1;
6866 } else {
6867 if (replace)
6868 return -1;
6869 }
6870
6871 /* svc_state between 0 - 0xff is mandatory */
6872 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
6873 return -1;
6874
6875 pos = os_strchr(pos, ' ');
6876 if (pos == NULL)
6877 return -1;
6878
6879 /* config_methods is mandatory */
6880 pos++;
6881 if (sscanf(pos, "%x", &config_methods) != 1)
6882 return -1;
6883
6884 if (!(config_methods &
6885 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
6886 return -1;
6887
6888 pos = os_strchr(pos, ' ');
6889 if (pos == NULL)
6890 return -1;
6891
6892 pos++;
6893 adv_str = pos;
6894
6895 /* Advertisement string is mandatory */
6896 if (!pos[0] || pos[0] == ' ')
6897 return -1;
6898
6899 /* Terminate svc string */
6900 pos = os_strchr(pos, ' ');
6901 if (pos != NULL)
6902 *pos++ = '\0';
6903
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006904 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6905 if (cpt_prio_str) {
6906 pos = os_strchr(pos, ' ');
6907 if (pos != NULL)
6908 *pos++ = '\0';
6909
6910 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6911 return -1;
6912 } else {
6913 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6914 cpt_prio[1] = 0;
6915 }
6916
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006917 /* Service and Response Information are optional */
6918 if (pos && pos[0]) {
6919 size_t len;
6920
6921 /* Note the bare ' included, which cannot exist legally
6922 * in unescaped string. */
6923 svc_info = os_strstr(pos, "svc_info='");
6924
6925 if (svc_info) {
6926 svc_info += 9;
6927 len = os_strlen(svc_info);
6928 utf8_unescape(svc_info, len, svc_info, len);
6929 }
6930 }
6931
6932 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6933 (u8) svc_state, (u16) config_methods,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006934 svc_info, cpt_prio);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006935}
6936
6937
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006938static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6939{
6940 char *pos;
6941
6942 pos = os_strchr(cmd, ' ');
6943 if (pos == NULL)
6944 return -1;
6945 *pos++ = '\0';
6946
6947 if (os_strcmp(cmd, "bonjour") == 0)
6948 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6949 if (os_strcmp(cmd, "upnp") == 0)
6950 return p2p_ctrl_service_add_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006951 if (os_strcmp(cmd, "asp") == 0)
6952 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006953 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6954 return -1;
6955}
6956
6957
6958static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6959 char *cmd)
6960{
6961 size_t len;
6962 struct wpabuf *query;
6963 int ret;
6964
6965 len = os_strlen(cmd);
6966 if (len & 1)
6967 return -1;
6968 len /= 2;
6969 query = wpabuf_alloc(len);
6970 if (query == NULL)
6971 return -1;
6972 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6973 wpabuf_free(query);
6974 return -1;
6975 }
6976
6977 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6978 wpabuf_free(query);
6979 return ret;
6980}
6981
6982
6983static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6984{
6985 char *pos;
6986 u8 version;
6987
6988 pos = os_strchr(cmd, ' ');
6989 if (pos == NULL)
6990 return -1;
6991 *pos++ = '\0';
6992
6993 if (hexstr2bin(cmd, &version, 1) < 0)
6994 return -1;
6995
6996 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6997}
6998
6999
Dmitry Shmidt216983b2015-02-06 10:50:36 -08007000static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
7001{
7002 u32 adv_id;
7003
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07007004 if (os_strcmp(cmd, "all") == 0) {
7005 wpas_p2p_service_flush_asp(wpa_s);
7006 return 0;
7007 }
7008
Dmitry Shmidt216983b2015-02-06 10:50:36 -08007009 if (sscanf(cmd, "%x", &adv_id) != 1)
7010 return -1;
7011
7012 return wpas_p2p_service_del_asp(wpa_s, adv_id);
7013}
7014
7015
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007016static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
7017{
7018 char *pos;
7019
7020 pos = os_strchr(cmd, ' ');
7021 if (pos == NULL)
7022 return -1;
7023 *pos++ = '\0';
7024
7025 if (os_strcmp(cmd, "bonjour") == 0)
7026 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
7027 if (os_strcmp(cmd, "upnp") == 0)
7028 return p2p_ctrl_service_del_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08007029 if (os_strcmp(cmd, "asp") == 0)
7030 return p2p_ctrl_service_del_asp(wpa_s, pos);
7031 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
7032 return -1;
7033}
7034
7035
7036static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
7037{
7038 char *pos;
7039
7040 pos = os_strchr(cmd, ' ');
7041 if (pos == NULL)
7042 return -1;
7043 *pos++ = '\0';
7044
7045 if (os_strcmp(cmd, "asp") == 0)
7046 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
7047
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007048 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
7049 return -1;
7050}
7051
7052
7053static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
7054{
7055 u8 addr[ETH_ALEN];
7056
7057 /* <addr> */
7058
7059 if (hwaddr_aton(cmd, addr))
7060 return -1;
7061
7062 return wpas_p2p_reject(wpa_s, addr);
7063}
7064
7065
7066static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
7067{
7068 char *pos;
7069 int id;
7070 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007071 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08007072 int freq = 0, pref_freq = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08007073 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007074 int edmg;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007075 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007076
7077 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007078 pos = os_strstr(cmd, " peer=");
7079 if (pos) {
7080 pos += 6;
7081 if (hwaddr_aton(pos, peer))
7082 return -1;
7083 _peer = peer;
7084 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007085 ssid = wpa_config_get_network(wpa_s->conf, id);
7086 if (ssid == NULL || ssid->disabled != 2) {
7087 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
7088 "for persistent P2P group",
7089 id);
7090 return -1;
7091 }
7092
Jouni Malinen31be0a42012-08-31 21:20:51 +03007093 pos = os_strstr(cmd, " freq=");
7094 if (pos) {
7095 pos += 6;
7096 freq = atoi(pos);
7097 if (freq <= 0)
7098 return -1;
7099 }
7100
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08007101 pos = os_strstr(cmd, " pref=");
7102 if (pos) {
7103 pos += 6;
7104 pref_freq = atoi(pos);
7105 if (pref_freq <= 0)
7106 return -1;
7107 }
7108
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007109 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
7110 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
7111 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08007112 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007113 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Jouni Malinen31be0a42012-08-31 21:20:51 +03007114
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007115 pos = os_strstr(cmd, "freq2=");
7116 if (pos)
7117 freq2 = atoi(pos + 6);
7118
7119 pos = os_strstr(cmd, " max_oper_chwidth=");
7120 if (pos)
7121 chwidth = atoi(pos + 18);
7122
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007123 max_oper_chwidth = chwidth_freq2_to_ch_width(chwidth, freq2);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007124 if (max_oper_chwidth < 0)
7125 return -1;
7126
Hai Shaloma20dcd72022-02-04 13:43:00 -08007127 allow_6ghz = os_strstr(cmd, " allow_6ghz") != NULL;
7128
7129 if (allow_6ghz && chwidth == 40)
Sunil8cd6f4d2022-06-28 18:40:46 +00007130 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007131
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007132 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
Hai Shaloma20dcd72022-02-04 13:43:00 -08007133 max_oper_chwidth, pref_freq, he, edmg,
7134 allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007135}
7136
7137
7138static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
7139{
7140 char *pos;
7141 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007142 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007143
7144 pos = os_strstr(cmd, " peer=");
7145 if (!pos)
7146 return -1;
7147
7148 *pos = '\0';
7149 pos += 6;
7150 if (hwaddr_aton(pos, peer)) {
7151 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
7152 return -1;
7153 }
7154
Hai Shaloma20dcd72022-02-04 13:43:00 -08007155 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
7156
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007157 pos = os_strstr(pos, " go_dev_addr=");
7158 if (pos) {
7159 pos += 13;
7160 if (hwaddr_aton(pos, go_dev_addr)) {
7161 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
7162 pos);
7163 return -1;
7164 }
7165 go_dev = go_dev_addr;
7166 }
7167
Hai Shaloma20dcd72022-02-04 13:43:00 -08007168 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007169}
7170
7171
7172static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
7173{
7174 if (os_strncmp(cmd, "persistent=", 11) == 0)
7175 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
7176 if (os_strncmp(cmd, "group=", 6) == 0)
7177 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
7178
7179 return -1;
7180}
7181
7182
7183static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007184 int id, int freq, int vht_center_freq2,
Hai Shalom74f70d42019-02-11 14:42:39 -08007185 int ht40, int vht, int vht_chwidth,
Sunil Raviaf8751c2023-03-29 11:35:17 -07007186 int he, int edmg, bool allow_6ghz,
7187 const u8 *go_bssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007188{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007189 struct wpa_ssid *ssid;
7190
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007191 ssid = wpa_config_get_network(wpa_s->conf, id);
7192 if (ssid == NULL || ssid->disabled != 2) {
7193 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
7194 "for persistent P2P group",
7195 id);
7196 return -1;
7197 }
7198
Sunil Ravic0f5d412024-09-11 22:12:49 +00007199 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, freq,
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007200 vht_center_freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007201 vht_chwidth, he, edmg,
Sunil Raviaf8751c2023-03-29 11:35:17 -07007202 NULL, 0, 0, allow_6ghz, 0,
7203 go_bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007204}
7205
7206
7207static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
7208{
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007209 int freq = 0, persistent = 0, group_id = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007210 bool allow_6ghz = false;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007211 int vht = wpa_s->conf->p2p_go_vht;
7212 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08007213 int he = wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007214 int edmg = wpa_s->conf->p2p_go_edmg;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007215 int max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007216 char *token, *context = NULL;
Sunil Raviaf8751c2023-03-29 11:35:17 -07007217 u8 go_bssid_buf[ETH_ALEN], *go_bssid = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007218#ifdef CONFIG_ACS
7219 int acs = 0;
7220#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007221
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007222 while ((token = str_token(cmd, " ", &context))) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07007223 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007224 sscanf(token, "persistent=%d", &group_id) == 1 ||
7225 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007226 continue;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007227#ifdef CONFIG_ACS
7228 } else if (os_strcmp(token, "freq=acs") == 0) {
7229 acs = 1;
7230#endif /* CONFIG_ACS */
7231 } else if (sscanf(token, "freq=%d", &freq) == 1) {
7232 continue;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007233 } else if (os_strcmp(token, "ht40") == 0) {
7234 ht40 = 1;
7235 } else if (os_strcmp(token, "vht") == 0) {
7236 vht = 1;
7237 ht40 = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08007238 } else if (os_strcmp(token, "he") == 0) {
7239 he = 1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007240 } else if (os_strcmp(token, "edmg") == 0) {
7241 edmg = 1;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007242 } else if (os_strcmp(token, "persistent") == 0) {
7243 persistent = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007244 } else if (os_strcmp(token, "allow_6ghz") == 0) {
7245 allow_6ghz = true;
Sunil Raviaf8751c2023-03-29 11:35:17 -07007246 } else if (os_strncmp(token, "go_bssid=", 9) == 0) {
7247 if (hwaddr_aton(token + 9, go_bssid_buf))
7248 return -1;
7249 go_bssid = go_bssid_buf;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007250 } else {
7251 wpa_printf(MSG_DEBUG,
7252 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
7253 token);
7254 return -1;
7255 }
7256 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007257
Roshan Pius3a1667e2018-07-03 15:17:14 -07007258#ifdef CONFIG_ACS
7259 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
7260 (acs || freq == 2 || freq == 5)) {
7261 if (freq == 2 && wpa_s->best_24_freq <= 0) {
7262 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
7263 wpa_s->p2p_go_do_acs = 1;
7264 freq = 0;
7265 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
7266 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
7267 wpa_s->p2p_go_do_acs = 1;
7268 freq = 0;
7269 } else {
7270 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
7271 wpa_s->p2p_go_do_acs = 1;
7272 }
Hai Shalom021b0b52019-04-10 11:17:58 -07007273 } else {
7274 wpa_s->p2p_go_do_acs = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007275 }
7276#endif /* CONFIG_ACS */
7277
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007278 max_oper_chwidth = chwidth_freq2_to_ch_width(chwidth, freq2);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007279 if (max_oper_chwidth < 0)
7280 return -1;
7281
Hai Shaloma20dcd72022-02-04 13:43:00 -08007282 if (allow_6ghz && chwidth == 40)
Sunil8cd6f4d2022-06-28 18:40:46 +00007283 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007284
7285 /* Allow DFS to be used for Autonomous GO */
7286 wpa_s->p2p_go_allow_dfs = !!(wpa_s->drv_flags &
7287 WPA_DRIVER_FLAGS_DFS_OFFLOAD);
7288
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007289 if (group_id >= 0)
7290 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007291 freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007292 max_oper_chwidth, he,
Sunil Raviaf8751c2023-03-29 11:35:17 -07007293 edmg, allow_6ghz,
7294 go_bssid);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007295
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007296 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
Hai Shaloma20dcd72022-02-04 13:43:00 -08007297 max_oper_chwidth, he, edmg, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007298}
7299
7300
Dmitry Shmidt849734c2016-05-27 09:59:01 -07007301static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
7302 char *buf, size_t buflen)
7303{
7304 u8 dev_addr[ETH_ALEN];
7305 struct wpa_ssid *ssid;
7306 int res;
7307 const u8 *iaddr;
7308
7309 ssid = wpa_s->current_ssid;
7310 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
7311 hwaddr_aton(cmd, dev_addr))
7312 return -1;
7313
7314 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
7315 if (!iaddr)
7316 return -1;
7317 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
7318 if (os_snprintf_error(buflen, res))
7319 return -1;
7320 return res;
7321}
7322
7323
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007324static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
7325 const u8 *p2p_dev_addr)
7326{
7327 struct wpa_supplicant *wpa_s;
7328
7329 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7330 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
7331 return 1;
7332 }
7333
7334 return 0;
7335}
7336
7337
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007338static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
7339 char *buf, size_t buflen)
7340{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007341 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007342 int next, res;
7343 const struct p2p_peer_info *info;
7344 char *pos, *end;
7345 char devtype[WPS_DEV_TYPE_BUFSIZE];
7346 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007347 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007348
7349 if (!wpa_s->global->p2p)
7350 return -1;
7351
7352 if (os_strcmp(cmd, "FIRST") == 0) {
7353 addr_ptr = NULL;
7354 next = 0;
7355 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
7356 if (hwaddr_aton(cmd + 5, addr) < 0)
7357 return -1;
7358 addr_ptr = addr;
7359 next = 1;
7360 } else {
7361 if (hwaddr_aton(cmd, addr) < 0)
7362 return -1;
7363 addr_ptr = addr;
7364 next = 0;
7365 }
7366
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007367 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
7368 if (info == NULL)
7369 return -1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007370 group_capab = info->group_capab;
7371
7372 if (group_capab &&
7373 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
7374 wpa_printf(MSG_DEBUG,
7375 "P2P: Could not find any BSS with p2p_dev_addr "
7376 MACSTR ", hence override group_capab from 0x%x to 0",
7377 MAC2STR(info->p2p_device_addr), group_capab);
7378 group_capab = 0;
7379 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007380
7381 pos = buf;
7382 end = buf + buflen;
7383
7384 res = os_snprintf(pos, end - pos, MACSTR "\n"
7385 "pri_dev_type=%s\n"
7386 "device_name=%s\n"
7387 "manufacturer=%s\n"
7388 "model_name=%s\n"
7389 "model_number=%s\n"
7390 "serial_number=%s\n"
7391 "config_methods=0x%x\n"
7392 "dev_capab=0x%x\n"
7393 "group_capab=0x%x\n"
7394 "level=%d\n",
7395 MAC2STR(info->p2p_device_addr),
7396 wps_dev_type_bin2str(info->pri_dev_type,
7397 devtype, sizeof(devtype)),
7398 info->device_name,
7399 info->manufacturer,
7400 info->model_name,
7401 info->model_number,
7402 info->serial_number,
7403 info->config_methods,
7404 info->dev_capab,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007405 group_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007406 info->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007407 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007408 return pos - buf;
7409 pos += res;
7410
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007411 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
7412 {
7413 const u8 *t;
7414 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
7415 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
7416 wps_dev_type_bin2str(t, devtype,
7417 sizeof(devtype)));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007418 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007419 return pos - buf;
7420 pos += res;
7421 }
7422
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007423 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007424 if (ssid) {
7425 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007426 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007427 return pos - buf;
7428 pos += res;
7429 }
7430
7431 res = p2p_get_peer_info_txt(info, pos, end - pos);
7432 if (res < 0)
7433 return pos - buf;
7434 pos += res;
7435
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007436 if (info->vendor_elems) {
7437 res = os_snprintf(pos, end - pos, "vendor_elems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007438 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007439 return pos - buf;
7440 pos += res;
7441
7442 pos += wpa_snprintf_hex(pos, end - pos,
7443 wpabuf_head(info->vendor_elems),
7444 wpabuf_len(info->vendor_elems));
7445
7446 res = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007447 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007448 return pos - buf;
7449 pos += res;
7450 }
7451
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007452 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007453}
7454
7455
Dmitry Shmidt04949592012-07-19 12:16:46 -07007456static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
7457 const char *param)
7458{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007459 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007460
7461 if (wpa_s->global->p2p == NULL)
7462 return -1;
7463
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007464 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
7465 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007466
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007467 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
7468 struct wpa_freq_range *freq;
7469 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07007470 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007471 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007472 }
7473
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007474 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007475 return 0;
7476}
7477
7478
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007479static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
7480{
7481 char *param;
7482
7483 if (wpa_s->global->p2p == NULL)
7484 return -1;
7485
7486 param = os_strchr(cmd, ' ');
7487 if (param == NULL)
7488 return -1;
7489 *param++ = '\0';
7490
7491 if (os_strcmp(cmd, "discoverability") == 0) {
7492 p2p_set_client_discoverability(wpa_s->global->p2p,
7493 atoi(param));
7494 return 0;
7495 }
7496
7497 if (os_strcmp(cmd, "managed") == 0) {
7498 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
7499 return 0;
7500 }
7501
7502 if (os_strcmp(cmd, "listen_channel") == 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08007503 char *pos;
7504 u8 channel, op_class;
7505
7506 channel = atoi(param);
7507 pos = os_strchr(param, ' ');
7508 op_class = pos ? atoi(pos) : 81;
7509
7510 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
7511 channel, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007512 }
7513
7514 if (os_strcmp(cmd, "ssid_postfix") == 0) {
7515 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
7516 os_strlen(param));
7517 }
7518
7519 if (os_strcmp(cmd, "noa") == 0) {
7520 char *pos;
7521 int count, start, duration;
7522 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
7523 count = atoi(param);
7524 pos = os_strchr(param, ',');
7525 if (pos == NULL)
7526 return -1;
7527 pos++;
7528 start = atoi(pos);
7529 pos = os_strchr(pos, ',');
7530 if (pos == NULL)
7531 return -1;
7532 pos++;
7533 duration = atoi(pos);
7534 if (count < 0 || count > 255 || start < 0 || duration < 0)
7535 return -1;
7536 if (count == 0 && duration > 0)
7537 return -1;
7538 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
7539 "start=%d duration=%d", count, start, duration);
7540 return wpas_p2p_set_noa(wpa_s, count, start, duration);
7541 }
7542
7543 if (os_strcmp(cmd, "ps") == 0)
7544 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
7545
7546 if (os_strcmp(cmd, "oppps") == 0)
7547 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
7548
7549 if (os_strcmp(cmd, "ctwindow") == 0)
7550 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
7551
7552 if (os_strcmp(cmd, "disabled") == 0) {
7553 wpa_s->global->p2p_disabled = atoi(param);
7554 wpa_printf(MSG_DEBUG, "P2P functionality %s",
7555 wpa_s->global->p2p_disabled ?
7556 "disabled" : "enabled");
7557 if (wpa_s->global->p2p_disabled) {
7558 wpas_p2p_stop_find(wpa_s);
7559 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7560 p2p_flush(wpa_s->global->p2p);
7561 }
7562 return 0;
7563 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007564
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007565 if (os_strcmp(cmd, "conc_pref") == 0) {
7566 if (os_strcmp(param, "sta") == 0)
7567 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
7568 else if (os_strcmp(param, "p2p") == 0)
7569 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007570 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007571 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007572 return -1;
7573 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007574 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07007575 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007576 return 0;
7577 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007578
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007579 if (os_strcmp(cmd, "force_long_sd") == 0) {
7580 wpa_s->force_long_sd = atoi(param);
7581 return 0;
7582 }
7583
7584 if (os_strcmp(cmd, "peer_filter") == 0) {
7585 u8 addr[ETH_ALEN];
7586 if (hwaddr_aton(param, addr))
7587 return -1;
7588 p2p_set_peer_filter(wpa_s->global->p2p, addr);
7589 return 0;
7590 }
7591
7592 if (os_strcmp(cmd, "cross_connect") == 0)
7593 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
7594
7595 if (os_strcmp(cmd, "go_apsd") == 0) {
7596 if (os_strcmp(param, "disable") == 0)
7597 wpa_s->set_ap_uapsd = 0;
7598 else {
7599 wpa_s->set_ap_uapsd = 1;
7600 wpa_s->ap_uapsd = atoi(param);
7601 }
7602 return 0;
7603 }
7604
7605 if (os_strcmp(cmd, "client_apsd") == 0) {
7606 if (os_strcmp(param, "disable") == 0)
7607 wpa_s->set_sta_uapsd = 0;
7608 else {
7609 int be, bk, vi, vo;
7610 char *pos;
7611 /* format: BE,BK,VI,VO;max SP Length */
7612 be = atoi(param);
7613 pos = os_strchr(param, ',');
7614 if (pos == NULL)
7615 return -1;
7616 pos++;
7617 bk = atoi(pos);
7618 pos = os_strchr(pos, ',');
7619 if (pos == NULL)
7620 return -1;
7621 pos++;
7622 vi = atoi(pos);
7623 pos = os_strchr(pos, ',');
7624 if (pos == NULL)
7625 return -1;
7626 pos++;
7627 vo = atoi(pos);
7628 /* ignore max SP Length for now */
7629
7630 wpa_s->set_sta_uapsd = 1;
7631 wpa_s->sta_uapsd = 0;
7632 if (be)
7633 wpa_s->sta_uapsd |= BIT(0);
7634 if (bk)
7635 wpa_s->sta_uapsd |= BIT(1);
7636 if (vi)
7637 wpa_s->sta_uapsd |= BIT(2);
7638 if (vo)
7639 wpa_s->sta_uapsd |= BIT(3);
7640 }
7641 return 0;
7642 }
7643
Dmitry Shmidt04949592012-07-19 12:16:46 -07007644 if (os_strcmp(cmd, "disallow_freq") == 0)
7645 return p2p_ctrl_disallow_freq(wpa_s, param);
7646
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007647 if (os_strcmp(cmd, "disc_int") == 0) {
7648 int min_disc_int, max_disc_int, max_disc_tu;
7649 char *pos;
7650
7651 pos = param;
7652
7653 min_disc_int = atoi(pos);
7654 pos = os_strchr(pos, ' ');
7655 if (pos == NULL)
7656 return -1;
7657 *pos++ = '\0';
7658
7659 max_disc_int = atoi(pos);
7660 pos = os_strchr(pos, ' ');
7661 if (pos == NULL)
7662 return -1;
7663 *pos++ = '\0';
7664
7665 max_disc_tu = atoi(pos);
7666
7667 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
7668 max_disc_int, max_disc_tu);
7669 }
7670
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007671 if (os_strcmp(cmd, "per_sta_psk") == 0) {
7672 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
7673 return 0;
7674 }
7675
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007676#ifdef CONFIG_WPS_NFC
7677 if (os_strcmp(cmd, "nfc_tag") == 0)
7678 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
7679#endif /* CONFIG_WPS_NFC */
7680
7681 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
7682 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
7683 return 0;
7684 }
7685
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007686 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
7687 int op_class, chan;
7688
7689 op_class = atoi(param);
7690 param = os_strchr(param, ':');
7691 if (!param)
7692 return -1;
7693 param++;
7694 chan = atoi(param);
7695 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
7696 chan);
7697 return 0;
7698 }
7699
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007700 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
7701 cmd);
7702
7703 return -1;
7704}
7705
7706
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007707static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
7708{
7709 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7710 wpa_s->force_long_sd = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007711
7712#ifdef CONFIG_TESTING_OPTIONS
7713 os_free(wpa_s->get_pref_freq_list_override);
7714 wpa_s->get_pref_freq_list_override = NULL;
7715#endif /* CONFIG_TESTING_OPTIONS */
7716
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007717 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007718 wpa_s->parent->p2ps_method_config_any = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007719 if (wpa_s->global->p2p)
7720 p2p_flush(wpa_s->global->p2p);
7721}
7722
7723
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007724static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
7725{
7726 char *pos, *pos2;
7727 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
7728
7729 if (cmd[0]) {
7730 pos = os_strchr(cmd, ' ');
7731 if (pos == NULL)
7732 return -1;
7733 *pos++ = '\0';
7734 dur1 = atoi(cmd);
7735
7736 pos2 = os_strchr(pos, ' ');
7737 if (pos2)
7738 *pos2++ = '\0';
7739 int1 = atoi(pos);
7740 } else
7741 pos2 = NULL;
7742
7743 if (pos2) {
7744 pos = os_strchr(pos2, ' ');
7745 if (pos == NULL)
7746 return -1;
7747 *pos++ = '\0';
7748 dur2 = atoi(pos2);
7749 int2 = atoi(pos);
7750 }
7751
7752 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
7753}
7754
7755
7756static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
7757{
7758 char *pos;
7759 unsigned int period = 0, interval = 0;
7760
7761 if (cmd[0]) {
7762 pos = os_strchr(cmd, ' ');
7763 if (pos == NULL)
7764 return -1;
7765 *pos++ = '\0';
7766 period = atoi(cmd);
7767 interval = atoi(pos);
7768 }
7769
7770 return wpas_p2p_ext_listen(wpa_s, period, interval);
7771}
7772
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007773
7774static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
7775{
7776 const char *pos;
7777 u8 peer[ETH_ALEN];
7778 int iface_addr = 0;
7779
7780 pos = cmd;
7781 if (os_strncmp(pos, "iface=", 6) == 0) {
7782 iface_addr = 1;
7783 pos += 6;
7784 }
7785 if (hwaddr_aton(pos, peer))
7786 return -1;
7787
7788 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
7789 return 0;
7790}
7791
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007792
7793static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
7794{
7795 int freq = 0, period = 0, interval = 0, count = 0;
7796
7797 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
7798 {
7799 wpa_printf(MSG_DEBUG,
7800 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
7801 return -1;
7802 }
7803
7804 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
7805}
7806
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007807#endif /* CONFIG_P2P */
7808
7809
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007810static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
7811{
7812 struct wpa_freq_range_list ranges;
7813 int *freqs = NULL;
7814 struct hostapd_hw_modes *mode;
7815 u16 i;
7816
7817 if (wpa_s->hw.modes == NULL)
7818 return NULL;
7819
7820 os_memset(&ranges, 0, sizeof(ranges));
7821 if (freq_range_list_parse(&ranges, val) < 0)
7822 return NULL;
7823
7824 for (i = 0; i < wpa_s->hw.num_modes; i++) {
7825 int j;
7826
7827 mode = &wpa_s->hw.modes[i];
7828 for (j = 0; j < mode->num_channels; j++) {
7829 unsigned int freq;
7830
7831 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
7832 continue;
7833
7834 freq = mode->channels[j].freq;
7835 if (!freq_range_list_includes(&ranges, freq))
7836 continue;
7837
7838 int_array_add_unique(&freqs, freq);
7839 }
7840 }
7841
7842 os_free(ranges.range);
7843 return freqs;
7844}
7845
7846
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007847#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007848
7849static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
7850{
7851 int auto_sel = 0;
7852 int *freqs = NULL;
7853
7854 if (param) {
7855 char *pos;
7856
7857 auto_sel = os_strstr(param, "auto") != NULL;
7858
7859 pos = os_strstr(param, "freq=");
7860 if (pos) {
7861 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
7862 if (freqs == NULL)
7863 return -1;
7864 }
7865
7866 }
7867
7868 return interworking_select(wpa_s, auto_sel, freqs);
7869}
7870
7871
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007872static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
7873 int only_add)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007874{
7875 u8 bssid[ETH_ALEN];
7876 struct wpa_bss *bss;
7877
7878 if (hwaddr_aton(dst, bssid)) {
7879 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
7880 return -1;
7881 }
7882
Hai Shalomfdcde762020-04-02 11:19:20 -07007883 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007884 if (bss == NULL) {
7885 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
7886 MAC2STR(bssid));
7887 return -1;
7888 }
7889
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007890 if (bss->ssid_len == 0) {
7891 int found = 0;
7892
7893 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
7894 " does not have SSID information", MAC2STR(bssid));
7895
7896 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
7897 list) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00007898 if (ether_addr_equal(bss->bssid, bssid) &&
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007899 bss->ssid_len > 0) {
7900 found = 1;
7901 break;
7902 }
7903 }
7904
7905 if (!found)
7906 return -1;
7907 wpa_printf(MSG_DEBUG,
7908 "Found another matching BSS entry with SSID");
7909 }
7910
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007911 return interworking_connect(wpa_s, bss, only_add);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007912}
7913
7914
7915static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
7916{
7917 u8 dst_addr[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07007918 int used, freq = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007919 char *pos;
7920#define MAX_ANQP_INFO_ID 100
7921 u16 id[MAX_ANQP_INFO_ID];
7922 size_t num_id = 0;
Dmitry Shmidt15907092014-03-25 10:42:57 -07007923 u32 subtypes = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007924 u32 mbo_subtypes = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007925
7926 used = hwaddr_aton2(dst, dst_addr);
7927 if (used < 0)
7928 return -1;
7929 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007930 if (*pos == ' ')
7931 pos++;
Hai Shalom899fcc72020-10-19 14:38:18 -07007932
7933 if (os_strncmp(pos, "freq=", 5) == 0) {
7934 freq = atoi(pos + 5);
7935 pos = os_strchr(pos, ' ');
7936 if (!pos)
7937 return -1;
7938 pos++;
7939 }
7940
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007941 while (num_id < MAX_ANQP_INFO_ID) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07007942 if (os_strncmp(pos, "hs20:", 5) == 0) {
7943#ifdef CONFIG_HS20
7944 int num = atoi(pos + 5);
7945 if (num <= 0 || num > 31)
7946 return -1;
7947 subtypes |= BIT(num);
7948#else /* CONFIG_HS20 */
7949 return -1;
7950#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007951 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7952#ifdef CONFIG_MBO
7953 int num = atoi(pos + 4);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007954
7955 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007956 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007957 mbo_subtypes |= BIT(num);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007958#else /* CONFIG_MBO */
7959 return -1;
7960#endif /* CONFIG_MBO */
Dmitry Shmidt15907092014-03-25 10:42:57 -07007961 } else {
7962 id[num_id] = atoi(pos);
7963 if (id[num_id])
7964 num_id++;
7965 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007966 pos = os_strchr(pos + 1, ',');
7967 if (pos == NULL)
7968 break;
7969 pos++;
7970 }
7971
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007972 if (num_id == 0 && !subtypes && !mbo_subtypes)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007973 return -1;
7974
Hai Shalom899fcc72020-10-19 14:38:18 -07007975 return anqp_send_req(wpa_s, dst_addr, freq, id, num_id, subtypes,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007976 mbo_subtypes);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007977}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007978
7979
7980static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7981{
7982 u8 dst_addr[ETH_ALEN];
7983 struct wpabuf *advproto, *query = NULL;
7984 int used, ret = -1;
7985 char *pos, *end;
7986 size_t len;
7987
7988 used = hwaddr_aton2(cmd, dst_addr);
7989 if (used < 0)
7990 return -1;
7991
7992 pos = cmd + used;
7993 while (*pos == ' ')
7994 pos++;
7995
7996 /* Advertisement Protocol ID */
7997 end = os_strchr(pos, ' ');
7998 if (end)
7999 len = end - pos;
8000 else
8001 len = os_strlen(pos);
8002 if (len & 0x01)
8003 return -1;
8004 len /= 2;
8005 if (len == 0)
8006 return -1;
8007 advproto = wpabuf_alloc(len);
8008 if (advproto == NULL)
8009 return -1;
8010 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
8011 goto fail;
8012
8013 if (end) {
8014 /* Optional Query Request */
8015 pos = end + 1;
8016 while (*pos == ' ')
8017 pos++;
8018
8019 len = os_strlen(pos);
8020 if (len) {
8021 if (len & 0x01)
8022 goto fail;
8023 len /= 2;
8024 if (len == 0)
8025 goto fail;
8026 query = wpabuf_alloc(len);
8027 if (query == NULL)
8028 goto fail;
8029 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
8030 goto fail;
8031 }
8032 }
8033
8034 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
8035
8036fail:
8037 wpabuf_free(advproto);
8038 wpabuf_free(query);
8039
8040 return ret;
8041}
8042
8043
8044static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
8045 size_t buflen)
8046{
8047 u8 addr[ETH_ALEN];
8048 int dialog_token;
8049 int used;
8050 char *pos;
8051 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008052 struct wpabuf *resp;
8053 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008054
8055 used = hwaddr_aton2(cmd, addr);
8056 if (used < 0)
8057 return -1;
8058
8059 pos = cmd + used;
8060 while (*pos == ' ')
8061 pos++;
8062 dialog_token = atoi(pos);
8063
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008064 if (wpa_s->last_gas_resp &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008065 ether_addr_equal(addr, wpa_s->last_gas_addr) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008066 dialog_token == wpa_s->last_gas_dialog_token)
8067 resp = wpa_s->last_gas_resp;
8068 else if (wpa_s->prev_gas_resp &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008069 ether_addr_equal(addr, wpa_s->prev_gas_addr) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008070 dialog_token == wpa_s->prev_gas_dialog_token)
8071 resp = wpa_s->prev_gas_resp;
8072 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008073 return -1;
8074
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008075 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008076 start = 0;
8077 requested_len = resp_len;
8078
8079 pos = os_strchr(pos, ' ');
8080 if (pos) {
8081 start = atoi(pos);
8082 if (start > resp_len)
8083 return os_snprintf(buf, buflen, "FAIL-Invalid range");
8084 pos = os_strchr(pos, ',');
8085 if (pos == NULL)
8086 return -1;
8087 pos++;
8088 requested_len = atoi(pos);
8089 if (start + requested_len > resp_len)
8090 return os_snprintf(buf, buflen, "FAIL-Invalid range");
8091 }
8092
8093 if (requested_len * 2 + 1 > buflen)
8094 return os_snprintf(buf, buflen, "FAIL-Too long response");
8095
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008096 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
8097 requested_len);
8098
8099 if (start + requested_len == resp_len) {
8100 /*
8101 * Free memory by dropping the response after it has been
8102 * fetched.
8103 */
8104 if (resp == wpa_s->prev_gas_resp) {
8105 wpabuf_free(wpa_s->prev_gas_resp);
8106 wpa_s->prev_gas_resp = NULL;
8107 } else {
8108 wpabuf_free(wpa_s->last_gas_resp);
8109 wpa_s->last_gas_resp = NULL;
8110 }
8111 }
8112
8113 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008114}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008115#endif /* CONFIG_INTERWORKING */
8116
8117
Dmitry Shmidt04949592012-07-19 12:16:46 -07008118#ifdef CONFIG_HS20
8119
8120static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
8121{
8122 u8 dst_addr[ETH_ALEN];
8123 int used;
8124 char *pos;
8125 u32 subtypes = 0;
8126
8127 used = hwaddr_aton2(dst, dst_addr);
8128 if (used < 0)
8129 return -1;
8130 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008131 if (*pos == ' ')
8132 pos++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07008133 for (;;) {
8134 int num = atoi(pos);
8135 if (num <= 0 || num > 31)
8136 return -1;
8137 subtypes |= BIT(num);
8138 pos = os_strchr(pos + 1, ',');
8139 if (pos == NULL)
8140 break;
8141 pos++;
8142 }
8143
8144 if (subtypes == 0)
8145 return -1;
8146
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008147 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008148}
8149
8150
8151static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
8152 const u8 *addr, const char *realm)
8153{
8154 u8 *buf;
8155 size_t rlen, len;
8156 int ret;
8157
8158 rlen = os_strlen(realm);
8159 len = 3 + rlen;
8160 buf = os_malloc(len);
8161 if (buf == NULL)
8162 return -1;
8163 buf[0] = 1; /* NAI Home Realm Count */
8164 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
8165 buf[2] = rlen;
8166 os_memcpy(buf + 3, realm, rlen);
8167
8168 ret = hs20_anqp_send_req(wpa_s, addr,
8169 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008170 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008171
8172 os_free(buf);
8173
8174 return ret;
8175}
8176
8177
8178static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
8179 char *dst)
8180{
8181 struct wpa_cred *cred = wpa_s->conf->cred;
8182 u8 dst_addr[ETH_ALEN];
8183 int used;
8184 u8 *buf;
8185 size_t len;
8186 int ret;
8187
8188 used = hwaddr_aton2(dst, dst_addr);
8189 if (used < 0)
8190 return -1;
8191
8192 while (dst[used] == ' ')
8193 used++;
8194 if (os_strncmp(dst + used, "realm=", 6) == 0)
8195 return hs20_nai_home_realm_list(wpa_s, dst_addr,
8196 dst + used + 6);
8197
8198 len = os_strlen(dst + used);
8199
8200 if (len == 0 && cred && cred->realm)
8201 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
8202
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07008203 if (len & 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07008204 return -1;
8205 len /= 2;
8206 buf = os_malloc(len);
8207 if (buf == NULL)
8208 return -1;
8209 if (hexstr2bin(dst + used, buf, len) < 0) {
8210 os_free(buf);
8211 return -1;
8212 }
8213
8214 ret = hs20_anqp_send_req(wpa_s, dst_addr,
8215 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008216 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008217 os_free(buf);
8218
8219 return ret;
8220}
8221
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008222
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008223static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
8224 int buflen)
8225{
8226 u8 dst_addr[ETH_ALEN];
8227 int used;
8228 char *ctx = NULL, *icon, *poffset, *psize;
8229
8230 used = hwaddr_aton2(cmd, dst_addr);
8231 if (used < 0)
8232 return -1;
8233 cmd += used;
8234
8235 icon = str_token(cmd, " ", &ctx);
8236 poffset = str_token(cmd, " ", &ctx);
8237 psize = str_token(cmd, " ", &ctx);
8238 if (!icon || !poffset || !psize)
8239 return -1;
8240
8241 wpa_s->fetch_osu_icon_in_progress = 0;
8242 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
8243 reply, buflen);
8244}
8245
8246
8247static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
8248{
8249 u8 dst_addr[ETH_ALEN];
8250 int used;
8251 char *icon;
8252
8253 if (!cmd[0])
8254 return hs20_del_icon(wpa_s, NULL, NULL);
8255
8256 used = hwaddr_aton2(cmd, dst_addr);
8257 if (used < 0)
8258 return -1;
8259
8260 while (cmd[used] == ' ')
8261 used++;
8262 icon = cmd[used] ? &cmd[used] : NULL;
8263
8264 return hs20_del_icon(wpa_s, dst_addr, icon);
8265}
8266
8267
8268static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008269{
8270 u8 dst_addr[ETH_ALEN];
8271 int used;
8272 char *icon;
8273
8274 used = hwaddr_aton2(cmd, dst_addr);
8275 if (used < 0)
8276 return -1;
8277
8278 while (cmd[used] == ' ')
8279 used++;
8280 icon = &cmd[used];
8281
8282 wpa_s->fetch_osu_icon_in_progress = 0;
8283 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008284 (u8 *) icon, os_strlen(icon), inmem);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008285}
8286
Dmitry Shmidt04949592012-07-19 12:16:46 -07008287#endif /* CONFIG_HS20 */
8288
8289
Dmitry Shmidt04949592012-07-19 12:16:46 -07008290#ifdef CONFIG_AUTOSCAN
8291
8292static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
8293 char *cmd)
8294{
8295 enum wpa_states state = wpa_s->wpa_state;
8296 char *new_params = NULL;
8297
8298 if (os_strlen(cmd) > 0) {
8299 new_params = os_strdup(cmd);
8300 if (new_params == NULL)
8301 return -1;
8302 }
8303
8304 os_free(wpa_s->conf->autoscan);
8305 wpa_s->conf->autoscan = new_params;
8306
8307 if (wpa_s->conf->autoscan == NULL)
8308 autoscan_deinit(wpa_s);
8309 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
8310 autoscan_init(wpa_s, 1);
8311 else if (state == WPA_SCANNING)
8312 wpa_supplicant_reinit_autoscan(wpa_s);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08008313 else
8314 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
8315 wpa_supplicant_state_txt(state));
Dmitry Shmidt04949592012-07-19 12:16:46 -07008316
8317 return 0;
8318}
8319
8320#endif /* CONFIG_AUTOSCAN */
8321
8322
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08008323#ifdef CONFIG_WNM
8324
8325static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
8326{
8327 int enter;
8328 int intval = 0;
8329 char *pos;
8330 int ret;
8331 struct wpabuf *tfs_req = NULL;
8332
8333 if (os_strncmp(cmd, "enter", 5) == 0)
8334 enter = 1;
8335 else if (os_strncmp(cmd, "exit", 4) == 0)
8336 enter = 0;
8337 else
8338 return -1;
8339
8340 pos = os_strstr(cmd, " interval=");
8341 if (pos)
8342 intval = atoi(pos + 10);
8343
8344 pos = os_strstr(cmd, " tfs_req=");
8345 if (pos) {
8346 char *end;
8347 size_t len;
8348 pos += 9;
8349 end = os_strchr(pos, ' ');
8350 if (end)
8351 len = end - pos;
8352 else
8353 len = os_strlen(pos);
8354 if (len & 1)
8355 return -1;
8356 len /= 2;
8357 tfs_req = wpabuf_alloc(len);
8358 if (tfs_req == NULL)
8359 return -1;
8360 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
8361 wpabuf_free(tfs_req);
8362 return -1;
8363 }
8364 }
8365
8366 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
8367 WNM_SLEEP_MODE_EXIT, intval,
8368 tfs_req);
8369 wpabuf_free(tfs_req);
8370
8371 return ret;
8372}
8373
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008374
8375static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
8376{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008377 int query_reason, list = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008378 char *btm_candidates = NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008379
8380 query_reason = atoi(cmd);
8381
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008382 cmd = os_strchr(cmd, ' ');
8383 if (cmd) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008384 if (os_strncmp(cmd, " list", 5) == 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008385 list = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008386 else
8387 btm_candidates = cmd;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008388 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008389
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008390 wpa_printf(MSG_DEBUG,
8391 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
8392 query_reason, list ? " candidate list" : "");
8393
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008394 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
8395 btm_candidates,
8396 list);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008397}
8398
Hai Shalom39ba6fc2019-01-22 12:40:38 -08008399
8400static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
8401 char *cmd)
8402{
8403 struct wpabuf *elems;
8404 int ret;
8405
8406 elems = wpabuf_parse_bin(cmd);
8407 if (!elems)
8408 return -1;
8409
8410 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
8411 wpabuf_free(elems);
8412 return ret;
8413}
8414
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08008415#endif /* CONFIG_WNM */
8416
8417
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008418static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
8419 size_t buflen)
8420{
8421 struct wpa_signal_info si;
8422 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008423 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008424
8425 ret = wpa_drv_signal_poll(wpa_s, &si);
8426 if (ret)
8427 return -1;
8428
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008429 pos = buf;
8430 end = buf + buflen;
8431
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008432 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%lu\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008433 "NOISE=%d\nFREQUENCY=%u\n",
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008434 si.data.signal, si.data.current_tx_rate / 1000,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008435 si.current_noise, si.frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008436 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008437 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008438 pos += ret;
8439
8440 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
8441 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008442 channel_width_to_string(si.chanwidth));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008443 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008444 return -1;
8445 pos += ret;
8446 }
8447
Roshan Pius3a1667e2018-07-03 15:17:14 -07008448 if (si.center_frq1 > 0) {
8449 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
8450 si.center_frq1);
8451 if (os_snprintf_error(end - pos, ret))
8452 return -1;
8453 pos += ret;
8454 }
8455
8456 if (si.center_frq2 > 0) {
8457 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
8458 si.center_frq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008459 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008460 return -1;
8461 pos += ret;
8462 }
8463
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008464 if (si.data.avg_signal) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008465 ret = os_snprintf(pos, end - pos,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008466 "AVG_RSSI=%d\n", si.data.avg_signal);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008467 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008468 return -1;
8469 pos += ret;
8470 }
8471
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008472 if (si.data.avg_beacon_signal) {
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07008473 ret = os_snprintf(pos, end - pos,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008474 "AVG_BEACON_RSSI=%d\n",
8475 si.data.avg_beacon_signal);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07008476 if (os_snprintf_error(end - pos, ret))
8477 return -1;
8478 pos += ret;
8479 }
8480
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008481 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008482}
8483
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008484
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008485static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
8486 const char *cmd)
8487{
8488 const char *pos;
8489 int threshold = 0;
8490 int hysteresis = 0;
8491
8492 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
8493 wpa_printf(MSG_DEBUG,
8494 "Reject SIGNAL_MONITOR command - bgscan is active");
8495 return -1;
8496 }
8497 pos = os_strstr(cmd, "THRESHOLD=");
8498 if (pos)
8499 threshold = atoi(pos + 10);
8500 pos = os_strstr(cmd, "HYSTERESIS=");
8501 if (pos)
8502 hysteresis = atoi(pos + 11);
8503 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
8504}
8505
8506
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008507#ifdef CONFIG_TESTING_OPTIONS
8508int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
8509 enum wpa_driver_if_type if_type,
8510 unsigned int *num,
Sunil8cd6f4d2022-06-28 18:40:46 +00008511 struct weighted_pcl *freq_list)
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008512{
8513 char *pos = wpa_s->get_pref_freq_list_override;
8514 char *end;
8515 unsigned int count = 0;
8516
8517 /* Override string format:
8518 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
8519
8520 while (pos) {
8521 if (atoi(pos) == (int) if_type)
8522 break;
8523 pos = os_strchr(pos, ' ');
8524 if (pos)
8525 pos++;
8526 }
8527 if (!pos)
8528 return -1;
8529 pos = os_strchr(pos, ':');
8530 if (!pos)
8531 return -1;
8532 pos++;
8533 end = os_strchr(pos, ' ');
8534 while (pos && (!end || pos < end) && count < *num) {
Sunil8cd6f4d2022-06-28 18:40:46 +00008535 freq_list[count].freq = atoi(pos);
8536 freq_list[count++].flag = WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008537 pos = os_strchr(pos, ',');
8538 if (pos)
8539 pos++;
8540 }
8541
8542 *num = count;
8543 return 0;
8544}
8545#endif /* CONFIG_TESTING_OPTIONS */
8546
8547
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008548static int wpas_ctrl_iface_get_pref_freq_list(
8549 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
8550{
Sunil8cd6f4d2022-06-28 18:40:46 +00008551 unsigned int num = 100, i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008552 int ret;
8553 enum wpa_driver_if_type iface_type;
8554 char *pos, *end;
Sunil8cd6f4d2022-06-28 18:40:46 +00008555 struct weighted_pcl freq_list[100];
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008556
8557 pos = buf;
8558 end = buf + buflen;
8559
8560 /* buf: "<interface_type>" */
8561 if (os_strcmp(cmd, "STATION") == 0)
8562 iface_type = WPA_IF_STATION;
8563 else if (os_strcmp(cmd, "AP") == 0)
8564 iface_type = WPA_IF_AP_BSS;
8565 else if (os_strcmp(cmd, "P2P_GO") == 0)
8566 iface_type = WPA_IF_P2P_GO;
8567 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
8568 iface_type = WPA_IF_P2P_CLIENT;
8569 else if (os_strcmp(cmd, "IBSS") == 0)
8570 iface_type = WPA_IF_IBSS;
8571 else if (os_strcmp(cmd, "TDLS") == 0)
8572 iface_type = WPA_IF_TDLS;
8573 else
8574 return -1;
8575
8576 wpa_printf(MSG_DEBUG,
8577 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
Hai Shalom5f92bc92019-04-18 11:54:11 -07008578 iface_type, cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008579
8580 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
8581 if (ret)
8582 return -1;
8583
8584 for (i = 0; i < num; i++) {
8585 ret = os_snprintf(pos, end - pos, "%s%u",
Sunil8cd6f4d2022-06-28 18:40:46 +00008586 i > 0 ? "," : "", freq_list[i].freq);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008587 if (os_snprintf_error(end - pos, ret))
8588 return -1;
8589 pos += ret;
8590 }
8591
8592 return pos - buf;
8593}
8594
8595
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008596static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
8597 char *buf, size_t buflen)
8598{
8599 int ret, i;
8600 char *pos, *end;
8601
8602 ret = os_snprintf(buf, buflen, "%016llX:\n",
8603 (long long unsigned) wpa_s->drv_flags);
8604 if (os_snprintf_error(buflen, ret))
8605 return -1;
8606
8607 pos = buf + ret;
8608 end = buf + buflen;
8609
8610 for (i = 0; i < 64; i++) {
8611 if (wpa_s->drv_flags & (1LLU << i)) {
8612 ret = os_snprintf(pos, end - pos, "%s\n",
8613 driver_flag_to_string(1LLU << i));
8614 if (os_snprintf_error(end - pos, ret))
8615 return -1;
8616 pos += ret;
8617 }
8618 }
8619
8620 return pos - buf;
8621}
8622
8623
Hai Shalomb755a2a2020-04-23 21:49:02 -07008624static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s,
8625 char *buf, size_t buflen)
8626{
8627 int ret, i;
8628 char *pos, *end;
8629
8630 ret = os_snprintf(buf, buflen, "%016llX:\n",
8631 (long long unsigned) wpa_s->drv_flags2);
8632 if (os_snprintf_error(buflen, ret))
8633 return -1;
8634
8635 pos = buf + ret;
8636 end = buf + buflen;
8637
8638 for (i = 0; i < 64; i++) {
8639 if (wpa_s->drv_flags2 & (1LLU << i)) {
8640 ret = os_snprintf(pos, end - pos, "%s\n",
8641 driver_flag2_to_string(1LLU << i));
8642 if (os_snprintf_error(end - pos, ret))
8643 return -1;
8644 pos += ret;
8645 }
8646 }
8647
8648 return pos - buf;
8649}
8650
8651
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008652static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
8653 size_t buflen)
8654{
8655 struct hostap_sta_driver_data sta;
8656 int ret;
8657
8658 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
8659 if (ret)
8660 return -1;
8661
8662 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008663 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008664 if (os_snprintf_error(buflen, ret))
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008665 return -1;
8666 return ret;
8667}
8668
8669
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008670#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008671static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8672 char *buf, size_t buflen)
8673{
8674 int ret;
8675
8676 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008677 if (ret == 0) {
8678 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
8679 struct p2p_data *p2p = wpa_s->global->p2p;
8680 if (p2p) {
8681 char country[3];
8682 country[0] = cmd[8];
8683 country[1] = cmd[9];
8684 country[2] = 0x04;
8685 p2p_set_country(p2p, country);
8686 }
8687 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008688 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008689 if (os_snprintf_error(buflen, ret))
8690 ret = -1;
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008691 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008692 return ret;
8693}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008694#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008695
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07008696
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008697static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8698 char *buf, size_t buflen)
8699{
8700 int ret;
Hai Shalom60840252021-02-19 19:02:11 -08008701 char *pos, *temp = NULL;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008702 u8 *data = NULL;
8703 unsigned int vendor_id, subcmd;
Hai Shalom60840252021-02-19 19:02:11 -08008704 enum nested_attr nested_attr_flag = NESTED_ATTR_UNSPECIFIED;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008705 struct wpabuf *reply;
8706 size_t data_len = 0;
8707
Hai Shalom60840252021-02-19 19:02:11 -08008708 /**
8709 * cmd: <vendor id> <subcommand id> [<hex formatted data>]
8710 * [nested=<0|1>]
8711 */
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008712 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008713 if (!isblank((unsigned char) *pos))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008714 return -EINVAL;
8715
8716 subcmd = strtoul(pos, &pos, 10);
8717
8718 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008719 if (!isblank((unsigned char) *pos++))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008720 return -EINVAL;
Hai Shalom60840252021-02-19 19:02:11 -08008721
8722 temp = os_strchr(pos, ' ');
8723 data_len = temp ? (size_t) (temp - pos) : os_strlen(pos);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008724 }
8725
8726 if (data_len) {
8727 data_len /= 2;
8728 data = os_malloc(data_len);
8729 if (!data)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008730 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008731
8732 if (hexstr2bin(pos, data, data_len)) {
8733 wpa_printf(MSG_DEBUG,
8734 "Vendor command: wrong parameter format");
8735 os_free(data);
8736 return -EINVAL;
8737 }
8738 }
8739
Hai Shalom60840252021-02-19 19:02:11 -08008740 pos = os_strstr(cmd, "nested=");
8741 if (pos)
8742 nested_attr_flag = atoi(pos + 7) ? NESTED_ATTR_USED :
8743 NESTED_ATTR_NOT_USED;
8744
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008745 reply = wpabuf_alloc((buflen - 1) / 2);
8746 if (!reply) {
8747 os_free(data);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008748 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008749 }
8750
8751 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
Hai Shalom60840252021-02-19 19:02:11 -08008752 nested_attr_flag, reply);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008753
8754 if (ret == 0)
8755 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
8756 wpabuf_len(reply));
8757
8758 wpabuf_free(reply);
8759 os_free(data);
8760
8761 return ret;
8762}
8763
8764
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008765static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
8766{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008767#ifdef CONFIG_P2P
8768 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
8769 wpa_s->global->p2p_init_wpa_s : wpa_s;
8770#endif /* CONFIG_P2P */
8771
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008772 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
8773
Dmitry Shmidt29333592017-01-09 12:27:11 -08008774 if (wpas_abort_ongoing_scan(wpa_s) == 0)
8775 wpa_s->ignore_post_flush_scan_res = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008776
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008777 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
8778 /*
8779 * Avoid possible auto connect re-connection on getting
8780 * disconnected due to state flush.
8781 */
8782 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
8783 }
8784
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008785#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008786 wpas_p2p_group_remove(p2p_wpa_s, "*");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008787 wpas_p2p_cancel(p2p_wpa_s);
8788 p2p_ctrl_flush(p2p_wpa_s);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008789 wpas_p2p_service_flush(p2p_wpa_s);
8790 p2p_wpa_s->global->p2p_disabled = 0;
8791 p2p_wpa_s->global->p2p_per_sta_psk = 0;
8792 p2p_wpa_s->conf->num_sec_device_types = 0;
8793 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
8794 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
8795 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008796 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08008797 p2p_wpa_s->global->pending_p2ps_group = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008798 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008799#endif /* CONFIG_P2P */
8800
8801#ifdef CONFIG_WPS_TESTING
8802 wps_version_number = 0x20;
Hai Shaloma20dcd72022-02-04 13:43:00 -08008803 wps_testing_stub_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08008804 wps_corrupt_pkhash = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008805 wps_force_auth_types_in_use = 0;
8806 wps_force_encr_types_in_use = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008807#endif /* CONFIG_WPS_TESTING */
8808#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008809 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008810 wpas_wps_cancel(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008811 wps_registrar_flush(wpa_s->wps->registrar);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008812#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07008813 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008814 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008815
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008816#ifdef CONFIG_DPP
8817 wpas_dpp_deinit(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07008818 wpa_s->dpp_init_max_tries = 0;
8819 wpa_s->dpp_init_retry_time = 0;
8820 wpa_s->dpp_resp_wait_time = 0;
8821 wpa_s->dpp_resp_max_tries = 0;
8822 wpa_s->dpp_resp_retry_time = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008823#ifdef CONFIG_DPP2
8824 wpas_dpp_chirp_stop(wpa_s);
8825 wpa_s->dpp_pfs_fallback = 0;
8826#endif /* CONFIG_DPP2 */
Sunil Ravi89eba102022-09-13 21:04:37 -07008827#ifdef CONFIG_DPP3
8828 {
8829 int i;
8830
8831 for (i = 0; i < DPP_PB_INFO_COUNT; i++) {
8832 struct dpp_pb_info *info;
8833
8834 info = &wpa_s->dpp_pb[i];
8835 info->rx_time.sec = 0;
8836 info->rx_time.usec = 0;
8837 }
8838 }
8839#endif /* CONFIG_DPP3 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008840#ifdef CONFIG_TESTING_OPTIONS
8841 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
8842 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
8843 dpp_pkex_ephemeral_key_override_len = 0;
8844 dpp_protocol_key_override_len = 0;
8845 dpp_nonce_override_len = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08008846#ifdef CONFIG_DPP3
8847 dpp_version_override = 3;
8848#elif defined(CONFIG_DPP2)
Hai Shalom4fbc08f2020-05-18 12:37:00 -07008849 dpp_version_override = 2;
8850#else /* CONFIG_DPP2 */
8851 dpp_version_override = 1;
8852#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008853#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008854#endif /* CONFIG_DPP */
8855
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008856#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008857#ifdef CONFIG_TDLS_TESTING
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008858 tdls_testing = 0;
8859#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008860 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
8861 wpa_tdls_enable(wpa_s->wpa, 1);
8862#endif /* CONFIG_TDLS */
8863
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008864 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
8865 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07008866 wpa_s->last_michael_mic_error.sec = 0;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008867
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008868 wpa_s->no_keep_alive = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08008869 wpa_s->own_disconnect_req = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008870 wpa_s->own_reconnect_req = 0;
8871 wpa_s->deny_ptk0_rekey = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008872
8873 os_free(wpa_s->disallow_aps_bssid);
8874 wpa_s->disallow_aps_bssid = NULL;
8875 wpa_s->disallow_aps_bssid_count = 0;
8876 os_free(wpa_s->disallow_aps_ssid);
8877 wpa_s->disallow_aps_ssid = NULL;
8878 wpa_s->disallow_aps_ssid_count = 0;
8879
8880 wpa_s->set_sta_uapsd = 0;
8881 wpa_s->sta_uapsd = 0;
8882
Hai Shalom899fcc72020-10-19 14:38:18 -07008883 wpa_s->consecutive_conn_failures = 0;
8884
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008885 wpa_drv_radio_disable(wpa_s, 0);
Hai Shalom60840252021-02-19 19:02:11 -08008886 wpa_bssid_ignore_clear(wpa_s);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008887 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
8888 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08008889 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08008890 wpa_s->conf->auto_interworking = 0;
8891 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008892
Hai Shalom60840252021-02-19 19:02:11 -08008893 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008894 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
8895 rsn_preauth_deinit(wpa_s->wpa);
8896
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008897 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
8898 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
8899 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
Hai Shalome21d4e82020-04-29 16:34:06 -07008900 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008901
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008902 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008903 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008904
8905 wpa_s->next_ssid = NULL;
8906
Sunil Ravi99c035e2024-07-12 01:42:03 +00008907 wnm_btm_reset(wpa_s);
8908
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008909#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008910#ifdef CONFIG_HS20
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008911 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008912 hs20_del_icon(wpa_s, NULL, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008913#endif /* CONFIG_HS20 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008914#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008915
8916 wpa_s->ext_mgmt_frame_handling = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008917 wpa_s->ext_eapol_frame_io = 0;
8918#ifdef CONFIG_TESTING_OPTIONS
8919 wpa_s->extra_roc_dur = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008920 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008921 wpa_s->p2p_go_csa_on_inv = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008922 wpa_s->ignore_auth_resp = 0;
8923 wpa_s->ignore_assoc_disallow = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008924 wpa_s->disable_sa_query = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008925 wpa_s->testing_resend_assoc = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008926 wpa_s->ignore_sae_h2e_only = 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07008927 wpa_s->ft_rsnxe_used = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008928 wpa_s->reject_btm_req_reason = 0;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008929 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008930 wpa_sm_set_test_eapol_m2_elems(wpa_s->wpa, NULL);
8931 wpa_sm_set_test_eapol_m4_elems(wpa_s->wpa, NULL);
8932 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ENCRYPT_EAPOL_M2, 0);
8933 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_ENCRYPT_EAPOL_M4, 0);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008934 os_free(wpa_s->get_pref_freq_list_override);
8935 wpa_s->get_pref_freq_list_override = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008936 wpabuf_free(wpa_s->sae_commit_override);
8937 wpa_s->sae_commit_override = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008938 os_free(wpa_s->extra_sae_rejected_groups);
8939 wpa_s->extra_sae_rejected_groups = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008940 wpabuf_free(wpa_s->rsne_override_eapol);
8941 wpa_s->rsne_override_eapol = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008942 wpabuf_free(wpa_s->rsnxe_override_assoc);
8943 wpa_s->rsnxe_override_assoc = NULL;
8944 wpabuf_free(wpa_s->rsnxe_override_eapol);
8945 wpa_s->rsnxe_override_eapol = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008946 wpas_clear_driver_signal_override(wpa_s);
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008947#ifndef CONFIG_NO_ROBUST_AV
Hai Shaloma20dcd72022-02-04 13:43:00 -08008948 wpa_s->disable_scs_support = 0;
8949 wpa_s->disable_mscs_support = 0;
8950 wpa_s->enable_dscp_policy_capa = 0;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008951#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalom899fcc72020-10-19 14:38:18 -07008952 wpa_s->oci_freq_override_eapol = 0;
8953 wpa_s->oci_freq_override_saquery_req = 0;
8954 wpa_s->oci_freq_override_saquery_resp = 0;
8955 wpa_s->oci_freq_override_eapol_g2 = 0;
8956 wpa_s->oci_freq_override_ft_assoc = 0;
8957 wpa_s->oci_freq_override_fils_assoc = 0;
8958 wpa_s->oci_freq_override_wnm_sleep = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -07008959 wpa_s->disable_eapol_g2_tx = 0;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008960 wpa_s->test_assoc_comeback_type = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008961#ifdef CONFIG_DPP
8962 os_free(wpa_s->dpp_config_obj_override);
8963 wpa_s->dpp_config_obj_override = NULL;
8964 os_free(wpa_s->dpp_discovery_override);
8965 wpa_s->dpp_discovery_override = NULL;
8966 os_free(wpa_s->dpp_groups_override);
8967 wpa_s->dpp_groups_override = NULL;
Sunil8cd6f4d2022-06-28 18:40:46 +00008968 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
8969 wpa_s->dpp_discard_public_action = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008970 dpp_test = DPP_TEST_DISABLED;
8971#endif /* CONFIG_DPP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008972#endif /* CONFIG_TESTING_OPTIONS */
8973
8974 wpa_s->disconnected = 0;
8975 os_free(wpa_s->next_scan_freqs);
8976 wpa_s->next_scan_freqs = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008977 os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN);
8978 wpa_s->next_scan_bssid_wildcard_ssid = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008979 os_free(wpa_s->select_network_scan_freqs);
8980 wpa_s->select_network_scan_freqs = NULL;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008981#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07008982 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Sunil Ravib0ac25f2024-07-12 01:42:03 +00008983#endif /* CONFIG_NO_ROBUST_AV */
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008984
8985 wpa_bss_flush(wpa_s);
8986 if (!dl_list_empty(&wpa_s->bss)) {
8987 wpa_printf(MSG_DEBUG,
8988 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8989 MACSTR " pending_bssid=" MACSTR,
8990 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
8991 MAC2STR(wpa_s->bssid),
8992 MAC2STR(wpa_s->pending_bssid));
8993 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008994
8995 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -08008996 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008997
8998#ifdef CONFIG_SME
8999 wpa_s->sme.last_unprot_disconnect.sec = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07009000 wpa_s->sme.auth_alg = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07009001#endif /* CONFIG_SME */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009002
9003 wpabuf_free(wpa_s->ric_ies);
9004 wpa_s->ric_ies = NULL;
Hai Shalom74f70d42019-02-11 14:42:39 -08009005
9006 wpa_supplicant_update_channel_list(wpa_s, NULL);
9007
9008 free_bss_tmp_disallowed(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -07009009
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009010#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -07009011 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009012#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalom60840252021-02-19 19:02:11 -08009013
9014#ifdef CONFIG_PASN
9015 wpas_pasn_auth_stop(wpa_s);
9016#endif /* CONFIG_PASN */
9017
9018 if (wpa_s->mac_addr_changed && wpa_s->conf->mac_addr == 0)
9019 wpas_restore_permanent_mac_addr(wpa_s);
Sunil Ravia04bd252022-05-02 22:54:18 -07009020
9021 wpa_s->conf->ignore_old_scan_res = 0;
Sunil Ravib0ac25f2024-07-12 01:42:03 +00009022
9023#ifdef CONFIG_NAN_USD
9024 wpas_nan_usd_flush(wpa_s);
9025#endif /* CONFIG_NAN_USD */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009026}
9027
9028
9029static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
9030 char *buf, size_t buflen)
9031{
9032 struct wpa_radio_work *work;
9033 char *pos, *end;
9034 struct os_reltime now, diff;
9035
9036 pos = buf;
9037 end = buf + buflen;
9038
9039 os_get_reltime(&now);
9040
9041 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
9042 {
9043 int ret;
9044
9045 os_reltime_sub(&now, &work->time, &diff);
9046 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
9047 work->type, work->wpa_s->ifname, work->freq,
9048 work->started, diff.sec, diff.usec);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009049 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009050 break;
9051 pos += ret;
9052 }
9053
9054 return pos - buf;
9055}
9056
9057
9058static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
9059{
9060 struct wpa_radio_work *work = eloop_ctx;
9061 struct wpa_external_work *ework = work->ctx;
9062
9063 wpa_dbg(work->wpa_s, MSG_DEBUG,
9064 "Timing out external radio work %u (%s)",
9065 ework->id, work->type);
9066 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009067 work->wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009068 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07009069 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009070}
9071
9072
9073static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
9074{
9075 struct wpa_external_work *ework = work->ctx;
9076
9077 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08009078 if (work->started)
9079 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
9080 work, NULL);
9081
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009082 /*
9083 * work->type points to a buffer in ework, so need to replace
9084 * that here with a fixed string to avoid use of freed memory
9085 * in debug prints.
9086 */
9087 work->type = "freed-ext-work";
9088 work->ctx = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009089 os_free(ework);
9090 return;
9091 }
9092
9093 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
9094 ework->id, ework->type);
9095 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009096 work->wpa_s->ext_work_in_progress = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009097 if (!ework->timeout)
9098 ework->timeout = 10;
9099 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
9100 work, NULL);
9101}
9102
9103
9104static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
9105 char *buf, size_t buflen)
9106{
9107 struct wpa_external_work *ework;
9108 char *pos, *pos2;
9109 size_t type_len;
9110 int ret;
9111 unsigned int freq = 0;
9112
9113 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
9114
9115 ework = os_zalloc(sizeof(*ework));
9116 if (ework == NULL)
9117 return -1;
9118
9119 pos = os_strchr(cmd, ' ');
9120 if (pos) {
9121 type_len = pos - cmd;
9122 pos++;
9123
9124 pos2 = os_strstr(pos, "freq=");
9125 if (pos2)
9126 freq = atoi(pos2 + 5);
9127
9128 pos2 = os_strstr(pos, "timeout=");
9129 if (pos2)
9130 ework->timeout = atoi(pos2 + 8);
9131 } else {
9132 type_len = os_strlen(cmd);
9133 }
9134 if (4 + type_len >= sizeof(ework->type))
9135 type_len = sizeof(ework->type) - 4 - 1;
9136 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
9137 os_memcpy(ework->type + 4, cmd, type_len);
9138 ework->type[4 + type_len] = '\0';
9139
9140 wpa_s->ext_work_id++;
9141 if (wpa_s->ext_work_id == 0)
9142 wpa_s->ext_work_id++;
9143 ework->id = wpa_s->ext_work_id;
9144
9145 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
9146 ework) < 0) {
9147 os_free(ework);
9148 return -1;
9149 }
9150
9151 ret = os_snprintf(buf, buflen, "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009152 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009153 return -1;
9154 return ret;
9155}
9156
9157
9158static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
9159{
9160 struct wpa_radio_work *work;
9161 unsigned int id = atoi(cmd);
9162
9163 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
9164 {
9165 struct wpa_external_work *ework;
9166
9167 if (os_strncmp(work->type, "ext:", 4) != 0)
9168 continue;
9169 ework = work->ctx;
9170 if (id && ework->id != id)
9171 continue;
9172 wpa_dbg(wpa_s, MSG_DEBUG,
9173 "Completed external radio work %u (%s)",
9174 ework->id, ework->type);
9175 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009176 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009177 radio_work_done(work);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07009178 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009179 return 3; /* "OK\n" */
9180 }
9181
9182 return -1;
9183}
9184
9185
9186static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
9187 char *buf, size_t buflen)
9188{
9189 if (os_strcmp(cmd, "show") == 0)
9190 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
9191 if (os_strncmp(cmd, "add ", 4) == 0)
9192 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
9193 if (os_strncmp(cmd, "done ", 5) == 0)
9194 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
9195 return -1;
9196}
9197
9198
9199void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
9200{
9201 struct wpa_radio_work *work, *tmp;
9202
Dmitry Shmidt18463232014-01-24 12:29:41 -08009203 if (!wpa_s || !wpa_s->radio)
9204 return;
9205
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009206 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
9207 struct wpa_radio_work, list) {
9208 struct wpa_external_work *ework;
9209
9210 if (os_strncmp(work->type, "ext:", 4) != 0)
9211 continue;
9212 ework = work->ctx;
9213 wpa_dbg(wpa_s, MSG_DEBUG,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07009214 "Flushing%s external radio work %u (%s)",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009215 work->started ? " started" : "", ework->id,
9216 ework->type);
9217 if (work->started)
9218 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
9219 work, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009220 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07009221 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009222 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07009223}
9224
9225
Dmitry Shmidt051af732013-10-22 13:52:46 -07009226static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
9227{
9228 struct wpa_supplicant *wpa_s = eloop_ctx;
9229 eapol_sm_notify_ctrl_response(wpa_s->eapol);
9230}
9231
9232
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009233static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
9234 unsigned int *scan_id_count, int scan_id[])
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009235{
9236 const char *pos = value;
9237
9238 while (pos) {
9239 if (*pos == ' ' || *pos == '\0')
9240 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009241 if (*scan_id_count == MAX_SCAN_ID)
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009242 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009243 scan_id[(*scan_id_count)++] = atoi(pos);
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009244 pos = os_strchr(pos, ',');
9245 if (pos)
9246 pos++;
9247 }
9248
9249 return 0;
9250}
9251
9252
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009253static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
9254 char *reply, int reply_size, int *reply_len)
9255{
9256 char *pos;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009257 unsigned int manual_scan_passive = 0;
9258 unsigned int manual_scan_use_id = 0;
9259 unsigned int manual_scan_only_new = 0;
9260 unsigned int scan_only = 0;
9261 unsigned int scan_id_count = 0;
Sunil8cd6f4d2022-06-28 18:40:46 +00009262 unsigned int manual_non_coloc_6ghz = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009263 int scan_id[MAX_SCAN_ID];
9264 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
9265 struct wpa_scan_results *scan_res);
9266 int *manual_scan_freqs = NULL;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009267 struct wpa_ssid_value *ssid = NULL, *ns;
9268 unsigned int ssid_count = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009269
9270 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
9271 *reply_len = -1;
9272 return;
9273 }
9274
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009275 if (radio_work_pending(wpa_s, "scan")) {
9276 wpa_printf(MSG_DEBUG,
9277 "Pending scan scheduled - reject new request");
9278 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9279 return;
9280 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009281
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07009282#ifdef CONFIG_INTERWORKING
9283 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
9284 wpa_printf(MSG_DEBUG,
9285 "Interworking select in progress - reject new scan");
9286 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9287 return;
9288 }
9289#endif /* CONFIG_INTERWORKING */
9290
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009291 if (params) {
9292 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009293 scan_only = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009294
9295 pos = os_strstr(params, "freq=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009296 if (pos) {
9297 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
9298 pos + 5);
9299 if (manual_scan_freqs == NULL) {
9300 *reply_len = -1;
9301 goto done;
9302 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009303 }
9304
9305 pos = os_strstr(params, "passive=");
9306 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009307 manual_scan_passive = !!atoi(pos + 8);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009308
9309 pos = os_strstr(params, "use_id=");
9310 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009311 manual_scan_use_id = atoi(pos + 7);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009312
9313 pos = os_strstr(params, "only_new=1");
9314 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009315 manual_scan_only_new = 1;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009316
9317 pos = os_strstr(params, "scan_id=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009318 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
9319 scan_id) < 0) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009320 *reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009321 goto done;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009322 }
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009323
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009324 pos = os_strstr(params, "bssid=");
9325 if (pos) {
9326 u8 bssid[ETH_ALEN];
9327
9328 pos += 6;
9329 if (hwaddr_aton(pos, bssid)) {
9330 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
9331 *reply_len = -1;
9332 goto done;
9333 }
9334 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
Hai Shalomfdcde762020-04-02 11:19:20 -07009335
9336 wpa_s->next_scan_bssid_wildcard_ssid =
9337 os_strstr(params, "wildcard_ssid=1") != NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009338 }
9339
Sunil8cd6f4d2022-06-28 18:40:46 +00009340 pos = os_strstr(params, "non_coloc_6ghz=");
9341 if (pos)
9342 manual_non_coloc_6ghz = !!atoi(pos + 15);
9343
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009344 pos = params;
9345 while (pos && *pos != '\0') {
9346 if (os_strncmp(pos, "ssid ", 5) == 0) {
9347 char *end;
9348
9349 pos += 5;
9350 end = pos;
9351 while (*end) {
9352 if (*end == '\0' || *end == ' ')
9353 break;
9354 end++;
9355 }
9356
9357 ns = os_realloc_array(
9358 ssid, ssid_count + 1,
9359 sizeof(struct wpa_ssid_value));
9360 if (ns == NULL) {
9361 *reply_len = -1;
9362 goto done;
9363 }
9364 ssid = ns;
9365
9366 if ((end - pos) & 0x01 ||
9367 end - pos > 2 * SSID_MAX_LEN ||
9368 hexstr2bin(pos, ssid[ssid_count].ssid,
9369 (end - pos) / 2) < 0) {
9370 wpa_printf(MSG_DEBUG,
9371 "Invalid SSID value '%s'",
9372 pos);
9373 *reply_len = -1;
9374 goto done;
9375 }
9376 ssid[ssid_count].ssid_len = (end - pos) / 2;
9377 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
9378 ssid[ssid_count].ssid,
9379 ssid[ssid_count].ssid_len);
9380 ssid_count++;
9381 pos = end;
9382 }
9383
9384 pos = os_strchr(pos, ' ');
9385 if (pos)
9386 pos++;
9387 }
9388 }
9389
9390 wpa_s->num_ssids_from_scan_req = ssid_count;
9391 os_free(wpa_s->ssids_from_scan_req);
9392 if (ssid_count) {
9393 wpa_s->ssids_from_scan_req = ssid;
9394 ssid = NULL;
9395 } else {
9396 wpa_s->ssids_from_scan_req = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009397 }
9398
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009399 if (scan_only)
9400 scan_res_handler = scan_only_handler;
9401 else if (wpa_s->scan_res_handler == scan_only_handler)
9402 scan_res_handler = NULL;
9403 else
9404 scan_res_handler = wpa_s->scan_res_handler;
9405
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009406 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
9407 ((wpa_s->wpa_state <= WPA_SCANNING) ||
9408 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009409 wpa_s->manual_scan_passive = manual_scan_passive;
9410 wpa_s->manual_scan_use_id = manual_scan_use_id;
9411 wpa_s->manual_scan_only_new = manual_scan_only_new;
9412 wpa_s->scan_id_count = scan_id_count;
Sunil8cd6f4d2022-06-28 18:40:46 +00009413 wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009414 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9415 wpa_s->scan_res_handler = scan_res_handler;
9416 os_free(wpa_s->manual_scan_freqs);
9417 wpa_s->manual_scan_freqs = manual_scan_freqs;
9418 manual_scan_freqs = NULL;
9419
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009420 wpa_s->normal_scans = 0;
9421 wpa_s->scan_req = MANUAL_SCAN_REQ;
9422 wpa_s->after_wps = 0;
9423 wpa_s->known_wps_freq = 0;
9424 wpa_supplicant_req_scan(wpa_s, 0, 0);
9425 if (wpa_s->manual_scan_use_id) {
9426 wpa_s->manual_scan_id++;
9427 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9428 wpa_s->manual_scan_id);
9429 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9430 wpa_s->manual_scan_id);
9431 }
9432 } else if (wpa_s->sched_scanning) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009433 wpa_s->manual_scan_passive = manual_scan_passive;
9434 wpa_s->manual_scan_use_id = manual_scan_use_id;
9435 wpa_s->manual_scan_only_new = manual_scan_only_new;
9436 wpa_s->scan_id_count = scan_id_count;
Sunil8cd6f4d2022-06-28 18:40:46 +00009437 wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009438 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9439 wpa_s->scan_res_handler = scan_res_handler;
9440 os_free(wpa_s->manual_scan_freqs);
9441 wpa_s->manual_scan_freqs = manual_scan_freqs;
9442 manual_scan_freqs = NULL;
9443
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009444 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
9445 wpa_supplicant_cancel_sched_scan(wpa_s);
9446 wpa_s->scan_req = MANUAL_SCAN_REQ;
9447 wpa_supplicant_req_scan(wpa_s, 0, 0);
9448 if (wpa_s->manual_scan_use_id) {
9449 wpa_s->manual_scan_id++;
9450 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9451 wpa_s->manual_scan_id);
9452 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9453 wpa_s->manual_scan_id);
9454 }
9455 } else {
9456 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
9457 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9458 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009459
9460done:
9461 os_free(manual_scan_freqs);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009462 os_free(ssid);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009463}
9464
9465
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009466#ifdef CONFIG_TESTING_OPTIONS
9467
9468static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
9469 unsigned int freq, const u8 *dst,
9470 const u8 *src, const u8 *bssid,
9471 const u8 *data, size_t data_len,
9472 enum offchannel_send_action_result
9473 result)
9474{
9475 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
9476 " src=" MACSTR " bssid=" MACSTR " result=%s",
9477 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
9478 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
9479 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
9480 "NO_ACK" : "FAILED"));
9481}
9482
9483
9484static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
9485{
9486 char *pos, *param;
9487 size_t len;
9488 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
9489 int res, used;
9490 int freq = 0, no_cck = 0, wait_time = 0;
9491
9492 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
9493 * <action=Action frame payload> */
9494
9495 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
9496
9497 pos = cmd;
9498 used = hwaddr_aton2(pos, da);
9499 if (used < 0)
9500 return -1;
9501 pos += used;
9502 while (*pos == ' ')
9503 pos++;
9504 used = hwaddr_aton2(pos, bssid);
9505 if (used < 0)
9506 return -1;
9507 pos += used;
9508
9509 param = os_strstr(pos, " freq=");
9510 if (param) {
9511 param += 6;
9512 freq = atoi(param);
9513 }
9514
9515 param = os_strstr(pos, " no_cck=");
9516 if (param) {
9517 param += 8;
9518 no_cck = atoi(param);
9519 }
9520
9521 param = os_strstr(pos, " wait_time=");
9522 if (param) {
9523 param += 11;
9524 wait_time = atoi(param);
9525 }
9526
9527 param = os_strstr(pos, " action=");
9528 if (param == NULL)
9529 return -1;
9530 param += 8;
9531
9532 len = os_strlen(param);
9533 if (len & 1)
9534 return -1;
9535 len /= 2;
9536
9537 buf = os_malloc(len);
9538 if (buf == NULL)
9539 return -1;
9540
9541 if (hexstr2bin(param, buf, len) < 0) {
9542 os_free(buf);
9543 return -1;
9544 }
9545
9546 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
9547 buf, len, wait_time,
9548 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
9549 os_free(buf);
9550 return res;
9551}
9552
9553
9554static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
9555{
9556 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
9557 offchannel_send_action_done(wpa_s);
9558}
9559
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009560
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009561static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
9562 char *cmd)
9563{
9564 char *pos, *param;
9565 size_t len;
9566 u8 *buf;
9567 int freq = 0, datarate = 0, ssi_signal = 0;
9568 union wpa_event_data event;
9569
9570 if (!wpa_s->ext_mgmt_frame_handling)
9571 return -1;
9572
9573 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
9574
9575 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
9576
9577 pos = cmd;
9578 param = os_strstr(pos, "freq=");
9579 if (param) {
9580 param += 5;
9581 freq = atoi(param);
9582 }
9583
9584 param = os_strstr(pos, " datarate=");
9585 if (param) {
9586 param += 10;
9587 datarate = atoi(param);
9588 }
9589
9590 param = os_strstr(pos, " ssi_signal=");
9591 if (param) {
9592 param += 12;
9593 ssi_signal = atoi(param);
9594 }
9595
9596 param = os_strstr(pos, " frame=");
9597 if (param == NULL)
9598 return -1;
9599 param += 7;
9600
9601 len = os_strlen(param);
9602 if (len & 1)
9603 return -1;
9604 len /= 2;
9605
9606 buf = os_malloc(len);
9607 if (buf == NULL)
9608 return -1;
9609
9610 if (hexstr2bin(param, buf, len) < 0) {
9611 os_free(buf);
9612 return -1;
9613 }
9614
9615 os_memset(&event, 0, sizeof(event));
9616 event.rx_mgmt.freq = freq;
9617 event.rx_mgmt.frame = buf;
9618 event.rx_mgmt.frame_len = len;
9619 event.rx_mgmt.ssi_signal = ssi_signal;
9620 event.rx_mgmt.datarate = datarate;
9621 wpa_s->ext_mgmt_frame_handling = 0;
9622 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
9623 wpa_s->ext_mgmt_frame_handling = 1;
9624
9625 os_free(buf);
9626
9627 return 0;
9628}
9629
9630
Paul Stewart092955c2017-02-06 09:13:09 -08009631static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
9632 char *param)
9633{
9634 struct wpa_scan_res *res;
9635 struct os_reltime now;
9636 char *pos, *end;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009637 int ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08009638
9639 if (!param)
9640 return -1;
9641
9642 if (os_strcmp(param, "START") == 0) {
9643 wpa_bss_update_start(wpa_s);
9644 return 0;
9645 }
9646
9647 if (os_strcmp(param, "END") == 0) {
9648 wpa_bss_update_end(wpa_s, NULL, 1);
9649 return 0;
9650 }
9651
9652 if (os_strncmp(param, "BSS ", 4) != 0)
9653 return -1;
9654 param += 3;
9655
9656 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
9657 if (!res)
9658 return -1;
9659
9660 pos = os_strstr(param, " flags=");
9661 if (pos)
9662 res->flags = strtol(pos + 7, NULL, 16);
9663
9664 pos = os_strstr(param, " bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009665 if (pos && hwaddr_aton(pos + 7, res->bssid))
9666 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009667
9668 pos = os_strstr(param, " freq=");
9669 if (pos)
9670 res->freq = atoi(pos + 6);
9671
9672 pos = os_strstr(param, " beacon_int=");
9673 if (pos)
9674 res->beacon_int = atoi(pos + 12);
9675
9676 pos = os_strstr(param, " caps=");
9677 if (pos)
9678 res->caps = strtol(pos + 6, NULL, 16);
9679
9680 pos = os_strstr(param, " qual=");
9681 if (pos)
9682 res->qual = atoi(pos + 6);
9683
9684 pos = os_strstr(param, " noise=");
9685 if (pos)
9686 res->noise = atoi(pos + 7);
9687
9688 pos = os_strstr(param, " level=");
9689 if (pos)
9690 res->level = atoi(pos + 7);
9691
9692 pos = os_strstr(param, " tsf=");
9693 if (pos)
9694 res->tsf = strtoll(pos + 5, NULL, 16);
9695
9696 pos = os_strstr(param, " age=");
9697 if (pos)
9698 res->age = atoi(pos + 5);
9699
9700 pos = os_strstr(param, " est_throughput=");
9701 if (pos)
9702 res->est_throughput = atoi(pos + 16);
9703
9704 pos = os_strstr(param, " snr=");
9705 if (pos)
9706 res->snr = atoi(pos + 5);
9707
9708 pos = os_strstr(param, " parent_tsf=");
9709 if (pos)
9710 res->parent_tsf = strtoll(pos + 7, NULL, 16);
9711
9712 pos = os_strstr(param, " tsf_bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009713 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
9714 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009715
9716 pos = os_strstr(param, " ie=");
9717 if (pos) {
9718 pos += 4;
9719 end = os_strchr(pos, ' ');
9720 if (!end)
9721 end = pos + os_strlen(pos);
9722 res->ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009723 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
9724 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009725 }
9726
9727 pos = os_strstr(param, " beacon_ie=");
9728 if (pos) {
9729 pos += 11;
9730 end = os_strchr(pos, ' ');
9731 if (!end)
9732 end = pos + os_strlen(pos);
9733 res->beacon_ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009734 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
9735 res->beacon_ie_len))
9736 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009737 }
9738
9739 os_get_reltime(&now);
9740 wpa_bss_update_scan_res(wpa_s, res, &now);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009741 ret = 0;
9742fail:
Paul Stewart092955c2017-02-06 09:13:09 -08009743 os_free(res);
9744
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009745 return ret;
Paul Stewart092955c2017-02-06 09:13:09 -08009746}
9747
9748
Hai Shaloma20dcd72022-02-04 13:43:00 -08009749static int wpas_ctrl_iface_driver_event_assoc(struct wpa_supplicant *wpa_s,
9750 char *param)
9751{
9752 union wpa_event_data event;
9753 struct assoc_info *ai;
9754 char *ctx = NULL;
9755 int ret = -1;
9756 struct wpabuf *req_ies = NULL;
9757 struct wpabuf *resp_ies = NULL;
9758 struct wpabuf *resp_frame = NULL;
9759 struct wpabuf *beacon_ies = NULL;
9760 struct wpabuf *key_replay_ctr = NULL;
9761 struct wpabuf *ptk_kck = NULL;
9762 struct wpabuf *ptk_kek = NULL;
9763 struct wpabuf *fils_pmk = NULL;
9764 char *str, *pos;
9765 u8 addr[ETH_ALEN];
9766 u8 fils_pmkid[PMKID_LEN];
9767
9768 os_memset(&event, 0, sizeof(event));
9769 ai = &event.assoc_info;
9770
9771 while ((str = str_token(param, " ", &ctx))) {
9772 pos = os_strchr(str, '=');
9773 if (!pos)
9774 goto fail;
9775 *pos++ = '\0';
9776
9777 if (os_strcmp(str, "reassoc") == 0) {
9778 ai->reassoc = atoi(pos);
9779 } else if (os_strcmp(str, "req_ies") == 0) {
9780 wpabuf_free(req_ies);
9781 req_ies = wpabuf_parse_bin(pos);
9782 if (!req_ies)
9783 goto fail;
9784 ai->req_ies = wpabuf_head(req_ies);
9785 ai->req_ies_len = wpabuf_len(req_ies);
9786 } else if (os_strcmp(str, "resp_ies") == 0) {
9787 wpabuf_free(resp_ies);
9788 resp_ies = wpabuf_parse_bin(pos);
9789 if (!resp_ies)
9790 goto fail;
9791 ai->resp_ies = wpabuf_head(resp_ies);
9792 ai->resp_ies_len = wpabuf_len(resp_ies);
9793 } else if (os_strcmp(str, "resp_frame") == 0) {
9794 wpabuf_free(resp_frame);
9795 resp_frame = wpabuf_parse_bin(pos);
9796 if (!resp_frame)
9797 goto fail;
9798 ai->resp_frame = wpabuf_head(resp_frame);
9799 ai->resp_frame_len = wpabuf_len(resp_frame);
9800 } else if (os_strcmp(str, "beacon_ies") == 0) {
9801 wpabuf_free(beacon_ies);
9802 beacon_ies = wpabuf_parse_bin(pos);
9803 if (!beacon_ies)
9804 goto fail;
9805 ai->beacon_ies = wpabuf_head(beacon_ies);
9806 ai->beacon_ies_len = wpabuf_len(beacon_ies);
9807 } else if (os_strcmp(str, "freq") == 0) {
9808 ai->freq = atoi(pos);
9809 } else if (os_strcmp(str, "wmm::info_bitmap") == 0) {
9810 ai->wmm_params.info_bitmap = atoi(pos);
9811 } else if (os_strcmp(str, "wmm::uapsd_queues") == 0) {
9812 ai->wmm_params.uapsd_queues = atoi(pos);
9813 } else if (os_strcmp(str, "addr") == 0) {
9814 if (hwaddr_aton(pos, addr))
9815 goto fail;
9816 ai->addr = addr;
9817 } else if (os_strcmp(str, "authorized") == 0) {
9818 ai->authorized = atoi(pos);
9819 } else if (os_strcmp(str, "key_replay_ctr") == 0) {
9820 wpabuf_free(key_replay_ctr);
9821 key_replay_ctr = wpabuf_parse_bin(pos);
9822 if (!key_replay_ctr)
9823 goto fail;
9824 ai->key_replay_ctr = wpabuf_head(key_replay_ctr);
9825 ai->key_replay_ctr_len = wpabuf_len(key_replay_ctr);
9826 } else if (os_strcmp(str, "ptk_kck") == 0) {
9827 wpabuf_free(ptk_kck);
9828 ptk_kck = wpabuf_parse_bin(pos);
9829 if (!ptk_kck)
9830 goto fail;
9831 ai->ptk_kck = wpabuf_head(ptk_kck);
9832 ai->ptk_kck_len = wpabuf_len(ptk_kck);
9833 } else if (os_strcmp(str, "ptk_kek") == 0) {
9834 wpabuf_free(ptk_kek);
9835 ptk_kek = wpabuf_parse_bin(pos);
9836 if (!ptk_kek)
9837 goto fail;
9838 ai->ptk_kek = wpabuf_head(ptk_kek);
9839 ai->ptk_kek_len = wpabuf_len(ptk_kek);
9840 } else if (os_strcmp(str, "subnet_status") == 0) {
9841 ai->subnet_status = atoi(pos);
9842 } else if (os_strcmp(str, "fils_erp_next_seq_num") == 0) {
9843 ai->fils_erp_next_seq_num = atoi(pos);
9844 } else if (os_strcmp(str, "fils_pmk") == 0) {
9845 wpabuf_free(fils_pmk);
9846 fils_pmk = wpabuf_parse_bin(pos);
9847 if (!fils_pmk)
9848 goto fail;
9849 ai->fils_pmk = wpabuf_head(fils_pmk);
9850 ai->fils_pmk_len = wpabuf_len(fils_pmk);
9851 } else if (os_strcmp(str, "fils_pmkid") == 0) {
9852 if (hexstr2bin(pos, fils_pmkid, PMKID_LEN) < 0)
9853 goto fail;
9854 ai->fils_pmkid = fils_pmkid;
9855 } else {
9856 goto fail;
9857 }
9858 }
9859
9860 wpa_supplicant_event(wpa_s, EVENT_ASSOC, &event);
9861 ret = 0;
9862fail:
9863 wpabuf_free(req_ies);
9864 wpabuf_free(resp_ies);
9865 wpabuf_free(resp_frame);
9866 wpabuf_free(beacon_ies);
9867 wpabuf_free(key_replay_ctr);
9868 wpabuf_free(ptk_kck);
9869 wpabuf_free(ptk_kek);
9870 wpabuf_free(fils_pmk);
9871 return ret;
9872}
9873
9874
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009875static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
9876{
9877 char *pos, *param;
9878 union wpa_event_data event;
9879 enum wpa_event_type ev;
9880
9881 /* <event name> [parameters..] */
9882
9883 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
9884
9885 pos = cmd;
9886 param = os_strchr(pos, ' ');
9887 if (param)
9888 *param++ = '\0';
9889
9890 os_memset(&event, 0, sizeof(event));
9891
9892 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
9893 ev = EVENT_INTERFACE_ENABLED;
9894 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
9895 ev = EVENT_INTERFACE_DISABLED;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07009896 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
9897 ev = EVENT_AVOID_FREQUENCIES;
9898 if (param == NULL)
9899 param = "";
9900 if (freq_range_list_parse(&event.freq_range, param) < 0)
9901 return -1;
9902 wpa_supplicant_event(wpa_s, ev, &event);
9903 os_free(event.freq_range.range);
9904 return 0;
Paul Stewart092955c2017-02-06 09:13:09 -08009905 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
9906 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
Hai Shaloma20dcd72022-02-04 13:43:00 -08009907 } else if (os_strcmp(cmd, "ASSOC") == 0) {
9908 return wpas_ctrl_iface_driver_event_assoc(wpa_s, param);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009909 } else {
9910 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
9911 cmd);
9912 return -1;
9913 }
9914
9915 wpa_supplicant_event(wpa_s, ev, &event);
9916
9917 return 0;
9918}
9919
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009920
9921static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
9922{
9923 char *pos;
9924 u8 src[ETH_ALEN], *buf;
9925 int used;
9926 size_t len;
9927
9928 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
9929
9930 pos = cmd;
9931 used = hwaddr_aton2(pos, src);
9932 if (used < 0)
9933 return -1;
9934 pos += used;
9935 while (*pos == ' ')
9936 pos++;
9937
9938 len = os_strlen(pos);
9939 if (len & 1)
9940 return -1;
9941 len /= 2;
9942
9943 buf = os_malloc(len);
9944 if (buf == NULL)
9945 return -1;
9946
9947 if (hexstr2bin(pos, buf, len) < 0) {
9948 os_free(buf);
9949 return -1;
9950 }
9951
Sunil8cd6f4d2022-06-28 18:40:46 +00009952 wpa_supplicant_rx_eapol(wpa_s, src, buf, len, FRAME_ENCRYPTION_UNKNOWN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009953 os_free(buf);
9954
9955 return 0;
9956}
9957
9958
Hai Shaloma20dcd72022-02-04 13:43:00 -08009959static int wpas_ctrl_iface_eapol_tx(struct wpa_supplicant *wpa_s, char *cmd)
9960{
9961 char *pos;
9962 u8 dst[ETH_ALEN], *buf;
9963 int used, ret;
9964 size_t len;
9965 unsigned int prev;
9966
9967 wpa_printf(MSG_DEBUG, "External EAPOL TX: %s", cmd);
9968
9969 pos = cmd;
9970 used = hwaddr_aton2(pos, dst);
9971 if (used < 0)
9972 return -1;
9973 pos += used;
9974 while (*pos == ' ')
9975 pos++;
9976
9977 len = os_strlen(pos);
9978 if (len & 1)
9979 return -1;
9980 len /= 2;
9981
9982 buf = os_malloc(len);
9983 if (!buf || hexstr2bin(pos, buf, len) < 0) {
9984 os_free(buf);
9985 return -1;
9986 }
9987
9988 prev = wpa_s->ext_eapol_frame_io;
9989 wpa_s->ext_eapol_frame_io = 0;
9990 ret = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, buf, len);
9991 wpa_s->ext_eapol_frame_io = prev;
9992 os_free(buf);
9993
9994 return ret;
9995}
9996
9997
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009998static u16 ipv4_hdr_checksum(const void *buf, size_t len)
9999{
10000 size_t i;
10001 u32 sum = 0;
10002 const u16 *pos = buf;
10003
10004 for (i = 0; i < len / 2; i++)
10005 sum += *pos++;
10006
10007 while (sum >> 16)
10008 sum = (sum & 0xffff) + (sum >> 16);
10009
10010 return sum ^ 0xffff;
10011}
10012
10013
10014#define HWSIM_PACKETLEN 1500
10015#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
10016
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -070010017static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
10018 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010019{
10020 struct wpa_supplicant *wpa_s = ctx;
10021 const struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -070010022 struct ip ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010023 const u8 *pos;
10024 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -080010025 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010026
Hai Shalom74f70d42019-02-11 14:42:39 -080010027 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
10028 wpa_printf(MSG_DEBUG,
10029 "test data: RX - ignore unexpected length %d",
10030 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010031 return;
Hai Shalom74f70d42019-02-11 14:42:39 -080010032 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010033
10034 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010035 os_memcpy(&ip, eth + 1, sizeof(ip));
10036 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010037
Hai Shalomfdcde762020-04-02 11:19:20 -070010038 if (ip.ip_hl != 5 || ip.ip_v != 4 || ntohs(ip.ip_len) > HWSIM_IP_LEN) {
Hai Shalom74f70d42019-02-11 14:42:39 -080010039 wpa_printf(MSG_DEBUG,
Hai Shalom899fcc72020-10-19 14:38:18 -070010040 "test data: RX - ignore unexpected IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010041 return;
Hai Shalom39bc25d2019-02-06 16:32:13 -080010042 }
Hai Shalombf6e0ba2019-02-11 12:01:50 -080010043
Hai Shalomfdcde762020-04-02 11:19:20 -070010044 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
Hai Shalom74f70d42019-02-11 14:42:39 -080010045 if (*pos != (u8) i) {
10046 wpa_printf(MSG_DEBUG,
10047 "test data: RX - ignore mismatching payload");
10048 return;
10049 }
10050 pos++;
10051 }
10052 extra[0] = '\0';
Hai Shalomfdcde762020-04-02 11:19:20 -070010053 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
10054 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
Hai Shalom74f70d42019-02-11 14:42:39 -080010055 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
10056 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010057}
10058
10059
10060static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
10061 char *cmd)
10062{
10063 int enabled = atoi(cmd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080010064 char *pos;
10065 const char *ifname;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010066
10067 if (!enabled) {
10068 if (wpa_s->l2_test) {
10069 l2_packet_deinit(wpa_s->l2_test);
10070 wpa_s->l2_test = NULL;
10071 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
10072 }
10073 return 0;
10074 }
10075
10076 if (wpa_s->l2_test)
10077 return 0;
10078
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080010079 pos = os_strstr(cmd, " ifname=");
10080 if (pos)
10081 ifname = pos + 8;
10082 else
10083 ifname = wpa_s->ifname;
10084
10085 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010086 ETHERTYPE_IP, wpas_data_test_rx,
10087 wpa_s, 1);
10088 if (wpa_s->l2_test == NULL)
10089 return -1;
10090
10091 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
10092
10093 return 0;
10094}
10095
10096
10097static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
10098{
10099 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom74f70d42019-02-11 14:42:39 -080010100 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010101 int used;
10102 long int val;
10103 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010104 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010105 struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -070010106 struct ip *ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010107 u8 *dpos;
10108 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -080010109 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010110
10111 if (wpa_s->l2_test == NULL)
10112 return -1;
10113
Hai Shalom74f70d42019-02-11 14:42:39 -080010114 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010115
10116 pos = cmd;
10117 used = hwaddr_aton2(pos, dst);
10118 if (used < 0)
10119 return -1;
10120 pos += used;
10121 while (*pos == ' ')
10122 pos++;
10123 used = hwaddr_aton2(pos, src);
10124 if (used < 0)
10125 return -1;
10126 pos += used;
10127
Hai Shalom74f70d42019-02-11 14:42:39 -080010128 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010129 if (val < 0 || val > 0xff)
10130 return -1;
10131 tos = val;
10132
Hai Shalom74f70d42019-02-11 14:42:39 -080010133 pos = os_strstr(pos2, " len=");
10134 if (pos) {
10135 i = atoi(pos + 5);
10136 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
10137 return -1;
10138 send_len = i;
10139 }
10140
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010141 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010142 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
10143 os_memcpy(eth->ether_shost, src, ETH_ALEN);
10144 eth->ether_type = htons(ETHERTYPE_IP);
Hai Shalomfdcde762020-04-02 11:19:20 -070010145 ip = (struct ip *) (eth + 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010146 os_memset(ip, 0, sizeof(*ip));
Hai Shalomfdcde762020-04-02 11:19:20 -070010147 ip->ip_hl = 5;
10148 ip->ip_v = 4;
10149 ip->ip_ttl = 64;
10150 ip->ip_tos = tos;
10151 ip->ip_len = htons(send_len);
10152 ip->ip_p = 1;
10153 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
10154 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
10155 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010156 dpos = (u8 *) (ip + 1);
Hai Shalom74f70d42019-02-11 14:42:39 -080010157 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010158 *dpos++ = i;
10159
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010160 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom74f70d42019-02-11 14:42:39 -080010161 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010162 return -1;
10163
10164 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
10165 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
10166
10167 return 0;
10168}
10169
10170
10171static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
10172 char *cmd)
10173{
10174 u8 *buf;
10175 struct ether_header *eth;
10176 struct l2_packet_data *l2 = NULL;
10177 size_t len;
10178 u16 ethertype;
10179 int res = -1;
10180
10181 len = os_strlen(cmd);
10182 if (len & 1 || len < ETH_HLEN * 2)
10183 return -1;
10184 len /= 2;
10185
10186 buf = os_malloc(len);
10187 if (buf == NULL)
10188 return -1;
10189
10190 if (hexstr2bin(cmd, buf, len) < 0)
10191 goto done;
10192
10193 eth = (struct ether_header *) buf;
10194 ethertype = ntohs(eth->ether_type);
10195
10196 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
10197 wpas_data_test_rx, wpa_s, 1);
10198 if (l2 == NULL)
10199 goto done;
10200
10201 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
10202 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
10203done:
10204 if (l2)
10205 l2_packet_deinit(l2);
10206 os_free(buf);
10207
10208 return res < 0 ? -1 : 0;
10209}
10210
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010211
Jouni Malinenc4818362015-10-04 11:45:13 +030010212static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
10213{
10214 struct wpa_supplicant *wpa_s = eloop_ctx;
10215 int i, count = (intptr_t) timeout_ctx;
10216
10217 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
10218 count);
10219 for (i = 0; i < count; i++) {
10220 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
10221 i + 1, count);
10222 }
10223}
10224
10225
10226static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
10227{
10228 int count;
10229
10230 count = atoi(cmd);
10231 if (count <= 0)
10232 return -1;
10233
10234 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
10235 (void *) (intptr_t) count);
10236}
10237
Dmitry Shmidt818ea482014-03-10 13:15:21 -070010238
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010239static int wpas_get_hex_buf(const char *val, struct wpabuf **ret)
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010240{
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010241 struct wpabuf *buf;
10242 size_t len;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010243
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010244 len = os_strlen(val);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010245 if (len & 1)
10246 return -1;
10247 len /= 2;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010248
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010249 if (len == 0) {
10250 buf = NULL;
10251 } else {
10252 buf = wpabuf_alloc(len);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010253 if (!buf)
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010254 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010255
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010256 if (hexstr2bin(val, wpabuf_put(buf, len), len) < 0) {
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010257 wpabuf_free(buf);
10258 return -1;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010259 }
10260 }
10261
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010262 *ret = buf;
10263 return 0;
10264}
10265
10266
10267static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
10268 const char *cmd)
10269{
10270 struct wpabuf *buf;
10271
10272 if (wpas_get_hex_buf(cmd, &buf) < 0)
10273 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010274 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
10275 return 0;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010276}
10277
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010278
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010279static int wpas_ctrl_test_eapol_m2_elems(struct wpa_supplicant *wpa_s,
10280 const char *cmd)
10281{
10282 struct wpabuf *buf;
10283
10284 if (wpas_get_hex_buf(cmd, &buf) < 0)
10285 return -1;
10286 wpa_sm_set_test_eapol_m2_elems(wpa_s->wpa, buf);
10287 return 0;
10288}
10289
10290
10291static int wpas_ctrl_test_eapol_m4_elems(struct wpa_supplicant *wpa_s,
10292 const char *cmd)
10293{
10294 struct wpabuf *buf;
10295
10296 if (wpas_get_hex_buf(cmd, &buf) < 0)
10297 return -1;
10298 wpa_sm_set_test_eapol_m4_elems(wpa_s->wpa, buf);
10299 return 0;
10300}
10301
10302
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010303static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
10304{
10305 u8 zero[WPA_TK_MAX_LEN];
10306
10307 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
10308 return -1;
10309
10310 wpa_printf(MSG_INFO, "TESTING: Reset PN");
10311 os_memset(zero, 0, sizeof(zero));
10312
10313 /* First, use a zero key to avoid any possible duplicate key avoidance
10314 * in the driver. */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000010315 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 -070010316 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -070010317 zero, wpa_s->last_tk_len,
10318 KEY_FLAG_PAIRWISE_RX_TX) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010319 return -1;
10320
10321 /* Set the previously configured key to reset its TSC/RSC */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000010322 return wpa_drv_set_key(wpa_s, -1, wpa_s->last_tk_alg,
10323 wpa_s->last_tk_addr,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010324 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -070010325 wpa_s->last_tk, wpa_s->last_tk_len,
10326 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010327}
10328
10329
10330static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
10331{
10332 const char *pos = cmd;
10333 int error, pairwise;
10334
10335 error = atoi(pos);
10336 pos = os_strchr(pos, ' ');
10337 if (!pos)
10338 return -1;
10339 pairwise = atoi(pos);
10340 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
10341 return 0;
10342}
10343
10344
10345static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
10346{
10347#ifdef CONFIG_SME
10348 struct wpa_driver_associate_params params;
10349 int ret;
10350
10351 os_memset(&params, 0, sizeof(params));
10352 params.bssid = wpa_s->bssid;
10353 params.ssid = wpa_s->sme.ssid;
10354 params.ssid_len = wpa_s->sme.ssid_len;
10355 params.freq.freq = wpa_s->sme.freq;
10356 if (wpa_s->last_assoc_req_wpa_ie) {
10357 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
10358 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
10359 }
10360 params.pairwise_suite = wpa_s->pairwise_cipher;
10361 params.group_suite = wpa_s->group_cipher;
10362 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
10363 params.key_mgmt_suite = wpa_s->key_mgmt;
10364 params.wpa_proto = wpa_s->wpa_proto;
10365 params.mgmt_frame_protection = wpa_s->sme.mfp;
10366 params.rrm_used = wpa_s->rrm.rrm_used;
10367 if (wpa_s->sme.prev_bssid_set)
10368 params.prev_bssid = wpa_s->sme.prev_bssid;
10369 wpa_printf(MSG_INFO, "TESTING: Resend association request");
10370 ret = wpa_drv_associate(wpa_s, &params);
10371 wpa_s->testing_resend_assoc = 1;
10372 return ret;
10373#else /* CONFIG_SME */
10374 return -1;
10375#endif /* CONFIG_SME */
10376}
10377
Hai Shaloma20dcd72022-02-04 13:43:00 -080010378
10379static int wpas_ctrl_iface_send_twt_setup(struct wpa_supplicant *wpa_s,
10380 const char *cmd)
10381{
10382 u8 dtok = 1;
10383 int exponent = 10;
10384 int mantissa = 8192;
10385 u8 min_twt = 255;
10386 unsigned long long twt = 0;
10387 bool requestor = true;
10388 int setup_cmd = 0;
10389 bool trigger = true;
10390 bool implicit = true;
10391 bool flow_type = true;
10392 int flow_id = 0;
10393 bool protection = false;
10394 u8 twt_channel = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -070010395 u8 control = BIT(4); /* Control field (IEEE Std 802.11ax-2021,
10396 * Figure 9-687 - Control field format):
10397 * B4 = TWT Information Frame Disabled */
Hai Shaloma20dcd72022-02-04 13:43:00 -080010398 const char *tok_s;
10399
10400 tok_s = os_strstr(cmd, " dialog=");
10401 if (tok_s)
10402 dtok = atoi(tok_s + os_strlen(" dialog="));
10403
10404 tok_s = os_strstr(cmd, " exponent=");
10405 if (tok_s)
10406 exponent = atoi(tok_s + os_strlen(" exponent="));
10407
10408 tok_s = os_strstr(cmd, " mantissa=");
10409 if (tok_s)
10410 mantissa = atoi(tok_s + os_strlen(" mantissa="));
10411
10412 tok_s = os_strstr(cmd, " min_twt=");
10413 if (tok_s)
10414 min_twt = atoi(tok_s + os_strlen(" min_twt="));
10415
10416 tok_s = os_strstr(cmd, " setup_cmd=");
10417 if (tok_s)
10418 setup_cmd = atoi(tok_s + os_strlen(" setup_cmd="));
10419
10420 tok_s = os_strstr(cmd, " twt=");
Sunil8cd6f4d2022-06-28 18:40:46 +000010421 if (tok_s &&
10422 sscanf(tok_s + os_strlen(" twt="), "%llu", &twt) != 1)
10423 return -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080010424
10425 tok_s = os_strstr(cmd, " requestor=");
10426 if (tok_s)
10427 requestor = atoi(tok_s + os_strlen(" requestor="));
10428
10429 tok_s = os_strstr(cmd, " trigger=");
10430 if (tok_s)
10431 trigger = atoi(tok_s + os_strlen(" trigger="));
10432
10433 tok_s = os_strstr(cmd, " implicit=");
10434 if (tok_s)
10435 implicit = atoi(tok_s + os_strlen(" implicit="));
10436
10437 tok_s = os_strstr(cmd, " flow_type=");
10438 if (tok_s)
10439 flow_type = atoi(tok_s + os_strlen(" flow_type="));
10440
10441 tok_s = os_strstr(cmd, " flow_id=");
10442 if (tok_s)
10443 flow_id = atoi(tok_s + os_strlen(" flow_id="));
10444
10445 tok_s = os_strstr(cmd, " protection=");
10446 if (tok_s)
10447 protection = atoi(tok_s + os_strlen(" protection="));
10448
10449 tok_s = os_strstr(cmd, " twt_channel=");
10450 if (tok_s)
10451 twt_channel = atoi(tok_s + os_strlen(" twt_channel="));
10452
10453 tok_s = os_strstr(cmd, " control=");
10454 if (tok_s)
10455 control = atoi(tok_s + os_strlen(" control="));
10456
10457 return wpas_twt_send_setup(wpa_s, dtok, exponent, mantissa, min_twt,
10458 setup_cmd, twt, requestor, trigger, implicit,
10459 flow_type, flow_id, protection, twt_channel,
10460 control);
10461}
10462
10463
10464static int wpas_ctrl_iface_send_twt_teardown(struct wpa_supplicant *wpa_s,
10465 const char *cmd)
10466{
10467 u8 flags = 0x1;
10468 const char *tok_s;
10469
10470 tok_s = os_strstr(cmd, " flags=");
10471 if (tok_s)
10472 flags = atoi(tok_s + os_strlen(" flags="));
10473
10474 return wpas_twt_send_teardown(wpa_s, flags);
10475}
10476
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010477#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010478
10479
10480static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
10481{
10482 char *pos = cmd;
10483 int frame;
10484 size_t len;
10485 struct wpabuf *buf;
10486 struct ieee802_11_elems elems;
10487
10488 frame = atoi(pos);
10489 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10490 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010491 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010492
10493 pos = os_strchr(pos, ' ');
10494 if (pos == NULL)
10495 return -1;
10496 pos++;
10497
10498 len = os_strlen(pos);
10499 if (len == 0)
10500 return 0;
10501 if (len & 1)
10502 return -1;
10503 len /= 2;
10504
10505 buf = wpabuf_alloc(len);
10506 if (buf == NULL)
10507 return -1;
10508
10509 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
10510 wpabuf_free(buf);
10511 return -1;
10512 }
10513
10514 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
10515 ParseFailed) {
10516 wpabuf_free(buf);
10517 return -1;
10518 }
10519
10520 if (wpa_s->vendor_elem[frame] == NULL) {
10521 wpa_s->vendor_elem[frame] = buf;
Hai Shalom60840252021-02-19 19:02:11 -080010522 goto update_ies;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010523 }
10524
10525 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
10526 wpabuf_free(buf);
10527 return -1;
10528 }
10529
10530 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
10531 wpabuf_free(buf);
Hai Shalom60840252021-02-19 19:02:11 -080010532
10533update_ies:
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010534 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010535
Hai Shalom60840252021-02-19 19:02:11 -080010536 if (frame == VENDOR_ELEM_PROBE_REQ ||
10537 frame == VENDOR_ELEM_PROBE_REQ_P2P)
10538 wpa_supplicant_set_default_scan_ies(wpa_s);
10539
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010540 return 0;
10541}
10542
10543
10544static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
10545 char *buf, size_t buflen)
10546{
10547 int frame = atoi(cmd);
10548
10549 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10550 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010551 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010552
10553 if (wpa_s->vendor_elem[frame] == NULL)
10554 return 0;
10555
10556 return wpa_snprintf_hex(buf, buflen,
10557 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
10558 wpabuf_len(wpa_s->vendor_elem[frame]));
10559}
10560
10561
10562static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
10563{
10564 char *pos = cmd;
10565 int frame;
10566 size_t len;
10567 u8 *buf;
10568 struct ieee802_11_elems elems;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010569 int res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010570
10571 frame = atoi(pos);
10572 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10573 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010574 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010575
10576 pos = os_strchr(pos, ' ');
10577 if (pos == NULL)
10578 return -1;
10579 pos++;
10580
10581 if (*pos == '*') {
10582 wpabuf_free(wpa_s->vendor_elem[frame]);
10583 wpa_s->vendor_elem[frame] = NULL;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010584 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010585 return 0;
10586 }
10587
10588 if (wpa_s->vendor_elem[frame] == NULL)
10589 return -1;
10590
10591 len = os_strlen(pos);
10592 if (len == 0)
10593 return 0;
10594 if (len & 1)
10595 return -1;
10596 len /= 2;
10597
10598 buf = os_malloc(len);
10599 if (buf == NULL)
10600 return -1;
10601
10602 if (hexstr2bin(pos, buf, len) < 0) {
10603 os_free(buf);
10604 return -1;
10605 }
10606
10607 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
10608 os_free(buf);
10609 return -1;
10610 }
10611
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010612 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010613 os_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010614 return res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010615}
10616
10617
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010618#ifndef CONFIG_NO_RRM
10619
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010620static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
10621{
10622 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010623 size_t len;
10624 const u8 *data;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010625
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010626 /*
10627 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
10628 * BSSID[6]
10629 * BSSID Information[4]
10630 * Operating Class[1]
10631 * Channel Number[1]
10632 * PHY Type[1]
10633 * Optional Subelements[variable]
10634 */
10635#define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
10636
10637 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010638 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010639 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010640 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010641
10642 data = wpabuf_head_u8(neighbor_rep);
10643 len = wpabuf_len(neighbor_rep);
10644
10645 while (len >= 2 + NR_IE_MIN_LEN) {
10646 const u8 *nr;
10647 char lci[256 * 2 + 1];
10648 char civic[256 * 2 + 1];
10649 u8 nr_len = data[1];
10650 const u8 *pos = data, *end;
10651
10652 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
10653 nr_len < NR_IE_MIN_LEN) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010654 wpa_dbg(wpa_s, MSG_DEBUG,
10655 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
10656 data[0], nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010657 goto out;
10658 }
10659
10660 if (2U + nr_len > len) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010661 wpa_dbg(wpa_s, MSG_DEBUG,
10662 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
10663 data[0], len, nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010664 goto out;
10665 }
10666 pos += 2;
10667 end = pos + nr_len;
10668
10669 nr = pos;
10670 pos += NR_IE_MIN_LEN;
10671
10672 lci[0] = '\0';
10673 civic[0] = '\0';
10674 while (end - pos > 2) {
10675 u8 s_id, s_len;
10676
10677 s_id = *pos++;
10678 s_len = *pos++;
10679 if (s_len > end - pos)
10680 goto out;
10681 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
10682 /* Measurement Token[1] */
10683 /* Measurement Report Mode[1] */
10684 /* Measurement Type[1] */
10685 /* Measurement Report[variable] */
10686 switch (pos[2]) {
10687 case MEASURE_TYPE_LCI:
10688 if (lci[0])
10689 break;
10690 wpa_snprintf_hex(lci, sizeof(lci),
10691 pos, s_len);
10692 break;
10693 case MEASURE_TYPE_LOCATION_CIVIC:
10694 if (civic[0])
10695 break;
10696 wpa_snprintf_hex(civic, sizeof(civic),
10697 pos, s_len);
10698 break;
10699 }
10700 }
10701
10702 pos += s_len;
10703 }
10704
10705 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
10706 "bssid=" MACSTR
10707 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
10708 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
10709 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
10710 nr[ETH_ALEN + 6],
10711 lci[0] ? " lci=" : "", lci,
10712 civic[0] ? " civic=" : "", civic);
10713
10714 data = end;
10715 len -= 2 + nr_len;
10716 }
10717
10718out:
10719 wpabuf_free(neighbor_rep);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010720}
10721
10722
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010723static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
10724 char *cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010725{
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010726 struct wpa_ssid_value ssid, *ssid_p = NULL;
10727 int ret, lci = 0, civic = 0;
10728 char *ssid_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010729
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010730 ssid_s = os_strstr(cmd, "ssid=");
10731 if (ssid_s) {
10732 if (ssid_parse(ssid_s + 5, &ssid)) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010733 wpa_msg(wpa_s, MSG_INFO,
10734 "CTRL: Send Neighbor Report: bad SSID");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010735 return -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010736 }
10737
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010738 ssid_p = &ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010739
10740 /*
10741 * Move cmd after the SSID text that may include "lci" or
10742 * "civic".
10743 */
10744 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
10745 if (cmd)
10746 cmd++;
10747
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010748 }
10749
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010750 if (cmd && os_strstr(cmd, "lci"))
10751 lci = 1;
10752
10753 if (cmd && os_strstr(cmd, "civic"))
10754 civic = 1;
10755
10756 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010757 wpas_ctrl_neighbor_rep_cb,
10758 wpa_s);
10759
10760 return ret;
10761}
10762
Sunil Ravib0ac25f2024-07-12 01:42:03 +000010763#endif /* CONFIG_NO_RRM */
10764
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010765
10766static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
10767{
10768 eapol_sm_erp_flush(wpa_s->eapol);
10769 return 0;
10770}
10771
10772
10773static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
10774 char *cmd)
10775{
10776 char *token, *context = NULL;
10777 unsigned int enable = ~0, type = 0;
10778 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
10779 u8 *addr = NULL, *mask = NULL;
10780
10781 while ((token = str_token(cmd, " ", &context))) {
10782 if (os_strcasecmp(token, "scan") == 0) {
10783 type |= MAC_ADDR_RAND_SCAN;
10784 } else if (os_strcasecmp(token, "sched") == 0) {
10785 type |= MAC_ADDR_RAND_SCHED_SCAN;
10786 } else if (os_strcasecmp(token, "pno") == 0) {
10787 type |= MAC_ADDR_RAND_PNO;
10788 } else if (os_strcasecmp(token, "all") == 0) {
10789 type = wpa_s->mac_addr_rand_supported;
10790 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
10791 enable = atoi(token + 7);
10792 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
10793 addr = _addr;
10794 if (hwaddr_aton(token + 5, addr)) {
10795 wpa_printf(MSG_INFO,
10796 "CTRL: Invalid MAC address: %s",
10797 token);
10798 return -1;
10799 }
10800 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
10801 mask = _mask;
10802 if (hwaddr_aton(token + 5, mask)) {
10803 wpa_printf(MSG_INFO,
10804 "CTRL: Invalid MAC address mask: %s",
10805 token);
10806 return -1;
10807 }
10808 } else {
10809 wpa_printf(MSG_INFO,
10810 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
10811 token);
10812 return -1;
10813 }
10814 }
10815
10816 if (!type) {
10817 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
10818 return -1;
10819 }
10820
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010821 if (enable > 1) {
10822 wpa_printf(MSG_INFO,
10823 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
10824 return -1;
10825 }
10826
Hai Shalom81f62d82019-07-22 12:10:00 -070010827 if (!enable)
10828 return wpas_disable_mac_addr_randomization(wpa_s, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010829
Hai Shalom81f62d82019-07-22 12:10:00 -070010830 return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010831}
10832
10833
Dmitry Shmidte4663042016-04-04 10:07:49 -070010834static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
10835 char *buf, size_t buflen)
10836{
10837 size_t reply_len;
10838
10839 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
10840#ifdef CONFIG_AP
10841 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
10842 buflen - reply_len);
10843#endif /* CONFIG_AP */
10844 return reply_len;
10845}
10846
10847
10848static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
10849{
Hai Shalom60840252021-02-19 19:02:11 -080010850 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
Dmitry Shmidte4663042016-04-04 10:07:49 -070010851 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
10852#ifdef CONFIG_AP
10853 wpas_ap_pmksa_cache_flush(wpa_s);
10854#endif /* CONFIG_AP */
10855}
10856
10857
Dmitry Shmidt29333592017-01-09 12:27:11 -080010858#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10859
10860static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
10861 const char *cmd, char *buf, size_t buflen)
10862{
10863 struct rsn_pmksa_cache_entry *entry;
10864 struct wpa_ssid *ssid;
10865 char *pos, *pos2, *end;
10866 int ret;
10867 struct os_reltime now;
10868
10869 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10870 if (!ssid)
10871 return -1;
10872
10873 pos = buf;
10874 end = buf + buflen;
10875
10876 os_get_reltime(&now);
10877
10878 /*
10879 * Entry format:
10880 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10881 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010882 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010883 */
10884
10885 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
10886 entry = entry->next) {
10887 if (entry->network_ctx != ssid)
10888 continue;
10889
10890 pos2 = pos;
10891 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
10892 MAC2STR(entry->aa));
10893 if (os_snprintf_error(end - pos2, ret))
10894 break;
10895 pos2 += ret;
10896
10897 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
10898 PMKID_LEN);
10899
10900 ret = os_snprintf(pos2, end - pos2, " ");
10901 if (os_snprintf_error(end - pos2, ret))
10902 break;
10903 pos2 += ret;
10904
10905 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
10906 entry->pmk_len);
10907
10908 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
10909 (int) (entry->reauth_time - now.sec),
10910 (int) (entry->expiration - now.sec),
10911 entry->akmp,
10912 entry->opportunistic);
10913 if (os_snprintf_error(end - pos2, ret))
10914 break;
10915 pos2 += ret;
10916
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010917 if (entry->fils_cache_id_set) {
10918 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
10919 entry->fils_cache_id[0],
10920 entry->fils_cache_id[1]);
10921 if (os_snprintf_error(end - pos2, ret))
10922 break;
10923 pos2 += ret;
10924 }
10925
Dmitry Shmidt29333592017-01-09 12:27:11 -080010926 ret = os_snprintf(pos2, end - pos2, "\n");
10927 if (os_snprintf_error(end - pos2, ret))
10928 break;
10929 pos2 += ret;
10930
10931 pos = pos2;
10932 }
10933
10934 return pos - buf;
10935}
10936
10937
10938static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
10939 char *cmd)
10940{
10941 struct rsn_pmksa_cache_entry *entry;
10942 struct wpa_ssid *ssid;
10943 char *pos, *pos2;
10944 int ret = -1;
10945 struct os_reltime now;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010946 int reauth_time = 0, expiration = 0, i;
Dmitry Shmidt29333592017-01-09 12:27:11 -080010947
10948 /*
10949 * Entry format:
10950 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10951 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010952 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010953 */
10954
10955 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10956 if (!ssid)
10957 return -1;
10958
10959 pos = os_strchr(cmd, ' ');
10960 if (!pos)
10961 return -1;
10962 pos++;
10963
10964 entry = os_zalloc(sizeof(*entry));
10965 if (!entry)
10966 return -1;
10967
10968 if (hwaddr_aton(pos, entry->aa))
10969 goto fail;
10970
10971 pos = os_strchr(pos, ' ');
10972 if (!pos)
10973 goto fail;
10974 pos++;
10975
10976 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
10977 goto fail;
10978
10979 pos = os_strchr(pos, ' ');
10980 if (!pos)
10981 goto fail;
10982 pos++;
10983
10984 pos2 = os_strchr(pos, ' ');
10985 if (!pos2)
10986 goto fail;
10987 entry->pmk_len = (pos2 - pos) / 2;
10988 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
10989 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
10990 goto fail;
10991
10992 pos = os_strchr(pos, ' ');
10993 if (!pos)
10994 goto fail;
10995 pos++;
10996
10997 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
10998 &entry->akmp, &entry->opportunistic) != 4)
10999 goto fail;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011000 if (reauth_time > expiration)
11001 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011002 for (i = 0; i < 4; i++) {
11003 pos = os_strchr(pos, ' ');
11004 if (!pos) {
11005 if (i < 3)
11006 goto fail;
11007 break;
11008 }
11009 pos++;
11010 }
11011 if (pos) {
11012 if (hexstr2bin(pos, entry->fils_cache_id,
11013 FILS_CACHE_ID_LEN) < 0)
11014 goto fail;
11015 entry->fils_cache_id_set = 1;
11016 }
Dmitry Shmidt29333592017-01-09 12:27:11 -080011017 os_get_reltime(&now);
11018 entry->expiration = now.sec + expiration;
11019 entry->reauth_time = now.sec + reauth_time;
11020
11021 entry->network_ctx = ssid;
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000011022 os_memcpy(entry->spa, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt29333592017-01-09 12:27:11 -080011023
Hai Shaloma20dcd72022-02-04 13:43:00 -080011024 entry->external = true;
11025
Dmitry Shmidt29333592017-01-09 12:27:11 -080011026 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
11027 entry = NULL;
11028 ret = 0;
11029fail:
11030 os_free(entry);
11031 return ret;
11032}
11033
Paul Stewart092955c2017-02-06 09:13:09 -080011034
11035#ifdef CONFIG_MESH
11036
11037static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
11038 const char *cmd, char *buf,
11039 size_t buflen)
11040{
11041 u8 spa[ETH_ALEN];
11042
11043 if (!wpa_s->ifmsh)
11044 return -1;
11045
11046 if (os_strcasecmp(cmd, "any") == 0)
11047 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
11048
11049 if (hwaddr_aton(cmd, spa))
11050 return -1;
11051
11052 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
11053}
11054
11055
11056static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
11057 char *cmd)
11058{
11059 /*
Hai Shalom60840252021-02-19 19:02:11 -080011060 * We do not check mesh interface existence because PMKSA should be
Paul Stewart092955c2017-02-06 09:13:09 -080011061 * stored before wpa_s->ifmsh creation to suppress commit message
11062 * creation.
11063 */
11064 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
11065}
11066
11067#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080011068#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
11069
11070
Paul Stewart092955c2017-02-06 09:13:09 -080011071#ifdef CONFIG_FILS
11072static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
11073 const char *cmd)
11074{
11075 struct fils_hlp_req *req;
11076 const char *pos;
11077
11078 /* format: <dst> <packet starting from ethertype> */
11079
11080 req = os_zalloc(sizeof(*req));
11081 if (!req)
11082 return -1;
11083
11084 if (hwaddr_aton(cmd, req->dst))
11085 goto fail;
11086
11087 pos = os_strchr(cmd, ' ');
11088 if (!pos)
11089 goto fail;
11090 pos++;
11091 req->pkt = wpabuf_parse_bin(pos);
11092 if (!req->pkt)
11093 goto fail;
11094
11095 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
11096 return 0;
11097fail:
11098 wpabuf_free(req->pkt);
11099 os_free(req);
11100 return -1;
11101}
11102#endif /* CONFIG_FILS */
11103
11104
Sunil Ravia04bd252022-05-02 22:54:18 -070011105int wpas_ctrl_cmd_debug_level(const char *cmd)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011106{
11107 if (os_strcmp(cmd, "PING") == 0 ||
11108 os_strncmp(cmd, "BSS ", 4) == 0 ||
11109 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
11110 os_strncmp(cmd, "STATUS", 6) == 0 ||
11111 os_strncmp(cmd, "STA ", 4) == 0 ||
11112 os_strncmp(cmd, "STA-", 4) == 0)
11113 return MSG_EXCESSIVE;
11114 return MSG_DEBUG;
11115}
11116
11117
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011118#ifndef CONFIG_NO_ROBUST_AV
Hai Shalom899fcc72020-10-19 14:38:18 -070011119static int wpas_ctrl_iface_configure_mscs(struct wpa_supplicant *wpa_s,
11120 const char *cmd)
11121{
11122 size_t frame_classifier_len;
11123 const char *pos, *end;
11124 struct robust_av_data *robust_av = &wpa_s->robust_av;
11125 int val;
11126
11127 /*
11128 * format:
11129 * <add|remove|change> [up_bitmap=<hex byte>] [up_limit=<integer>]
11130 * [stream_timeout=<in TUs>] [frame_classifier=<hex bytes>]
11131 */
11132 os_memset(robust_av, 0, sizeof(struct robust_av_data));
11133 if (os_strncmp(cmd, "add ", 4) == 0) {
11134 robust_av->request_type = SCS_REQ_ADD;
11135 } else if (os_strcmp(cmd, "remove") == 0) {
11136 robust_av->request_type = SCS_REQ_REMOVE;
11137 robust_av->valid_config = false;
11138 return wpas_send_mscs_req(wpa_s);
11139 } else if (os_strncmp(cmd, "change ", 7) == 0) {
11140 robust_av->request_type = SCS_REQ_CHANGE;
11141 } else {
11142 return -1;
11143 }
11144
11145 pos = os_strstr(cmd, "up_bitmap=");
11146 if (!pos)
11147 return -1;
11148
11149 val = hex2byte(pos + 10);
11150 if (val < 0)
11151 return -1;
11152 robust_av->up_bitmap = val;
11153
11154 pos = os_strstr(cmd, "up_limit=");
11155 if (!pos)
11156 return -1;
11157
11158 robust_av->up_limit = atoi(pos + 9);
11159
11160 pos = os_strstr(cmd, "stream_timeout=");
11161 if (!pos)
11162 return -1;
11163
11164 robust_av->stream_timeout = atoi(pos + 15);
11165 if (robust_av->stream_timeout == 0)
11166 return -1;
11167
11168 pos = os_strstr(cmd, "frame_classifier=");
11169 if (!pos)
11170 return -1;
11171
11172 pos += 17;
11173 end = os_strchr(pos, ' ');
11174 if (!end)
11175 end = pos + os_strlen(pos);
11176
11177 frame_classifier_len = (end - pos) / 2;
11178 if (frame_classifier_len > sizeof(robust_av->frame_classifier) ||
11179 hexstr2bin(pos, robust_av->frame_classifier, frame_classifier_len))
11180 return -1;
11181
11182 robust_av->frame_classifier_len = frame_classifier_len;
11183 robust_av->valid_config = true;
11184
11185 return wpas_send_mscs_req(wpa_s);
11186}
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011187#endif /* CONFIG_NO_ROBUST_AV */
Hai Shalom899fcc72020-10-19 14:38:18 -070011188
11189
Hai Shalom60840252021-02-19 19:02:11 -080011190#ifdef CONFIG_PASN
11191static int wpas_ctrl_iface_pasn_start(struct wpa_supplicant *wpa_s, char *cmd)
11192{
11193 char *token, *context = NULL;
11194 u8 bssid[ETH_ALEN];
11195 int akmp = -1, cipher = -1, got_bssid = 0;
11196 u16 group = 0xFFFF;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011197 u8 *comeback = NULL;
11198 size_t comeback_len = 0;
11199 int id = 0, ret = -1;
Hai Shalom60840252021-02-19 19:02:11 -080011200
11201 /*
11202 * Entry format: bssid=<BSSID> akmp=<AKMP> cipher=<CIPHER> group=<group>
Hai Shaloma20dcd72022-02-04 13:43:00 -080011203 * [comeback=<hexdump>]
Hai Shalom60840252021-02-19 19:02:11 -080011204 */
11205 while ((token = str_token(cmd, " ", &context))) {
11206 if (os_strncmp(token, "bssid=", 6) == 0) {
11207 if (hwaddr_aton(token + 6, bssid))
Hai Shaloma20dcd72022-02-04 13:43:00 -080011208 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080011209 got_bssid = 1;
11210 } else if (os_strcmp(token, "akmp=PASN") == 0) {
11211 akmp = WPA_KEY_MGMT_PASN;
11212#ifdef CONFIG_IEEE80211R
11213 } else if (os_strcmp(token, "akmp=FT-PSK") == 0) {
11214 akmp = WPA_KEY_MGMT_FT_PSK;
11215 } else if (os_strcmp(token, "akmp=FT-EAP-SHA384") == 0) {
11216 akmp = WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
11217 } else if (os_strcmp(token, "akmp=FT-EAP") == 0) {
11218 akmp = WPA_KEY_MGMT_FT_IEEE8021X;
11219#endif /* CONFIG_IEEE80211R */
11220#ifdef CONFIG_SAE
11221 } else if (os_strcmp(token, "akmp=SAE") == 0) {
11222 akmp = WPA_KEY_MGMT_SAE;
Sunil Ravi89eba102022-09-13 21:04:37 -070011223 } else if (os_strcmp(token, "akmp=SAE-EXT-KEY") == 0) {
11224 akmp = WPA_KEY_MGMT_SAE_EXT_KEY;
Hai Shalom60840252021-02-19 19:02:11 -080011225#endif /* CONFIG_SAE */
11226#ifdef CONFIG_FILS
11227 } else if (os_strcmp(token, "akmp=FILS-SHA256") == 0) {
11228 akmp = WPA_KEY_MGMT_FILS_SHA256;
11229 } else if (os_strcmp(token, "akmp=FILS-SHA384") == 0) {
11230 akmp = WPA_KEY_MGMT_FILS_SHA384;
11231#endif /* CONFIG_FILS */
11232 } else if (os_strcmp(token, "cipher=CCMP-256") == 0) {
11233 cipher = WPA_CIPHER_CCMP_256;
11234 } else if (os_strcmp(token, "cipher=GCMP-256") == 0) {
11235 cipher = WPA_CIPHER_GCMP_256;
11236 } else if (os_strcmp(token, "cipher=CCMP") == 0) {
11237 cipher = WPA_CIPHER_CCMP;
11238 } else if (os_strcmp(token, "cipher=GCMP") == 0) {
11239 cipher = WPA_CIPHER_GCMP;
11240 } else if (os_strncmp(token, "group=", 6) == 0) {
11241 group = atoi(token + 6);
11242 } else if (os_strncmp(token, "nid=", 4) == 0) {
11243 id = atoi(token + 4);
Hai Shaloma20dcd72022-02-04 13:43:00 -080011244 } else if (os_strncmp(token, "comeback=", 9) == 0) {
11245 comeback_len = os_strlen(token + 9);
11246 if (comeback || !comeback_len || comeback_len % 2)
11247 goto out;
11248
11249 comeback_len /= 2;
11250 comeback = os_malloc(comeback_len);
11251 if (!comeback ||
11252 hexstr2bin(token + 9, comeback, comeback_len))
11253 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080011254 } else {
11255 wpa_printf(MSG_DEBUG,
11256 "CTRL: PASN Invalid parameter: '%s'",
11257 token);
Hai Shaloma20dcd72022-02-04 13:43:00 -080011258 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080011259 }
11260 }
11261
11262 if (!got_bssid || akmp == -1 || cipher == -1 || group == 0xFFFF) {
11263 wpa_printf(MSG_DEBUG,"CTRL: PASN missing parameter");
Hai Shaloma20dcd72022-02-04 13:43:00 -080011264 goto out;
11265 }
11266
Sunil Ravi89eba102022-09-13 21:04:37 -070011267 ret = wpas_pasn_auth_start(wpa_s, wpa_s->own_addr, bssid, akmp, cipher,
11268 group, id, comeback, comeback_len);
Hai Shaloma20dcd72022-02-04 13:43:00 -080011269out:
11270 os_free(comeback);
11271 return ret;
11272}
11273
11274
11275static int wpas_ctrl_iface_pasn_deauthenticate(struct wpa_supplicant *wpa_s,
11276 const char *cmd)
11277{
11278 u8 bssid[ETH_ALEN];
11279
11280 if (os_strncmp(cmd, "bssid=", 6) != 0 || hwaddr_aton(cmd + 6, bssid)) {
11281 wpa_printf(MSG_DEBUG,
11282 "CTRL: PASN_DEAUTH without valid BSSID");
Hai Shalom60840252021-02-19 19:02:11 -080011283 return -1;
11284 }
11285
Sunil Ravi89eba102022-09-13 21:04:37 -070011286 return wpas_pasn_deauthenticate(wpa_s, wpa_s->own_addr, bssid);
Hai Shalom60840252021-02-19 19:02:11 -080011287}
Hai Shaloma20dcd72022-02-04 13:43:00 -080011288
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011289
11290#ifdef CONFIG_TESTING_OPTIONS
11291static int wpas_ctrl_iface_pasn_driver(struct wpa_supplicant *wpa_s,
11292 const char *cmd)
11293{
11294 union wpa_event_data event;
11295 const char *pos = cmd;
11296 u8 addr[ETH_ALEN];
11297
11298 os_memset(&event, 0, sizeof(event));
11299
11300 if (os_strncmp(pos, "auth ", 5) == 0)
11301 event.pasn_auth.action = PASN_ACTION_AUTH;
11302 else if (os_strncmp(pos, "del ", 4) == 0)
11303 event.pasn_auth.action =
11304 PASN_ACTION_DELETE_SECURE_RANGING_CONTEXT;
11305 else
11306 return -1;
11307
11308 pos = os_strchr(pos, ' ');
11309 if (!pos)
11310 return -1;
11311 pos++;
11312 while (hwaddr_aton(pos, addr) == 0) {
11313 struct pasn_peer *peer;
11314
11315 if (event.pasn_auth.num_peers == WPAS_MAX_PASN_PEERS)
11316 return -1;
11317 peer = &event.pasn_auth.peer[event.pasn_auth.num_peers];
11318 os_memcpy(peer->own_addr, wpa_s->own_addr, ETH_ALEN);
11319 os_memcpy(peer->peer_addr, addr, ETH_ALEN);
11320 event.pasn_auth.num_peers++;
11321
11322 pos = os_strchr(pos, ' ');
11323 if (!pos)
11324 break;
11325 pos++;
11326 }
11327
11328 wpa_supplicant_event(wpa_s, EVENT_PASN_AUTH, &event);
11329 return 0;
11330}
11331#endif /* CONFIG_TESTING_OPTIONS */
11332
Hai Shalom60840252021-02-19 19:02:11 -080011333#endif /* CONFIG_PASN */
11334
11335
Sunil Ravib0ac25f2024-07-12 01:42:03 +000011336#ifndef CONFIG_NO_ROBUST_AV
11337
Hai Shaloma20dcd72022-02-04 13:43:00 -080011338static int set_type4_frame_classifier(const char *cmd,
11339 struct type4_params *param)
11340{
11341 const char *pos, *end;
11342 u8 classifier_mask = 0;
11343 int ret;
11344 char addr[INET6_ADDRSTRLEN];
11345 size_t alen;
11346
11347 if (os_strstr(cmd, "ip_version=ipv4")) {
11348 param->ip_version = IPV4;
11349 } else if (os_strstr(cmd, "ip_version=ipv6")) {
11350 param->ip_version = IPV6;
11351 } else {
11352 wpa_printf(MSG_ERROR, "IP version missing/invalid");
11353 return -1;
11354 }
11355
11356 classifier_mask |= BIT(0);
11357
11358 pos = os_strstr(cmd, "src_ip=");
11359 if (pos) {
11360 pos += 7;
11361 end = os_strchr(pos, ' ');
11362 if (!end)
11363 end = pos + os_strlen(pos);
11364
11365 alen = end - pos;
11366 if (alen >= INET6_ADDRSTRLEN)
11367 return -1;
11368 os_memcpy(addr, pos, alen);
11369 addr[alen] = '\0';
11370 if (param->ip_version == IPV4)
11371 ret = inet_pton(AF_INET, addr,
11372 &param->ip_params.v4.src_ip);
11373 else
11374 ret = inet_pton(AF_INET6, addr,
11375 &param->ip_params.v6.src_ip);
11376
11377 if (ret != 1) {
11378 wpa_printf(MSG_ERROR,
11379 "Error converting src IP address to binary ret=%d",
11380 ret);
11381 return -1;
11382 }
11383
11384 classifier_mask |= BIT(1);
11385 }
11386
11387 pos = os_strstr(cmd, "dst_ip=");
11388 if (pos) {
11389 pos += 7;
11390 end = os_strchr(pos, ' ');
11391 if (!end)
11392 end = pos + os_strlen(pos);
11393
11394 alen = end - pos;
11395 if (alen >= INET6_ADDRSTRLEN)
11396 return -1;
11397 os_memcpy(addr, pos, alen);
11398 addr[alen] = '\0';
11399 if (param->ip_version == IPV4)
11400 ret = inet_pton(AF_INET, addr,
11401 &param->ip_params.v4.dst_ip);
11402 else
11403 ret = inet_pton(AF_INET6, addr,
11404 &param->ip_params.v6.dst_ip);
11405
11406 if (ret != 1) {
11407 wpa_printf(MSG_ERROR,
11408 "Error converting dst IP address to binary ret=%d",
11409 ret);
11410 return -1;
11411 }
11412
11413 classifier_mask |= BIT(2);
11414 }
11415
11416 pos = os_strstr(cmd, "src_port=");
11417 if (pos && atoi(pos + 9) > 0) {
11418 if (param->ip_version == IPV4)
11419 param->ip_params.v4.src_port = atoi(pos + 9);
11420 else
11421 param->ip_params.v6.src_port = atoi(pos + 9);
11422 classifier_mask |= BIT(3);
11423 }
11424
11425 pos = os_strstr(cmd, "dst_port=");
11426 if (pos && atoi(pos + 9) > 0) {
11427 if (param->ip_version == IPV4)
11428 param->ip_params.v4.dst_port = atoi(pos + 9);
11429 else
11430 param->ip_params.v6.dst_port = atoi(pos + 9);
11431 classifier_mask |= BIT(4);
11432 }
11433
11434 pos = os_strstr(cmd, "dscp=");
11435 if (pos && atoi(pos + 5) > 0) {
11436 if (param->ip_version == IPV4)
11437 param->ip_params.v4.dscp = atoi(pos + 5);
11438 else
11439 param->ip_params.v6.dscp = atoi(pos + 5);
11440 classifier_mask |= BIT(5);
11441 }
11442
11443 if (param->ip_version == IPV4) {
11444 pos = os_strstr(cmd, "protocol=");
11445 if (pos) {
11446 if (os_strstr(pos, "udp")) {
11447 param->ip_params.v4.protocol = 17;
11448 } else if (os_strstr(pos, "tcp")) {
11449 param->ip_params.v4.protocol = 6;
11450 } else if (os_strstr(pos, "esp")) {
11451 param->ip_params.v4.protocol = 50;
11452 } else {
11453 wpa_printf(MSG_ERROR, "Invalid protocol");
11454 return -1;
11455 }
11456 classifier_mask |= BIT(6);
11457 }
11458 } else {
11459 pos = os_strstr(cmd, "next_header=");
11460 if (pos) {
11461 if (os_strstr(pos, "udp")) {
11462 param->ip_params.v6.next_header = 17;
11463 } else if (os_strstr(pos, "tcp")) {
11464 param->ip_params.v6.next_header = 6;
11465 } else if (os_strstr(pos, "esp")) {
11466 param->ip_params.v6.next_header = 50;
11467 } else {
11468 wpa_printf(MSG_ERROR, "Invalid next header");
11469 return -1;
11470 }
11471
11472 classifier_mask |= BIT(6);
11473 }
11474
11475 pos = os_strstr(cmd, "flow_label=");
11476 if (pos) {
11477 pos += 11;
11478 end = os_strchr(pos, ' ');
11479 if (!end)
11480 end = pos + os_strlen(pos);
11481
11482 if (end - pos != 6 ||
11483 hexstr2bin(pos, param->ip_params.v6.flow_label,
11484 3) ||
11485 param->ip_params.v6.flow_label[0] > 0x0F) {
11486 wpa_printf(MSG_ERROR, "Invalid flow label");
11487 return -1;
11488 }
11489
11490 classifier_mask |= BIT(7);
11491 }
11492 }
11493
11494 param->classifier_mask = classifier_mask;
11495 return 0;
11496}
11497
11498
11499static int set_type10_frame_classifier(const char *cmd,
11500 struct type10_params *param)
11501{
11502 const char *pos, *end;
11503 size_t filter_len;
11504
11505 pos = os_strstr(cmd, "prot_instance=");
11506 if (!pos) {
11507 wpa_printf(MSG_ERROR, "Protocol instance missing");
11508 return -1;
11509 }
11510 param->prot_instance = atoi(pos + 14);
11511
11512 pos = os_strstr(cmd, "prot_number=");
11513 if (!pos) {
11514 wpa_printf(MSG_ERROR, "Protocol number missing");
11515 return -1;
11516 }
11517 if (os_strstr(pos, "udp")) {
11518 param->prot_number = 17;
11519 } else if (os_strstr(pos, "tcp")) {
11520 param->prot_number = 6;
11521 } else if (os_strstr(pos, "esp")) {
11522 param->prot_number = 50;
11523 } else {
11524 wpa_printf(MSG_ERROR, "Invalid protocol number");
11525 return -1;
11526 }
11527
11528 pos = os_strstr(cmd, "filter_value=");
11529 if (!pos) {
11530 wpa_printf(MSG_ERROR,
11531 "Classifier parameter filter_value missing");
11532 return -1;
11533 }
11534
11535 pos += 13;
11536 end = os_strchr(pos, ' ');
11537 if (!end)
11538 end = pos + os_strlen(pos);
11539
11540 filter_len = (end - pos) / 2;
11541 param->filter_value = os_malloc(filter_len);
11542 if (!param->filter_value)
11543 return -1;
11544
11545 if (hexstr2bin(pos, param->filter_value, filter_len)) {
11546 wpa_printf(MSG_ERROR, "Invalid filter_value %s", pos);
11547 goto free;
11548 }
11549
11550 pos = os_strstr(cmd, "filter_mask=");
11551 if (!pos) {
11552 wpa_printf(MSG_ERROR,
11553 "Classifier parameter filter_mask missing");
11554 goto free;
11555 }
11556
11557 pos += 12;
11558 end = os_strchr(pos, ' ');
11559 if (!end)
11560 end = pos + os_strlen(pos);
11561
11562 if (filter_len != (size_t) (end - pos) / 2) {
11563 wpa_printf(MSG_ERROR,
11564 "Filter mask length mismatch expected=%zu received=%zu",
11565 filter_len, (size_t) (end - pos) / 2);
11566 goto free;
11567 }
11568
11569 param->filter_mask = os_malloc(filter_len);
11570 if (!param->filter_mask)
11571 goto free;
11572
11573 if (hexstr2bin(pos, param->filter_mask, filter_len)) {
11574 wpa_printf(MSG_ERROR, "Invalid filter mask %s", pos);
11575 os_free(param->filter_mask);
11576 param->filter_mask = NULL;
11577 goto free;
11578 }
11579
11580 param->filter_len = filter_len;
11581 return 0;
11582free:
11583 os_free(param->filter_value);
11584 param->filter_value = NULL;
11585 return -1;
11586}
11587
11588
11589static int scs_parse_type4(struct tclas_element *elem, const char *pos)
11590{
11591 struct type4_params type4_param = { 0 };
11592
11593 if (set_type4_frame_classifier(pos, &type4_param) == -1) {
11594 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 4");
11595 return -1;
11596 }
11597
11598 os_memcpy(&elem->frame_classifier.type4_param,
11599 &type4_param, sizeof(struct type4_params));
11600 return 0;
11601}
11602
11603
11604static int scs_parse_type10(struct tclas_element *elem, const char *pos)
11605{
11606 struct type10_params type10_param = { 0 };
11607
11608 if (set_type10_frame_classifier(pos, &type10_param) == -1) {
11609 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 10");
11610 return -1;
11611 }
11612
11613 os_memcpy(&elem->frame_classifier.type10_param,
11614 &type10_param, sizeof(struct type10_params));
11615 return 0;
11616}
11617
11618
11619static int wpas_ctrl_iface_configure_scs(struct wpa_supplicant *wpa_s,
11620 char *cmd)
11621{
11622 char *pos1, *pos;
11623 struct scs_robust_av_data *scs_data = &wpa_s->scs_robust_av_req;
11624 struct scs_desc_elem desc_elem = { 0 };
11625 int val;
11626 unsigned int num_scs_desc = 0;
11627
11628 if (wpa_s->ongoing_scs_req) {
11629 wpa_printf(MSG_ERROR, "%s: SCS Request already in queue",
11630 __func__);
11631 return -1;
11632 }
11633
11634 /**
11635 * format:
11636 * [scs_id=<decimal number>] <add|remove|change> [scs_up=<0-7>]
11637 * [classifier_type=<4|10>]
11638 * [classifier params based on classifier type]
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011639 * [tclas_processing=<0|1>]
11640 * [qos_characteristics] <up/down/direct> [min_si=<decimal number>]
11641 * [max_si=<decimal number>] [min_data_rate=<decimal number>]
11642 * [delay_bound=<decimal number>] [max_msdu=<decimal number>]
11643 * [service_start_time=<decimal number>]
11644 * [service_start_time_link_id=<decimal number>]
11645 * [mean_data_rate=<decimal number>] [burst_size=<decimal number>]
11646 * [msdu_lifetime=<decimal number>]
11647 * [msdu_delivery_info=<decimal number>] [medium_time=<decimal number>]
11648 * [scs_id=<decimal number>] ...
Hai Shaloma20dcd72022-02-04 13:43:00 -080011649 */
11650 pos1 = os_strstr(cmd, "scs_id=");
11651 if (!pos1) {
11652 wpa_printf(MSG_ERROR, "SCSID not present");
11653 return -1;
11654 }
11655
11656 free_up_scs_desc(scs_data);
11657
11658 while (pos1) {
11659 struct scs_desc_elem *n1;
11660 struct active_scs_elem *active_scs_desc;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011661 char *next_scs_desc, *pos2;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011662 unsigned int num_tclas_elem = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011663 bool scsid_active = false, tclas_present = false;
11664 struct qos_characteristics *qos_elem = &desc_elem.qos_char_elem;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011665
11666 desc_elem.scs_id = atoi(pos1 + 7);
11667 pos1 += 7;
11668
11669 next_scs_desc = os_strstr(pos1, "scs_id=");
11670 if (next_scs_desc) {
11671 char temp[20];
11672
11673 os_snprintf(temp, sizeof(temp), "scs_id=%d ",
11674 desc_elem.scs_id);
11675 if (os_strstr(next_scs_desc, temp)) {
11676 wpa_printf(MSG_ERROR,
11677 "Multiple SCS descriptors configured with same SCSID(=%d)",
11678 desc_elem.scs_id);
11679 goto free_scs_desc;
11680 }
11681 pos1[next_scs_desc - pos1 - 1] = '\0';
11682 }
11683
11684 dl_list_for_each(active_scs_desc, &wpa_s->active_scs_ids,
11685 struct active_scs_elem, list) {
11686 if (desc_elem.scs_id == active_scs_desc->scs_id) {
11687 scsid_active = true;
11688 break;
11689 }
11690 }
11691
11692 if (os_strstr(pos1, "add ")) {
11693 desc_elem.request_type = SCS_REQ_ADD;
11694 if (scsid_active) {
11695 wpa_printf(MSG_ERROR, "SCSID %d already active",
11696 desc_elem.scs_id);
11697 return -1;
11698 }
11699 } else if (os_strstr(pos1, "remove")) {
11700 desc_elem.request_type = SCS_REQ_REMOVE;
11701 if (!scsid_active) {
11702 wpa_printf(MSG_ERROR, "SCSID %d not active",
11703 desc_elem.scs_id);
11704 return -1;
11705 }
11706 goto scs_desc_end;
11707 } else if (os_strstr(pos1, "change ")) {
11708 desc_elem.request_type = SCS_REQ_CHANGE;
11709 if (!scsid_active) {
11710 wpa_printf(MSG_ERROR, "SCSID %d not active",
11711 desc_elem.scs_id);
11712 return -1;
11713 }
11714 } else {
11715 wpa_printf(MSG_ERROR, "SCS Request type invalid");
11716 goto free_scs_desc;
11717 }
11718
11719 pos1 = os_strstr(pos1, "scs_up=");
11720 if (!pos1) {
11721 wpa_printf(MSG_ERROR,
11722 "Intra-Access user priority not present");
11723 goto free_scs_desc;
11724 }
11725
11726 val = atoi(pos1 + 7);
11727 if (val < 0 || val > 7) {
11728 wpa_printf(MSG_ERROR,
11729 "Intra-Access user priority invalid %d",
11730 val);
11731 goto free_scs_desc;
11732 }
11733
11734 desc_elem.intra_access_priority = val;
11735 desc_elem.scs_up_avail = true;
11736
11737 pos = os_strstr(pos1, "classifier_type=");
11738 if (!pos) {
11739 wpa_printf(MSG_ERROR, "classifier type empty");
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011740 goto qos_characteristics;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011741 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011742 tclas_present = true;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011743
11744 while (pos) {
11745 struct tclas_element elem = { 0 }, *n;
11746 char *next_tclas_elem;
11747
11748 val = atoi(pos + 16);
11749 if (val != 4 && val != 10) {
11750 wpa_printf(MSG_ERROR,
11751 "classifier type invalid %d", val);
11752 goto free_scs_desc;
11753 }
11754
11755 elem.classifier_type = val;
11756 pos += 16;
11757
11758 next_tclas_elem = os_strstr(pos, "classifier_type=");
11759 if (next_tclas_elem) {
11760 pos1 = next_tclas_elem;
11761 pos[next_tclas_elem - pos - 1] = '\0';
11762 }
11763
11764 switch (val) {
11765 case 4:
11766 if (scs_parse_type4(&elem, pos) < 0)
11767 goto free_scs_desc;
11768 break;
11769 case 10:
11770 if (scs_parse_type10(&elem, pos) < 0)
11771 goto free_scs_desc;
11772 break;
11773 }
11774
11775 n = os_realloc(desc_elem.tclas_elems,
11776 (num_tclas_elem + 1) * sizeof(elem));
11777 if (!n)
11778 goto free_scs_desc;
11779
11780 desc_elem.tclas_elems = n;
11781 os_memcpy((u8 *) desc_elem.tclas_elems +
11782 num_tclas_elem * sizeof(elem),
11783 &elem, sizeof(elem));
11784 num_tclas_elem++;
11785 desc_elem.num_tclas_elem = num_tclas_elem;
11786 pos = next_tclas_elem;
11787 }
11788
11789 if (desc_elem.num_tclas_elem > 1) {
11790 pos1 = os_strstr(pos1, "tclas_processing=");
11791 if (!pos1) {
11792 wpa_printf(MSG_ERROR, "tclas_processing empty");
11793 goto free_scs_desc;
11794 }
11795
11796 val = atoi(pos1 + 17);
11797 if (val != 0 && val != 1) {
11798 wpa_printf(MSG_ERROR,
11799 "tclas_processing invalid");
11800 goto free_scs_desc;
11801 }
11802
11803 desc_elem.tclas_processing = val;
11804 }
11805
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011806 qos_characteristics:
11807 pos1 = os_strstr(pos1, "qos_characteristics");
11808 if (!pos1 && !tclas_present)
11809 goto free_scs_desc;
11810 if (!pos1)
11811 goto scs_desc_end;
11812
11813 qos_elem->available = true;
11814 if (os_strstr(pos1, "up ")) {
11815 qos_elem->direction = SCS_DIRECTION_UP;
11816 if (tclas_present) {
11817 wpa_printf(MSG_ERROR,
11818 "TCLAS with direction:UP not allowed");
11819 goto free_scs_desc;
11820 }
11821 } else if (os_strstr(pos1, "down ")) {
11822 qos_elem->direction = SCS_DIRECTION_DOWN;
11823 } else if (os_strstr(pos1, "direct ")) {
11824 qos_elem->direction = SCS_DIRECTION_DIRECT;
11825 }
11826
11827 pos1 = os_strstr(pos1, "min_si=");
11828 if (!pos1) {
11829 wpa_printf(MSG_ERROR, "Min SI is required");
11830 goto free_scs_desc;
11831 }
11832 qos_elem->min_si = atoi(pos1 + 7);
11833
11834 pos1 = os_strstr(pos1, "max_si=");
11835 if (!pos1) {
11836 wpa_printf(MSG_ERROR, "Max SI is required");
11837 goto free_scs_desc;
11838 }
11839 qos_elem->max_si = atoi(pos1 + 7);
11840
11841 if (qos_elem->min_si && qos_elem->max_si &&
11842 qos_elem->max_si < qos_elem->min_si) {
11843 wpa_printf(MSG_ERROR, "Invalid Max SI");
11844 goto free_scs_desc;
11845 }
11846
11847 pos1 = os_strstr(pos1, "min_data_rate=");
11848 if (!pos1) {
11849 wpa_printf(MSG_ERROR, "Min data rate is required");
11850 goto free_scs_desc;
11851 }
11852 qos_elem->min_data_rate = atoi(pos1 + 14);
11853
11854 pos1 = os_strstr(pos1, "delay_bound=");
11855 if (!pos1) {
11856 wpa_printf(MSG_ERROR, "Delay Bound is required");
11857 goto free_scs_desc;
11858 }
11859 qos_elem->delay_bound = atoi(pos1 + 12);
11860
11861 if (qos_elem->min_data_rate >= BIT(24) ||
11862 qos_elem->delay_bound >= BIT(24)) {
11863 wpa_printf(MSG_ERROR,
11864 "Invalid min_data_rate or delay_bound");
11865 goto free_scs_desc;
11866 }
11867
11868 pos2 = os_strstr(pos1, "max_msdu=");
11869 if (pos2) {
11870 qos_elem->max_msdu_size = atoi(pos2 + 9);
11871 qos_elem->mask |= SCS_QOS_BIT_MAX_MSDU_SIZE;
11872 }
11873
11874 pos2 = os_strstr(pos1, "service_start_time=");
11875 if (pos2) {
11876 qos_elem->service_start_time = atoi(pos2 + 19);
11877 qos_elem->mask |= SCS_QOS_BIT_SERVICE_START_TIME;
11878 }
11879
11880 pos2 = os_strstr(pos1, "service_start_time_link_id=");
11881 if (pos2) {
11882 qos_elem->service_start_time_link_id = atoi(pos2 + 27);
11883 qos_elem->mask |= SCS_QOS_BIT_SERVICE_START_TIME_LINKID;
11884 }
11885
11886 pos2 = os_strstr(pos1, "mean_data_rate=");
11887 if (pos2) {
11888 qos_elem->mean_data_rate = atoi(pos2 + 15);
11889 qos_elem->mask |= SCS_QOS_BIT_MEAN_DATA_RATE;
11890 }
11891
11892 pos2 = os_strstr(pos1, "burst_size=");
11893 if (pos2) {
11894 qos_elem->burst_size = atoi(pos2 + 11);
11895 qos_elem->mask |=
11896 SCS_QOS_BIT_DELAYED_BOUNDED_BURST_SIZE;
11897 }
11898
11899 pos2 = os_strstr(pos1, "msdu_lifetime=");
11900 if (pos2) {
11901 qos_elem->msdu_lifetime = atoi(pos2 + 14);
11902 qos_elem->mask |= SCS_QOS_BIT_MSDU_LIFETIME;
11903 }
11904
11905 pos2 = os_strstr(pos1, "msdu_delivery_info=");
11906 if (pos2) {
11907 qos_elem->msdu_delivery_info = atoi(pos2 + 19);
11908 qos_elem->mask |= SCS_QOS_BIT_MSDU_DELIVERY_INFO;
11909 }
11910
11911 pos2 = os_strstr(pos1, "medium_time=");
11912 if (pos2) {
11913 qos_elem->medium_time = atoi(pos2 + 12);
11914 qos_elem->mask |= SCS_QOS_BIT_MEDIUM_TIME;
11915 }
11916
Hai Shaloma20dcd72022-02-04 13:43:00 -080011917scs_desc_end:
11918 n1 = os_realloc(scs_data->scs_desc_elems, (num_scs_desc + 1) *
11919 sizeof(struct scs_desc_elem));
11920 if (!n1)
11921 goto free_scs_desc;
11922
11923 scs_data->scs_desc_elems = n1;
11924 os_memcpy((u8 *) scs_data->scs_desc_elems + num_scs_desc *
11925 sizeof(desc_elem), &desc_elem, sizeof(desc_elem));
11926 num_scs_desc++;
11927 scs_data->num_scs_desc = num_scs_desc;
11928 pos1 = next_scs_desc;
11929 os_memset(&desc_elem, 0, sizeof(desc_elem));
11930 }
11931
11932 return wpas_send_scs_req(wpa_s);
11933
11934free_scs_desc:
11935 free_up_tclas_elem(&desc_elem);
11936 free_up_scs_desc(scs_data);
11937 return -1;
11938}
11939
11940
11941static int wpas_ctrl_iface_send_dscp_resp(struct wpa_supplicant *wpa_s,
11942 const char *cmd)
11943{
11944 char *pos;
11945 struct dscp_policy_status *policy = NULL, *n;
11946 int num_policies = 0, ret = -1;
11947 struct dscp_resp_data resp_data;
11948
11949 /*
11950 * format:
11951 * <[reset]>/<[solicited] [policy_id=1 status=0...]> [more]
11952 */
11953
11954 os_memset(&resp_data, 0, sizeof(resp_data));
11955
11956 resp_data.more = os_strstr(cmd, "more") != NULL;
11957
11958 if (os_strstr(cmd, "reset")) {
11959 resp_data.reset = true;
11960 resp_data.solicited = false;
11961 goto send_resp;
11962 }
11963
11964 resp_data.solicited = os_strstr(cmd, "solicited") != NULL;
11965
11966 pos = os_strstr(cmd, "policy_id=");
11967 while (pos) {
11968 n = os_realloc(policy, (num_policies + 1) * sizeof(*policy));
11969 if (!n)
11970 goto fail;
11971
11972 policy = n;
11973 pos += 10;
11974 policy[num_policies].id = atoi(pos);
11975 if (policy[num_policies].id == 0) {
11976 wpa_printf(MSG_ERROR, "DSCP: Invalid policy id");
11977 goto fail;
11978 }
11979
11980 pos = os_strstr(pos, "status=");
11981 if (!pos) {
11982 wpa_printf(MSG_ERROR,
11983 "DSCP: Status is not found for a policy");
11984 goto fail;
11985 }
11986
11987 pos += 7;
11988 policy[num_policies].status = atoi(pos);
11989 num_policies++;
11990
11991 pos = os_strstr(pos, "policy_id");
11992 }
11993
11994 resp_data.policy = policy;
11995 resp_data.num_policies = num_policies;
11996send_resp:
11997 ret = wpas_send_dscp_response(wpa_s, &resp_data);
11998 if (ret)
11999 wpa_printf(MSG_ERROR, "DSCP: Failed to send DSCP response");
12000fail:
12001 os_free(policy);
12002 return ret;
12003}
12004
12005
12006static int wpas_ctrl_iface_send_dscp_query(struct wpa_supplicant *wpa_s,
12007 const char *cmd)
12008{
12009 char *pos;
12010
12011 /*
12012 * format:
12013 * Wildcard DSCP query
12014 * <wildcard>
12015 *
12016 * DSCP query with a domain name attribute:
12017 * [domain_name=<string>]
12018 */
12019
12020 if (os_strstr(cmd, "wildcard")) {
12021 wpa_printf(MSG_DEBUG, "QM: Send wildcard DSCP policy query");
12022 return wpas_send_dscp_query(wpa_s, NULL, 0);
12023 }
12024
12025 pos = os_strstr(cmd, "domain_name=");
12026 if (!pos || !os_strlen(pos + 12)) {
12027 wpa_printf(MSG_ERROR, "QM: Domain name not preset");
12028 return -1;
12029 }
12030
12031 return wpas_send_dscp_query(wpa_s, pos + 12, os_strlen(pos + 12));
12032}
12033
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012034#endif /* CONFIG_NO_ROBUST_AV */
12035
Hai Shaloma20dcd72022-02-04 13:43:00 -080012036
Sunil Ravi89eba102022-09-13 21:04:37 -070012037static int wpas_ctrl_iface_mlo_signal_poll(struct wpa_supplicant *wpa_s,
12038 char *buf, size_t buflen)
12039{
12040 int ret, i;
12041 char *pos, *end;
12042 struct wpa_mlo_signal_info mlo_si;
12043
12044 if (!wpa_s->valid_links)
12045 return -1;
12046
12047 ret = wpa_drv_mlo_signal_poll(wpa_s, &mlo_si);
12048 if (ret)
12049 return -1;
12050
12051 pos = buf;
12052 end = buf + buflen;
12053
Sunil Ravi99c035e2024-07-12 01:42:03 +000012054 for_each_link(mlo_si.valid_links, i) {
Sunil Ravi89eba102022-09-13 21:04:37 -070012055 ret = os_snprintf(pos, end - pos,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000012056 "LINK_ID=%d\nRSSI=%d\nLINKSPEED=%lu\n"
Sunil Ravi89eba102022-09-13 21:04:37 -070012057 "NOISE=%d\nFREQUENCY=%u\n",
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000012058 i, mlo_si.links[i].data.signal,
12059 mlo_si.links[i].data.current_tx_rate / 1000,
Sunil Ravi89eba102022-09-13 21:04:37 -070012060 mlo_si.links[i].current_noise,
12061 mlo_si.links[i].frequency);
12062 if (os_snprintf_error(end - pos, ret))
12063 return -1;
12064 pos += ret;
12065
12066 if (mlo_si.links[i].chanwidth != CHAN_WIDTH_UNKNOWN) {
12067 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
12068 channel_width_to_string(
12069 mlo_si.links[i].chanwidth));
12070 if (os_snprintf_error(end - pos, ret))
12071 return -1;
12072 pos += ret;
12073 }
12074
12075 if (mlo_si.links[i].center_frq1 > 0) {
12076 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
12077 mlo_si.links[i].center_frq1);
12078 if (os_snprintf_error(end - pos, ret))
12079 return -1;
12080 pos += ret;
12081 }
12082
12083 if (mlo_si.links[i].center_frq2 > 0) {
12084 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
12085 mlo_si.links[i].center_frq2);
12086 if (os_snprintf_error(end - pos, ret))
12087 return -1;
12088 pos += ret;
12089 }
12090
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000012091 if (mlo_si.links[i].data.avg_signal) {
Sunil Ravi89eba102022-09-13 21:04:37 -070012092 ret = os_snprintf(pos, end - pos,
12093 "AVG_RSSI=%d\n",
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000012094 mlo_si.links[i].data.avg_signal);
Sunil Ravi89eba102022-09-13 21:04:37 -070012095 if (os_snprintf_error(end - pos, ret))
12096 return -1;
12097 pos += ret;
12098 }
12099
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000012100 if (mlo_si.links[i].data.avg_beacon_signal) {
12101 ret = os_snprintf(
12102 pos, end - pos, "AVG_BEACON_RSSI=%d\n",
12103 mlo_si.links[i].data.avg_beacon_signal);
Sunil Ravi89eba102022-09-13 21:04:37 -070012104 if (os_snprintf_error(end - pos, ret))
12105 return -1;
12106 pos += ret;
12107 }
12108 }
12109
12110 return pos - buf;
12111}
12112
12113
12114static int wpas_ctrl_iface_mlo_status(struct wpa_supplicant *wpa_s,
12115 char *buf, size_t buflen)
12116{
12117 int ret, i;
12118 char *pos, *end;
12119
12120 if (!wpa_s->valid_links)
12121 return -1;
12122
12123 pos = buf;
12124 end = buf + buflen;
12125
Sunil Ravi99c035e2024-07-12 01:42:03 +000012126 for_each_link(wpa_s->valid_links, i) {
Sunil Ravi89eba102022-09-13 21:04:37 -070012127 ret = os_snprintf(pos, end - pos, "link_id=%d\nfreq=%u\n"
12128 "ap_link_addr=" MACSTR
12129 "\nsta_link_addr=" MACSTR "\n",
12130 i, wpa_s->links[i].freq,
12131 MAC2STR(wpa_s->links[i].bssid),
12132 MAC2STR(wpa_s->links[i].addr));
12133 if (os_snprintf_error(end - pos, ret))
12134 return pos - buf;
12135 pos += ret;
12136 }
12137
12138 return pos - buf;
12139}
12140
12141
Sunil Ravi2a14cf12023-11-21 00:54:38 +000012142#ifdef CONFIG_TESTING_OPTIONS
12143static int wpas_ctrl_ml_probe(struct wpa_supplicant *wpa_s, char *cmd)
12144{
12145 char *token, *context = NULL;
12146 u8 bssid[ETH_ALEN];
12147 int mld_id = -1, link_id = -1;
12148 struct wpa_bss *bss;
12149 int *freqs;
12150
12151 os_memset(bssid, 0, sizeof(bssid));
12152
12153 while ((token = str_token(cmd, " ", &context))) {
12154 if (os_strncmp(token, "bssid=", 6) == 0) {
12155 if (hwaddr_aton(token + 6, bssid))
12156 return -1;
12157 } else if (os_strncmp(token, "mld_id=", 7) == 0) {
12158 mld_id = atoi(token + 7);
12159 } else if (os_strncmp(token, "link_id=", 8) == 0) {
12160 link_id = atoi(token + 8);
12161 }
12162 }
12163
Sunil Ravi7f769292024-07-23 22:21:32 +000012164 if (is_zero_ether_addr(bssid)) {
Sunil Ravi2a14cf12023-11-21 00:54:38 +000012165 wpa_printf(MSG_DEBUG,
12166 "MLD: Failed parsing ML probe request arguments");
12167 return -1;
12168 }
12169
12170 bss = wpa_bss_get_bssid(wpa_s, bssid);
12171 if (!bss) {
12172 wpa_printf(MSG_DEBUG,
12173 "MLD: Unknown BSS for " MACSTR, MAC2STR(bssid));
12174 return -1;
12175 }
12176
12177 if (wpa_s->sched_scanning || wpa_s->scanning ||
12178 (wpa_s->wpa_state > WPA_SCANNING &&
12179 wpa_s->wpa_state != WPA_COMPLETED)) {
12180 wpa_printf(MSG_DEBUG,
12181 "MLO: Ongoing scan: Reject ML probe request");
12182 return -1;
12183 }
12184
12185 freqs = os_malloc(sizeof(int) * 2);
12186 if (!freqs)
12187 return -1;
12188
12189 freqs[0] = bss->freq;
12190 freqs[1] = 0;
12191
12192 wpa_s->manual_scan_passive = 0;
12193 wpa_s->manual_scan_use_id = 0;
12194 wpa_s->manual_scan_only_new = 0;
12195 wpa_s->scan_id_count = 0;
12196 wpa_s->scan_res_handler = scan_only_handler;
12197 os_free(wpa_s->manual_scan_freqs);
12198 wpa_s->manual_scan_freqs = freqs;
12199
12200 os_memcpy(wpa_s->ml_probe_bssid, bssid, ETH_ALEN);
12201 wpa_s->ml_probe_mld_id = mld_id;
12202 if (link_id >= 0)
12203 wpa_s->ml_probe_links = BIT(link_id);
12204
12205 wpa_s->normal_scans = 0;
12206 wpa_s->scan_req = MANUAL_SCAN_REQ;
12207 wpa_s->after_wps = 0;
12208 wpa_s->known_wps_freq = 0;
12209 wpa_supplicant_req_scan(wpa_s, 0, 0);
12210
12211 return 0;
12212}
12213#endif /* CONFIG_TESTING_OPTIONS */
12214
12215
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012216#ifdef CONFIG_NAN_USD
12217
12218static int wpas_ctrl_nan_publish(struct wpa_supplicant *wpa_s, char *cmd,
12219 char *buf, size_t buflen)
12220{
12221 char *token, *context = NULL;
12222 int publish_id;
12223 struct nan_publish_params params;
12224 const char *service_name = NULL;
12225 struct wpabuf *ssi = NULL;
12226 int ret = -1;
12227 enum nan_service_protocol_type srv_proto_type = 0;
12228 int *freq_list = NULL;
Sunil Ravic0f5d412024-09-11 22:12:49 +000012229 bool p2p = false;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012230
12231 os_memset(&params, 0, sizeof(params));
12232 /* USD shall use both solicited and unsolicited transmissions */
12233 params.unsolicited = true;
12234 params.solicited = true;
12235 /* USD shall require FSD without GAS */
12236 params.fsd = true;
12237 params.freq = NAN_USD_DEFAULT_FREQ;
12238
12239 while ((token = str_token(cmd, " ", &context))) {
12240 if (os_strncmp(token, "service_name=", 13) == 0) {
12241 service_name = token + 13;
12242 continue;
12243 }
12244
12245 if (os_strncmp(token, "ttl=", 4) == 0) {
12246 params.ttl = atoi(token + 4);
12247 continue;
12248 }
12249
12250 if (os_strncmp(token, "freq=", 5) == 0) {
12251 params.freq = atoi(token + 5);
12252 continue;
12253 }
12254
12255 if (os_strncmp(token, "freq_list=", 10) == 0) {
12256 char *pos = token + 10;
12257
12258 if (os_strcmp(pos, "all") == 0) {
12259 os_free(freq_list);
12260 freq_list = wpas_nan_usd_all_freqs(wpa_s);
12261 params.freq_list = freq_list;
12262 continue;
12263 }
12264
12265 while (pos && pos[0]) {
12266 int_array_add_unique(&freq_list, atoi(pos));
12267 pos = os_strchr(pos, ',');
12268 if (pos)
12269 pos++;
12270 }
12271
12272 params.freq_list = freq_list;
12273 continue;
12274 }
12275
12276 if (os_strncmp(token, "srv_proto_type=", 15) == 0) {
12277 srv_proto_type = atoi(token + 15);
12278 continue;
12279 }
12280
12281 if (os_strncmp(token, "ssi=", 4) == 0) {
12282 if (ssi)
12283 goto fail;
12284 ssi = wpabuf_parse_bin(token + 4);
12285 if (!ssi)
12286 goto fail;
12287 continue;
12288 }
12289
Sunil Ravic0f5d412024-09-11 22:12:49 +000012290 if (os_strcmp(token, "p2p=1") == 0) {
12291 p2p = true;
12292 continue;
12293 }
12294
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012295 if (os_strcmp(token, "solicited=0") == 0) {
12296 params.solicited = false;
12297 continue;
12298 }
12299
12300 if (os_strcmp(token, "unsolicited=0") == 0) {
12301 params.unsolicited = false;
12302 continue;
12303 }
12304
12305 if (os_strcmp(token, "fsd=0") == 0) {
12306 params.fsd = false;
12307 continue;
12308 }
12309
12310 wpa_printf(MSG_INFO, "CTRL: Invalid NAN_PUBLISH parameter: %s",
12311 token);
12312 goto fail;
12313 }
12314
12315 publish_id = wpas_nan_usd_publish(wpa_s, service_name, srv_proto_type,
Sunil Ravic0f5d412024-09-11 22:12:49 +000012316 ssi, &params, p2p);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012317 if (publish_id > 0)
12318 ret = os_snprintf(buf, buflen, "%d", publish_id);
12319fail:
12320 wpabuf_free(ssi);
12321 os_free(freq_list);
12322 return ret;
12323}
12324
12325
12326static int wpas_ctrl_nan_cancel_publish(struct wpa_supplicant *wpa_s,
12327 char *cmd)
12328{
12329 char *token, *context = NULL;
12330 int publish_id = 0;
12331
12332 while ((token = str_token(cmd, " ", &context))) {
12333 if (sscanf(token, "publish_id=%i", &publish_id) == 1)
12334 continue;
12335 wpa_printf(MSG_INFO,
12336 "CTRL: Invalid NAN_CANCEL_PUBLISH parameter: %s",
12337 token);
12338 return -1;
12339 }
12340
12341 if (publish_id <= 0) {
12342 wpa_printf(MSG_INFO,
12343 "CTRL: Invalid or missing NAN_CANCEL_PUBLISH publish_id");
12344 return -1;
12345 }
12346
12347 wpas_nan_usd_cancel_publish(wpa_s, publish_id);
12348 return 0;
12349}
12350
12351
12352static int wpas_ctrl_nan_update_publish(struct wpa_supplicant *wpa_s,
12353 char *cmd)
12354{
12355 char *token, *context = NULL;
12356 int publish_id = 0;
12357 struct wpabuf *ssi = NULL;
12358 int ret = -1;
12359
12360 while ((token = str_token(cmd, " ", &context))) {
12361 if (sscanf(token, "publish_id=%i", &publish_id) == 1)
12362 continue;
12363 if (os_strncmp(token, "ssi=", 4) == 0) {
12364 if (ssi)
12365 goto fail;
12366 ssi = wpabuf_parse_bin(token + 4);
12367 if (!ssi)
12368 goto fail;
12369 continue;
12370 }
12371 wpa_printf(MSG_INFO,
12372 "CTRL: Invalid NAN_UPDATE_PUBLISH parameter: %s",
12373 token);
12374 goto fail;
12375 }
12376
12377 if (publish_id <= 0) {
12378 wpa_printf(MSG_INFO,
12379 "CTRL: Invalid or missing NAN_UPDATE_PUBLISH publish_id");
12380 goto fail;
12381 }
12382
12383 ret = wpas_nan_usd_update_publish(wpa_s, publish_id, ssi);
12384fail:
12385 wpabuf_free(ssi);
12386 return ret;
12387}
12388
12389
12390static int wpas_ctrl_nan_subscribe(struct wpa_supplicant *wpa_s, char *cmd,
12391 char *buf, size_t buflen)
12392{
12393 char *token, *context = NULL;
12394 int subscribe_id;
12395 struct nan_subscribe_params params;
12396 const char *service_name = NULL;
12397 struct wpabuf *ssi = NULL;
12398 int ret = -1;
12399 enum nan_service_protocol_type srv_proto_type = 0;
Sunil Ravic0f5d412024-09-11 22:12:49 +000012400 int *freq_list = NULL;
12401 bool p2p = false;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012402
12403 os_memset(&params, 0, sizeof(params));
12404 params.freq = NAN_USD_DEFAULT_FREQ;
12405
12406 while ((token = str_token(cmd, " ", &context))) {
12407 if (os_strncmp(token, "service_name=", 13) == 0) {
12408 service_name = token + 13;
12409 continue;
12410 }
12411
12412 if (os_strcmp(token, "active=1") == 0) {
12413 params.active = true;
12414 continue;
12415 }
12416
12417 if (os_strncmp(token, "ttl=", 4) == 0) {
12418 params.ttl = atoi(token + 4);
12419 continue;
12420 }
12421
12422 if (os_strncmp(token, "freq=", 5) == 0) {
12423 params.freq = atoi(token + 5);
12424 continue;
12425 }
12426
Sunil Ravic0f5d412024-09-11 22:12:49 +000012427 if (os_strncmp(token, "freq_list=", 10) == 0) {
12428 char *pos = token + 10;
12429
12430 if (os_strcmp(pos, "all") == 0) {
12431 os_free(freq_list);
12432 freq_list = wpas_nan_usd_all_freqs(wpa_s);
12433 params.freq_list = freq_list;
12434 continue;
12435 }
12436
12437 while (pos && pos[0]) {
12438 int_array_add_unique(&freq_list, atoi(pos));
12439 pos = os_strchr(pos, ',');
12440 if (pos)
12441 pos++;
12442 }
12443
12444 params.freq_list = freq_list;
12445 continue;
12446 }
12447
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012448 if (os_strncmp(token, "srv_proto_type=", 15) == 0) {
12449 srv_proto_type = atoi(token + 15);
12450 continue;
12451 }
12452
12453 if (os_strncmp(token, "ssi=", 4) == 0) {
12454 if (ssi)
12455 goto fail;
12456 ssi = wpabuf_parse_bin(token + 4);
12457 if (!ssi)
12458 goto fail;
12459 continue;
12460 }
12461
Sunil Ravic0f5d412024-09-11 22:12:49 +000012462 if (os_strcmp(token, "p2p=1") == 0) {
12463 p2p = true;
12464 continue;
12465 }
12466
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012467 wpa_printf(MSG_INFO,
12468 "CTRL: Invalid NAN_SUBSCRIBE parameter: %s",
12469 token);
12470 goto fail;
12471 }
12472
12473 subscribe_id = wpas_nan_usd_subscribe(wpa_s, service_name,
12474 srv_proto_type, ssi,
Sunil Ravic0f5d412024-09-11 22:12:49 +000012475 &params, p2p);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012476 if (subscribe_id > 0)
12477 ret = os_snprintf(buf, buflen, "%d", subscribe_id);
12478fail:
12479 wpabuf_free(ssi);
Sunil Ravic0f5d412024-09-11 22:12:49 +000012480 os_free(freq_list);
Sunil Ravib0ac25f2024-07-12 01:42:03 +000012481 return ret;
12482}
12483
12484
12485static int wpas_ctrl_nan_cancel_subscribe(struct wpa_supplicant *wpa_s,
12486 char *cmd)
12487{
12488 char *token, *context = NULL;
12489 int subscribe_id = 0;
12490
12491 while ((token = str_token(cmd, " ", &context))) {
12492 if (sscanf(token, "subscribe_id=%i", &subscribe_id) == 1)
12493 continue;
12494 wpa_printf(MSG_INFO,
12495 "CTRL: Invalid NAN_CANCEL_SUBSCRIBE parameter: %s",
12496 token);
12497 return -1;
12498 }
12499
12500 if (subscribe_id <= 0) {
12501 wpa_printf(MSG_INFO,
12502 "CTRL: Invalid or missing NAN_CANCEL_SUBSCRIBE subscribe_id");
12503 return -1;
12504 }
12505
12506 wpas_nan_usd_cancel_subscribe(wpa_s, subscribe_id);
12507 return 0;
12508}
12509
12510
12511static int wpas_ctrl_nan_transmit(struct wpa_supplicant *wpa_s, char *cmd)
12512{
12513 char *token, *context = NULL;
12514 int handle = 0;
12515 int req_instance_id = 0;
12516 struct wpabuf *ssi = NULL;
12517 u8 peer_addr[ETH_ALEN];
12518 int ret = -1;
12519
12520 os_memset(peer_addr, 0, ETH_ALEN);
12521
12522 while ((token = str_token(cmd, " ", &context))) {
12523 if (sscanf(token, "handle=%i", &handle) == 1)
12524 continue;
12525
12526 if (sscanf(token, "req_instance_id=%i", &req_instance_id) == 1)
12527 continue;
12528
12529 if (os_strncmp(token, "address=", 8) == 0) {
12530 if (hwaddr_aton(token + 8, peer_addr) < 0)
12531 return -1;
12532 continue;
12533 }
12534
12535 if (os_strncmp(token, "ssi=", 4) == 0) {
12536 if (ssi)
12537 goto fail;
12538 ssi = wpabuf_parse_bin(token + 4);
12539 if (!ssi)
12540 goto fail;
12541 continue;
12542 }
12543
12544 wpa_printf(MSG_INFO,
12545 "CTRL: Invalid NAN_TRANSMIT parameter: %s",
12546 token);
12547 goto fail;
12548 }
12549
12550 if (handle <= 0) {
12551 wpa_printf(MSG_INFO,
12552 "CTRL: Invalid or missing NAN_TRANSMIT handle");
12553 goto fail;
12554 }
12555
12556 if (is_zero_ether_addr(peer_addr)) {
12557 wpa_printf(MSG_INFO,
12558 "CTRL: Invalid or missing NAN_TRANSMIT address");
12559 goto fail;
12560 }
12561
12562 ret = wpas_nan_usd_transmit(wpa_s, handle, ssi, NULL, peer_addr,
12563 req_instance_id);
12564fail:
12565 wpabuf_free(ssi);
12566 return ret;
12567}
12568
12569#endif /* CONFIG_NAN_USD */
12570
12571
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012572char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
12573 char *buf, size_t *resp_len)
12574{
12575 char *reply;
12576 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012577 int reply_len;
12578
12579 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012580 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
12581 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
12582 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012583 if (wpa_debug_show_keys)
12584 wpa_dbg(wpa_s, MSG_DEBUG,
12585 "Control interface command '%s'", buf);
12586 else
12587 wpa_dbg(wpa_s, MSG_DEBUG,
12588 "Control interface command '%s [REMOVED]'",
12589 os_strncmp(buf, WPA_CTRL_RSP,
12590 os_strlen(WPA_CTRL_RSP)) == 0 ?
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012591 WPA_CTRL_RSP :
12592 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
12593 "SET_NETWORK" : "key-add"));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012594 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
Dmitry Shmidt21de2142014-04-08 10:50:52 -070012595 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012596 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
12597 (const u8 *) buf, os_strlen(buf));
12598 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012599 int level = wpas_ctrl_cmd_debug_level(buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -070012600 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012601 }
12602
12603 reply = os_malloc(reply_size);
12604 if (reply == NULL) {
12605 *resp_len = 1;
12606 return NULL;
12607 }
12608
12609 os_memcpy(reply, "OK\n", 3);
12610 reply_len = 3;
12611
12612 if (os_strcmp(buf, "PING") == 0) {
12613 os_memcpy(reply, "PONG\n", 5);
12614 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070012615 } else if (os_strcmp(buf, "IFNAME") == 0) {
12616 reply_len = os_strlen(wpa_s->ifname);
12617 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012618 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
12619 if (wpa_debug_reopen_file() < 0)
12620 reply_len = -1;
12621 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
12622 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
12623 } else if (os_strcmp(buf, "MIB") == 0) {
12624 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
12625 if (reply_len >= 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012626 reply_len += eapol_sm_get_mib(wpa_s->eapol,
12627 reply + reply_len,
12628 reply_size - reply_len);
Hai Shalom74f70d42019-02-11 14:42:39 -080012629#ifdef CONFIG_MACSEC
12630 reply_len += ieee802_1x_kay_get_mib(
12631 wpa_s->kay, reply + reply_len,
12632 reply_size - reply_len);
12633#endif /* CONFIG_MACSEC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012634 }
12635 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
12636 reply_len = wpa_supplicant_ctrl_iface_status(
12637 wpa_s, buf + 6, reply, reply_size);
12638 } else if (os_strcmp(buf, "PMKSA") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070012639 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070012640 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070012641 wpas_ctrl_iface_pmksa_flush(wpa_s);
Dmitry Shmidt29333592017-01-09 12:27:11 -080012642#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
12643 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
12644 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
12645 reply, reply_size);
12646 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
12647 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
12648 reply_len = -1;
Paul Stewart092955c2017-02-06 09:13:09 -080012649#ifdef CONFIG_MESH
12650 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
12651 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
12652 reply, reply_size);
12653 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
12654 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
12655 reply_len = -1;
12656#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080012657#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012658 } else if (os_strncmp(buf, "SET ", 4) == 0) {
12659 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
12660 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012661 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
12662 reply_len = wpa_config_dump_values(wpa_s->conf,
12663 reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012664 } else if (os_strncmp(buf, "GET ", 4) == 0) {
12665 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
12666 reply, reply_size);
12667 } else if (os_strcmp(buf, "LOGON") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070012668 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012669 } else if (os_strcmp(buf, "LOGOFF") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070012670 eapol_sm_notify_logoff(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012671 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
12672 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
12673 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012674 else
12675 wpas_request_connection(wpa_s);
Dmitry Shmidt98660862014-03-11 17:26:21 -070012676 } else if (os_strcmp(buf, "REATTACH") == 0) {
12677 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
12678 !wpa_s->current_ssid)
12679 reply_len = -1;
12680 else {
12681 wpa_s->reattach = 1;
12682 wpas_request_connection(wpa_s);
12683 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012684 } else if (os_strcmp(buf, "RECONNECT") == 0) {
12685 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
12686 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012687 else if (wpa_s->disconnected)
12688 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012689#ifdef IEEE8021X_EAPOL
12690 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
12691 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
12692 reply_len = -1;
12693#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012694#ifdef CONFIG_IEEE80211R
12695 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
12696 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
12697 reply_len = -1;
12698#endif /* CONFIG_IEEE80211R */
12699#ifdef CONFIG_WPS
12700 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
12701 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
12702 if (res == -2) {
12703 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12704 reply_len = 17;
12705 } else if (res)
12706 reply_len = -1;
12707 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
12708 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
12709 if (res == -2) {
12710 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12711 reply_len = 17;
12712 } else if (res)
12713 reply_len = -1;
12714 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
12715 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
12716 reply,
12717 reply_size);
12718 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
12719 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
12720 wpa_s, buf + 14, reply, reply_size);
12721 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
12722 if (wpas_wps_cancel(wpa_s))
12723 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012724#ifdef CONFIG_WPS_NFC
12725 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
12726 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
12727 reply_len = -1;
12728 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
12729 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
12730 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -080012731 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
12732 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
12733 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012734 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
12735 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
12736 wpa_s, buf + 14, reply, reply_size);
12737 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
12738 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
12739 buf + 17))
12740 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012741 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
12742 reply_len = wpas_ctrl_nfc_get_handover_req(
12743 wpa_s, buf + 21, reply, reply_size);
12744 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
12745 reply_len = wpas_ctrl_nfc_get_handover_sel(
12746 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -080012747 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
12748 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
12749 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012750#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012751 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
12752 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
12753 reply_len = -1;
12754#ifdef CONFIG_AP
12755 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
12756 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
12757 wpa_s, buf + 11, reply, reply_size);
12758#endif /* CONFIG_AP */
12759#ifdef CONFIG_WPS_ER
12760 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
12761 if (wpas_wps_er_start(wpa_s, NULL))
12762 reply_len = -1;
12763 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
12764 if (wpas_wps_er_start(wpa_s, buf + 13))
12765 reply_len = -1;
12766 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012767 wpas_wps_er_stop(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012768 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
12769 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
12770 reply_len = -1;
12771 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
12772 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
12773 if (ret == -2) {
12774 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12775 reply_len = 17;
12776 } else if (ret == -3) {
12777 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
12778 reply_len = 18;
12779 } else if (ret == -4) {
12780 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
12781 reply_len = 20;
12782 } else if (ret)
12783 reply_len = -1;
12784 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
12785 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
12786 reply_len = -1;
12787 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
12788 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
12789 buf + 18))
12790 reply_len = -1;
12791 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
12792 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
12793 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012794#ifdef CONFIG_WPS_NFC
12795 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
12796 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
12797 wpa_s, buf + 24, reply, reply_size);
12798#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012799#endif /* CONFIG_WPS_ER */
12800#endif /* CONFIG_WPS */
12801#ifdef CONFIG_IBSS_RSN
12802 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
12803 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
12804 reply_len = -1;
12805#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012806#ifdef CONFIG_MESH
12807 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
12808 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
12809 wpa_s, buf + 19, reply, reply_size);
12810 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
12811 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
12812 wpa_s, "", reply, reply_size);
12813 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
12814 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
12815 reply_len = -1;
12816 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
12817 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
12818 buf + 18))
12819 reply_len = -1;
Dmitry Shmidte4663042016-04-04 10:07:49 -070012820 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
12821 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
12822 reply_len = -1;
12823 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
12824 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
12825 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070012826 } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) {
12827 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16))
12828 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012829#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012830#ifdef CONFIG_P2P
12831 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012832 if (p2p_ctrl_find(wpa_s, buf + 8))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012833 reply_len = -1;
12834 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
12835 if (p2p_ctrl_find(wpa_s, ""))
12836 reply_len = -1;
12837 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
12838 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012839 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
12840 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
12841 reply_len = -1;
12842 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
12843 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
12844 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012845 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
12846 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
12847 reply_size);
12848 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
12849 if (p2p_ctrl_listen(wpa_s, buf + 11))
12850 reply_len = -1;
12851 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
12852 if (p2p_ctrl_listen(wpa_s, ""))
12853 reply_len = -1;
12854 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
12855 if (wpas_p2p_group_remove(wpa_s, buf + 17))
12856 reply_len = -1;
12857 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070012858 if (p2p_ctrl_group_add(wpa_s, ""))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012859 reply_len = -1;
12860 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
12861 if (p2p_ctrl_group_add(wpa_s, buf + 14))
12862 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070012863 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
12864 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
12865 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012866 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
12867 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
12868 reply_len = -1;
12869 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
12870 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
12871 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
12872 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
12873 reply_size);
12874 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
12875 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
12876 reply_len = -1;
12877 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
12878 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
12879 reply_len = -1;
12880 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
12881 wpas_p2p_sd_service_update(wpa_s);
12882 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
12883 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
12884 reply_len = -1;
12885 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
12886 wpas_p2p_service_flush(wpa_s);
12887 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
12888 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
12889 reply_len = -1;
12890 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
12891 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
12892 reply_len = -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012893 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
12894 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
12895 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012896 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
12897 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
12898 reply_len = -1;
12899 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
12900 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
12901 reply_len = -1;
12902 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
12903 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
12904 reply_size);
12905 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
12906 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
12907 reply_len = -1;
12908 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -070012909 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012910 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
12911 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
12912 reply_len = -1;
12913 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
12914 if (wpas_p2p_cancel(wpa_s))
12915 reply_len = -1;
12916 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
12917 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
12918 reply_len = -1;
12919 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
12920 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
12921 reply_len = -1;
12922 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
12923 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
12924 reply_len = -1;
12925 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
12926 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
12927 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070012928 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
12929 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
12930 reply_len = -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070012931 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
12932 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
12933 reply_len = -1;
12934 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
12935 if (wpas_p2p_lo_stop(wpa_s))
12936 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012937#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070012938#ifdef CONFIG_WIFI_DISPLAY
12939 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
12940 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
12941 reply_len = -1;
12942 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
12943 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
12944 reply, reply_size);
12945#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012946#ifdef CONFIG_INTERWORKING
12947 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
12948 if (interworking_fetch_anqp(wpa_s) < 0)
12949 reply_len = -1;
12950 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
12951 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012952 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
12953 if (ctrl_interworking_select(wpa_s, NULL) < 0)
12954 reply_len = -1;
12955 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
12956 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012957 reply_len = -1;
12958 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012959 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012960 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012961 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
12962 int id;
12963
12964 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
12965 if (id < 0)
12966 reply_len = -1;
12967 else {
12968 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
12969 if (os_snprintf_error(reply_size, reply_len))
12970 reply_len = -1;
12971 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012972 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
12973 if (get_anqp(wpa_s, buf + 9) < 0)
12974 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070012975 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
12976 if (gas_request(wpa_s, buf + 12) < 0)
12977 reply_len = -1;
12978 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
12979 reply_len = gas_response_get(wpa_s, buf + 17, reply,
12980 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012981#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -070012982#ifdef CONFIG_HS20
12983 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
12984 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
12985 reply_len = -1;
12986 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
12987 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
12988 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080012989 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080012990 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
12991 reply_len = -1;
12992 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
12993 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
12994 reply_len = -1;
12995 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
12996 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
12997 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
12998 if (del_hs20_icon(wpa_s, buf + 14) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080012999 reply_len = -1;
13000 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070013001 if (hs20_fetch_osu(wpa_s, 0) < 0)
13002 reply_len = -1;
13003 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
13004 if (hs20_fetch_osu(wpa_s, 1) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080013005 reply_len = -1;
13006 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
13007 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -070013008#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013009 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
13010 {
13011 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
13012 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
13013 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -070013014 else {
13015 /*
13016 * Notify response from timeout to allow the control
13017 * interface response to be sent first.
13018 */
13019 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
13020 wpa_s, NULL);
13021 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013022 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
13023 if (wpa_supplicant_reload_configuration(wpa_s))
13024 reply_len = -1;
13025 } else if (os_strcmp(buf, "TERMINATE") == 0) {
13026 wpa_supplicant_terminate_proc(wpa_s->global);
13027 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
13028 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
13029 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080013030 } else if (os_strncmp(buf, "BSSID_IGNORE", 12) == 0) {
13031 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
13032 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidte19501d2011-03-16 14:32:18 -070013033 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -080013034 /* deprecated backwards compatibility alias for BSSID_IGNORE */
13035 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080013036 wpa_s, buf + 9, reply, reply_size);
13037 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
13038 reply_len = wpa_supplicant_ctrl_iface_log_level(
13039 wpa_s, buf + 9, reply, reply_size);
Vinit Deshpandeda134e92014-12-02 10:59:29 -080013040 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
13041 reply_len = wpa_supplicant_ctrl_iface_list_networks(
13042 wpa_s, buf + 14, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013043 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
13044 reply_len = wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -080013045 wpa_s, NULL, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013046 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070013047 wpas_request_disconnection(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080013048 } else if (os_strcmp(buf, "SCAN") == 0) {
13049 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
13050 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
13051 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013052 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
13053 reply_len = wpa_supplicant_ctrl_iface_scan_results(
13054 wpa_s, reply, reply_size);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013055 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
13056 if (wpas_abort_ongoing_scan(wpa_s) < 0)
13057 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013058 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
13059 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
13060 reply_len = -1;
13061 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
13062 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
13063 reply_len = -1;
13064 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
13065 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
13066 reply_len = -1;
13067 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
13068 reply_len = wpa_supplicant_ctrl_iface_add_network(
13069 wpa_s, reply, reply_size);
13070 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
13071 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
13072 reply_len = -1;
13073 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
13074 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
13075 reply_len = -1;
13076 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
13077 reply_len = wpa_supplicant_ctrl_iface_get_network(
13078 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt684785c2014-05-12 13:34:29 -070013079 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013080 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
13081 wpa_s))
Dmitry Shmidt684785c2014-05-12 13:34:29 -070013082 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070013083 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
13084 reply_len = wpa_supplicant_ctrl_iface_list_creds(
13085 wpa_s, reply, reply_size);
13086 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
13087 reply_len = wpa_supplicant_ctrl_iface_add_cred(
13088 wpa_s, reply, reply_size);
13089 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
13090 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
13091 reply_len = -1;
13092 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
13093 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
13094 reply_len = -1;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -070013095 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
13096 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
13097 reply,
13098 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013099#ifndef CONFIG_NO_CONFIG_WRITE
13100 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
13101 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
13102 reply_len = -1;
13103#endif /* CONFIG_NO_CONFIG_WRITE */
13104 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
13105 reply_len = wpa_supplicant_ctrl_iface_get_capability(
13106 wpa_s, buf + 15, reply, reply_size);
13107 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
13108 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
13109 reply_len = -1;
13110 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
13111 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
13112 reply_len = -1;
13113 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
13114 reply_len = wpa_supplicant_global_iface_list(
13115 wpa_s->global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013116 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013117 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013118 wpa_s->global, buf + 10, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013119 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
13120 reply_len = wpa_supplicant_ctrl_iface_bss(
13121 wpa_s, buf + 4, reply, reply_size);
13122#ifdef CONFIG_AP
13123 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
13124 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
13125 } else if (os_strncmp(buf, "STA ", 4) == 0) {
13126 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
13127 reply_size);
13128 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
13129 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
13130 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070013131 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
13132 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
13133 reply_len = -1;
13134 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
13135 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
13136 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080013137 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
13138 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
13139 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080013140 } else if (os_strcmp(buf, "STOP_AP") == 0) {
13141 if (wpas_ap_stop_ap(wpa_s))
13142 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080013143 } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) {
13144 if (wpas_ap_update_beacon(wpa_s))
13145 reply_len = -1;
Sunil Ravia04bd252022-05-02 22:54:18 -070013146 } else if (os_strncmp(buf, "ACCEPT_ACL ", 11) == 0) {
13147 if (os_strncmp(buf + 11, "ADD_MAC ", 8) == 0) {
13148 if (ap_ctrl_iface_acl_add_mac(wpa_s,
13149 DENY_UNLESS_ACCEPTED,
13150 buf + 19) ||
13151 ap_ctrl_iface_set_acl(wpa_s))
13152 reply_len = -1;
13153 } else if (os_strncmp((buf + 11), "DEL_MAC ", 8) == 0) {
13154 if (ap_ctrl_iface_acl_del_mac(wpa_s,
13155 DENY_UNLESS_ACCEPTED,
13156 buf + 19) ||
13157 ap_ctrl_iface_set_acl(wpa_s) ||
13158 ap_ctrl_iface_disassoc_accept_mac(wpa_s))
13159 reply_len = -1;
13160 } else if (os_strcmp(buf + 11, "SHOW") == 0) {
13161 reply_len = ap_ctrl_iface_acl_show_mac(
13162 wpa_s, DENY_UNLESS_ACCEPTED,
13163 reply, reply_size);
13164 } else if (os_strcmp(buf + 11, "CLEAR") == 0) {
13165 ap_ctrl_iface_acl_clear_list(wpa_s,
13166 DENY_UNLESS_ACCEPTED);
13167 if (ap_ctrl_iface_set_acl(wpa_s) ||
13168 ap_ctrl_iface_disassoc_accept_mac(wpa_s))
13169 reply_len = -1;
13170 } else {
13171 reply_len = -1;
13172 }
13173 } else if (os_strncmp(buf, "DENY_ACL ", 9) == 0) {
13174 if (os_strncmp(buf + 9, "ADD_MAC ", 8) == 0) {
13175 if (ap_ctrl_iface_acl_add_mac(wpa_s,
13176 ACCEPT_UNLESS_DENIED,
13177 buf + 17) ||
13178 ap_ctrl_iface_set_acl(wpa_s) ||
13179 ap_ctrl_iface_disassoc_deny_mac(wpa_s))
13180 reply_len = -1;
13181 } else if (os_strncmp(buf + 9, "DEL_MAC ", 8) == 0) {
13182 if (ap_ctrl_iface_acl_del_mac(wpa_s,
13183 ACCEPT_UNLESS_DENIED,
13184 buf + 17) ||
13185 ap_ctrl_iface_set_acl(wpa_s))
13186 reply_len = -1;
13187 } else if (os_strcmp(buf + 9, "SHOW") == 0) {
13188 reply_len = ap_ctrl_iface_acl_show_mac(
13189 wpa_s, ACCEPT_UNLESS_DENIED, reply, reply_size);
13190 } else if (os_strcmp(buf + 9, "CLEAR") == 0) {
13191 ap_ctrl_iface_acl_clear_list(wpa_s,
13192 ACCEPT_UNLESS_DENIED);
13193 if (ap_ctrl_iface_set_acl(wpa_s))
13194 reply_len = -1;
13195 } else {
13196 reply_len = -1;
13197 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013198#endif /* CONFIG_AP */
13199 } else if (os_strcmp(buf, "SUSPEND") == 0) {
13200 wpas_notify_suspend(wpa_s->global);
13201 } else if (os_strcmp(buf, "RESUME") == 0) {
13202 wpas_notify_resume(wpa_s->global);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070013203#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013204 } else if (os_strcmp(buf, "DROP_SA") == 0) {
13205 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070013206#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013207 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
13208 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
13209 reply_len = -1;
13210 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013211 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013212 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
13213 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
13214 reply_len = -1;
13215 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
13216 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
13217 buf + 17))
13218 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -070013219 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013220 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013221#ifdef CONFIG_TDLS
13222 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
13223 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
13224 reply_len = -1;
13225 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
13226 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
13227 reply_len = -1;
13228 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
13229 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
13230 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013231 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
13232 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
13233 buf + 17))
13234 reply_len = -1;
13235 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
13236 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
13237 buf + 24))
13238 reply_len = -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -070013239 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
13240 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
13241 wpa_s, buf + 17, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013242#endif /* CONFIG_TDLS */
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013243#ifndef CONFIG_NO_WMM_AC
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013244 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
13245 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
13246 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
13247 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
13248 reply_len = -1;
13249 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
13250 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
13251 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013252#endif /* CONFIG_NO_WMM_AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013253 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
13254 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
13255 reply_size);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080013256 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
13257 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
13258 reply_len = -1;
Yuhao Zhengfcd6f212012-07-27 10:37:52 -070013259 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
13260 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
13261 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070013262#ifdef CONFIG_AUTOSCAN
13263 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
13264 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
13265 reply_len = -1;
13266#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070013267 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
13268 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
13269 reply_size);
Hai Shalomb755a2a2020-04-23 21:49:02 -070013270 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
13271 reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply,
13272 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080013273#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -070013274 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
13275 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
13276 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080013277#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080013278 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
13279 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
13280 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080013281 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080013282 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080013283 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080013284#ifdef CONFIG_WNM
13285 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
13286 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
13287 reply_len = -1;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080013288 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
13289 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
Dmitry Shmidt44c95782013-05-17 09:51:35 -070013290 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -080013291 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
13292 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
13293 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080013294#endif /* CONFIG_WNM */
Sunil Ravia04bd252022-05-02 22:54:18 -070013295#ifdef CONFIG_WNM_AP
13296 } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
13297 if (ap_ctrl_iface_disassoc_imminent(wpa_s, buf + 18))
13298 reply_len = -1;
13299 } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
13300 if (ap_ctrl_iface_ess_disassoc(wpa_s, buf + 13))
13301 reply_len = -1;
13302 } else if (os_strncmp(buf, "BSS_TM_REQ ", 11) == 0) {
13303 if (ap_ctrl_iface_bss_tm_req(wpa_s, buf + 11))
13304 reply_len = -1;
13305#endif /* CONFIG_WNM_AP */
Dmitry Shmidt444d5672013-04-01 13:08:44 -070013306 } else if (os_strcmp(buf, "FLUSH") == 0) {
13307 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080013308 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
13309 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
13310 reply_size);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070013311#ifdef CONFIG_TESTING_OPTIONS
13312 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
13313 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
13314 reply_len = -1;
13315 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
13316 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013317 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
13318 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
13319 reply_len = -1;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -070013320 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
13321 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
13322 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013323 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
13324 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
13325 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080013326 } else if (os_strncmp(buf, "EAPOL_TX ", 9) == 0) {
13327 if (wpas_ctrl_iface_eapol_tx(wpa_s, buf + 9) < 0)
13328 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013329 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
13330 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
13331 reply_len = -1;
13332 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
13333 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
13334 reply_len = -1;
13335 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
13336 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
13337 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -080013338 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013339 if (testing_set_fail_pattern(true, buf + 16) < 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -080013340 reply_len = -1;
13341 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013342 reply_len = testing_get_fail_pattern(true, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013343 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013344 if (testing_set_fail_pattern(false, buf + 10) < 0)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013345 reply_len = -1;
13346 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013347 reply_len = testing_get_fail_pattern(false, reply, reply_size);
Jouni Malinenc4818362015-10-04 11:45:13 +030013348 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
13349 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
13350 reply_len = -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080013351 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
13352 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
13353 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013354 } else if (os_strncmp(buf, "TEST_EAPOL_M2_ELEMS ", 20) == 0) {
13355 if (wpas_ctrl_test_eapol_m2_elems(wpa_s, buf + 20) < 0)
13356 reply_len = -1;
13357 } else if (os_strncmp(buf, "TEST_EAPOL_M4_ELEMS ", 20) == 0) {
13358 if (wpas_ctrl_test_eapol_m4_elems(wpa_s, buf + 20) < 0)
13359 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013360 } else if (os_strcmp(buf, "RESET_PN") == 0) {
13361 if (wpas_ctrl_reset_pn(wpa_s) < 0)
13362 reply_len = -1;
13363 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
13364 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
13365 reply_len = -1;
13366 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
13367 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
13368 reply_len = -1;
Hai Shalom74f70d42019-02-11 14:42:39 -080013369 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
13370 sme_event_unprot_disconnect(
13371 wpa_s, wpa_s->bssid, NULL,
13372 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
Hai Shaloma20dcd72022-02-04 13:43:00 -080013373 } else if (os_strncmp(buf, "TWT_SETUP ", 10) == 0) {
13374 if (wpas_ctrl_iface_send_twt_setup(wpa_s, buf + 9))
13375 reply_len = -1;
13376 } else if (os_strcmp(buf, "TWT_SETUP") == 0) {
13377 if (wpas_ctrl_iface_send_twt_setup(wpa_s, ""))
13378 reply_len = -1;
13379 } else if (os_strncmp(buf, "TWT_TEARDOWN ", 13) == 0) {
13380 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, buf + 12))
13381 reply_len = -1;
13382 } else if (os_strcmp(buf, "TWT_TEARDOWN") == 0) {
13383 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, ""))
13384 reply_len = -1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000013385 } else if (os_strncmp(buf, "ML_PROBE_REQ ", 13) == 0) {
13386 if (wpas_ctrl_ml_probe(wpa_s, buf + 13))
13387 reply_len = -1;
Dmitry Shmidt818ea482014-03-10 13:15:21 -070013388#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070013389 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
13390 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
13391 reply_len = -1;
13392 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
13393 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
13394 reply_size);
13395 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
13396 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
13397 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013398#ifndef CONFIG_NO_RRM
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013399 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013400 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013401 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013402#endif /* CONFIG_NO_RRM */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013403 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
13404 wpas_ctrl_iface_erp_flush(wpa_s);
13405 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
13406 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
13407 reply_len = -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013408 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
13409 reply_len = wpas_ctrl_iface_get_pref_freq_list(
13410 wpa_s, buf + 19, reply, reply_size);
Paul Stewart092955c2017-02-06 09:13:09 -080013411#ifdef CONFIG_FILS
13412 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
13413 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
13414 reply_len = -1;
13415 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
13416 wpas_flush_fils_hlp_req(wpa_s);
13417#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013418#ifdef CONFIG_DPP
13419 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
13420 int res;
13421
13422 res = wpas_dpp_qr_code(wpa_s, buf + 12);
13423 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 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080013430 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
13431 int res;
13432
13433 res = wpas_dpp_nfc_uri(wpa_s, buf + 12);
13434 if (res < 0) {
13435 reply_len = -1;
13436 } else {
13437 reply_len = os_snprintf(reply, reply_size, "%d", res);
13438 if (os_snprintf_error(reply_size, reply_len))
13439 reply_len = -1;
13440 }
Hai Shalomfdcde762020-04-02 11:19:20 -070013441 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
13442 int res;
13443
13444 res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20);
13445 if (res < 0) {
13446 reply_len = -1;
13447 } else {
13448 reply_len = os_snprintf(reply, reply_size, "%d", res);
13449 if (os_snprintf_error(reply_size, reply_len))
13450 reply_len = -1;
13451 }
13452 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
13453 int res;
13454
13455 res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20);
13456 if (res < 0) {
13457 reply_len = -1;
13458 } else {
13459 reply_len = os_snprintf(reply, reply_size, "%d", res);
13460 if (os_snprintf_error(reply_size, reply_len))
13461 reply_len = -1;
13462 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013463 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
13464 int res;
13465
Hai Shalom021b0b52019-04-10 11:17:58 -070013466 res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013467 if (res < 0) {
13468 reply_len = -1;
13469 } else {
13470 reply_len = os_snprintf(reply, reply_size, "%d", res);
13471 if (os_snprintf_error(reply_size, reply_len))
13472 reply_len = -1;
13473 }
13474 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070013475 if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013476 reply_len = -1;
13477 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
13478 const char *uri;
13479
Hai Shalom021b0b52019-04-10 11:17:58 -070013480 uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013481 if (!uri) {
13482 reply_len = -1;
13483 } else {
13484 reply_len = os_snprintf(reply, reply_size, "%s", uri);
13485 if (os_snprintf_error(reply_size, reply_len))
13486 reply_len = -1;
13487 }
13488 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070013489 reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19),
13490 reply, reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -070013491 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
13492 if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18),
13493 os_strchr(buf + 18, ' ')) < 0)
13494 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013495 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
13496 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
13497 reply_len = -1;
13498 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
13499 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
13500 reply_len = -1;
13501 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -070013502 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013503 wpas_dpp_listen_stop(wpa_s);
13504 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
13505 int res;
13506
Hai Shalom021b0b52019-04-10 11:17:58 -070013507 res = dpp_configurator_add(wpa_s->dpp, buf + 20);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013508 if (res < 0) {
13509 reply_len = -1;
13510 } else {
13511 reply_len = os_snprintf(reply, reply_size, "%d", res);
13512 if (os_snprintf_error(reply_size, reply_len))
13513 reply_len = -1;
13514 }
Sunil Ravia04bd252022-05-02 22:54:18 -070013515 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SET ", 21) == 0) {
13516 if (dpp_configurator_set(wpa_s->dpp, buf + 20) < 0)
13517 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013518 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070013519 if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013520 reply_len = -1;
13521 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -080013522 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013523 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -070013524 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070013525 reply_len = dpp_configurator_get_key_id(wpa_s->dpp,
13526 atoi(buf + 25),
13527 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013528 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
13529 int res;
13530
13531 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
13532 if (res < 0) {
13533 reply_len = -1;
13534 } else {
13535 reply_len = os_snprintf(reply, reply_size, "%d", res);
13536 if (os_snprintf_error(reply_size, reply_len))
13537 reply_len = -1;
13538 }
13539 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
13540 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
13541 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080013542 } else if (os_strncmp(buf, "DPP_CONF_SET ", 13) == 0) {
13543 if (wpas_dpp_conf_set(wpa_s, buf + 12) < 0)
13544 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070013545#ifdef CONFIG_DPP2
13546 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
13547 if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0)
13548 reply_len = -1;
13549 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
13550 if (wpas_dpp_controller_start(wpa_s, NULL) < 0)
13551 reply_len = -1;
13552 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
13553 dpp_controller_stop(wpa_s->dpp);
Hai Shalomfdcde762020-04-02 11:19:20 -070013554 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
13555 if (wpas_dpp_chirp(wpa_s, buf + 9) < 0)
13556 reply_len = -1;
13557 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
13558 wpas_dpp_chirp_stop(wpa_s);
Hai Shalom4fbc08f2020-05-18 12:37:00 -070013559 } else if (os_strncmp(buf, "DPP_RECONFIG ", 13) == 0) {
Hai Shalom899fcc72020-10-19 14:38:18 -070013560 if (wpas_dpp_reconfig(wpa_s, buf + 13) < 0)
13561 reply_len = -1;
13562 } else if (os_strncmp(buf, "DPP_CA_SET ", 11) == 0) {
13563 if (wpas_dpp_ca_set(wpa_s, buf + 10) < 0)
Hai Shalom4fbc08f2020-05-18 12:37:00 -070013564 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070013565#endif /* CONFIG_DPP2 */
Sunil Ravi89eba102022-09-13 21:04:37 -070013566#ifdef CONFIG_DPP3
13567 } else if (os_strcmp(buf, "DPP_PUSH_BUTTON") == 0) {
13568 if (wpas_dpp_push_button(wpa_s, NULL) < 0)
13569 reply_len = -1;
13570 } else if (os_strncmp(buf, "DPP_PUSH_BUTTON ", 16) == 0) {
13571 if (wpas_dpp_push_button(wpa_s, buf + 15) < 0)
13572 reply_len = -1;
13573#endif /* CONFIG_DPP3 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013574#endif /* CONFIG_DPP */
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013575#ifdef CONFIG_NAN_USD
13576 } else if (os_strncmp(buf, "NAN_PUBLISH ", 12) == 0) {
13577 reply_len = wpas_ctrl_nan_publish(wpa_s, buf + 12, reply,
13578 reply_size);
13579 } else if (os_strncmp(buf, "NAN_CANCEL_PUBLISH ", 19) == 0) {
13580 if (wpas_ctrl_nan_cancel_publish(wpa_s, buf + 19) < 0)
Hai Shalom899fcc72020-10-19 14:38:18 -070013581 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013582 } else if (os_strncmp(buf, "NAN_UPDATE_PUBLISH ", 19) == 0) {
13583 if (wpas_ctrl_nan_update_publish(wpa_s, buf + 19) < 0)
13584 reply_len = -1;
13585 } else if (os_strncmp(buf, "NAN_SUBSCRIBE ", 14) == 0) {
13586 reply_len = wpas_ctrl_nan_subscribe(wpa_s, buf + 14, reply,
13587 reply_size);
13588 } else if (os_strncmp(buf, "NAN_CANCEL_SUBSCRIBE ", 21) == 0) {
13589 if (wpas_ctrl_nan_cancel_subscribe(wpa_s, buf + 21) < 0)
13590 reply_len = -1;
13591 } else if (os_strncmp(buf, "NAN_TRANSMIT ", 13) == 0) {
13592 if (wpas_ctrl_nan_transmit(wpa_s, buf + 13) < 0)
13593 reply_len = -1;
13594#endif /* CONFIG_NAN_USD */
Hai Shalom60840252021-02-19 19:02:11 -080013595#ifdef CONFIG_PASN
13596 } else if (os_strncmp(buf, "PASN_START ", 11) == 0) {
13597 if (wpas_ctrl_iface_pasn_start(wpa_s, buf + 11) < 0)
13598 reply_len = -1;
13599 } else if (os_strcmp(buf, "PASN_STOP") == 0) {
13600 wpas_pasn_auth_stop(wpa_s);
13601 } else if (os_strcmp(buf, "PTKSA_CACHE_LIST") == 0) {
13602 reply_len = ptksa_cache_list(wpa_s->ptksa, reply, reply_size);
Hai Shaloma20dcd72022-02-04 13:43:00 -080013603 } else if (os_strncmp(buf, "PASN_DEAUTH ", 12) == 0) {
13604 if (wpas_ctrl_iface_pasn_deauthenticate(wpa_s, buf + 12) < 0)
13605 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013606#ifdef CONFIG_TESTING_OPTIONS
13607 } else if (os_strncmp(buf, "PASN_DRIVER ", 12) == 0) {
13608 if (wpas_ctrl_iface_pasn_driver(wpa_s, buf + 12) < 0)
13609 reply_len = -1;
13610#endif /* CONFIG_TESTING_OPTIONS */
Hai Shalom60840252021-02-19 19:02:11 -080013611#endif /* CONFIG_PASN */
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013612#ifndef CONFIG_NO_ROBUST_AV
13613 } else if (os_strncmp(buf, "MSCS ", 5) == 0) {
13614 if (wpas_ctrl_iface_configure_mscs(wpa_s, buf + 5))
13615 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080013616 } else if (os_strncmp(buf, "SCS ", 4) == 0) {
13617 if (wpas_ctrl_iface_configure_scs(wpa_s, buf + 4))
13618 reply_len = -1;
13619 } else if (os_strncmp(buf, "DSCP_RESP ", 10) == 0) {
13620 if (wpas_ctrl_iface_send_dscp_resp(wpa_s, buf + 10))
13621 reply_len = -1;
13622 } else if (os_strncmp(buf, "DSCP_QUERY ", 11) == 0) {
13623 if (wpas_ctrl_iface_send_dscp_query(wpa_s, buf + 11))
13624 reply_len = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +000013625#endif /* CONFIG_NO_ROBUST_AV */
Sunil Ravi89eba102022-09-13 21:04:37 -070013626 } else if (os_strcmp(buf, "MLO_STATUS") == 0) {
13627 reply_len = wpas_ctrl_iface_mlo_status(wpa_s, reply,
13628 reply_size);
13629 } else if (os_strcmp(buf, "MLO_SIGNAL_POLL") == 0) {
13630 reply_len = wpas_ctrl_iface_mlo_signal_poll(wpa_s, reply,
13631 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013632 } else {
13633 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
13634 reply_len = 16;
13635 }
13636
13637 if (reply_len < 0) {
13638 os_memcpy(reply, "FAIL\n", 5);
13639 reply_len = 5;
13640 }
13641
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013642 *resp_len = reply_len;
13643 return reply;
13644}
13645
13646
13647static int wpa_supplicant_global_iface_add(struct wpa_global *global,
13648 char *cmd)
13649{
13650 struct wpa_interface iface;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013651 char *pos, *extra;
13652 struct wpa_supplicant *wpa_s;
13653 unsigned int create_iface = 0;
13654 u8 mac_addr[ETH_ALEN];
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013655 enum wpa_driver_if_type type = WPA_IF_STATION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013656
13657 /*
13658 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013659 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013660 */
13661 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
13662
13663 os_memset(&iface, 0, sizeof(iface));
13664
13665 do {
13666 iface.ifname = pos = cmd;
13667 pos = os_strchr(pos, '\t');
13668 if (pos)
13669 *pos++ = '\0';
13670 if (iface.ifname[0] == '\0')
13671 return -1;
13672 if (pos == NULL)
13673 break;
13674
13675 iface.confname = pos;
13676 pos = os_strchr(pos, '\t');
13677 if (pos)
13678 *pos++ = '\0';
13679 if (iface.confname[0] == '\0')
13680 iface.confname = NULL;
13681 if (pos == NULL)
13682 break;
13683
13684 iface.driver = pos;
13685 pos = os_strchr(pos, '\t');
13686 if (pos)
13687 *pos++ = '\0';
13688 if (iface.driver[0] == '\0')
13689 iface.driver = NULL;
13690 if (pos == NULL)
13691 break;
13692
13693 iface.ctrl_interface = pos;
13694 pos = os_strchr(pos, '\t');
13695 if (pos)
13696 *pos++ = '\0';
13697 if (iface.ctrl_interface[0] == '\0')
13698 iface.ctrl_interface = NULL;
13699 if (pos == NULL)
13700 break;
13701
13702 iface.driver_param = pos;
13703 pos = os_strchr(pos, '\t');
13704 if (pos)
13705 *pos++ = '\0';
13706 if (iface.driver_param[0] == '\0')
13707 iface.driver_param = NULL;
13708 if (pos == NULL)
13709 break;
13710
13711 iface.bridge_ifname = pos;
13712 pos = os_strchr(pos, '\t');
13713 if (pos)
13714 *pos++ = '\0';
13715 if (iface.bridge_ifname[0] == '\0')
13716 iface.bridge_ifname = NULL;
13717 if (pos == NULL)
13718 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013719
13720 extra = pos;
13721 pos = os_strchr(pos, '\t');
13722 if (pos)
13723 *pos++ = '\0';
Dmitry Shmidt83474442015-04-15 13:47:09 -070013724 if (!extra[0])
13725 break;
13726
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013727 if (os_strcmp(extra, "create") == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013728 create_iface = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013729 if (!pos)
13730 break;
13731
13732 if (os_strcmp(pos, "sta") == 0) {
13733 type = WPA_IF_STATION;
13734 } else if (os_strcmp(pos, "ap") == 0) {
13735 type = WPA_IF_AP_BSS;
13736 } else {
13737 wpa_printf(MSG_DEBUG,
13738 "INTERFACE_ADD unsupported interface type: '%s'",
13739 pos);
13740 return -1;
13741 }
13742 } else {
Dmitry Shmidt83474442015-04-15 13:47:09 -070013743 wpa_printf(MSG_DEBUG,
13744 "INTERFACE_ADD unsupported extra parameter: '%s'",
13745 extra);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013746 return -1;
Dmitry Shmidt83474442015-04-15 13:47:09 -070013747 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013748 } while (0);
13749
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013750 if (create_iface) {
13751 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
13752 iface.ifname);
13753 if (!global->ifaces)
13754 return -1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013755 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013756 NULL, NULL, NULL, mac_addr, NULL) < 0) {
13757 wpa_printf(MSG_ERROR,
13758 "CTRL_IFACE interface creation failed");
13759 return -1;
13760 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013761
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013762 wpa_printf(MSG_DEBUG,
13763 "CTRL_IFACE interface '%s' created with MAC addr: "
13764 MACSTR, iface.ifname, MAC2STR(mac_addr));
13765 }
13766
13767 if (wpa_supplicant_get_iface(global, iface.ifname))
13768 goto fail;
13769
13770 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
13771 if (!wpa_s)
13772 goto fail;
13773 wpa_s->added_vif = create_iface;
13774 return 0;
13775
13776fail:
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000013777 if (create_iface) {
13778 /* wpa_supplicant does not create multi-BSS AP, so collapse to
13779 * WPA_IF_STATION to avoid unwanted clean up in the driver. */
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013780 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000013781 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013782 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013783}
13784
13785
13786static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
13787 char *cmd)
13788{
13789 struct wpa_supplicant *wpa_s;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013790 int ret;
13791 unsigned int delete_iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013792
13793 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
13794
13795 wpa_s = wpa_supplicant_get_iface(global, cmd);
13796 if (wpa_s == NULL)
13797 return -1;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013798 delete_iface = wpa_s->added_vif;
13799 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
13800 if (!ret && delete_iface) {
13801 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
13802 cmd);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000013803 /* wpa_supplicant does not create multi-BSS AP, so collapse to
13804 * WPA_IF_STATION to avoid unwanted clean up in the driver. */
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013805 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
13806 }
13807 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013808}
13809
13810
13811static void wpa_free_iface_info(struct wpa_interface_info *iface)
13812{
13813 struct wpa_interface_info *prev;
13814
13815 while (iface) {
13816 prev = iface;
13817 iface = iface->next;
13818
13819 os_free(prev->ifname);
13820 os_free(prev->desc);
13821 os_free(prev);
13822 }
13823}
13824
13825
13826static int wpa_supplicant_global_iface_list(struct wpa_global *global,
13827 char *buf, int len)
13828{
13829 int i, res;
13830 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
13831 char *pos, *end;
13832
13833 for (i = 0; wpa_drivers[i]; i++) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070013834 const struct wpa_driver_ops *drv = wpa_drivers[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013835 if (drv->get_interfaces == NULL)
13836 continue;
13837 tmp = drv->get_interfaces(global->drv_priv[i]);
13838 if (tmp == NULL)
13839 continue;
13840
13841 if (last == NULL)
13842 iface = last = tmp;
13843 else
13844 last->next = tmp;
13845 while (last->next)
13846 last = last->next;
13847 }
13848
13849 pos = buf;
13850 end = buf + len;
13851 for (tmp = iface; tmp; tmp = tmp->next) {
13852 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
13853 tmp->drv_name, tmp->ifname,
13854 tmp->desc ? tmp->desc : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013855 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013856 *pos = '\0';
13857 break;
13858 }
13859 pos += res;
13860 }
13861
13862 wpa_free_iface_info(iface);
13863
13864 return pos - buf;
13865}
13866
13867
13868static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013869 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013870 char *buf, int len)
13871{
13872 int res;
13873 char *pos, *end;
13874 struct wpa_supplicant *wpa_s;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013875 int show_ctrl = 0;
13876
13877 if (input)
13878 show_ctrl = !!os_strstr(input, "ctrl");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013879
13880 wpa_s = global->ifaces;
13881 pos = buf;
13882 end = buf + len;
13883
13884 while (wpa_s) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013885 if (show_ctrl)
13886 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
13887 wpa_s->ifname,
13888 wpa_s->conf->ctrl_interface ?
13889 wpa_s->conf->ctrl_interface : "N/A");
13890 else
13891 res = os_snprintf(pos, end - pos, "%s\n",
13892 wpa_s->ifname);
13893
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013894 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013895 *pos = '\0';
13896 break;
13897 }
13898 pos += res;
13899 wpa_s = wpa_s->next;
13900 }
13901 return pos - buf;
13902}
13903
13904
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013905static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
13906 const char *ifname,
13907 char *cmd, size_t *resp_len)
13908{
13909 struct wpa_supplicant *wpa_s;
13910
13911 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
13912 if (os_strcmp(ifname, wpa_s->ifname) == 0)
13913 break;
13914 }
13915
13916 if (wpa_s == NULL) {
13917 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
13918 if (resp)
13919 *resp_len = os_strlen(resp);
13920 else
13921 *resp_len = 1;
13922 return resp;
13923 }
13924
13925 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
13926}
13927
13928
13929static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
13930 char *buf, size_t *resp_len)
13931{
13932#ifdef CONFIG_P2P
13933 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070013934 "LIST_NETWORKS",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013935 "P2P_FIND",
13936 "P2P_STOP_FIND",
13937 "P2P_LISTEN",
13938 "P2P_GROUP_ADD",
13939 "P2P_GET_PASSPHRASE",
13940 "P2P_SERVICE_UPDATE",
13941 "P2P_SERVICE_FLUSH",
13942 "P2P_FLUSH",
13943 "P2P_CANCEL",
13944 "P2P_PRESENCE_REQ",
13945 "P2P_EXT_LISTEN",
Paul Stewart092955c2017-02-06 09:13:09 -080013946#ifdef CONFIG_AP
13947 "STA-FIRST",
13948#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013949 NULL
13950 };
13951 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080013952#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070013953 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080013954#endif /* ANDROID */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013955 "GET_CAPABILITY ",
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070013956 "GET_NETWORK ",
13957 "REMOVE_NETWORK ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013958 "P2P_FIND ",
13959 "P2P_CONNECT ",
13960 "P2P_LISTEN ",
13961 "P2P_GROUP_REMOVE ",
13962 "P2P_GROUP_ADD ",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013963 "P2P_GROUP_MEMBER ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013964 "P2P_PROV_DISC ",
13965 "P2P_SERV_DISC_REQ ",
13966 "P2P_SERV_DISC_CANCEL_REQ ",
13967 "P2P_SERV_DISC_RESP ",
13968 "P2P_SERV_DISC_EXTERNAL ",
13969 "P2P_SERVICE_ADD ",
13970 "P2P_SERVICE_DEL ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080013971 "P2P_SERVICE_REP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013972 "P2P_REJECT ",
13973 "P2P_INVITE ",
13974 "P2P_PEER ",
13975 "P2P_SET ",
13976 "P2P_UNAUTHORIZE ",
13977 "P2P_PRESENCE_REQ ",
13978 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070013979 "P2P_REMOVE_CLIENT ",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080013980 "WPS_NFC_TOKEN ",
13981 "WPS_NFC_TAG_READ ",
Dmitry Shmidt413dde72014-04-11 10:23:22 -070013982 "NFC_GET_HANDOVER_SEL ",
13983 "NFC_GET_HANDOVER_REQ ",
13984 "NFC_REPORT_HANDOVER ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080013985 "P2P_ASP_PROVISION ",
13986 "P2P_ASP_PROVISION_RESP ",
Paul Stewart092955c2017-02-06 09:13:09 -080013987#ifdef CONFIG_AP
13988 "STA ",
13989 "STA-NEXT ",
13990#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013991 NULL
13992 };
13993 int found = 0;
13994 int i;
13995
13996 if (global->p2p_init_wpa_s == NULL)
13997 return NULL;
13998
13999 for (i = 0; !found && cmd[i]; i++) {
14000 if (os_strcmp(buf, cmd[i]) == 0)
14001 found = 1;
14002 }
14003
14004 for (i = 0; !found && prefix[i]; i++) {
14005 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
14006 found = 1;
14007 }
14008
14009 if (found)
14010 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
14011 buf, resp_len);
14012#endif /* CONFIG_P2P */
14013 return NULL;
14014}
14015
14016
14017static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
14018 char *buf, size_t *resp_len)
14019{
14020#ifdef CONFIG_WIFI_DISPLAY
14021 if (global->p2p_init_wpa_s == NULL)
14022 return NULL;
14023 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
14024 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
14025 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
14026 buf, resp_len);
14027#endif /* CONFIG_WIFI_DISPLAY */
14028 return NULL;
14029}
14030
14031
14032static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
14033 char *buf, size_t *resp_len)
14034{
14035 char *ret;
14036
14037 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
14038 if (ret)
14039 return ret;
14040
14041 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
14042 if (ret)
14043 return ret;
14044
14045 return NULL;
14046}
14047
14048
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014049static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
14050{
14051 char *value;
14052
14053 value = os_strchr(cmd, ' ');
14054 if (value == NULL)
14055 return -1;
14056 *value++ = '\0';
14057
14058 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
14059
14060#ifdef CONFIG_WIFI_DISPLAY
14061 if (os_strcasecmp(cmd, "wifi_display") == 0) {
14062 wifi_display_enable(global, !!atoi(value));
14063 return 0;
14064 }
14065#endif /* CONFIG_WIFI_DISPLAY */
14066
Dmitry Shmidt61593f02014-04-21 16:27:35 -070014067 /* Restore cmd to its original value to allow redirection */
14068 value[-1] = ' ';
14069
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014070 return -1;
14071}
14072
14073
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080014074static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
14075 char *cmd)
14076{
14077 struct wpa_supplicant *wpa_s[2]; /* src, dst */
14078 char *p;
14079 unsigned int i;
14080
14081 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
14082 * <variable name> */
14083
14084 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
14085 p = os_strchr(cmd, ' ');
14086 if (p == NULL)
14087 return -1;
14088 *p = '\0';
14089
14090 wpa_s[i] = global->ifaces;
14091 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
14092 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
14093 break;
14094 }
14095
14096 if (!wpa_s[i]) {
14097 wpa_printf(MSG_DEBUG,
14098 "CTRL_IFACE: Could not find iface=%s", cmd);
14099 return -1;
14100 }
14101
14102 cmd = p + 1;
14103 }
14104
14105 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
14106}
14107
14108
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014109#ifndef CONFIG_NO_CONFIG_WRITE
14110static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
14111{
Dmitry Shmidt61593f02014-04-21 16:27:35 -070014112 int ret = 0, saved = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014113 struct wpa_supplicant *wpa_s;
14114
14115 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
14116 if (!wpa_s->conf->update_config) {
14117 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
14118 continue;
14119 }
14120
14121 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
14122 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
14123 ret = 1;
14124 } else {
14125 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
Dmitry Shmidt61593f02014-04-21 16:27:35 -070014126 saved++;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014127 }
14128 }
14129
Dmitry Shmidt61593f02014-04-21 16:27:35 -070014130 if (!saved && !ret) {
14131 wpa_dbg(wpa_s, MSG_DEBUG,
14132 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
14133 ret = 1;
14134 }
14135
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014136 return ret;
14137}
14138#endif /* CONFIG_NO_CONFIG_WRITE */
14139
14140
14141static int wpas_global_ctrl_iface_status(struct wpa_global *global,
14142 char *buf, size_t buflen)
14143{
14144 char *pos, *end;
14145 int ret;
14146 struct wpa_supplicant *wpa_s;
14147
14148 pos = buf;
14149 end = buf + buflen;
14150
14151#ifdef CONFIG_P2P
14152 if (global->p2p && !global->p2p_disabled) {
14153 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
14154 "\n"
14155 "p2p_state=%s\n",
14156 MAC2STR(global->p2p_dev_addr),
14157 p2p_get_state_txt(global->p2p));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014158 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014159 return pos - buf;
14160 pos += ret;
14161 } else if (global->p2p) {
14162 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014163 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014164 return pos - buf;
14165 pos += ret;
14166 }
14167#endif /* CONFIG_P2P */
14168
14169#ifdef CONFIG_WIFI_DISPLAY
14170 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
14171 !!global->wifi_display);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014172 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014173 return pos - buf;
14174 pos += ret;
14175#endif /* CONFIG_WIFI_DISPLAY */
14176
14177 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
14178 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
14179 "address=" MACSTR "\n",
14180 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014181 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014182 return pos - buf;
14183 pos += ret;
14184 }
14185
14186 return pos - buf;
14187}
14188
14189
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080014190#ifdef CONFIG_FST
14191
14192static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
14193 char *cmd, char *buf,
14194 size_t reply_size)
14195{
14196 char ifname[IFNAMSIZ + 1];
14197 struct fst_iface_cfg cfg;
14198 struct wpa_supplicant *wpa_s;
14199 struct fst_wpa_obj iface_obj;
14200
14201 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
14202 wpa_s = wpa_supplicant_get_iface(global, ifname);
14203 if (wpa_s) {
14204 if (wpa_s->fst) {
14205 wpa_printf(MSG_INFO, "FST: Already attached");
14206 return -1;
14207 }
14208 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
14209 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
14210 &iface_obj, &cfg);
14211 if (wpa_s->fst)
14212 return os_snprintf(buf, reply_size, "OK\n");
14213 }
14214 }
14215
14216 return -1;
14217}
14218
14219
14220static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
14221 char *cmd, char *buf,
14222 size_t reply_size)
14223{
14224 char ifname[IFNAMSIZ + 1];
14225 struct wpa_supplicant *wpa_s;
14226
14227 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
14228 wpa_s = wpa_supplicant_get_iface(global, ifname);
14229 if (wpa_s) {
14230 if (!fst_iface_detach(ifname)) {
14231 wpa_s->fst = NULL;
14232 return os_snprintf(buf, reply_size, "OK\n");
14233 }
14234 }
14235 }
14236
14237 return -1;
14238}
14239
14240#endif /* CONFIG_FST */
14241
14242
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014243char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
14244 char *buf, size_t *resp_len)
14245{
14246 char *reply;
14247 const int reply_size = 2048;
14248 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014249 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014250
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070014251 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
14252 char *pos = os_strchr(buf + 7, ' ');
14253 if (pos) {
14254 *pos++ = '\0';
14255 return wpas_global_ctrl_iface_ifname(global,
14256 buf + 7, pos,
14257 resp_len);
14258 }
14259 }
14260
14261 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
14262 if (reply)
14263 return reply;
14264
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014265 if (os_strcmp(buf, "PING") == 0)
14266 level = MSG_EXCESSIVE;
14267 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014268 (const u8 *) buf, os_strlen(buf));
14269
14270 reply = os_malloc(reply_size);
14271 if (reply == NULL) {
14272 *resp_len = 1;
14273 return NULL;
14274 }
14275
14276 os_memcpy(reply, "OK\n", 3);
14277 reply_len = 3;
14278
14279 if (os_strcmp(buf, "PING") == 0) {
14280 os_memcpy(reply, "PONG\n", 5);
14281 reply_len = 5;
14282 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
14283 if (wpa_supplicant_global_iface_add(global, buf + 14))
14284 reply_len = -1;
14285 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
14286 if (wpa_supplicant_global_iface_remove(global, buf + 17))
14287 reply_len = -1;
14288 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
14289 reply_len = wpa_supplicant_global_iface_list(
14290 global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080014291 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014292 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080014293 global, buf + 10, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080014294#ifdef CONFIG_FST
14295 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
14296 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
14297 reply,
14298 reply_size);
14299 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
14300 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
14301 reply,
14302 reply_size);
14303 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
14304 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
14305#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014306 } else if (os_strcmp(buf, "TERMINATE") == 0) {
14307 wpa_supplicant_terminate_proc(global);
14308 } else if (os_strcmp(buf, "SUSPEND") == 0) {
14309 wpas_notify_suspend(global);
14310 } else if (os_strcmp(buf, "RESUME") == 0) {
14311 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014312 } else if (os_strncmp(buf, "SET ", 4) == 0) {
Dmitry Shmidt61593f02014-04-21 16:27:35 -070014313 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
14314#ifdef CONFIG_P2P
14315 if (global->p2p_init_wpa_s) {
14316 os_free(reply);
14317 /* Check if P2P redirection would work for this
14318 * command. */
14319 return wpa_supplicant_ctrl_iface_process(
14320 global->p2p_init_wpa_s,
14321 buf, resp_len);
14322 }
14323#endif /* CONFIG_P2P */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014324 reply_len = -1;
Dmitry Shmidt61593f02014-04-21 16:27:35 -070014325 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080014326 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
14327 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
14328 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070014329#ifndef CONFIG_NO_CONFIG_WRITE
14330 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
14331 if (wpas_global_ctrl_iface_save_config(global))
14332 reply_len = -1;
14333#endif /* CONFIG_NO_CONFIG_WRITE */
14334 } else if (os_strcmp(buf, "STATUS") == 0) {
14335 reply_len = wpas_global_ctrl_iface_status(global, reply,
14336 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080014337#ifdef CONFIG_MODULE_TESTS
14338 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080014339 if (wpas_module_tests() < 0)
14340 reply_len = -1;
14341#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080014342 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
14343 if (wpa_debug_reopen_file() < 0)
14344 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014345 } else {
14346 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
14347 reply_len = 16;
14348 }
14349
14350 if (reply_len < 0) {
14351 os_memcpy(reply, "FAIL\n", 5);
14352 reply_len = 5;
14353 }
14354
14355 *resp_len = reply_len;
14356 return reply;
14357}