blob: a68802e4935cca5e01dd0138b19421c0de95f4a5 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant / Control interface (shared code for all backends)
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003 * Copyright (c) 2004-2020, 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 */
Hai Shalom60840252021-02-19 19:02:11 -080025#include "common/ptksa_cache.h"
Dmitry Shmidtff787d52015-01-12 13:01:47 -080026#include "crypto/tls.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080027#include "ap/hostapd.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "eap_peer/eap.h"
29#include "eapol_supp/eapol_supp_sm.h"
30#include "rsn_supp/wpa.h"
31#include "rsn_supp/preauth.h"
32#include "rsn_supp/pmksa_cache.h"
33#include "l2_packet/l2_packet.h"
34#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080035#include "fst/fst.h"
36#include "fst/fst_ctrl_iface.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "config.h"
38#include "wpa_supplicant_i.h"
39#include "driver_i.h"
40#include "wps_supplicant.h"
41#include "ibss_rsn.h"
Hai Shaloma20dcd72022-02-04 13:43:00 -080042#include "wpas_glue.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "ap.h"
44#include "p2p_supplicant.h"
45#include "p2p/p2p.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070046#include "hs20_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070047#include "wifi_display.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070048#include "notify.h"
49#include "bss.h"
50#include "scan.h"
51#include "ctrl_iface.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080052#include "interworking.h"
Hai Shalom60840252021-02-19 19:02:11 -080053#include "bssid_ignore.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070054#include "autoscan.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080055#include "wnm_sta.h"
Dmitry Shmidt818ea482014-03-10 13:15:21 -070056#include "offchannel.h"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070057#include "drivers/driver.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080058#include "mesh.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070059#include "dpp_supplicant.h"
Hai Shalom74f70d42019-02-11 14:42:39 -080060#include "sme.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070061
Hai Shalomc3565922019-10-28 11:58:20 -070062#ifdef __NetBSD__
63#include <net/if_ether.h>
64#elif !defined(__CYGWIN__) && !defined(CONFIG_NATIVE_WINDOWS)
65#include <net/ethernet.h>
66#endif
67
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070068static int wpa_supplicant_global_iface_list(struct wpa_global *global,
69 char *buf, int len);
70static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080071 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070072 char *buf, int len);
Dmitry Shmidtd11f0192014-03-24 12:09:47 -070073static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
74 char *val);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070075
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070076
Dmitry Shmidt04949592012-07-19 12:16:46 -070077static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
78{
79 char *pos;
80 u8 addr[ETH_ALEN], *filter = NULL, *n;
81 size_t count = 0;
82
83 pos = val;
84 while (pos) {
85 if (*pos == '\0')
86 break;
87 if (hwaddr_aton(pos, addr)) {
88 os_free(filter);
89 return -1;
90 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070091 n = os_realloc_array(filter, count + 1, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -070092 if (n == NULL) {
93 os_free(filter);
94 return -1;
95 }
96 filter = n;
97 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
98 count++;
99
100 pos = os_strchr(pos, ' ');
101 if (pos)
102 pos++;
103 }
104
105 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
106 os_free(wpa_s->bssid_filter);
107 wpa_s->bssid_filter = filter;
108 wpa_s->bssid_filter_count = count;
109
110 return 0;
111}
112
113
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800114static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
115{
116 char *pos;
117 u8 addr[ETH_ALEN], *bssid = NULL, *n;
118 struct wpa_ssid_value *ssid = NULL, *ns;
119 size_t count = 0, ssid_count = 0;
120 struct wpa_ssid *c;
121
122 /*
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800123 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800124 * SSID_SPEC ::= ssid <SSID_HEX>
125 * BSSID_SPEC ::= bssid <BSSID_HEX>
126 */
127
128 pos = val;
129 while (pos) {
130 if (*pos == '\0')
131 break;
132 if (os_strncmp(pos, "bssid ", 6) == 0) {
133 int res;
134 pos += 6;
135 res = hwaddr_aton2(pos, addr);
136 if (res < 0) {
137 os_free(ssid);
138 os_free(bssid);
139 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
140 "BSSID value '%s'", pos);
141 return -1;
142 }
143 pos += res;
144 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
145 if (n == NULL) {
146 os_free(ssid);
147 os_free(bssid);
148 return -1;
149 }
150 bssid = n;
151 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
152 count++;
153 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
154 char *end;
155 pos += 5;
156
157 end = pos;
158 while (*end) {
159 if (*end == '\0' || *end == ' ')
160 break;
161 end++;
162 }
163
164 ns = os_realloc_array(ssid, ssid_count + 1,
165 sizeof(struct wpa_ssid_value));
166 if (ns == NULL) {
167 os_free(ssid);
168 os_free(bssid);
169 return -1;
170 }
171 ssid = ns;
172
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700173 if ((end - pos) & 0x01 ||
174 end - pos > 2 * SSID_MAX_LEN ||
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800175 hexstr2bin(pos, ssid[ssid_count].ssid,
176 (end - pos) / 2) < 0) {
177 os_free(ssid);
178 os_free(bssid);
179 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
180 "SSID value '%s'", pos);
181 return -1;
182 }
183 ssid[ssid_count].ssid_len = (end - pos) / 2;
184 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
185 ssid[ssid_count].ssid,
186 ssid[ssid_count].ssid_len);
187 ssid_count++;
188 pos = end;
189 } else {
190 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
191 "'%s'", pos);
192 os_free(ssid);
193 os_free(bssid);
194 return -1;
195 }
196
197 pos = os_strchr(pos, ' ');
198 if (pos)
199 pos++;
200 }
201
202 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
203 os_free(wpa_s->disallow_aps_bssid);
204 wpa_s->disallow_aps_bssid = bssid;
205 wpa_s->disallow_aps_bssid_count = count;
206
207 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
208 os_free(wpa_s->disallow_aps_ssid);
209 wpa_s->disallow_aps_ssid = ssid;
210 wpa_s->disallow_aps_ssid_count = ssid_count;
211
212 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
213 return 0;
214
215 c = wpa_s->current_ssid;
216 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
217 return 0;
218
219 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
220 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
221 return 0;
222
223 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
224 "because current AP was marked disallowed");
225
226#ifdef CONFIG_SME
227 wpa_s->sme.prev_bssid_set = 0;
228#endif /* CONFIG_SME */
229 wpa_s->reassociate = 1;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800230 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800231 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
232 wpa_supplicant_req_scan(wpa_s, 0, 0);
233
234 return 0;
235}
236
237
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700238#ifndef CONFIG_NO_CONFIG_BLOBS
239static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
240{
241 char *name = pos;
242 struct wpa_config_blob *blob;
243 size_t len;
244
245 pos = os_strchr(pos, ' ');
246 if (pos == NULL)
247 return -1;
248 *pos++ = '\0';
249 len = os_strlen(pos);
250 if (len & 1)
251 return -1;
252
253 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
254 blob = os_zalloc(sizeof(*blob));
255 if (blob == NULL)
256 return -1;
257 blob->name = os_strdup(name);
258 blob->data = os_malloc(len / 2);
259 if (blob->name == NULL || blob->data == NULL) {
260 wpa_config_free_blob(blob);
261 return -1;
262 }
263
264 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
265 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
266 wpa_config_free_blob(blob);
267 return -1;
268 }
269 blob->len = len / 2;
270
271 wpa_config_set_blob(wpa_s->conf, blob);
272
273 return 0;
274}
275#endif /* CONFIG_NO_CONFIG_BLOBS */
276
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700277
278static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
279{
280 char *params;
281 char *pos;
282 int *freqs = NULL;
283 int ret;
284
285 if (atoi(cmd)) {
286 params = os_strchr(cmd, ' ');
287 os_free(wpa_s->manual_sched_scan_freqs);
288 if (params) {
289 params++;
290 pos = os_strstr(params, "freq=");
291 if (pos)
292 freqs = freq_range_to_channel_list(wpa_s,
293 pos + 5);
294 }
295 wpa_s->manual_sched_scan_freqs = freqs;
296 ret = wpas_start_pno(wpa_s);
297 } else {
298 ret = wpas_stop_pno(wpa_s);
299 }
300 return ret;
301}
302
303
Hai Shalom60840252021-02-19 19:02:11 -0800304static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *bands)
Ravi Joshie6ccb162015-07-16 17:45:41 -0700305{
306 union wpa_event_data event;
Hai Shalom60840252021-02-19 19:02:11 -0800307 u32 setband_mask = WPA_SETBAND_AUTO;
Ravi Joshie6ccb162015-07-16 17:45:41 -0700308
Hai Shalom60840252021-02-19 19:02:11 -0800309 /*
310 * For example:
311 * SET setband 2G,6G
312 * SET setband 5G
313 * SET setband AUTO
314 */
315 if (!os_strstr(bands, "AUTO")) {
316 if (os_strstr(bands, "5G"))
317 setband_mask |= WPA_SETBAND_5G;
318 if (os_strstr(bands, "6G"))
319 setband_mask |= WPA_SETBAND_6G;
320 if (os_strstr(bands, "2G"))
321 setband_mask |= WPA_SETBAND_2G;
322 if (setband_mask == WPA_SETBAND_AUTO)
323 return -1;
324 }
Ravi Joshie6ccb162015-07-16 17:45:41 -0700325
Hai Shalom60840252021-02-19 19:02:11 -0800326 wpa_s->setband_mask = setband_mask;
327 if (wpa_drv_setband(wpa_s, wpa_s->setband_mask) == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700328 os_memset(&event, 0, sizeof(event));
329 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
330 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
331 wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
332 }
333
334 return 0;
335}
336
337
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700338static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s,
339 const char *cmd)
340{
341 struct wpabuf *lci;
342
343 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
344 wpabuf_free(wpa_s->lci);
345 wpa_s->lci = NULL;
346 return 0;
347 }
348
349 lci = wpabuf_parse_bin(cmd);
350 if (!lci)
351 return -1;
352
353 if (os_get_reltime(&wpa_s->lci_time)) {
354 wpabuf_free(lci);
355 return -1;
356 }
357
358 wpabuf_free(wpa_s->lci);
359 wpa_s->lci = lci;
360
361 return 0;
362}
363
364
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800365static int
366wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd)
367{
368 int relative_rssi;
369
370 if (os_strcmp(cmd, "disable") == 0) {
371 wpa_s->srp.relative_rssi_set = 0;
372 return 0;
373 }
374
375 relative_rssi = atoi(cmd);
376 if (relative_rssi < 0 || relative_rssi > 100)
377 return -1;
378 wpa_s->srp.relative_rssi = relative_rssi;
379 wpa_s->srp.relative_rssi_set = 1;
380 return 0;
381}
382
383
384static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s,
385 const char *cmd)
386{
387 char *pos;
388 int adjust_rssi;
389
390 /* <band>:adjust_value */
391 pos = os_strchr(cmd, ':');
392 if (!pos)
393 return -1;
394 pos++;
395 adjust_rssi = atoi(pos);
396 if (adjust_rssi < -100 || adjust_rssi > 100)
397 return -1;
398
399 if (os_strncmp(cmd, "2G", 2) == 0)
400 wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G;
401 else if (os_strncmp(cmd, "5G", 2) == 0)
402 wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G;
403 else
404 return -1;
405
406 wpa_s->srp.relative_adjust_rssi = adjust_rssi;
407
408 return 0;
409}
410
411
412static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s,
413 const char *cmd)
414{
415 struct wpabuf *ric_ies;
416
417 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
418 wpabuf_free(wpa_s->ric_ies);
419 wpa_s->ric_ies = NULL;
420 return 0;
421 }
422
423 ric_ies = wpabuf_parse_bin(cmd);
424 if (!ric_ies)
425 return -1;
426
427 wpabuf_free(wpa_s->ric_ies);
428 wpa_s->ric_ies = ric_ies;
429
430 return 0;
431}
432
433
Hai Shalomfdcde762020-04-02 11:19:20 -0700434#ifdef CONFIG_TESTING_OPTIONS
435static int wpas_ctrl_iface_set_dso(struct wpa_supplicant *wpa_s,
436 const char *val)
437{
438 u8 bssid[ETH_ALEN];
439 const char *pos = val;
440 struct driver_signal_override *dso = NULL, *tmp, parsed;
441
442 if (hwaddr_aton(pos, bssid))
443 return -1;
444 pos = os_strchr(pos, ' ');
445
446 dl_list_for_each(tmp, &wpa_s->drv_signal_override,
447 struct driver_signal_override, list) {
448 if (os_memcmp(bssid, tmp->bssid, ETH_ALEN) == 0) {
449 dso = tmp;
450 break;
451 }
452 }
453
454 if (!pos) {
455 /* Remove existing entry */
456 if (dso) {
457 dl_list_del(&dso->list);
458 os_free(dso);
459 }
460 return 0;
461 }
462 pos++;
463
464 /* Update an existing entry or add a new one */
465 os_memset(&parsed, 0, sizeof(parsed));
466 if (sscanf(pos, "%d %d %d %d %d",
467 &parsed.si_current_signal,
468 &parsed.si_avg_signal,
469 &parsed.si_avg_beacon_signal,
470 &parsed.si_current_noise,
471 &parsed.scan_level) != 5)
472 return -1;
473
474 if (!dso) {
475 dso = os_zalloc(sizeof(*dso));
476 if (!dso)
477 return -1;
478 os_memcpy(dso->bssid, bssid, ETH_ALEN);
479 dl_list_add(&wpa_s->drv_signal_override, &dso->list);
480 }
481 dso->si_current_signal = parsed.si_current_signal;
482 dso->si_avg_signal = parsed.si_avg_signal;
483 dso->si_avg_beacon_signal = parsed.si_avg_beacon_signal;
484 dso->si_current_noise = parsed.si_current_noise;
485 dso->scan_level = parsed.scan_level;
486
487 return 0;
488}
489#endif /* CONFIG_TESTING_OPTIONS */
490
491
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700492static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
493 char *cmd)
494{
495 char *value;
496 int ret = 0;
497
498 value = os_strchr(cmd, ' ');
499 if (value == NULL)
500 return -1;
501 *value++ = '\0';
502
503 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
504 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
505 eapol_sm_configure(wpa_s->eapol,
506 atoi(value), -1, -1, -1);
507 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
508 eapol_sm_configure(wpa_s->eapol,
509 -1, atoi(value), -1, -1);
510 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
511 eapol_sm_configure(wpa_s->eapol,
512 -1, -1, atoi(value), -1);
513 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
514 eapol_sm_configure(wpa_s->eapol,
515 -1, -1, -1, atoi(value));
Hai Shaloma20dcd72022-02-04 13:43:00 -0800516#ifdef CONFIG_TESTING_OPTIONS
517 } else if (os_strcasecmp(cmd, "EAPOL::portControl") == 0) {
518 if (os_strcmp(value, "Auto") == 0)
519 eapol_sm_notify_portControl(wpa_s->eapol, Auto);
520 else if (os_strcmp(value, "ForceUnauthorized") == 0)
521 eapol_sm_notify_portControl(wpa_s->eapol,
522 ForceUnauthorized);
523 else if (os_strcmp(value, "ForceAuthorized") == 0)
524 eapol_sm_notify_portControl(wpa_s->eapol,
525 ForceAuthorized);
526 else
527 ret = -1;
528#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
530 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
Paul Stewart092955c2017-02-06 09:13:09 -0800531 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700532 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800533 } else {
534 value[-1] = '=';
535 wpa_config_process_global(wpa_s->conf, cmd, -1);
536 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700537 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
538 0) {
539 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
Paul Stewart092955c2017-02-06 09:13:09 -0800540 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800542 } else {
543 value[-1] = '=';
544 wpa_config_process_global(wpa_s->conf, cmd, -1);
545 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700546 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
Paul Stewart092955c2017-02-06 09:13:09 -0800547 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
548 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700549 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800550 } else {
551 value[-1] = '=';
552 wpa_config_process_global(wpa_s->conf, cmd, -1);
553 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700554 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
555 wpa_s->wps_fragment_size = atoi(value);
556#ifdef CONFIG_WPS_TESTING
557 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
558 long int val;
559 val = strtol(value, NULL, 0);
560 if (val < 0 || val > 0xff) {
561 ret = -1;
562 wpa_printf(MSG_DEBUG, "WPS: Invalid "
563 "wps_version_number %ld", val);
564 } else {
565 wps_version_number = val;
566 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
567 "version %u.%u",
568 (wps_version_number & 0xf0) >> 4,
569 wps_version_number & 0x0f);
570 }
Hai Shaloma20dcd72022-02-04 13:43:00 -0800571 } else if (os_strcasecmp(cmd, "wps_testing_stub_cred") == 0) {
572 wps_testing_stub_cred = atoi(value);
573 wpa_printf(MSG_DEBUG, "WPS: Testing - stub_cred=%d",
574 wps_testing_stub_cred);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800575 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
576 wps_corrupt_pkhash = atoi(value);
577 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
578 wps_corrupt_pkhash);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800579 } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
580 if (value[0] == '\0') {
581 wps_force_auth_types_in_use = 0;
582 } else {
583 wps_force_auth_types = strtol(value, NULL, 0);
584 wps_force_auth_types_in_use = 1;
585 }
586 } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
587 if (value[0] == '\0') {
588 wps_force_encr_types_in_use = 0;
589 } else {
590 wps_force_encr_types = strtol(value, NULL, 0);
591 wps_force_encr_types_in_use = 1;
592 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700593#endif /* CONFIG_WPS_TESTING */
594 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
595 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
596 ret = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800597#ifdef CONFIG_TDLS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700598#ifdef CONFIG_TDLS_TESTING
599 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700600 tdls_testing = strtol(value, NULL, 0);
601 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
602#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700603 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
604 int disabled = atoi(value);
605 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
606 if (disabled) {
607 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
608 ret = -1;
609 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
610 ret = -1;
611 wpa_tdls_enable(wpa_s->wpa, !disabled);
612#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800613 } else if (os_strcasecmp(cmd, "pno") == 0) {
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700614 ret = wpas_ctrl_pno(wpa_s, value);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700615 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
616 int disabled = atoi(value);
617 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
618 ret = -1;
619 else if (disabled)
620 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
621 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
622 if (os_strcmp(value, "disable") == 0)
623 wpa_s->set_sta_uapsd = 0;
624 else {
625 int be, bk, vi, vo;
626 char *pos;
627 /* format: BE,BK,VI,VO;max SP Length */
628 be = atoi(value);
629 pos = os_strchr(value, ',');
630 if (pos == NULL)
631 return -1;
632 pos++;
633 bk = atoi(pos);
634 pos = os_strchr(pos, ',');
635 if (pos == NULL)
636 return -1;
637 pos++;
638 vi = atoi(pos);
639 pos = os_strchr(pos, ',');
640 if (pos == NULL)
641 return -1;
642 pos++;
643 vo = atoi(pos);
644 /* ignore max SP Length for now */
645
646 wpa_s->set_sta_uapsd = 1;
647 wpa_s->sta_uapsd = 0;
648 if (be)
649 wpa_s->sta_uapsd |= BIT(0);
650 if (bk)
651 wpa_s->sta_uapsd |= BIT(1);
652 if (vi)
653 wpa_s->sta_uapsd |= BIT(2);
654 if (vo)
655 wpa_s->sta_uapsd |= BIT(3);
656 }
Jouni Malinen21d6bc82012-04-10 16:17:59 -0700657 } else if (os_strcasecmp(cmd, "ps") == 0) {
658 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700659#ifdef CONFIG_WIFI_DISPLAY
660 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800661 int enabled = !!atoi(value);
662 if (enabled && !wpa_s->global->p2p)
663 ret = -1;
664 else
665 wifi_display_enable(wpa_s->global, enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700666#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700667 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
668 ret = set_bssid_filter(wpa_s, value);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800669 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
670 ret = set_disallow_aps(wpa_s, value);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800671 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
672 wpa_s->no_keep_alive = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700673#ifdef CONFIG_DPP
674 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
675 os_free(wpa_s->dpp_configurator_params);
676 wpa_s->dpp_configurator_params = os_strdup(value);
Sunil Ravia04bd252022-05-02 22:54:18 -0700677#ifdef CONFIG_DPP2
678 dpp_controller_set_params(wpa_s->dpp, value);
679#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700680 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
681 wpa_s->dpp_init_max_tries = atoi(value);
682 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
683 wpa_s->dpp_init_retry_time = atoi(value);
684 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
685 wpa_s->dpp_resp_wait_time = atoi(value);
686 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
687 wpa_s->dpp_resp_max_tries = atoi(value);
688 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
689 wpa_s->dpp_resp_retry_time = atoi(value);
690#ifdef CONFIG_TESTING_OPTIONS
691 } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
692 if (hwaddr_aton(value, dpp_pkex_own_mac_override))
693 ret = -1;
694 } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
695 if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
696 ret = -1;
697 } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
698 size_t hex_len = os_strlen(value);
699
700 if (hex_len >
701 2 * sizeof(dpp_pkex_ephemeral_key_override))
702 ret = -1;
703 else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
704 hex_len / 2))
705 ret = -1;
706 else
707 dpp_pkex_ephemeral_key_override_len = hex_len / 2;
708 } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) {
709 size_t hex_len = os_strlen(value);
710
711 if (hex_len > 2 * sizeof(dpp_protocol_key_override))
712 ret = -1;
713 else if (hexstr2bin(value, dpp_protocol_key_override,
714 hex_len / 2))
715 ret = -1;
716 else
717 dpp_protocol_key_override_len = hex_len / 2;
718 } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) {
719 size_t hex_len = os_strlen(value);
720
721 if (hex_len > 2 * sizeof(dpp_nonce_override))
722 ret = -1;
723 else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2))
724 ret = -1;
725 else
726 dpp_nonce_override_len = hex_len / 2;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700727 } else if (os_strcasecmp(cmd, "dpp_version_override") == 0) {
728 dpp_version_override = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700729#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700730#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700731#ifdef CONFIG_TESTING_OPTIONS
732 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
733 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800734 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
735 wpa_s->ext_eapol_frame_io = !!atoi(value);
736#ifdef CONFIG_AP
737 if (wpa_s->ap_iface) {
738 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
739 wpa_s->ext_eapol_frame_io;
740 }
741#endif /* CONFIG_AP */
742 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
743 wpa_s->extra_roc_dur = atoi(value);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800744 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
745 wpa_s->test_failure = atoi(value);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800746 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
747 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700748 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
749 wpa_s->ignore_auth_resp = !!atoi(value);
750 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
751 wpa_s->ignore_assoc_disallow = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700752 wpa_drv_ignore_assoc_disallow(wpa_s,
753 wpa_s->ignore_assoc_disallow);
Hai Shalomfdcde762020-04-02 11:19:20 -0700754 } else if (os_strcasecmp(cmd, "disable_sa_query") == 0) {
755 wpa_s->disable_sa_query = !!atoi(value);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800756 } else if (os_strcasecmp(cmd, "ignore_sae_h2e_only") == 0) {
757 wpa_s->ignore_sae_h2e_only = !!atoi(value);
758 } else if (os_strcasecmp(cmd, "extra_sae_rejected_groups") == 0) {
759 char *pos;
760
761 os_free(wpa_s->extra_sae_rejected_groups);
762 wpa_s->extra_sae_rejected_groups = NULL;
763 pos = value;
764 while (pos && pos[0]) {
765 int group;
766
767 group = atoi(pos);
768 wpa_printf(MSG_DEBUG,
769 "TESTING: Extra rejection of SAE group %d",
770 group);
771 if (group)
772 int_array_add_unique(
773 &wpa_s->extra_sae_rejected_groups,
774 group);
775 pos = os_strchr(pos, ' ');
776 if (!pos)
777 break;
778 pos++;
779 }
Hai Shalomb755a2a2020-04-23 21:49:02 -0700780 } else if (os_strcasecmp(cmd, "ft_rsnxe_used") == 0) {
781 wpa_s->ft_rsnxe_used = atoi(value);
Hai Shalom899fcc72020-10-19 14:38:18 -0700782 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol") == 0) {
783 wpa_s->oci_freq_override_eapol = atoi(value);
784 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_req") == 0) {
785 wpa_s->oci_freq_override_saquery_req = atoi(value);
786 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_resp") == 0) {
787 wpa_s->oci_freq_override_saquery_resp = atoi(value);
788 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol_g2") == 0) {
789 wpa_s->oci_freq_override_eapol_g2 = atoi(value);
790 /* Populate value to wpa_sm if already associated. */
791 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_EAPOL_G2,
792 wpa_s->oci_freq_override_eapol_g2);
793 } else if (os_strcasecmp(cmd, "oci_freq_override_ft_assoc") == 0) {
794 wpa_s->oci_freq_override_ft_assoc = atoi(value);
795 /* Populate value to wpa_sm if already associated. */
796 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_FT_ASSOC,
797 wpa_s->oci_freq_override_ft_assoc);
798 } else if (os_strcasecmp(cmd, "oci_freq_override_fils_assoc") == 0) {
799 wpa_s->oci_freq_override_fils_assoc = atoi(value);
800 } else if (os_strcasecmp(cmd, "oci_freq_override_wnm_sleep") == 0) {
801 wpa_s->oci_freq_override_wnm_sleep = atoi(value);
Hai Shalomfdcde762020-04-02 11:19:20 -0700802 } else if (os_strcasecmp(cmd, "rsne_override_eapol") == 0) {
803 wpabuf_free(wpa_s->rsne_override_eapol);
804 if (os_strcmp(value, "NULL") == 0)
805 wpa_s->rsne_override_eapol = NULL;
806 else
807 wpa_s->rsne_override_eapol = wpabuf_parse_bin(value);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800808 } else if (os_strcasecmp(cmd, "rsnxe_override_assoc") == 0) {
809 wpabuf_free(wpa_s->rsnxe_override_assoc);
810 if (os_strcmp(value, "NULL") == 0)
811 wpa_s->rsnxe_override_assoc = NULL;
812 else
813 wpa_s->rsnxe_override_assoc = wpabuf_parse_bin(value);
814 } else if (os_strcasecmp(cmd, "rsnxe_override_eapol") == 0) {
815 wpabuf_free(wpa_s->rsnxe_override_eapol);
816 if (os_strcmp(value, "NULL") == 0)
817 wpa_s->rsnxe_override_eapol = NULL;
818 else
819 wpa_s->rsnxe_override_eapol = wpabuf_parse_bin(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700820 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
821 wpa_s->reject_btm_req_reason = atoi(value);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800822 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
823 os_free(wpa_s->get_pref_freq_list_override);
824 if (!value[0])
825 wpa_s->get_pref_freq_list_override = NULL;
826 else
827 wpa_s->get_pref_freq_list_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700828 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
829 wpabuf_free(wpa_s->sae_commit_override);
830 if (value[0] == '\0')
831 wpa_s->sae_commit_override = NULL;
832 else
833 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
Hai Shalomfdcde762020-04-02 11:19:20 -0700834 } else if (os_strcasecmp(cmd, "driver_signal_override") == 0) {
835 ret = wpas_ctrl_iface_set_dso(wpa_s, value);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800836 } else if (os_strcasecmp(cmd, "disable_scs_support") == 0) {
837 wpa_s->disable_scs_support = !!atoi(value);
838 } else if (os_strcasecmp(cmd, "disable_mscs_support") == 0) {
839 wpa_s->disable_mscs_support = !!atoi(value);
Sunil Ravia04bd252022-05-02 22:54:18 -0700840 } else if (os_strcasecmp(cmd, "disable_eapol_g2_tx") == 0) {
841 wpa_s->disable_eapol_g2_tx = !!atoi(value);
842 /* Populate value to wpa_sm if already associated. */
843 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_DISABLE_EAPOL_G2_TX,
844 wpa_s->disable_eapol_g2_tx);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700845#ifdef CONFIG_DPP
846 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
847 os_free(wpa_s->dpp_config_obj_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700848 if (value[0] == '\0')
849 wpa_s->dpp_config_obj_override = NULL;
850 else
851 wpa_s->dpp_config_obj_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700852 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
853 os_free(wpa_s->dpp_discovery_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700854 if (value[0] == '\0')
855 wpa_s->dpp_discovery_override = NULL;
856 else
857 wpa_s->dpp_discovery_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700858 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
859 os_free(wpa_s->dpp_groups_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700860 if (value[0] == '\0')
861 wpa_s->dpp_groups_override = NULL;
862 else
863 wpa_s->dpp_groups_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700864 } else if (os_strcasecmp(cmd,
865 "dpp_ignore_netaccesskey_mismatch") == 0) {
866 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
Sunil8cd6f4d2022-06-28 18:40:46 +0000867 } else if (os_strcasecmp(cmd, "dpp_discard_public_action") == 0) {
868 wpa_s->dpp_discard_public_action = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700869 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
870 dpp_test = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700871#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700872#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700873#ifdef CONFIG_FILS
874 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
875 wpa_s->disable_fils = !!atoi(value);
876 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
877 wpa_supplicant_set_default_scan_ies(wpa_s);
878#endif /* CONFIG_FILS */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700879#ifndef CONFIG_NO_CONFIG_BLOBS
880 } else if (os_strcmp(cmd, "blob") == 0) {
881 ret = wpas_ctrl_set_blob(wpa_s, value);
882#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800883 } else if (os_strcasecmp(cmd, "setband") == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700884 ret = wpas_ctrl_set_band(wpa_s, value);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800885#ifdef CONFIG_MBO
886 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
887 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
Paul Stewart092955c2017-02-06 09:13:09 -0800888 if (ret == 0) {
889 value[-1] = '=';
890 wpa_config_process_global(wpa_s->conf, cmd, -1);
891 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800892 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
893 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700894 } else if (os_strcasecmp(cmd, "oce") == 0) {
895 wpa_s->conf->oce = atoi(value);
896 if (wpa_s->conf->oce) {
897 if ((wpa_s->conf->oce & OCE_STA) &&
898 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
899 wpa_s->enable_oce = OCE_STA;
900
901 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
902 (wpa_s->drv_flags &
903 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
904 /* TODO: Need to add STA-CFON support */
905 wpa_printf(MSG_ERROR,
906 "OCE STA-CFON feature is not yet supported");
907 return -1;
908 }
909 } else {
910 wpa_s->enable_oce = 0;
911 }
912 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800913#endif /* CONFIG_MBO */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700914 } else if (os_strcasecmp(cmd, "lci") == 0) {
915 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800916 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
917 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800918 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
919 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
920 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
921 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
922 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
923 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700924 } else if (os_strcasecmp(cmd, "roaming") == 0) {
925 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800926#ifdef CONFIG_WNM
927 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
928 struct wpabuf *elems;
929
930 elems = wpabuf_parse_bin(value);
931 if (!elems)
932 return -1;
933 wnm_set_coloc_intf_elems(wpa_s, elems);
934#endif /* CONFIG_WNM */
Hai Shaloma20dcd72022-02-04 13:43:00 -0800935 } else if (os_strcasecmp(cmd, "enable_dscp_policy_capa") == 0) {
936 wpa_s->enable_dscp_policy_capa = !!atoi(value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700937 } else {
938 value[-1] = '=';
939 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
940 if (ret == 0)
941 wpa_supplicant_update_config(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -0700942 else if (ret == 1)
943 ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700944 }
945
946 return ret;
947}
948
949
950static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
951 char *cmd, char *buf, size_t buflen)
952{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700953 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700954
955 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
956
957 if (os_strcmp(cmd, "version") == 0) {
958 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700959 } else if (os_strcasecmp(cmd, "max_command_len") == 0) {
960 res = os_snprintf(buf, buflen, "%u", CTRL_IFACE_MAX_LEN);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700961 } else if (os_strcasecmp(cmd, "country") == 0) {
962 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
963 res = os_snprintf(buf, buflen, "%c%c",
964 wpa_s->conf->country[0],
965 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700966#ifdef CONFIG_WIFI_DISPLAY
967 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800968 int enabled;
969 if (wpa_s->global->p2p == NULL ||
970 wpa_s->global->p2p_disabled)
971 enabled = 0;
972 else
973 enabled = wpa_s->global->wifi_display;
974 res = os_snprintf(buf, buflen, "%d", enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700975#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700976#ifdef CONFIG_TESTING_GET_GTK
977 } else if (os_strcmp(cmd, "gtk") == 0) {
978 if (wpa_s->last_gtk_len == 0)
979 return -1;
980 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
981 wpa_s->last_gtk_len);
982 return res;
983#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800984 } else if (os_strcmp(cmd, "tls_library") == 0) {
985 res = tls_get_library_version(buf, buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700986#ifdef CONFIG_TESTING_OPTIONS
987 } else if (os_strcmp(cmd, "anonce") == 0) {
988 return wpa_snprintf_hex(buf, buflen,
989 wpa_sm_get_anonce(wpa_s->wpa),
990 WPA_NONCE_LEN);
Hai Shalomfdcde762020-04-02 11:19:20 -0700991 } else if (os_strcasecmp(cmd, "last_tk_key_idx") == 0) {
992 res = os_snprintf(buf, buflen, "%d", wpa_s->last_tk_key_idx);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700993#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800994 } else {
995 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700996 }
997
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800998 if (os_snprintf_error(buflen, res))
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700999 return -1;
1000 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001001}
1002
1003
1004#ifdef IEEE8021X_EAPOL
1005static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
1006 char *addr)
1007{
1008 u8 bssid[ETH_ALEN];
1009 struct wpa_ssid *ssid = wpa_s->current_ssid;
1010
1011 if (hwaddr_aton(addr, bssid)) {
1012 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
1013 "'%s'", addr);
1014 return -1;
1015 }
1016
1017 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
1018 rsn_preauth_deinit(wpa_s->wpa);
1019 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
1020 return -1;
1021
1022 return 0;
1023}
1024#endif /* IEEE8021X_EAPOL */
1025
1026
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001027#ifdef CONFIG_TDLS
1028
1029static int wpa_supplicant_ctrl_iface_tdls_discover(
1030 struct wpa_supplicant *wpa_s, char *addr)
1031{
1032 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001033 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034
1035 if (hwaddr_aton(addr, peer)) {
1036 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
1037 "address '%s'", addr);
1038 return -1;
1039 }
1040
1041 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
1042 MAC2STR(peer));
1043
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001044 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1045 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
1046 else
1047 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
1048
1049 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001050}
1051
1052
1053static int wpa_supplicant_ctrl_iface_tdls_setup(
1054 struct wpa_supplicant *wpa_s, char *addr)
1055{
1056 u8 peer[ETH_ALEN];
1057 int ret;
1058
1059 if (hwaddr_aton(addr, peer)) {
1060 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
1061 "address '%s'", addr);
1062 return -1;
1063 }
1064
1065 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
1066 MAC2STR(peer));
1067
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001068 if ((wpa_s->conf->tdls_external_control) &&
1069 wpa_tdls_is_external_setup(wpa_s->wpa))
1070 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
1071
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001072 wpa_tdls_remove(wpa_s->wpa, peer);
1073
1074 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1075 ret = wpa_tdls_start(wpa_s->wpa, peer);
1076 else
1077 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001078
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001079 return ret;
1080}
1081
1082
1083static int wpa_supplicant_ctrl_iface_tdls_teardown(
1084 struct wpa_supplicant *wpa_s, char *addr)
1085{
1086 u8 peer[ETH_ALEN];
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001087 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001089 if (os_strcmp(addr, "*") == 0) {
1090 /* remove everyone */
1091 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
1092 wpa_tdls_teardown_peers(wpa_s->wpa);
1093 return 0;
1094 }
1095
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001096 if (hwaddr_aton(addr, peer)) {
1097 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
1098 "address '%s'", addr);
1099 return -1;
1100 }
1101
1102 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
1103 MAC2STR(peer));
1104
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001105 if ((wpa_s->conf->tdls_external_control) &&
1106 wpa_tdls_is_external_setup(wpa_s->wpa))
1107 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1108
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001109 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1110 ret = wpa_tdls_teardown_link(
1111 wpa_s->wpa, peer,
1112 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
1113 else
1114 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1115
1116 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001117}
1118
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001119
1120static int ctrl_iface_get_capability_tdls(
1121 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1122{
1123 int ret;
1124
1125 ret = os_snprintf(buf, buflen, "%s\n",
1126 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
1127 (wpa_s->drv_flags &
1128 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
1129 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001130 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001131 return -1;
1132 return ret;
1133}
1134
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001135
1136static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
1137 struct wpa_supplicant *wpa_s, char *cmd)
1138{
1139 u8 peer[ETH_ALEN];
1140 struct hostapd_freq_params freq_params;
1141 u8 oper_class;
1142 char *pos, *end;
1143
1144 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1145 wpa_printf(MSG_INFO,
1146 "tdls_chanswitch: Only supported with external setup");
1147 return -1;
1148 }
1149
1150 os_memset(&freq_params, 0, sizeof(freq_params));
1151
1152 pos = os_strchr(cmd, ' ');
1153 if (pos == NULL)
1154 return -1;
1155 *pos++ = '\0';
1156
1157 oper_class = strtol(pos, &end, 10);
1158 if (pos == end) {
1159 wpa_printf(MSG_INFO,
1160 "tdls_chanswitch: Invalid op class provided");
1161 return -1;
1162 }
1163
1164 pos = end;
1165 freq_params.freq = atoi(pos);
1166 if (freq_params.freq == 0) {
1167 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
1168 return -1;
1169 }
1170
1171#define SET_FREQ_SETTING(str) \
1172 do { \
1173 const char *pos2 = os_strstr(pos, " " #str "="); \
1174 if (pos2) { \
1175 pos2 += sizeof(" " #str "=") - 1; \
1176 freq_params.str = atoi(pos2); \
1177 } \
1178 } while (0)
1179
1180 SET_FREQ_SETTING(center_freq1);
1181 SET_FREQ_SETTING(center_freq2);
1182 SET_FREQ_SETTING(bandwidth);
1183 SET_FREQ_SETTING(sec_channel_offset);
1184#undef SET_FREQ_SETTING
1185
1186 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1187 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1188
1189 if (hwaddr_aton(cmd, peer)) {
1190 wpa_printf(MSG_DEBUG,
1191 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1192 cmd);
1193 return -1;
1194 }
1195
1196 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1197 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1198 MAC2STR(peer), oper_class, freq_params.freq,
1199 freq_params.center_freq1, freq_params.center_freq2,
1200 freq_params.bandwidth, freq_params.sec_channel_offset,
1201 freq_params.ht_enabled ? " HT" : "",
1202 freq_params.vht_enabled ? " VHT" : "");
1203
1204 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1205 &freq_params);
1206}
1207
1208
1209static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1210 struct wpa_supplicant *wpa_s, char *cmd)
1211{
1212 u8 peer[ETH_ALEN];
1213
1214 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1215 wpa_printf(MSG_INFO,
1216 "tdls_chanswitch: Only supported with external setup");
1217 return -1;
1218 }
1219
1220 if (hwaddr_aton(cmd, peer)) {
1221 wpa_printf(MSG_DEBUG,
1222 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1223 cmd);
1224 return -1;
1225 }
1226
1227 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1228 MAC2STR(peer));
1229
1230 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1231}
1232
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07001233
1234static int wpa_supplicant_ctrl_iface_tdls_link_status(
1235 struct wpa_supplicant *wpa_s, const char *addr,
1236 char *buf, size_t buflen)
1237{
1238 u8 peer[ETH_ALEN];
1239 const char *tdls_status;
1240 int ret;
1241
1242 if (hwaddr_aton(addr, peer)) {
1243 wpa_printf(MSG_DEBUG,
1244 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1245 addr);
1246 return -1;
1247 }
1248 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1249 MAC2STR(peer));
1250
1251 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1252 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1253 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1254 if (os_snprintf_error(buflen, ret))
1255 return -1;
1256
1257 return ret;
1258}
1259
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001260#endif /* CONFIG_TDLS */
1261
1262
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001263static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1264{
1265 char *token, *context = NULL;
1266 struct wmm_ac_ts_setup_params params = {
1267 .tsid = 0xff,
1268 .direction = 0xff,
1269 };
1270
1271 while ((token = str_token(cmd, " ", &context))) {
1272 if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
1273 sscanf(token, "up=%i", &params.user_priority) == 1 ||
1274 sscanf(token, "nominal_msdu_size=%i",
1275 &params.nominal_msdu_size) == 1 ||
1276 sscanf(token, "mean_data_rate=%i",
1277 &params.mean_data_rate) == 1 ||
1278 sscanf(token, "min_phy_rate=%i",
1279 &params.minimum_phy_rate) == 1 ||
1280 sscanf(token, "sba=%i",
1281 &params.surplus_bandwidth_allowance) == 1)
1282 continue;
1283
1284 if (os_strcasecmp(token, "downlink") == 0) {
1285 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1286 } else if (os_strcasecmp(token, "uplink") == 0) {
1287 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1288 } else if (os_strcasecmp(token, "bidi") == 0) {
1289 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1290 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1291 params.fixed_nominal_msdu = 1;
1292 } else {
1293 wpa_printf(MSG_DEBUG,
1294 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1295 token);
1296 return -1;
1297 }
1298
1299 }
1300
1301 return wpas_wmm_ac_addts(wpa_s, &params);
1302}
1303
1304
1305static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1306{
1307 u8 tsid = atoi(cmd);
1308
1309 return wpas_wmm_ac_delts(wpa_s, tsid);
1310}
1311
1312
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001313#ifdef CONFIG_IEEE80211R
1314static int wpa_supplicant_ctrl_iface_ft_ds(
1315 struct wpa_supplicant *wpa_s, char *addr)
1316{
1317 u8 target_ap[ETH_ALEN];
1318 struct wpa_bss *bss;
1319 const u8 *mdie;
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00001320 bool force = os_strstr(addr, " force") != NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001321
1322 if (hwaddr_aton(addr, target_ap)) {
1323 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1324 "address '%s'", addr);
1325 return -1;
1326 }
1327
1328 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1329
1330 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1331 if (bss)
1332 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1333 else
1334 mdie = NULL;
1335
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00001336 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie, force);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001337}
1338#endif /* CONFIG_IEEE80211R */
1339
1340
1341#ifdef CONFIG_WPS
1342static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1343 char *cmd)
1344{
1345 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001346#ifdef CONFIG_P2P
1347 u8 p2p_dev_addr[ETH_ALEN];
1348#endif /* CONFIG_P2P */
1349#ifdef CONFIG_AP
1350 u8 *_p2p_dev_addr = NULL;
1351#endif /* CONFIG_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001352 char *pos;
1353 int multi_ap = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001354
Hai Shalom021b0b52019-04-10 11:17:58 -07001355 if (!cmd || os_strcmp(cmd, "any") == 0 ||
1356 os_strncmp(cmd, "any ", 4) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001357 _bssid = NULL;
1358#ifdef CONFIG_P2P
1359 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1360 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1361 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1362 "P2P Device Address '%s'",
1363 cmd + 13);
1364 return -1;
1365 }
1366 _p2p_dev_addr = p2p_dev_addr;
1367#endif /* CONFIG_P2P */
Hai Shalom021b0b52019-04-10 11:17:58 -07001368 } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) {
1369 _bssid = NULL;
1370 multi_ap = atoi(cmd + 9);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001371 } else if (hwaddr_aton(cmd, bssid)) {
1372 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1373 cmd);
1374 return -1;
1375 }
1376
Hai Shalom021b0b52019-04-10 11:17:58 -07001377 if (cmd) {
1378 pos = os_strstr(cmd, " multi_ap=");
1379 if (pos) {
1380 pos += 10;
1381 multi_ap = atoi(pos);
1382 }
1383 }
1384
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001385#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001386 if (wpa_s->ap_iface)
1387 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1388#endif /* CONFIG_AP */
1389
Hai Shalom021b0b52019-04-10 11:17:58 -07001390 return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001391}
1392
1393
1394static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1395 char *cmd, char *buf,
1396 size_t buflen)
1397{
1398 u8 bssid[ETH_ALEN], *_bssid = bssid;
1399 char *pin;
1400 int ret;
1401
1402 pin = os_strchr(cmd, ' ');
1403 if (pin)
1404 *pin++ = '\0';
1405
1406 if (os_strcmp(cmd, "any") == 0)
1407 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001408 else if (os_strcmp(cmd, "get") == 0) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001409 if (wps_generate_pin((unsigned int *) &ret) < 0)
1410 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001411 goto done;
1412 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001413 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1414 cmd);
1415 return -1;
1416 }
1417
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001418#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001419 if (wpa_s->ap_iface) {
1420 int timeout = 0;
1421 char *pos;
1422
1423 if (pin) {
1424 pos = os_strchr(pin, ' ');
1425 if (pos) {
1426 *pos++ = '\0';
1427 timeout = atoi(pos);
1428 }
1429 }
1430
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001431 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001432 buf, buflen, timeout);
1433 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001434#endif /* CONFIG_AP */
1435
1436 if (pin) {
1437 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1438 DEV_PW_DEFAULT);
1439 if (ret < 0)
1440 return -1;
1441 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001442 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001443 return -1;
1444 return ret;
1445 }
1446
1447 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1448 if (ret < 0)
1449 return -1;
1450
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001451done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001452 /* Return the generated PIN */
1453 ret = os_snprintf(buf, buflen, "%08d", ret);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001454 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001455 return -1;
1456 return ret;
1457}
1458
1459
1460static int wpa_supplicant_ctrl_iface_wps_check_pin(
1461 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1462{
1463 char pin[9];
1464 size_t len;
1465 char *pos;
1466 int ret;
1467
1468 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1469 (u8 *) cmd, os_strlen(cmd));
1470 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1471 if (*pos < '0' || *pos > '9')
1472 continue;
1473 pin[len++] = *pos;
1474 if (len == 9) {
1475 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1476 return -1;
1477 }
1478 }
1479 if (len != 4 && len != 8) {
1480 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1481 return -1;
1482 }
1483 pin[len] = '\0';
1484
1485 if (len == 8) {
1486 unsigned int pin_val;
1487 pin_val = atoi(pin);
1488 if (!wps_pin_valid(pin_val)) {
1489 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1490 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001491 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001492 return -1;
1493 return ret;
1494 }
1495 }
1496
1497 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001498 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001499 return -1;
1500
1501 return ret;
1502}
1503
1504
Dmitry Shmidt04949592012-07-19 12:16:46 -07001505#ifdef CONFIG_WPS_NFC
1506
1507static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1508 char *cmd)
1509{
1510 u8 bssid[ETH_ALEN], *_bssid = bssid;
1511
1512 if (cmd == NULL || cmd[0] == '\0')
1513 _bssid = NULL;
1514 else if (hwaddr_aton(cmd, bssid))
1515 return -1;
1516
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001517 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1518 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001519}
1520
1521
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001522static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1523 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1524{
1525 int ndef;
1526 struct wpabuf *buf;
1527 int res;
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001528 char *pos;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001529
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001530 pos = os_strchr(cmd, ' ');
1531 if (pos)
1532 *pos++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001533 if (os_strcmp(cmd, "WPS") == 0)
1534 ndef = 0;
1535 else if (os_strcmp(cmd, "NDEF") == 0)
1536 ndef = 1;
1537 else
1538 return -1;
1539
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001540 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001541 if (buf == NULL)
1542 return -1;
1543
1544 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1545 wpabuf_len(buf));
1546 reply[res++] = '\n';
1547 reply[res] = '\0';
1548
1549 wpabuf_free(buf);
1550
1551 return res;
1552}
1553
1554
Dmitry Shmidt04949592012-07-19 12:16:46 -07001555static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1556 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1557{
1558 int ndef;
1559 struct wpabuf *buf;
1560 int res;
1561
1562 if (os_strcmp(cmd, "WPS") == 0)
1563 ndef = 0;
1564 else if (os_strcmp(cmd, "NDEF") == 0)
1565 ndef = 1;
1566 else
1567 return -1;
1568
1569 buf = wpas_wps_nfc_token(wpa_s, ndef);
1570 if (buf == NULL)
1571 return -1;
1572
1573 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1574 wpabuf_len(buf));
1575 reply[res++] = '\n';
1576 reply[res] = '\0';
1577
1578 wpabuf_free(buf);
1579
1580 return res;
1581}
1582
1583
1584static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1585 struct wpa_supplicant *wpa_s, char *pos)
1586{
1587 size_t len;
1588 struct wpabuf *buf;
1589 int ret;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001590 char *freq;
1591 int forced_freq = 0;
1592
1593 freq = strstr(pos, " freq=");
1594 if (freq) {
1595 *freq = '\0';
1596 freq += 6;
1597 forced_freq = atoi(freq);
1598 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001599
1600 len = os_strlen(pos);
1601 if (len & 0x01)
1602 return -1;
1603 len /= 2;
1604
1605 buf = wpabuf_alloc(len);
1606 if (buf == NULL)
1607 return -1;
1608 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1609 wpabuf_free(buf);
1610 return -1;
1611 }
1612
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001613 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001614 wpabuf_free(buf);
1615
1616 return ret;
1617}
1618
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001619
1620static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001621 char *reply, size_t max_len,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001622 int ndef)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001623{
1624 struct wpabuf *buf;
1625 int res;
1626
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001627 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001628 if (buf == NULL)
1629 return -1;
1630
1631 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1632 wpabuf_len(buf));
1633 reply[res++] = '\n';
1634 reply[res] = '\0';
1635
1636 wpabuf_free(buf);
1637
1638 return res;
1639}
1640
1641
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001642#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001643static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1644 char *reply, size_t max_len,
1645 int ndef)
1646{
1647 struct wpabuf *buf;
1648 int res;
1649
1650 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1651 if (buf == NULL) {
1652 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1653 return -1;
1654 }
1655
1656 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1657 wpabuf_len(buf));
1658 reply[res++] = '\n';
1659 reply[res] = '\0';
1660
1661 wpabuf_free(buf);
1662
1663 return res;
1664}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001665#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001666
1667
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001668static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1669 char *cmd, char *reply,
1670 size_t max_len)
1671{
1672 char *pos;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001673 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001674
1675 pos = os_strchr(cmd, ' ');
1676 if (pos == NULL)
1677 return -1;
1678 *pos++ = '\0';
1679
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001680 if (os_strcmp(cmd, "WPS") == 0)
1681 ndef = 0;
1682 else if (os_strcmp(cmd, "NDEF") == 0)
1683 ndef = 1;
1684 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001685 return -1;
1686
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001687 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001688 if (!ndef)
1689 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001690 return wpas_ctrl_nfc_get_handover_req_wps(
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001691 wpa_s, reply, max_len, ndef);
1692 }
1693
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001694#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001695 if (os_strcmp(pos, "P2P-CR") == 0) {
1696 return wpas_ctrl_nfc_get_handover_req_p2p(
1697 wpa_s, reply, max_len, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001698 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001699#endif /* CONFIG_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001700
1701 return -1;
1702}
1703
1704
1705static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001706 char *reply, size_t max_len,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001707 int ndef, int cr, char *uuid)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001708{
1709 struct wpabuf *buf;
1710 int res;
1711
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001712 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001713 if (buf == NULL)
1714 return -1;
1715
1716 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1717 wpabuf_len(buf));
1718 reply[res++] = '\n';
1719 reply[res] = '\0';
1720
1721 wpabuf_free(buf);
1722
1723 return res;
1724}
1725
1726
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001727#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001728static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1729 char *reply, size_t max_len,
1730 int ndef, int tag)
1731{
1732 struct wpabuf *buf;
1733 int res;
1734
1735 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1736 if (buf == NULL)
1737 return -1;
1738
1739 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1740 wpabuf_len(buf));
1741 reply[res++] = '\n';
1742 reply[res] = '\0';
1743
1744 wpabuf_free(buf);
1745
1746 return res;
1747}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001748#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001749
1750
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001751static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1752 char *cmd, char *reply,
1753 size_t max_len)
1754{
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001755 char *pos, *pos2;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001756 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001757
1758 pos = os_strchr(cmd, ' ');
1759 if (pos == NULL)
1760 return -1;
1761 *pos++ = '\0';
1762
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001763 if (os_strcmp(cmd, "WPS") == 0)
1764 ndef = 0;
1765 else if (os_strcmp(cmd, "NDEF") == 0)
1766 ndef = 1;
1767 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001768 return -1;
1769
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001770 pos2 = os_strchr(pos, ' ');
1771 if (pos2)
1772 *pos2++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001773 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001774 if (!ndef)
1775 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001776 return wpas_ctrl_nfc_get_handover_sel_wps(
1777 wpa_s, reply, max_len, ndef,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001778 os_strcmp(pos, "WPS-CR") == 0, pos2);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001779 }
1780
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001781#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001782 if (os_strcmp(pos, "P2P-CR") == 0) {
1783 return wpas_ctrl_nfc_get_handover_sel_p2p(
1784 wpa_s, reply, max_len, ndef, 0);
1785 }
1786
1787 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1788 return wpas_ctrl_nfc_get_handover_sel_p2p(
1789 wpa_s, reply, max_len, ndef, 1);
1790 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001791#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001792
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001793 return -1;
1794}
1795
1796
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001797static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1798 char *cmd)
1799{
1800 size_t len;
1801 struct wpabuf *req, *sel;
1802 int ret;
1803 char *pos, *role, *type, *pos2;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001804#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001805 char *freq;
1806 int forced_freq = 0;
1807
1808 freq = strstr(cmd, " freq=");
1809 if (freq) {
1810 *freq = '\0';
1811 freq += 6;
1812 forced_freq = atoi(freq);
1813 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001814#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001815
1816 role = cmd;
1817 pos = os_strchr(role, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001818 if (pos == NULL) {
1819 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001820 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001821 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001822 *pos++ = '\0';
1823
1824 type = pos;
1825 pos = os_strchr(type, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001826 if (pos == NULL) {
1827 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001828 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001829 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001830 *pos++ = '\0';
1831
1832 pos2 = os_strchr(pos, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001833 if (pos2 == NULL) {
1834 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001835 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001836 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001837 *pos2++ = '\0';
1838
1839 len = os_strlen(pos);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001840 if (len & 0x01) {
1841 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001842 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001843 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001844 len /= 2;
1845
1846 req = wpabuf_alloc(len);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001847 if (req == NULL) {
1848 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
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 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001852 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001853 wpabuf_free(req);
1854 return -1;
1855 }
1856
1857 len = os_strlen(pos2);
1858 if (len & 0x01) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001859 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001860 wpabuf_free(req);
1861 return -1;
1862 }
1863 len /= 2;
1864
1865 sel = wpabuf_alloc(len);
1866 if (sel == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001867 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001868 wpabuf_free(req);
1869 return -1;
1870 }
1871 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001872 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001873 wpabuf_free(req);
1874 wpabuf_free(sel);
1875 return -1;
1876 }
1877
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001878 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1879 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1880
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001881 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1882 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001883#ifdef CONFIG_AP
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001884 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1885 {
1886 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1887 if (ret < 0)
1888 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001889#endif /* CONFIG_AP */
1890#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001891 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1892 {
1893 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1894 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1895 {
1896 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1897 forced_freq);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001898#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001899 } else {
1900 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1901 "reported: role=%s type=%s", role, type);
1902 ret = -1;
1903 }
1904 wpabuf_free(req);
1905 wpabuf_free(sel);
1906
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001907 if (ret)
1908 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1909
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001910 return ret;
1911}
1912
Dmitry Shmidt04949592012-07-19 12:16:46 -07001913#endif /* CONFIG_WPS_NFC */
1914
1915
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001916static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1917 char *cmd)
1918{
1919 u8 bssid[ETH_ALEN];
1920 char *pin;
1921 char *new_ssid;
1922 char *new_auth;
1923 char *new_encr;
1924 char *new_key;
1925 struct wps_new_ap_settings ap;
1926
1927 pin = os_strchr(cmd, ' ');
1928 if (pin == NULL)
1929 return -1;
1930 *pin++ = '\0';
1931
1932 if (hwaddr_aton(cmd, bssid)) {
1933 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1934 cmd);
1935 return -1;
1936 }
1937
1938 new_ssid = os_strchr(pin, ' ');
1939 if (new_ssid == NULL)
1940 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1941 *new_ssid++ = '\0';
1942
1943 new_auth = os_strchr(new_ssid, ' ');
1944 if (new_auth == NULL)
1945 return -1;
1946 *new_auth++ = '\0';
1947
1948 new_encr = os_strchr(new_auth, ' ');
1949 if (new_encr == NULL)
1950 return -1;
1951 *new_encr++ = '\0';
1952
1953 new_key = os_strchr(new_encr, ' ');
1954 if (new_key == NULL)
1955 return -1;
1956 *new_key++ = '\0';
1957
1958 os_memset(&ap, 0, sizeof(ap));
1959 ap.ssid_hex = new_ssid;
1960 ap.auth = new_auth;
1961 ap.encr = new_encr;
1962 ap.key_hex = new_key;
1963 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1964}
1965
1966
1967#ifdef CONFIG_AP
1968static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1969 char *cmd, char *buf,
1970 size_t buflen)
1971{
1972 int timeout = 300;
1973 char *pos;
1974 const char *pin_txt;
1975
1976 if (!wpa_s->ap_iface)
1977 return -1;
1978
1979 pos = os_strchr(cmd, ' ');
1980 if (pos)
1981 *pos++ = '\0';
1982
1983 if (os_strcmp(cmd, "disable") == 0) {
1984 wpas_wps_ap_pin_disable(wpa_s);
1985 return os_snprintf(buf, buflen, "OK\n");
1986 }
1987
1988 if (os_strcmp(cmd, "random") == 0) {
1989 if (pos)
1990 timeout = atoi(pos);
1991 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1992 if (pin_txt == NULL)
1993 return -1;
1994 return os_snprintf(buf, buflen, "%s", pin_txt);
1995 }
1996
1997 if (os_strcmp(cmd, "get") == 0) {
1998 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1999 if (pin_txt == NULL)
2000 return -1;
2001 return os_snprintf(buf, buflen, "%s", pin_txt);
2002 }
2003
2004 if (os_strcmp(cmd, "set") == 0) {
2005 char *pin;
2006 if (pos == NULL)
2007 return -1;
2008 pin = pos;
2009 pos = os_strchr(pos, ' ');
2010 if (pos) {
2011 *pos++ = '\0';
2012 timeout = atoi(pos);
2013 }
2014 if (os_strlen(pin) > buflen)
2015 return -1;
2016 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
2017 return -1;
2018 return os_snprintf(buf, buflen, "%s", pin);
2019 }
2020
2021 return -1;
2022}
2023#endif /* CONFIG_AP */
2024
2025
2026#ifdef CONFIG_WPS_ER
2027static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
2028 char *cmd)
2029{
2030 char *uuid = cmd, *pin, *pos;
2031 u8 addr_buf[ETH_ALEN], *addr = NULL;
2032 pin = os_strchr(uuid, ' ');
2033 if (pin == NULL)
2034 return -1;
2035 *pin++ = '\0';
2036 pos = os_strchr(pin, ' ');
2037 if (pos) {
2038 *pos++ = '\0';
2039 if (hwaddr_aton(pos, addr_buf) == 0)
2040 addr = addr_buf;
2041 }
2042 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
2043}
2044
2045
2046static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
2047 char *cmd)
2048{
2049 char *uuid = cmd, *pin;
2050 pin = os_strchr(uuid, ' ');
2051 if (pin == NULL)
2052 return -1;
2053 *pin++ = '\0';
2054 return wpas_wps_er_learn(wpa_s, uuid, pin);
2055}
2056
2057
2058static int wpa_supplicant_ctrl_iface_wps_er_set_config(
2059 struct wpa_supplicant *wpa_s, char *cmd)
2060{
2061 char *uuid = cmd, *id;
2062 id = os_strchr(uuid, ' ');
2063 if (id == NULL)
2064 return -1;
2065 *id++ = '\0';
2066 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
2067}
2068
2069
2070static int wpa_supplicant_ctrl_iface_wps_er_config(
2071 struct wpa_supplicant *wpa_s, char *cmd)
2072{
2073 char *pin;
2074 char *new_ssid;
2075 char *new_auth;
2076 char *new_encr;
2077 char *new_key;
2078 struct wps_new_ap_settings ap;
2079
2080 pin = os_strchr(cmd, ' ');
2081 if (pin == NULL)
2082 return -1;
2083 *pin++ = '\0';
2084
2085 new_ssid = os_strchr(pin, ' ');
2086 if (new_ssid == NULL)
2087 return -1;
2088 *new_ssid++ = '\0';
2089
2090 new_auth = os_strchr(new_ssid, ' ');
2091 if (new_auth == NULL)
2092 return -1;
2093 *new_auth++ = '\0';
2094
2095 new_encr = os_strchr(new_auth, ' ');
2096 if (new_encr == NULL)
2097 return -1;
2098 *new_encr++ = '\0';
2099
2100 new_key = os_strchr(new_encr, ' ');
2101 if (new_key == NULL)
2102 return -1;
2103 *new_key++ = '\0';
2104
2105 os_memset(&ap, 0, sizeof(ap));
2106 ap.ssid_hex = new_ssid;
2107 ap.auth = new_auth;
2108 ap.encr = new_encr;
2109 ap.key_hex = new_key;
2110 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
2111}
Dmitry Shmidt04949592012-07-19 12:16:46 -07002112
2113
2114#ifdef CONFIG_WPS_NFC
2115static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
2116 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2117{
2118 int ndef;
2119 struct wpabuf *buf;
2120 int res;
2121 char *uuid;
2122
2123 uuid = os_strchr(cmd, ' ');
2124 if (uuid == NULL)
2125 return -1;
2126 *uuid++ = '\0';
2127
2128 if (os_strcmp(cmd, "WPS") == 0)
2129 ndef = 0;
2130 else if (os_strcmp(cmd, "NDEF") == 0)
2131 ndef = 1;
2132 else
2133 return -1;
2134
2135 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
2136 if (buf == NULL)
2137 return -1;
2138
2139 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
2140 wpabuf_len(buf));
2141 reply[res++] = '\n';
2142 reply[res] = '\0';
2143
2144 wpabuf_free(buf);
2145
2146 return res;
2147}
2148#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002149#endif /* CONFIG_WPS_ER */
2150
2151#endif /* CONFIG_WPS */
2152
2153
2154#ifdef CONFIG_IBSS_RSN
2155static int wpa_supplicant_ctrl_iface_ibss_rsn(
2156 struct wpa_supplicant *wpa_s, char *addr)
2157{
2158 u8 peer[ETH_ALEN];
2159
2160 if (hwaddr_aton(addr, peer)) {
2161 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
2162 "address '%s'", addr);
2163 return -1;
2164 }
2165
2166 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
2167 MAC2STR(peer));
2168
2169 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
2170}
2171#endif /* CONFIG_IBSS_RSN */
2172
2173
2174static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
2175 char *rsp)
2176{
2177#ifdef IEEE8021X_EAPOL
2178 char *pos, *id_pos;
2179 int id;
2180 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002181
2182 pos = os_strchr(rsp, '-');
2183 if (pos == NULL)
2184 return -1;
2185 *pos++ = '\0';
2186 id_pos = pos;
2187 pos = os_strchr(pos, ':');
2188 if (pos == NULL)
2189 return -1;
2190 *pos++ = '\0';
2191 id = atoi(id_pos);
2192 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
2193 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2194 (u8 *) pos, os_strlen(pos));
2195
2196 ssid = wpa_config_get_network(wpa_s->conf, id);
2197 if (ssid == NULL) {
2198 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2199 "to update", id);
2200 return -1;
2201 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002202
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002203 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2204 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002205#else /* IEEE8021X_EAPOL */
2206 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2207 return -1;
2208#endif /* IEEE8021X_EAPOL */
2209}
2210
2211
2212static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2213 const char *params,
2214 char *buf, size_t buflen)
2215{
2216 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002217 int res, verbose, wps, ret;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002218#ifdef CONFIG_HS20
2219 const u8 *hs20;
2220#endif /* CONFIG_HS20 */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002221 const u8 *sess_id;
2222 size_t sess_id_len;
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002223
Dmitry Shmidt56052862013-10-04 10:23:25 -07002224 if (os_strcmp(params, "-DRIVER") == 0)
2225 return wpa_drv_status(wpa_s, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002226 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002227 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002228 pos = buf;
2229 end = buf + buflen;
2230 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2231 struct wpa_ssid *ssid = wpa_s->current_ssid;
2232 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2233 MAC2STR(wpa_s->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002234 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002235 return pos - buf;
2236 pos += ret;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002237 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2238 wpa_s->assoc_freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002239 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002240 return pos - buf;
2241 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002242 if (ssid) {
2243 u8 *_ssid = ssid->ssid;
2244 size_t ssid_len = ssid->ssid_len;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002245 u8 ssid_buf[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002246 if (ssid_len == 0) {
2247 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2248 if (_res < 0)
2249 ssid_len = 0;
2250 else
2251 ssid_len = _res;
2252 _ssid = ssid_buf;
2253 }
2254 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2255 wpa_ssid_txt(_ssid, ssid_len),
2256 ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002257 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002258 return pos - buf;
2259 pos += ret;
2260
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002261 if (wps && ssid->passphrase &&
2262 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2263 (ssid->mode == WPAS_MODE_AP ||
2264 ssid->mode == WPAS_MODE_P2P_GO)) {
2265 ret = os_snprintf(pos, end - pos,
2266 "passphrase=%s\n",
2267 ssid->passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002268 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002269 return pos - buf;
2270 pos += ret;
2271 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002272 if (ssid->id_str) {
2273 ret = os_snprintf(pos, end - pos,
2274 "id_str=%s\n",
2275 ssid->id_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002276 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002277 return pos - buf;
2278 pos += ret;
2279 }
2280
2281 switch (ssid->mode) {
2282 case WPAS_MODE_INFRA:
2283 ret = os_snprintf(pos, end - pos,
2284 "mode=station\n");
2285 break;
2286 case WPAS_MODE_IBSS:
2287 ret = os_snprintf(pos, end - pos,
2288 "mode=IBSS\n");
2289 break;
2290 case WPAS_MODE_AP:
2291 ret = os_snprintf(pos, end - pos,
2292 "mode=AP\n");
2293 break;
2294 case WPAS_MODE_P2P_GO:
2295 ret = os_snprintf(pos, end - pos,
2296 "mode=P2P GO\n");
2297 break;
2298 case WPAS_MODE_P2P_GROUP_FORMATION:
2299 ret = os_snprintf(pos, end - pos,
2300 "mode=P2P GO - group "
2301 "formation\n");
2302 break;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002303 case WPAS_MODE_MESH:
2304 ret = os_snprintf(pos, end - pos,
2305 "mode=mesh\n");
2306 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002307 default:
2308 ret = 0;
2309 break;
2310 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002311 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002312 return pos - buf;
2313 pos += ret;
2314 }
2315
Hai Shalom021b0b52019-04-10 11:17:58 -07002316 if (wpa_s->connection_set &&
2317 (wpa_s->connection_ht || wpa_s->connection_vht ||
Sunil Ravia04bd252022-05-02 22:54:18 -07002318 wpa_s->connection_he || wpa_s->connection_eht)) {
Hai Shalom021b0b52019-04-10 11:17:58 -07002319 ret = os_snprintf(pos, end - pos,
2320 "wifi_generation=%u\n",
Sunil Ravia04bd252022-05-02 22:54:18 -07002321 wpa_s->connection_eht ? 7 :
2322 (wpa_s->connection_he ? 6 :
2323 (wpa_s->connection_vht ? 5 : 4)));
Hai Shalom021b0b52019-04-10 11:17:58 -07002324 if (os_snprintf_error(end - pos, ret))
2325 return pos - buf;
2326 pos += ret;
2327 }
2328
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002329#ifdef CONFIG_AP
2330 if (wpa_s->ap_iface) {
2331 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2332 end - pos,
2333 verbose);
2334 } else
2335#endif /* CONFIG_AP */
2336 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2337 }
Paul Stewart092955c2017-02-06 09:13:09 -08002338#ifdef CONFIG_SME
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002339#ifdef CONFIG_SAE
2340 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002341#ifdef CONFIG_AP
2342 !wpa_s->ap_iface &&
2343#endif /* CONFIG_AP */
2344 wpa_s->sme.sae.state == SAE_ACCEPTED) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002345 ret = os_snprintf(pos, end - pos, "sae_group=%d\n"
2346 "sae_h2e=%d\n"
2347 "sae_pk=%d\n",
2348 wpa_s->sme.sae.group,
2349 wpa_s->sme.sae.h2e,
2350 wpa_s->sme.sae.pk);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002351 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002352 return pos - buf;
2353 pos += ret;
2354 }
2355#endif /* CONFIG_SAE */
Paul Stewart092955c2017-02-06 09:13:09 -08002356#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002357 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2358 wpa_supplicant_state_txt(wpa_s->wpa_state));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002359 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002360 return pos - buf;
2361 pos += ret;
2362
2363 if (wpa_s->l2 &&
2364 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2365 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002366 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002367 return pos - buf;
2368 pos += ret;
2369 }
2370
2371#ifdef CONFIG_P2P
2372 if (wpa_s->global->p2p) {
2373 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2374 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002375 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002376 return pos - buf;
2377 pos += ret;
2378 }
2379#endif /* CONFIG_P2P */
2380
2381 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2382 MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002383 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384 return pos - buf;
2385 pos += ret;
2386
Sunil Ravi89eba102022-09-13 21:04:37 -07002387 if (wpa_s->valid_links) {
2388 ret = os_snprintf(pos, end - pos, "ap_mld_addr=" MACSTR "\n",
2389 MAC2STR(wpa_s->ap_mld_addr));
2390 if (os_snprintf_error(end - pos, ret))
2391 return pos - buf;
2392 pos += ret;
2393 }
2394
Dmitry Shmidt04949592012-07-19 12:16:46 -07002395#ifdef CONFIG_HS20
2396 if (wpa_s->current_bss &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002397 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2398 HS20_IE_VENDOR_TYPE)) &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002399 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2400 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002401 int release = 1;
2402 if (hs20[1] >= 5) {
2403 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2404 release = rel_num + 1;
2405 }
2406 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002407 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002408 return pos - buf;
2409 pos += ret;
2410 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002411
2412 if (wpa_s->current_ssid) {
2413 struct wpa_cred *cred;
2414 char *type;
2415
2416 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002417 size_t i;
2418
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002419 if (wpa_s->current_ssid->parent_cred != cred)
2420 continue;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002421
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002422 if (cred->provisioning_sp) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002423 ret = os_snprintf(pos, end - pos,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002424 "provisioning_sp=%s\n",
2425 cred->provisioning_sp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002426 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt051af732013-10-22 13:52:46 -07002427 return pos - buf;
2428 pos += ret;
2429 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002430
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002431 if (!cred->domain)
2432 goto no_domain;
2433
2434 i = 0;
2435 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2436 struct wpabuf *names =
2437 wpa_s->current_bss->anqp->domain_name;
2438 for (i = 0; names && i < cred->num_domain; i++)
2439 {
2440 if (domain_name_list_contains(
2441 names, cred->domain[i], 1))
2442 break;
2443 }
2444 if (i == cred->num_domain)
2445 i = 0; /* show first entry by default */
2446 }
2447 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2448 cred->domain[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002449 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002450 return pos - buf;
2451 pos += ret;
2452
2453 no_domain:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002454 if (wpa_s->current_bss == NULL ||
2455 wpa_s->current_bss->anqp == NULL)
2456 res = -1;
2457 else
2458 res = interworking_home_sp_cred(
2459 wpa_s, cred,
2460 wpa_s->current_bss->anqp->domain_name);
2461 if (res > 0)
2462 type = "home";
2463 else if (res == 0)
2464 type = "roaming";
2465 else
2466 type = "unknown";
2467
2468 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002469 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002470 return pos - buf;
2471 pos += ret;
2472
2473 break;
2474 }
2475 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002476#endif /* CONFIG_HS20 */
2477
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002478 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2479 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2480 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2481 verbose);
2482 if (res >= 0)
2483 pos += res;
2484 }
2485
Dmitry Shmidt29333592017-01-09 12:27:11 -08002486#ifdef CONFIG_MACSEC
2487 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2488 if (res > 0)
2489 pos += res;
2490#endif /* CONFIG_MACSEC */
2491
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002492 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2493 if (sess_id) {
2494 char *start = pos;
2495
2496 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2497 if (os_snprintf_error(end - pos, ret))
2498 return start - buf;
2499 pos += ret;
2500 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2501 if (ret <= 0)
2502 return start - buf;
2503 pos += ret;
2504 ret = os_snprintf(pos, end - pos, "\n");
2505 if (os_snprintf_error(end - pos, ret))
2506 return start - buf;
2507 pos += ret;
2508 }
2509
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002510 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2511 if (res >= 0)
2512 pos += res;
2513
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002514#ifdef CONFIG_WPS
2515 {
2516 char uuid_str[100];
2517 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2518 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002519 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002520 return pos - buf;
2521 pos += ret;
2522 }
2523#endif /* CONFIG_WPS */
2524
Roshan Pius3a1667e2018-07-03 15:17:14 -07002525 if (wpa_s->ieee80211ac) {
2526 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2527 if (os_snprintf_error(end - pos, ret))
2528 return pos - buf;
2529 pos += ret;
2530 }
2531
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002532#ifdef ANDROID
vandwalleffc70182014-09-11 11:40:14 -07002533 /*
2534 * Allow using the STATUS command with default behavior, say for debug,
2535 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2536 * events with STATUS-NO_EVENTS.
2537 */
2538 if (os_strcmp(params, "-NO_EVENTS")) {
2539 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2540 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2541 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2542 wpa_s->wpa_state,
2543 MAC2STR(wpa_s->bssid),
2544 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2545 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2546 wpa_s->current_ssid->ssid_len) : "");
2547 if (wpa_s->wpa_state == WPA_COMPLETED) {
2548 struct wpa_ssid *ssid = wpa_s->current_ssid;
Sunil Ravi89eba102022-09-13 21:04:37 -07002549 char mld_addr[50];
2550
2551 mld_addr[0] = '\0';
2552 if (wpa_s->valid_links)
2553 os_snprintf(mld_addr, sizeof(mld_addr),
2554 " ap_mld_addr=" MACSTR,
2555 MAC2STR(wpa_s->ap_mld_addr));
2556
vandwalleffc70182014-09-11 11:40:14 -07002557 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2558 "- connection to " MACSTR
Sunil Ravi89eba102022-09-13 21:04:37 -07002559 " completed %s [id=%d id_str=%s]%s",
vandwalleffc70182014-09-11 11:40:14 -07002560 MAC2STR(wpa_s->bssid), "(auth)",
2561 ssid ? ssid->id : -1,
Sunil Ravi89eba102022-09-13 21:04:37 -07002562 ssid && ssid->id_str ? ssid->id_str : "",
2563 mld_addr);
vandwalleffc70182014-09-11 11:40:14 -07002564 }
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08002565 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002566#endif /* ANDROID */
2567
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002568 return pos - buf;
2569}
2570
2571
2572static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2573 char *cmd)
2574{
2575 char *pos;
2576 int id;
2577 struct wpa_ssid *ssid;
2578 u8 bssid[ETH_ALEN];
2579
2580 /* cmd: "<network id> <BSSID>" */
2581 pos = os_strchr(cmd, ' ');
2582 if (pos == NULL)
2583 return -1;
2584 *pos++ = '\0';
2585 id = atoi(cmd);
2586 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2587 if (hwaddr_aton(pos, bssid)) {
2588 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2589 return -1;
2590 }
2591
2592 ssid = wpa_config_get_network(wpa_s->conf, id);
2593 if (ssid == NULL) {
2594 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2595 "to update", id);
2596 return -1;
2597 }
2598
2599 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2600 ssid->bssid_set = !is_zero_ether_addr(bssid);
2601
2602 return 0;
2603}
2604
2605
Hai Shalom60840252021-02-19 19:02:11 -08002606static int wpa_supplicant_ctrl_iface_bssid_ignore(struct wpa_supplicant *wpa_s,
2607 char *cmd, char *buf,
2608 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002609{
2610 u8 bssid[ETH_ALEN];
Hai Shalom60840252021-02-19 19:02:11 -08002611 struct wpa_bssid_ignore *e;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002612 char *pos, *end;
2613 int ret;
2614
Hai Shalom60840252021-02-19 19:02:11 -08002615 /* cmd: "BSSID_IGNORE [<BSSID>]" */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002616 if (*cmd == '\0') {
2617 pos = buf;
2618 end = buf + buflen;
Hai Shalom60840252021-02-19 19:02:11 -08002619 e = wpa_s->bssid_ignore;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002620 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002621 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2622 MAC2STR(e->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002623 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002624 return pos - buf;
2625 pos += ret;
2626 e = e->next;
2627 }
2628 return pos - buf;
2629 }
2630
2631 cmd++;
2632 if (os_strncmp(cmd, "clear", 5) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -08002633 wpa_bssid_ignore_clear(wpa_s);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002634 os_memcpy(buf, "OK\n", 3);
2635 return 3;
2636 }
2637
Hai Shalom60840252021-02-19 19:02:11 -08002638 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BSSID_IGNORE bssid='%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002639 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002640 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002641 return -1;
2642 }
2643
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002644 /*
2645 * Add the BSSID twice, so its count will be 2, causing it to be
2646 * skipped when processing scan results.
2647 */
Hai Shalom60840252021-02-19 19:02:11 -08002648 ret = wpa_bssid_ignore_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002649 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002650 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002651 ret = wpa_bssid_ignore_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002652 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002653 return -1;
2654 os_memcpy(buf, "OK\n", 3);
2655 return 3;
2656}
2657
2658
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002659static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2660 char *cmd, char *buf,
2661 size_t buflen)
2662{
2663 char *pos, *end, *stamp;
2664 int ret;
2665
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002666 /* cmd: "LOG_LEVEL [<level>]" */
2667 if (*cmd == '\0') {
2668 pos = buf;
2669 end = buf + buflen;
2670 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2671 "Timestamp: %d\n",
2672 debug_level_str(wpa_debug_level),
2673 wpa_debug_timestamp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002674 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002675 ret = 0;
2676
2677 return ret;
2678 }
2679
2680 while (*cmd == ' ')
2681 cmd++;
2682
2683 stamp = os_strchr(cmd, ' ');
2684 if (stamp) {
2685 *stamp++ = '\0';
2686 while (*stamp == ' ') {
2687 stamp++;
2688 }
2689 }
2690
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002691 if (os_strlen(cmd)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002692 int level = str_to_debug_level(cmd);
2693 if (level < 0)
2694 return -1;
2695 wpa_debug_level = level;
2696 }
2697
2698 if (stamp && os_strlen(stamp))
2699 wpa_debug_timestamp = atoi(stamp);
2700
2701 os_memcpy(buf, "OK\n", 3);
2702 return 3;
2703}
2704
2705
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002706static int wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002707 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002708{
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002709 char *pos, *end, *prev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002710 struct wpa_ssid *ssid;
2711 int ret;
2712
2713 pos = buf;
2714 end = buf + buflen;
2715 ret = os_snprintf(pos, end - pos,
2716 "network id / ssid / bssid / flags\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002717 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002718 return pos - buf;
2719 pos += ret;
2720
2721 ssid = wpa_s->conf->ssid;
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002722
2723 /* skip over ssids until we find next one */
2724 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2725 int last_id = atoi(cmd + 8);
2726 if (last_id != -1) {
2727 while (ssid != NULL && ssid->id <= last_id) {
2728 ssid = ssid->next;
2729 }
2730 }
2731 }
2732
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002733 while (ssid) {
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002734 prev = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002735 ret = os_snprintf(pos, end - pos, "%d\t%s",
2736 ssid->id,
2737 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002738 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002739 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002740 pos += ret;
2741 if (ssid->bssid_set) {
2742 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2743 MAC2STR(ssid->bssid));
2744 } else {
2745 ret = os_snprintf(pos, end - pos, "\tany");
2746 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002747 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002748 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002749 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002750 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002751 ssid == wpa_s->current_ssid ?
2752 "[CURRENT]" : "",
2753 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002754 ssid->disabled_until.sec ?
2755 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002756 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2757 "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002758 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002759 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002760 pos += ret;
2761 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002762 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002763 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002764 pos += ret;
2765
2766 ssid = ssid->next;
2767 }
2768
2769 return pos - buf;
2770}
2771
2772
2773static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2774{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002775 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002776 ret = os_snprintf(pos, end - pos, "-");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002777 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002778 return pos;
2779 pos += ret;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002780 ret = wpa_write_ciphers(pos, end, cipher, "+");
2781 if (ret < 0)
2782 return pos;
2783 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002784 return pos;
2785}
2786
2787
2788static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2789 const u8 *ie, size_t ie_len)
2790{
2791 struct wpa_ie_data data;
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002792 char *start;
2793 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002794
2795 ret = os_snprintf(pos, end - pos, "[%s-", proto);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002796 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002797 return pos;
2798 pos += ret;
2799
2800 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2801 ret = os_snprintf(pos, end - pos, "?]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002802 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002803 return pos;
2804 pos += ret;
2805 return pos;
2806 }
2807
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002808 start = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002809 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002810 ret = os_snprintf(pos, end - pos, "%sEAP",
2811 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002812 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002813 return pos;
2814 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002815 }
2816 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002817 ret = os_snprintf(pos, end - pos, "%sPSK",
2818 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002819 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002820 return pos;
2821 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002822 }
2823 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002824 ret = os_snprintf(pos, end - pos, "%sNone",
2825 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002826 if (os_snprintf_error(end - pos, ret))
2827 return pos;
2828 pos += ret;
2829 }
2830 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2831 ret = os_snprintf(pos, end - pos, "%sSAE",
2832 pos == start ? "" : "+");
2833 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002834 return pos;
2835 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002836 }
Sunil Ravi89eba102022-09-13 21:04:37 -07002837 if (data.key_mgmt & WPA_KEY_MGMT_SAE_EXT_KEY) {
2838 ret = os_snprintf(pos, end - pos, "%sSAE-EXT-KEY",
2839 pos == start ? "" : "+");
2840 if (os_snprintf_error(end - pos, ret))
2841 return pos;
2842 pos += ret;
2843 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002844#ifdef CONFIG_IEEE80211R
2845 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2846 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002847 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002848 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002849 return pos;
2850 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002851 }
2852 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2853 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002854 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002855 if (os_snprintf_error(end - pos, ret))
2856 return pos;
2857 pos += ret;
2858 }
2859 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2860 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2861 pos == start ? "" : "+");
2862 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002863 return pos;
2864 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002865 }
Sunil Ravi89eba102022-09-13 21:04:37 -07002866 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE_EXT_KEY) {
2867 ret = os_snprintf(pos, end - pos, "%sFT/SAE-EXT-KEY",
2868 pos == start ? "" : "+");
2869 if (os_snprintf_error(end - pos, ret))
2870 return pos;
2871 pos += ret;
2872 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002873#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002874 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2875 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002876 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002877 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002878 return pos;
2879 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002880 }
2881 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2882 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002883 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002884 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002885 return pos;
2886 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002887 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002888
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002889#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002890 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2891 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2892 pos == start ? "" : "+");
2893 if (os_snprintf_error(end - pos, ret))
2894 return pos;
2895 pos += ret;
2896 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002897#endif /* CONFIG_SUITEB */
2898
2899#ifdef CONFIG_SUITEB192
2900 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2901 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2902 pos == start ? "" : "+");
2903 if (os_snprintf_error(end - pos, ret))
2904 return pos;
2905 pos += ret;
2906 }
2907#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002908
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002909#ifdef CONFIG_FILS
2910 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2911 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2912 pos == start ? "" : "+");
2913 if (os_snprintf_error(end - pos, ret))
2914 return pos;
2915 pos += ret;
2916 }
2917 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2918 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2919 pos == start ? "" : "+");
2920 if (os_snprintf_error(end - pos, ret))
2921 return pos;
2922 pos += ret;
2923 }
2924#ifdef CONFIG_IEEE80211R
2925 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2926 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2927 pos == start ? "" : "+");
2928 if (os_snprintf_error(end - pos, ret))
2929 return pos;
2930 pos += ret;
2931 }
2932 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2933 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2934 pos == start ? "" : "+");
2935 if (os_snprintf_error(end - pos, ret))
2936 return pos;
2937 pos += ret;
2938 }
2939#endif /* CONFIG_IEEE80211R */
2940#endif /* CONFIG_FILS */
2941
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002942#ifdef CONFIG_OWE
2943 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2944 ret = os_snprintf(pos, end - pos, "%sOWE",
2945 pos == start ? "" : "+");
2946 if (os_snprintf_error(end - pos, ret))
2947 return pos;
2948 pos += ret;
2949 }
2950#endif /* CONFIG_OWE */
2951
2952#ifdef CONFIG_DPP
2953 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
2954 ret = os_snprintf(pos, end - pos, "%sDPP",
2955 pos == start ? "" : "+");
2956 if (os_snprintf_error(end - pos, ret))
2957 return pos;
2958 pos += ret;
2959 }
2960#endif /* CONFIG_DPP */
2961
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002962 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2963 ret = os_snprintf(pos, end - pos, "%sOSEN",
2964 pos == start ? "" : "+");
2965 if (os_snprintf_error(end - pos, ret))
2966 return pos;
2967 pos += ret;
2968 }
2969
Sunil Ravi2a14cf12023-11-21 00:54:38 +00002970#ifdef CONFIG_SHA384
2971 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA384) {
2972 ret = os_snprintf(pos, end - pos, "%sEAP-SHA384",
2973 pos == start ? "" : "+");
2974 if (os_snprintf_error(end - pos, ret))
2975 return pos;
2976 pos += ret;
2977 }
2978#endif /* CONFIG_SHA384 */
2979
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002980 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2981
2982 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2983 ret = os_snprintf(pos, end - pos, "-preauth");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002984 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002985 return pos;
2986 pos += ret;
2987 }
2988
2989 ret = os_snprintf(pos, end - pos, "]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002990 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002991 return pos;
2992 pos += ret;
2993
2994 return pos;
2995}
2996
2997
2998#ifdef CONFIG_WPS
2999static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
3000 char *pos, char *end,
3001 struct wpabuf *wps_ie)
3002{
3003 int ret;
3004 const char *txt;
3005
3006 if (wps_ie == NULL)
3007 return pos;
3008 if (wps_is_selected_pbc_registrar(wps_ie))
3009 txt = "[WPS-PBC]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003010 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
3011 txt = "[WPS-AUTH]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003012 else if (wps_is_selected_pin_registrar(wps_ie))
3013 txt = "[WPS-PIN]";
3014 else
3015 txt = "[WPS]";
3016
3017 ret = os_snprintf(pos, end - pos, "%s", txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003018 if (!os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003019 pos += ret;
3020 wpabuf_free(wps_ie);
3021 return pos;
3022}
3023#endif /* CONFIG_WPS */
3024
3025
3026static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
3027 char *pos, char *end,
3028 const struct wpa_bss *bss)
3029{
3030#ifdef CONFIG_WPS
3031 struct wpabuf *wps_ie;
3032 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
3033 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
3034#else /* CONFIG_WPS */
3035 return pos;
3036#endif /* CONFIG_WPS */
3037}
3038
3039
3040/* Format one result on one text line into a buffer. */
3041static int wpa_supplicant_ctrl_iface_scan_result(
3042 struct wpa_supplicant *wpa_s,
3043 const struct wpa_bss *bss, char *buf, size_t buflen)
3044{
3045 char *pos, *end;
3046 int ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07003047 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe, *rsnxe;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003048
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003049 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003050 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07003051 if (!p2p)
3052 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003053 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
3054 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
3055 0)
3056 return 0; /* Do not show P2P listen discovery results here */
3057
3058 pos = buf;
3059 end = buf + buflen;
3060
3061 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
3062 MAC2STR(bss->bssid), bss->freq, bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003063 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003064 return -1;
3065 pos += ret;
3066 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3067 if (ie)
3068 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
3069 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003070 if (ie2) {
3071 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
3072 ie2, 2 + ie2[1]);
3073 }
Hai Shalom899fcc72020-10-19 14:38:18 -07003074 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003075 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
3076 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
3077 if (os_snprintf_error(end - pos, ret))
3078 return -1;
3079 pos += ret;
3080 }
3081 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
3082 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
3083 if (os_snprintf_error(end - pos, ret))
3084 return -1;
3085 pos += ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07003086 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003087 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
3088 if (osen_ie)
3089 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
3090 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003091 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
3092 if (owe) {
3093 ret = os_snprintf(pos, end - pos,
3094 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
3095 if (os_snprintf_error(end - pos, ret))
3096 return -1;
3097 pos += ret;
3098 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003099 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003100 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003101 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003102 if (os_snprintf_error(end - pos, ret))
3103 return -1;
3104 pos += ret;
3105 }
3106 if (mesh) {
3107 ret = os_snprintf(pos, end - pos, "[MESH]");
3108 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003109 return -1;
3110 pos += ret;
3111 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003112 if (bss_is_dmg(bss)) {
3113 const char *s;
Hai Shalomc3565922019-10-28 11:58:20 -07003114
Hai Shalom60840252021-02-19 19:02:11 -08003115 if (wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_EDMG_OPERATION)) {
Hai Shalomc3565922019-10-28 11:58:20 -07003116 ret = os_snprintf(pos, end - pos, "[EDMG]");
3117 if (os_snprintf_error(end - pos, ret))
3118 return -1;
3119 pos += ret;
3120 }
3121
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003122 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003123 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003124 return -1;
3125 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003126 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3127 case IEEE80211_CAP_DMG_IBSS:
3128 s = "[IBSS]";
3129 break;
3130 case IEEE80211_CAP_DMG_AP:
3131 s = "[ESS]";
3132 break;
3133 case IEEE80211_CAP_DMG_PBSS:
3134 s = "[PBSS]";
3135 break;
3136 default:
3137 s = "";
3138 break;
3139 }
3140 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003141 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003142 return -1;
3143 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003144 } else {
3145 if (bss->caps & IEEE80211_CAP_IBSS) {
3146 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003147 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003148 return -1;
3149 pos += ret;
3150 }
3151 if (bss->caps & IEEE80211_CAP_ESS) {
3152 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003153 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003154 return -1;
3155 pos += ret;
3156 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003157 }
3158 if (p2p) {
3159 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003160 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003161 return -1;
3162 pos += ret;
3163 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003164#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003165 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003166 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003167 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003168 return -1;
3169 pos += ret;
3170 }
3171#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003172#ifdef CONFIG_FILS
3173 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
3174 ret = os_snprintf(pos, end - pos, "[FILS]");
3175 if (os_snprintf_error(end - pos, ret))
3176 return -1;
3177 pos += ret;
3178 }
3179#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003180#ifdef CONFIG_FST
3181 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
3182 ret = os_snprintf(pos, end - pos, "[FST]");
3183 if (os_snprintf_error(end - pos, ret))
3184 return -1;
3185 pos += ret;
3186 }
3187#endif /* CONFIG_FST */
Hai Shalom74f70d42019-02-11 14:42:39 -08003188 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
3189 ret = os_snprintf(pos, end - pos, "[UTF-8]");
3190 if (os_snprintf_error(end - pos, ret))
3191 return -1;
3192 pos += ret;
3193 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003194
3195 ret = os_snprintf(pos, end - pos, "\t%s",
3196 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003197 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003198 return -1;
3199 pos += ret;
3200
3201 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003202 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003203 return -1;
3204 pos += ret;
3205
3206 return pos - buf;
3207}
3208
3209
3210static int wpa_supplicant_ctrl_iface_scan_results(
3211 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3212{
3213 char *pos, *end;
3214 struct wpa_bss *bss;
3215 int ret;
3216
3217 pos = buf;
3218 end = buf + buflen;
3219 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
3220 "flags / ssid\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003221 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003222 return pos - buf;
3223 pos += ret;
3224
3225 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3226 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
3227 end - pos);
3228 if (ret < 0 || ret >= end - pos)
3229 return pos - buf;
3230 pos += ret;
3231 }
3232
3233 return pos - buf;
3234}
3235
3236
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003237#ifdef CONFIG_MESH
3238
3239static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3240 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
3241{
3242 char *pos, ifname[IFNAMSIZ + 1];
3243
3244 ifname[0] = '\0';
3245
3246 pos = os_strstr(cmd, "ifname=");
3247 if (pos) {
3248 pos += 7;
3249 os_strlcpy(ifname, pos, sizeof(ifname));
3250 }
3251
3252 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
3253 return -1;
3254
3255 os_strlcpy(reply, ifname, max_len);
3256 return os_strlen(ifname);
3257}
3258
3259
3260static int wpa_supplicant_ctrl_iface_mesh_group_add(
3261 struct wpa_supplicant *wpa_s, char *cmd)
3262{
3263 int id;
3264 struct wpa_ssid *ssid;
3265
3266 id = atoi(cmd);
3267 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
3268
3269 ssid = wpa_config_get_network(wpa_s->conf, id);
3270 if (ssid == NULL) {
3271 wpa_printf(MSG_DEBUG,
3272 "CTRL_IFACE: Could not find network id=%d", id);
3273 return -1;
3274 }
3275 if (ssid->mode != WPAS_MODE_MESH) {
3276 wpa_printf(MSG_DEBUG,
3277 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3278 return -1;
3279 }
3280 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
Sunil Ravi89eba102022-09-13 21:04:37 -07003281 ssid->key_mgmt != WPA_KEY_MGMT_SAE &&
3282 ssid->key_mgmt != WPA_KEY_MGMT_SAE_EXT_KEY) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003283 wpa_printf(MSG_ERROR,
3284 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3285 return -1;
3286 }
3287
3288 /*
3289 * TODO: If necessary write our own group_add function,
3290 * for now we can reuse select_network
3291 */
3292 wpa_supplicant_select_network(wpa_s, ssid);
3293
3294 return 0;
3295}
3296
3297
3298static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3299 struct wpa_supplicant *wpa_s, char *cmd)
3300{
3301 struct wpa_supplicant *orig;
3302 struct wpa_global *global;
3303 int found = 0;
3304
3305 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3306
3307 global = wpa_s->global;
3308 orig = wpa_s;
3309
3310 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3311 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3312 found = 1;
3313 break;
3314 }
3315 }
3316 if (!found) {
3317 wpa_printf(MSG_ERROR,
3318 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3319 cmd);
3320 return -1;
3321 }
3322 if (wpa_s->mesh_if_created && wpa_s == orig) {
3323 wpa_printf(MSG_ERROR,
3324 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3325 return -1;
3326 }
3327
3328 wpa_s->reassociate = 0;
3329 wpa_s->disconnected = 1;
3330 wpa_supplicant_cancel_sched_scan(wpa_s);
3331 wpa_supplicant_cancel_scan(wpa_s);
3332
3333 /*
3334 * TODO: If necessary write our own group_remove function,
3335 * for now we can reuse deauthenticate
3336 */
3337 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3338
3339 if (wpa_s->mesh_if_created)
3340 wpa_supplicant_remove_iface(global, wpa_s, 0);
3341
3342 return 0;
3343}
3344
Dmitry Shmidte4663042016-04-04 10:07:49 -07003345
3346static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3347 struct wpa_supplicant *wpa_s, char *cmd)
3348{
3349 u8 addr[ETH_ALEN];
3350
3351 if (hwaddr_aton(cmd, addr) < 0)
3352 return -1;
3353
3354 return wpas_mesh_peer_remove(wpa_s, addr);
3355}
3356
3357
3358static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3359 struct wpa_supplicant *wpa_s, char *cmd)
3360{
3361 u8 addr[ETH_ALEN];
3362 int duration;
3363 char *pos;
3364
3365 pos = os_strstr(cmd, " duration=");
3366 if (pos) {
3367 *pos = '\0';
3368 duration = atoi(pos + 10);
3369 } else {
3370 duration = -1;
3371 }
3372
3373 if (hwaddr_aton(cmd, addr))
3374 return -1;
3375
3376 return wpas_mesh_peer_add(wpa_s, addr, duration);
3377}
3378
Hai Shalom81f62d82019-07-22 12:10:00 -07003379
3380static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3381 struct wpa_supplicant *wpa_s, char *cmd)
3382{
3383 struct ether_header *eth;
3384 u8 addr[ETH_ALEN];
3385 u8 *buf;
3386 char *pos;
3387 size_t payload_len = 0, len;
3388 int ret = -1;
3389
3390 if (hwaddr_aton(cmd, addr))
3391 return -1;
3392
3393 pos = os_strstr(cmd, " payload=");
3394 if (pos) {
3395 pos = pos + 9;
3396 payload_len = os_strlen(pos);
3397 if (payload_len & 1)
3398 return -1;
3399
3400 payload_len /= 2;
3401 }
3402
3403 len = ETH_HLEN + payload_len;
3404 buf = os_malloc(len);
3405 if (!buf)
3406 return -1;
3407
3408 eth = (struct ether_header *) buf;
3409 os_memcpy(eth->ether_dhost, addr, ETH_ALEN);
3410 os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN);
3411 eth->ether_type = htons(ETH_P_802_3);
3412
3413 if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0)
3414 goto fail;
3415
3416 ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len);
3417fail:
3418 os_free(buf);
3419 return -ret;
3420}
3421
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003422#endif /* CONFIG_MESH */
3423
3424
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003425static int wpa_supplicant_ctrl_iface_select_network(
3426 struct wpa_supplicant *wpa_s, char *cmd)
3427{
3428 int id;
3429 struct wpa_ssid *ssid;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003430 char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003431
3432 /* cmd: "<network id>" or "any" */
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003433 if (os_strncmp(cmd, "any", 3) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003434 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3435 ssid = NULL;
3436 } else {
3437 id = atoi(cmd);
3438 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3439
3440 ssid = wpa_config_get_network(wpa_s->conf, id);
3441 if (ssid == NULL) {
3442 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3443 "network id=%d", id);
3444 return -1;
3445 }
3446 if (ssid->disabled == 2) {
3447 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3448 "SELECT_NETWORK with persistent P2P group");
3449 return -1;
3450 }
3451 }
3452
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003453 pos = os_strstr(cmd, " freq=");
3454 if (pos) {
3455 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3456 if (freqs) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003457 os_free(wpa_s->select_network_scan_freqs);
3458 wpa_s->select_network_scan_freqs = freqs;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003459 }
3460 }
3461
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003462 wpa_s->scan_min_time.sec = 0;
3463 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003464 wpa_supplicant_select_network(wpa_s, ssid);
3465
3466 return 0;
3467}
3468
3469
3470static int wpa_supplicant_ctrl_iface_enable_network(
3471 struct wpa_supplicant *wpa_s, char *cmd)
3472{
3473 int id;
3474 struct wpa_ssid *ssid;
3475
3476 /* cmd: "<network id>" or "all" */
3477 if (os_strcmp(cmd, "all") == 0) {
3478 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3479 ssid = NULL;
3480 } else {
3481 id = atoi(cmd);
3482 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3483
3484 ssid = wpa_config_get_network(wpa_s->conf, id);
3485 if (ssid == NULL) {
3486 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3487 "network id=%d", id);
3488 return -1;
3489 }
3490 if (ssid->disabled == 2) {
3491 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3492 "ENABLE_NETWORK with persistent P2P group");
3493 return -1;
3494 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003495
3496 if (os_strstr(cmd, " no-connect")) {
3497 ssid->disabled = 0;
3498 return 0;
3499 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003500 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003501 wpa_s->scan_min_time.sec = 0;
3502 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003503 wpa_supplicant_enable_network(wpa_s, ssid);
3504
3505 return 0;
3506}
3507
3508
3509static int wpa_supplicant_ctrl_iface_disable_network(
3510 struct wpa_supplicant *wpa_s, char *cmd)
3511{
3512 int id;
3513 struct wpa_ssid *ssid;
3514
3515 /* cmd: "<network id>" or "all" */
3516 if (os_strcmp(cmd, "all") == 0) {
3517 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3518 ssid = NULL;
3519 } else {
3520 id = atoi(cmd);
3521 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3522
3523 ssid = wpa_config_get_network(wpa_s->conf, id);
3524 if (ssid == NULL) {
3525 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3526 "network id=%d", id);
3527 return -1;
3528 }
3529 if (ssid->disabled == 2) {
3530 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3531 "DISABLE_NETWORK with persistent P2P "
3532 "group");
3533 return -1;
3534 }
3535 }
3536 wpa_supplicant_disable_network(wpa_s, ssid);
3537
3538 return 0;
3539}
3540
3541
3542static int wpa_supplicant_ctrl_iface_add_network(
3543 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3544{
3545 struct wpa_ssid *ssid;
3546 int ret;
3547
3548 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3549
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003550 ssid = wpa_supplicant_add_network(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003551 if (ssid == NULL)
3552 return -1;
3553
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003554 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003555 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003556 return -1;
3557 return ret;
3558}
3559
3560
3561static int wpa_supplicant_ctrl_iface_remove_network(
3562 struct wpa_supplicant *wpa_s, char *cmd)
3563{
3564 int id;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003565 int result;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003566
3567 /* cmd: "<network id>" or "all" */
3568 if (os_strcmp(cmd, "all") == 0) {
3569 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Hai Shalom899fcc72020-10-19 14:38:18 -07003570 return wpa_supplicant_remove_all_networks(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003571 }
3572
3573 id = atoi(cmd);
3574 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3575
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003576 result = wpa_supplicant_remove_network(wpa_s, id);
3577 if (result == -1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003578 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3579 "id=%d", id);
3580 return -1;
3581 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003582 if (result == -2) {
Deepthi Gowria831d782012-09-03 11:55:38 +03003583 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3584 "network id=%d", id);
3585 return -1;
3586 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003587 return 0;
3588}
3589
3590
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003591static int wpa_supplicant_ctrl_iface_update_network(
3592 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3593 char *name, char *value)
3594{
Dmitry Shmidte4663042016-04-04 10:07:49 -07003595 int ret;
3596
3597 ret = wpa_config_set(ssid, name, value, 0);
3598 if (ret < 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003599 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3600 "variable '%s'", name);
3601 return -1;
3602 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07003603 if (ret == 1)
3604 return 0; /* No change to the previously configured value */
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003605
Hai Shalom899fcc72020-10-19 14:38:18 -07003606#ifdef CONFIG_BGSCAN
3607 if (os_strcmp(name, "bgscan") == 0) {
3608 /*
3609 * Reset the bgscan parameters for the current network and
3610 * return. There's no need to flush caches for bgscan parameter
3611 * changes.
3612 */
3613 if (wpa_s->current_ssid == ssid &&
3614 wpa_s->wpa_state == WPA_COMPLETED)
3615 wpa_supplicant_reset_bgscan(wpa_s);
3616 return 0;
3617 }
3618#endif /* CONFIG_BGSCAN */
3619
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003620 if (os_strcmp(name, "bssid") != 0 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003621 os_strcmp(name, "bssid_hint") != 0 &&
Sunil Ravi2a14cf12023-11-21 00:54:38 +00003622 os_strcmp(name, "scan_freq") != 0 &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003623 os_strcmp(name, "priority") != 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003624 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3625
Dmitry Shmidte4663042016-04-04 10:07:49 -07003626 if (wpa_s->current_ssid == ssid ||
3627 wpa_s->current_ssid == NULL) {
3628 /*
3629 * Invalidate the EAP session cache if anything in the
3630 * current or previously used configuration changes.
3631 */
3632 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3633 }
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003634 }
3635
3636 if ((os_strcmp(name, "psk") == 0 &&
3637 value[0] == '"' && ssid->ssid_len) ||
3638 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3639 wpa_config_update_psk(ssid);
3640 else if (os_strcmp(name, "priority") == 0)
3641 wpa_config_update_prio_list(wpa_s->conf);
3642
3643 return 0;
3644}
3645
3646
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003647static int wpa_supplicant_ctrl_iface_set_network(
3648 struct wpa_supplicant *wpa_s, char *cmd)
3649{
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003650 int id, ret, prev_bssid_set, prev_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003651 struct wpa_ssid *ssid;
3652 char *name, *value;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003653 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003654
3655 /* cmd: "<network id> <variable name> <value>" */
3656 name = os_strchr(cmd, ' ');
3657 if (name == NULL)
3658 return -1;
3659 *name++ = '\0';
3660
3661 value = os_strchr(name, ' ');
3662 if (value == NULL)
3663 return -1;
3664 *value++ = '\0';
3665
3666 id = atoi(cmd);
3667 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3668 id, name);
3669 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3670 (u8 *) value, os_strlen(value));
3671
3672 ssid = wpa_config_get_network(wpa_s->conf, id);
3673 if (ssid == NULL) {
3674 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3675 "id=%d", id);
3676 return -1;
3677 }
3678
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003679 prev_bssid_set = ssid->bssid_set;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003680 prev_disabled = ssid->disabled;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003681 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3682 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3683 value);
3684 if (ret == 0 &&
3685 (ssid->bssid_set != prev_bssid_set ||
3686 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3687 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003688
3689 if (prev_disabled != ssid->disabled &&
3690 (prev_disabled == 2 || ssid->disabled == 2))
3691 wpas_notify_network_type_changed(wpa_s, ssid);
3692
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003693 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003694}
3695
3696
3697static int wpa_supplicant_ctrl_iface_get_network(
3698 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3699{
3700 int id;
3701 size_t res;
3702 struct wpa_ssid *ssid;
3703 char *name, *value;
3704
3705 /* cmd: "<network id> <variable name>" */
3706 name = os_strchr(cmd, ' ');
3707 if (name == NULL || buflen == 0)
3708 return -1;
3709 *name++ = '\0';
3710
3711 id = atoi(cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003712 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003713 id, name);
3714
3715 ssid = wpa_config_get_network(wpa_s->conf, id);
3716 if (ssid == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003717 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003718 "id=%d", id);
3719 return -1;
3720 }
3721
3722 value = wpa_config_get_no_key(ssid, name);
3723 if (value == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003724 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003725 "variable '%s'", name);
3726 return -1;
3727 }
3728
3729 res = os_strlcpy(buf, value, buflen);
3730 if (res >= buflen) {
3731 os_free(value);
3732 return -1;
3733 }
3734
3735 os_free(value);
3736
3737 return res;
3738}
3739
3740
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003741static int wpa_supplicant_ctrl_iface_dup_network(
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003742 struct wpa_supplicant *wpa_s, char *cmd,
3743 struct wpa_supplicant *dst_wpa_s)
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003744{
3745 struct wpa_ssid *ssid_s, *ssid_d;
3746 char *name, *id, *value;
3747 int id_s, id_d, ret;
3748
3749 /* cmd: "<src network id> <dst network id> <variable name>" */
3750 id = os_strchr(cmd, ' ');
3751 if (id == NULL)
3752 return -1;
3753 *id++ = '\0';
3754
3755 name = os_strchr(id, ' ');
3756 if (name == NULL)
3757 return -1;
3758 *name++ = '\0';
3759
3760 id_s = atoi(cmd);
3761 id_d = atoi(id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003762
3763 wpa_printf(MSG_DEBUG,
3764 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3765 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003766
3767 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3768 if (ssid_s == NULL) {
3769 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3770 "network id=%d", id_s);
3771 return -1;
3772 }
3773
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003774 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003775 if (ssid_d == NULL) {
3776 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003777 "network id=%d", id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003778 return -1;
3779 }
3780
3781 value = wpa_config_get(ssid_s, name);
3782 if (value == NULL) {
3783 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3784 "variable '%s'", name);
3785 return -1;
3786 }
3787
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003788 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003789 value);
3790
3791 os_free(value);
3792
3793 return ret;
3794}
3795
3796
Dmitry Shmidt04949592012-07-19 12:16:46 -07003797static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3798 char *buf, size_t buflen)
3799{
3800 char *pos, *end;
3801 struct wpa_cred *cred;
3802 int ret;
3803
3804 pos = buf;
3805 end = buf + buflen;
3806 ret = os_snprintf(pos, end - pos,
3807 "cred id / realm / username / domain / imsi\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003808 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003809 return pos - buf;
3810 pos += ret;
3811
3812 cred = wpa_s->conf->cred;
3813 while (cred) {
3814 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3815 cred->id, cred->realm ? cred->realm : "",
3816 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07003817 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003818 cred->imsi ? cred->imsi : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003819 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003820 return pos - buf;
3821 pos += ret;
3822
3823 cred = cred->next;
3824 }
3825
3826 return pos - buf;
3827}
3828
3829
3830static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3831 char *buf, size_t buflen)
3832{
3833 struct wpa_cred *cred;
3834 int ret;
3835
3836 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3837
3838 cred = wpa_config_add_cred(wpa_s->conf);
3839 if (cred == NULL)
3840 return -1;
3841
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003842 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3843
Dmitry Shmidt04949592012-07-19 12:16:46 -07003844 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003845 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003846 return -1;
3847 return ret;
3848}
3849
3850
3851static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3852 char *cmd)
3853{
3854 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003855 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003856
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003857 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3858 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003859 if (os_strcmp(cmd, "all") == 0) {
3860 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
Hai Shaloma20dcd72022-02-04 13:43:00 -08003861 return wpas_remove_all_creds(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003862 }
3863
3864 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3865 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3866 cmd + 8);
3867 cred = wpa_s->conf->cred;
3868 while (cred) {
3869 prev = cred;
3870 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003871 if (prev->domain) {
3872 size_t i;
3873 for (i = 0; i < prev->num_domain; i++) {
3874 if (os_strcmp(prev->domain[i], cmd + 8)
3875 != 0)
3876 continue;
Hai Shaloma20dcd72022-02-04 13:43:00 -08003877 wpas_remove_cred(wpa_s, prev);
Dmitry Shmidt051af732013-10-22 13:52:46 -07003878 break;
3879 }
3880 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003881 }
3882 return 0;
3883 }
3884
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003885 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3886 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3887 cmd + 16);
3888 cred = wpa_s->conf->cred;
3889 while (cred) {
3890 prev = cred;
3891 cred = cred->next;
3892 if (prev->provisioning_sp &&
3893 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
Hai Shaloma20dcd72022-02-04 13:43:00 -08003894 wpas_remove_cred(wpa_s, prev);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003895 }
3896 return 0;
3897 }
3898
Dmitry Shmidt04949592012-07-19 12:16:46 -07003899 id = atoi(cmd);
3900 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3901
3902 cred = wpa_config_get_cred(wpa_s->conf, id);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003903 return wpas_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003904}
3905
3906
3907static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3908 char *cmd)
3909{
3910 int id;
3911 struct wpa_cred *cred;
3912 char *name, *value;
3913
3914 /* cmd: "<cred id> <variable name> <value>" */
3915 name = os_strchr(cmd, ' ');
3916 if (name == NULL)
3917 return -1;
3918 *name++ = '\0';
3919
3920 value = os_strchr(name, ' ');
3921 if (value == NULL)
3922 return -1;
3923 *value++ = '\0';
3924
3925 id = atoi(cmd);
3926 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3927 id, name);
3928 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3929 (u8 *) value, os_strlen(value));
3930
3931 cred = wpa_config_get_cred(wpa_s->conf, id);
3932 if (cred == NULL) {
3933 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3934 id);
3935 return -1;
3936 }
3937
3938 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3939 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3940 "variable '%s'", name);
3941 return -1;
3942 }
3943
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003944 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3945
Dmitry Shmidt04949592012-07-19 12:16:46 -07003946 return 0;
3947}
3948
3949
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003950static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3951 char *cmd, char *buf,
3952 size_t buflen)
3953{
3954 int id;
3955 size_t res;
3956 struct wpa_cred *cred;
3957 char *name, *value;
3958
3959 /* cmd: "<cred id> <variable name>" */
3960 name = os_strchr(cmd, ' ');
3961 if (name == NULL)
3962 return -1;
3963 *name++ = '\0';
3964
3965 id = atoi(cmd);
3966 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3967 id, name);
3968
3969 cred = wpa_config_get_cred(wpa_s->conf, id);
3970 if (cred == NULL) {
3971 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3972 id);
3973 return -1;
3974 }
3975
3976 value = wpa_config_get_cred_no_key(cred, name);
3977 if (value == NULL) {
3978 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3979 name);
3980 return -1;
3981 }
3982
3983 res = os_strlcpy(buf, value, buflen);
3984 if (res >= buflen) {
3985 os_free(value);
3986 return -1;
3987 }
3988
3989 os_free(value);
3990
3991 return res;
3992}
3993
3994
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003995#ifndef CONFIG_NO_CONFIG_WRITE
3996static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3997{
3998 int ret;
3999
4000 if (!wpa_s->conf->update_config) {
4001 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
4002 "to update configuration (update_config=0)");
4003 return -1;
4004 }
4005
4006 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
4007 if (ret) {
4008 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
4009 "update configuration");
4010 } else {
4011 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
4012 " updated");
4013 }
4014
4015 return ret;
4016}
4017#endif /* CONFIG_NO_CONFIG_WRITE */
4018
4019
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004020struct cipher_info {
4021 unsigned int capa;
4022 const char *name;
4023 int group_only;
4024};
4025
4026static const struct cipher_info ciphers[] = {
4027 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
4028 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
4029 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
4030 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07004031#ifndef CONFIG_NO_TKIP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004032 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07004033#endif /* CONFIG_NO_TKIP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004034 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
Hai Shalomfdcde762020-04-02 11:19:20 -07004035#ifdef CONFIG_WEP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004036 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
4037 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004038#endif /* CONFIG_WEP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004039};
4040
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004041static const struct cipher_info ciphers_group_mgmt[] = {
4042 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
4043 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
4044 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
4045 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
4046};
4047
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004048
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004049static int ctrl_iface_get_capability_pairwise(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004050 struct wpa_driver_capa *capa,
4051 char *buf, size_t buflen)
4052{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004053 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004054 char *pos, *end;
4055 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004056 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004057
4058 pos = buf;
4059 end = pos + buflen;
4060
4061 if (res < 0) {
4062 if (strict)
4063 return 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07004064#ifdef CONFIG_NO_TKIP
4065 len = os_strlcpy(buf, "CCMP NONE", buflen);
4066#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004067 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004068#endif /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004069 if (len >= buflen)
4070 return -1;
4071 return len;
4072 }
4073
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004074 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4075 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
4076 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004077 pos == buf ? "" : " ",
4078 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004079 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004080 return pos - buf;
4081 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004082 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004083 }
4084
4085 return pos - buf;
4086}
4087
4088
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004089static int ctrl_iface_get_capability_group(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004090 struct wpa_driver_capa *capa,
4091 char *buf, size_t buflen)
4092{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004093 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004094 char *pos, *end;
4095 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004096 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004097
4098 pos = buf;
4099 end = pos + buflen;
4100
4101 if (res < 0) {
4102 if (strict)
4103 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07004104#ifdef CONFIG_WEP
Hai Shalomb755a2a2020-04-23 21:49:02 -07004105#ifdef CONFIG_NO_TKIP
4106 len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen);
4107#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004108 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004109#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004110#else /* CONFIG_WEP */
Hai Shalomb755a2a2020-04-23 21:49:02 -07004111#ifdef CONFIG_NO_TKIP
4112 len = os_strlcpy(buf, "CCMP", buflen);
4113#else /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004114 len = os_strlcpy(buf, "CCMP TKIP", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004115#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004116#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004117 if (len >= buflen)
4118 return -1;
4119 return len;
4120 }
4121
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004122 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4123 if (capa->enc & ciphers[i].capa) {
4124 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004125 pos == buf ? "" : " ",
4126 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004127 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004128 return pos - buf;
4129 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004130 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004131 }
4132
4133 return pos - buf;
4134}
4135
4136
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004137static int ctrl_iface_get_capability_group_mgmt(int res, bool strict,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004138 struct wpa_driver_capa *capa,
4139 char *buf, size_t buflen)
4140{
4141 int ret;
4142 char *pos, *end;
4143 unsigned int i;
4144
4145 pos = buf;
4146 end = pos + buflen;
4147
4148 if (res < 0)
4149 return 0;
4150
4151 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
4152 if (capa->enc & ciphers_group_mgmt[i].capa) {
4153 ret = os_snprintf(pos, end - pos, "%s%s",
4154 pos == buf ? "" : " ",
4155 ciphers_group_mgmt[i].name);
4156 if (os_snprintf_error(end - pos, ret))
4157 return pos - buf;
4158 pos += ret;
4159 }
4160 }
4161
4162 return pos - buf;
4163}
4164
4165
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004166static int iftype_str_to_index(const char *iftype_str)
4167{
4168 if (!iftype_str)
4169 return WPA_IF_MAX;
4170
4171 if (os_strcmp(iftype_str, "STATION") == 0)
4172 return WPA_IF_STATION;
4173
4174 if (os_strcmp(iftype_str, "AP_VLAN") == 0)
4175 return WPA_IF_AP_VLAN;
4176
4177 if (os_strcmp(iftype_str, "AP") == 0)
4178 return WPA_IF_AP_BSS;
4179
4180 if (os_strcmp(iftype_str, "P2P_GO") == 0)
4181 return WPA_IF_P2P_GO;
4182
4183 if (os_strcmp(iftype_str, "P2P_CLIENT") == 0)
4184 return WPA_IF_P2P_CLIENT;
4185
4186 if (os_strcmp(iftype_str, "P2P_DEVICE") == 0)
4187 return WPA_IF_P2P_DEVICE;
4188
4189 if (os_strcmp(iftype_str, "MESH") == 0)
4190 return WPA_IF_MESH;
4191
4192 if (os_strcmp(iftype_str, "IBSS") == 0)
4193 return WPA_IF_IBSS;
4194
4195 if (os_strcmp(iftype_str, "NAN") == 0)
4196 return WPA_IF_NAN;
4197
4198 return WPA_IF_MAX;
4199}
4200
4201
4202static int ctrl_iface_get_capability_key_mgmt(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004203 struct wpa_driver_capa *capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004204 const char *iftype_str,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004205 char *buf, size_t buflen)
4206{
4207 int ret;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004208 unsigned int key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004209 char *pos, *end;
4210 size_t len;
4211
4212 pos = buf;
4213 end = pos + buflen;
4214
4215 if (res < 0) {
4216 if (strict)
4217 return 0;
4218 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4219 "NONE", buflen);
4220 if (len >= buflen)
4221 return -1;
4222 return len;
4223 }
4224
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004225 if (iftype_str) {
4226 enum wpa_driver_if_type iftype;
4227
4228 iftype = iftype_str_to_index(iftype_str);
4229 if (iftype == WPA_IF_MAX)
4230 return -1;
4231 key_mgmt = capa->key_mgmt_iftype[iftype];
4232 } else {
4233 key_mgmt = capa->key_mgmt;
4234 }
4235
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004236 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004237 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004238 return pos - buf;
4239 pos += ret;
4240
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004241 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4242 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004243 ret = os_snprintf(pos, end - pos, " WPA-EAP");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004244 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004245 return pos - buf;
4246 pos += ret;
4247 }
4248
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004249 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
4250 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004251 ret = os_snprintf(pos, end - pos, " WPA-PSK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004252 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004253 return pos - buf;
4254 pos += ret;
4255 }
4256
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004257 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004258 ret = os_snprintf(pos, end - pos, " WPA-NONE");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004259 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004260 return pos - buf;
4261 pos += ret;
4262 }
4263
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304264 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WAPI_PSK) {
4265 ret = os_snprintf(pos, end - pos, " WAPI-PSK");
4266 if (os_snprintf_error(end - pos, ret))
4267 return pos - buf;
4268 pos += ret;
4269 }
4270
4271 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE) {
4272 ret = os_snprintf(pos, end - pos, " TPK-HANDSHAKE");
4273 if (os_snprintf_error(end - pos, ret))
4274 return pos - buf;
4275 pos += ret;
4276 }
4277
4278 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_CCKM) {
4279 ret = os_snprintf(pos, end - pos, " CCKM");
4280 if (os_snprintf_error(end - pos, ret))
4281 return pos - buf;
4282 pos += ret;
4283 }
4284
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004285#ifdef CONFIG_SUITEB
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004286 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004287 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
4288 if (os_snprintf_error(end - pos, ret))
4289 return pos - buf;
4290 pos += ret;
4291 }
4292#endif /* CONFIG_SUITEB */
4293#ifdef CONFIG_SUITEB192
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004294 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004295 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
4296 if (os_snprintf_error(end - pos, ret))
4297 return pos - buf;
4298 pos += ret;
4299 }
4300#endif /* CONFIG_SUITEB192 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004301#ifdef CONFIG_OWE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004302 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004303 ret = os_snprintf(pos, end - pos, " OWE");
4304 if (os_snprintf_error(end - pos, ret))
4305 return pos - buf;
4306 pos += ret;
4307 }
4308#endif /* CONFIG_OWE */
4309#ifdef CONFIG_DPP
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004310 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004311 ret = os_snprintf(pos, end - pos, " DPP");
4312 if (os_snprintf_error(end - pos, ret))
4313 return pos - buf;
4314 pos += ret;
4315 }
4316#endif /* CONFIG_DPP */
4317#ifdef CONFIG_FILS
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004318 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004319 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
4320 if (os_snprintf_error(end - pos, ret))
4321 return pos - buf;
4322 pos += ret;
4323 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004324 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004325 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
4326 if (os_snprintf_error(end - pos, ret))
4327 return pos - buf;
4328 pos += ret;
4329 }
4330#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004331 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004332 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
4333 if (os_snprintf_error(end - pos, ret))
4334 return pos - buf;
4335 pos += ret;
4336 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004337 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004338 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
4339 if (os_snprintf_error(end - pos, ret))
4340 return pos - buf;
4341 pos += ret;
4342 }
4343#endif /* CONFIG_IEEE80211R */
4344#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08004345#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004346 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004347 ret = os_snprintf(pos, end - pos, " FT-PSK");
4348 if (os_snprintf_error(end - pos, ret))
4349 return pos - buf;
4350 pos += ret;
4351 }
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304352 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) {
4353 ret = os_snprintf(pos, end - pos, " FT-EAP");
4354 if (os_snprintf_error(end - pos, ret))
4355 return pos - buf;
4356 pos += ret;
4357 }
4358#ifdef CONFIG_SAE
4359 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE) {
4360 ret = os_snprintf(pos, end - pos, " FT-SAE");
4361 if (os_snprintf_error(end - pos, ret))
4362 return pos - buf;
4363 pos += ret;
4364 }
Sunil Ravi89eba102022-09-13 21:04:37 -07004365 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE_EXT_KEY) {
4366 ret = os_snprintf(pos, end - pos, " FT-SAE-EXT-KEY");
4367 if (os_snprintf_error(end - pos, ret))
4368 return pos - buf;
4369 pos += ret;
4370 }
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304371#endif /* CONFIG_SAE */
4372#ifdef CONFIG_SHA384
4373 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384) {
4374 ret = os_snprintf(pos, end - pos, " FT-EAP-SHA384");
4375 if (os_snprintf_error(end - pos, ret))
4376 return pos - buf;
4377 pos += ret;
4378 }
4379#endif /* CONFIG_SHA384 */
Hai Shalom74f70d42019-02-11 14:42:39 -08004380#endif /* CONFIG_IEEE80211R */
4381#ifdef CONFIG_SAE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004382 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004383 ret = os_snprintf(pos, end - pos, " SAE");
4384 if (os_snprintf_error(end - pos, ret))
4385 return pos - buf;
4386 pos += ret;
4387 }
Sunil Ravi89eba102022-09-13 21:04:37 -07004388 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE_EXT_KEY) {
4389 ret = os_snprintf(pos, end - pos, " SAE-EXT-KEY");
4390 if (os_snprintf_error(end - pos, ret))
4391 return pos - buf;
4392 pos += ret;
4393 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004394#endif /* CONFIG_SAE */
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304395#ifdef CONFIG_SHA256
4396 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256) {
4397 ret = os_snprintf(pos, end - pos, " WPA-EAP-SHA256");
4398 if (os_snprintf_error(end - pos, ret))
4399 return pos - buf;
4400 pos += ret;
4401 }
4402
4403 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256) {
4404 ret = os_snprintf(pos, end - pos, " WPA-PSK-SHA256");
4405 if (os_snprintf_error(end - pos, ret))
4406 return pos - buf;
4407 pos += ret;
4408 }
4409#endif /* CONFIG_SHA256 */
4410#ifdef CONFIG_HS20
4411 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OSEN) {
4412 ret = os_snprintf(pos, end - pos, " OSEN");
4413 if (os_snprintf_error(end - pos, ret))
4414 return pos - buf;
4415 pos += ret;
4416 }
4417#endif /* CONFIG_HS20 */
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004418
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004419 return pos - buf;
4420}
4421
4422
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004423static int ctrl_iface_get_capability_proto(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004424 struct wpa_driver_capa *capa,
4425 char *buf, size_t buflen)
4426{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004427 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004428 char *pos, *end;
4429 size_t len;
4430
4431 pos = buf;
4432 end = pos + buflen;
4433
4434 if (res < 0) {
4435 if (strict)
4436 return 0;
4437 len = os_strlcpy(buf, "RSN WPA", buflen);
4438 if (len >= buflen)
4439 return -1;
4440 return len;
4441 }
4442
4443 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4444 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004445 ret = os_snprintf(pos, end - pos, "%sRSN",
4446 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004447 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004448 return pos - buf;
4449 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004450 }
4451
4452 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4453 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004454 ret = os_snprintf(pos, end - pos, "%sWPA",
4455 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004456 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004457 return pos - buf;
4458 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004459 }
4460
4461 return pos - buf;
4462}
4463
4464
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004465static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004466 int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004467 struct wpa_driver_capa *capa,
4468 char *buf, size_t buflen)
4469{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004470 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004471 char *pos, *end;
4472 size_t len;
4473
4474 pos = buf;
4475 end = pos + buflen;
4476
4477 if (res < 0) {
4478 if (strict)
4479 return 0;
4480 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4481 if (len >= buflen)
4482 return -1;
4483 return len;
4484 }
4485
4486 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004487 ret = os_snprintf(pos, end - pos, "%sOPEN",
4488 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004489 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004490 return pos - buf;
4491 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004492 }
4493
4494 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4495 ret = os_snprintf(pos, end - pos, "%sSHARED",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004496 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004497 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004498 return pos - buf;
4499 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004500 }
4501
4502 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004503 ret = os_snprintf(pos, end - pos, "%sLEAP",
4504 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004505 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004506 return pos - buf;
4507 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004508 }
4509
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004510#ifdef CONFIG_SAE
4511 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4512 ret = os_snprintf(pos, end - pos, "%sSAE",
4513 pos == buf ? "" : " ");
4514 if (os_snprintf_error(end - pos, ret))
4515 return pos - buf;
4516 pos += ret;
4517 }
4518#endif /* CONFIG_SAE */
4519
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004520#ifdef CONFIG_FILS
4521 if (wpa_is_fils_supported(wpa_s)) {
4522 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4523 pos == buf ? "" : " ");
4524 if (os_snprintf_error(end - pos, ret))
4525 return pos - buf;
4526 pos += ret;
4527 }
4528
4529#ifdef CONFIG_FILS_SK_PFS
4530 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4531 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4532 pos == buf ? "" : " ");
4533 if (os_snprintf_error(end - pos, ret))
4534 return pos - buf;
4535 pos += ret;
4536 }
4537#endif /* CONFIG_FILS_SK_PFS */
4538#endif /* CONFIG_FILS */
4539
Hai Shalom60840252021-02-19 19:02:11 -08004540#ifdef CONFIG_PASN
4541 ret = os_snprintf(pos, end - pos, "%sPASN",
4542 pos == buf ? "" : " ");
4543 if (os_snprintf_error(end - pos, ret))
4544 return pos - buf;
4545 pos += ret;
4546
4547#endif /* CONFIG_PASN */
4548
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004549 return pos - buf;
4550}
4551
4552
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004553static int ctrl_iface_get_capability_modes(int res, bool strict,
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004554 struct wpa_driver_capa *capa,
4555 char *buf, size_t buflen)
4556{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004557 int ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004558 char *pos, *end;
4559 size_t len;
4560
4561 pos = buf;
4562 end = pos + buflen;
4563
4564 if (res < 0) {
4565 if (strict)
4566 return 0;
4567 len = os_strlcpy(buf, "IBSS AP", buflen);
4568 if (len >= buflen)
4569 return -1;
4570 return len;
4571 }
4572
4573 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004574 ret = os_snprintf(pos, end - pos, "%sIBSS",
4575 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004576 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004577 return pos - buf;
4578 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004579 }
4580
4581 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004582 ret = os_snprintf(pos, end - pos, "%sAP",
4583 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004584 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004585 return pos - buf;
4586 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004587 }
4588
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004589#ifdef CONFIG_MESH
4590 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4591 ret = os_snprintf(pos, end - pos, "%sMESH",
4592 pos == buf ? "" : " ");
4593 if (os_snprintf_error(end - pos, ret))
4594 return pos - buf;
4595 pos += ret;
4596 }
4597#endif /* CONFIG_MESH */
4598
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004599 return pos - buf;
4600}
4601
4602
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004603static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4604 char *buf, size_t buflen)
4605{
4606 struct hostapd_channel_data *chnl;
4607 int ret, i, j;
4608 char *pos, *end, *hmode;
4609
4610 pos = buf;
4611 end = pos + buflen;
4612
4613 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4614 switch (wpa_s->hw.modes[j].mode) {
4615 case HOSTAPD_MODE_IEEE80211B:
4616 hmode = "B";
4617 break;
4618 case HOSTAPD_MODE_IEEE80211G:
4619 hmode = "G";
4620 break;
4621 case HOSTAPD_MODE_IEEE80211A:
4622 hmode = "A";
4623 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004624 case HOSTAPD_MODE_IEEE80211AD:
4625 hmode = "AD";
4626 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004627 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004628 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004629 }
4630 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004631 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004632 return pos - buf;
4633 pos += ret;
4634 chnl = wpa_s->hw.modes[j].channels;
4635 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004636 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4637 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004638 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004639 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004640 return pos - buf;
4641 pos += ret;
4642 }
4643 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004644 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004645 return pos - buf;
4646 pos += ret;
4647 }
4648
4649 return pos - buf;
4650}
4651
4652
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004653static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4654 char *buf, size_t buflen)
4655{
4656 struct hostapd_channel_data *chnl;
4657 int ret, i, j;
4658 char *pos, *end, *hmode;
4659
4660 pos = buf;
4661 end = pos + buflen;
4662
4663 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4664 switch (wpa_s->hw.modes[j].mode) {
4665 case HOSTAPD_MODE_IEEE80211B:
4666 hmode = "B";
4667 break;
4668 case HOSTAPD_MODE_IEEE80211G:
4669 hmode = "G";
4670 break;
4671 case HOSTAPD_MODE_IEEE80211A:
4672 hmode = "A";
4673 break;
4674 case HOSTAPD_MODE_IEEE80211AD:
4675 hmode = "AD";
4676 break;
4677 default:
4678 continue;
4679 }
4680 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4681 hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004682 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004683 return pos - buf;
4684 pos += ret;
4685 chnl = wpa_s->hw.modes[j].channels;
4686 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4687 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4688 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004689 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004690 chnl[i].chan, chnl[i].freq,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004691 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4692 " (NO_IR)" : "",
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004693 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4694 " (DFS)" : "");
4695
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004696 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004697 return pos - buf;
4698 pos += ret;
4699 }
4700 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004701 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004702 return pos - buf;
4703 pos += ret;
4704 }
4705
4706 return pos - buf;
4707}
4708
4709
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004710static int wpa_supplicant_ctrl_iface_get_capability(
4711 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4712 size_t buflen)
4713{
4714 struct wpa_driver_capa capa;
4715 int res;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004716 char *next_param, *curr_param, *iftype = NULL;
4717 bool strict = false;
4718 char field[50];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004719 size_t len;
4720
4721 /* Determine whether or not strict checking was requested */
4722 len = os_strlcpy(field, _field, sizeof(field));
4723 if (len >= sizeof(field))
4724 return -1;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004725
4726 next_param = os_strchr(field, ' ');
4727 while (next_param) {
4728 *next_param++ = '\0';
4729 curr_param = next_param;
4730 next_param = os_strchr(next_param, ' ');
4731
4732 if (next_param)
4733 *next_param = '\0';
4734
4735 if (os_strcmp(curr_param, "strict") == 0)
4736 strict = true;
4737 else if (os_strncmp(curr_param, "iftype=", 7) == 0)
4738 iftype = curr_param + 7;
4739 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004740 return -1;
4741 }
4742
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004743 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'%s%s%s",
4744 field, iftype ? " iftype=" : "", iftype ? iftype : "",
4745 strict ? " strict" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004746
4747 if (os_strcmp(field, "eap") == 0) {
4748 return eap_get_names(buf, buflen);
4749 }
4750
4751 res = wpa_drv_get_capa(wpa_s, &capa);
4752
4753 if (os_strcmp(field, "pairwise") == 0)
4754 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4755 buf, buflen);
4756
4757 if (os_strcmp(field, "group") == 0)
4758 return ctrl_iface_get_capability_group(res, strict, &capa,
4759 buf, buflen);
4760
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004761 if (os_strcmp(field, "group_mgmt") == 0)
4762 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4763 buf, buflen);
4764
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004765 if (os_strcmp(field, "key_mgmt") == 0)
4766 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004767 iftype, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004768
4769 if (os_strcmp(field, "proto") == 0)
4770 return ctrl_iface_get_capability_proto(res, strict, &capa,
4771 buf, buflen);
4772
4773 if (os_strcmp(field, "auth_alg") == 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004774 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4775 &capa, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004776
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004777 if (os_strcmp(field, "modes") == 0)
4778 return ctrl_iface_get_capability_modes(res, strict, &capa,
4779 buf, buflen);
4780
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004781 if (os_strcmp(field, "channels") == 0)
4782 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4783
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004784 if (os_strcmp(field, "freq") == 0)
4785 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4786
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004787#ifdef CONFIG_TDLS
4788 if (os_strcmp(field, "tdls") == 0)
4789 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4790#endif /* CONFIG_TDLS */
4791
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004792#ifdef CONFIG_ERP
4793 if (os_strcmp(field, "erp") == 0) {
4794 res = os_snprintf(buf, buflen, "ERP");
4795 if (os_snprintf_error(buflen, res))
4796 return -1;
4797 return res;
4798 }
4799#endif /* CONFIG_EPR */
4800
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004801#ifdef CONFIG_FIPS
4802 if (os_strcmp(field, "fips") == 0) {
4803 res = os_snprintf(buf, buflen, "FIPS");
4804 if (os_snprintf_error(buflen, res))
4805 return -1;
4806 return res;
4807 }
4808#endif /* CONFIG_FIPS */
4809
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004810#ifdef CONFIG_ACS
4811 if (os_strcmp(field, "acs") == 0) {
4812 res = os_snprintf(buf, buflen, "ACS");
4813 if (os_snprintf_error(buflen, res))
4814 return -1;
4815 return res;
4816 }
4817#endif /* CONFIG_ACS */
4818
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004819#ifdef CONFIG_FILS
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004820 if (os_strcmp(field, "fils") == 0) {
4821#ifdef CONFIG_FILS_SK_PFS
4822 if (wpa_is_fils_supported(wpa_s) &&
4823 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4824 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4825 if (os_snprintf_error(buflen, res))
4826 return -1;
4827 return res;
4828 }
4829#endif /* CONFIG_FILS_SK_PFS */
4830
4831 if (wpa_is_fils_supported(wpa_s)) {
4832 res = os_snprintf(buf, buflen, "FILS");
4833 if (os_snprintf_error(buflen, res))
4834 return -1;
4835 return res;
4836 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004837 }
4838#endif /* CONFIG_FILS */
4839
Hai Shalom74f70d42019-02-11 14:42:39 -08004840 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
4841 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
4842 if (os_snprintf_error(buflen, res))
4843 return -1;
4844 return res;
4845 }
4846
Hai Shalom021b0b52019-04-10 11:17:58 -07004847#ifdef CONFIG_DPP
4848 if (os_strcmp(field, "dpp") == 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08004849#ifdef CONFIG_DPP3
4850 res = os_snprintf(buf, buflen, "DPP=3");
4851#elif defined(CONFIG_DPP2)
Hai Shalom021b0b52019-04-10 11:17:58 -07004852 res = os_snprintf(buf, buflen, "DPP=2");
4853#else /* CONFIG_DPP2 */
4854 res = os_snprintf(buf, buflen, "DPP=1");
4855#endif /* CONFIG_DPP2 */
4856 if (os_snprintf_error(buflen, res))
4857 return -1;
4858 return res;
4859 }
4860#endif /* CONFIG_DPP */
4861
Hai Shalom899fcc72020-10-19 14:38:18 -07004862#ifdef CONFIG_SAE
4863 if (os_strcmp(field, "sae") == 0 &&
4864 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4865#ifdef CONFIG_SAE_PK
4866 res = os_snprintf(buf, buflen, "H2E PK");
4867#else /* CONFIG_SAE_PK */
4868 res = os_snprintf(buf, buflen, "H2E");
4869#endif /* CONFIG_SAE_PK */
4870 if (os_snprintf_error(buflen, res))
4871 return -1;
4872 return res;
4873 }
4874#endif /* CONFIG_SAE */
4875
Hai Shalom60840252021-02-19 19:02:11 -08004876#ifdef CONFIG_OCV
4877 if (os_strcmp(field, "ocv") == 0) {
4878 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
4879 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV))
4880 res = os_snprintf(buf, buflen, "supported");
4881 else
4882 res = os_snprintf(buf, buflen, "not supported");
4883 if (os_snprintf_error(buflen, res))
4884 return -1;
4885 return res;
4886 }
4887#endif /* CONFIG_OCV */
4888
4889 if (os_strcmp(field, "beacon_prot") == 0) {
4890 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) ||
4891 (wpa_s->drv_flags2 &
4892 WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT))
4893 res = os_snprintf(buf, buflen, "supported");
4894 else
4895 res = os_snprintf(buf, buflen, "not supported");
4896 if (os_snprintf_error(buflen, res))
4897 return -1;
4898 return res;
4899 }
4900
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004901 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4902 field);
4903
4904 return -1;
4905}
4906
4907
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004908#ifdef CONFIG_INTERWORKING
4909static char * anqp_add_hex(char *pos, char *end, const char *title,
4910 struct wpabuf *data)
4911{
4912 char *start = pos;
4913 size_t i;
4914 int ret;
4915 const u8 *d;
4916
4917 if (data == NULL)
4918 return start;
4919
4920 ret = os_snprintf(pos, end - pos, "%s=", title);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004921 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004922 return start;
4923 pos += ret;
4924
4925 d = wpabuf_head_u8(data);
4926 for (i = 0; i < wpabuf_len(data); i++) {
4927 ret = os_snprintf(pos, end - pos, "%02x", *d++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004928 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004929 return start;
4930 pos += ret;
4931 }
4932
4933 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004934 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004935 return start;
4936 pos += ret;
4937
4938 return pos;
4939}
4940#endif /* CONFIG_INTERWORKING */
4941
4942
Dmitry Shmidt29333592017-01-09 12:27:11 -08004943#ifdef CONFIG_FILS
4944static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4945{
4946 char *start = pos;
4947 const u8 *ie, *ie_end;
4948 u16 info, realms;
4949 int ret;
4950
4951 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4952 if (!ie)
4953 return 0;
4954 ie_end = ie + 2 + ie[1];
4955 ie += 2;
4956 if (ie_end - ie < 2)
4957 return -1;
4958
4959 info = WPA_GET_LE16(ie);
4960 ie += 2;
4961 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4962 if (os_snprintf_error(end - pos, ret))
4963 return 0;
4964 pos += ret;
4965
4966 if (info & BIT(7)) {
4967 /* Cache Identifier Included */
4968 if (ie_end - ie < 2)
4969 return -1;
4970 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4971 ie[0], ie[1]);
4972 if (os_snprintf_error(end - pos, ret))
4973 return 0;
4974 pos += ret;
4975 ie += 2;
4976 }
4977
4978 if (info & BIT(8)) {
4979 /* HESSID Included */
4980 if (ie_end - ie < ETH_ALEN)
4981 return -1;
4982 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4983 MAC2STR(ie));
4984 if (os_snprintf_error(end - pos, ret))
4985 return 0;
4986 pos += ret;
4987 ie += ETH_ALEN;
4988 }
4989
4990 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4991 if (realms) {
4992 if (ie_end - ie < realms * 2)
4993 return -1;
4994 ret = os_snprintf(pos, end - pos, "fils_realms=");
4995 if (os_snprintf_error(end - pos, ret))
4996 return 0;
4997 pos += ret;
4998
4999 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
5000 if (ret <= 0)
5001 return 0;
5002 pos += ret;
5003 ie += realms * 2;
5004 ret = os_snprintf(pos, end - pos, "\n");
5005 if (os_snprintf_error(end - pos, ret))
5006 return 0;
5007 pos += ret;
5008 }
5009
5010 return pos - start;
5011}
5012#endif /* CONFIG_FILS */
5013
5014
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005015static int print_rnr(struct wpa_bss *bss, char *pos, char *end)
5016{
5017 char *start = pos;
5018 const u8 *ie, *ie_end;
5019 unsigned int n = 0;
5020 int ret;
5021
5022 ie = wpa_bss_get_ie(bss, WLAN_EID_REDUCED_NEIGHBOR_REPORT);
5023 if (!ie)
5024 return 0;
5025
5026 ie_end = ie + 2 + ie[1];
5027 ie += 2;
5028
5029 while (ie < ie_end) {
5030 const struct ieee80211_neighbor_ap_info *info =
5031 (const struct ieee80211_neighbor_ap_info *) ie;
5032 const u8 *tbtt_start;
5033 size_t left = ie_end - ie;
5034
5035 if (left < sizeof(struct ieee80211_neighbor_ap_info))
5036 return 0;
5037
5038 left -= sizeof(struct ieee80211_neighbor_ap_info);
5039 if (left < info->tbtt_info_len)
5040 return 0;
5041
5042 ret = os_snprintf(pos, end - pos,
5043 "ap_info[%u]: tbtt_info: hdr=0x%x, len=%u, op_c=%u, channel=%u, ",
5044 n, *ie, info->tbtt_info_len,
5045 info->op_class, info->channel);
5046 if (os_snprintf_error(end - pos, ret))
5047 return 0;
5048 pos += ret;
5049
5050 ie += sizeof(struct ieee80211_neighbor_ap_info);
5051 tbtt_start = ie;
5052 if (info->tbtt_info_len >= 1) {
5053 ret = os_snprintf(pos, end - pos,
5054 "tbtt_offset=%u, ", *ie);
5055 if (os_snprintf_error(end - pos, ret))
5056 return 0;
5057
5058 ie++;
5059 pos += ret;
5060 }
5061
5062 if (info->tbtt_info_len >= 7) {
5063 ret = os_snprintf(pos, end - pos,
5064 "bssid=" MACSTR ", ",
5065 MAC2STR(ie));
5066 if (os_snprintf_error(end - pos, ret))
5067 return 0;
5068
5069 ie += ETH_ALEN;
5070 pos += ret;
5071 }
5072
5073 if (info->tbtt_info_len >= 11) {
5074 ret = os_snprintf(pos, end - pos,
5075 "short SSID=0x%x, ",
5076 WPA_GET_LE32(ie));
5077 if (os_snprintf_error(end - pos, ret))
5078 return 0;
5079
5080 ie += 4;
5081 pos += ret;
5082 }
5083
5084 if (info->tbtt_info_len >= 12) {
5085 ret = os_snprintf(pos, end - pos,
5086 "bss_params=0x%x, ", *ie);
5087 if (os_snprintf_error(end - pos, ret))
5088 return 0;
5089
5090 ie++;
5091 pos += ret;
5092 }
5093
5094 if (info->tbtt_info_len >= 13) {
5095 ret = os_snprintf(pos, end - pos,
5096 "PSD=0x%x, ", *ie);
5097 if (os_snprintf_error(end - pos, ret))
5098 return 0;
5099
5100 ie++;
5101 pos += ret;
5102 }
5103
5104 if (info->tbtt_info_len >= 16) {
5105 ret = os_snprintf(pos, end - pos,
5106 "mld ID=%u, link ID=%u",
5107 *ie, *(ie + 1) & 0xF);
5108 if (os_snprintf_error(end - pos, ret))
5109 return 0;
5110
5111 ie += 3;
5112 pos += ret;
5113 }
5114
5115 ie = tbtt_start + info->tbtt_info_len;
5116
5117 ret = os_snprintf(pos, end - pos, "\n");
5118 if (os_snprintf_error(end - pos, ret))
5119 return 0;
5120 pos += ret;
5121
5122 n++;
5123 }
5124
5125 return pos - start;
5126}
5127
5128
5129static int print_ml(struct wpa_bss *bss, char *pos, char *end)
5130{
5131 const struct ieee80211_eht_ml *ml;
5132 char *start = pos;
5133 const u8 *ie, *ie_end;
5134 u16 ml_control;
5135 u8 common_info_length;
5136 int ret;
5137
5138 ie = get_ml_ie(wpa_bss_ie_ptr(bss), bss->ie_len,
5139 MULTI_LINK_CONTROL_TYPE_BASIC);
5140 if (!ie)
5141 return 0;
5142
5143 ie_end = ie + 2 + ie[1];
5144 ie += 3;
5145 ml = (const struct ieee80211_eht_ml *) ie;
5146
5147 /* control + common info length + MLD MAC Address */
5148 if (ie_end - ie < 2 + 1 + ETH_ALEN)
5149 return 0;
5150
5151 ml_control = le_to_host16(ml->ml_control);
5152
5153 common_info_length = *(ie + 2);
5154 ret = os_snprintf(pos, end - pos,
5155 "multi-link: control=0x%x, common info len=%u",
5156 ml_control, common_info_length);
5157 if (os_snprintf_error(end - pos, ret))
5158 return 0;
5159 pos += ret;
5160
5161 ie += 2;
5162 if (ie_end - ie < common_info_length)
5163 return 0;
5164
5165 ie++;
5166 common_info_length--;
5167
5168 if (common_info_length < ETH_ALEN)
5169 return 0;
5170
5171 ret = os_snprintf(pos, end - pos, ", MLD addr=" MACSTR, MAC2STR(ie));
5172 if (os_snprintf_error(end - pos, ret))
5173 return 0;
5174 pos += ret;
5175
5176 ie += ETH_ALEN;
5177 common_info_length -= ETH_ALEN;
5178
5179 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_LINK_ID) {
5180 if (common_info_length < 1)
5181 return 0;
5182
5183 ret = os_snprintf(pos, end - pos, ", link ID=%u", *ie & 0x0f);
5184 if (os_snprintf_error(end - pos, ret))
5185 return 0;
5186 pos += ret;
5187 ie++;
5188 common_info_length--;
5189 }
5190
5191 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT) {
5192 if (common_info_length < 1)
5193 return 0;
5194
5195 ret = os_snprintf(pos, end - pos,
5196 ", BSS change parameters=0x%x", *ie);
5197 if (os_snprintf_error(end - pos, ret))
5198 return 0;
5199 pos += ret;
5200 ie++;
5201 common_info_length--;
5202 }
5203
5204 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
5205 if (common_info_length < 2)
5206 return 0;
5207
5208 ret = os_snprintf(pos, end - pos, ", MSD Info=0x%x",
5209 WPA_GET_LE16(ie));
5210 if (os_snprintf_error(end - pos, ret))
5211 return 0;
5212 pos += ret;
5213 ie += 2;
5214 common_info_length -= 2;
5215 }
5216
5217 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
5218 if (common_info_length < 2)
5219 return 0;
5220
5221 ret = os_snprintf(pos, end - pos, ", EML capabilities=0x%x",
5222 WPA_GET_LE16(ie));
5223 if (os_snprintf_error(end - pos, ret))
5224 return 0;
5225 pos += ret;
5226 ie += 2;
5227 common_info_length -= 2;
5228 }
5229
5230 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
5231 if (common_info_length < 2)
5232 return 0;
5233
5234 ret = os_snprintf(pos, end - pos, ", MLD capabilities=0x%x",
5235 WPA_GET_LE16(ie));
5236 if (os_snprintf_error(end - pos, ret))
5237 return 0;
5238 pos += ret;
5239 ie += 2;
5240 common_info_length -= 2;
5241 }
5242
5243 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
5244 if (common_info_length < 1)
5245 return 0;
5246
5247 ret = os_snprintf(pos, end - pos, ", MLD ID=0x%x\n", *ie);
5248 if (os_snprintf_error(end - pos, ret))
5249 return 0;
5250 pos += ret;
5251 ie += 1;
5252 common_info_length--;
5253 }
5254
5255 return pos - start;
5256}
5257
5258
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005259static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
5260 unsigned long mask, char *buf, size_t buflen)
5261{
5262 size_t i;
5263 int ret;
5264 char *pos, *end;
Hai Shalom899fcc72020-10-19 14:38:18 -07005265 const u8 *ie, *ie2, *osen_ie, *mesh, *owe, *rsnxe;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005266
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005267 pos = buf;
5268 end = buf + buflen;
5269
5270 if (mask & WPA_BSS_MASK_ID) {
5271 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005272 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005273 return 0;
5274 pos += ret;
5275 }
5276
5277 if (mask & WPA_BSS_MASK_BSSID) {
5278 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
5279 MAC2STR(bss->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005280 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005281 return 0;
5282 pos += ret;
5283 }
5284
5285 if (mask & WPA_BSS_MASK_FREQ) {
5286 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005287 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005288 return 0;
5289 pos += ret;
5290 }
5291
5292 if (mask & WPA_BSS_MASK_BEACON_INT) {
5293 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
5294 bss->beacon_int);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005295 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005296 return 0;
5297 pos += ret;
5298 }
5299
5300 if (mask & WPA_BSS_MASK_CAPABILITIES) {
5301 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
5302 bss->caps);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005303 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005304 return 0;
5305 pos += ret;
5306 }
5307
5308 if (mask & WPA_BSS_MASK_QUAL) {
5309 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005310 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005311 return 0;
5312 pos += ret;
5313 }
5314
5315 if (mask & WPA_BSS_MASK_NOISE) {
5316 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005317 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005318 return 0;
5319 pos += ret;
5320 }
5321
5322 if (mask & WPA_BSS_MASK_LEVEL) {
5323 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005324 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005325 return 0;
5326 pos += ret;
5327 }
5328
5329 if (mask & WPA_BSS_MASK_TSF) {
5330 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
5331 (unsigned long long) bss->tsf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005332 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005333 return 0;
5334 pos += ret;
5335 }
5336
5337 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005338 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005339
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005340 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005341 ret = os_snprintf(pos, end - pos, "age=%d\n",
5342 (int) (now.sec - bss->last_update.sec));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005343 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005344 return 0;
5345 pos += ret;
5346 }
5347
5348 if (mask & WPA_BSS_MASK_IE) {
5349 ret = os_snprintf(pos, end - pos, "ie=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005350 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005351 return 0;
5352 pos += ret;
5353
Hai Shalom60840252021-02-19 19:02:11 -08005354 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005355 for (i = 0; i < bss->ie_len; i++) {
5356 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005357 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005358 return 0;
5359 pos += ret;
5360 }
5361
5362 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005363 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005364 return 0;
5365 pos += ret;
5366 }
5367
5368 if (mask & WPA_BSS_MASK_FLAGS) {
5369 ret = os_snprintf(pos, end - pos, "flags=");
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
Dmitry Shmidt29333592017-01-09 12:27:11 -08005374 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
5375
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005376 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
5377 if (ie)
5378 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
5379 2 + ie[1]);
5380 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
5381 if (ie2)
Dmitry Shmidt29333592017-01-09 12:27:11 -08005382 pos = wpa_supplicant_ie_txt(pos, end,
5383 mesh ? "RSN" : "WPA2", ie2,
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005384 2 + ie2[1]);
Hai Shalom899fcc72020-10-19 14:38:18 -07005385 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shaloma20dcd72022-02-04 13:43:00 -08005386 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
5387 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
5388 if (os_snprintf_error(end - pos, ret))
5389 return -1;
5390 pos += ret;
5391 }
5392 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
5393 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
5394 if (os_snprintf_error(end - pos, ret))
5395 return -1;
5396 pos += ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07005397 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005398 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
5399 if (osen_ie)
5400 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
5401 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005402 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
5403 if (owe) {
5404 ret = os_snprintf(
5405 pos, end - pos,
5406 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
5407 if (os_snprintf_error(end - pos, ret))
5408 return 0;
5409 pos += ret;
5410 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005411 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005412 if (!ie && !ie2 && !osen_ie &&
5413 (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005414 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005415 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005416 return 0;
5417 pos += ret;
5418 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005419
5420 if (mesh) {
5421 ret = os_snprintf(pos, end - pos, "[MESH]");
5422 if (os_snprintf_error(end - pos, ret))
5423 return 0;
5424 pos += ret;
5425 }
5426
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005427 if (bss_is_dmg(bss)) {
5428 const char *s;
5429 ret = os_snprintf(pos, end - pos, "[DMG]");
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;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005433 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
5434 case IEEE80211_CAP_DMG_IBSS:
5435 s = "[IBSS]";
5436 break;
5437 case IEEE80211_CAP_DMG_AP:
5438 s = "[ESS]";
5439 break;
5440 case IEEE80211_CAP_DMG_PBSS:
5441 s = "[PBSS]";
5442 break;
5443 default:
5444 s = "";
5445 break;
5446 }
5447 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005448 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005449 return 0;
5450 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005451 } else {
5452 if (bss->caps & IEEE80211_CAP_IBSS) {
5453 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005454 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005455 return 0;
5456 pos += ret;
5457 }
5458 if (bss->caps & IEEE80211_CAP_ESS) {
5459 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005460 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005461 return 0;
5462 pos += ret;
5463 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005464 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07005465 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
5466 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005467 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005468 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005469 return 0;
5470 pos += ret;
5471 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005472#ifdef CONFIG_HS20
5473 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
5474 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005475 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005476 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005477 pos += ret;
5478 }
5479#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005480#ifdef CONFIG_FILS
5481 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
5482 ret = os_snprintf(pos, end - pos, "[FILS]");
5483 if (os_snprintf_error(end - pos, ret))
5484 return 0;
5485 pos += ret;
5486 }
5487#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08005488#ifdef CONFIG_FST
5489 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
5490 ret = os_snprintf(pos, end - pos, "[FST]");
5491 if (os_snprintf_error(end - pos, ret))
5492 return 0;
5493 pos += ret;
5494 }
5495#endif /* CONFIG_FST */
5496 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
5497 ret = os_snprintf(pos, end - pos, "[UTF-8]");
5498 if (os_snprintf_error(end - pos, ret))
5499 return 0;
5500 pos += ret;
5501 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005502
5503 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005504 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005505 return 0;
5506 pos += ret;
5507 }
5508
5509 if (mask & WPA_BSS_MASK_SSID) {
5510 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
5511 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005512 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005513 return 0;
5514 pos += ret;
5515 }
5516
5517#ifdef CONFIG_WPS
5518 if (mask & WPA_BSS_MASK_WPS_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005519 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005520 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005521 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005522 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005523 if (ret > 0)
5524 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005525 }
5526#endif /* CONFIG_WPS */
5527
5528#ifdef CONFIG_P2P
5529 if (mask & WPA_BSS_MASK_P2P_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005530 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005531 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005532 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005533 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005534 if (ret > 0)
5535 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005536 }
5537#endif /* CONFIG_P2P */
5538
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005539#ifdef CONFIG_WIFI_DISPLAY
5540 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
5541 struct wpabuf *wfd;
Hai Shalom60840252021-02-19 19:02:11 -08005542
5543 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005544 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
5545 WFD_IE_VENDOR_TYPE);
5546 if (wfd) {
5547 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005548 if (os_snprintf_error(end - pos, ret)) {
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005549 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005550 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005551 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005552 pos += ret;
5553
5554 pos += wpa_snprintf_hex(pos, end - pos,
5555 wpabuf_head(wfd),
5556 wpabuf_len(wfd));
5557 wpabuf_free(wfd);
5558
5559 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005560 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005561 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005562 pos += ret;
5563 }
5564 }
5565#endif /* CONFIG_WIFI_DISPLAY */
5566
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005567#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005568 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
5569 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005570 struct wpa_bss_anqp_elem *elem;
5571
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005572 pos = anqp_add_hex(pos, end, "anqp_capability_list",
5573 anqp->capability_list);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005574 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005575 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005576 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005577 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005578 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005579 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005580 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005581 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005582 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005583 anqp->nai_realm);
5584 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005585 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005586 anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005587 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
5588 anqp->fils_realm_info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005589#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005590 pos = anqp_add_hex(pos, end, "hs20_capability_list",
5591 anqp->hs20_capability_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005592 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005593 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005594 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005595 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005596 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005597 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005598 pos = anqp_add_hex(pos, end, "hs20_operating_class",
5599 anqp->hs20_operating_class);
5600 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
5601 anqp->hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005602 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
5603 anqp->hs20_operator_icon_metadata);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005604 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
5605 anqp->hs20_osu_providers_nai_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005606#endif /* CONFIG_HS20 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005607
5608 dl_list_for_each(elem, &anqp->anqp_elems,
5609 struct wpa_bss_anqp_elem, list) {
5610 char title[20];
5611
5612 os_snprintf(title, sizeof(title), "anqp[%u]",
5613 elem->infoid);
5614 pos = anqp_add_hex(pos, end, title, elem->payload);
Hai Shalom60840252021-02-19 19:02:11 -08005615 if (elem->protected_response) {
5616 ret = os_snprintf(pos, end - pos,
5617 "protected-anqp-info[%u]=1\n",
5618 elem->infoid);
5619 if (os_snprintf_error(end - pos, ret))
5620 return 0;
5621 pos += ret;
5622 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005623 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005624 }
5625#endif /* CONFIG_INTERWORKING */
5626
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005627#ifdef CONFIG_MESH
5628 if (mask & WPA_BSS_MASK_MESH_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005629 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005630 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005631 if (ret >= end - pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005632 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005633 if (ret > 0)
5634 pos += ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005635 }
5636#endif /* CONFIG_MESH */
5637
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005638 if (mask & WPA_BSS_MASK_SNR) {
5639 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
5640 if (os_snprintf_error(end - pos, ret))
5641 return 0;
5642 pos += ret;
5643 }
5644
5645 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
5646 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
5647 bss->est_throughput);
5648 if (os_snprintf_error(end - pos, ret))
5649 return 0;
5650 pos += ret;
5651 }
5652
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005653#ifdef CONFIG_FST
5654 if (mask & WPA_BSS_MASK_FST) {
5655 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
5656 if (ret < 0 || ret >= end - pos)
5657 return 0;
5658 pos += ret;
5659 }
5660#endif /* CONFIG_FST */
5661
Dmitry Shmidt29333592017-01-09 12:27:11 -08005662 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
5663 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
5664 bss->last_update_idx);
5665 if (os_snprintf_error(end - pos, ret))
5666 return 0;
5667 pos += ret;
5668 }
5669
5670 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
5671 ret = os_snprintf(pos, end - pos, "beacon_ie=");
5672 if (os_snprintf_error(end - pos, ret))
5673 return 0;
5674 pos += ret;
5675
Hai Shalom60840252021-02-19 19:02:11 -08005676 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005677 ie += bss->ie_len;
5678 for (i = 0; i < bss->beacon_ie_len; i++) {
5679 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
5680 if (os_snprintf_error(end - pos, ret))
5681 return 0;
5682 pos += ret;
5683 }
5684
5685 ret = os_snprintf(pos, end - pos, "\n");
5686 if (os_snprintf_error(end - pos, ret))
5687 return 0;
5688 pos += ret;
5689 }
5690
5691#ifdef CONFIG_FILS
5692 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
5693 ret = print_fils_indication(bss, pos, end);
5694 if (ret < 0)
5695 return 0;
5696 pos += ret;
5697 }
5698#endif /* CONFIG_FILS */
5699
Sunil Ravi2a14cf12023-11-21 00:54:38 +00005700 if (!is_zero_ether_addr(bss->mld_addr) &&
5701 (mask & WPA_BSS_MASK_AP_MLD_ADDR)) {
Sunil Ravi89eba102022-09-13 21:04:37 -07005702 ret = os_snprintf(pos, end - pos,
5703 "ap_mld_addr=" MACSTR "\n",
5704 MAC2STR(bss->mld_addr));
5705 if (os_snprintf_error(end - pos, ret))
5706 return 0;
5707 pos += ret;
5708 }
5709
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005710 if (mask & WPA_BSS_MASK_RNR)
5711 pos += print_rnr(bss, pos, end);
5712
5713 if (mask & WPA_BSS_MASK_ML)
5714 pos += print_ml(bss, pos, end);
5715
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005716 if (mask & WPA_BSS_MASK_DELIM) {
5717 ret = os_snprintf(pos, end - pos, "====\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005718 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005719 return 0;
5720 pos += ret;
5721 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07005722
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005723 return pos - buf;
5724}
5725
Dmitry Shmidt04949592012-07-19 12:16:46 -07005726
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005727static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
5728 const char *cmd, char *buf,
5729 size_t buflen)
5730{
5731 u8 bssid[ETH_ALEN];
5732 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005733 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005734 struct wpa_bss *bsslast = NULL;
5735 struct dl_list *next;
5736 int ret = 0;
5737 int len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005738 char *ctmp, *end = buf + buflen;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005739 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005740
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005741 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
5742 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
5743 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005744 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005745 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
5746 list_id);
5747 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005748 unsigned int id1, id2;
5749
5750 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
5751 wpa_printf(MSG_INFO, "Wrong BSS range "
5752 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005753 return 0;
5754 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005755
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005756 if (*(cmd + 6) == '-')
5757 id1 = 0;
5758 else
5759 id1 = atoi(cmd + 6);
5760 ctmp++;
5761 if (*ctmp >= '0' && *ctmp <= '9')
5762 id2 = atoi(ctmp);
5763 else
5764 id2 = (unsigned int) -1;
5765 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
5766 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005767 bsslast = dl_list_last(&wpa_s->bss_id,
5768 struct wpa_bss,
5769 list_id);
5770 else {
5771 bsslast = wpa_bss_get_id(wpa_s, id2);
5772 if (bsslast == NULL && bss && id2 > id1) {
5773 struct wpa_bss *tmp = bss;
5774 for (;;) {
5775 next = tmp->list_id.next;
5776 if (next == &wpa_s->bss_id)
5777 break;
5778 tmp = dl_list_entry(
5779 next, struct wpa_bss,
5780 list_id);
5781 if (tmp->id > id2)
5782 break;
5783 bsslast = tmp;
5784 }
5785 }
5786 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005787 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005788 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005789 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005790 else if (os_strncmp(cmd, "LAST", 4) == 0)
5791 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005792 else if (os_strncmp(cmd, "ID-", 3) == 0) {
5793 i = atoi(cmd + 3);
5794 bss = wpa_bss_get_id(wpa_s, i);
5795 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5796 i = atoi(cmd + 5);
5797 bss = wpa_bss_get_id(wpa_s, i);
5798 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005799 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005800 if (next == &wpa_s->bss_id)
5801 bss = NULL;
5802 else
5803 bss = dl_list_entry(next, struct wpa_bss,
5804 list_id);
5805 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005806 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5807 bss = wpa_s->current_bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005808#ifdef CONFIG_P2P
5809 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5810 if (hwaddr_aton(cmd + 13, bssid) == 0)
5811 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5812 else
5813 bss = NULL;
5814#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005815 } else if (hwaddr_aton(cmd, bssid) == 0)
5816 bss = wpa_bss_get_bssid(wpa_s, bssid);
5817 else {
5818 struct wpa_bss *tmp;
5819 i = atoi(cmd);
5820 bss = NULL;
5821 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5822 {
Hai Shalom021b0b52019-04-10 11:17:58 -07005823 if (i == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005824 bss = tmp;
5825 break;
5826 }
Hai Shalom021b0b52019-04-10 11:17:58 -07005827 i--;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005828 }
5829 }
5830
Dmitry Shmidt04949592012-07-19 12:16:46 -07005831 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5832 mask = strtoul(ctmp + 5, NULL, 0x10);
5833 if (mask == 0)
5834 mask = WPA_BSS_MASK_ALL;
5835 }
5836
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005837 if (bss == NULL)
5838 return 0;
5839
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005840 if (bsslast == NULL)
5841 bsslast = bss;
5842 do {
5843 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5844 ret += len;
5845 buf += len;
5846 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005847 if (bss == bsslast) {
5848 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5849 (bss == dl_list_last(&wpa_s->bss_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005850 struct wpa_bss, list_id))) {
5851 int res;
5852
5853 res = os_snprintf(buf - 5, end - buf + 5,
5854 "####\n");
5855 if (os_snprintf_error(end - buf + 5, res)) {
5856 wpa_printf(MSG_DEBUG,
5857 "Could not add end delim");
5858 }
5859 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005860 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005861 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005862 next = bss->list_id.next;
5863 if (next == &wpa_s->bss_id)
5864 break;
5865 bss = dl_list_entry(next, struct wpa_bss, list_id);
5866 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005867
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005868 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005869}
5870
5871
5872static int wpa_supplicant_ctrl_iface_ap_scan(
5873 struct wpa_supplicant *wpa_s, char *cmd)
5874{
5875 int ap_scan = atoi(cmd);
5876 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5877}
5878
5879
5880static int wpa_supplicant_ctrl_iface_scan_interval(
5881 struct wpa_supplicant *wpa_s, char *cmd)
5882{
5883 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005884 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005885}
5886
5887
5888static int wpa_supplicant_ctrl_iface_bss_expire_age(
5889 struct wpa_supplicant *wpa_s, char *cmd)
5890{
5891 int expire_age = atoi(cmd);
5892 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5893}
5894
5895
5896static int wpa_supplicant_ctrl_iface_bss_expire_count(
5897 struct wpa_supplicant *wpa_s, char *cmd)
5898{
5899 int expire_count = atoi(cmd);
5900 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5901}
5902
5903
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005904static void wpa_supplicant_ctrl_iface_bss_flush(
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005905 struct wpa_supplicant *wpa_s, char *cmd)
5906{
5907 int flush_age = atoi(cmd);
5908
5909 if (flush_age == 0)
5910 wpa_bss_flush(wpa_s);
5911 else
5912 wpa_bss_flush_by_age(wpa_s, flush_age);
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005913}
5914
5915
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005916#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005917static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5918{
5919 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5920 /* MLME-DELETEKEYS.request */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005921 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005922 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005923 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005924 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005925 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005926 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005927 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005928 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005929 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005930 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005931 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005932 0, KEY_FLAG_GROUP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005933
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005934 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0,
5935 NULL, 0, KEY_FLAG_PAIRWISE);
Hai Shalomfdcde762020-04-02 11:19:20 -07005936 if (wpa_sm_ext_key_id(wpa_s->wpa))
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005937 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, wpa_s->bssid, 1, 0,
Hai Shalomfdcde762020-04-02 11:19:20 -07005938 NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005939 /* MLME-SETPROTECTION.request(None) */
5940 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5941 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5942 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5943 wpa_sm_drop_sa(wpa_s->wpa);
5944}
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005945#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005946
5947
5948static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5949 char *addr)
5950{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005951#ifdef CONFIG_NO_SCAN_PROCESSING
5952 return -1;
5953#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005954 u8 bssid[ETH_ALEN];
5955 struct wpa_bss *bss;
5956 struct wpa_ssid *ssid = wpa_s->current_ssid;
Hai Shaloma20dcd72022-02-04 13:43:00 -08005957 struct wpa_radio_work *already_connecting;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005958
5959 if (hwaddr_aton(addr, bssid)) {
5960 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5961 "address '%s'", addr);
5962 return -1;
5963 }
5964
5965 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5966
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005967 if (!ssid) {
5968 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5969 "configuration known for the target AP");
5970 return -1;
5971 }
5972
5973 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005974 if (!bss) {
5975 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
5976 "from BSS table");
5977 return -1;
5978 }
5979
5980 /*
5981 * TODO: Find best network configuration block from configuration to
5982 * allow roaming to other networks
5983 */
5984
Hai Shaloma20dcd72022-02-04 13:43:00 -08005985 already_connecting = radio_work_pending(wpa_s, "sme-connect");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005986 wpa_s->reassociate = 1;
5987 wpa_supplicant_connect(wpa_s, bss, ssid);
5988
Hai Shaloma20dcd72022-02-04 13:43:00 -08005989 /*
5990 * Indicate that an explicitly requested roam is in progress so scan
5991 * results that come in before the 'sme-connect' radio work gets
5992 * executed do not override the original connection attempt.
5993 */
5994 if (!already_connecting && radio_work_pending(wpa_s, "sme-connect"))
5995 wpa_s->roam_in_progress = true;
5996
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005997 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005998#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005999}
6000
6001
6002#ifdef CONFIG_P2P
6003static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
6004{
6005 unsigned int timeout = atoi(cmd);
6006 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006007 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08006008 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006009 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006010 unsigned int search_delay;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006011 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006012 u8 seek_count = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006013 int freq = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006014 bool include_6ghz = false;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006015
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006016 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6017 wpa_dbg(wpa_s, MSG_INFO,
6018 "Reject P2P_FIND since interface is disabled");
6019 return -1;
6020 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08006021
6022 if (os_strstr(cmd, " include_6ghz"))
6023 include_6ghz = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006024 if (os_strstr(cmd, "type=social"))
6025 type = P2P_FIND_ONLY_SOCIAL;
6026 else if (os_strstr(cmd, "type=progressive"))
6027 type = P2P_FIND_PROGRESSIVE;
6028
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006029 pos = os_strstr(cmd, "dev_id=");
6030 if (pos) {
6031 pos += 7;
6032 if (hwaddr_aton(pos, dev_id))
6033 return -1;
6034 _dev_id = dev_id;
6035 }
6036
Dmitry Shmidt344abd32014-01-14 13:17:00 -08006037 pos = os_strstr(cmd, "dev_type=");
6038 if (pos) {
6039 pos += 9;
6040 if (wps_dev_type_str2bin(pos, dev_type) < 0)
6041 return -1;
6042 _dev_type = dev_type;
6043 }
6044
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006045 pos = os_strstr(cmd, "delay=");
6046 if (pos) {
6047 pos += 6;
6048 search_delay = atoi(pos);
6049 } else
6050 search_delay = wpas_p2p_search_delay(wpa_s);
6051
Dmitry Shmidt41712582015-06-29 11:02:15 -07006052 pos = os_strstr(cmd, "freq=");
6053 if (pos) {
6054 pos += 5;
6055 freq = atoi(pos);
6056 if (freq <= 0)
6057 return -1;
6058 }
6059
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006060 /* Must be searched for last, because it adds nul termination */
6061 pos = os_strstr(cmd, " seek=");
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006062 if (pos)
6063 pos += 6;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006064 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
6065 char *term;
6066
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006067 _seek[seek_count++] = pos;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006068 seek = _seek;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006069 term = os_strchr(pos, ' ');
6070 if (!term)
6071 break;
6072 *term = '\0';
6073 pos = os_strstr(term + 1, "seek=");
6074 if (pos)
6075 pos += 5;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006076 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006077 if (seek_count > P2P_MAX_QUERY_HASH) {
6078 seek[0] = NULL;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006079 seek_count = 1;
6080 }
6081
Dmitry Shmidt344abd32014-01-14 13:17:00 -08006082 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006083 _dev_id, search_delay, seek_count, seek, freq,
6084 include_6ghz);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006085}
6086
6087
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006088static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
6089{
6090 const char *last = NULL;
6091 const char *token;
6092 long int token_len;
6093 unsigned int i;
6094
6095 /* Expected predefined CPT names delimited by ':' */
6096 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
6097 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
6098 wpa_printf(MSG_ERROR,
6099 "P2PS: CPT name list is too long, expected up to %d names",
6100 P2PS_FEATURE_CAPAB_CPT_MAX);
6101 cpt[0] = 0;
6102 return -1;
6103 }
6104
6105 token_len = last - token;
6106
6107 if (token_len == 3 &&
6108 os_memcmp(token, "UDP", token_len) == 0) {
6109 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6110 } else if (token_len == 3 &&
6111 os_memcmp(token, "MAC", token_len) == 0) {
6112 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
6113 } else {
6114 wpa_printf(MSG_ERROR,
6115 "P2PS: Unsupported CPT name '%s'", token);
6116 cpt[0] = 0;
6117 return -1;
6118 }
6119
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006120 if (isblank((unsigned char) *last)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006121 i++;
6122 break;
6123 }
6124 }
6125 cpt[i] = 0;
6126 return 0;
6127}
6128
6129
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006130static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
6131{
6132 struct p2ps_provision *p2ps_prov;
6133 char *pos;
6134 size_t info_len = 0;
6135 char *info = NULL;
6136 u8 role = P2PS_SETUP_NONE;
6137 long long unsigned val;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006138 int i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006139
6140 pos = os_strstr(cmd, "info=");
6141 if (pos) {
6142 pos += 5;
6143 info_len = os_strlen(pos);
6144
6145 if (info_len) {
6146 info = os_malloc(info_len + 1);
6147 if (info) {
6148 info_len = utf8_unescape(pos, info_len,
6149 info, info_len + 1);
6150 } else
6151 info_len = 0;
6152 }
6153 }
6154
6155 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
6156 if (p2ps_prov == NULL) {
6157 os_free(info);
6158 return NULL;
6159 }
6160
6161 if (info) {
6162 os_memcpy(p2ps_prov->info, info, info_len);
6163 p2ps_prov->info[info_len] = '\0';
6164 os_free(info);
6165 }
6166
6167 pos = os_strstr(cmd, "status=");
6168 if (pos)
6169 p2ps_prov->status = atoi(pos + 7);
6170 else
6171 p2ps_prov->status = -1;
6172
6173 pos = os_strstr(cmd, "adv_id=");
6174 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
6175 goto invalid_args;
6176 p2ps_prov->adv_id = val;
6177
6178 pos = os_strstr(cmd, "method=");
6179 if (pos)
6180 p2ps_prov->method = strtol(pos + 7, NULL, 16);
6181 else
6182 p2ps_prov->method = 0;
6183
6184 pos = os_strstr(cmd, "session=");
6185 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
6186 goto invalid_args;
6187 p2ps_prov->session_id = val;
6188
6189 pos = os_strstr(cmd, "adv_mac=");
6190 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
6191 goto invalid_args;
6192
6193 pos = os_strstr(cmd, "session_mac=");
6194 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
6195 goto invalid_args;
6196
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006197 pos = os_strstr(cmd, "cpt=");
6198 if (pos) {
6199 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
6200 p2ps_prov->cpt_priority))
6201 goto invalid_args;
6202 } else {
6203 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6204 }
6205
6206 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
6207 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
6208
Hai Shaloma20dcd72022-02-04 13:43:00 -08006209 /* force conncap with tstCap (no validity checks) */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006210 pos = os_strstr(cmd, "tstCap=");
6211 if (pos) {
6212 role = strtol(pos + 7, NULL, 16);
6213 } else {
6214 pos = os_strstr(cmd, "role=");
6215 if (pos) {
6216 role = strtol(pos + 5, NULL, 16);
6217 if (role != P2PS_SETUP_CLIENT &&
6218 role != P2PS_SETUP_GROUP_OWNER)
6219 role = P2PS_SETUP_NONE;
6220 }
6221 }
6222 p2ps_prov->role = role;
6223
6224 return p2ps_prov;
6225
6226invalid_args:
6227 os_free(p2ps_prov);
6228 return NULL;
6229}
6230
6231
6232static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
6233{
6234 u8 addr[ETH_ALEN];
6235 struct p2ps_provision *p2ps_prov;
6236 char *pos;
6237
6238 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
6239
6240 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
6241
6242 if (hwaddr_aton(cmd, addr))
6243 return -1;
6244
6245 pos = cmd + 17;
6246 if (*pos != ' ')
6247 return -1;
6248
6249 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
6250 if (!p2ps_prov)
6251 return -1;
6252
6253 if (p2ps_prov->status < 0) {
6254 os_free(p2ps_prov);
6255 return -1;
6256 }
6257
6258 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
6259 p2ps_prov);
6260}
6261
6262
6263static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
6264{
6265 u8 addr[ETH_ALEN];
6266 struct p2ps_provision *p2ps_prov;
6267 char *pos;
6268
6269 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
6270 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
6271 */
6272
6273 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
6274 if (hwaddr_aton(cmd, addr))
6275 return -1;
6276
6277 pos = cmd + 17;
6278 if (*pos != ' ')
6279 return -1;
6280
6281 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
6282 if (!p2ps_prov)
6283 return -1;
6284
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006285 p2ps_prov->pd_seeker = 1;
6286
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006287 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
6288 p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006289}
6290
6291
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006292static int parse_freq(int chwidth, int freq2)
6293{
6294 if (freq2 < 0)
6295 return -1;
6296 if (freq2)
Sunil8cd6f4d2022-06-28 18:40:46 +00006297 return CONF_OPER_CHWIDTH_80P80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006298
6299 switch (chwidth) {
6300 case 0:
6301 case 20:
6302 case 40:
Sunil8cd6f4d2022-06-28 18:40:46 +00006303 return CONF_OPER_CHWIDTH_USE_HT;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006304 case 80:
Sunil8cd6f4d2022-06-28 18:40:46 +00006305 return CONF_OPER_CHWIDTH_80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006306 case 160:
Sunil8cd6f4d2022-06-28 18:40:46 +00006307 return CONF_OPER_CHWIDTH_160MHZ;
6308 case 320:
6309 return CONF_OPER_CHWIDTH_320MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006310 default:
6311 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
6312 chwidth);
6313 return -1;
6314 }
6315}
6316
6317
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006318static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
6319 char *buf, size_t buflen)
6320{
6321 u8 addr[ETH_ALEN];
6322 char *pos, *pos2;
6323 char *pin = NULL;
6324 enum p2p_wps_method wps_method;
6325 int new_pin;
6326 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006327 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006328 int join;
6329 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006330 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006331 int go_intent = -1;
6332 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006333 int pd;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006334 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006335 int edmg;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006336 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
6337 size_t group_ssid_len = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08006338 int he;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006339 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006340
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006341 if (!wpa_s->global->p2p_init_wpa_s)
6342 return -1;
6343 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
6344 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
6345 wpa_s->global->p2p_init_wpa_s->ifname);
6346 wpa_s = wpa_s->global->p2p_init_wpa_s;
6347 }
6348
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006349 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
Dmitry Shmidt04949592012-07-19 12:16:46 -07006350 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006351 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006352 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006353
6354 if (hwaddr_aton(cmd, addr))
6355 return -1;
6356
6357 pos = cmd + 17;
6358 if (*pos != ' ')
6359 return -1;
6360 pos++;
6361
6362 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006363 pos2 = os_strstr(pos, " persistent=");
6364 if (pos2) {
6365 struct wpa_ssid *ssid;
6366 persistent_id = atoi(pos2 + 12);
6367 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
6368 if (ssid == NULL || ssid->disabled != 2 ||
6369 ssid->mode != WPAS_MODE_P2P_GO) {
6370 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
6371 "SSID id=%d for persistent P2P group (GO)",
6372 persistent_id);
6373 return -1;
6374 }
6375 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006376 join = os_strstr(pos, " join") != NULL;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006377 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006378 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006379 automatic = os_strstr(pos, " auto") != NULL;
6380 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006381 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6382 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6383 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006384 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006385 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006386
6387 pos2 = os_strstr(pos, " go_intent=");
6388 if (pos2) {
6389 pos2 += 11;
6390 go_intent = atoi(pos2);
6391 if (go_intent < 0 || go_intent > 15)
6392 return -1;
6393 }
6394
6395 pos2 = os_strstr(pos, " freq=");
6396 if (pos2) {
6397 pos2 += 6;
6398 freq = atoi(pos2);
6399 if (freq <= 0)
6400 return -1;
6401 }
6402
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006403 pos2 = os_strstr(pos, " freq2=");
6404 if (pos2)
6405 freq2 = atoi(pos2 + 7);
6406
6407 pos2 = os_strstr(pos, " max_oper_chwidth=");
6408 if (pos2)
6409 chwidth = atoi(pos2 + 18);
6410
6411 max_oper_chwidth = parse_freq(chwidth, freq2);
6412 if (max_oper_chwidth < 0)
6413 return -1;
6414
Hai Shaloma20dcd72022-02-04 13:43:00 -08006415 if (allow_6ghz && chwidth == 40)
Sunil8cd6f4d2022-06-28 18:40:46 +00006416 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006417
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006418 pos2 = os_strstr(pos, " ssid=");
6419 if (pos2) {
6420 char *end;
6421
6422 pos2 += 6;
6423 end = os_strchr(pos2, ' ');
6424 if (!end)
6425 group_ssid_len = os_strlen(pos2) / 2;
6426 else
6427 group_ssid_len = (end - pos2) / 2;
6428 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
6429 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
6430 return -1;
6431 group_ssid = _group_ssid;
6432 }
6433
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006434 if (os_strncmp(pos, "pin", 3) == 0) {
6435 /* Request random PIN (to be displayed) and enable the PIN */
6436 wps_method = WPS_PIN_DISPLAY;
6437 } else if (os_strncmp(pos, "pbc", 3) == 0) {
6438 wps_method = WPS_PBC;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006439 } else if (os_strstr(pos, "p2ps") != NULL) {
6440 wps_method = WPS_P2PS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006441 } else {
6442 pin = pos;
6443 pos = os_strchr(pin, ' ');
6444 wps_method = WPS_PIN_KEYPAD;
6445 if (pos) {
6446 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006447 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006448 wps_method = WPS_PIN_DISPLAY;
6449 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006450 if (!wps_pin_str_valid(pin)) {
6451 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
6452 return 17;
6453 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006454 }
6455
6456 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006457 persistent_group, automatic, join,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006458 auth, go_intent, freq, freq2, persistent_id,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006459 pd, ht40, vht, max_oper_chwidth, he, edmg,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006460 group_ssid, group_ssid_len, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006461 if (new_pin == -2) {
6462 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
6463 return 25;
6464 }
6465 if (new_pin == -3) {
6466 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
6467 return 25;
6468 }
6469 if (new_pin < 0)
6470 return -1;
6471 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
6472 ret = os_snprintf(buf, buflen, "%08d", new_pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006473 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006474 return -1;
6475 return ret;
6476 }
6477
6478 os_memcpy(buf, "OK\n", 3);
6479 return 3;
6480}
6481
6482
6483static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
6484{
6485 unsigned int timeout = atoi(cmd);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006486 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6487 wpa_dbg(wpa_s, MSG_INFO,
6488 "Reject P2P_LISTEN since interface is disabled");
6489 return -1;
6490 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006491 return wpas_p2p_listen(wpa_s, timeout);
6492}
6493
6494
6495static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
6496{
6497 u8 addr[ETH_ALEN];
6498 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006499 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006500
Dmitry Shmidt04949592012-07-19 12:16:46 -07006501 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006502
6503 if (hwaddr_aton(cmd, addr))
6504 return -1;
6505
6506 pos = cmd + 17;
6507 if (*pos != ' ')
6508 return -1;
6509 pos++;
6510
Dmitry Shmidt04949592012-07-19 12:16:46 -07006511 if (os_strstr(pos, " join") != NULL)
6512 use = WPAS_P2P_PD_FOR_JOIN;
6513 else if (os_strstr(pos, " auto") != NULL)
6514 use = WPAS_P2P_PD_AUTO;
6515
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006516 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006517}
6518
6519
6520static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
6521 size_t buflen)
6522{
6523 struct wpa_ssid *ssid = wpa_s->current_ssid;
6524
6525 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
6526 ssid->passphrase == NULL)
6527 return -1;
6528
6529 os_strlcpy(buf, ssid->passphrase, buflen);
6530 return os_strlen(buf);
6531}
6532
6533
6534static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
6535 char *buf, size_t buflen)
6536{
6537 u64 ref;
6538 int res;
6539 u8 dst_buf[ETH_ALEN], *dst;
6540 struct wpabuf *tlvs;
6541 char *pos;
6542 size_t len;
6543
6544 if (hwaddr_aton(cmd, dst_buf))
6545 return -1;
6546 dst = dst_buf;
6547 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
6548 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
6549 dst = NULL;
6550 pos = cmd + 17;
6551 if (*pos != ' ')
6552 return -1;
6553 pos++;
6554
6555 if (os_strncmp(pos, "upnp ", 5) == 0) {
6556 u8 version;
6557 pos += 5;
6558 if (hexstr2bin(pos, &version, 1) < 0)
6559 return -1;
6560 pos += 2;
6561 if (*pos != ' ')
6562 return -1;
6563 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006564 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006565#ifdef CONFIG_WIFI_DISPLAY
6566 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
6567 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
6568#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006569 } else if (os_strncmp(pos, "asp ", 4) == 0) {
6570 char *svc_str;
6571 char *svc_info = NULL;
6572 u32 id;
6573
6574 pos += 4;
6575 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
6576 return -1;
6577
6578 pos = os_strchr(pos, ' ');
6579 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
6580 return -1;
6581
6582 svc_str = pos + 1;
6583
6584 pos = os_strchr(svc_str, ' ');
6585
6586 if (pos)
6587 *pos++ = '\0';
6588
6589 /* All remaining data is the svc_info string */
6590 if (pos && pos[0] && pos[0] != ' ') {
6591 len = os_strlen(pos);
6592
6593 /* Unescape in place */
6594 len = utf8_unescape(pos, len, pos, len);
6595 if (len > 0xff)
6596 return -1;
6597
6598 svc_info = pos;
6599 }
6600
6601 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
6602 svc_str, svc_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006603 } else {
6604 len = os_strlen(pos);
6605 if (len & 1)
6606 return -1;
6607 len /= 2;
6608 tlvs = wpabuf_alloc(len);
6609 if (tlvs == NULL)
6610 return -1;
6611 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
6612 wpabuf_free(tlvs);
6613 return -1;
6614 }
6615
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006616 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006617 wpabuf_free(tlvs);
6618 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006619 if (ref == 0)
6620 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006621 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006622 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006623 return -1;
6624 return res;
6625}
6626
6627
6628static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
6629 char *cmd)
6630{
6631 long long unsigned val;
6632 u64 req;
6633 if (sscanf(cmd, "%llx", &val) != 1)
6634 return -1;
6635 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006636 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006637}
6638
6639
6640static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
6641{
6642 int freq;
6643 u8 dst[ETH_ALEN];
6644 u8 dialog_token;
6645 struct wpabuf *resp_tlvs;
6646 char *pos, *pos2;
6647 size_t len;
6648
6649 pos = os_strchr(cmd, ' ');
6650 if (pos == NULL)
6651 return -1;
6652 *pos++ = '\0';
6653 freq = atoi(cmd);
6654 if (freq == 0)
6655 return -1;
6656
6657 if (hwaddr_aton(pos, dst))
6658 return -1;
6659 pos += 17;
6660 if (*pos != ' ')
6661 return -1;
6662 pos++;
6663
6664 pos2 = os_strchr(pos, ' ');
6665 if (pos2 == NULL)
6666 return -1;
6667 *pos2++ = '\0';
6668 dialog_token = atoi(pos);
6669
6670 len = os_strlen(pos2);
6671 if (len & 1)
6672 return -1;
6673 len /= 2;
6674 resp_tlvs = wpabuf_alloc(len);
6675 if (resp_tlvs == NULL)
6676 return -1;
6677 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
6678 wpabuf_free(resp_tlvs);
6679 return -1;
6680 }
6681
6682 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
6683 wpabuf_free(resp_tlvs);
6684 return 0;
6685}
6686
6687
6688static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
6689 char *cmd)
6690{
Dmitry Shmidt04949592012-07-19 12:16:46 -07006691 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
6692 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006693 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
6694 return 0;
6695}
6696
6697
6698static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
6699 char *cmd)
6700{
6701 char *pos;
6702 size_t len;
6703 struct wpabuf *query, *resp;
6704
6705 pos = os_strchr(cmd, ' ');
6706 if (pos == NULL)
6707 return -1;
6708 *pos++ = '\0';
6709
6710 len = os_strlen(cmd);
6711 if (len & 1)
6712 return -1;
6713 len /= 2;
6714 query = wpabuf_alloc(len);
6715 if (query == NULL)
6716 return -1;
6717 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6718 wpabuf_free(query);
6719 return -1;
6720 }
6721
6722 len = os_strlen(pos);
6723 if (len & 1) {
6724 wpabuf_free(query);
6725 return -1;
6726 }
6727 len /= 2;
6728 resp = wpabuf_alloc(len);
6729 if (resp == NULL) {
6730 wpabuf_free(query);
6731 return -1;
6732 }
6733 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
6734 wpabuf_free(query);
6735 wpabuf_free(resp);
6736 return -1;
6737 }
6738
6739 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
6740 wpabuf_free(query);
6741 wpabuf_free(resp);
6742 return -1;
6743 }
6744 return 0;
6745}
6746
6747
6748static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6749{
6750 char *pos;
6751 u8 version;
6752
6753 pos = os_strchr(cmd, ' ');
6754 if (pos == NULL)
6755 return -1;
6756 *pos++ = '\0';
6757
6758 if (hexstr2bin(cmd, &version, 1) < 0)
6759 return -1;
6760
6761 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
6762}
6763
6764
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006765static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
6766 u8 replace, char *cmd)
6767{
6768 char *pos;
6769 char *adv_str;
6770 u32 auto_accept, adv_id, svc_state, config_methods;
6771 char *svc_info = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006772 char *cpt_prio_str;
6773 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006774
6775 pos = os_strchr(cmd, ' ');
6776 if (pos == NULL)
6777 return -1;
6778 *pos++ = '\0';
6779
6780 /* Auto-Accept value is mandatory, and must be one of the
6781 * single values (0, 1, 2, 4) */
6782 auto_accept = atoi(cmd);
6783 switch (auto_accept) {
6784 case P2PS_SETUP_NONE: /* No auto-accept */
6785 case P2PS_SETUP_NEW:
6786 case P2PS_SETUP_CLIENT:
6787 case P2PS_SETUP_GROUP_OWNER:
6788 break;
6789 default:
6790 return -1;
6791 }
6792
6793 /* Advertisement ID is mandatory */
6794 cmd = pos;
6795 pos = os_strchr(cmd, ' ');
6796 if (pos == NULL)
6797 return -1;
6798 *pos++ = '\0';
6799
6800 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6801 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
6802 return -1;
6803
6804 /* Only allow replacements if exist, and adds if not */
6805 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
6806 if (!replace)
6807 return -1;
6808 } else {
6809 if (replace)
6810 return -1;
6811 }
6812
6813 /* svc_state between 0 - 0xff is mandatory */
6814 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
6815 return -1;
6816
6817 pos = os_strchr(pos, ' ');
6818 if (pos == NULL)
6819 return -1;
6820
6821 /* config_methods is mandatory */
6822 pos++;
6823 if (sscanf(pos, "%x", &config_methods) != 1)
6824 return -1;
6825
6826 if (!(config_methods &
6827 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
6828 return -1;
6829
6830 pos = os_strchr(pos, ' ');
6831 if (pos == NULL)
6832 return -1;
6833
6834 pos++;
6835 adv_str = pos;
6836
6837 /* Advertisement string is mandatory */
6838 if (!pos[0] || pos[0] == ' ')
6839 return -1;
6840
6841 /* Terminate svc string */
6842 pos = os_strchr(pos, ' ');
6843 if (pos != NULL)
6844 *pos++ = '\0';
6845
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006846 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6847 if (cpt_prio_str) {
6848 pos = os_strchr(pos, ' ');
6849 if (pos != NULL)
6850 *pos++ = '\0';
6851
6852 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6853 return -1;
6854 } else {
6855 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6856 cpt_prio[1] = 0;
6857 }
6858
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006859 /* Service and Response Information are optional */
6860 if (pos && pos[0]) {
6861 size_t len;
6862
6863 /* Note the bare ' included, which cannot exist legally
6864 * in unescaped string. */
6865 svc_info = os_strstr(pos, "svc_info='");
6866
6867 if (svc_info) {
6868 svc_info += 9;
6869 len = os_strlen(svc_info);
6870 utf8_unescape(svc_info, len, svc_info, len);
6871 }
6872 }
6873
6874 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6875 (u8) svc_state, (u16) config_methods,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006876 svc_info, cpt_prio);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006877}
6878
6879
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006880static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6881{
6882 char *pos;
6883
6884 pos = os_strchr(cmd, ' ');
6885 if (pos == NULL)
6886 return -1;
6887 *pos++ = '\0';
6888
6889 if (os_strcmp(cmd, "bonjour") == 0)
6890 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6891 if (os_strcmp(cmd, "upnp") == 0)
6892 return p2p_ctrl_service_add_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006893 if (os_strcmp(cmd, "asp") == 0)
6894 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006895 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6896 return -1;
6897}
6898
6899
6900static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6901 char *cmd)
6902{
6903 size_t len;
6904 struct wpabuf *query;
6905 int ret;
6906
6907 len = os_strlen(cmd);
6908 if (len & 1)
6909 return -1;
6910 len /= 2;
6911 query = wpabuf_alloc(len);
6912 if (query == NULL)
6913 return -1;
6914 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6915 wpabuf_free(query);
6916 return -1;
6917 }
6918
6919 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6920 wpabuf_free(query);
6921 return ret;
6922}
6923
6924
6925static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6926{
6927 char *pos;
6928 u8 version;
6929
6930 pos = os_strchr(cmd, ' ');
6931 if (pos == NULL)
6932 return -1;
6933 *pos++ = '\0';
6934
6935 if (hexstr2bin(cmd, &version, 1) < 0)
6936 return -1;
6937
6938 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6939}
6940
6941
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006942static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6943{
6944 u32 adv_id;
6945
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07006946 if (os_strcmp(cmd, "all") == 0) {
6947 wpas_p2p_service_flush_asp(wpa_s);
6948 return 0;
6949 }
6950
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006951 if (sscanf(cmd, "%x", &adv_id) != 1)
6952 return -1;
6953
6954 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6955}
6956
6957
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006958static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6959{
6960 char *pos;
6961
6962 pos = os_strchr(cmd, ' ');
6963 if (pos == NULL)
6964 return -1;
6965 *pos++ = '\0';
6966
6967 if (os_strcmp(cmd, "bonjour") == 0)
6968 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6969 if (os_strcmp(cmd, "upnp") == 0)
6970 return p2p_ctrl_service_del_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006971 if (os_strcmp(cmd, "asp") == 0)
6972 return p2p_ctrl_service_del_asp(wpa_s, pos);
6973 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6974 return -1;
6975}
6976
6977
6978static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6979{
6980 char *pos;
6981
6982 pos = os_strchr(cmd, ' ');
6983 if (pos == NULL)
6984 return -1;
6985 *pos++ = '\0';
6986
6987 if (os_strcmp(cmd, "asp") == 0)
6988 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6989
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006990 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6991 return -1;
6992}
6993
6994
6995static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
6996{
6997 u8 addr[ETH_ALEN];
6998
6999 /* <addr> */
7000
7001 if (hwaddr_aton(cmd, addr))
7002 return -1;
7003
7004 return wpas_p2p_reject(wpa_s, addr);
7005}
7006
7007
7008static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
7009{
7010 char *pos;
7011 int id;
7012 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007013 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08007014 int freq = 0, pref_freq = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08007015 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007016 int edmg;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007017 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007018
7019 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007020 pos = os_strstr(cmd, " peer=");
7021 if (pos) {
7022 pos += 6;
7023 if (hwaddr_aton(pos, peer))
7024 return -1;
7025 _peer = peer;
7026 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007027 ssid = wpa_config_get_network(wpa_s->conf, id);
7028 if (ssid == NULL || ssid->disabled != 2) {
7029 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
7030 "for persistent P2P group",
7031 id);
7032 return -1;
7033 }
7034
Jouni Malinen31be0a42012-08-31 21:20:51 +03007035 pos = os_strstr(cmd, " freq=");
7036 if (pos) {
7037 pos += 6;
7038 freq = atoi(pos);
7039 if (freq <= 0)
7040 return -1;
7041 }
7042
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08007043 pos = os_strstr(cmd, " pref=");
7044 if (pos) {
7045 pos += 6;
7046 pref_freq = atoi(pos);
7047 if (pref_freq <= 0)
7048 return -1;
7049 }
7050
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007051 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
7052 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
7053 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08007054 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007055 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Jouni Malinen31be0a42012-08-31 21:20:51 +03007056
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007057 pos = os_strstr(cmd, "freq2=");
7058 if (pos)
7059 freq2 = atoi(pos + 6);
7060
7061 pos = os_strstr(cmd, " max_oper_chwidth=");
7062 if (pos)
7063 chwidth = atoi(pos + 18);
7064
7065 max_oper_chwidth = parse_freq(chwidth, freq2);
7066 if (max_oper_chwidth < 0)
7067 return -1;
7068
Hai Shaloma20dcd72022-02-04 13:43:00 -08007069 allow_6ghz = os_strstr(cmd, " allow_6ghz") != NULL;
7070
7071 if (allow_6ghz && chwidth == 40)
Sunil8cd6f4d2022-06-28 18:40:46 +00007072 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007073
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007074 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
Hai Shaloma20dcd72022-02-04 13:43:00 -08007075 max_oper_chwidth, pref_freq, he, edmg,
7076 allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007077}
7078
7079
7080static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
7081{
7082 char *pos;
7083 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007084 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007085
7086 pos = os_strstr(cmd, " peer=");
7087 if (!pos)
7088 return -1;
7089
7090 *pos = '\0';
7091 pos += 6;
7092 if (hwaddr_aton(pos, peer)) {
7093 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
7094 return -1;
7095 }
7096
Hai Shaloma20dcd72022-02-04 13:43:00 -08007097 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
7098
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007099 pos = os_strstr(pos, " go_dev_addr=");
7100 if (pos) {
7101 pos += 13;
7102 if (hwaddr_aton(pos, go_dev_addr)) {
7103 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
7104 pos);
7105 return -1;
7106 }
7107 go_dev = go_dev_addr;
7108 }
7109
Hai Shaloma20dcd72022-02-04 13:43:00 -08007110 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007111}
7112
7113
7114static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
7115{
7116 if (os_strncmp(cmd, "persistent=", 11) == 0)
7117 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
7118 if (os_strncmp(cmd, "group=", 6) == 0)
7119 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
7120
7121 return -1;
7122}
7123
7124
7125static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007126 int id, int freq, int vht_center_freq2,
Hai Shalom74f70d42019-02-11 14:42:39 -08007127 int ht40, int vht, int vht_chwidth,
Sunil Raviaf8751c2023-03-29 11:35:17 -07007128 int he, int edmg, bool allow_6ghz,
7129 const u8 *go_bssid)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007130{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007131 struct wpa_ssid *ssid;
7132
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007133 ssid = wpa_config_get_network(wpa_s->conf, id);
7134 if (ssid == NULL || ssid->disabled != 2) {
7135 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
7136 "for persistent P2P group",
7137 id);
7138 return -1;
7139 }
7140
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007141 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
7142 vht_center_freq2, 0, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007143 vht_chwidth, he, edmg,
Sunil Raviaf8751c2023-03-29 11:35:17 -07007144 NULL, 0, 0, allow_6ghz, 0,
7145 go_bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007146}
7147
7148
7149static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
7150{
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007151 int freq = 0, persistent = 0, group_id = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007152 bool allow_6ghz = false;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007153 int vht = wpa_s->conf->p2p_go_vht;
7154 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08007155 int he = wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007156 int edmg = wpa_s->conf->p2p_go_edmg;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007157 int max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007158 char *token, *context = NULL;
Sunil Raviaf8751c2023-03-29 11:35:17 -07007159 u8 go_bssid_buf[ETH_ALEN], *go_bssid = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007160#ifdef CONFIG_ACS
7161 int acs = 0;
7162#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007163
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007164 while ((token = str_token(cmd, " ", &context))) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07007165 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007166 sscanf(token, "persistent=%d", &group_id) == 1 ||
7167 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007168 continue;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007169#ifdef CONFIG_ACS
7170 } else if (os_strcmp(token, "freq=acs") == 0) {
7171 acs = 1;
7172#endif /* CONFIG_ACS */
7173 } else if (sscanf(token, "freq=%d", &freq) == 1) {
7174 continue;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007175 } else if (os_strcmp(token, "ht40") == 0) {
7176 ht40 = 1;
7177 } else if (os_strcmp(token, "vht") == 0) {
7178 vht = 1;
7179 ht40 = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08007180 } else if (os_strcmp(token, "he") == 0) {
7181 he = 1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007182 } else if (os_strcmp(token, "edmg") == 0) {
7183 edmg = 1;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007184 } else if (os_strcmp(token, "persistent") == 0) {
7185 persistent = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007186 } else if (os_strcmp(token, "allow_6ghz") == 0) {
7187 allow_6ghz = true;
Sunil Raviaf8751c2023-03-29 11:35:17 -07007188 } else if (os_strncmp(token, "go_bssid=", 9) == 0) {
7189 if (hwaddr_aton(token + 9, go_bssid_buf))
7190 return -1;
7191 go_bssid = go_bssid_buf;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007192 } else {
7193 wpa_printf(MSG_DEBUG,
7194 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
7195 token);
7196 return -1;
7197 }
7198 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007199
Roshan Pius3a1667e2018-07-03 15:17:14 -07007200#ifdef CONFIG_ACS
7201 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
7202 (acs || freq == 2 || freq == 5)) {
7203 if (freq == 2 && wpa_s->best_24_freq <= 0) {
7204 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
7205 wpa_s->p2p_go_do_acs = 1;
7206 freq = 0;
7207 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
7208 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
7209 wpa_s->p2p_go_do_acs = 1;
7210 freq = 0;
7211 } else {
7212 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
7213 wpa_s->p2p_go_do_acs = 1;
7214 }
Hai Shalom021b0b52019-04-10 11:17:58 -07007215 } else {
7216 wpa_s->p2p_go_do_acs = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007217 }
7218#endif /* CONFIG_ACS */
7219
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007220 max_oper_chwidth = parse_freq(chwidth, freq2);
7221 if (max_oper_chwidth < 0)
7222 return -1;
7223
Hai Shaloma20dcd72022-02-04 13:43:00 -08007224 if (allow_6ghz && chwidth == 40)
Sunil8cd6f4d2022-06-28 18:40:46 +00007225 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007226
7227 /* Allow DFS to be used for Autonomous GO */
7228 wpa_s->p2p_go_allow_dfs = !!(wpa_s->drv_flags &
7229 WPA_DRIVER_FLAGS_DFS_OFFLOAD);
7230
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007231 if (group_id >= 0)
7232 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007233 freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007234 max_oper_chwidth, he,
Sunil Raviaf8751c2023-03-29 11:35:17 -07007235 edmg, allow_6ghz,
7236 go_bssid);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007237
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007238 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
Hai Shaloma20dcd72022-02-04 13:43:00 -08007239 max_oper_chwidth, he, edmg, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007240}
7241
7242
Dmitry Shmidt849734c2016-05-27 09:59:01 -07007243static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
7244 char *buf, size_t buflen)
7245{
7246 u8 dev_addr[ETH_ALEN];
7247 struct wpa_ssid *ssid;
7248 int res;
7249 const u8 *iaddr;
7250
7251 ssid = wpa_s->current_ssid;
7252 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
7253 hwaddr_aton(cmd, dev_addr))
7254 return -1;
7255
7256 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
7257 if (!iaddr)
7258 return -1;
7259 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
7260 if (os_snprintf_error(buflen, res))
7261 return -1;
7262 return res;
7263}
7264
7265
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007266static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
7267 const u8 *p2p_dev_addr)
7268{
7269 struct wpa_supplicant *wpa_s;
7270
7271 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7272 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
7273 return 1;
7274 }
7275
7276 return 0;
7277}
7278
7279
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007280static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
7281 char *buf, size_t buflen)
7282{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007283 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007284 int next, res;
7285 const struct p2p_peer_info *info;
7286 char *pos, *end;
7287 char devtype[WPS_DEV_TYPE_BUFSIZE];
7288 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007289 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007290
7291 if (!wpa_s->global->p2p)
7292 return -1;
7293
7294 if (os_strcmp(cmd, "FIRST") == 0) {
7295 addr_ptr = NULL;
7296 next = 0;
7297 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
7298 if (hwaddr_aton(cmd + 5, addr) < 0)
7299 return -1;
7300 addr_ptr = addr;
7301 next = 1;
7302 } else {
7303 if (hwaddr_aton(cmd, addr) < 0)
7304 return -1;
7305 addr_ptr = addr;
7306 next = 0;
7307 }
7308
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007309 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
7310 if (info == NULL)
7311 return -1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007312 group_capab = info->group_capab;
7313
7314 if (group_capab &&
7315 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
7316 wpa_printf(MSG_DEBUG,
7317 "P2P: Could not find any BSS with p2p_dev_addr "
7318 MACSTR ", hence override group_capab from 0x%x to 0",
7319 MAC2STR(info->p2p_device_addr), group_capab);
7320 group_capab = 0;
7321 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007322
7323 pos = buf;
7324 end = buf + buflen;
7325
7326 res = os_snprintf(pos, end - pos, MACSTR "\n"
7327 "pri_dev_type=%s\n"
7328 "device_name=%s\n"
7329 "manufacturer=%s\n"
7330 "model_name=%s\n"
7331 "model_number=%s\n"
7332 "serial_number=%s\n"
7333 "config_methods=0x%x\n"
7334 "dev_capab=0x%x\n"
7335 "group_capab=0x%x\n"
7336 "level=%d\n",
7337 MAC2STR(info->p2p_device_addr),
7338 wps_dev_type_bin2str(info->pri_dev_type,
7339 devtype, sizeof(devtype)),
7340 info->device_name,
7341 info->manufacturer,
7342 info->model_name,
7343 info->model_number,
7344 info->serial_number,
7345 info->config_methods,
7346 info->dev_capab,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007347 group_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007348 info->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007349 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007350 return pos - buf;
7351 pos += res;
7352
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007353 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
7354 {
7355 const u8 *t;
7356 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
7357 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
7358 wps_dev_type_bin2str(t, devtype,
7359 sizeof(devtype)));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007360 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007361 return pos - buf;
7362 pos += res;
7363 }
7364
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007365 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007366 if (ssid) {
7367 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007368 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007369 return pos - buf;
7370 pos += res;
7371 }
7372
7373 res = p2p_get_peer_info_txt(info, pos, end - pos);
7374 if (res < 0)
7375 return pos - buf;
7376 pos += res;
7377
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007378 if (info->vendor_elems) {
7379 res = os_snprintf(pos, end - pos, "vendor_elems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007380 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007381 return pos - buf;
7382 pos += res;
7383
7384 pos += wpa_snprintf_hex(pos, end - pos,
7385 wpabuf_head(info->vendor_elems),
7386 wpabuf_len(info->vendor_elems));
7387
7388 res = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007389 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007390 return pos - buf;
7391 pos += res;
7392 }
7393
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007394 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007395}
7396
7397
Dmitry Shmidt04949592012-07-19 12:16:46 -07007398static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
7399 const char *param)
7400{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007401 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007402
7403 if (wpa_s->global->p2p == NULL)
7404 return -1;
7405
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007406 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
7407 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007408
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007409 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
7410 struct wpa_freq_range *freq;
7411 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07007412 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007413 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007414 }
7415
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007416 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007417 return 0;
7418}
7419
7420
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007421static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
7422{
7423 char *param;
7424
7425 if (wpa_s->global->p2p == NULL)
7426 return -1;
7427
7428 param = os_strchr(cmd, ' ');
7429 if (param == NULL)
7430 return -1;
7431 *param++ = '\0';
7432
7433 if (os_strcmp(cmd, "discoverability") == 0) {
7434 p2p_set_client_discoverability(wpa_s->global->p2p,
7435 atoi(param));
7436 return 0;
7437 }
7438
7439 if (os_strcmp(cmd, "managed") == 0) {
7440 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
7441 return 0;
7442 }
7443
7444 if (os_strcmp(cmd, "listen_channel") == 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08007445 char *pos;
7446 u8 channel, op_class;
7447
7448 channel = atoi(param);
7449 pos = os_strchr(param, ' ');
7450 op_class = pos ? atoi(pos) : 81;
7451
7452 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
7453 channel, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007454 }
7455
7456 if (os_strcmp(cmd, "ssid_postfix") == 0) {
7457 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
7458 os_strlen(param));
7459 }
7460
7461 if (os_strcmp(cmd, "noa") == 0) {
7462 char *pos;
7463 int count, start, duration;
7464 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
7465 count = atoi(param);
7466 pos = os_strchr(param, ',');
7467 if (pos == NULL)
7468 return -1;
7469 pos++;
7470 start = atoi(pos);
7471 pos = os_strchr(pos, ',');
7472 if (pos == NULL)
7473 return -1;
7474 pos++;
7475 duration = atoi(pos);
7476 if (count < 0 || count > 255 || start < 0 || duration < 0)
7477 return -1;
7478 if (count == 0 && duration > 0)
7479 return -1;
7480 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
7481 "start=%d duration=%d", count, start, duration);
7482 return wpas_p2p_set_noa(wpa_s, count, start, duration);
7483 }
7484
7485 if (os_strcmp(cmd, "ps") == 0)
7486 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
7487
7488 if (os_strcmp(cmd, "oppps") == 0)
7489 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
7490
7491 if (os_strcmp(cmd, "ctwindow") == 0)
7492 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
7493
7494 if (os_strcmp(cmd, "disabled") == 0) {
7495 wpa_s->global->p2p_disabled = atoi(param);
7496 wpa_printf(MSG_DEBUG, "P2P functionality %s",
7497 wpa_s->global->p2p_disabled ?
7498 "disabled" : "enabled");
7499 if (wpa_s->global->p2p_disabled) {
7500 wpas_p2p_stop_find(wpa_s);
7501 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7502 p2p_flush(wpa_s->global->p2p);
7503 }
7504 return 0;
7505 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007506
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007507 if (os_strcmp(cmd, "conc_pref") == 0) {
7508 if (os_strcmp(param, "sta") == 0)
7509 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
7510 else if (os_strcmp(param, "p2p") == 0)
7511 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007512 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007513 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007514 return -1;
7515 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007516 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07007517 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007518 return 0;
7519 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007520
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007521 if (os_strcmp(cmd, "force_long_sd") == 0) {
7522 wpa_s->force_long_sd = atoi(param);
7523 return 0;
7524 }
7525
7526 if (os_strcmp(cmd, "peer_filter") == 0) {
7527 u8 addr[ETH_ALEN];
7528 if (hwaddr_aton(param, addr))
7529 return -1;
7530 p2p_set_peer_filter(wpa_s->global->p2p, addr);
7531 return 0;
7532 }
7533
7534 if (os_strcmp(cmd, "cross_connect") == 0)
7535 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
7536
7537 if (os_strcmp(cmd, "go_apsd") == 0) {
7538 if (os_strcmp(param, "disable") == 0)
7539 wpa_s->set_ap_uapsd = 0;
7540 else {
7541 wpa_s->set_ap_uapsd = 1;
7542 wpa_s->ap_uapsd = atoi(param);
7543 }
7544 return 0;
7545 }
7546
7547 if (os_strcmp(cmd, "client_apsd") == 0) {
7548 if (os_strcmp(param, "disable") == 0)
7549 wpa_s->set_sta_uapsd = 0;
7550 else {
7551 int be, bk, vi, vo;
7552 char *pos;
7553 /* format: BE,BK,VI,VO;max SP Length */
7554 be = atoi(param);
7555 pos = os_strchr(param, ',');
7556 if (pos == NULL)
7557 return -1;
7558 pos++;
7559 bk = atoi(pos);
7560 pos = os_strchr(pos, ',');
7561 if (pos == NULL)
7562 return -1;
7563 pos++;
7564 vi = atoi(pos);
7565 pos = os_strchr(pos, ',');
7566 if (pos == NULL)
7567 return -1;
7568 pos++;
7569 vo = atoi(pos);
7570 /* ignore max SP Length for now */
7571
7572 wpa_s->set_sta_uapsd = 1;
7573 wpa_s->sta_uapsd = 0;
7574 if (be)
7575 wpa_s->sta_uapsd |= BIT(0);
7576 if (bk)
7577 wpa_s->sta_uapsd |= BIT(1);
7578 if (vi)
7579 wpa_s->sta_uapsd |= BIT(2);
7580 if (vo)
7581 wpa_s->sta_uapsd |= BIT(3);
7582 }
7583 return 0;
7584 }
7585
Dmitry Shmidt04949592012-07-19 12:16:46 -07007586 if (os_strcmp(cmd, "disallow_freq") == 0)
7587 return p2p_ctrl_disallow_freq(wpa_s, param);
7588
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007589 if (os_strcmp(cmd, "disc_int") == 0) {
7590 int min_disc_int, max_disc_int, max_disc_tu;
7591 char *pos;
7592
7593 pos = param;
7594
7595 min_disc_int = atoi(pos);
7596 pos = os_strchr(pos, ' ');
7597 if (pos == NULL)
7598 return -1;
7599 *pos++ = '\0';
7600
7601 max_disc_int = atoi(pos);
7602 pos = os_strchr(pos, ' ');
7603 if (pos == NULL)
7604 return -1;
7605 *pos++ = '\0';
7606
7607 max_disc_tu = atoi(pos);
7608
7609 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
7610 max_disc_int, max_disc_tu);
7611 }
7612
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007613 if (os_strcmp(cmd, "per_sta_psk") == 0) {
7614 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
7615 return 0;
7616 }
7617
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007618#ifdef CONFIG_WPS_NFC
7619 if (os_strcmp(cmd, "nfc_tag") == 0)
7620 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
7621#endif /* CONFIG_WPS_NFC */
7622
7623 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
7624 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
7625 return 0;
7626 }
7627
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007628 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
7629 int op_class, chan;
7630
7631 op_class = atoi(param);
7632 param = os_strchr(param, ':');
7633 if (!param)
7634 return -1;
7635 param++;
7636 chan = atoi(param);
7637 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
7638 chan);
7639 return 0;
7640 }
7641
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007642 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
7643 cmd);
7644
7645 return -1;
7646}
7647
7648
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007649static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
7650{
7651 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7652 wpa_s->force_long_sd = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007653
7654#ifdef CONFIG_TESTING_OPTIONS
7655 os_free(wpa_s->get_pref_freq_list_override);
7656 wpa_s->get_pref_freq_list_override = NULL;
7657#endif /* CONFIG_TESTING_OPTIONS */
7658
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007659 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007660 wpa_s->parent->p2ps_method_config_any = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007661 if (wpa_s->global->p2p)
7662 p2p_flush(wpa_s->global->p2p);
7663}
7664
7665
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007666static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
7667{
7668 char *pos, *pos2;
7669 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
7670
7671 if (cmd[0]) {
7672 pos = os_strchr(cmd, ' ');
7673 if (pos == NULL)
7674 return -1;
7675 *pos++ = '\0';
7676 dur1 = atoi(cmd);
7677
7678 pos2 = os_strchr(pos, ' ');
7679 if (pos2)
7680 *pos2++ = '\0';
7681 int1 = atoi(pos);
7682 } else
7683 pos2 = NULL;
7684
7685 if (pos2) {
7686 pos = os_strchr(pos2, ' ');
7687 if (pos == NULL)
7688 return -1;
7689 *pos++ = '\0';
7690 dur2 = atoi(pos2);
7691 int2 = atoi(pos);
7692 }
7693
7694 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
7695}
7696
7697
7698static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
7699{
7700 char *pos;
7701 unsigned int period = 0, interval = 0;
7702
7703 if (cmd[0]) {
7704 pos = os_strchr(cmd, ' ');
7705 if (pos == NULL)
7706 return -1;
7707 *pos++ = '\0';
7708 period = atoi(cmd);
7709 interval = atoi(pos);
7710 }
7711
7712 return wpas_p2p_ext_listen(wpa_s, period, interval);
7713}
7714
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007715
7716static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
7717{
7718 const char *pos;
7719 u8 peer[ETH_ALEN];
7720 int iface_addr = 0;
7721
7722 pos = cmd;
7723 if (os_strncmp(pos, "iface=", 6) == 0) {
7724 iface_addr = 1;
7725 pos += 6;
7726 }
7727 if (hwaddr_aton(pos, peer))
7728 return -1;
7729
7730 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
7731 return 0;
7732}
7733
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007734
7735static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
7736{
7737 int freq = 0, period = 0, interval = 0, count = 0;
7738
7739 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
7740 {
7741 wpa_printf(MSG_DEBUG,
7742 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
7743 return -1;
7744 }
7745
7746 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
7747}
7748
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007749#endif /* CONFIG_P2P */
7750
7751
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007752static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
7753{
7754 struct wpa_freq_range_list ranges;
7755 int *freqs = NULL;
7756 struct hostapd_hw_modes *mode;
7757 u16 i;
7758
7759 if (wpa_s->hw.modes == NULL)
7760 return NULL;
7761
7762 os_memset(&ranges, 0, sizeof(ranges));
7763 if (freq_range_list_parse(&ranges, val) < 0)
7764 return NULL;
7765
7766 for (i = 0; i < wpa_s->hw.num_modes; i++) {
7767 int j;
7768
7769 mode = &wpa_s->hw.modes[i];
7770 for (j = 0; j < mode->num_channels; j++) {
7771 unsigned int freq;
7772
7773 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
7774 continue;
7775
7776 freq = mode->channels[j].freq;
7777 if (!freq_range_list_includes(&ranges, freq))
7778 continue;
7779
7780 int_array_add_unique(&freqs, freq);
7781 }
7782 }
7783
7784 os_free(ranges.range);
7785 return freqs;
7786}
7787
7788
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007789#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007790
7791static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
7792{
7793 int auto_sel = 0;
7794 int *freqs = NULL;
7795
7796 if (param) {
7797 char *pos;
7798
7799 auto_sel = os_strstr(param, "auto") != NULL;
7800
7801 pos = os_strstr(param, "freq=");
7802 if (pos) {
7803 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
7804 if (freqs == NULL)
7805 return -1;
7806 }
7807
7808 }
7809
7810 return interworking_select(wpa_s, auto_sel, freqs);
7811}
7812
7813
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007814static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
7815 int only_add)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007816{
7817 u8 bssid[ETH_ALEN];
7818 struct wpa_bss *bss;
7819
7820 if (hwaddr_aton(dst, bssid)) {
7821 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
7822 return -1;
7823 }
7824
Hai Shalomfdcde762020-04-02 11:19:20 -07007825 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007826 if (bss == NULL) {
7827 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
7828 MAC2STR(bssid));
7829 return -1;
7830 }
7831
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007832 if (bss->ssid_len == 0) {
7833 int found = 0;
7834
7835 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
7836 " does not have SSID information", MAC2STR(bssid));
7837
7838 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
7839 list) {
7840 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
7841 bss->ssid_len > 0) {
7842 found = 1;
7843 break;
7844 }
7845 }
7846
7847 if (!found)
7848 return -1;
7849 wpa_printf(MSG_DEBUG,
7850 "Found another matching BSS entry with SSID");
7851 }
7852
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007853 return interworking_connect(wpa_s, bss, only_add);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007854}
7855
7856
7857static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
7858{
7859 u8 dst_addr[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07007860 int used, freq = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007861 char *pos;
7862#define MAX_ANQP_INFO_ID 100
7863 u16 id[MAX_ANQP_INFO_ID];
7864 size_t num_id = 0;
Dmitry Shmidt15907092014-03-25 10:42:57 -07007865 u32 subtypes = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007866 u32 mbo_subtypes = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007867
7868 used = hwaddr_aton2(dst, dst_addr);
7869 if (used < 0)
7870 return -1;
7871 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007872 if (*pos == ' ')
7873 pos++;
Hai Shalom899fcc72020-10-19 14:38:18 -07007874
7875 if (os_strncmp(pos, "freq=", 5) == 0) {
7876 freq = atoi(pos + 5);
7877 pos = os_strchr(pos, ' ');
7878 if (!pos)
7879 return -1;
7880 pos++;
7881 }
7882
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007883 while (num_id < MAX_ANQP_INFO_ID) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07007884 if (os_strncmp(pos, "hs20:", 5) == 0) {
7885#ifdef CONFIG_HS20
7886 int num = atoi(pos + 5);
7887 if (num <= 0 || num > 31)
7888 return -1;
7889 subtypes |= BIT(num);
7890#else /* CONFIG_HS20 */
7891 return -1;
7892#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007893 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7894#ifdef CONFIG_MBO
7895 int num = atoi(pos + 4);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007896
7897 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007898 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007899 mbo_subtypes |= BIT(num);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007900#else /* CONFIG_MBO */
7901 return -1;
7902#endif /* CONFIG_MBO */
Dmitry Shmidt15907092014-03-25 10:42:57 -07007903 } else {
7904 id[num_id] = atoi(pos);
7905 if (id[num_id])
7906 num_id++;
7907 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007908 pos = os_strchr(pos + 1, ',');
7909 if (pos == NULL)
7910 break;
7911 pos++;
7912 }
7913
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007914 if (num_id == 0 && !subtypes && !mbo_subtypes)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007915 return -1;
7916
Hai Shalom899fcc72020-10-19 14:38:18 -07007917 return anqp_send_req(wpa_s, dst_addr, freq, id, num_id, subtypes,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007918 mbo_subtypes);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007919}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007920
7921
7922static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7923{
7924 u8 dst_addr[ETH_ALEN];
7925 struct wpabuf *advproto, *query = NULL;
7926 int used, ret = -1;
7927 char *pos, *end;
7928 size_t len;
7929
7930 used = hwaddr_aton2(cmd, dst_addr);
7931 if (used < 0)
7932 return -1;
7933
7934 pos = cmd + used;
7935 while (*pos == ' ')
7936 pos++;
7937
7938 /* Advertisement Protocol ID */
7939 end = os_strchr(pos, ' ');
7940 if (end)
7941 len = end - pos;
7942 else
7943 len = os_strlen(pos);
7944 if (len & 0x01)
7945 return -1;
7946 len /= 2;
7947 if (len == 0)
7948 return -1;
7949 advproto = wpabuf_alloc(len);
7950 if (advproto == NULL)
7951 return -1;
7952 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7953 goto fail;
7954
7955 if (end) {
7956 /* Optional Query Request */
7957 pos = end + 1;
7958 while (*pos == ' ')
7959 pos++;
7960
7961 len = os_strlen(pos);
7962 if (len) {
7963 if (len & 0x01)
7964 goto fail;
7965 len /= 2;
7966 if (len == 0)
7967 goto fail;
7968 query = wpabuf_alloc(len);
7969 if (query == NULL)
7970 goto fail;
7971 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7972 goto fail;
7973 }
7974 }
7975
7976 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7977
7978fail:
7979 wpabuf_free(advproto);
7980 wpabuf_free(query);
7981
7982 return ret;
7983}
7984
7985
7986static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7987 size_t buflen)
7988{
7989 u8 addr[ETH_ALEN];
7990 int dialog_token;
7991 int used;
7992 char *pos;
7993 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007994 struct wpabuf *resp;
7995 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007996
7997 used = hwaddr_aton2(cmd, addr);
7998 if (used < 0)
7999 return -1;
8000
8001 pos = cmd + used;
8002 while (*pos == ' ')
8003 pos++;
8004 dialog_token = atoi(pos);
8005
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008006 if (wpa_s->last_gas_resp &&
8007 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
8008 dialog_token == wpa_s->last_gas_dialog_token)
8009 resp = wpa_s->last_gas_resp;
8010 else if (wpa_s->prev_gas_resp &&
8011 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
8012 dialog_token == wpa_s->prev_gas_dialog_token)
8013 resp = wpa_s->prev_gas_resp;
8014 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008015 return -1;
8016
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008017 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008018 start = 0;
8019 requested_len = resp_len;
8020
8021 pos = os_strchr(pos, ' ');
8022 if (pos) {
8023 start = atoi(pos);
8024 if (start > resp_len)
8025 return os_snprintf(buf, buflen, "FAIL-Invalid range");
8026 pos = os_strchr(pos, ',');
8027 if (pos == NULL)
8028 return -1;
8029 pos++;
8030 requested_len = atoi(pos);
8031 if (start + requested_len > resp_len)
8032 return os_snprintf(buf, buflen, "FAIL-Invalid range");
8033 }
8034
8035 if (requested_len * 2 + 1 > buflen)
8036 return os_snprintf(buf, buflen, "FAIL-Too long response");
8037
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008038 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
8039 requested_len);
8040
8041 if (start + requested_len == resp_len) {
8042 /*
8043 * Free memory by dropping the response after it has been
8044 * fetched.
8045 */
8046 if (resp == wpa_s->prev_gas_resp) {
8047 wpabuf_free(wpa_s->prev_gas_resp);
8048 wpa_s->prev_gas_resp = NULL;
8049 } else {
8050 wpabuf_free(wpa_s->last_gas_resp);
8051 wpa_s->last_gas_resp = NULL;
8052 }
8053 }
8054
8055 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008056}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008057#endif /* CONFIG_INTERWORKING */
8058
8059
Dmitry Shmidt04949592012-07-19 12:16:46 -07008060#ifdef CONFIG_HS20
8061
8062static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
8063{
8064 u8 dst_addr[ETH_ALEN];
8065 int used;
8066 char *pos;
8067 u32 subtypes = 0;
8068
8069 used = hwaddr_aton2(dst, dst_addr);
8070 if (used < 0)
8071 return -1;
8072 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008073 if (*pos == ' ')
8074 pos++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07008075 for (;;) {
8076 int num = atoi(pos);
8077 if (num <= 0 || num > 31)
8078 return -1;
8079 subtypes |= BIT(num);
8080 pos = os_strchr(pos + 1, ',');
8081 if (pos == NULL)
8082 break;
8083 pos++;
8084 }
8085
8086 if (subtypes == 0)
8087 return -1;
8088
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008089 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008090}
8091
8092
8093static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
8094 const u8 *addr, const char *realm)
8095{
8096 u8 *buf;
8097 size_t rlen, len;
8098 int ret;
8099
8100 rlen = os_strlen(realm);
8101 len = 3 + rlen;
8102 buf = os_malloc(len);
8103 if (buf == NULL)
8104 return -1;
8105 buf[0] = 1; /* NAI Home Realm Count */
8106 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
8107 buf[2] = rlen;
8108 os_memcpy(buf + 3, realm, rlen);
8109
8110 ret = hs20_anqp_send_req(wpa_s, addr,
8111 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008112 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008113
8114 os_free(buf);
8115
8116 return ret;
8117}
8118
8119
8120static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
8121 char *dst)
8122{
8123 struct wpa_cred *cred = wpa_s->conf->cred;
8124 u8 dst_addr[ETH_ALEN];
8125 int used;
8126 u8 *buf;
8127 size_t len;
8128 int ret;
8129
8130 used = hwaddr_aton2(dst, dst_addr);
8131 if (used < 0)
8132 return -1;
8133
8134 while (dst[used] == ' ')
8135 used++;
8136 if (os_strncmp(dst + used, "realm=", 6) == 0)
8137 return hs20_nai_home_realm_list(wpa_s, dst_addr,
8138 dst + used + 6);
8139
8140 len = os_strlen(dst + used);
8141
8142 if (len == 0 && cred && cred->realm)
8143 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
8144
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07008145 if (len & 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07008146 return -1;
8147 len /= 2;
8148 buf = os_malloc(len);
8149 if (buf == NULL)
8150 return -1;
8151 if (hexstr2bin(dst + used, buf, len) < 0) {
8152 os_free(buf);
8153 return -1;
8154 }
8155
8156 ret = hs20_anqp_send_req(wpa_s, dst_addr,
8157 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008158 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008159 os_free(buf);
8160
8161 return ret;
8162}
8163
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008164
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008165static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
8166 int buflen)
8167{
8168 u8 dst_addr[ETH_ALEN];
8169 int used;
8170 char *ctx = NULL, *icon, *poffset, *psize;
8171
8172 used = hwaddr_aton2(cmd, dst_addr);
8173 if (used < 0)
8174 return -1;
8175 cmd += used;
8176
8177 icon = str_token(cmd, " ", &ctx);
8178 poffset = str_token(cmd, " ", &ctx);
8179 psize = str_token(cmd, " ", &ctx);
8180 if (!icon || !poffset || !psize)
8181 return -1;
8182
8183 wpa_s->fetch_osu_icon_in_progress = 0;
8184 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
8185 reply, buflen);
8186}
8187
8188
8189static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
8190{
8191 u8 dst_addr[ETH_ALEN];
8192 int used;
8193 char *icon;
8194
8195 if (!cmd[0])
8196 return hs20_del_icon(wpa_s, NULL, NULL);
8197
8198 used = hwaddr_aton2(cmd, dst_addr);
8199 if (used < 0)
8200 return -1;
8201
8202 while (cmd[used] == ' ')
8203 used++;
8204 icon = cmd[used] ? &cmd[used] : NULL;
8205
8206 return hs20_del_icon(wpa_s, dst_addr, icon);
8207}
8208
8209
8210static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008211{
8212 u8 dst_addr[ETH_ALEN];
8213 int used;
8214 char *icon;
8215
8216 used = hwaddr_aton2(cmd, dst_addr);
8217 if (used < 0)
8218 return -1;
8219
8220 while (cmd[used] == ' ')
8221 used++;
8222 icon = &cmd[used];
8223
8224 wpa_s->fetch_osu_icon_in_progress = 0;
8225 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008226 (u8 *) icon, os_strlen(icon), inmem);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008227}
8228
Dmitry Shmidt04949592012-07-19 12:16:46 -07008229#endif /* CONFIG_HS20 */
8230
8231
Dmitry Shmidt04949592012-07-19 12:16:46 -07008232#ifdef CONFIG_AUTOSCAN
8233
8234static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
8235 char *cmd)
8236{
8237 enum wpa_states state = wpa_s->wpa_state;
8238 char *new_params = NULL;
8239
8240 if (os_strlen(cmd) > 0) {
8241 new_params = os_strdup(cmd);
8242 if (new_params == NULL)
8243 return -1;
8244 }
8245
8246 os_free(wpa_s->conf->autoscan);
8247 wpa_s->conf->autoscan = new_params;
8248
8249 if (wpa_s->conf->autoscan == NULL)
8250 autoscan_deinit(wpa_s);
8251 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
8252 autoscan_init(wpa_s, 1);
8253 else if (state == WPA_SCANNING)
8254 wpa_supplicant_reinit_autoscan(wpa_s);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08008255 else
8256 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
8257 wpa_supplicant_state_txt(state));
Dmitry Shmidt04949592012-07-19 12:16:46 -07008258
8259 return 0;
8260}
8261
8262#endif /* CONFIG_AUTOSCAN */
8263
8264
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08008265#ifdef CONFIG_WNM
8266
8267static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
8268{
8269 int enter;
8270 int intval = 0;
8271 char *pos;
8272 int ret;
8273 struct wpabuf *tfs_req = NULL;
8274
8275 if (os_strncmp(cmd, "enter", 5) == 0)
8276 enter = 1;
8277 else if (os_strncmp(cmd, "exit", 4) == 0)
8278 enter = 0;
8279 else
8280 return -1;
8281
8282 pos = os_strstr(cmd, " interval=");
8283 if (pos)
8284 intval = atoi(pos + 10);
8285
8286 pos = os_strstr(cmd, " tfs_req=");
8287 if (pos) {
8288 char *end;
8289 size_t len;
8290 pos += 9;
8291 end = os_strchr(pos, ' ');
8292 if (end)
8293 len = end - pos;
8294 else
8295 len = os_strlen(pos);
8296 if (len & 1)
8297 return -1;
8298 len /= 2;
8299 tfs_req = wpabuf_alloc(len);
8300 if (tfs_req == NULL)
8301 return -1;
8302 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
8303 wpabuf_free(tfs_req);
8304 return -1;
8305 }
8306 }
8307
8308 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
8309 WNM_SLEEP_MODE_EXIT, intval,
8310 tfs_req);
8311 wpabuf_free(tfs_req);
8312
8313 return ret;
8314}
8315
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008316
8317static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
8318{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008319 int query_reason, list = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008320 char *btm_candidates = NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008321
8322 query_reason = atoi(cmd);
8323
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008324 cmd = os_strchr(cmd, ' ');
8325 if (cmd) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008326 if (os_strncmp(cmd, " list", 5) == 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008327 list = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008328 else
8329 btm_candidates = cmd;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008330 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008331
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008332 wpa_printf(MSG_DEBUG,
8333 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
8334 query_reason, list ? " candidate list" : "");
8335
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008336 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
8337 btm_candidates,
8338 list);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008339}
8340
Hai Shalom39ba6fc2019-01-22 12:40:38 -08008341
8342static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
8343 char *cmd)
8344{
8345 struct wpabuf *elems;
8346 int ret;
8347
8348 elems = wpabuf_parse_bin(cmd);
8349 if (!elems)
8350 return -1;
8351
8352 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
8353 wpabuf_free(elems);
8354 return ret;
8355}
8356
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08008357#endif /* CONFIG_WNM */
8358
8359
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008360static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
8361 size_t buflen)
8362{
8363 struct wpa_signal_info si;
8364 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008365 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008366
8367 ret = wpa_drv_signal_poll(wpa_s, &si);
8368 if (ret)
8369 return -1;
8370
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008371 pos = buf;
8372 end = buf + buflen;
8373
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008374 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%lu\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008375 "NOISE=%d\nFREQUENCY=%u\n",
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008376 si.data.signal, si.data.current_tx_rate / 1000,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008377 si.current_noise, si.frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008378 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008379 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008380 pos += ret;
8381
8382 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
8383 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008384 channel_width_to_string(si.chanwidth));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008385 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008386 return -1;
8387 pos += ret;
8388 }
8389
Roshan Pius3a1667e2018-07-03 15:17:14 -07008390 if (si.center_frq1 > 0) {
8391 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
8392 si.center_frq1);
8393 if (os_snprintf_error(end - pos, ret))
8394 return -1;
8395 pos += ret;
8396 }
8397
8398 if (si.center_frq2 > 0) {
8399 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
8400 si.center_frq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008401 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008402 return -1;
8403 pos += ret;
8404 }
8405
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008406 if (si.data.avg_signal) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008407 ret = os_snprintf(pos, end - pos,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008408 "AVG_RSSI=%d\n", si.data.avg_signal);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008409 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008410 return -1;
8411 pos += ret;
8412 }
8413
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008414 if (si.data.avg_beacon_signal) {
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07008415 ret = os_snprintf(pos, end - pos,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008416 "AVG_BEACON_RSSI=%d\n",
8417 si.data.avg_beacon_signal);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07008418 if (os_snprintf_error(end - pos, ret))
8419 return -1;
8420 pos += ret;
8421 }
8422
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008423 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008424}
8425
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008426
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008427static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
8428 const char *cmd)
8429{
8430 const char *pos;
8431 int threshold = 0;
8432 int hysteresis = 0;
8433
8434 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
8435 wpa_printf(MSG_DEBUG,
8436 "Reject SIGNAL_MONITOR command - bgscan is active");
8437 return -1;
8438 }
8439 pos = os_strstr(cmd, "THRESHOLD=");
8440 if (pos)
8441 threshold = atoi(pos + 10);
8442 pos = os_strstr(cmd, "HYSTERESIS=");
8443 if (pos)
8444 hysteresis = atoi(pos + 11);
8445 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
8446}
8447
8448
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008449#ifdef CONFIG_TESTING_OPTIONS
8450int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
8451 enum wpa_driver_if_type if_type,
8452 unsigned int *num,
Sunil8cd6f4d2022-06-28 18:40:46 +00008453 struct weighted_pcl *freq_list)
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008454{
8455 char *pos = wpa_s->get_pref_freq_list_override;
8456 char *end;
8457 unsigned int count = 0;
8458
8459 /* Override string format:
8460 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
8461
8462 while (pos) {
8463 if (atoi(pos) == (int) if_type)
8464 break;
8465 pos = os_strchr(pos, ' ');
8466 if (pos)
8467 pos++;
8468 }
8469 if (!pos)
8470 return -1;
8471 pos = os_strchr(pos, ':');
8472 if (!pos)
8473 return -1;
8474 pos++;
8475 end = os_strchr(pos, ' ');
8476 while (pos && (!end || pos < end) && count < *num) {
Sunil8cd6f4d2022-06-28 18:40:46 +00008477 freq_list[count].freq = atoi(pos);
8478 freq_list[count++].flag = WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008479 pos = os_strchr(pos, ',');
8480 if (pos)
8481 pos++;
8482 }
8483
8484 *num = count;
8485 return 0;
8486}
8487#endif /* CONFIG_TESTING_OPTIONS */
8488
8489
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008490static int wpas_ctrl_iface_get_pref_freq_list(
8491 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
8492{
Sunil8cd6f4d2022-06-28 18:40:46 +00008493 unsigned int num = 100, i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008494 int ret;
8495 enum wpa_driver_if_type iface_type;
8496 char *pos, *end;
Sunil8cd6f4d2022-06-28 18:40:46 +00008497 struct weighted_pcl freq_list[100];
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008498
8499 pos = buf;
8500 end = buf + buflen;
8501
8502 /* buf: "<interface_type>" */
8503 if (os_strcmp(cmd, "STATION") == 0)
8504 iface_type = WPA_IF_STATION;
8505 else if (os_strcmp(cmd, "AP") == 0)
8506 iface_type = WPA_IF_AP_BSS;
8507 else if (os_strcmp(cmd, "P2P_GO") == 0)
8508 iface_type = WPA_IF_P2P_GO;
8509 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
8510 iface_type = WPA_IF_P2P_CLIENT;
8511 else if (os_strcmp(cmd, "IBSS") == 0)
8512 iface_type = WPA_IF_IBSS;
8513 else if (os_strcmp(cmd, "TDLS") == 0)
8514 iface_type = WPA_IF_TDLS;
8515 else
8516 return -1;
8517
8518 wpa_printf(MSG_DEBUG,
8519 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
Hai Shalom5f92bc92019-04-18 11:54:11 -07008520 iface_type, cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008521
8522 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
8523 if (ret)
8524 return -1;
8525
8526 for (i = 0; i < num; i++) {
8527 ret = os_snprintf(pos, end - pos, "%s%u",
Sunil8cd6f4d2022-06-28 18:40:46 +00008528 i > 0 ? "," : "", freq_list[i].freq);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008529 if (os_snprintf_error(end - pos, ret))
8530 return -1;
8531 pos += ret;
8532 }
8533
8534 return pos - buf;
8535}
8536
8537
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008538static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
8539 char *buf, size_t buflen)
8540{
8541 int ret, i;
8542 char *pos, *end;
8543
8544 ret = os_snprintf(buf, buflen, "%016llX:\n",
8545 (long long unsigned) wpa_s->drv_flags);
8546 if (os_snprintf_error(buflen, ret))
8547 return -1;
8548
8549 pos = buf + ret;
8550 end = buf + buflen;
8551
8552 for (i = 0; i < 64; i++) {
8553 if (wpa_s->drv_flags & (1LLU << i)) {
8554 ret = os_snprintf(pos, end - pos, "%s\n",
8555 driver_flag_to_string(1LLU << i));
8556 if (os_snprintf_error(end - pos, ret))
8557 return -1;
8558 pos += ret;
8559 }
8560 }
8561
8562 return pos - buf;
8563}
8564
8565
Hai Shalomb755a2a2020-04-23 21:49:02 -07008566static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s,
8567 char *buf, size_t buflen)
8568{
8569 int ret, i;
8570 char *pos, *end;
8571
8572 ret = os_snprintf(buf, buflen, "%016llX:\n",
8573 (long long unsigned) wpa_s->drv_flags2);
8574 if (os_snprintf_error(buflen, ret))
8575 return -1;
8576
8577 pos = buf + ret;
8578 end = buf + buflen;
8579
8580 for (i = 0; i < 64; i++) {
8581 if (wpa_s->drv_flags2 & (1LLU << i)) {
8582 ret = os_snprintf(pos, end - pos, "%s\n",
8583 driver_flag2_to_string(1LLU << i));
8584 if (os_snprintf_error(end - pos, ret))
8585 return -1;
8586 pos += ret;
8587 }
8588 }
8589
8590 return pos - buf;
8591}
8592
8593
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008594static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
8595 size_t buflen)
8596{
8597 struct hostap_sta_driver_data sta;
8598 int ret;
8599
8600 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
8601 if (ret)
8602 return -1;
8603
8604 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008605 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008606 if (os_snprintf_error(buflen, ret))
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008607 return -1;
8608 return ret;
8609}
8610
8611
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008612#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008613static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8614 char *buf, size_t buflen)
8615{
8616 int ret;
8617
8618 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008619 if (ret == 0) {
8620 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
8621 struct p2p_data *p2p = wpa_s->global->p2p;
8622 if (p2p) {
8623 char country[3];
8624 country[0] = cmd[8];
8625 country[1] = cmd[9];
8626 country[2] = 0x04;
8627 p2p_set_country(p2p, country);
8628 }
8629 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008630 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008631 if (os_snprintf_error(buflen, ret))
8632 ret = -1;
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008633 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008634 return ret;
8635}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008636#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008637
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07008638
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008639static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8640 char *buf, size_t buflen)
8641{
8642 int ret;
Hai Shalom60840252021-02-19 19:02:11 -08008643 char *pos, *temp = NULL;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008644 u8 *data = NULL;
8645 unsigned int vendor_id, subcmd;
Hai Shalom60840252021-02-19 19:02:11 -08008646 enum nested_attr nested_attr_flag = NESTED_ATTR_UNSPECIFIED;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008647 struct wpabuf *reply;
8648 size_t data_len = 0;
8649
Hai Shalom60840252021-02-19 19:02:11 -08008650 /**
8651 * cmd: <vendor id> <subcommand id> [<hex formatted data>]
8652 * [nested=<0|1>]
8653 */
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008654 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008655 if (!isblank((unsigned char) *pos))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008656 return -EINVAL;
8657
8658 subcmd = strtoul(pos, &pos, 10);
8659
8660 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008661 if (!isblank((unsigned char) *pos++))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008662 return -EINVAL;
Hai Shalom60840252021-02-19 19:02:11 -08008663
8664 temp = os_strchr(pos, ' ');
8665 data_len = temp ? (size_t) (temp - pos) : os_strlen(pos);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008666 }
8667
8668 if (data_len) {
8669 data_len /= 2;
8670 data = os_malloc(data_len);
8671 if (!data)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008672 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008673
8674 if (hexstr2bin(pos, data, data_len)) {
8675 wpa_printf(MSG_DEBUG,
8676 "Vendor command: wrong parameter format");
8677 os_free(data);
8678 return -EINVAL;
8679 }
8680 }
8681
Hai Shalom60840252021-02-19 19:02:11 -08008682 pos = os_strstr(cmd, "nested=");
8683 if (pos)
8684 nested_attr_flag = atoi(pos + 7) ? NESTED_ATTR_USED :
8685 NESTED_ATTR_NOT_USED;
8686
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008687 reply = wpabuf_alloc((buflen - 1) / 2);
8688 if (!reply) {
8689 os_free(data);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008690 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008691 }
8692
8693 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
Hai Shalom60840252021-02-19 19:02:11 -08008694 nested_attr_flag, reply);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008695
8696 if (ret == 0)
8697 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
8698 wpabuf_len(reply));
8699
8700 wpabuf_free(reply);
8701 os_free(data);
8702
8703 return ret;
8704}
8705
8706
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008707static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
8708{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008709#ifdef CONFIG_P2P
8710 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
8711 wpa_s->global->p2p_init_wpa_s : wpa_s;
8712#endif /* CONFIG_P2P */
8713
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008714 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
8715
Dmitry Shmidt29333592017-01-09 12:27:11 -08008716 if (wpas_abort_ongoing_scan(wpa_s) == 0)
8717 wpa_s->ignore_post_flush_scan_res = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008718
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008719 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
8720 /*
8721 * Avoid possible auto connect re-connection on getting
8722 * disconnected due to state flush.
8723 */
8724 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
8725 }
8726
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008727#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008728 wpas_p2p_group_remove(p2p_wpa_s, "*");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008729 wpas_p2p_cancel(p2p_wpa_s);
8730 p2p_ctrl_flush(p2p_wpa_s);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008731 wpas_p2p_service_flush(p2p_wpa_s);
8732 p2p_wpa_s->global->p2p_disabled = 0;
8733 p2p_wpa_s->global->p2p_per_sta_psk = 0;
8734 p2p_wpa_s->conf->num_sec_device_types = 0;
8735 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
8736 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
8737 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008738 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08008739 p2p_wpa_s->global->pending_p2ps_group = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008740 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008741#endif /* CONFIG_P2P */
8742
8743#ifdef CONFIG_WPS_TESTING
8744 wps_version_number = 0x20;
Hai Shaloma20dcd72022-02-04 13:43:00 -08008745 wps_testing_stub_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08008746 wps_corrupt_pkhash = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008747 wps_force_auth_types_in_use = 0;
8748 wps_force_encr_types_in_use = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008749#endif /* CONFIG_WPS_TESTING */
8750#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008751 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008752 wpas_wps_cancel(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008753 wps_registrar_flush(wpa_s->wps->registrar);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008754#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07008755 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008756 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008757
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008758#ifdef CONFIG_DPP
8759 wpas_dpp_deinit(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07008760 wpa_s->dpp_init_max_tries = 0;
8761 wpa_s->dpp_init_retry_time = 0;
8762 wpa_s->dpp_resp_wait_time = 0;
8763 wpa_s->dpp_resp_max_tries = 0;
8764 wpa_s->dpp_resp_retry_time = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008765#ifdef CONFIG_DPP2
8766 wpas_dpp_chirp_stop(wpa_s);
8767 wpa_s->dpp_pfs_fallback = 0;
8768#endif /* CONFIG_DPP2 */
Sunil Ravi89eba102022-09-13 21:04:37 -07008769#ifdef CONFIG_DPP3
8770 {
8771 int i;
8772
8773 for (i = 0; i < DPP_PB_INFO_COUNT; i++) {
8774 struct dpp_pb_info *info;
8775
8776 info = &wpa_s->dpp_pb[i];
8777 info->rx_time.sec = 0;
8778 info->rx_time.usec = 0;
8779 }
8780 }
8781#endif /* CONFIG_DPP3 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008782#ifdef CONFIG_TESTING_OPTIONS
8783 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
8784 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
8785 dpp_pkex_ephemeral_key_override_len = 0;
8786 dpp_protocol_key_override_len = 0;
8787 dpp_nonce_override_len = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08008788#ifdef CONFIG_DPP3
8789 dpp_version_override = 3;
8790#elif defined(CONFIG_DPP2)
Hai Shalom4fbc08f2020-05-18 12:37:00 -07008791 dpp_version_override = 2;
8792#else /* CONFIG_DPP2 */
8793 dpp_version_override = 1;
8794#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008795#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008796#endif /* CONFIG_DPP */
8797
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008798#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008799#ifdef CONFIG_TDLS_TESTING
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008800 tdls_testing = 0;
8801#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008802 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
8803 wpa_tdls_enable(wpa_s->wpa, 1);
8804#endif /* CONFIG_TDLS */
8805
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008806 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
8807 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07008808 wpa_s->last_michael_mic_error.sec = 0;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008809
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008810 wpa_s->no_keep_alive = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08008811 wpa_s->own_disconnect_req = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008812 wpa_s->own_reconnect_req = 0;
8813 wpa_s->deny_ptk0_rekey = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008814
8815 os_free(wpa_s->disallow_aps_bssid);
8816 wpa_s->disallow_aps_bssid = NULL;
8817 wpa_s->disallow_aps_bssid_count = 0;
8818 os_free(wpa_s->disallow_aps_ssid);
8819 wpa_s->disallow_aps_ssid = NULL;
8820 wpa_s->disallow_aps_ssid_count = 0;
8821
8822 wpa_s->set_sta_uapsd = 0;
8823 wpa_s->sta_uapsd = 0;
8824
Hai Shalom899fcc72020-10-19 14:38:18 -07008825 wpa_s->consecutive_conn_failures = 0;
8826
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008827 wpa_drv_radio_disable(wpa_s, 0);
Hai Shalom60840252021-02-19 19:02:11 -08008828 wpa_bssid_ignore_clear(wpa_s);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008829 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
8830 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08008831 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08008832 wpa_s->conf->auto_interworking = 0;
8833 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008834
Hai Shalom60840252021-02-19 19:02:11 -08008835 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008836 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
8837 rsn_preauth_deinit(wpa_s->wpa);
8838
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008839 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
8840 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
8841 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
Hai Shalome21d4e82020-04-29 16:34:06 -07008842 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008843
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008844 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008845 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008846
8847 wpa_s->next_ssid = NULL;
8848
8849#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008850#ifdef CONFIG_HS20
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008851 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008852 hs20_del_icon(wpa_s, NULL, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008853#endif /* CONFIG_HS20 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008854#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008855
8856 wpa_s->ext_mgmt_frame_handling = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008857 wpa_s->ext_eapol_frame_io = 0;
8858#ifdef CONFIG_TESTING_OPTIONS
8859 wpa_s->extra_roc_dur = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008860 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008861 wpa_s->p2p_go_csa_on_inv = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008862 wpa_s->ignore_auth_resp = 0;
8863 wpa_s->ignore_assoc_disallow = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008864 wpa_s->disable_sa_query = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008865 wpa_s->testing_resend_assoc = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008866 wpa_s->ignore_sae_h2e_only = 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07008867 wpa_s->ft_rsnxe_used = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008868 wpa_s->reject_btm_req_reason = 0;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008869 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008870 os_free(wpa_s->get_pref_freq_list_override);
8871 wpa_s->get_pref_freq_list_override = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008872 wpabuf_free(wpa_s->sae_commit_override);
8873 wpa_s->sae_commit_override = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008874 os_free(wpa_s->extra_sae_rejected_groups);
8875 wpa_s->extra_sae_rejected_groups = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008876 wpabuf_free(wpa_s->rsne_override_eapol);
8877 wpa_s->rsne_override_eapol = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008878 wpabuf_free(wpa_s->rsnxe_override_assoc);
8879 wpa_s->rsnxe_override_assoc = NULL;
8880 wpabuf_free(wpa_s->rsnxe_override_eapol);
8881 wpa_s->rsnxe_override_eapol = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008882 wpas_clear_driver_signal_override(wpa_s);
Hai Shaloma20dcd72022-02-04 13:43:00 -08008883 wpa_s->disable_scs_support = 0;
8884 wpa_s->disable_mscs_support = 0;
8885 wpa_s->enable_dscp_policy_capa = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07008886 wpa_s->oci_freq_override_eapol = 0;
8887 wpa_s->oci_freq_override_saquery_req = 0;
8888 wpa_s->oci_freq_override_saquery_resp = 0;
8889 wpa_s->oci_freq_override_eapol_g2 = 0;
8890 wpa_s->oci_freq_override_ft_assoc = 0;
8891 wpa_s->oci_freq_override_fils_assoc = 0;
8892 wpa_s->oci_freq_override_wnm_sleep = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -07008893 wpa_s->disable_eapol_g2_tx = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008894#ifdef CONFIG_DPP
8895 os_free(wpa_s->dpp_config_obj_override);
8896 wpa_s->dpp_config_obj_override = NULL;
8897 os_free(wpa_s->dpp_discovery_override);
8898 wpa_s->dpp_discovery_override = NULL;
8899 os_free(wpa_s->dpp_groups_override);
8900 wpa_s->dpp_groups_override = NULL;
Sunil8cd6f4d2022-06-28 18:40:46 +00008901 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
8902 wpa_s->dpp_discard_public_action = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008903 dpp_test = DPP_TEST_DISABLED;
8904#endif /* CONFIG_DPP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008905#endif /* CONFIG_TESTING_OPTIONS */
8906
8907 wpa_s->disconnected = 0;
8908 os_free(wpa_s->next_scan_freqs);
8909 wpa_s->next_scan_freqs = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008910 os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN);
8911 wpa_s->next_scan_bssid_wildcard_ssid = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008912 os_free(wpa_s->select_network_scan_freqs);
8913 wpa_s->select_network_scan_freqs = NULL;
Hai Shalom899fcc72020-10-19 14:38:18 -07008914 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008915
8916 wpa_bss_flush(wpa_s);
8917 if (!dl_list_empty(&wpa_s->bss)) {
8918 wpa_printf(MSG_DEBUG,
8919 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8920 MACSTR " pending_bssid=" MACSTR,
8921 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
8922 MAC2STR(wpa_s->bssid),
8923 MAC2STR(wpa_s->pending_bssid));
8924 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008925
8926 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -08008927 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008928
8929#ifdef CONFIG_SME
8930 wpa_s->sme.last_unprot_disconnect.sec = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008931 wpa_s->sme.auth_alg = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008932#endif /* CONFIG_SME */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008933
8934 wpabuf_free(wpa_s->ric_ies);
8935 wpa_s->ric_ies = NULL;
Hai Shalom74f70d42019-02-11 14:42:39 -08008936
8937 wpa_supplicant_update_channel_list(wpa_s, NULL);
8938
8939 free_bss_tmp_disallowed(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -07008940
8941 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Hai Shalom60840252021-02-19 19:02:11 -08008942
8943#ifdef CONFIG_PASN
8944 wpas_pasn_auth_stop(wpa_s);
8945#endif /* CONFIG_PASN */
8946
8947 if (wpa_s->mac_addr_changed && wpa_s->conf->mac_addr == 0)
8948 wpas_restore_permanent_mac_addr(wpa_s);
Sunil Ravia04bd252022-05-02 22:54:18 -07008949
8950 wpa_s->conf->ignore_old_scan_res = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008951}
8952
8953
8954static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
8955 char *buf, size_t buflen)
8956{
8957 struct wpa_radio_work *work;
8958 char *pos, *end;
8959 struct os_reltime now, diff;
8960
8961 pos = buf;
8962 end = buf + buflen;
8963
8964 os_get_reltime(&now);
8965
8966 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8967 {
8968 int ret;
8969
8970 os_reltime_sub(&now, &work->time, &diff);
8971 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
8972 work->type, work->wpa_s->ifname, work->freq,
8973 work->started, diff.sec, diff.usec);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008974 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008975 break;
8976 pos += ret;
8977 }
8978
8979 return pos - buf;
8980}
8981
8982
8983static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
8984{
8985 struct wpa_radio_work *work = eloop_ctx;
8986 struct wpa_external_work *ework = work->ctx;
8987
8988 wpa_dbg(work->wpa_s, MSG_DEBUG,
8989 "Timing out external radio work %u (%s)",
8990 ework->id, work->type);
8991 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008992 work->wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008993 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008994 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008995}
8996
8997
8998static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
8999{
9000 struct wpa_external_work *ework = work->ctx;
9001
9002 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08009003 if (work->started)
9004 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
9005 work, NULL);
9006
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009007 /*
9008 * work->type points to a buffer in ework, so need to replace
9009 * that here with a fixed string to avoid use of freed memory
9010 * in debug prints.
9011 */
9012 work->type = "freed-ext-work";
9013 work->ctx = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009014 os_free(ework);
9015 return;
9016 }
9017
9018 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
9019 ework->id, ework->type);
9020 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009021 work->wpa_s->ext_work_in_progress = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009022 if (!ework->timeout)
9023 ework->timeout = 10;
9024 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
9025 work, NULL);
9026}
9027
9028
9029static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
9030 char *buf, size_t buflen)
9031{
9032 struct wpa_external_work *ework;
9033 char *pos, *pos2;
9034 size_t type_len;
9035 int ret;
9036 unsigned int freq = 0;
9037
9038 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
9039
9040 ework = os_zalloc(sizeof(*ework));
9041 if (ework == NULL)
9042 return -1;
9043
9044 pos = os_strchr(cmd, ' ');
9045 if (pos) {
9046 type_len = pos - cmd;
9047 pos++;
9048
9049 pos2 = os_strstr(pos, "freq=");
9050 if (pos2)
9051 freq = atoi(pos2 + 5);
9052
9053 pos2 = os_strstr(pos, "timeout=");
9054 if (pos2)
9055 ework->timeout = atoi(pos2 + 8);
9056 } else {
9057 type_len = os_strlen(cmd);
9058 }
9059 if (4 + type_len >= sizeof(ework->type))
9060 type_len = sizeof(ework->type) - 4 - 1;
9061 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
9062 os_memcpy(ework->type + 4, cmd, type_len);
9063 ework->type[4 + type_len] = '\0';
9064
9065 wpa_s->ext_work_id++;
9066 if (wpa_s->ext_work_id == 0)
9067 wpa_s->ext_work_id++;
9068 ework->id = wpa_s->ext_work_id;
9069
9070 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
9071 ework) < 0) {
9072 os_free(ework);
9073 return -1;
9074 }
9075
9076 ret = os_snprintf(buf, buflen, "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009077 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009078 return -1;
9079 return ret;
9080}
9081
9082
9083static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
9084{
9085 struct wpa_radio_work *work;
9086 unsigned int id = atoi(cmd);
9087
9088 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
9089 {
9090 struct wpa_external_work *ework;
9091
9092 if (os_strncmp(work->type, "ext:", 4) != 0)
9093 continue;
9094 ework = work->ctx;
9095 if (id && ework->id != id)
9096 continue;
9097 wpa_dbg(wpa_s, MSG_DEBUG,
9098 "Completed external radio work %u (%s)",
9099 ework->id, ework->type);
9100 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009101 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009102 radio_work_done(work);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07009103 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009104 return 3; /* "OK\n" */
9105 }
9106
9107 return -1;
9108}
9109
9110
9111static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
9112 char *buf, size_t buflen)
9113{
9114 if (os_strcmp(cmd, "show") == 0)
9115 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
9116 if (os_strncmp(cmd, "add ", 4) == 0)
9117 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
9118 if (os_strncmp(cmd, "done ", 5) == 0)
9119 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
9120 return -1;
9121}
9122
9123
9124void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
9125{
9126 struct wpa_radio_work *work, *tmp;
9127
Dmitry Shmidt18463232014-01-24 12:29:41 -08009128 if (!wpa_s || !wpa_s->radio)
9129 return;
9130
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009131 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
9132 struct wpa_radio_work, list) {
9133 struct wpa_external_work *ework;
9134
9135 if (os_strncmp(work->type, "ext:", 4) != 0)
9136 continue;
9137 ework = work->ctx;
9138 wpa_dbg(wpa_s, MSG_DEBUG,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07009139 "Flushing%s external radio work %u (%s)",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009140 work->started ? " started" : "", ework->id,
9141 ework->type);
9142 if (work->started)
9143 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
9144 work, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009145 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07009146 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009147 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07009148}
9149
9150
Dmitry Shmidt051af732013-10-22 13:52:46 -07009151static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
9152{
9153 struct wpa_supplicant *wpa_s = eloop_ctx;
9154 eapol_sm_notify_ctrl_response(wpa_s->eapol);
9155}
9156
9157
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009158static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
9159 unsigned int *scan_id_count, int scan_id[])
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009160{
9161 const char *pos = value;
9162
9163 while (pos) {
9164 if (*pos == ' ' || *pos == '\0')
9165 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009166 if (*scan_id_count == MAX_SCAN_ID)
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009167 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009168 scan_id[(*scan_id_count)++] = atoi(pos);
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009169 pos = os_strchr(pos, ',');
9170 if (pos)
9171 pos++;
9172 }
9173
9174 return 0;
9175}
9176
9177
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009178static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
9179 char *reply, int reply_size, int *reply_len)
9180{
9181 char *pos;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009182 unsigned int manual_scan_passive = 0;
9183 unsigned int manual_scan_use_id = 0;
9184 unsigned int manual_scan_only_new = 0;
9185 unsigned int scan_only = 0;
9186 unsigned int scan_id_count = 0;
Sunil8cd6f4d2022-06-28 18:40:46 +00009187 unsigned int manual_non_coloc_6ghz = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009188 int scan_id[MAX_SCAN_ID];
9189 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
9190 struct wpa_scan_results *scan_res);
9191 int *manual_scan_freqs = NULL;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009192 struct wpa_ssid_value *ssid = NULL, *ns;
9193 unsigned int ssid_count = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009194
9195 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
9196 *reply_len = -1;
9197 return;
9198 }
9199
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009200 if (radio_work_pending(wpa_s, "scan")) {
9201 wpa_printf(MSG_DEBUG,
9202 "Pending scan scheduled - reject new request");
9203 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9204 return;
9205 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009206
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07009207#ifdef CONFIG_INTERWORKING
9208 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
9209 wpa_printf(MSG_DEBUG,
9210 "Interworking select in progress - reject new scan");
9211 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9212 return;
9213 }
9214#endif /* CONFIG_INTERWORKING */
9215
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009216 if (params) {
9217 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009218 scan_only = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009219
9220 pos = os_strstr(params, "freq=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009221 if (pos) {
9222 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
9223 pos + 5);
9224 if (manual_scan_freqs == NULL) {
9225 *reply_len = -1;
9226 goto done;
9227 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009228 }
9229
9230 pos = os_strstr(params, "passive=");
9231 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009232 manual_scan_passive = !!atoi(pos + 8);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009233
9234 pos = os_strstr(params, "use_id=");
9235 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009236 manual_scan_use_id = atoi(pos + 7);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009237
9238 pos = os_strstr(params, "only_new=1");
9239 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009240 manual_scan_only_new = 1;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009241
9242 pos = os_strstr(params, "scan_id=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009243 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
9244 scan_id) < 0) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009245 *reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009246 goto done;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009247 }
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009248
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009249 pos = os_strstr(params, "bssid=");
9250 if (pos) {
9251 u8 bssid[ETH_ALEN];
9252
9253 pos += 6;
9254 if (hwaddr_aton(pos, bssid)) {
9255 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
9256 *reply_len = -1;
9257 goto done;
9258 }
9259 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
Hai Shalomfdcde762020-04-02 11:19:20 -07009260
9261 wpa_s->next_scan_bssid_wildcard_ssid =
9262 os_strstr(params, "wildcard_ssid=1") != NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009263 }
9264
Sunil8cd6f4d2022-06-28 18:40:46 +00009265 pos = os_strstr(params, "non_coloc_6ghz=");
9266 if (pos)
9267 manual_non_coloc_6ghz = !!atoi(pos + 15);
9268
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009269 pos = params;
9270 while (pos && *pos != '\0') {
9271 if (os_strncmp(pos, "ssid ", 5) == 0) {
9272 char *end;
9273
9274 pos += 5;
9275 end = pos;
9276 while (*end) {
9277 if (*end == '\0' || *end == ' ')
9278 break;
9279 end++;
9280 }
9281
9282 ns = os_realloc_array(
9283 ssid, ssid_count + 1,
9284 sizeof(struct wpa_ssid_value));
9285 if (ns == NULL) {
9286 *reply_len = -1;
9287 goto done;
9288 }
9289 ssid = ns;
9290
9291 if ((end - pos) & 0x01 ||
9292 end - pos > 2 * SSID_MAX_LEN ||
9293 hexstr2bin(pos, ssid[ssid_count].ssid,
9294 (end - pos) / 2) < 0) {
9295 wpa_printf(MSG_DEBUG,
9296 "Invalid SSID value '%s'",
9297 pos);
9298 *reply_len = -1;
9299 goto done;
9300 }
9301 ssid[ssid_count].ssid_len = (end - pos) / 2;
9302 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
9303 ssid[ssid_count].ssid,
9304 ssid[ssid_count].ssid_len);
9305 ssid_count++;
9306 pos = end;
9307 }
9308
9309 pos = os_strchr(pos, ' ');
9310 if (pos)
9311 pos++;
9312 }
9313 }
9314
9315 wpa_s->num_ssids_from_scan_req = ssid_count;
9316 os_free(wpa_s->ssids_from_scan_req);
9317 if (ssid_count) {
9318 wpa_s->ssids_from_scan_req = ssid;
9319 ssid = NULL;
9320 } else {
9321 wpa_s->ssids_from_scan_req = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009322 }
9323
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009324 if (scan_only)
9325 scan_res_handler = scan_only_handler;
9326 else if (wpa_s->scan_res_handler == scan_only_handler)
9327 scan_res_handler = NULL;
9328 else
9329 scan_res_handler = wpa_s->scan_res_handler;
9330
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009331 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
9332 ((wpa_s->wpa_state <= WPA_SCANNING) ||
9333 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009334 wpa_s->manual_scan_passive = manual_scan_passive;
9335 wpa_s->manual_scan_use_id = manual_scan_use_id;
9336 wpa_s->manual_scan_only_new = manual_scan_only_new;
9337 wpa_s->scan_id_count = scan_id_count;
Sunil8cd6f4d2022-06-28 18:40:46 +00009338 wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009339 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9340 wpa_s->scan_res_handler = scan_res_handler;
9341 os_free(wpa_s->manual_scan_freqs);
9342 wpa_s->manual_scan_freqs = manual_scan_freqs;
9343 manual_scan_freqs = NULL;
9344
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009345 wpa_s->normal_scans = 0;
9346 wpa_s->scan_req = MANUAL_SCAN_REQ;
9347 wpa_s->after_wps = 0;
9348 wpa_s->known_wps_freq = 0;
9349 wpa_supplicant_req_scan(wpa_s, 0, 0);
9350 if (wpa_s->manual_scan_use_id) {
9351 wpa_s->manual_scan_id++;
9352 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9353 wpa_s->manual_scan_id);
9354 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9355 wpa_s->manual_scan_id);
9356 }
9357 } else if (wpa_s->sched_scanning) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009358 wpa_s->manual_scan_passive = manual_scan_passive;
9359 wpa_s->manual_scan_use_id = manual_scan_use_id;
9360 wpa_s->manual_scan_only_new = manual_scan_only_new;
9361 wpa_s->scan_id_count = scan_id_count;
Sunil8cd6f4d2022-06-28 18:40:46 +00009362 wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009363 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9364 wpa_s->scan_res_handler = scan_res_handler;
9365 os_free(wpa_s->manual_scan_freqs);
9366 wpa_s->manual_scan_freqs = manual_scan_freqs;
9367 manual_scan_freqs = NULL;
9368
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009369 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
9370 wpa_supplicant_cancel_sched_scan(wpa_s);
9371 wpa_s->scan_req = MANUAL_SCAN_REQ;
9372 wpa_supplicant_req_scan(wpa_s, 0, 0);
9373 if (wpa_s->manual_scan_use_id) {
9374 wpa_s->manual_scan_id++;
9375 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9376 wpa_s->manual_scan_id);
9377 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9378 wpa_s->manual_scan_id);
9379 }
9380 } else {
9381 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
9382 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9383 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009384
9385done:
9386 os_free(manual_scan_freqs);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009387 os_free(ssid);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009388}
9389
9390
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009391#ifdef CONFIG_TESTING_OPTIONS
9392
9393static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
9394 unsigned int freq, const u8 *dst,
9395 const u8 *src, const u8 *bssid,
9396 const u8 *data, size_t data_len,
9397 enum offchannel_send_action_result
9398 result)
9399{
9400 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
9401 " src=" MACSTR " bssid=" MACSTR " result=%s",
9402 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
9403 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
9404 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
9405 "NO_ACK" : "FAILED"));
9406}
9407
9408
9409static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
9410{
9411 char *pos, *param;
9412 size_t len;
9413 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
9414 int res, used;
9415 int freq = 0, no_cck = 0, wait_time = 0;
9416
9417 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
9418 * <action=Action frame payload> */
9419
9420 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
9421
9422 pos = cmd;
9423 used = hwaddr_aton2(pos, da);
9424 if (used < 0)
9425 return -1;
9426 pos += used;
9427 while (*pos == ' ')
9428 pos++;
9429 used = hwaddr_aton2(pos, bssid);
9430 if (used < 0)
9431 return -1;
9432 pos += used;
9433
9434 param = os_strstr(pos, " freq=");
9435 if (param) {
9436 param += 6;
9437 freq = atoi(param);
9438 }
9439
9440 param = os_strstr(pos, " no_cck=");
9441 if (param) {
9442 param += 8;
9443 no_cck = atoi(param);
9444 }
9445
9446 param = os_strstr(pos, " wait_time=");
9447 if (param) {
9448 param += 11;
9449 wait_time = atoi(param);
9450 }
9451
9452 param = os_strstr(pos, " action=");
9453 if (param == NULL)
9454 return -1;
9455 param += 8;
9456
9457 len = os_strlen(param);
9458 if (len & 1)
9459 return -1;
9460 len /= 2;
9461
9462 buf = os_malloc(len);
9463 if (buf == NULL)
9464 return -1;
9465
9466 if (hexstr2bin(param, buf, len) < 0) {
9467 os_free(buf);
9468 return -1;
9469 }
9470
9471 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
9472 buf, len, wait_time,
9473 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
9474 os_free(buf);
9475 return res;
9476}
9477
9478
9479static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
9480{
9481 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
9482 offchannel_send_action_done(wpa_s);
9483}
9484
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009485
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009486static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
9487 char *cmd)
9488{
9489 char *pos, *param;
9490 size_t len;
9491 u8 *buf;
9492 int freq = 0, datarate = 0, ssi_signal = 0;
9493 union wpa_event_data event;
9494
9495 if (!wpa_s->ext_mgmt_frame_handling)
9496 return -1;
9497
9498 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
9499
9500 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
9501
9502 pos = cmd;
9503 param = os_strstr(pos, "freq=");
9504 if (param) {
9505 param += 5;
9506 freq = atoi(param);
9507 }
9508
9509 param = os_strstr(pos, " datarate=");
9510 if (param) {
9511 param += 10;
9512 datarate = atoi(param);
9513 }
9514
9515 param = os_strstr(pos, " ssi_signal=");
9516 if (param) {
9517 param += 12;
9518 ssi_signal = atoi(param);
9519 }
9520
9521 param = os_strstr(pos, " frame=");
9522 if (param == NULL)
9523 return -1;
9524 param += 7;
9525
9526 len = os_strlen(param);
9527 if (len & 1)
9528 return -1;
9529 len /= 2;
9530
9531 buf = os_malloc(len);
9532 if (buf == NULL)
9533 return -1;
9534
9535 if (hexstr2bin(param, buf, len) < 0) {
9536 os_free(buf);
9537 return -1;
9538 }
9539
9540 os_memset(&event, 0, sizeof(event));
9541 event.rx_mgmt.freq = freq;
9542 event.rx_mgmt.frame = buf;
9543 event.rx_mgmt.frame_len = len;
9544 event.rx_mgmt.ssi_signal = ssi_signal;
9545 event.rx_mgmt.datarate = datarate;
9546 wpa_s->ext_mgmt_frame_handling = 0;
9547 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
9548 wpa_s->ext_mgmt_frame_handling = 1;
9549
9550 os_free(buf);
9551
9552 return 0;
9553}
9554
9555
Paul Stewart092955c2017-02-06 09:13:09 -08009556static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
9557 char *param)
9558{
9559 struct wpa_scan_res *res;
9560 struct os_reltime now;
9561 char *pos, *end;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009562 int ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08009563
9564 if (!param)
9565 return -1;
9566
9567 if (os_strcmp(param, "START") == 0) {
9568 wpa_bss_update_start(wpa_s);
9569 return 0;
9570 }
9571
9572 if (os_strcmp(param, "END") == 0) {
9573 wpa_bss_update_end(wpa_s, NULL, 1);
9574 return 0;
9575 }
9576
9577 if (os_strncmp(param, "BSS ", 4) != 0)
9578 return -1;
9579 param += 3;
9580
9581 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
9582 if (!res)
9583 return -1;
9584
9585 pos = os_strstr(param, " flags=");
9586 if (pos)
9587 res->flags = strtol(pos + 7, NULL, 16);
9588
9589 pos = os_strstr(param, " bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009590 if (pos && hwaddr_aton(pos + 7, res->bssid))
9591 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009592
9593 pos = os_strstr(param, " freq=");
9594 if (pos)
9595 res->freq = atoi(pos + 6);
9596
9597 pos = os_strstr(param, " beacon_int=");
9598 if (pos)
9599 res->beacon_int = atoi(pos + 12);
9600
9601 pos = os_strstr(param, " caps=");
9602 if (pos)
9603 res->caps = strtol(pos + 6, NULL, 16);
9604
9605 pos = os_strstr(param, " qual=");
9606 if (pos)
9607 res->qual = atoi(pos + 6);
9608
9609 pos = os_strstr(param, " noise=");
9610 if (pos)
9611 res->noise = atoi(pos + 7);
9612
9613 pos = os_strstr(param, " level=");
9614 if (pos)
9615 res->level = atoi(pos + 7);
9616
9617 pos = os_strstr(param, " tsf=");
9618 if (pos)
9619 res->tsf = strtoll(pos + 5, NULL, 16);
9620
9621 pos = os_strstr(param, " age=");
9622 if (pos)
9623 res->age = atoi(pos + 5);
9624
9625 pos = os_strstr(param, " est_throughput=");
9626 if (pos)
9627 res->est_throughput = atoi(pos + 16);
9628
9629 pos = os_strstr(param, " snr=");
9630 if (pos)
9631 res->snr = atoi(pos + 5);
9632
9633 pos = os_strstr(param, " parent_tsf=");
9634 if (pos)
9635 res->parent_tsf = strtoll(pos + 7, NULL, 16);
9636
9637 pos = os_strstr(param, " tsf_bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009638 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
9639 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009640
9641 pos = os_strstr(param, " ie=");
9642 if (pos) {
9643 pos += 4;
9644 end = os_strchr(pos, ' ');
9645 if (!end)
9646 end = pos + os_strlen(pos);
9647 res->ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009648 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
9649 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009650 }
9651
9652 pos = os_strstr(param, " beacon_ie=");
9653 if (pos) {
9654 pos += 11;
9655 end = os_strchr(pos, ' ');
9656 if (!end)
9657 end = pos + os_strlen(pos);
9658 res->beacon_ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009659 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
9660 res->beacon_ie_len))
9661 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009662 }
9663
9664 os_get_reltime(&now);
9665 wpa_bss_update_scan_res(wpa_s, res, &now);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009666 ret = 0;
9667fail:
Paul Stewart092955c2017-02-06 09:13:09 -08009668 os_free(res);
9669
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009670 return ret;
Paul Stewart092955c2017-02-06 09:13:09 -08009671}
9672
9673
Hai Shaloma20dcd72022-02-04 13:43:00 -08009674static int wpas_ctrl_iface_driver_event_assoc(struct wpa_supplicant *wpa_s,
9675 char *param)
9676{
9677 union wpa_event_data event;
9678 struct assoc_info *ai;
9679 char *ctx = NULL;
9680 int ret = -1;
9681 struct wpabuf *req_ies = NULL;
9682 struct wpabuf *resp_ies = NULL;
9683 struct wpabuf *resp_frame = NULL;
9684 struct wpabuf *beacon_ies = NULL;
9685 struct wpabuf *key_replay_ctr = NULL;
9686 struct wpabuf *ptk_kck = NULL;
9687 struct wpabuf *ptk_kek = NULL;
9688 struct wpabuf *fils_pmk = NULL;
9689 char *str, *pos;
9690 u8 addr[ETH_ALEN];
9691 u8 fils_pmkid[PMKID_LEN];
9692
9693 os_memset(&event, 0, sizeof(event));
9694 ai = &event.assoc_info;
9695
9696 while ((str = str_token(param, " ", &ctx))) {
9697 pos = os_strchr(str, '=');
9698 if (!pos)
9699 goto fail;
9700 *pos++ = '\0';
9701
9702 if (os_strcmp(str, "reassoc") == 0) {
9703 ai->reassoc = atoi(pos);
9704 } else if (os_strcmp(str, "req_ies") == 0) {
9705 wpabuf_free(req_ies);
9706 req_ies = wpabuf_parse_bin(pos);
9707 if (!req_ies)
9708 goto fail;
9709 ai->req_ies = wpabuf_head(req_ies);
9710 ai->req_ies_len = wpabuf_len(req_ies);
9711 } else if (os_strcmp(str, "resp_ies") == 0) {
9712 wpabuf_free(resp_ies);
9713 resp_ies = wpabuf_parse_bin(pos);
9714 if (!resp_ies)
9715 goto fail;
9716 ai->resp_ies = wpabuf_head(resp_ies);
9717 ai->resp_ies_len = wpabuf_len(resp_ies);
9718 } else if (os_strcmp(str, "resp_frame") == 0) {
9719 wpabuf_free(resp_frame);
9720 resp_frame = wpabuf_parse_bin(pos);
9721 if (!resp_frame)
9722 goto fail;
9723 ai->resp_frame = wpabuf_head(resp_frame);
9724 ai->resp_frame_len = wpabuf_len(resp_frame);
9725 } else if (os_strcmp(str, "beacon_ies") == 0) {
9726 wpabuf_free(beacon_ies);
9727 beacon_ies = wpabuf_parse_bin(pos);
9728 if (!beacon_ies)
9729 goto fail;
9730 ai->beacon_ies = wpabuf_head(beacon_ies);
9731 ai->beacon_ies_len = wpabuf_len(beacon_ies);
9732 } else if (os_strcmp(str, "freq") == 0) {
9733 ai->freq = atoi(pos);
9734 } else if (os_strcmp(str, "wmm::info_bitmap") == 0) {
9735 ai->wmm_params.info_bitmap = atoi(pos);
9736 } else if (os_strcmp(str, "wmm::uapsd_queues") == 0) {
9737 ai->wmm_params.uapsd_queues = atoi(pos);
9738 } else if (os_strcmp(str, "addr") == 0) {
9739 if (hwaddr_aton(pos, addr))
9740 goto fail;
9741 ai->addr = addr;
9742 } else if (os_strcmp(str, "authorized") == 0) {
9743 ai->authorized = atoi(pos);
9744 } else if (os_strcmp(str, "key_replay_ctr") == 0) {
9745 wpabuf_free(key_replay_ctr);
9746 key_replay_ctr = wpabuf_parse_bin(pos);
9747 if (!key_replay_ctr)
9748 goto fail;
9749 ai->key_replay_ctr = wpabuf_head(key_replay_ctr);
9750 ai->key_replay_ctr_len = wpabuf_len(key_replay_ctr);
9751 } else if (os_strcmp(str, "ptk_kck") == 0) {
9752 wpabuf_free(ptk_kck);
9753 ptk_kck = wpabuf_parse_bin(pos);
9754 if (!ptk_kck)
9755 goto fail;
9756 ai->ptk_kck = wpabuf_head(ptk_kck);
9757 ai->ptk_kck_len = wpabuf_len(ptk_kck);
9758 } else if (os_strcmp(str, "ptk_kek") == 0) {
9759 wpabuf_free(ptk_kek);
9760 ptk_kek = wpabuf_parse_bin(pos);
9761 if (!ptk_kek)
9762 goto fail;
9763 ai->ptk_kek = wpabuf_head(ptk_kek);
9764 ai->ptk_kek_len = wpabuf_len(ptk_kek);
9765 } else if (os_strcmp(str, "subnet_status") == 0) {
9766 ai->subnet_status = atoi(pos);
9767 } else if (os_strcmp(str, "fils_erp_next_seq_num") == 0) {
9768 ai->fils_erp_next_seq_num = atoi(pos);
9769 } else if (os_strcmp(str, "fils_pmk") == 0) {
9770 wpabuf_free(fils_pmk);
9771 fils_pmk = wpabuf_parse_bin(pos);
9772 if (!fils_pmk)
9773 goto fail;
9774 ai->fils_pmk = wpabuf_head(fils_pmk);
9775 ai->fils_pmk_len = wpabuf_len(fils_pmk);
9776 } else if (os_strcmp(str, "fils_pmkid") == 0) {
9777 if (hexstr2bin(pos, fils_pmkid, PMKID_LEN) < 0)
9778 goto fail;
9779 ai->fils_pmkid = fils_pmkid;
9780 } else {
9781 goto fail;
9782 }
9783 }
9784
9785 wpa_supplicant_event(wpa_s, EVENT_ASSOC, &event);
9786 ret = 0;
9787fail:
9788 wpabuf_free(req_ies);
9789 wpabuf_free(resp_ies);
9790 wpabuf_free(resp_frame);
9791 wpabuf_free(beacon_ies);
9792 wpabuf_free(key_replay_ctr);
9793 wpabuf_free(ptk_kck);
9794 wpabuf_free(ptk_kek);
9795 wpabuf_free(fils_pmk);
9796 return ret;
9797}
9798
9799
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009800static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
9801{
9802 char *pos, *param;
9803 union wpa_event_data event;
9804 enum wpa_event_type ev;
9805
9806 /* <event name> [parameters..] */
9807
9808 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
9809
9810 pos = cmd;
9811 param = os_strchr(pos, ' ');
9812 if (param)
9813 *param++ = '\0';
9814
9815 os_memset(&event, 0, sizeof(event));
9816
9817 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
9818 ev = EVENT_INTERFACE_ENABLED;
9819 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
9820 ev = EVENT_INTERFACE_DISABLED;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07009821 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
9822 ev = EVENT_AVOID_FREQUENCIES;
9823 if (param == NULL)
9824 param = "";
9825 if (freq_range_list_parse(&event.freq_range, param) < 0)
9826 return -1;
9827 wpa_supplicant_event(wpa_s, ev, &event);
9828 os_free(event.freq_range.range);
9829 return 0;
Paul Stewart092955c2017-02-06 09:13:09 -08009830 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
9831 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
Hai Shaloma20dcd72022-02-04 13:43:00 -08009832 } else if (os_strcmp(cmd, "ASSOC") == 0) {
9833 return wpas_ctrl_iface_driver_event_assoc(wpa_s, param);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009834 } else {
9835 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
9836 cmd);
9837 return -1;
9838 }
9839
9840 wpa_supplicant_event(wpa_s, ev, &event);
9841
9842 return 0;
9843}
9844
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009845
9846static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
9847{
9848 char *pos;
9849 u8 src[ETH_ALEN], *buf;
9850 int used;
9851 size_t len;
9852
9853 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
9854
9855 pos = cmd;
9856 used = hwaddr_aton2(pos, src);
9857 if (used < 0)
9858 return -1;
9859 pos += used;
9860 while (*pos == ' ')
9861 pos++;
9862
9863 len = os_strlen(pos);
9864 if (len & 1)
9865 return -1;
9866 len /= 2;
9867
9868 buf = os_malloc(len);
9869 if (buf == NULL)
9870 return -1;
9871
9872 if (hexstr2bin(pos, buf, len) < 0) {
9873 os_free(buf);
9874 return -1;
9875 }
9876
Sunil8cd6f4d2022-06-28 18:40:46 +00009877 wpa_supplicant_rx_eapol(wpa_s, src, buf, len, FRAME_ENCRYPTION_UNKNOWN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009878 os_free(buf);
9879
9880 return 0;
9881}
9882
9883
Hai Shaloma20dcd72022-02-04 13:43:00 -08009884static int wpas_ctrl_iface_eapol_tx(struct wpa_supplicant *wpa_s, char *cmd)
9885{
9886 char *pos;
9887 u8 dst[ETH_ALEN], *buf;
9888 int used, ret;
9889 size_t len;
9890 unsigned int prev;
9891
9892 wpa_printf(MSG_DEBUG, "External EAPOL TX: %s", cmd);
9893
9894 pos = cmd;
9895 used = hwaddr_aton2(pos, dst);
9896 if (used < 0)
9897 return -1;
9898 pos += used;
9899 while (*pos == ' ')
9900 pos++;
9901
9902 len = os_strlen(pos);
9903 if (len & 1)
9904 return -1;
9905 len /= 2;
9906
9907 buf = os_malloc(len);
9908 if (!buf || hexstr2bin(pos, buf, len) < 0) {
9909 os_free(buf);
9910 return -1;
9911 }
9912
9913 prev = wpa_s->ext_eapol_frame_io;
9914 wpa_s->ext_eapol_frame_io = 0;
9915 ret = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, buf, len);
9916 wpa_s->ext_eapol_frame_io = prev;
9917 os_free(buf);
9918
9919 return ret;
9920}
9921
9922
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009923static u16 ipv4_hdr_checksum(const void *buf, size_t len)
9924{
9925 size_t i;
9926 u32 sum = 0;
9927 const u16 *pos = buf;
9928
9929 for (i = 0; i < len / 2; i++)
9930 sum += *pos++;
9931
9932 while (sum >> 16)
9933 sum = (sum & 0xffff) + (sum >> 16);
9934
9935 return sum ^ 0xffff;
9936}
9937
9938
9939#define HWSIM_PACKETLEN 1500
9940#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
9941
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07009942static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
9943 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009944{
9945 struct wpa_supplicant *wpa_s = ctx;
9946 const struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07009947 struct ip ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009948 const u8 *pos;
9949 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08009950 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009951
Hai Shalom74f70d42019-02-11 14:42:39 -08009952 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
9953 wpa_printf(MSG_DEBUG,
9954 "test data: RX - ignore unexpected length %d",
9955 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009956 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08009957 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009958
9959 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009960 os_memcpy(&ip, eth + 1, sizeof(ip));
9961 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009962
Hai Shalomfdcde762020-04-02 11:19:20 -07009963 if (ip.ip_hl != 5 || ip.ip_v != 4 || ntohs(ip.ip_len) > HWSIM_IP_LEN) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009964 wpa_printf(MSG_DEBUG,
Hai Shalom899fcc72020-10-19 14:38:18 -07009965 "test data: RX - ignore unexpected IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009966 return;
Hai Shalom39bc25d2019-02-06 16:32:13 -08009967 }
Hai Shalombf6e0ba2019-02-11 12:01:50 -08009968
Hai Shalomfdcde762020-04-02 11:19:20 -07009969 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009970 if (*pos != (u8) i) {
9971 wpa_printf(MSG_DEBUG,
9972 "test data: RX - ignore mismatching payload");
9973 return;
9974 }
9975 pos++;
9976 }
9977 extra[0] = '\0';
Hai Shalomfdcde762020-04-02 11:19:20 -07009978 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
9979 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
Hai Shalom74f70d42019-02-11 14:42:39 -08009980 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
9981 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009982}
9983
9984
9985static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
9986 char *cmd)
9987{
9988 int enabled = atoi(cmd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009989 char *pos;
9990 const char *ifname;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009991
9992 if (!enabled) {
9993 if (wpa_s->l2_test) {
9994 l2_packet_deinit(wpa_s->l2_test);
9995 wpa_s->l2_test = NULL;
9996 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
9997 }
9998 return 0;
9999 }
10000
10001 if (wpa_s->l2_test)
10002 return 0;
10003
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080010004 pos = os_strstr(cmd, " ifname=");
10005 if (pos)
10006 ifname = pos + 8;
10007 else
10008 ifname = wpa_s->ifname;
10009
10010 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010011 ETHERTYPE_IP, wpas_data_test_rx,
10012 wpa_s, 1);
10013 if (wpa_s->l2_test == NULL)
10014 return -1;
10015
10016 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
10017
10018 return 0;
10019}
10020
10021
10022static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
10023{
10024 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom74f70d42019-02-11 14:42:39 -080010025 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010026 int used;
10027 long int val;
10028 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010029 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010030 struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -070010031 struct ip *ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010032 u8 *dpos;
10033 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -080010034 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010035
10036 if (wpa_s->l2_test == NULL)
10037 return -1;
10038
Hai Shalom74f70d42019-02-11 14:42:39 -080010039 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010040
10041 pos = cmd;
10042 used = hwaddr_aton2(pos, dst);
10043 if (used < 0)
10044 return -1;
10045 pos += used;
10046 while (*pos == ' ')
10047 pos++;
10048 used = hwaddr_aton2(pos, src);
10049 if (used < 0)
10050 return -1;
10051 pos += used;
10052
Hai Shalom74f70d42019-02-11 14:42:39 -080010053 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010054 if (val < 0 || val > 0xff)
10055 return -1;
10056 tos = val;
10057
Hai Shalom74f70d42019-02-11 14:42:39 -080010058 pos = os_strstr(pos2, " len=");
10059 if (pos) {
10060 i = atoi(pos + 5);
10061 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
10062 return -1;
10063 send_len = i;
10064 }
10065
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010066 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010067 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
10068 os_memcpy(eth->ether_shost, src, ETH_ALEN);
10069 eth->ether_type = htons(ETHERTYPE_IP);
Hai Shalomfdcde762020-04-02 11:19:20 -070010070 ip = (struct ip *) (eth + 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010071 os_memset(ip, 0, sizeof(*ip));
Hai Shalomfdcde762020-04-02 11:19:20 -070010072 ip->ip_hl = 5;
10073 ip->ip_v = 4;
10074 ip->ip_ttl = 64;
10075 ip->ip_tos = tos;
10076 ip->ip_len = htons(send_len);
10077 ip->ip_p = 1;
10078 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
10079 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
10080 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010081 dpos = (u8 *) (ip + 1);
Hai Shalom74f70d42019-02-11 14:42:39 -080010082 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010083 *dpos++ = i;
10084
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010085 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom74f70d42019-02-11 14:42:39 -080010086 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010087 return -1;
10088
10089 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
10090 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
10091
10092 return 0;
10093}
10094
10095
10096static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
10097 char *cmd)
10098{
10099 u8 *buf;
10100 struct ether_header *eth;
10101 struct l2_packet_data *l2 = NULL;
10102 size_t len;
10103 u16 ethertype;
10104 int res = -1;
10105
10106 len = os_strlen(cmd);
10107 if (len & 1 || len < ETH_HLEN * 2)
10108 return -1;
10109 len /= 2;
10110
10111 buf = os_malloc(len);
10112 if (buf == NULL)
10113 return -1;
10114
10115 if (hexstr2bin(cmd, buf, len) < 0)
10116 goto done;
10117
10118 eth = (struct ether_header *) buf;
10119 ethertype = ntohs(eth->ether_type);
10120
10121 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
10122 wpas_data_test_rx, wpa_s, 1);
10123 if (l2 == NULL)
10124 goto done;
10125
10126 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
10127 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
10128done:
10129 if (l2)
10130 l2_packet_deinit(l2);
10131 os_free(buf);
10132
10133 return res < 0 ? -1 : 0;
10134}
10135
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010136
10137static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
10138{
10139#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010140 char *pos;
10141
10142 wpa_trace_fail_after = atoi(cmd);
10143 pos = os_strchr(cmd, ':');
10144 if (pos) {
10145 pos++;
10146 os_strlcpy(wpa_trace_fail_func, pos,
10147 sizeof(wpa_trace_fail_func));
10148 } else {
10149 wpa_trace_fail_after = 0;
10150 }
10151 return 0;
10152#else /* WPA_TRACE_BFD */
10153 return -1;
10154#endif /* WPA_TRACE_BFD */
10155}
10156
10157
10158static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
10159 char *buf, size_t buflen)
10160{
10161#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010162 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
10163 wpa_trace_fail_func);
10164#else /* WPA_TRACE_BFD */
10165 return -1;
10166#endif /* WPA_TRACE_BFD */
10167}
10168
Jouni Malinenc4818362015-10-04 11:45:13 +030010169
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010170static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
10171{
10172#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010173 char *pos;
10174
10175 wpa_trace_test_fail_after = atoi(cmd);
10176 pos = os_strchr(cmd, ':');
10177 if (pos) {
10178 pos++;
10179 os_strlcpy(wpa_trace_test_fail_func, pos,
10180 sizeof(wpa_trace_test_fail_func));
10181 } else {
10182 wpa_trace_test_fail_after = 0;
10183 }
10184 return 0;
10185#else /* WPA_TRACE_BFD */
10186 return -1;
10187#endif /* WPA_TRACE_BFD */
10188}
10189
10190
10191static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
10192 char *buf, size_t buflen)
10193{
10194#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010195 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
10196 wpa_trace_test_fail_func);
10197#else /* WPA_TRACE_BFD */
10198 return -1;
10199#endif /* WPA_TRACE_BFD */
10200}
10201
10202
Jouni Malinenc4818362015-10-04 11:45:13 +030010203static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
10204{
10205 struct wpa_supplicant *wpa_s = eloop_ctx;
10206 int i, count = (intptr_t) timeout_ctx;
10207
10208 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
10209 count);
10210 for (i = 0; i < count; i++) {
10211 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
10212 i + 1, count);
10213 }
10214}
10215
10216
10217static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
10218{
10219 int count;
10220
10221 count = atoi(cmd);
10222 if (count <= 0)
10223 return -1;
10224
10225 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
10226 (void *) (intptr_t) count);
10227}
10228
Dmitry Shmidt818ea482014-03-10 13:15:21 -070010229
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010230static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
10231 const char *cmd)
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010232{
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010233 struct wpabuf *buf;
10234 size_t len;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010235
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010236 len = os_strlen(cmd);
10237 if (len & 1)
10238 return -1;
10239 len /= 2;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010240
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010241 if (len == 0) {
10242 buf = NULL;
10243 } else {
10244 buf = wpabuf_alloc(len);
10245 if (buf == NULL)
10246 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010247
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010248 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
10249 wpabuf_free(buf);
10250 return -1;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010251 }
10252 }
10253
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010254 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
10255 return 0;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010256}
10257
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010258
10259static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
10260{
10261 u8 zero[WPA_TK_MAX_LEN];
10262
10263 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
10264 return -1;
10265
10266 wpa_printf(MSG_INFO, "TESTING: Reset PN");
10267 os_memset(zero, 0, sizeof(zero));
10268
10269 /* First, use a zero key to avoid any possible duplicate key avoidance
10270 * in the driver. */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000010271 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 -070010272 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -070010273 zero, wpa_s->last_tk_len,
10274 KEY_FLAG_PAIRWISE_RX_TX) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010275 return -1;
10276
10277 /* Set the previously configured key to reset its TSC/RSC */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000010278 return wpa_drv_set_key(wpa_s, -1, wpa_s->last_tk_alg,
10279 wpa_s->last_tk_addr,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010280 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -070010281 wpa_s->last_tk, wpa_s->last_tk_len,
10282 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010283}
10284
10285
10286static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
10287{
10288 const char *pos = cmd;
10289 int error, pairwise;
10290
10291 error = atoi(pos);
10292 pos = os_strchr(pos, ' ');
10293 if (!pos)
10294 return -1;
10295 pairwise = atoi(pos);
10296 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
10297 return 0;
10298}
10299
10300
10301static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
10302{
10303#ifdef CONFIG_SME
10304 struct wpa_driver_associate_params params;
10305 int ret;
10306
10307 os_memset(&params, 0, sizeof(params));
10308 params.bssid = wpa_s->bssid;
10309 params.ssid = wpa_s->sme.ssid;
10310 params.ssid_len = wpa_s->sme.ssid_len;
10311 params.freq.freq = wpa_s->sme.freq;
10312 if (wpa_s->last_assoc_req_wpa_ie) {
10313 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
10314 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
10315 }
10316 params.pairwise_suite = wpa_s->pairwise_cipher;
10317 params.group_suite = wpa_s->group_cipher;
10318 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
10319 params.key_mgmt_suite = wpa_s->key_mgmt;
10320 params.wpa_proto = wpa_s->wpa_proto;
10321 params.mgmt_frame_protection = wpa_s->sme.mfp;
10322 params.rrm_used = wpa_s->rrm.rrm_used;
10323 if (wpa_s->sme.prev_bssid_set)
10324 params.prev_bssid = wpa_s->sme.prev_bssid;
10325 wpa_printf(MSG_INFO, "TESTING: Resend association request");
10326 ret = wpa_drv_associate(wpa_s, &params);
10327 wpa_s->testing_resend_assoc = 1;
10328 return ret;
10329#else /* CONFIG_SME */
10330 return -1;
10331#endif /* CONFIG_SME */
10332}
10333
Hai Shaloma20dcd72022-02-04 13:43:00 -080010334
10335static int wpas_ctrl_iface_send_twt_setup(struct wpa_supplicant *wpa_s,
10336 const char *cmd)
10337{
10338 u8 dtok = 1;
10339 int exponent = 10;
10340 int mantissa = 8192;
10341 u8 min_twt = 255;
10342 unsigned long long twt = 0;
10343 bool requestor = true;
10344 int setup_cmd = 0;
10345 bool trigger = true;
10346 bool implicit = true;
10347 bool flow_type = true;
10348 int flow_id = 0;
10349 bool protection = false;
10350 u8 twt_channel = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -070010351 u8 control = BIT(4); /* Control field (IEEE Std 802.11ax-2021,
10352 * Figure 9-687 - Control field format):
10353 * B4 = TWT Information Frame Disabled */
Hai Shaloma20dcd72022-02-04 13:43:00 -080010354 const char *tok_s;
10355
10356 tok_s = os_strstr(cmd, " dialog=");
10357 if (tok_s)
10358 dtok = atoi(tok_s + os_strlen(" dialog="));
10359
10360 tok_s = os_strstr(cmd, " exponent=");
10361 if (tok_s)
10362 exponent = atoi(tok_s + os_strlen(" exponent="));
10363
10364 tok_s = os_strstr(cmd, " mantissa=");
10365 if (tok_s)
10366 mantissa = atoi(tok_s + os_strlen(" mantissa="));
10367
10368 tok_s = os_strstr(cmd, " min_twt=");
10369 if (tok_s)
10370 min_twt = atoi(tok_s + os_strlen(" min_twt="));
10371
10372 tok_s = os_strstr(cmd, " setup_cmd=");
10373 if (tok_s)
10374 setup_cmd = atoi(tok_s + os_strlen(" setup_cmd="));
10375
10376 tok_s = os_strstr(cmd, " twt=");
Sunil8cd6f4d2022-06-28 18:40:46 +000010377 if (tok_s &&
10378 sscanf(tok_s + os_strlen(" twt="), "%llu", &twt) != 1)
10379 return -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080010380
10381 tok_s = os_strstr(cmd, " requestor=");
10382 if (tok_s)
10383 requestor = atoi(tok_s + os_strlen(" requestor="));
10384
10385 tok_s = os_strstr(cmd, " trigger=");
10386 if (tok_s)
10387 trigger = atoi(tok_s + os_strlen(" trigger="));
10388
10389 tok_s = os_strstr(cmd, " implicit=");
10390 if (tok_s)
10391 implicit = atoi(tok_s + os_strlen(" implicit="));
10392
10393 tok_s = os_strstr(cmd, " flow_type=");
10394 if (tok_s)
10395 flow_type = atoi(tok_s + os_strlen(" flow_type="));
10396
10397 tok_s = os_strstr(cmd, " flow_id=");
10398 if (tok_s)
10399 flow_id = atoi(tok_s + os_strlen(" flow_id="));
10400
10401 tok_s = os_strstr(cmd, " protection=");
10402 if (tok_s)
10403 protection = atoi(tok_s + os_strlen(" protection="));
10404
10405 tok_s = os_strstr(cmd, " twt_channel=");
10406 if (tok_s)
10407 twt_channel = atoi(tok_s + os_strlen(" twt_channel="));
10408
10409 tok_s = os_strstr(cmd, " control=");
10410 if (tok_s)
10411 control = atoi(tok_s + os_strlen(" control="));
10412
10413 return wpas_twt_send_setup(wpa_s, dtok, exponent, mantissa, min_twt,
10414 setup_cmd, twt, requestor, trigger, implicit,
10415 flow_type, flow_id, protection, twt_channel,
10416 control);
10417}
10418
10419
10420static int wpas_ctrl_iface_send_twt_teardown(struct wpa_supplicant *wpa_s,
10421 const char *cmd)
10422{
10423 u8 flags = 0x1;
10424 const char *tok_s;
10425
10426 tok_s = os_strstr(cmd, " flags=");
10427 if (tok_s)
10428 flags = atoi(tok_s + os_strlen(" flags="));
10429
10430 return wpas_twt_send_teardown(wpa_s, flags);
10431}
10432
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010433#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010434
10435
10436static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
10437{
10438 char *pos = cmd;
10439 int frame;
10440 size_t len;
10441 struct wpabuf *buf;
10442 struct ieee802_11_elems elems;
10443
10444 frame = atoi(pos);
10445 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10446 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010447 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010448
10449 pos = os_strchr(pos, ' ');
10450 if (pos == NULL)
10451 return -1;
10452 pos++;
10453
10454 len = os_strlen(pos);
10455 if (len == 0)
10456 return 0;
10457 if (len & 1)
10458 return -1;
10459 len /= 2;
10460
10461 buf = wpabuf_alloc(len);
10462 if (buf == NULL)
10463 return -1;
10464
10465 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
10466 wpabuf_free(buf);
10467 return -1;
10468 }
10469
10470 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
10471 ParseFailed) {
10472 wpabuf_free(buf);
10473 return -1;
10474 }
10475
10476 if (wpa_s->vendor_elem[frame] == NULL) {
10477 wpa_s->vendor_elem[frame] = buf;
Hai Shalom60840252021-02-19 19:02:11 -080010478 goto update_ies;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010479 }
10480
10481 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
10482 wpabuf_free(buf);
10483 return -1;
10484 }
10485
10486 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
10487 wpabuf_free(buf);
Hai Shalom60840252021-02-19 19:02:11 -080010488
10489update_ies:
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010490 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010491
Hai Shalom60840252021-02-19 19:02:11 -080010492 if (frame == VENDOR_ELEM_PROBE_REQ ||
10493 frame == VENDOR_ELEM_PROBE_REQ_P2P)
10494 wpa_supplicant_set_default_scan_ies(wpa_s);
10495
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010496 return 0;
10497}
10498
10499
10500static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
10501 char *buf, size_t buflen)
10502{
10503 int frame = atoi(cmd);
10504
10505 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10506 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010507 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010508
10509 if (wpa_s->vendor_elem[frame] == NULL)
10510 return 0;
10511
10512 return wpa_snprintf_hex(buf, buflen,
10513 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
10514 wpabuf_len(wpa_s->vendor_elem[frame]));
10515}
10516
10517
10518static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
10519{
10520 char *pos = cmd;
10521 int frame;
10522 size_t len;
10523 u8 *buf;
10524 struct ieee802_11_elems elems;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010525 int res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010526
10527 frame = atoi(pos);
10528 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10529 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010530 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010531
10532 pos = os_strchr(pos, ' ');
10533 if (pos == NULL)
10534 return -1;
10535 pos++;
10536
10537 if (*pos == '*') {
10538 wpabuf_free(wpa_s->vendor_elem[frame]);
10539 wpa_s->vendor_elem[frame] = NULL;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010540 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010541 return 0;
10542 }
10543
10544 if (wpa_s->vendor_elem[frame] == NULL)
10545 return -1;
10546
10547 len = os_strlen(pos);
10548 if (len == 0)
10549 return 0;
10550 if (len & 1)
10551 return -1;
10552 len /= 2;
10553
10554 buf = os_malloc(len);
10555 if (buf == NULL)
10556 return -1;
10557
10558 if (hexstr2bin(pos, buf, len) < 0) {
10559 os_free(buf);
10560 return -1;
10561 }
10562
10563 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
10564 os_free(buf);
10565 return -1;
10566 }
10567
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010568 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010569 os_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010570 return res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010571}
10572
10573
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010574static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
10575{
10576 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010577 size_t len;
10578 const u8 *data;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010579
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010580 /*
10581 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
10582 * BSSID[6]
10583 * BSSID Information[4]
10584 * Operating Class[1]
10585 * Channel Number[1]
10586 * PHY Type[1]
10587 * Optional Subelements[variable]
10588 */
10589#define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
10590
10591 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010592 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010593 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010594 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010595
10596 data = wpabuf_head_u8(neighbor_rep);
10597 len = wpabuf_len(neighbor_rep);
10598
10599 while (len >= 2 + NR_IE_MIN_LEN) {
10600 const u8 *nr;
10601 char lci[256 * 2 + 1];
10602 char civic[256 * 2 + 1];
10603 u8 nr_len = data[1];
10604 const u8 *pos = data, *end;
10605
10606 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
10607 nr_len < NR_IE_MIN_LEN) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010608 wpa_dbg(wpa_s, MSG_DEBUG,
10609 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
10610 data[0], nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010611 goto out;
10612 }
10613
10614 if (2U + nr_len > len) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010615 wpa_dbg(wpa_s, MSG_DEBUG,
10616 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
10617 data[0], len, nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010618 goto out;
10619 }
10620 pos += 2;
10621 end = pos + nr_len;
10622
10623 nr = pos;
10624 pos += NR_IE_MIN_LEN;
10625
10626 lci[0] = '\0';
10627 civic[0] = '\0';
10628 while (end - pos > 2) {
10629 u8 s_id, s_len;
10630
10631 s_id = *pos++;
10632 s_len = *pos++;
10633 if (s_len > end - pos)
10634 goto out;
10635 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
10636 /* Measurement Token[1] */
10637 /* Measurement Report Mode[1] */
10638 /* Measurement Type[1] */
10639 /* Measurement Report[variable] */
10640 switch (pos[2]) {
10641 case MEASURE_TYPE_LCI:
10642 if (lci[0])
10643 break;
10644 wpa_snprintf_hex(lci, sizeof(lci),
10645 pos, s_len);
10646 break;
10647 case MEASURE_TYPE_LOCATION_CIVIC:
10648 if (civic[0])
10649 break;
10650 wpa_snprintf_hex(civic, sizeof(civic),
10651 pos, s_len);
10652 break;
10653 }
10654 }
10655
10656 pos += s_len;
10657 }
10658
10659 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
10660 "bssid=" MACSTR
10661 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
10662 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
10663 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
10664 nr[ETH_ALEN + 6],
10665 lci[0] ? " lci=" : "", lci,
10666 civic[0] ? " civic=" : "", civic);
10667
10668 data = end;
10669 len -= 2 + nr_len;
10670 }
10671
10672out:
10673 wpabuf_free(neighbor_rep);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010674}
10675
10676
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010677static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
10678 char *cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010679{
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010680 struct wpa_ssid_value ssid, *ssid_p = NULL;
10681 int ret, lci = 0, civic = 0;
10682 char *ssid_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010683
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010684 ssid_s = os_strstr(cmd, "ssid=");
10685 if (ssid_s) {
10686 if (ssid_parse(ssid_s + 5, &ssid)) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010687 wpa_msg(wpa_s, MSG_INFO,
10688 "CTRL: Send Neighbor Report: bad SSID");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010689 return -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010690 }
10691
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010692 ssid_p = &ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010693
10694 /*
10695 * Move cmd after the SSID text that may include "lci" or
10696 * "civic".
10697 */
10698 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
10699 if (cmd)
10700 cmd++;
10701
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010702 }
10703
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010704 if (cmd && os_strstr(cmd, "lci"))
10705 lci = 1;
10706
10707 if (cmd && os_strstr(cmd, "civic"))
10708 civic = 1;
10709
10710 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010711 wpas_ctrl_neighbor_rep_cb,
10712 wpa_s);
10713
10714 return ret;
10715}
10716
10717
10718static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
10719{
10720 eapol_sm_erp_flush(wpa_s->eapol);
10721 return 0;
10722}
10723
10724
10725static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
10726 char *cmd)
10727{
10728 char *token, *context = NULL;
10729 unsigned int enable = ~0, type = 0;
10730 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
10731 u8 *addr = NULL, *mask = NULL;
10732
10733 while ((token = str_token(cmd, " ", &context))) {
10734 if (os_strcasecmp(token, "scan") == 0) {
10735 type |= MAC_ADDR_RAND_SCAN;
10736 } else if (os_strcasecmp(token, "sched") == 0) {
10737 type |= MAC_ADDR_RAND_SCHED_SCAN;
10738 } else if (os_strcasecmp(token, "pno") == 0) {
10739 type |= MAC_ADDR_RAND_PNO;
10740 } else if (os_strcasecmp(token, "all") == 0) {
10741 type = wpa_s->mac_addr_rand_supported;
10742 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
10743 enable = atoi(token + 7);
10744 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
10745 addr = _addr;
10746 if (hwaddr_aton(token + 5, addr)) {
10747 wpa_printf(MSG_INFO,
10748 "CTRL: Invalid MAC address: %s",
10749 token);
10750 return -1;
10751 }
10752 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
10753 mask = _mask;
10754 if (hwaddr_aton(token + 5, mask)) {
10755 wpa_printf(MSG_INFO,
10756 "CTRL: Invalid MAC address mask: %s",
10757 token);
10758 return -1;
10759 }
10760 } else {
10761 wpa_printf(MSG_INFO,
10762 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
10763 token);
10764 return -1;
10765 }
10766 }
10767
10768 if (!type) {
10769 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
10770 return -1;
10771 }
10772
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010773 if (enable > 1) {
10774 wpa_printf(MSG_INFO,
10775 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
10776 return -1;
10777 }
10778
Hai Shalom81f62d82019-07-22 12:10:00 -070010779 if (!enable)
10780 return wpas_disable_mac_addr_randomization(wpa_s, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010781
Hai Shalom81f62d82019-07-22 12:10:00 -070010782 return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010783}
10784
10785
Dmitry Shmidte4663042016-04-04 10:07:49 -070010786static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
10787 char *buf, size_t buflen)
10788{
10789 size_t reply_len;
10790
10791 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
10792#ifdef CONFIG_AP
10793 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
10794 buflen - reply_len);
10795#endif /* CONFIG_AP */
10796 return reply_len;
10797}
10798
10799
10800static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
10801{
Hai Shalom60840252021-02-19 19:02:11 -080010802 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
Dmitry Shmidte4663042016-04-04 10:07:49 -070010803 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
10804#ifdef CONFIG_AP
10805 wpas_ap_pmksa_cache_flush(wpa_s);
10806#endif /* CONFIG_AP */
10807}
10808
10809
Dmitry Shmidt29333592017-01-09 12:27:11 -080010810#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10811
10812static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
10813 const char *cmd, char *buf, size_t buflen)
10814{
10815 struct rsn_pmksa_cache_entry *entry;
10816 struct wpa_ssid *ssid;
10817 char *pos, *pos2, *end;
10818 int ret;
10819 struct os_reltime now;
10820
10821 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10822 if (!ssid)
10823 return -1;
10824
10825 pos = buf;
10826 end = buf + buflen;
10827
10828 os_get_reltime(&now);
10829
10830 /*
10831 * Entry format:
10832 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10833 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010834 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010835 */
10836
10837 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
10838 entry = entry->next) {
10839 if (entry->network_ctx != ssid)
10840 continue;
10841
10842 pos2 = pos;
10843 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
10844 MAC2STR(entry->aa));
10845 if (os_snprintf_error(end - pos2, ret))
10846 break;
10847 pos2 += ret;
10848
10849 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
10850 PMKID_LEN);
10851
10852 ret = os_snprintf(pos2, end - pos2, " ");
10853 if (os_snprintf_error(end - pos2, ret))
10854 break;
10855 pos2 += ret;
10856
10857 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
10858 entry->pmk_len);
10859
10860 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
10861 (int) (entry->reauth_time - now.sec),
10862 (int) (entry->expiration - now.sec),
10863 entry->akmp,
10864 entry->opportunistic);
10865 if (os_snprintf_error(end - pos2, ret))
10866 break;
10867 pos2 += ret;
10868
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010869 if (entry->fils_cache_id_set) {
10870 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
10871 entry->fils_cache_id[0],
10872 entry->fils_cache_id[1]);
10873 if (os_snprintf_error(end - pos2, ret))
10874 break;
10875 pos2 += ret;
10876 }
10877
Dmitry Shmidt29333592017-01-09 12:27:11 -080010878 ret = os_snprintf(pos2, end - pos2, "\n");
10879 if (os_snprintf_error(end - pos2, ret))
10880 break;
10881 pos2 += ret;
10882
10883 pos = pos2;
10884 }
10885
10886 return pos - buf;
10887}
10888
10889
10890static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
10891 char *cmd)
10892{
10893 struct rsn_pmksa_cache_entry *entry;
10894 struct wpa_ssid *ssid;
10895 char *pos, *pos2;
10896 int ret = -1;
10897 struct os_reltime now;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010898 int reauth_time = 0, expiration = 0, i;
Dmitry Shmidt29333592017-01-09 12:27:11 -080010899
10900 /*
10901 * Entry format:
10902 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10903 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010904 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010905 */
10906
10907 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10908 if (!ssid)
10909 return -1;
10910
10911 pos = os_strchr(cmd, ' ');
10912 if (!pos)
10913 return -1;
10914 pos++;
10915
10916 entry = os_zalloc(sizeof(*entry));
10917 if (!entry)
10918 return -1;
10919
10920 if (hwaddr_aton(pos, entry->aa))
10921 goto fail;
10922
10923 pos = os_strchr(pos, ' ');
10924 if (!pos)
10925 goto fail;
10926 pos++;
10927
10928 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
10929 goto fail;
10930
10931 pos = os_strchr(pos, ' ');
10932 if (!pos)
10933 goto fail;
10934 pos++;
10935
10936 pos2 = os_strchr(pos, ' ');
10937 if (!pos2)
10938 goto fail;
10939 entry->pmk_len = (pos2 - pos) / 2;
10940 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
10941 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
10942 goto fail;
10943
10944 pos = os_strchr(pos, ' ');
10945 if (!pos)
10946 goto fail;
10947 pos++;
10948
10949 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
10950 &entry->akmp, &entry->opportunistic) != 4)
10951 goto fail;
Hai Shaloma20dcd72022-02-04 13:43:00 -080010952 if (reauth_time > expiration)
10953 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010954 for (i = 0; i < 4; i++) {
10955 pos = os_strchr(pos, ' ');
10956 if (!pos) {
10957 if (i < 3)
10958 goto fail;
10959 break;
10960 }
10961 pos++;
10962 }
10963 if (pos) {
10964 if (hexstr2bin(pos, entry->fils_cache_id,
10965 FILS_CACHE_ID_LEN) < 0)
10966 goto fail;
10967 entry->fils_cache_id_set = 1;
10968 }
Dmitry Shmidt29333592017-01-09 12:27:11 -080010969 os_get_reltime(&now);
10970 entry->expiration = now.sec + expiration;
10971 entry->reauth_time = now.sec + reauth_time;
10972
10973 entry->network_ctx = ssid;
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000010974 os_memcpy(entry->spa, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt29333592017-01-09 12:27:11 -080010975
Hai Shaloma20dcd72022-02-04 13:43:00 -080010976 entry->external = true;
10977
Dmitry Shmidt29333592017-01-09 12:27:11 -080010978 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
10979 entry = NULL;
10980 ret = 0;
10981fail:
10982 os_free(entry);
10983 return ret;
10984}
10985
Paul Stewart092955c2017-02-06 09:13:09 -080010986
10987#ifdef CONFIG_MESH
10988
10989static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
10990 const char *cmd, char *buf,
10991 size_t buflen)
10992{
10993 u8 spa[ETH_ALEN];
10994
10995 if (!wpa_s->ifmsh)
10996 return -1;
10997
10998 if (os_strcasecmp(cmd, "any") == 0)
10999 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
11000
11001 if (hwaddr_aton(cmd, spa))
11002 return -1;
11003
11004 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
11005}
11006
11007
11008static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
11009 char *cmd)
11010{
11011 /*
Hai Shalom60840252021-02-19 19:02:11 -080011012 * We do not check mesh interface existence because PMKSA should be
Paul Stewart092955c2017-02-06 09:13:09 -080011013 * stored before wpa_s->ifmsh creation to suppress commit message
11014 * creation.
11015 */
11016 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
11017}
11018
11019#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080011020#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
11021
11022
Paul Stewart092955c2017-02-06 09:13:09 -080011023#ifdef CONFIG_FILS
11024static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
11025 const char *cmd)
11026{
11027 struct fils_hlp_req *req;
11028 const char *pos;
11029
11030 /* format: <dst> <packet starting from ethertype> */
11031
11032 req = os_zalloc(sizeof(*req));
11033 if (!req)
11034 return -1;
11035
11036 if (hwaddr_aton(cmd, req->dst))
11037 goto fail;
11038
11039 pos = os_strchr(cmd, ' ');
11040 if (!pos)
11041 goto fail;
11042 pos++;
11043 req->pkt = wpabuf_parse_bin(pos);
11044 if (!req->pkt)
11045 goto fail;
11046
11047 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
11048 return 0;
11049fail:
11050 wpabuf_free(req->pkt);
11051 os_free(req);
11052 return -1;
11053}
11054#endif /* CONFIG_FILS */
11055
11056
Sunil Ravia04bd252022-05-02 22:54:18 -070011057int wpas_ctrl_cmd_debug_level(const char *cmd)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011058{
11059 if (os_strcmp(cmd, "PING") == 0 ||
11060 os_strncmp(cmd, "BSS ", 4) == 0 ||
11061 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
11062 os_strncmp(cmd, "STATUS", 6) == 0 ||
11063 os_strncmp(cmd, "STA ", 4) == 0 ||
11064 os_strncmp(cmd, "STA-", 4) == 0)
11065 return MSG_EXCESSIVE;
11066 return MSG_DEBUG;
11067}
11068
11069
Hai Shalom899fcc72020-10-19 14:38:18 -070011070static int wpas_ctrl_iface_configure_mscs(struct wpa_supplicant *wpa_s,
11071 const char *cmd)
11072{
11073 size_t frame_classifier_len;
11074 const char *pos, *end;
11075 struct robust_av_data *robust_av = &wpa_s->robust_av;
11076 int val;
11077
11078 /*
11079 * format:
11080 * <add|remove|change> [up_bitmap=<hex byte>] [up_limit=<integer>]
11081 * [stream_timeout=<in TUs>] [frame_classifier=<hex bytes>]
11082 */
11083 os_memset(robust_av, 0, sizeof(struct robust_av_data));
11084 if (os_strncmp(cmd, "add ", 4) == 0) {
11085 robust_av->request_type = SCS_REQ_ADD;
11086 } else if (os_strcmp(cmd, "remove") == 0) {
11087 robust_av->request_type = SCS_REQ_REMOVE;
11088 robust_av->valid_config = false;
11089 return wpas_send_mscs_req(wpa_s);
11090 } else if (os_strncmp(cmd, "change ", 7) == 0) {
11091 robust_av->request_type = SCS_REQ_CHANGE;
11092 } else {
11093 return -1;
11094 }
11095
11096 pos = os_strstr(cmd, "up_bitmap=");
11097 if (!pos)
11098 return -1;
11099
11100 val = hex2byte(pos + 10);
11101 if (val < 0)
11102 return -1;
11103 robust_av->up_bitmap = val;
11104
11105 pos = os_strstr(cmd, "up_limit=");
11106 if (!pos)
11107 return -1;
11108
11109 robust_av->up_limit = atoi(pos + 9);
11110
11111 pos = os_strstr(cmd, "stream_timeout=");
11112 if (!pos)
11113 return -1;
11114
11115 robust_av->stream_timeout = atoi(pos + 15);
11116 if (robust_av->stream_timeout == 0)
11117 return -1;
11118
11119 pos = os_strstr(cmd, "frame_classifier=");
11120 if (!pos)
11121 return -1;
11122
11123 pos += 17;
11124 end = os_strchr(pos, ' ');
11125 if (!end)
11126 end = pos + os_strlen(pos);
11127
11128 frame_classifier_len = (end - pos) / 2;
11129 if (frame_classifier_len > sizeof(robust_av->frame_classifier) ||
11130 hexstr2bin(pos, robust_av->frame_classifier, frame_classifier_len))
11131 return -1;
11132
11133 robust_av->frame_classifier_len = frame_classifier_len;
11134 robust_av->valid_config = true;
11135
11136 return wpas_send_mscs_req(wpa_s);
11137}
11138
11139
Hai Shalom60840252021-02-19 19:02:11 -080011140#ifdef CONFIG_PASN
11141static int wpas_ctrl_iface_pasn_start(struct wpa_supplicant *wpa_s, char *cmd)
11142{
11143 char *token, *context = NULL;
11144 u8 bssid[ETH_ALEN];
11145 int akmp = -1, cipher = -1, got_bssid = 0;
11146 u16 group = 0xFFFF;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011147 u8 *comeback = NULL;
11148 size_t comeback_len = 0;
11149 int id = 0, ret = -1;
Hai Shalom60840252021-02-19 19:02:11 -080011150
11151 /*
11152 * Entry format: bssid=<BSSID> akmp=<AKMP> cipher=<CIPHER> group=<group>
Hai Shaloma20dcd72022-02-04 13:43:00 -080011153 * [comeback=<hexdump>]
Hai Shalom60840252021-02-19 19:02:11 -080011154 */
11155 while ((token = str_token(cmd, " ", &context))) {
11156 if (os_strncmp(token, "bssid=", 6) == 0) {
11157 if (hwaddr_aton(token + 6, bssid))
Hai Shaloma20dcd72022-02-04 13:43:00 -080011158 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080011159 got_bssid = 1;
11160 } else if (os_strcmp(token, "akmp=PASN") == 0) {
11161 akmp = WPA_KEY_MGMT_PASN;
11162#ifdef CONFIG_IEEE80211R
11163 } else if (os_strcmp(token, "akmp=FT-PSK") == 0) {
11164 akmp = WPA_KEY_MGMT_FT_PSK;
11165 } else if (os_strcmp(token, "akmp=FT-EAP-SHA384") == 0) {
11166 akmp = WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
11167 } else if (os_strcmp(token, "akmp=FT-EAP") == 0) {
11168 akmp = WPA_KEY_MGMT_FT_IEEE8021X;
11169#endif /* CONFIG_IEEE80211R */
11170#ifdef CONFIG_SAE
11171 } else if (os_strcmp(token, "akmp=SAE") == 0) {
11172 akmp = WPA_KEY_MGMT_SAE;
Sunil Ravi89eba102022-09-13 21:04:37 -070011173 } else if (os_strcmp(token, "akmp=SAE-EXT-KEY") == 0) {
11174 akmp = WPA_KEY_MGMT_SAE_EXT_KEY;
Hai Shalom60840252021-02-19 19:02:11 -080011175#endif /* CONFIG_SAE */
11176#ifdef CONFIG_FILS
11177 } else if (os_strcmp(token, "akmp=FILS-SHA256") == 0) {
11178 akmp = WPA_KEY_MGMT_FILS_SHA256;
11179 } else if (os_strcmp(token, "akmp=FILS-SHA384") == 0) {
11180 akmp = WPA_KEY_MGMT_FILS_SHA384;
11181#endif /* CONFIG_FILS */
11182 } else if (os_strcmp(token, "cipher=CCMP-256") == 0) {
11183 cipher = WPA_CIPHER_CCMP_256;
11184 } else if (os_strcmp(token, "cipher=GCMP-256") == 0) {
11185 cipher = WPA_CIPHER_GCMP_256;
11186 } else if (os_strcmp(token, "cipher=CCMP") == 0) {
11187 cipher = WPA_CIPHER_CCMP;
11188 } else if (os_strcmp(token, "cipher=GCMP") == 0) {
11189 cipher = WPA_CIPHER_GCMP;
11190 } else if (os_strncmp(token, "group=", 6) == 0) {
11191 group = atoi(token + 6);
11192 } else if (os_strncmp(token, "nid=", 4) == 0) {
11193 id = atoi(token + 4);
Hai Shaloma20dcd72022-02-04 13:43:00 -080011194 } else if (os_strncmp(token, "comeback=", 9) == 0) {
11195 comeback_len = os_strlen(token + 9);
11196 if (comeback || !comeback_len || comeback_len % 2)
11197 goto out;
11198
11199 comeback_len /= 2;
11200 comeback = os_malloc(comeback_len);
11201 if (!comeback ||
11202 hexstr2bin(token + 9, comeback, comeback_len))
11203 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080011204 } else {
11205 wpa_printf(MSG_DEBUG,
11206 "CTRL: PASN Invalid parameter: '%s'",
11207 token);
Hai Shaloma20dcd72022-02-04 13:43:00 -080011208 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080011209 }
11210 }
11211
11212 if (!got_bssid || akmp == -1 || cipher == -1 || group == 0xFFFF) {
11213 wpa_printf(MSG_DEBUG,"CTRL: PASN missing parameter");
Hai Shaloma20dcd72022-02-04 13:43:00 -080011214 goto out;
11215 }
11216
Sunil Ravi89eba102022-09-13 21:04:37 -070011217 ret = wpas_pasn_auth_start(wpa_s, wpa_s->own_addr, bssid, akmp, cipher,
11218 group, id, comeback, comeback_len);
Hai Shaloma20dcd72022-02-04 13:43:00 -080011219out:
11220 os_free(comeback);
11221 return ret;
11222}
11223
11224
11225static int wpas_ctrl_iface_pasn_deauthenticate(struct wpa_supplicant *wpa_s,
11226 const char *cmd)
11227{
11228 u8 bssid[ETH_ALEN];
11229
11230 if (os_strncmp(cmd, "bssid=", 6) != 0 || hwaddr_aton(cmd + 6, bssid)) {
11231 wpa_printf(MSG_DEBUG,
11232 "CTRL: PASN_DEAUTH without valid BSSID");
Hai Shalom60840252021-02-19 19:02:11 -080011233 return -1;
11234 }
11235
Sunil Ravi89eba102022-09-13 21:04:37 -070011236 return wpas_pasn_deauthenticate(wpa_s, wpa_s->own_addr, bssid);
Hai Shalom60840252021-02-19 19:02:11 -080011237}
Hai Shaloma20dcd72022-02-04 13:43:00 -080011238
Hai Shalom60840252021-02-19 19:02:11 -080011239#endif /* CONFIG_PASN */
11240
11241
Hai Shaloma20dcd72022-02-04 13:43:00 -080011242static int set_type4_frame_classifier(const char *cmd,
11243 struct type4_params *param)
11244{
11245 const char *pos, *end;
11246 u8 classifier_mask = 0;
11247 int ret;
11248 char addr[INET6_ADDRSTRLEN];
11249 size_t alen;
11250
11251 if (os_strstr(cmd, "ip_version=ipv4")) {
11252 param->ip_version = IPV4;
11253 } else if (os_strstr(cmd, "ip_version=ipv6")) {
11254 param->ip_version = IPV6;
11255 } else {
11256 wpa_printf(MSG_ERROR, "IP version missing/invalid");
11257 return -1;
11258 }
11259
11260 classifier_mask |= BIT(0);
11261
11262 pos = os_strstr(cmd, "src_ip=");
11263 if (pos) {
11264 pos += 7;
11265 end = os_strchr(pos, ' ');
11266 if (!end)
11267 end = pos + os_strlen(pos);
11268
11269 alen = end - pos;
11270 if (alen >= INET6_ADDRSTRLEN)
11271 return -1;
11272 os_memcpy(addr, pos, alen);
11273 addr[alen] = '\0';
11274 if (param->ip_version == IPV4)
11275 ret = inet_pton(AF_INET, addr,
11276 &param->ip_params.v4.src_ip);
11277 else
11278 ret = inet_pton(AF_INET6, addr,
11279 &param->ip_params.v6.src_ip);
11280
11281 if (ret != 1) {
11282 wpa_printf(MSG_ERROR,
11283 "Error converting src IP address to binary ret=%d",
11284 ret);
11285 return -1;
11286 }
11287
11288 classifier_mask |= BIT(1);
11289 }
11290
11291 pos = os_strstr(cmd, "dst_ip=");
11292 if (pos) {
11293 pos += 7;
11294 end = os_strchr(pos, ' ');
11295 if (!end)
11296 end = pos + os_strlen(pos);
11297
11298 alen = end - pos;
11299 if (alen >= INET6_ADDRSTRLEN)
11300 return -1;
11301 os_memcpy(addr, pos, alen);
11302 addr[alen] = '\0';
11303 if (param->ip_version == IPV4)
11304 ret = inet_pton(AF_INET, addr,
11305 &param->ip_params.v4.dst_ip);
11306 else
11307 ret = inet_pton(AF_INET6, addr,
11308 &param->ip_params.v6.dst_ip);
11309
11310 if (ret != 1) {
11311 wpa_printf(MSG_ERROR,
11312 "Error converting dst IP address to binary ret=%d",
11313 ret);
11314 return -1;
11315 }
11316
11317 classifier_mask |= BIT(2);
11318 }
11319
11320 pos = os_strstr(cmd, "src_port=");
11321 if (pos && atoi(pos + 9) > 0) {
11322 if (param->ip_version == IPV4)
11323 param->ip_params.v4.src_port = atoi(pos + 9);
11324 else
11325 param->ip_params.v6.src_port = atoi(pos + 9);
11326 classifier_mask |= BIT(3);
11327 }
11328
11329 pos = os_strstr(cmd, "dst_port=");
11330 if (pos && atoi(pos + 9) > 0) {
11331 if (param->ip_version == IPV4)
11332 param->ip_params.v4.dst_port = atoi(pos + 9);
11333 else
11334 param->ip_params.v6.dst_port = atoi(pos + 9);
11335 classifier_mask |= BIT(4);
11336 }
11337
11338 pos = os_strstr(cmd, "dscp=");
11339 if (pos && atoi(pos + 5) > 0) {
11340 if (param->ip_version == IPV4)
11341 param->ip_params.v4.dscp = atoi(pos + 5);
11342 else
11343 param->ip_params.v6.dscp = atoi(pos + 5);
11344 classifier_mask |= BIT(5);
11345 }
11346
11347 if (param->ip_version == IPV4) {
11348 pos = os_strstr(cmd, "protocol=");
11349 if (pos) {
11350 if (os_strstr(pos, "udp")) {
11351 param->ip_params.v4.protocol = 17;
11352 } else if (os_strstr(pos, "tcp")) {
11353 param->ip_params.v4.protocol = 6;
11354 } else if (os_strstr(pos, "esp")) {
11355 param->ip_params.v4.protocol = 50;
11356 } else {
11357 wpa_printf(MSG_ERROR, "Invalid protocol");
11358 return -1;
11359 }
11360 classifier_mask |= BIT(6);
11361 }
11362 } else {
11363 pos = os_strstr(cmd, "next_header=");
11364 if (pos) {
11365 if (os_strstr(pos, "udp")) {
11366 param->ip_params.v6.next_header = 17;
11367 } else if (os_strstr(pos, "tcp")) {
11368 param->ip_params.v6.next_header = 6;
11369 } else if (os_strstr(pos, "esp")) {
11370 param->ip_params.v6.next_header = 50;
11371 } else {
11372 wpa_printf(MSG_ERROR, "Invalid next header");
11373 return -1;
11374 }
11375
11376 classifier_mask |= BIT(6);
11377 }
11378
11379 pos = os_strstr(cmd, "flow_label=");
11380 if (pos) {
11381 pos += 11;
11382 end = os_strchr(pos, ' ');
11383 if (!end)
11384 end = pos + os_strlen(pos);
11385
11386 if (end - pos != 6 ||
11387 hexstr2bin(pos, param->ip_params.v6.flow_label,
11388 3) ||
11389 param->ip_params.v6.flow_label[0] > 0x0F) {
11390 wpa_printf(MSG_ERROR, "Invalid flow label");
11391 return -1;
11392 }
11393
11394 classifier_mask |= BIT(7);
11395 }
11396 }
11397
11398 param->classifier_mask = classifier_mask;
11399 return 0;
11400}
11401
11402
11403static int set_type10_frame_classifier(const char *cmd,
11404 struct type10_params *param)
11405{
11406 const char *pos, *end;
11407 size_t filter_len;
11408
11409 pos = os_strstr(cmd, "prot_instance=");
11410 if (!pos) {
11411 wpa_printf(MSG_ERROR, "Protocol instance missing");
11412 return -1;
11413 }
11414 param->prot_instance = atoi(pos + 14);
11415
11416 pos = os_strstr(cmd, "prot_number=");
11417 if (!pos) {
11418 wpa_printf(MSG_ERROR, "Protocol number missing");
11419 return -1;
11420 }
11421 if (os_strstr(pos, "udp")) {
11422 param->prot_number = 17;
11423 } else if (os_strstr(pos, "tcp")) {
11424 param->prot_number = 6;
11425 } else if (os_strstr(pos, "esp")) {
11426 param->prot_number = 50;
11427 } else {
11428 wpa_printf(MSG_ERROR, "Invalid protocol number");
11429 return -1;
11430 }
11431
11432 pos = os_strstr(cmd, "filter_value=");
11433 if (!pos) {
11434 wpa_printf(MSG_ERROR,
11435 "Classifier parameter filter_value missing");
11436 return -1;
11437 }
11438
11439 pos += 13;
11440 end = os_strchr(pos, ' ');
11441 if (!end)
11442 end = pos + os_strlen(pos);
11443
11444 filter_len = (end - pos) / 2;
11445 param->filter_value = os_malloc(filter_len);
11446 if (!param->filter_value)
11447 return -1;
11448
11449 if (hexstr2bin(pos, param->filter_value, filter_len)) {
11450 wpa_printf(MSG_ERROR, "Invalid filter_value %s", pos);
11451 goto free;
11452 }
11453
11454 pos = os_strstr(cmd, "filter_mask=");
11455 if (!pos) {
11456 wpa_printf(MSG_ERROR,
11457 "Classifier parameter filter_mask missing");
11458 goto free;
11459 }
11460
11461 pos += 12;
11462 end = os_strchr(pos, ' ');
11463 if (!end)
11464 end = pos + os_strlen(pos);
11465
11466 if (filter_len != (size_t) (end - pos) / 2) {
11467 wpa_printf(MSG_ERROR,
11468 "Filter mask length mismatch expected=%zu received=%zu",
11469 filter_len, (size_t) (end - pos) / 2);
11470 goto free;
11471 }
11472
11473 param->filter_mask = os_malloc(filter_len);
11474 if (!param->filter_mask)
11475 goto free;
11476
11477 if (hexstr2bin(pos, param->filter_mask, filter_len)) {
11478 wpa_printf(MSG_ERROR, "Invalid filter mask %s", pos);
11479 os_free(param->filter_mask);
11480 param->filter_mask = NULL;
11481 goto free;
11482 }
11483
11484 param->filter_len = filter_len;
11485 return 0;
11486free:
11487 os_free(param->filter_value);
11488 param->filter_value = NULL;
11489 return -1;
11490}
11491
11492
11493static int scs_parse_type4(struct tclas_element *elem, const char *pos)
11494{
11495 struct type4_params type4_param = { 0 };
11496
11497 if (set_type4_frame_classifier(pos, &type4_param) == -1) {
11498 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 4");
11499 return -1;
11500 }
11501
11502 os_memcpy(&elem->frame_classifier.type4_param,
11503 &type4_param, sizeof(struct type4_params));
11504 return 0;
11505}
11506
11507
11508static int scs_parse_type10(struct tclas_element *elem, const char *pos)
11509{
11510 struct type10_params type10_param = { 0 };
11511
11512 if (set_type10_frame_classifier(pos, &type10_param) == -1) {
11513 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 10");
11514 return -1;
11515 }
11516
11517 os_memcpy(&elem->frame_classifier.type10_param,
11518 &type10_param, sizeof(struct type10_params));
11519 return 0;
11520}
11521
11522
11523static int wpas_ctrl_iface_configure_scs(struct wpa_supplicant *wpa_s,
11524 char *cmd)
11525{
11526 char *pos1, *pos;
11527 struct scs_robust_av_data *scs_data = &wpa_s->scs_robust_av_req;
11528 struct scs_desc_elem desc_elem = { 0 };
11529 int val;
11530 unsigned int num_scs_desc = 0;
11531
11532 if (wpa_s->ongoing_scs_req) {
11533 wpa_printf(MSG_ERROR, "%s: SCS Request already in queue",
11534 __func__);
11535 return -1;
11536 }
11537
11538 /**
11539 * format:
11540 * [scs_id=<decimal number>] <add|remove|change> [scs_up=<0-7>]
11541 * [classifier_type=<4|10>]
11542 * [classifier params based on classifier type]
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011543 * [tclas_processing=<0|1>]
11544 * [qos_characteristics] <up/down/direct> [min_si=<decimal number>]
11545 * [max_si=<decimal number>] [min_data_rate=<decimal number>]
11546 * [delay_bound=<decimal number>] [max_msdu=<decimal number>]
11547 * [service_start_time=<decimal number>]
11548 * [service_start_time_link_id=<decimal number>]
11549 * [mean_data_rate=<decimal number>] [burst_size=<decimal number>]
11550 * [msdu_lifetime=<decimal number>]
11551 * [msdu_delivery_info=<decimal number>] [medium_time=<decimal number>]
11552 * [scs_id=<decimal number>] ...
Hai Shaloma20dcd72022-02-04 13:43:00 -080011553 */
11554 pos1 = os_strstr(cmd, "scs_id=");
11555 if (!pos1) {
11556 wpa_printf(MSG_ERROR, "SCSID not present");
11557 return -1;
11558 }
11559
11560 free_up_scs_desc(scs_data);
11561
11562 while (pos1) {
11563 struct scs_desc_elem *n1;
11564 struct active_scs_elem *active_scs_desc;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011565 char *next_scs_desc, *pos2;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011566 unsigned int num_tclas_elem = 0;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011567 bool scsid_active = false, tclas_present = false;
11568 struct qos_characteristics *qos_elem = &desc_elem.qos_char_elem;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011569
11570 desc_elem.scs_id = atoi(pos1 + 7);
11571 pos1 += 7;
11572
11573 next_scs_desc = os_strstr(pos1, "scs_id=");
11574 if (next_scs_desc) {
11575 char temp[20];
11576
11577 os_snprintf(temp, sizeof(temp), "scs_id=%d ",
11578 desc_elem.scs_id);
11579 if (os_strstr(next_scs_desc, temp)) {
11580 wpa_printf(MSG_ERROR,
11581 "Multiple SCS descriptors configured with same SCSID(=%d)",
11582 desc_elem.scs_id);
11583 goto free_scs_desc;
11584 }
11585 pos1[next_scs_desc - pos1 - 1] = '\0';
11586 }
11587
11588 dl_list_for_each(active_scs_desc, &wpa_s->active_scs_ids,
11589 struct active_scs_elem, list) {
11590 if (desc_elem.scs_id == active_scs_desc->scs_id) {
11591 scsid_active = true;
11592 break;
11593 }
11594 }
11595
11596 if (os_strstr(pos1, "add ")) {
11597 desc_elem.request_type = SCS_REQ_ADD;
11598 if (scsid_active) {
11599 wpa_printf(MSG_ERROR, "SCSID %d already active",
11600 desc_elem.scs_id);
11601 return -1;
11602 }
11603 } else if (os_strstr(pos1, "remove")) {
11604 desc_elem.request_type = SCS_REQ_REMOVE;
11605 if (!scsid_active) {
11606 wpa_printf(MSG_ERROR, "SCSID %d not active",
11607 desc_elem.scs_id);
11608 return -1;
11609 }
11610 goto scs_desc_end;
11611 } else if (os_strstr(pos1, "change ")) {
11612 desc_elem.request_type = SCS_REQ_CHANGE;
11613 if (!scsid_active) {
11614 wpa_printf(MSG_ERROR, "SCSID %d not active",
11615 desc_elem.scs_id);
11616 return -1;
11617 }
11618 } else {
11619 wpa_printf(MSG_ERROR, "SCS Request type invalid");
11620 goto free_scs_desc;
11621 }
11622
11623 pos1 = os_strstr(pos1, "scs_up=");
11624 if (!pos1) {
11625 wpa_printf(MSG_ERROR,
11626 "Intra-Access user priority not present");
11627 goto free_scs_desc;
11628 }
11629
11630 val = atoi(pos1 + 7);
11631 if (val < 0 || val > 7) {
11632 wpa_printf(MSG_ERROR,
11633 "Intra-Access user priority invalid %d",
11634 val);
11635 goto free_scs_desc;
11636 }
11637
11638 desc_elem.intra_access_priority = val;
11639 desc_elem.scs_up_avail = true;
11640
11641 pos = os_strstr(pos1, "classifier_type=");
11642 if (!pos) {
11643 wpa_printf(MSG_ERROR, "classifier type empty");
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011644 goto qos_characteristics;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011645 }
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011646 tclas_present = true;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011647
11648 while (pos) {
11649 struct tclas_element elem = { 0 }, *n;
11650 char *next_tclas_elem;
11651
11652 val = atoi(pos + 16);
11653 if (val != 4 && val != 10) {
11654 wpa_printf(MSG_ERROR,
11655 "classifier type invalid %d", val);
11656 goto free_scs_desc;
11657 }
11658
11659 elem.classifier_type = val;
11660 pos += 16;
11661
11662 next_tclas_elem = os_strstr(pos, "classifier_type=");
11663 if (next_tclas_elem) {
11664 pos1 = next_tclas_elem;
11665 pos[next_tclas_elem - pos - 1] = '\0';
11666 }
11667
11668 switch (val) {
11669 case 4:
11670 if (scs_parse_type4(&elem, pos) < 0)
11671 goto free_scs_desc;
11672 break;
11673 case 10:
11674 if (scs_parse_type10(&elem, pos) < 0)
11675 goto free_scs_desc;
11676 break;
11677 }
11678
11679 n = os_realloc(desc_elem.tclas_elems,
11680 (num_tclas_elem + 1) * sizeof(elem));
11681 if (!n)
11682 goto free_scs_desc;
11683
11684 desc_elem.tclas_elems = n;
11685 os_memcpy((u8 *) desc_elem.tclas_elems +
11686 num_tclas_elem * sizeof(elem),
11687 &elem, sizeof(elem));
11688 num_tclas_elem++;
11689 desc_elem.num_tclas_elem = num_tclas_elem;
11690 pos = next_tclas_elem;
11691 }
11692
11693 if (desc_elem.num_tclas_elem > 1) {
11694 pos1 = os_strstr(pos1, "tclas_processing=");
11695 if (!pos1) {
11696 wpa_printf(MSG_ERROR, "tclas_processing empty");
11697 goto free_scs_desc;
11698 }
11699
11700 val = atoi(pos1 + 17);
11701 if (val != 0 && val != 1) {
11702 wpa_printf(MSG_ERROR,
11703 "tclas_processing invalid");
11704 goto free_scs_desc;
11705 }
11706
11707 desc_elem.tclas_processing = val;
11708 }
11709
Sunil Ravi2a14cf12023-11-21 00:54:38 +000011710 qos_characteristics:
11711 pos1 = os_strstr(pos1, "qos_characteristics");
11712 if (!pos1 && !tclas_present)
11713 goto free_scs_desc;
11714 if (!pos1)
11715 goto scs_desc_end;
11716
11717 qos_elem->available = true;
11718 if (os_strstr(pos1, "up ")) {
11719 qos_elem->direction = SCS_DIRECTION_UP;
11720 if (tclas_present) {
11721 wpa_printf(MSG_ERROR,
11722 "TCLAS with direction:UP not allowed");
11723 goto free_scs_desc;
11724 }
11725 } else if (os_strstr(pos1, "down ")) {
11726 qos_elem->direction = SCS_DIRECTION_DOWN;
11727 } else if (os_strstr(pos1, "direct ")) {
11728 qos_elem->direction = SCS_DIRECTION_DIRECT;
11729 }
11730
11731 pos1 = os_strstr(pos1, "min_si=");
11732 if (!pos1) {
11733 wpa_printf(MSG_ERROR, "Min SI is required");
11734 goto free_scs_desc;
11735 }
11736 qos_elem->min_si = atoi(pos1 + 7);
11737
11738 pos1 = os_strstr(pos1, "max_si=");
11739 if (!pos1) {
11740 wpa_printf(MSG_ERROR, "Max SI is required");
11741 goto free_scs_desc;
11742 }
11743 qos_elem->max_si = atoi(pos1 + 7);
11744
11745 if (qos_elem->min_si && qos_elem->max_si &&
11746 qos_elem->max_si < qos_elem->min_si) {
11747 wpa_printf(MSG_ERROR, "Invalid Max SI");
11748 goto free_scs_desc;
11749 }
11750
11751 pos1 = os_strstr(pos1, "min_data_rate=");
11752 if (!pos1) {
11753 wpa_printf(MSG_ERROR, "Min data rate is required");
11754 goto free_scs_desc;
11755 }
11756 qos_elem->min_data_rate = atoi(pos1 + 14);
11757
11758 pos1 = os_strstr(pos1, "delay_bound=");
11759 if (!pos1) {
11760 wpa_printf(MSG_ERROR, "Delay Bound is required");
11761 goto free_scs_desc;
11762 }
11763 qos_elem->delay_bound = atoi(pos1 + 12);
11764
11765 if (qos_elem->min_data_rate >= BIT(24) ||
11766 qos_elem->delay_bound >= BIT(24)) {
11767 wpa_printf(MSG_ERROR,
11768 "Invalid min_data_rate or delay_bound");
11769 goto free_scs_desc;
11770 }
11771
11772 pos2 = os_strstr(pos1, "max_msdu=");
11773 if (pos2) {
11774 qos_elem->max_msdu_size = atoi(pos2 + 9);
11775 qos_elem->mask |= SCS_QOS_BIT_MAX_MSDU_SIZE;
11776 }
11777
11778 pos2 = os_strstr(pos1, "service_start_time=");
11779 if (pos2) {
11780 qos_elem->service_start_time = atoi(pos2 + 19);
11781 qos_elem->mask |= SCS_QOS_BIT_SERVICE_START_TIME;
11782 }
11783
11784 pos2 = os_strstr(pos1, "service_start_time_link_id=");
11785 if (pos2) {
11786 qos_elem->service_start_time_link_id = atoi(pos2 + 27);
11787 qos_elem->mask |= SCS_QOS_BIT_SERVICE_START_TIME_LINKID;
11788 }
11789
11790 pos2 = os_strstr(pos1, "mean_data_rate=");
11791 if (pos2) {
11792 qos_elem->mean_data_rate = atoi(pos2 + 15);
11793 qos_elem->mask |= SCS_QOS_BIT_MEAN_DATA_RATE;
11794 }
11795
11796 pos2 = os_strstr(pos1, "burst_size=");
11797 if (pos2) {
11798 qos_elem->burst_size = atoi(pos2 + 11);
11799 qos_elem->mask |=
11800 SCS_QOS_BIT_DELAYED_BOUNDED_BURST_SIZE;
11801 }
11802
11803 pos2 = os_strstr(pos1, "msdu_lifetime=");
11804 if (pos2) {
11805 qos_elem->msdu_lifetime = atoi(pos2 + 14);
11806 qos_elem->mask |= SCS_QOS_BIT_MSDU_LIFETIME;
11807 }
11808
11809 pos2 = os_strstr(pos1, "msdu_delivery_info=");
11810 if (pos2) {
11811 qos_elem->msdu_delivery_info = atoi(pos2 + 19);
11812 qos_elem->mask |= SCS_QOS_BIT_MSDU_DELIVERY_INFO;
11813 }
11814
11815 pos2 = os_strstr(pos1, "medium_time=");
11816 if (pos2) {
11817 qos_elem->medium_time = atoi(pos2 + 12);
11818 qos_elem->mask |= SCS_QOS_BIT_MEDIUM_TIME;
11819 }
11820
Hai Shaloma20dcd72022-02-04 13:43:00 -080011821scs_desc_end:
11822 n1 = os_realloc(scs_data->scs_desc_elems, (num_scs_desc + 1) *
11823 sizeof(struct scs_desc_elem));
11824 if (!n1)
11825 goto free_scs_desc;
11826
11827 scs_data->scs_desc_elems = n1;
11828 os_memcpy((u8 *) scs_data->scs_desc_elems + num_scs_desc *
11829 sizeof(desc_elem), &desc_elem, sizeof(desc_elem));
11830 num_scs_desc++;
11831 scs_data->num_scs_desc = num_scs_desc;
11832 pos1 = next_scs_desc;
11833 os_memset(&desc_elem, 0, sizeof(desc_elem));
11834 }
11835
11836 return wpas_send_scs_req(wpa_s);
11837
11838free_scs_desc:
11839 free_up_tclas_elem(&desc_elem);
11840 free_up_scs_desc(scs_data);
11841 return -1;
11842}
11843
11844
11845static int wpas_ctrl_iface_send_dscp_resp(struct wpa_supplicant *wpa_s,
11846 const char *cmd)
11847{
11848 char *pos;
11849 struct dscp_policy_status *policy = NULL, *n;
11850 int num_policies = 0, ret = -1;
11851 struct dscp_resp_data resp_data;
11852
11853 /*
11854 * format:
11855 * <[reset]>/<[solicited] [policy_id=1 status=0...]> [more]
11856 */
11857
11858 os_memset(&resp_data, 0, sizeof(resp_data));
11859
11860 resp_data.more = os_strstr(cmd, "more") != NULL;
11861
11862 if (os_strstr(cmd, "reset")) {
11863 resp_data.reset = true;
11864 resp_data.solicited = false;
11865 goto send_resp;
11866 }
11867
11868 resp_data.solicited = os_strstr(cmd, "solicited") != NULL;
11869
11870 pos = os_strstr(cmd, "policy_id=");
11871 while (pos) {
11872 n = os_realloc(policy, (num_policies + 1) * sizeof(*policy));
11873 if (!n)
11874 goto fail;
11875
11876 policy = n;
11877 pos += 10;
11878 policy[num_policies].id = atoi(pos);
11879 if (policy[num_policies].id == 0) {
11880 wpa_printf(MSG_ERROR, "DSCP: Invalid policy id");
11881 goto fail;
11882 }
11883
11884 pos = os_strstr(pos, "status=");
11885 if (!pos) {
11886 wpa_printf(MSG_ERROR,
11887 "DSCP: Status is not found for a policy");
11888 goto fail;
11889 }
11890
11891 pos += 7;
11892 policy[num_policies].status = atoi(pos);
11893 num_policies++;
11894
11895 pos = os_strstr(pos, "policy_id");
11896 }
11897
11898 resp_data.policy = policy;
11899 resp_data.num_policies = num_policies;
11900send_resp:
11901 ret = wpas_send_dscp_response(wpa_s, &resp_data);
11902 if (ret)
11903 wpa_printf(MSG_ERROR, "DSCP: Failed to send DSCP response");
11904fail:
11905 os_free(policy);
11906 return ret;
11907}
11908
11909
11910static int wpas_ctrl_iface_send_dscp_query(struct wpa_supplicant *wpa_s,
11911 const char *cmd)
11912{
11913 char *pos;
11914
11915 /*
11916 * format:
11917 * Wildcard DSCP query
11918 * <wildcard>
11919 *
11920 * DSCP query with a domain name attribute:
11921 * [domain_name=<string>]
11922 */
11923
11924 if (os_strstr(cmd, "wildcard")) {
11925 wpa_printf(MSG_DEBUG, "QM: Send wildcard DSCP policy query");
11926 return wpas_send_dscp_query(wpa_s, NULL, 0);
11927 }
11928
11929 pos = os_strstr(cmd, "domain_name=");
11930 if (!pos || !os_strlen(pos + 12)) {
11931 wpa_printf(MSG_ERROR, "QM: Domain name not preset");
11932 return -1;
11933 }
11934
11935 return wpas_send_dscp_query(wpa_s, pos + 12, os_strlen(pos + 12));
11936}
11937
11938
Sunil Ravi89eba102022-09-13 21:04:37 -070011939static int wpas_ctrl_iface_mlo_signal_poll(struct wpa_supplicant *wpa_s,
11940 char *buf, size_t buflen)
11941{
11942 int ret, i;
11943 char *pos, *end;
11944 struct wpa_mlo_signal_info mlo_si;
11945
11946 if (!wpa_s->valid_links)
11947 return -1;
11948
11949 ret = wpa_drv_mlo_signal_poll(wpa_s, &mlo_si);
11950 if (ret)
11951 return -1;
11952
11953 pos = buf;
11954 end = buf + buflen;
11955
11956 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
11957 if (!(mlo_si.valid_links & BIT(i)))
11958 continue;
11959
11960 ret = os_snprintf(pos, end - pos,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000011961 "LINK_ID=%d\nRSSI=%d\nLINKSPEED=%lu\n"
Sunil Ravi89eba102022-09-13 21:04:37 -070011962 "NOISE=%d\nFREQUENCY=%u\n",
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000011963 i, mlo_si.links[i].data.signal,
11964 mlo_si.links[i].data.current_tx_rate / 1000,
Sunil Ravi89eba102022-09-13 21:04:37 -070011965 mlo_si.links[i].current_noise,
11966 mlo_si.links[i].frequency);
11967 if (os_snprintf_error(end - pos, ret))
11968 return -1;
11969 pos += ret;
11970
11971 if (mlo_si.links[i].chanwidth != CHAN_WIDTH_UNKNOWN) {
11972 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
11973 channel_width_to_string(
11974 mlo_si.links[i].chanwidth));
11975 if (os_snprintf_error(end - pos, ret))
11976 return -1;
11977 pos += ret;
11978 }
11979
11980 if (mlo_si.links[i].center_frq1 > 0) {
11981 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
11982 mlo_si.links[i].center_frq1);
11983 if (os_snprintf_error(end - pos, ret))
11984 return -1;
11985 pos += ret;
11986 }
11987
11988 if (mlo_si.links[i].center_frq2 > 0) {
11989 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
11990 mlo_si.links[i].center_frq2);
11991 if (os_snprintf_error(end - pos, ret))
11992 return -1;
11993 pos += ret;
11994 }
11995
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000011996 if (mlo_si.links[i].data.avg_signal) {
Sunil Ravi89eba102022-09-13 21:04:37 -070011997 ret = os_snprintf(pos, end - pos,
11998 "AVG_RSSI=%d\n",
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000011999 mlo_si.links[i].data.avg_signal);
Sunil Ravi89eba102022-09-13 21:04:37 -070012000 if (os_snprintf_error(end - pos, ret))
12001 return -1;
12002 pos += ret;
12003 }
12004
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000012005 if (mlo_si.links[i].data.avg_beacon_signal) {
12006 ret = os_snprintf(
12007 pos, end - pos, "AVG_BEACON_RSSI=%d\n",
12008 mlo_si.links[i].data.avg_beacon_signal);
Sunil Ravi89eba102022-09-13 21:04:37 -070012009 if (os_snprintf_error(end - pos, ret))
12010 return -1;
12011 pos += ret;
12012 }
12013 }
12014
12015 return pos - buf;
12016}
12017
12018
12019static int wpas_ctrl_iface_mlo_status(struct wpa_supplicant *wpa_s,
12020 char *buf, size_t buflen)
12021{
12022 int ret, i;
12023 char *pos, *end;
12024
12025 if (!wpa_s->valid_links)
12026 return -1;
12027
12028 pos = buf;
12029 end = buf + buflen;
12030
12031 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
12032 if (!(wpa_s->valid_links & BIT(i)))
12033 continue;
12034
12035 ret = os_snprintf(pos, end - pos, "link_id=%d\nfreq=%u\n"
12036 "ap_link_addr=" MACSTR
12037 "\nsta_link_addr=" MACSTR "\n",
12038 i, wpa_s->links[i].freq,
12039 MAC2STR(wpa_s->links[i].bssid),
12040 MAC2STR(wpa_s->links[i].addr));
12041 if (os_snprintf_error(end - pos, ret))
12042 return pos - buf;
12043 pos += ret;
12044 }
12045
12046 return pos - buf;
12047}
12048
12049
Sunil Ravi2a14cf12023-11-21 00:54:38 +000012050#ifdef CONFIG_TESTING_OPTIONS
12051static int wpas_ctrl_ml_probe(struct wpa_supplicant *wpa_s, char *cmd)
12052{
12053 char *token, *context = NULL;
12054 u8 bssid[ETH_ALEN];
12055 int mld_id = -1, link_id = -1;
12056 struct wpa_bss *bss;
12057 int *freqs;
12058
12059 os_memset(bssid, 0, sizeof(bssid));
12060
12061 while ((token = str_token(cmd, " ", &context))) {
12062 if (os_strncmp(token, "bssid=", 6) == 0) {
12063 if (hwaddr_aton(token + 6, bssid))
12064 return -1;
12065 } else if (os_strncmp(token, "mld_id=", 7) == 0) {
12066 mld_id = atoi(token + 7);
12067 } else if (os_strncmp(token, "link_id=", 8) == 0) {
12068 link_id = atoi(token + 8);
12069 }
12070 }
12071
12072 if (mld_id < 0 || is_zero_ether_addr(bssid)) {
12073 wpa_printf(MSG_DEBUG,
12074 "MLD: Failed parsing ML probe request arguments");
12075 return -1;
12076 }
12077
12078 bss = wpa_bss_get_bssid(wpa_s, bssid);
12079 if (!bss) {
12080 wpa_printf(MSG_DEBUG,
12081 "MLD: Unknown BSS for " MACSTR, MAC2STR(bssid));
12082 return -1;
12083 }
12084
12085 if (wpa_s->sched_scanning || wpa_s->scanning ||
12086 (wpa_s->wpa_state > WPA_SCANNING &&
12087 wpa_s->wpa_state != WPA_COMPLETED)) {
12088 wpa_printf(MSG_DEBUG,
12089 "MLO: Ongoing scan: Reject ML probe request");
12090 return -1;
12091 }
12092
12093 freqs = os_malloc(sizeof(int) * 2);
12094 if (!freqs)
12095 return -1;
12096
12097 freqs[0] = bss->freq;
12098 freqs[1] = 0;
12099
12100 wpa_s->manual_scan_passive = 0;
12101 wpa_s->manual_scan_use_id = 0;
12102 wpa_s->manual_scan_only_new = 0;
12103 wpa_s->scan_id_count = 0;
12104 wpa_s->scan_res_handler = scan_only_handler;
12105 os_free(wpa_s->manual_scan_freqs);
12106 wpa_s->manual_scan_freqs = freqs;
12107
12108 os_memcpy(wpa_s->ml_probe_bssid, bssid, ETH_ALEN);
12109 wpa_s->ml_probe_mld_id = mld_id;
12110 if (link_id >= 0)
12111 wpa_s->ml_probe_links = BIT(link_id);
12112
12113 wpa_s->normal_scans = 0;
12114 wpa_s->scan_req = MANUAL_SCAN_REQ;
12115 wpa_s->after_wps = 0;
12116 wpa_s->known_wps_freq = 0;
12117 wpa_supplicant_req_scan(wpa_s, 0, 0);
12118
12119 return 0;
12120}
12121#endif /* CONFIG_TESTING_OPTIONS */
12122
12123
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012124char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
12125 char *buf, size_t *resp_len)
12126{
12127 char *reply;
12128 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012129 int reply_len;
12130
12131 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012132 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
12133 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
12134 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012135 if (wpa_debug_show_keys)
12136 wpa_dbg(wpa_s, MSG_DEBUG,
12137 "Control interface command '%s'", buf);
12138 else
12139 wpa_dbg(wpa_s, MSG_DEBUG,
12140 "Control interface command '%s [REMOVED]'",
12141 os_strncmp(buf, WPA_CTRL_RSP,
12142 os_strlen(WPA_CTRL_RSP)) == 0 ?
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012143 WPA_CTRL_RSP :
12144 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
12145 "SET_NETWORK" : "key-add"));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012146 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
Dmitry Shmidt21de2142014-04-08 10:50:52 -070012147 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012148 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
12149 (const u8 *) buf, os_strlen(buf));
12150 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012151 int level = wpas_ctrl_cmd_debug_level(buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -070012152 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012153 }
12154
12155 reply = os_malloc(reply_size);
12156 if (reply == NULL) {
12157 *resp_len = 1;
12158 return NULL;
12159 }
12160
12161 os_memcpy(reply, "OK\n", 3);
12162 reply_len = 3;
12163
12164 if (os_strcmp(buf, "PING") == 0) {
12165 os_memcpy(reply, "PONG\n", 5);
12166 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070012167 } else if (os_strcmp(buf, "IFNAME") == 0) {
12168 reply_len = os_strlen(wpa_s->ifname);
12169 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012170 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
12171 if (wpa_debug_reopen_file() < 0)
12172 reply_len = -1;
12173 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
12174 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
12175 } else if (os_strcmp(buf, "MIB") == 0) {
12176 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
12177 if (reply_len >= 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012178 reply_len += eapol_sm_get_mib(wpa_s->eapol,
12179 reply + reply_len,
12180 reply_size - reply_len);
Hai Shalom74f70d42019-02-11 14:42:39 -080012181#ifdef CONFIG_MACSEC
12182 reply_len += ieee802_1x_kay_get_mib(
12183 wpa_s->kay, reply + reply_len,
12184 reply_size - reply_len);
12185#endif /* CONFIG_MACSEC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012186 }
12187 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
12188 reply_len = wpa_supplicant_ctrl_iface_status(
12189 wpa_s, buf + 6, reply, reply_size);
12190 } else if (os_strcmp(buf, "PMKSA") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070012191 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070012192 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070012193 wpas_ctrl_iface_pmksa_flush(wpa_s);
Dmitry Shmidt29333592017-01-09 12:27:11 -080012194#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
12195 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
12196 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
12197 reply, reply_size);
12198 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
12199 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
12200 reply_len = -1;
Paul Stewart092955c2017-02-06 09:13:09 -080012201#ifdef CONFIG_MESH
12202 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
12203 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
12204 reply, reply_size);
12205 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
12206 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
12207 reply_len = -1;
12208#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080012209#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012210 } else if (os_strncmp(buf, "SET ", 4) == 0) {
12211 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
12212 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012213 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
12214 reply_len = wpa_config_dump_values(wpa_s->conf,
12215 reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012216 } else if (os_strncmp(buf, "GET ", 4) == 0) {
12217 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
12218 reply, reply_size);
12219 } else if (os_strcmp(buf, "LOGON") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070012220 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012221 } else if (os_strcmp(buf, "LOGOFF") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070012222 eapol_sm_notify_logoff(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012223 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
12224 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
12225 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012226 else
12227 wpas_request_connection(wpa_s);
Dmitry Shmidt98660862014-03-11 17:26:21 -070012228 } else if (os_strcmp(buf, "REATTACH") == 0) {
12229 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
12230 !wpa_s->current_ssid)
12231 reply_len = -1;
12232 else {
12233 wpa_s->reattach = 1;
12234 wpas_request_connection(wpa_s);
12235 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012236 } else if (os_strcmp(buf, "RECONNECT") == 0) {
12237 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
12238 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012239 else if (wpa_s->disconnected)
12240 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012241#ifdef IEEE8021X_EAPOL
12242 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
12243 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
12244 reply_len = -1;
12245#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012246#ifdef CONFIG_IEEE80211R
12247 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
12248 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
12249 reply_len = -1;
12250#endif /* CONFIG_IEEE80211R */
12251#ifdef CONFIG_WPS
12252 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
12253 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
12254 if (res == -2) {
12255 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12256 reply_len = 17;
12257 } else if (res)
12258 reply_len = -1;
12259 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
12260 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
12261 if (res == -2) {
12262 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12263 reply_len = 17;
12264 } else if (res)
12265 reply_len = -1;
12266 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
12267 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
12268 reply,
12269 reply_size);
12270 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
12271 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
12272 wpa_s, buf + 14, reply, reply_size);
12273 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
12274 if (wpas_wps_cancel(wpa_s))
12275 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012276#ifdef CONFIG_WPS_NFC
12277 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
12278 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
12279 reply_len = -1;
12280 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
12281 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
12282 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -080012283 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
12284 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
12285 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012286 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
12287 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
12288 wpa_s, buf + 14, reply, reply_size);
12289 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
12290 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
12291 buf + 17))
12292 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012293 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
12294 reply_len = wpas_ctrl_nfc_get_handover_req(
12295 wpa_s, buf + 21, reply, reply_size);
12296 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
12297 reply_len = wpas_ctrl_nfc_get_handover_sel(
12298 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -080012299 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
12300 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
12301 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012302#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012303 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
12304 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
12305 reply_len = -1;
12306#ifdef CONFIG_AP
12307 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
12308 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
12309 wpa_s, buf + 11, reply, reply_size);
12310#endif /* CONFIG_AP */
12311#ifdef CONFIG_WPS_ER
12312 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
12313 if (wpas_wps_er_start(wpa_s, NULL))
12314 reply_len = -1;
12315 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
12316 if (wpas_wps_er_start(wpa_s, buf + 13))
12317 reply_len = -1;
12318 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012319 wpas_wps_er_stop(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012320 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
12321 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
12322 reply_len = -1;
12323 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
12324 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
12325 if (ret == -2) {
12326 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12327 reply_len = 17;
12328 } else if (ret == -3) {
12329 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
12330 reply_len = 18;
12331 } else if (ret == -4) {
12332 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
12333 reply_len = 20;
12334 } else if (ret)
12335 reply_len = -1;
12336 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
12337 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
12338 reply_len = -1;
12339 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
12340 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
12341 buf + 18))
12342 reply_len = -1;
12343 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
12344 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
12345 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012346#ifdef CONFIG_WPS_NFC
12347 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
12348 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
12349 wpa_s, buf + 24, reply, reply_size);
12350#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012351#endif /* CONFIG_WPS_ER */
12352#endif /* CONFIG_WPS */
12353#ifdef CONFIG_IBSS_RSN
12354 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
12355 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
12356 reply_len = -1;
12357#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012358#ifdef CONFIG_MESH
12359 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
12360 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
12361 wpa_s, buf + 19, reply, reply_size);
12362 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
12363 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
12364 wpa_s, "", reply, reply_size);
12365 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
12366 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
12367 reply_len = -1;
12368 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
12369 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
12370 buf + 18))
12371 reply_len = -1;
Dmitry Shmidte4663042016-04-04 10:07:49 -070012372 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
12373 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
12374 reply_len = -1;
12375 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
12376 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
12377 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070012378 } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) {
12379 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16))
12380 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012381#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012382#ifdef CONFIG_P2P
12383 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012384 if (p2p_ctrl_find(wpa_s, buf + 8))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012385 reply_len = -1;
12386 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
12387 if (p2p_ctrl_find(wpa_s, ""))
12388 reply_len = -1;
12389 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
12390 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012391 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
12392 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
12393 reply_len = -1;
12394 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
12395 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
12396 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012397 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
12398 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
12399 reply_size);
12400 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
12401 if (p2p_ctrl_listen(wpa_s, buf + 11))
12402 reply_len = -1;
12403 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
12404 if (p2p_ctrl_listen(wpa_s, ""))
12405 reply_len = -1;
12406 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
12407 if (wpas_p2p_group_remove(wpa_s, buf + 17))
12408 reply_len = -1;
12409 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070012410 if (p2p_ctrl_group_add(wpa_s, ""))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012411 reply_len = -1;
12412 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
12413 if (p2p_ctrl_group_add(wpa_s, buf + 14))
12414 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070012415 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
12416 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
12417 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012418 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
12419 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
12420 reply_len = -1;
12421 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
12422 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
12423 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
12424 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
12425 reply_size);
12426 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
12427 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
12428 reply_len = -1;
12429 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
12430 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
12431 reply_len = -1;
12432 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
12433 wpas_p2p_sd_service_update(wpa_s);
12434 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
12435 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
12436 reply_len = -1;
12437 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
12438 wpas_p2p_service_flush(wpa_s);
12439 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
12440 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
12441 reply_len = -1;
12442 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
12443 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
12444 reply_len = -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012445 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
12446 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
12447 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012448 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
12449 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
12450 reply_len = -1;
12451 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
12452 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
12453 reply_len = -1;
12454 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
12455 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
12456 reply_size);
12457 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
12458 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
12459 reply_len = -1;
12460 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -070012461 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012462 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
12463 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
12464 reply_len = -1;
12465 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
12466 if (wpas_p2p_cancel(wpa_s))
12467 reply_len = -1;
12468 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
12469 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
12470 reply_len = -1;
12471 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
12472 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
12473 reply_len = -1;
12474 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
12475 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
12476 reply_len = -1;
12477 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
12478 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
12479 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070012480 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
12481 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
12482 reply_len = -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070012483 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
12484 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
12485 reply_len = -1;
12486 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
12487 if (wpas_p2p_lo_stop(wpa_s))
12488 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012489#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070012490#ifdef CONFIG_WIFI_DISPLAY
12491 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
12492 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
12493 reply_len = -1;
12494 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
12495 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
12496 reply, reply_size);
12497#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012498#ifdef CONFIG_INTERWORKING
12499 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
12500 if (interworking_fetch_anqp(wpa_s) < 0)
12501 reply_len = -1;
12502 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
12503 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012504 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
12505 if (ctrl_interworking_select(wpa_s, NULL) < 0)
12506 reply_len = -1;
12507 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
12508 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012509 reply_len = -1;
12510 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012511 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012512 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012513 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
12514 int id;
12515
12516 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
12517 if (id < 0)
12518 reply_len = -1;
12519 else {
12520 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
12521 if (os_snprintf_error(reply_size, reply_len))
12522 reply_len = -1;
12523 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012524 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
12525 if (get_anqp(wpa_s, buf + 9) < 0)
12526 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070012527 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
12528 if (gas_request(wpa_s, buf + 12) < 0)
12529 reply_len = -1;
12530 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
12531 reply_len = gas_response_get(wpa_s, buf + 17, reply,
12532 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012533#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -070012534#ifdef CONFIG_HS20
12535 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
12536 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
12537 reply_len = -1;
12538 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
12539 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
12540 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080012541 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080012542 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
12543 reply_len = -1;
12544 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
12545 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
12546 reply_len = -1;
12547 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
12548 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
12549 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
12550 if (del_hs20_icon(wpa_s, buf + 14) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080012551 reply_len = -1;
12552 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070012553 if (hs20_fetch_osu(wpa_s, 0) < 0)
12554 reply_len = -1;
12555 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
12556 if (hs20_fetch_osu(wpa_s, 1) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080012557 reply_len = -1;
12558 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
12559 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012560#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012561 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
12562 {
12563 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
12564 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
12565 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -070012566 else {
12567 /*
12568 * Notify response from timeout to allow the control
12569 * interface response to be sent first.
12570 */
12571 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
12572 wpa_s, NULL);
12573 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012574 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
12575 if (wpa_supplicant_reload_configuration(wpa_s))
12576 reply_len = -1;
12577 } else if (os_strcmp(buf, "TERMINATE") == 0) {
12578 wpa_supplicant_terminate_proc(wpa_s->global);
12579 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
12580 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
12581 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080012582 } else if (os_strncmp(buf, "BSSID_IGNORE", 12) == 0) {
12583 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
12584 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidte19501d2011-03-16 14:32:18 -070012585 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -080012586 /* deprecated backwards compatibility alias for BSSID_IGNORE */
12587 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012588 wpa_s, buf + 9, reply, reply_size);
12589 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
12590 reply_len = wpa_supplicant_ctrl_iface_log_level(
12591 wpa_s, buf + 9, reply, reply_size);
Vinit Deshpandeda134e92014-12-02 10:59:29 -080012592 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
12593 reply_len = wpa_supplicant_ctrl_iface_list_networks(
12594 wpa_s, buf + 14, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012595 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
12596 reply_len = wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -080012597 wpa_s, NULL, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012598 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070012599 wpas_request_disconnection(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012600 } else if (os_strcmp(buf, "SCAN") == 0) {
12601 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
12602 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
12603 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012604 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
12605 reply_len = wpa_supplicant_ctrl_iface_scan_results(
12606 wpa_s, reply, reply_size);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080012607 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
12608 if (wpas_abort_ongoing_scan(wpa_s) < 0)
12609 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012610 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
12611 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
12612 reply_len = -1;
12613 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
12614 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
12615 reply_len = -1;
12616 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
12617 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
12618 reply_len = -1;
12619 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
12620 reply_len = wpa_supplicant_ctrl_iface_add_network(
12621 wpa_s, reply, reply_size);
12622 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
12623 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
12624 reply_len = -1;
12625 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
12626 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
12627 reply_len = -1;
12628 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
12629 reply_len = wpa_supplicant_ctrl_iface_get_network(
12630 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt684785c2014-05-12 13:34:29 -070012631 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012632 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
12633 wpa_s))
Dmitry Shmidt684785c2014-05-12 13:34:29 -070012634 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012635 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
12636 reply_len = wpa_supplicant_ctrl_iface_list_creds(
12637 wpa_s, reply, reply_size);
12638 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
12639 reply_len = wpa_supplicant_ctrl_iface_add_cred(
12640 wpa_s, reply, reply_size);
12641 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
12642 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
12643 reply_len = -1;
12644 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
12645 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
12646 reply_len = -1;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -070012647 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
12648 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
12649 reply,
12650 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012651#ifndef CONFIG_NO_CONFIG_WRITE
12652 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
12653 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
12654 reply_len = -1;
12655#endif /* CONFIG_NO_CONFIG_WRITE */
12656 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
12657 reply_len = wpa_supplicant_ctrl_iface_get_capability(
12658 wpa_s, buf + 15, reply, reply_size);
12659 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
12660 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
12661 reply_len = -1;
12662 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
12663 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
12664 reply_len = -1;
12665 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
12666 reply_len = wpa_supplicant_global_iface_list(
12667 wpa_s->global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080012668 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012669 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080012670 wpa_s->global, buf + 10, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012671 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
12672 reply_len = wpa_supplicant_ctrl_iface_bss(
12673 wpa_s, buf + 4, reply, reply_size);
12674#ifdef CONFIG_AP
12675 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
12676 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
12677 } else if (os_strncmp(buf, "STA ", 4) == 0) {
12678 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
12679 reply_size);
12680 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
12681 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
12682 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012683 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
12684 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
12685 reply_len = -1;
12686 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
12687 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
12688 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080012689 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
12690 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
12691 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012692 } else if (os_strcmp(buf, "STOP_AP") == 0) {
12693 if (wpas_ap_stop_ap(wpa_s))
12694 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080012695 } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) {
12696 if (wpas_ap_update_beacon(wpa_s))
12697 reply_len = -1;
Sunil Ravia04bd252022-05-02 22:54:18 -070012698 } else if (os_strncmp(buf, "ACCEPT_ACL ", 11) == 0) {
12699 if (os_strncmp(buf + 11, "ADD_MAC ", 8) == 0) {
12700 if (ap_ctrl_iface_acl_add_mac(wpa_s,
12701 DENY_UNLESS_ACCEPTED,
12702 buf + 19) ||
12703 ap_ctrl_iface_set_acl(wpa_s))
12704 reply_len = -1;
12705 } else if (os_strncmp((buf + 11), "DEL_MAC ", 8) == 0) {
12706 if (ap_ctrl_iface_acl_del_mac(wpa_s,
12707 DENY_UNLESS_ACCEPTED,
12708 buf + 19) ||
12709 ap_ctrl_iface_set_acl(wpa_s) ||
12710 ap_ctrl_iface_disassoc_accept_mac(wpa_s))
12711 reply_len = -1;
12712 } else if (os_strcmp(buf + 11, "SHOW") == 0) {
12713 reply_len = ap_ctrl_iface_acl_show_mac(
12714 wpa_s, DENY_UNLESS_ACCEPTED,
12715 reply, reply_size);
12716 } else if (os_strcmp(buf + 11, "CLEAR") == 0) {
12717 ap_ctrl_iface_acl_clear_list(wpa_s,
12718 DENY_UNLESS_ACCEPTED);
12719 if (ap_ctrl_iface_set_acl(wpa_s) ||
12720 ap_ctrl_iface_disassoc_accept_mac(wpa_s))
12721 reply_len = -1;
12722 } else {
12723 reply_len = -1;
12724 }
12725 } else if (os_strncmp(buf, "DENY_ACL ", 9) == 0) {
12726 if (os_strncmp(buf + 9, "ADD_MAC ", 8) == 0) {
12727 if (ap_ctrl_iface_acl_add_mac(wpa_s,
12728 ACCEPT_UNLESS_DENIED,
12729 buf + 17) ||
12730 ap_ctrl_iface_set_acl(wpa_s) ||
12731 ap_ctrl_iface_disassoc_deny_mac(wpa_s))
12732 reply_len = -1;
12733 } else if (os_strncmp(buf + 9, "DEL_MAC ", 8) == 0) {
12734 if (ap_ctrl_iface_acl_del_mac(wpa_s,
12735 ACCEPT_UNLESS_DENIED,
12736 buf + 17) ||
12737 ap_ctrl_iface_set_acl(wpa_s))
12738 reply_len = -1;
12739 } else if (os_strcmp(buf + 9, "SHOW") == 0) {
12740 reply_len = ap_ctrl_iface_acl_show_mac(
12741 wpa_s, ACCEPT_UNLESS_DENIED, reply, reply_size);
12742 } else if (os_strcmp(buf + 9, "CLEAR") == 0) {
12743 ap_ctrl_iface_acl_clear_list(wpa_s,
12744 ACCEPT_UNLESS_DENIED);
12745 if (ap_ctrl_iface_set_acl(wpa_s))
12746 reply_len = -1;
12747 } else {
12748 reply_len = -1;
12749 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012750#endif /* CONFIG_AP */
12751 } else if (os_strcmp(buf, "SUSPEND") == 0) {
12752 wpas_notify_suspend(wpa_s->global);
12753 } else if (os_strcmp(buf, "RESUME") == 0) {
12754 wpas_notify_resume(wpa_s->global);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070012755#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012756 } else if (os_strcmp(buf, "DROP_SA") == 0) {
12757 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070012758#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012759 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
12760 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
12761 reply_len = -1;
12762 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012763 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012764 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
12765 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
12766 reply_len = -1;
12767 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
12768 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
12769 buf + 17))
12770 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -070012771 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012772 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012773#ifdef CONFIG_TDLS
12774 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
12775 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
12776 reply_len = -1;
12777 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
12778 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
12779 reply_len = -1;
12780 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
12781 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
12782 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012783 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
12784 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
12785 buf + 17))
12786 reply_len = -1;
12787 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
12788 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
12789 buf + 24))
12790 reply_len = -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -070012791 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
12792 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
12793 wpa_s, buf + 17, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012794#endif /* CONFIG_TDLS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012795 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
12796 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
12797 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
12798 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
12799 reply_len = -1;
12800 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
12801 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
12802 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012803 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
12804 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
12805 reply_size);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080012806 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
12807 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
12808 reply_len = -1;
Yuhao Zhengfcd6f212012-07-27 10:37:52 -070012809 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
12810 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
12811 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012812#ifdef CONFIG_AUTOSCAN
12813 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
12814 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
12815 reply_len = -1;
12816#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070012817 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
12818 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
12819 reply_size);
Hai Shalomb755a2a2020-04-23 21:49:02 -070012820 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
12821 reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply,
12822 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080012823#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -070012824 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
12825 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
12826 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080012827#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080012828 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
12829 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
12830 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012831 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012832 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012833 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080012834#ifdef CONFIG_WNM
12835 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
12836 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
12837 reply_len = -1;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080012838 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
12839 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
Dmitry Shmidt44c95782013-05-17 09:51:35 -070012840 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -080012841 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
12842 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
12843 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080012844#endif /* CONFIG_WNM */
Sunil Ravia04bd252022-05-02 22:54:18 -070012845#ifdef CONFIG_WNM_AP
12846 } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
12847 if (ap_ctrl_iface_disassoc_imminent(wpa_s, buf + 18))
12848 reply_len = -1;
12849 } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
12850 if (ap_ctrl_iface_ess_disassoc(wpa_s, buf + 13))
12851 reply_len = -1;
12852 } else if (os_strncmp(buf, "BSS_TM_REQ ", 11) == 0) {
12853 if (ap_ctrl_iface_bss_tm_req(wpa_s, buf + 11))
12854 reply_len = -1;
12855#endif /* CONFIG_WNM_AP */
Dmitry Shmidt444d5672013-04-01 13:08:44 -070012856 } else if (os_strcmp(buf, "FLUSH") == 0) {
12857 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012858 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
12859 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
12860 reply_size);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070012861#ifdef CONFIG_TESTING_OPTIONS
12862 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
12863 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
12864 reply_len = -1;
12865 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
12866 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070012867 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
12868 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
12869 reply_len = -1;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -070012870 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
12871 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
12872 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012873 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
12874 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
12875 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080012876 } else if (os_strncmp(buf, "EAPOL_TX ", 9) == 0) {
12877 if (wpas_ctrl_iface_eapol_tx(wpa_s, buf + 9) < 0)
12878 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012879 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
12880 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
12881 reply_len = -1;
12882 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
12883 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
12884 reply_len = -1;
12885 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
12886 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
12887 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -080012888 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
12889 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
12890 reply_len = -1;
12891 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
12892 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012893 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
12894 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
12895 reply_len = -1;
12896 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
12897 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
Jouni Malinenc4818362015-10-04 11:45:13 +030012898 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
12899 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
12900 reply_len = -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080012901 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
12902 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
12903 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012904 } else if (os_strcmp(buf, "RESET_PN") == 0) {
12905 if (wpas_ctrl_reset_pn(wpa_s) < 0)
12906 reply_len = -1;
12907 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
12908 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
12909 reply_len = -1;
12910 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
12911 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
12912 reply_len = -1;
Hai Shalom74f70d42019-02-11 14:42:39 -080012913 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
12914 sme_event_unprot_disconnect(
12915 wpa_s, wpa_s->bssid, NULL,
12916 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
Hai Shaloma20dcd72022-02-04 13:43:00 -080012917 } else if (os_strncmp(buf, "TWT_SETUP ", 10) == 0) {
12918 if (wpas_ctrl_iface_send_twt_setup(wpa_s, buf + 9))
12919 reply_len = -1;
12920 } else if (os_strcmp(buf, "TWT_SETUP") == 0) {
12921 if (wpas_ctrl_iface_send_twt_setup(wpa_s, ""))
12922 reply_len = -1;
12923 } else if (os_strncmp(buf, "TWT_TEARDOWN ", 13) == 0) {
12924 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, buf + 12))
12925 reply_len = -1;
12926 } else if (os_strcmp(buf, "TWT_TEARDOWN") == 0) {
12927 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, ""))
12928 reply_len = -1;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000012929 } else if (os_strncmp(buf, "ML_PROBE_REQ ", 13) == 0) {
12930 if (wpas_ctrl_ml_probe(wpa_s, buf + 13))
12931 reply_len = -1;
Dmitry Shmidt818ea482014-03-10 13:15:21 -070012932#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070012933 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
12934 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
12935 reply_len = -1;
12936 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
12937 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
12938 reply_size);
12939 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
12940 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
12941 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012942 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -070012943 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012944 reply_len = -1;
12945 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
12946 wpas_ctrl_iface_erp_flush(wpa_s);
12947 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
12948 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
12949 reply_len = -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012950 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
12951 reply_len = wpas_ctrl_iface_get_pref_freq_list(
12952 wpa_s, buf + 19, reply, reply_size);
Paul Stewart092955c2017-02-06 09:13:09 -080012953#ifdef CONFIG_FILS
12954 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
12955 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
12956 reply_len = -1;
12957 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
12958 wpas_flush_fils_hlp_req(wpa_s);
12959#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012960#ifdef CONFIG_DPP
12961 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
12962 int res;
12963
12964 res = wpas_dpp_qr_code(wpa_s, buf + 12);
12965 if (res < 0) {
12966 reply_len = -1;
12967 } else {
12968 reply_len = os_snprintf(reply, reply_size, "%d", res);
12969 if (os_snprintf_error(reply_size, reply_len))
12970 reply_len = -1;
12971 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080012972 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
12973 int res;
12974
12975 res = wpas_dpp_nfc_uri(wpa_s, buf + 12);
12976 if (res < 0) {
12977 reply_len = -1;
12978 } else {
12979 reply_len = os_snprintf(reply, reply_size, "%d", res);
12980 if (os_snprintf_error(reply_size, reply_len))
12981 reply_len = -1;
12982 }
Hai Shalomfdcde762020-04-02 11:19:20 -070012983 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
12984 int res;
12985
12986 res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20);
12987 if (res < 0) {
12988 reply_len = -1;
12989 } else {
12990 reply_len = os_snprintf(reply, reply_size, "%d", res);
12991 if (os_snprintf_error(reply_size, reply_len))
12992 reply_len = -1;
12993 }
12994 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
12995 int res;
12996
12997 res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20);
12998 if (res < 0) {
12999 reply_len = -1;
13000 } else {
13001 reply_len = os_snprintf(reply, reply_size, "%d", res);
13002 if (os_snprintf_error(reply_size, reply_len))
13003 reply_len = -1;
13004 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013005 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
13006 int res;
13007
Hai Shalom021b0b52019-04-10 11:17:58 -070013008 res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013009 if (res < 0) {
13010 reply_len = -1;
13011 } else {
13012 reply_len = os_snprintf(reply, reply_size, "%d", res);
13013 if (os_snprintf_error(reply_size, reply_len))
13014 reply_len = -1;
13015 }
13016 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070013017 if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013018 reply_len = -1;
13019 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
13020 const char *uri;
13021
Hai Shalom021b0b52019-04-10 11:17:58 -070013022 uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013023 if (!uri) {
13024 reply_len = -1;
13025 } else {
13026 reply_len = os_snprintf(reply, reply_size, "%s", uri);
13027 if (os_snprintf_error(reply_size, reply_len))
13028 reply_len = -1;
13029 }
13030 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070013031 reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19),
13032 reply, reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -070013033 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
13034 if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18),
13035 os_strchr(buf + 18, ' ')) < 0)
13036 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013037 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
13038 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
13039 reply_len = -1;
13040 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
13041 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
13042 reply_len = -1;
13043 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -070013044 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013045 wpas_dpp_listen_stop(wpa_s);
13046 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
13047 int res;
13048
Hai Shalom021b0b52019-04-10 11:17:58 -070013049 res = dpp_configurator_add(wpa_s->dpp, buf + 20);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013050 if (res < 0) {
13051 reply_len = -1;
13052 } else {
13053 reply_len = os_snprintf(reply, reply_size, "%d", res);
13054 if (os_snprintf_error(reply_size, reply_len))
13055 reply_len = -1;
13056 }
Sunil Ravia04bd252022-05-02 22:54:18 -070013057 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SET ", 21) == 0) {
13058 if (dpp_configurator_set(wpa_s->dpp, buf + 20) < 0)
13059 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013060 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070013061 if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013062 reply_len = -1;
13063 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -080013064 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013065 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -070013066 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070013067 reply_len = dpp_configurator_get_key_id(wpa_s->dpp,
13068 atoi(buf + 25),
13069 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013070 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
13071 int res;
13072
13073 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
13074 if (res < 0) {
13075 reply_len = -1;
13076 } else {
13077 reply_len = os_snprintf(reply, reply_size, "%d", res);
13078 if (os_snprintf_error(reply_size, reply_len))
13079 reply_len = -1;
13080 }
13081 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
13082 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
13083 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080013084 } else if (os_strncmp(buf, "DPP_CONF_SET ", 13) == 0) {
13085 if (wpas_dpp_conf_set(wpa_s, buf + 12) < 0)
13086 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070013087#ifdef CONFIG_DPP2
13088 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
13089 if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0)
13090 reply_len = -1;
13091 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
13092 if (wpas_dpp_controller_start(wpa_s, NULL) < 0)
13093 reply_len = -1;
13094 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
13095 dpp_controller_stop(wpa_s->dpp);
Hai Shalomfdcde762020-04-02 11:19:20 -070013096 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
13097 if (wpas_dpp_chirp(wpa_s, buf + 9) < 0)
13098 reply_len = -1;
13099 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
13100 wpas_dpp_chirp_stop(wpa_s);
Hai Shalom4fbc08f2020-05-18 12:37:00 -070013101 } else if (os_strncmp(buf, "DPP_RECONFIG ", 13) == 0) {
Hai Shalom899fcc72020-10-19 14:38:18 -070013102 if (wpas_dpp_reconfig(wpa_s, buf + 13) < 0)
13103 reply_len = -1;
13104 } else if (os_strncmp(buf, "DPP_CA_SET ", 11) == 0) {
13105 if (wpas_dpp_ca_set(wpa_s, buf + 10) < 0)
Hai Shalom4fbc08f2020-05-18 12:37:00 -070013106 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070013107#endif /* CONFIG_DPP2 */
Sunil Ravi89eba102022-09-13 21:04:37 -070013108#ifdef CONFIG_DPP3
13109 } else if (os_strcmp(buf, "DPP_PUSH_BUTTON") == 0) {
13110 if (wpas_dpp_push_button(wpa_s, NULL) < 0)
13111 reply_len = -1;
13112 } else if (os_strncmp(buf, "DPP_PUSH_BUTTON ", 16) == 0) {
13113 if (wpas_dpp_push_button(wpa_s, buf + 15) < 0)
13114 reply_len = -1;
13115#endif /* CONFIG_DPP3 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013116#endif /* CONFIG_DPP */
Hai Shalom899fcc72020-10-19 14:38:18 -070013117 } else if (os_strncmp(buf, "MSCS ", 5) == 0) {
13118 if (wpas_ctrl_iface_configure_mscs(wpa_s, buf + 5))
13119 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080013120#ifdef CONFIG_PASN
13121 } else if (os_strncmp(buf, "PASN_START ", 11) == 0) {
13122 if (wpas_ctrl_iface_pasn_start(wpa_s, buf + 11) < 0)
13123 reply_len = -1;
13124 } else if (os_strcmp(buf, "PASN_STOP") == 0) {
13125 wpas_pasn_auth_stop(wpa_s);
13126 } else if (os_strcmp(buf, "PTKSA_CACHE_LIST") == 0) {
13127 reply_len = ptksa_cache_list(wpa_s->ptksa, reply, reply_size);
Hai Shaloma20dcd72022-02-04 13:43:00 -080013128 } else if (os_strncmp(buf, "PASN_DEAUTH ", 12) == 0) {
13129 if (wpas_ctrl_iface_pasn_deauthenticate(wpa_s, buf + 12) < 0)
13130 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080013131#endif /* CONFIG_PASN */
Hai Shaloma20dcd72022-02-04 13:43:00 -080013132 } else if (os_strncmp(buf, "SCS ", 4) == 0) {
13133 if (wpas_ctrl_iface_configure_scs(wpa_s, buf + 4))
13134 reply_len = -1;
13135 } else if (os_strncmp(buf, "DSCP_RESP ", 10) == 0) {
13136 if (wpas_ctrl_iface_send_dscp_resp(wpa_s, buf + 10))
13137 reply_len = -1;
13138 } else if (os_strncmp(buf, "DSCP_QUERY ", 11) == 0) {
13139 if (wpas_ctrl_iface_send_dscp_query(wpa_s, buf + 11))
13140 reply_len = -1;
Sunil Ravi89eba102022-09-13 21:04:37 -070013141 } else if (os_strcmp(buf, "MLO_STATUS") == 0) {
13142 reply_len = wpas_ctrl_iface_mlo_status(wpa_s, reply,
13143 reply_size);
13144 } else if (os_strcmp(buf, "MLO_SIGNAL_POLL") == 0) {
13145 reply_len = wpas_ctrl_iface_mlo_signal_poll(wpa_s, reply,
13146 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013147 } else {
13148 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
13149 reply_len = 16;
13150 }
13151
13152 if (reply_len < 0) {
13153 os_memcpy(reply, "FAIL\n", 5);
13154 reply_len = 5;
13155 }
13156
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013157 *resp_len = reply_len;
13158 return reply;
13159}
13160
13161
13162static int wpa_supplicant_global_iface_add(struct wpa_global *global,
13163 char *cmd)
13164{
13165 struct wpa_interface iface;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013166 char *pos, *extra;
13167 struct wpa_supplicant *wpa_s;
13168 unsigned int create_iface = 0;
13169 u8 mac_addr[ETH_ALEN];
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013170 enum wpa_driver_if_type type = WPA_IF_STATION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013171
13172 /*
13173 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013174 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013175 */
13176 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
13177
13178 os_memset(&iface, 0, sizeof(iface));
13179
13180 do {
13181 iface.ifname = pos = cmd;
13182 pos = os_strchr(pos, '\t');
13183 if (pos)
13184 *pos++ = '\0';
13185 if (iface.ifname[0] == '\0')
13186 return -1;
13187 if (pos == NULL)
13188 break;
13189
13190 iface.confname = pos;
13191 pos = os_strchr(pos, '\t');
13192 if (pos)
13193 *pos++ = '\0';
13194 if (iface.confname[0] == '\0')
13195 iface.confname = NULL;
13196 if (pos == NULL)
13197 break;
13198
13199 iface.driver = pos;
13200 pos = os_strchr(pos, '\t');
13201 if (pos)
13202 *pos++ = '\0';
13203 if (iface.driver[0] == '\0')
13204 iface.driver = NULL;
13205 if (pos == NULL)
13206 break;
13207
13208 iface.ctrl_interface = pos;
13209 pos = os_strchr(pos, '\t');
13210 if (pos)
13211 *pos++ = '\0';
13212 if (iface.ctrl_interface[0] == '\0')
13213 iface.ctrl_interface = NULL;
13214 if (pos == NULL)
13215 break;
13216
13217 iface.driver_param = pos;
13218 pos = os_strchr(pos, '\t');
13219 if (pos)
13220 *pos++ = '\0';
13221 if (iface.driver_param[0] == '\0')
13222 iface.driver_param = NULL;
13223 if (pos == NULL)
13224 break;
13225
13226 iface.bridge_ifname = pos;
13227 pos = os_strchr(pos, '\t');
13228 if (pos)
13229 *pos++ = '\0';
13230 if (iface.bridge_ifname[0] == '\0')
13231 iface.bridge_ifname = NULL;
13232 if (pos == NULL)
13233 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013234
13235 extra = pos;
13236 pos = os_strchr(pos, '\t');
13237 if (pos)
13238 *pos++ = '\0';
Dmitry Shmidt83474442015-04-15 13:47:09 -070013239 if (!extra[0])
13240 break;
13241
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013242 if (os_strcmp(extra, "create") == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013243 create_iface = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013244 if (!pos)
13245 break;
13246
13247 if (os_strcmp(pos, "sta") == 0) {
13248 type = WPA_IF_STATION;
13249 } else if (os_strcmp(pos, "ap") == 0) {
13250 type = WPA_IF_AP_BSS;
13251 } else {
13252 wpa_printf(MSG_DEBUG,
13253 "INTERFACE_ADD unsupported interface type: '%s'",
13254 pos);
13255 return -1;
13256 }
13257 } else {
Dmitry Shmidt83474442015-04-15 13:47:09 -070013258 wpa_printf(MSG_DEBUG,
13259 "INTERFACE_ADD unsupported extra parameter: '%s'",
13260 extra);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013261 return -1;
Dmitry Shmidt83474442015-04-15 13:47:09 -070013262 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013263 } while (0);
13264
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013265 if (create_iface) {
13266 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
13267 iface.ifname);
13268 if (!global->ifaces)
13269 return -1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013270 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013271 NULL, NULL, NULL, mac_addr, NULL) < 0) {
13272 wpa_printf(MSG_ERROR,
13273 "CTRL_IFACE interface creation failed");
13274 return -1;
13275 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013276
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013277 wpa_printf(MSG_DEBUG,
13278 "CTRL_IFACE interface '%s' created with MAC addr: "
13279 MACSTR, iface.ifname, MAC2STR(mac_addr));
13280 }
13281
13282 if (wpa_supplicant_get_iface(global, iface.ifname))
13283 goto fail;
13284
13285 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
13286 if (!wpa_s)
13287 goto fail;
13288 wpa_s->added_vif = create_iface;
13289 return 0;
13290
13291fail:
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000013292 if (create_iface) {
13293 /* wpa_supplicant does not create multi-BSS AP, so collapse to
13294 * WPA_IF_STATION to avoid unwanted clean up in the driver. */
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013295 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000013296 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013297 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013298}
13299
13300
13301static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
13302 char *cmd)
13303{
13304 struct wpa_supplicant *wpa_s;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013305 int ret;
13306 unsigned int delete_iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013307
13308 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
13309
13310 wpa_s = wpa_supplicant_get_iface(global, cmd);
13311 if (wpa_s == NULL)
13312 return -1;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013313 delete_iface = wpa_s->added_vif;
13314 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
13315 if (!ret && delete_iface) {
13316 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
13317 cmd);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000013318 /* wpa_supplicant does not create multi-BSS AP, so collapse to
13319 * WPA_IF_STATION to avoid unwanted clean up in the driver. */
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013320 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
13321 }
13322 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013323}
13324
13325
13326static void wpa_free_iface_info(struct wpa_interface_info *iface)
13327{
13328 struct wpa_interface_info *prev;
13329
13330 while (iface) {
13331 prev = iface;
13332 iface = iface->next;
13333
13334 os_free(prev->ifname);
13335 os_free(prev->desc);
13336 os_free(prev);
13337 }
13338}
13339
13340
13341static int wpa_supplicant_global_iface_list(struct wpa_global *global,
13342 char *buf, int len)
13343{
13344 int i, res;
13345 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
13346 char *pos, *end;
13347
13348 for (i = 0; wpa_drivers[i]; i++) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070013349 const struct wpa_driver_ops *drv = wpa_drivers[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013350 if (drv->get_interfaces == NULL)
13351 continue;
13352 tmp = drv->get_interfaces(global->drv_priv[i]);
13353 if (tmp == NULL)
13354 continue;
13355
13356 if (last == NULL)
13357 iface = last = tmp;
13358 else
13359 last->next = tmp;
13360 while (last->next)
13361 last = last->next;
13362 }
13363
13364 pos = buf;
13365 end = buf + len;
13366 for (tmp = iface; tmp; tmp = tmp->next) {
13367 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
13368 tmp->drv_name, tmp->ifname,
13369 tmp->desc ? tmp->desc : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013370 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013371 *pos = '\0';
13372 break;
13373 }
13374 pos += res;
13375 }
13376
13377 wpa_free_iface_info(iface);
13378
13379 return pos - buf;
13380}
13381
13382
13383static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013384 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013385 char *buf, int len)
13386{
13387 int res;
13388 char *pos, *end;
13389 struct wpa_supplicant *wpa_s;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013390 int show_ctrl = 0;
13391
13392 if (input)
13393 show_ctrl = !!os_strstr(input, "ctrl");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013394
13395 wpa_s = global->ifaces;
13396 pos = buf;
13397 end = buf + len;
13398
13399 while (wpa_s) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013400 if (show_ctrl)
13401 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
13402 wpa_s->ifname,
13403 wpa_s->conf->ctrl_interface ?
13404 wpa_s->conf->ctrl_interface : "N/A");
13405 else
13406 res = os_snprintf(pos, end - pos, "%s\n",
13407 wpa_s->ifname);
13408
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013409 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013410 *pos = '\0';
13411 break;
13412 }
13413 pos += res;
13414 wpa_s = wpa_s->next;
13415 }
13416 return pos - buf;
13417}
13418
13419
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013420static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
13421 const char *ifname,
13422 char *cmd, size_t *resp_len)
13423{
13424 struct wpa_supplicant *wpa_s;
13425
13426 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
13427 if (os_strcmp(ifname, wpa_s->ifname) == 0)
13428 break;
13429 }
13430
13431 if (wpa_s == NULL) {
13432 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
13433 if (resp)
13434 *resp_len = os_strlen(resp);
13435 else
13436 *resp_len = 1;
13437 return resp;
13438 }
13439
13440 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
13441}
13442
13443
13444static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
13445 char *buf, size_t *resp_len)
13446{
13447#ifdef CONFIG_P2P
13448 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070013449 "LIST_NETWORKS",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013450 "P2P_FIND",
13451 "P2P_STOP_FIND",
13452 "P2P_LISTEN",
13453 "P2P_GROUP_ADD",
13454 "P2P_GET_PASSPHRASE",
13455 "P2P_SERVICE_UPDATE",
13456 "P2P_SERVICE_FLUSH",
13457 "P2P_FLUSH",
13458 "P2P_CANCEL",
13459 "P2P_PRESENCE_REQ",
13460 "P2P_EXT_LISTEN",
Paul Stewart092955c2017-02-06 09:13:09 -080013461#ifdef CONFIG_AP
13462 "STA-FIRST",
13463#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013464 NULL
13465 };
13466 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080013467#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070013468 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080013469#endif /* ANDROID */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013470 "GET_CAPABILITY ",
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070013471 "GET_NETWORK ",
13472 "REMOVE_NETWORK ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013473 "P2P_FIND ",
13474 "P2P_CONNECT ",
13475 "P2P_LISTEN ",
13476 "P2P_GROUP_REMOVE ",
13477 "P2P_GROUP_ADD ",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013478 "P2P_GROUP_MEMBER ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013479 "P2P_PROV_DISC ",
13480 "P2P_SERV_DISC_REQ ",
13481 "P2P_SERV_DISC_CANCEL_REQ ",
13482 "P2P_SERV_DISC_RESP ",
13483 "P2P_SERV_DISC_EXTERNAL ",
13484 "P2P_SERVICE_ADD ",
13485 "P2P_SERVICE_DEL ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080013486 "P2P_SERVICE_REP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013487 "P2P_REJECT ",
13488 "P2P_INVITE ",
13489 "P2P_PEER ",
13490 "P2P_SET ",
13491 "P2P_UNAUTHORIZE ",
13492 "P2P_PRESENCE_REQ ",
13493 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070013494 "P2P_REMOVE_CLIENT ",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080013495 "WPS_NFC_TOKEN ",
13496 "WPS_NFC_TAG_READ ",
Dmitry Shmidt413dde72014-04-11 10:23:22 -070013497 "NFC_GET_HANDOVER_SEL ",
13498 "NFC_GET_HANDOVER_REQ ",
13499 "NFC_REPORT_HANDOVER ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080013500 "P2P_ASP_PROVISION ",
13501 "P2P_ASP_PROVISION_RESP ",
Paul Stewart092955c2017-02-06 09:13:09 -080013502#ifdef CONFIG_AP
13503 "STA ",
13504 "STA-NEXT ",
13505#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013506 NULL
13507 };
13508 int found = 0;
13509 int i;
13510
13511 if (global->p2p_init_wpa_s == NULL)
13512 return NULL;
13513
13514 for (i = 0; !found && cmd[i]; i++) {
13515 if (os_strcmp(buf, cmd[i]) == 0)
13516 found = 1;
13517 }
13518
13519 for (i = 0; !found && prefix[i]; i++) {
13520 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
13521 found = 1;
13522 }
13523
13524 if (found)
13525 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
13526 buf, resp_len);
13527#endif /* CONFIG_P2P */
13528 return NULL;
13529}
13530
13531
13532static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
13533 char *buf, size_t *resp_len)
13534{
13535#ifdef CONFIG_WIFI_DISPLAY
13536 if (global->p2p_init_wpa_s == NULL)
13537 return NULL;
13538 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
13539 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
13540 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
13541 buf, resp_len);
13542#endif /* CONFIG_WIFI_DISPLAY */
13543 return NULL;
13544}
13545
13546
13547static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
13548 char *buf, size_t *resp_len)
13549{
13550 char *ret;
13551
13552 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
13553 if (ret)
13554 return ret;
13555
13556 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
13557 if (ret)
13558 return ret;
13559
13560 return NULL;
13561}
13562
13563
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013564static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
13565{
13566 char *value;
13567
13568 value = os_strchr(cmd, ' ');
13569 if (value == NULL)
13570 return -1;
13571 *value++ = '\0';
13572
13573 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
13574
13575#ifdef CONFIG_WIFI_DISPLAY
13576 if (os_strcasecmp(cmd, "wifi_display") == 0) {
13577 wifi_display_enable(global, !!atoi(value));
13578 return 0;
13579 }
13580#endif /* CONFIG_WIFI_DISPLAY */
13581
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013582 /* Restore cmd to its original value to allow redirection */
13583 value[-1] = ' ';
13584
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013585 return -1;
13586}
13587
13588
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013589static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
13590 char *cmd)
13591{
13592 struct wpa_supplicant *wpa_s[2]; /* src, dst */
13593 char *p;
13594 unsigned int i;
13595
13596 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
13597 * <variable name> */
13598
13599 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
13600 p = os_strchr(cmd, ' ');
13601 if (p == NULL)
13602 return -1;
13603 *p = '\0';
13604
13605 wpa_s[i] = global->ifaces;
13606 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
13607 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
13608 break;
13609 }
13610
13611 if (!wpa_s[i]) {
13612 wpa_printf(MSG_DEBUG,
13613 "CTRL_IFACE: Could not find iface=%s", cmd);
13614 return -1;
13615 }
13616
13617 cmd = p + 1;
13618 }
13619
13620 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
13621}
13622
13623
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013624#ifndef CONFIG_NO_CONFIG_WRITE
13625static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
13626{
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013627 int ret = 0, saved = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013628 struct wpa_supplicant *wpa_s;
13629
13630 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
13631 if (!wpa_s->conf->update_config) {
13632 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
13633 continue;
13634 }
13635
13636 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
13637 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
13638 ret = 1;
13639 } else {
13640 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013641 saved++;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013642 }
13643 }
13644
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013645 if (!saved && !ret) {
13646 wpa_dbg(wpa_s, MSG_DEBUG,
13647 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
13648 ret = 1;
13649 }
13650
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013651 return ret;
13652}
13653#endif /* CONFIG_NO_CONFIG_WRITE */
13654
13655
13656static int wpas_global_ctrl_iface_status(struct wpa_global *global,
13657 char *buf, size_t buflen)
13658{
13659 char *pos, *end;
13660 int ret;
13661 struct wpa_supplicant *wpa_s;
13662
13663 pos = buf;
13664 end = buf + buflen;
13665
13666#ifdef CONFIG_P2P
13667 if (global->p2p && !global->p2p_disabled) {
13668 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
13669 "\n"
13670 "p2p_state=%s\n",
13671 MAC2STR(global->p2p_dev_addr),
13672 p2p_get_state_txt(global->p2p));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013673 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013674 return pos - buf;
13675 pos += ret;
13676 } else if (global->p2p) {
13677 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013678 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013679 return pos - buf;
13680 pos += ret;
13681 }
13682#endif /* CONFIG_P2P */
13683
13684#ifdef CONFIG_WIFI_DISPLAY
13685 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
13686 !!global->wifi_display);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013687 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013688 return pos - buf;
13689 pos += ret;
13690#endif /* CONFIG_WIFI_DISPLAY */
13691
13692 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
13693 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
13694 "address=" MACSTR "\n",
13695 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013696 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013697 return pos - buf;
13698 pos += ret;
13699 }
13700
13701 return pos - buf;
13702}
13703
13704
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013705#ifdef CONFIG_FST
13706
13707static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
13708 char *cmd, char *buf,
13709 size_t reply_size)
13710{
13711 char ifname[IFNAMSIZ + 1];
13712 struct fst_iface_cfg cfg;
13713 struct wpa_supplicant *wpa_s;
13714 struct fst_wpa_obj iface_obj;
13715
13716 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
13717 wpa_s = wpa_supplicant_get_iface(global, ifname);
13718 if (wpa_s) {
13719 if (wpa_s->fst) {
13720 wpa_printf(MSG_INFO, "FST: Already attached");
13721 return -1;
13722 }
13723 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
13724 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
13725 &iface_obj, &cfg);
13726 if (wpa_s->fst)
13727 return os_snprintf(buf, reply_size, "OK\n");
13728 }
13729 }
13730
13731 return -1;
13732}
13733
13734
13735static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
13736 char *cmd, char *buf,
13737 size_t reply_size)
13738{
13739 char ifname[IFNAMSIZ + 1];
13740 struct wpa_supplicant *wpa_s;
13741
13742 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
13743 wpa_s = wpa_supplicant_get_iface(global, ifname);
13744 if (wpa_s) {
13745 if (!fst_iface_detach(ifname)) {
13746 wpa_s->fst = NULL;
13747 return os_snprintf(buf, reply_size, "OK\n");
13748 }
13749 }
13750 }
13751
13752 return -1;
13753}
13754
13755#endif /* CONFIG_FST */
13756
13757
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013758char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
13759 char *buf, size_t *resp_len)
13760{
13761 char *reply;
13762 const int reply_size = 2048;
13763 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080013764 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013765
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013766 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
13767 char *pos = os_strchr(buf + 7, ' ');
13768 if (pos) {
13769 *pos++ = '\0';
13770 return wpas_global_ctrl_iface_ifname(global,
13771 buf + 7, pos,
13772 resp_len);
13773 }
13774 }
13775
13776 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
13777 if (reply)
13778 return reply;
13779
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080013780 if (os_strcmp(buf, "PING") == 0)
13781 level = MSG_EXCESSIVE;
13782 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013783 (const u8 *) buf, os_strlen(buf));
13784
13785 reply = os_malloc(reply_size);
13786 if (reply == NULL) {
13787 *resp_len = 1;
13788 return NULL;
13789 }
13790
13791 os_memcpy(reply, "OK\n", 3);
13792 reply_len = 3;
13793
13794 if (os_strcmp(buf, "PING") == 0) {
13795 os_memcpy(reply, "PONG\n", 5);
13796 reply_len = 5;
13797 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
13798 if (wpa_supplicant_global_iface_add(global, buf + 14))
13799 reply_len = -1;
13800 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
13801 if (wpa_supplicant_global_iface_remove(global, buf + 17))
13802 reply_len = -1;
13803 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
13804 reply_len = wpa_supplicant_global_iface_list(
13805 global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013806 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013807 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013808 global, buf + 10, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013809#ifdef CONFIG_FST
13810 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
13811 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
13812 reply,
13813 reply_size);
13814 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
13815 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
13816 reply,
13817 reply_size);
13818 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
13819 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
13820#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013821 } else if (os_strcmp(buf, "TERMINATE") == 0) {
13822 wpa_supplicant_terminate_proc(global);
13823 } else if (os_strcmp(buf, "SUSPEND") == 0) {
13824 wpas_notify_suspend(global);
13825 } else if (os_strcmp(buf, "RESUME") == 0) {
13826 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013827 } else if (os_strncmp(buf, "SET ", 4) == 0) {
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013828 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
13829#ifdef CONFIG_P2P
13830 if (global->p2p_init_wpa_s) {
13831 os_free(reply);
13832 /* Check if P2P redirection would work for this
13833 * command. */
13834 return wpa_supplicant_ctrl_iface_process(
13835 global->p2p_init_wpa_s,
13836 buf, resp_len);
13837 }
13838#endif /* CONFIG_P2P */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013839 reply_len = -1;
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013840 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013841 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
13842 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
13843 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013844#ifndef CONFIG_NO_CONFIG_WRITE
13845 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
13846 if (wpas_global_ctrl_iface_save_config(global))
13847 reply_len = -1;
13848#endif /* CONFIG_NO_CONFIG_WRITE */
13849 } else if (os_strcmp(buf, "STATUS") == 0) {
13850 reply_len = wpas_global_ctrl_iface_status(global, reply,
13851 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080013852#ifdef CONFIG_MODULE_TESTS
13853 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080013854 if (wpas_module_tests() < 0)
13855 reply_len = -1;
13856#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013857 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
13858 if (wpa_debug_reopen_file() < 0)
13859 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013860 } else {
13861 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
13862 reply_len = 16;
13863 }
13864
13865 if (reply_len < 0) {
13866 os_memcpy(reply, "FAIL\n", 5);
13867 reply_len = 5;
13868 }
13869
13870 *resp_len = reply_len;
13871 return reply;
13872}