blob: 68a62da72fdff87d33e22328775003703edcdc2a [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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002970 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2971
2972 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2973 ret = os_snprintf(pos, end - pos, "-preauth");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002974 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002975 return pos;
2976 pos += ret;
2977 }
2978
2979 ret = os_snprintf(pos, end - pos, "]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002980 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002981 return pos;
2982 pos += ret;
2983
2984 return pos;
2985}
2986
2987
2988#ifdef CONFIG_WPS
2989static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2990 char *pos, char *end,
2991 struct wpabuf *wps_ie)
2992{
2993 int ret;
2994 const char *txt;
2995
2996 if (wps_ie == NULL)
2997 return pos;
2998 if (wps_is_selected_pbc_registrar(wps_ie))
2999 txt = "[WPS-PBC]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003000 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
3001 txt = "[WPS-AUTH]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003002 else if (wps_is_selected_pin_registrar(wps_ie))
3003 txt = "[WPS-PIN]";
3004 else
3005 txt = "[WPS]";
3006
3007 ret = os_snprintf(pos, end - pos, "%s", txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003008 if (!os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003009 pos += ret;
3010 wpabuf_free(wps_ie);
3011 return pos;
3012}
3013#endif /* CONFIG_WPS */
3014
3015
3016static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
3017 char *pos, char *end,
3018 const struct wpa_bss *bss)
3019{
3020#ifdef CONFIG_WPS
3021 struct wpabuf *wps_ie;
3022 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
3023 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
3024#else /* CONFIG_WPS */
3025 return pos;
3026#endif /* CONFIG_WPS */
3027}
3028
3029
3030/* Format one result on one text line into a buffer. */
3031static int wpa_supplicant_ctrl_iface_scan_result(
3032 struct wpa_supplicant *wpa_s,
3033 const struct wpa_bss *bss, char *buf, size_t buflen)
3034{
3035 char *pos, *end;
3036 int ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07003037 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe, *rsnxe;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003038
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003039 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003040 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07003041 if (!p2p)
3042 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003043 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
3044 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
3045 0)
3046 return 0; /* Do not show P2P listen discovery results here */
3047
3048 pos = buf;
3049 end = buf + buflen;
3050
3051 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
3052 MAC2STR(bss->bssid), bss->freq, bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003053 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003054 return -1;
3055 pos += ret;
3056 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3057 if (ie)
3058 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
3059 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003060 if (ie2) {
3061 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
3062 ie2, 2 + ie2[1]);
3063 }
Hai Shalom899fcc72020-10-19 14:38:18 -07003064 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003065 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
3066 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
3067 if (os_snprintf_error(end - pos, ret))
3068 return -1;
3069 pos += ret;
3070 }
3071 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
3072 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
3073 if (os_snprintf_error(end - pos, ret))
3074 return -1;
3075 pos += ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07003076 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003077 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
3078 if (osen_ie)
3079 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
3080 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003081 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
3082 if (owe) {
3083 ret = os_snprintf(pos, end - pos,
3084 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
3085 if (os_snprintf_error(end - pos, ret))
3086 return -1;
3087 pos += ret;
3088 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003089 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003090 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003091 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003092 if (os_snprintf_error(end - pos, ret))
3093 return -1;
3094 pos += ret;
3095 }
3096 if (mesh) {
3097 ret = os_snprintf(pos, end - pos, "[MESH]");
3098 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003099 return -1;
3100 pos += ret;
3101 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003102 if (bss_is_dmg(bss)) {
3103 const char *s;
Hai Shalomc3565922019-10-28 11:58:20 -07003104
Hai Shalom60840252021-02-19 19:02:11 -08003105 if (wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_EDMG_OPERATION)) {
Hai Shalomc3565922019-10-28 11:58:20 -07003106 ret = os_snprintf(pos, end - pos, "[EDMG]");
3107 if (os_snprintf_error(end - pos, ret))
3108 return -1;
3109 pos += ret;
3110 }
3111
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003112 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003113 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003114 return -1;
3115 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003116 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3117 case IEEE80211_CAP_DMG_IBSS:
3118 s = "[IBSS]";
3119 break;
3120 case IEEE80211_CAP_DMG_AP:
3121 s = "[ESS]";
3122 break;
3123 case IEEE80211_CAP_DMG_PBSS:
3124 s = "[PBSS]";
3125 break;
3126 default:
3127 s = "";
3128 break;
3129 }
3130 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003131 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003132 return -1;
3133 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003134 } else {
3135 if (bss->caps & IEEE80211_CAP_IBSS) {
3136 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003137 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003138 return -1;
3139 pos += ret;
3140 }
3141 if (bss->caps & IEEE80211_CAP_ESS) {
3142 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003143 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003144 return -1;
3145 pos += ret;
3146 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003147 }
3148 if (p2p) {
3149 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003150 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003151 return -1;
3152 pos += ret;
3153 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003154#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003155 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003156 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003157 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003158 return -1;
3159 pos += ret;
3160 }
3161#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003162#ifdef CONFIG_FILS
3163 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
3164 ret = os_snprintf(pos, end - pos, "[FILS]");
3165 if (os_snprintf_error(end - pos, ret))
3166 return -1;
3167 pos += ret;
3168 }
3169#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003170#ifdef CONFIG_FST
3171 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
3172 ret = os_snprintf(pos, end - pos, "[FST]");
3173 if (os_snprintf_error(end - pos, ret))
3174 return -1;
3175 pos += ret;
3176 }
3177#endif /* CONFIG_FST */
Hai Shalom74f70d42019-02-11 14:42:39 -08003178 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
3179 ret = os_snprintf(pos, end - pos, "[UTF-8]");
3180 if (os_snprintf_error(end - pos, ret))
3181 return -1;
3182 pos += ret;
3183 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003184
3185 ret = os_snprintf(pos, end - pos, "\t%s",
3186 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003187 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003188 return -1;
3189 pos += ret;
3190
3191 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003192 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003193 return -1;
3194 pos += ret;
3195
3196 return pos - buf;
3197}
3198
3199
3200static int wpa_supplicant_ctrl_iface_scan_results(
3201 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3202{
3203 char *pos, *end;
3204 struct wpa_bss *bss;
3205 int ret;
3206
3207 pos = buf;
3208 end = buf + buflen;
3209 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
3210 "flags / ssid\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003211 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003212 return pos - buf;
3213 pos += ret;
3214
3215 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3216 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
3217 end - pos);
3218 if (ret < 0 || ret >= end - pos)
3219 return pos - buf;
3220 pos += ret;
3221 }
3222
3223 return pos - buf;
3224}
3225
3226
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003227#ifdef CONFIG_MESH
3228
3229static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3230 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
3231{
3232 char *pos, ifname[IFNAMSIZ + 1];
3233
3234 ifname[0] = '\0';
3235
3236 pos = os_strstr(cmd, "ifname=");
3237 if (pos) {
3238 pos += 7;
3239 os_strlcpy(ifname, pos, sizeof(ifname));
3240 }
3241
3242 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
3243 return -1;
3244
3245 os_strlcpy(reply, ifname, max_len);
3246 return os_strlen(ifname);
3247}
3248
3249
3250static int wpa_supplicant_ctrl_iface_mesh_group_add(
3251 struct wpa_supplicant *wpa_s, char *cmd)
3252{
3253 int id;
3254 struct wpa_ssid *ssid;
3255
3256 id = atoi(cmd);
3257 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
3258
3259 ssid = wpa_config_get_network(wpa_s->conf, id);
3260 if (ssid == NULL) {
3261 wpa_printf(MSG_DEBUG,
3262 "CTRL_IFACE: Could not find network id=%d", id);
3263 return -1;
3264 }
3265 if (ssid->mode != WPAS_MODE_MESH) {
3266 wpa_printf(MSG_DEBUG,
3267 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3268 return -1;
3269 }
3270 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
Sunil Ravi89eba102022-09-13 21:04:37 -07003271 ssid->key_mgmt != WPA_KEY_MGMT_SAE &&
3272 ssid->key_mgmt != WPA_KEY_MGMT_SAE_EXT_KEY) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003273 wpa_printf(MSG_ERROR,
3274 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3275 return -1;
3276 }
3277
3278 /*
3279 * TODO: If necessary write our own group_add function,
3280 * for now we can reuse select_network
3281 */
3282 wpa_supplicant_select_network(wpa_s, ssid);
3283
3284 return 0;
3285}
3286
3287
3288static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3289 struct wpa_supplicant *wpa_s, char *cmd)
3290{
3291 struct wpa_supplicant *orig;
3292 struct wpa_global *global;
3293 int found = 0;
3294
3295 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3296
3297 global = wpa_s->global;
3298 orig = wpa_s;
3299
3300 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3301 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3302 found = 1;
3303 break;
3304 }
3305 }
3306 if (!found) {
3307 wpa_printf(MSG_ERROR,
3308 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3309 cmd);
3310 return -1;
3311 }
3312 if (wpa_s->mesh_if_created && wpa_s == orig) {
3313 wpa_printf(MSG_ERROR,
3314 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3315 return -1;
3316 }
3317
3318 wpa_s->reassociate = 0;
3319 wpa_s->disconnected = 1;
3320 wpa_supplicant_cancel_sched_scan(wpa_s);
3321 wpa_supplicant_cancel_scan(wpa_s);
3322
3323 /*
3324 * TODO: If necessary write our own group_remove function,
3325 * for now we can reuse deauthenticate
3326 */
3327 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3328
3329 if (wpa_s->mesh_if_created)
3330 wpa_supplicant_remove_iface(global, wpa_s, 0);
3331
3332 return 0;
3333}
3334
Dmitry Shmidte4663042016-04-04 10:07:49 -07003335
3336static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3337 struct wpa_supplicant *wpa_s, char *cmd)
3338{
3339 u8 addr[ETH_ALEN];
3340
3341 if (hwaddr_aton(cmd, addr) < 0)
3342 return -1;
3343
3344 return wpas_mesh_peer_remove(wpa_s, addr);
3345}
3346
3347
3348static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3349 struct wpa_supplicant *wpa_s, char *cmd)
3350{
3351 u8 addr[ETH_ALEN];
3352 int duration;
3353 char *pos;
3354
3355 pos = os_strstr(cmd, " duration=");
3356 if (pos) {
3357 *pos = '\0';
3358 duration = atoi(pos + 10);
3359 } else {
3360 duration = -1;
3361 }
3362
3363 if (hwaddr_aton(cmd, addr))
3364 return -1;
3365
3366 return wpas_mesh_peer_add(wpa_s, addr, duration);
3367}
3368
Hai Shalom81f62d82019-07-22 12:10:00 -07003369
3370static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3371 struct wpa_supplicant *wpa_s, char *cmd)
3372{
3373 struct ether_header *eth;
3374 u8 addr[ETH_ALEN];
3375 u8 *buf;
3376 char *pos;
3377 size_t payload_len = 0, len;
3378 int ret = -1;
3379
3380 if (hwaddr_aton(cmd, addr))
3381 return -1;
3382
3383 pos = os_strstr(cmd, " payload=");
3384 if (pos) {
3385 pos = pos + 9;
3386 payload_len = os_strlen(pos);
3387 if (payload_len & 1)
3388 return -1;
3389
3390 payload_len /= 2;
3391 }
3392
3393 len = ETH_HLEN + payload_len;
3394 buf = os_malloc(len);
3395 if (!buf)
3396 return -1;
3397
3398 eth = (struct ether_header *) buf;
3399 os_memcpy(eth->ether_dhost, addr, ETH_ALEN);
3400 os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN);
3401 eth->ether_type = htons(ETH_P_802_3);
3402
3403 if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0)
3404 goto fail;
3405
3406 ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len);
3407fail:
3408 os_free(buf);
3409 return -ret;
3410}
3411
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003412#endif /* CONFIG_MESH */
3413
3414
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003415static int wpa_supplicant_ctrl_iface_select_network(
3416 struct wpa_supplicant *wpa_s, char *cmd)
3417{
3418 int id;
3419 struct wpa_ssid *ssid;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003420 char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003421
3422 /* cmd: "<network id>" or "any" */
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003423 if (os_strncmp(cmd, "any", 3) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003424 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3425 ssid = NULL;
3426 } else {
3427 id = atoi(cmd);
3428 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3429
3430 ssid = wpa_config_get_network(wpa_s->conf, id);
3431 if (ssid == NULL) {
3432 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3433 "network id=%d", id);
3434 return -1;
3435 }
3436 if (ssid->disabled == 2) {
3437 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3438 "SELECT_NETWORK with persistent P2P group");
3439 return -1;
3440 }
3441 }
3442
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003443 pos = os_strstr(cmd, " freq=");
3444 if (pos) {
3445 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3446 if (freqs) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003447 os_free(wpa_s->select_network_scan_freqs);
3448 wpa_s->select_network_scan_freqs = freqs;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003449 }
3450 }
3451
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003452 wpa_s->scan_min_time.sec = 0;
3453 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003454 wpa_supplicant_select_network(wpa_s, ssid);
3455
3456 return 0;
3457}
3458
3459
3460static int wpa_supplicant_ctrl_iface_enable_network(
3461 struct wpa_supplicant *wpa_s, char *cmd)
3462{
3463 int id;
3464 struct wpa_ssid *ssid;
3465
3466 /* cmd: "<network id>" or "all" */
3467 if (os_strcmp(cmd, "all") == 0) {
3468 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3469 ssid = NULL;
3470 } else {
3471 id = atoi(cmd);
3472 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3473
3474 ssid = wpa_config_get_network(wpa_s->conf, id);
3475 if (ssid == NULL) {
3476 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3477 "network id=%d", id);
3478 return -1;
3479 }
3480 if (ssid->disabled == 2) {
3481 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3482 "ENABLE_NETWORK with persistent P2P group");
3483 return -1;
3484 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003485
3486 if (os_strstr(cmd, " no-connect")) {
3487 ssid->disabled = 0;
3488 return 0;
3489 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003490 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003491 wpa_s->scan_min_time.sec = 0;
3492 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003493 wpa_supplicant_enable_network(wpa_s, ssid);
3494
3495 return 0;
3496}
3497
3498
3499static int wpa_supplicant_ctrl_iface_disable_network(
3500 struct wpa_supplicant *wpa_s, char *cmd)
3501{
3502 int id;
3503 struct wpa_ssid *ssid;
3504
3505 /* cmd: "<network id>" or "all" */
3506 if (os_strcmp(cmd, "all") == 0) {
3507 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3508 ssid = NULL;
3509 } else {
3510 id = atoi(cmd);
3511 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3512
3513 ssid = wpa_config_get_network(wpa_s->conf, id);
3514 if (ssid == NULL) {
3515 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3516 "network id=%d", id);
3517 return -1;
3518 }
3519 if (ssid->disabled == 2) {
3520 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3521 "DISABLE_NETWORK with persistent P2P "
3522 "group");
3523 return -1;
3524 }
3525 }
3526 wpa_supplicant_disable_network(wpa_s, ssid);
3527
3528 return 0;
3529}
3530
3531
3532static int wpa_supplicant_ctrl_iface_add_network(
3533 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3534{
3535 struct wpa_ssid *ssid;
3536 int ret;
3537
3538 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3539
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003540 ssid = wpa_supplicant_add_network(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003541 if (ssid == NULL)
3542 return -1;
3543
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003544 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003545 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003546 return -1;
3547 return ret;
3548}
3549
3550
3551static int wpa_supplicant_ctrl_iface_remove_network(
3552 struct wpa_supplicant *wpa_s, char *cmd)
3553{
3554 int id;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003555 int result;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003556
3557 /* cmd: "<network id>" or "all" */
3558 if (os_strcmp(cmd, "all") == 0) {
3559 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Hai Shalom899fcc72020-10-19 14:38:18 -07003560 return wpa_supplicant_remove_all_networks(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003561 }
3562
3563 id = atoi(cmd);
3564 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3565
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003566 result = wpa_supplicant_remove_network(wpa_s, id);
3567 if (result == -1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003568 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3569 "id=%d", id);
3570 return -1;
3571 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003572 if (result == -2) {
Deepthi Gowria831d782012-09-03 11:55:38 +03003573 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3574 "network id=%d", id);
3575 return -1;
3576 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003577 return 0;
3578}
3579
3580
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003581static int wpa_supplicant_ctrl_iface_update_network(
3582 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3583 char *name, char *value)
3584{
Dmitry Shmidte4663042016-04-04 10:07:49 -07003585 int ret;
3586
3587 ret = wpa_config_set(ssid, name, value, 0);
3588 if (ret < 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003589 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3590 "variable '%s'", name);
3591 return -1;
3592 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07003593 if (ret == 1)
3594 return 0; /* No change to the previously configured value */
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003595
Hai Shalom899fcc72020-10-19 14:38:18 -07003596#ifdef CONFIG_BGSCAN
3597 if (os_strcmp(name, "bgscan") == 0) {
3598 /*
3599 * Reset the bgscan parameters for the current network and
3600 * return. There's no need to flush caches for bgscan parameter
3601 * changes.
3602 */
3603 if (wpa_s->current_ssid == ssid &&
3604 wpa_s->wpa_state == WPA_COMPLETED)
3605 wpa_supplicant_reset_bgscan(wpa_s);
3606 return 0;
3607 }
3608#endif /* CONFIG_BGSCAN */
3609
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003610 if (os_strcmp(name, "bssid") != 0 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003611 os_strcmp(name, "bssid_hint") != 0 &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003612 os_strcmp(name, "priority") != 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003613 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3614
Dmitry Shmidte4663042016-04-04 10:07:49 -07003615 if (wpa_s->current_ssid == ssid ||
3616 wpa_s->current_ssid == NULL) {
3617 /*
3618 * Invalidate the EAP session cache if anything in the
3619 * current or previously used configuration changes.
3620 */
3621 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3622 }
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003623 }
3624
3625 if ((os_strcmp(name, "psk") == 0 &&
3626 value[0] == '"' && ssid->ssid_len) ||
3627 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3628 wpa_config_update_psk(ssid);
3629 else if (os_strcmp(name, "priority") == 0)
3630 wpa_config_update_prio_list(wpa_s->conf);
3631
3632 return 0;
3633}
3634
3635
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003636static int wpa_supplicant_ctrl_iface_set_network(
3637 struct wpa_supplicant *wpa_s, char *cmd)
3638{
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003639 int id, ret, prev_bssid_set, prev_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003640 struct wpa_ssid *ssid;
3641 char *name, *value;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003642 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003643
3644 /* cmd: "<network id> <variable name> <value>" */
3645 name = os_strchr(cmd, ' ');
3646 if (name == NULL)
3647 return -1;
3648 *name++ = '\0';
3649
3650 value = os_strchr(name, ' ');
3651 if (value == NULL)
3652 return -1;
3653 *value++ = '\0';
3654
3655 id = atoi(cmd);
3656 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3657 id, name);
3658 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3659 (u8 *) value, os_strlen(value));
3660
3661 ssid = wpa_config_get_network(wpa_s->conf, id);
3662 if (ssid == NULL) {
3663 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3664 "id=%d", id);
3665 return -1;
3666 }
3667
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003668 prev_bssid_set = ssid->bssid_set;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003669 prev_disabled = ssid->disabled;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003670 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3671 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3672 value);
3673 if (ret == 0 &&
3674 (ssid->bssid_set != prev_bssid_set ||
3675 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3676 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003677
3678 if (prev_disabled != ssid->disabled &&
3679 (prev_disabled == 2 || ssid->disabled == 2))
3680 wpas_notify_network_type_changed(wpa_s, ssid);
3681
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003682 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003683}
3684
3685
3686static int wpa_supplicant_ctrl_iface_get_network(
3687 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3688{
3689 int id;
3690 size_t res;
3691 struct wpa_ssid *ssid;
3692 char *name, *value;
3693
3694 /* cmd: "<network id> <variable name>" */
3695 name = os_strchr(cmd, ' ');
3696 if (name == NULL || buflen == 0)
3697 return -1;
3698 *name++ = '\0';
3699
3700 id = atoi(cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003701 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003702 id, name);
3703
3704 ssid = wpa_config_get_network(wpa_s->conf, id);
3705 if (ssid == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003706 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003707 "id=%d", id);
3708 return -1;
3709 }
3710
3711 value = wpa_config_get_no_key(ssid, name);
3712 if (value == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003713 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003714 "variable '%s'", name);
3715 return -1;
3716 }
3717
3718 res = os_strlcpy(buf, value, buflen);
3719 if (res >= buflen) {
3720 os_free(value);
3721 return -1;
3722 }
3723
3724 os_free(value);
3725
3726 return res;
3727}
3728
3729
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003730static int wpa_supplicant_ctrl_iface_dup_network(
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003731 struct wpa_supplicant *wpa_s, char *cmd,
3732 struct wpa_supplicant *dst_wpa_s)
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003733{
3734 struct wpa_ssid *ssid_s, *ssid_d;
3735 char *name, *id, *value;
3736 int id_s, id_d, ret;
3737
3738 /* cmd: "<src network id> <dst network id> <variable name>" */
3739 id = os_strchr(cmd, ' ');
3740 if (id == NULL)
3741 return -1;
3742 *id++ = '\0';
3743
3744 name = os_strchr(id, ' ');
3745 if (name == NULL)
3746 return -1;
3747 *name++ = '\0';
3748
3749 id_s = atoi(cmd);
3750 id_d = atoi(id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003751
3752 wpa_printf(MSG_DEBUG,
3753 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3754 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003755
3756 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3757 if (ssid_s == NULL) {
3758 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3759 "network id=%d", id_s);
3760 return -1;
3761 }
3762
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003763 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003764 if (ssid_d == NULL) {
3765 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003766 "network id=%d", id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003767 return -1;
3768 }
3769
3770 value = wpa_config_get(ssid_s, name);
3771 if (value == NULL) {
3772 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3773 "variable '%s'", name);
3774 return -1;
3775 }
3776
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003777 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003778 value);
3779
3780 os_free(value);
3781
3782 return ret;
3783}
3784
3785
Dmitry Shmidt04949592012-07-19 12:16:46 -07003786static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3787 char *buf, size_t buflen)
3788{
3789 char *pos, *end;
3790 struct wpa_cred *cred;
3791 int ret;
3792
3793 pos = buf;
3794 end = buf + buflen;
3795 ret = os_snprintf(pos, end - pos,
3796 "cred id / realm / username / domain / imsi\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003797 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003798 return pos - buf;
3799 pos += ret;
3800
3801 cred = wpa_s->conf->cred;
3802 while (cred) {
3803 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3804 cred->id, cred->realm ? cred->realm : "",
3805 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07003806 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003807 cred->imsi ? cred->imsi : "");
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 = cred->next;
3813 }
3814
3815 return pos - buf;
3816}
3817
3818
3819static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3820 char *buf, size_t buflen)
3821{
3822 struct wpa_cred *cred;
3823 int ret;
3824
3825 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3826
3827 cred = wpa_config_add_cred(wpa_s->conf);
3828 if (cred == NULL)
3829 return -1;
3830
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003831 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3832
Dmitry Shmidt04949592012-07-19 12:16:46 -07003833 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003834 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003835 return -1;
3836 return ret;
3837}
3838
3839
3840static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3841 char *cmd)
3842{
3843 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003844 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003845
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003846 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3847 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003848 if (os_strcmp(cmd, "all") == 0) {
3849 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
Hai Shaloma20dcd72022-02-04 13:43:00 -08003850 return wpas_remove_all_creds(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003851 }
3852
3853 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3854 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3855 cmd + 8);
3856 cred = wpa_s->conf->cred;
3857 while (cred) {
3858 prev = cred;
3859 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003860 if (prev->domain) {
3861 size_t i;
3862 for (i = 0; i < prev->num_domain; i++) {
3863 if (os_strcmp(prev->domain[i], cmd + 8)
3864 != 0)
3865 continue;
Hai Shaloma20dcd72022-02-04 13:43:00 -08003866 wpas_remove_cred(wpa_s, prev);
Dmitry Shmidt051af732013-10-22 13:52:46 -07003867 break;
3868 }
3869 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003870 }
3871 return 0;
3872 }
3873
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003874 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3875 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3876 cmd + 16);
3877 cred = wpa_s->conf->cred;
3878 while (cred) {
3879 prev = cred;
3880 cred = cred->next;
3881 if (prev->provisioning_sp &&
3882 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
Hai Shaloma20dcd72022-02-04 13:43:00 -08003883 wpas_remove_cred(wpa_s, prev);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003884 }
3885 return 0;
3886 }
3887
Dmitry Shmidt04949592012-07-19 12:16:46 -07003888 id = atoi(cmd);
3889 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3890
3891 cred = wpa_config_get_cred(wpa_s->conf, id);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003892 return wpas_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003893}
3894
3895
3896static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3897 char *cmd)
3898{
3899 int id;
3900 struct wpa_cred *cred;
3901 char *name, *value;
3902
3903 /* cmd: "<cred id> <variable name> <value>" */
3904 name = os_strchr(cmd, ' ');
3905 if (name == NULL)
3906 return -1;
3907 *name++ = '\0';
3908
3909 value = os_strchr(name, ' ');
3910 if (value == NULL)
3911 return -1;
3912 *value++ = '\0';
3913
3914 id = atoi(cmd);
3915 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3916 id, name);
3917 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3918 (u8 *) value, os_strlen(value));
3919
3920 cred = wpa_config_get_cred(wpa_s->conf, id);
3921 if (cred == NULL) {
3922 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3923 id);
3924 return -1;
3925 }
3926
3927 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3928 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3929 "variable '%s'", name);
3930 return -1;
3931 }
3932
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003933 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3934
Dmitry Shmidt04949592012-07-19 12:16:46 -07003935 return 0;
3936}
3937
3938
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003939static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3940 char *cmd, char *buf,
3941 size_t buflen)
3942{
3943 int id;
3944 size_t res;
3945 struct wpa_cred *cred;
3946 char *name, *value;
3947
3948 /* cmd: "<cred id> <variable name>" */
3949 name = os_strchr(cmd, ' ');
3950 if (name == NULL)
3951 return -1;
3952 *name++ = '\0';
3953
3954 id = atoi(cmd);
3955 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3956 id, name);
3957
3958 cred = wpa_config_get_cred(wpa_s->conf, id);
3959 if (cred == NULL) {
3960 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3961 id);
3962 return -1;
3963 }
3964
3965 value = wpa_config_get_cred_no_key(cred, name);
3966 if (value == NULL) {
3967 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3968 name);
3969 return -1;
3970 }
3971
3972 res = os_strlcpy(buf, value, buflen);
3973 if (res >= buflen) {
3974 os_free(value);
3975 return -1;
3976 }
3977
3978 os_free(value);
3979
3980 return res;
3981}
3982
3983
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003984#ifndef CONFIG_NO_CONFIG_WRITE
3985static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3986{
3987 int ret;
3988
3989 if (!wpa_s->conf->update_config) {
3990 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3991 "to update configuration (update_config=0)");
3992 return -1;
3993 }
3994
3995 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3996 if (ret) {
3997 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3998 "update configuration");
3999 } else {
4000 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
4001 " updated");
4002 }
4003
4004 return ret;
4005}
4006#endif /* CONFIG_NO_CONFIG_WRITE */
4007
4008
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004009struct cipher_info {
4010 unsigned int capa;
4011 const char *name;
4012 int group_only;
4013};
4014
4015static const struct cipher_info ciphers[] = {
4016 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
4017 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
4018 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
4019 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07004020#ifndef CONFIG_NO_TKIP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004021 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07004022#endif /* CONFIG_NO_TKIP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004023 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
Hai Shalomfdcde762020-04-02 11:19:20 -07004024#ifdef CONFIG_WEP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004025 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
4026 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004027#endif /* CONFIG_WEP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004028};
4029
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004030static const struct cipher_info ciphers_group_mgmt[] = {
4031 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
4032 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
4033 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
4034 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
4035};
4036
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004037
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004038static int ctrl_iface_get_capability_pairwise(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004039 struct wpa_driver_capa *capa,
4040 char *buf, size_t buflen)
4041{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004042 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004043 char *pos, *end;
4044 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004045 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004046
4047 pos = buf;
4048 end = pos + buflen;
4049
4050 if (res < 0) {
4051 if (strict)
4052 return 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07004053#ifdef CONFIG_NO_TKIP
4054 len = os_strlcpy(buf, "CCMP NONE", buflen);
4055#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004056 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004057#endif /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004058 if (len >= buflen)
4059 return -1;
4060 return len;
4061 }
4062
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004063 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4064 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
4065 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004066 pos == buf ? "" : " ",
4067 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004068 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004069 return pos - buf;
4070 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004071 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004072 }
4073
4074 return pos - buf;
4075}
4076
4077
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004078static int ctrl_iface_get_capability_group(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004079 struct wpa_driver_capa *capa,
4080 char *buf, size_t buflen)
4081{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004082 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004083 char *pos, *end;
4084 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004085 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004086
4087 pos = buf;
4088 end = pos + buflen;
4089
4090 if (res < 0) {
4091 if (strict)
4092 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07004093#ifdef CONFIG_WEP
Hai Shalomb755a2a2020-04-23 21:49:02 -07004094#ifdef CONFIG_NO_TKIP
4095 len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen);
4096#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004097 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004098#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004099#else /* CONFIG_WEP */
Hai Shalomb755a2a2020-04-23 21:49:02 -07004100#ifdef CONFIG_NO_TKIP
4101 len = os_strlcpy(buf, "CCMP", buflen);
4102#else /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004103 len = os_strlcpy(buf, "CCMP TKIP", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004104#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004105#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004106 if (len >= buflen)
4107 return -1;
4108 return len;
4109 }
4110
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004111 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4112 if (capa->enc & ciphers[i].capa) {
4113 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004114 pos == buf ? "" : " ",
4115 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004116 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004117 return pos - buf;
4118 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004119 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004120 }
4121
4122 return pos - buf;
4123}
4124
4125
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004126static int ctrl_iface_get_capability_group_mgmt(int res, bool strict,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004127 struct wpa_driver_capa *capa,
4128 char *buf, size_t buflen)
4129{
4130 int ret;
4131 char *pos, *end;
4132 unsigned int i;
4133
4134 pos = buf;
4135 end = pos + buflen;
4136
4137 if (res < 0)
4138 return 0;
4139
4140 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
4141 if (capa->enc & ciphers_group_mgmt[i].capa) {
4142 ret = os_snprintf(pos, end - pos, "%s%s",
4143 pos == buf ? "" : " ",
4144 ciphers_group_mgmt[i].name);
4145 if (os_snprintf_error(end - pos, ret))
4146 return pos - buf;
4147 pos += ret;
4148 }
4149 }
4150
4151 return pos - buf;
4152}
4153
4154
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004155static int iftype_str_to_index(const char *iftype_str)
4156{
4157 if (!iftype_str)
4158 return WPA_IF_MAX;
4159
4160 if (os_strcmp(iftype_str, "STATION") == 0)
4161 return WPA_IF_STATION;
4162
4163 if (os_strcmp(iftype_str, "AP_VLAN") == 0)
4164 return WPA_IF_AP_VLAN;
4165
4166 if (os_strcmp(iftype_str, "AP") == 0)
4167 return WPA_IF_AP_BSS;
4168
4169 if (os_strcmp(iftype_str, "P2P_GO") == 0)
4170 return WPA_IF_P2P_GO;
4171
4172 if (os_strcmp(iftype_str, "P2P_CLIENT") == 0)
4173 return WPA_IF_P2P_CLIENT;
4174
4175 if (os_strcmp(iftype_str, "P2P_DEVICE") == 0)
4176 return WPA_IF_P2P_DEVICE;
4177
4178 if (os_strcmp(iftype_str, "MESH") == 0)
4179 return WPA_IF_MESH;
4180
4181 if (os_strcmp(iftype_str, "IBSS") == 0)
4182 return WPA_IF_IBSS;
4183
4184 if (os_strcmp(iftype_str, "NAN") == 0)
4185 return WPA_IF_NAN;
4186
4187 return WPA_IF_MAX;
4188}
4189
4190
4191static int ctrl_iface_get_capability_key_mgmt(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004192 struct wpa_driver_capa *capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004193 const char *iftype_str,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004194 char *buf, size_t buflen)
4195{
4196 int ret;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004197 unsigned int key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004198 char *pos, *end;
4199 size_t len;
4200
4201 pos = buf;
4202 end = pos + buflen;
4203
4204 if (res < 0) {
4205 if (strict)
4206 return 0;
4207 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4208 "NONE", buflen);
4209 if (len >= buflen)
4210 return -1;
4211 return len;
4212 }
4213
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004214 if (iftype_str) {
4215 enum wpa_driver_if_type iftype;
4216
4217 iftype = iftype_str_to_index(iftype_str);
4218 if (iftype == WPA_IF_MAX)
4219 return -1;
4220 key_mgmt = capa->key_mgmt_iftype[iftype];
4221 } else {
4222 key_mgmt = capa->key_mgmt;
4223 }
4224
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004225 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004226 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004227 return pos - buf;
4228 pos += ret;
4229
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004230 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4231 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004232 ret = os_snprintf(pos, end - pos, " WPA-EAP");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004233 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004234 return pos - buf;
4235 pos += ret;
4236 }
4237
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004238 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
4239 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004240 ret = os_snprintf(pos, end - pos, " WPA-PSK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004241 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004242 return pos - buf;
4243 pos += ret;
4244 }
4245
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004246 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004247 ret = os_snprintf(pos, end - pos, " WPA-NONE");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004248 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004249 return pos - buf;
4250 pos += ret;
4251 }
4252
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304253 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WAPI_PSK) {
4254 ret = os_snprintf(pos, end - pos, " WAPI-PSK");
4255 if (os_snprintf_error(end - pos, ret))
4256 return pos - buf;
4257 pos += ret;
4258 }
4259
4260 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE) {
4261 ret = os_snprintf(pos, end - pos, " TPK-HANDSHAKE");
4262 if (os_snprintf_error(end - pos, ret))
4263 return pos - buf;
4264 pos += ret;
4265 }
4266
4267 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_CCKM) {
4268 ret = os_snprintf(pos, end - pos, " CCKM");
4269 if (os_snprintf_error(end - pos, ret))
4270 return pos - buf;
4271 pos += ret;
4272 }
4273
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004274#ifdef CONFIG_SUITEB
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004275 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004276 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
4277 if (os_snprintf_error(end - pos, ret))
4278 return pos - buf;
4279 pos += ret;
4280 }
4281#endif /* CONFIG_SUITEB */
4282#ifdef CONFIG_SUITEB192
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004283 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004284 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
4285 if (os_snprintf_error(end - pos, ret))
4286 return pos - buf;
4287 pos += ret;
4288 }
4289#endif /* CONFIG_SUITEB192 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004290#ifdef CONFIG_OWE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004291 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004292 ret = os_snprintf(pos, end - pos, " OWE");
4293 if (os_snprintf_error(end - pos, ret))
4294 return pos - buf;
4295 pos += ret;
4296 }
4297#endif /* CONFIG_OWE */
4298#ifdef CONFIG_DPP
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004299 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004300 ret = os_snprintf(pos, end - pos, " DPP");
4301 if (os_snprintf_error(end - pos, ret))
4302 return pos - buf;
4303 pos += ret;
4304 }
4305#endif /* CONFIG_DPP */
4306#ifdef CONFIG_FILS
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004307 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004308 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
4309 if (os_snprintf_error(end - pos, ret))
4310 return pos - buf;
4311 pos += ret;
4312 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004313 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004314 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
4315 if (os_snprintf_error(end - pos, ret))
4316 return pos - buf;
4317 pos += ret;
4318 }
4319#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004320 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004321 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
4322 if (os_snprintf_error(end - pos, ret))
4323 return pos - buf;
4324 pos += ret;
4325 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004326 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004327 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
4328 if (os_snprintf_error(end - pos, ret))
4329 return pos - buf;
4330 pos += ret;
4331 }
4332#endif /* CONFIG_IEEE80211R */
4333#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08004334#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004335 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004336 ret = os_snprintf(pos, end - pos, " FT-PSK");
4337 if (os_snprintf_error(end - pos, ret))
4338 return pos - buf;
4339 pos += ret;
4340 }
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304341 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) {
4342 ret = os_snprintf(pos, end - pos, " FT-EAP");
4343 if (os_snprintf_error(end - pos, ret))
4344 return pos - buf;
4345 pos += ret;
4346 }
4347#ifdef CONFIG_SAE
4348 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE) {
4349 ret = os_snprintf(pos, end - pos, " FT-SAE");
4350 if (os_snprintf_error(end - pos, ret))
4351 return pos - buf;
4352 pos += ret;
4353 }
Sunil Ravi89eba102022-09-13 21:04:37 -07004354 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE_EXT_KEY) {
4355 ret = os_snprintf(pos, end - pos, " FT-SAE-EXT-KEY");
4356 if (os_snprintf_error(end - pos, ret))
4357 return pos - buf;
4358 pos += ret;
4359 }
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304360#endif /* CONFIG_SAE */
4361#ifdef CONFIG_SHA384
4362 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384) {
4363 ret = os_snprintf(pos, end - pos, " FT-EAP-SHA384");
4364 if (os_snprintf_error(end - pos, ret))
4365 return pos - buf;
4366 pos += ret;
4367 }
4368#endif /* CONFIG_SHA384 */
Hai Shalom74f70d42019-02-11 14:42:39 -08004369#endif /* CONFIG_IEEE80211R */
4370#ifdef CONFIG_SAE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004371 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004372 ret = os_snprintf(pos, end - pos, " SAE");
4373 if (os_snprintf_error(end - pos, ret))
4374 return pos - buf;
4375 pos += ret;
4376 }
Sunil Ravi89eba102022-09-13 21:04:37 -07004377 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE_EXT_KEY) {
4378 ret = os_snprintf(pos, end - pos, " SAE-EXT-KEY");
4379 if (os_snprintf_error(end - pos, ret))
4380 return pos - buf;
4381 pos += ret;
4382 }
Hai Shalom74f70d42019-02-11 14:42:39 -08004383#endif /* CONFIG_SAE */
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304384#ifdef CONFIG_SHA256
4385 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256) {
4386 ret = os_snprintf(pos, end - pos, " WPA-EAP-SHA256");
4387 if (os_snprintf_error(end - pos, ret))
4388 return pos - buf;
4389 pos += ret;
4390 }
4391
4392 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256) {
4393 ret = os_snprintf(pos, end - pos, " WPA-PSK-SHA256");
4394 if (os_snprintf_error(end - pos, ret))
4395 return pos - buf;
4396 pos += ret;
4397 }
4398#endif /* CONFIG_SHA256 */
4399#ifdef CONFIG_HS20
4400 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OSEN) {
4401 ret = os_snprintf(pos, end - pos, " OSEN");
4402 if (os_snprintf_error(end - pos, ret))
4403 return pos - buf;
4404 pos += ret;
4405 }
4406#endif /* CONFIG_HS20 */
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004407
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004408 return pos - buf;
4409}
4410
4411
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004412static int ctrl_iface_get_capability_proto(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004413 struct wpa_driver_capa *capa,
4414 char *buf, size_t buflen)
4415{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004416 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004417 char *pos, *end;
4418 size_t len;
4419
4420 pos = buf;
4421 end = pos + buflen;
4422
4423 if (res < 0) {
4424 if (strict)
4425 return 0;
4426 len = os_strlcpy(buf, "RSN WPA", buflen);
4427 if (len >= buflen)
4428 return -1;
4429 return len;
4430 }
4431
4432 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4433 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004434 ret = os_snprintf(pos, end - pos, "%sRSN",
4435 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004436 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004437 return pos - buf;
4438 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004439 }
4440
4441 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4442 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004443 ret = os_snprintf(pos, end - pos, "%sWPA",
4444 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004445 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004446 return pos - buf;
4447 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004448 }
4449
4450 return pos - buf;
4451}
4452
4453
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004454static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004455 int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004456 struct wpa_driver_capa *capa,
4457 char *buf, size_t buflen)
4458{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004459 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004460 char *pos, *end;
4461 size_t len;
4462
4463 pos = buf;
4464 end = pos + buflen;
4465
4466 if (res < 0) {
4467 if (strict)
4468 return 0;
4469 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4470 if (len >= buflen)
4471 return -1;
4472 return len;
4473 }
4474
4475 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004476 ret = os_snprintf(pos, end - pos, "%sOPEN",
4477 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004478 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004479 return pos - buf;
4480 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004481 }
4482
4483 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4484 ret = os_snprintf(pos, end - pos, "%sSHARED",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004485 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004486 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004487 return pos - buf;
4488 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004489 }
4490
4491 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004492 ret = os_snprintf(pos, end - pos, "%sLEAP",
4493 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004494 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004495 return pos - buf;
4496 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004497 }
4498
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004499#ifdef CONFIG_SAE
4500 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4501 ret = os_snprintf(pos, end - pos, "%sSAE",
4502 pos == buf ? "" : " ");
4503 if (os_snprintf_error(end - pos, ret))
4504 return pos - buf;
4505 pos += ret;
4506 }
4507#endif /* CONFIG_SAE */
4508
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004509#ifdef CONFIG_FILS
4510 if (wpa_is_fils_supported(wpa_s)) {
4511 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4512 pos == buf ? "" : " ");
4513 if (os_snprintf_error(end - pos, ret))
4514 return pos - buf;
4515 pos += ret;
4516 }
4517
4518#ifdef CONFIG_FILS_SK_PFS
4519 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4520 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4521 pos == buf ? "" : " ");
4522 if (os_snprintf_error(end - pos, ret))
4523 return pos - buf;
4524 pos += ret;
4525 }
4526#endif /* CONFIG_FILS_SK_PFS */
4527#endif /* CONFIG_FILS */
4528
Hai Shalom60840252021-02-19 19:02:11 -08004529#ifdef CONFIG_PASN
4530 ret = os_snprintf(pos, end - pos, "%sPASN",
4531 pos == buf ? "" : " ");
4532 if (os_snprintf_error(end - pos, ret))
4533 return pos - buf;
4534 pos += ret;
4535
4536#endif /* CONFIG_PASN */
4537
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004538 return pos - buf;
4539}
4540
4541
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004542static int ctrl_iface_get_capability_modes(int res, bool strict,
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004543 struct wpa_driver_capa *capa,
4544 char *buf, size_t buflen)
4545{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004546 int ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004547 char *pos, *end;
4548 size_t len;
4549
4550 pos = buf;
4551 end = pos + buflen;
4552
4553 if (res < 0) {
4554 if (strict)
4555 return 0;
4556 len = os_strlcpy(buf, "IBSS AP", buflen);
4557 if (len >= buflen)
4558 return -1;
4559 return len;
4560 }
4561
4562 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004563 ret = os_snprintf(pos, end - pos, "%sIBSS",
4564 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004565 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004566 return pos - buf;
4567 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004568 }
4569
4570 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004571 ret = os_snprintf(pos, end - pos, "%sAP",
4572 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004573 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004574 return pos - buf;
4575 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004576 }
4577
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004578#ifdef CONFIG_MESH
4579 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4580 ret = os_snprintf(pos, end - pos, "%sMESH",
4581 pos == buf ? "" : " ");
4582 if (os_snprintf_error(end - pos, ret))
4583 return pos - buf;
4584 pos += ret;
4585 }
4586#endif /* CONFIG_MESH */
4587
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004588 return pos - buf;
4589}
4590
4591
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004592static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4593 char *buf, size_t buflen)
4594{
4595 struct hostapd_channel_data *chnl;
4596 int ret, i, j;
4597 char *pos, *end, *hmode;
4598
4599 pos = buf;
4600 end = pos + buflen;
4601
4602 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4603 switch (wpa_s->hw.modes[j].mode) {
4604 case HOSTAPD_MODE_IEEE80211B:
4605 hmode = "B";
4606 break;
4607 case HOSTAPD_MODE_IEEE80211G:
4608 hmode = "G";
4609 break;
4610 case HOSTAPD_MODE_IEEE80211A:
4611 hmode = "A";
4612 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004613 case HOSTAPD_MODE_IEEE80211AD:
4614 hmode = "AD";
4615 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004616 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004617 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004618 }
4619 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004620 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004621 return pos - buf;
4622 pos += ret;
4623 chnl = wpa_s->hw.modes[j].channels;
4624 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004625 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4626 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004627 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004628 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004629 return pos - buf;
4630 pos += ret;
4631 }
4632 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004633 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004634 return pos - buf;
4635 pos += ret;
4636 }
4637
4638 return pos - buf;
4639}
4640
4641
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004642static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4643 char *buf, size_t buflen)
4644{
4645 struct hostapd_channel_data *chnl;
4646 int ret, i, j;
4647 char *pos, *end, *hmode;
4648
4649 pos = buf;
4650 end = pos + buflen;
4651
4652 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4653 switch (wpa_s->hw.modes[j].mode) {
4654 case HOSTAPD_MODE_IEEE80211B:
4655 hmode = "B";
4656 break;
4657 case HOSTAPD_MODE_IEEE80211G:
4658 hmode = "G";
4659 break;
4660 case HOSTAPD_MODE_IEEE80211A:
4661 hmode = "A";
4662 break;
4663 case HOSTAPD_MODE_IEEE80211AD:
4664 hmode = "AD";
4665 break;
4666 default:
4667 continue;
4668 }
4669 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4670 hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004671 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004672 return pos - buf;
4673 pos += ret;
4674 chnl = wpa_s->hw.modes[j].channels;
4675 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4676 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4677 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004678 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004679 chnl[i].chan, chnl[i].freq,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004680 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4681 " (NO_IR)" : "",
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004682 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4683 " (DFS)" : "");
4684
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004685 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004686 return pos - buf;
4687 pos += ret;
4688 }
4689 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004690 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004691 return pos - buf;
4692 pos += ret;
4693 }
4694
4695 return pos - buf;
4696}
4697
4698
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004699static int wpa_supplicant_ctrl_iface_get_capability(
4700 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4701 size_t buflen)
4702{
4703 struct wpa_driver_capa capa;
4704 int res;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004705 char *next_param, *curr_param, *iftype = NULL;
4706 bool strict = false;
4707 char field[50];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004708 size_t len;
4709
4710 /* Determine whether or not strict checking was requested */
4711 len = os_strlcpy(field, _field, sizeof(field));
4712 if (len >= sizeof(field))
4713 return -1;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004714
4715 next_param = os_strchr(field, ' ');
4716 while (next_param) {
4717 *next_param++ = '\0';
4718 curr_param = next_param;
4719 next_param = os_strchr(next_param, ' ');
4720
4721 if (next_param)
4722 *next_param = '\0';
4723
4724 if (os_strcmp(curr_param, "strict") == 0)
4725 strict = true;
4726 else if (os_strncmp(curr_param, "iftype=", 7) == 0)
4727 iftype = curr_param + 7;
4728 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004729 return -1;
4730 }
4731
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004732 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'%s%s%s",
4733 field, iftype ? " iftype=" : "", iftype ? iftype : "",
4734 strict ? " strict" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004735
4736 if (os_strcmp(field, "eap") == 0) {
4737 return eap_get_names(buf, buflen);
4738 }
4739
4740 res = wpa_drv_get_capa(wpa_s, &capa);
4741
4742 if (os_strcmp(field, "pairwise") == 0)
4743 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4744 buf, buflen);
4745
4746 if (os_strcmp(field, "group") == 0)
4747 return ctrl_iface_get_capability_group(res, strict, &capa,
4748 buf, buflen);
4749
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004750 if (os_strcmp(field, "group_mgmt") == 0)
4751 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4752 buf, buflen);
4753
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004754 if (os_strcmp(field, "key_mgmt") == 0)
4755 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004756 iftype, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004757
4758 if (os_strcmp(field, "proto") == 0)
4759 return ctrl_iface_get_capability_proto(res, strict, &capa,
4760 buf, buflen);
4761
4762 if (os_strcmp(field, "auth_alg") == 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004763 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4764 &capa, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004765
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004766 if (os_strcmp(field, "modes") == 0)
4767 return ctrl_iface_get_capability_modes(res, strict, &capa,
4768 buf, buflen);
4769
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004770 if (os_strcmp(field, "channels") == 0)
4771 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4772
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004773 if (os_strcmp(field, "freq") == 0)
4774 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4775
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004776#ifdef CONFIG_TDLS
4777 if (os_strcmp(field, "tdls") == 0)
4778 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4779#endif /* CONFIG_TDLS */
4780
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004781#ifdef CONFIG_ERP
4782 if (os_strcmp(field, "erp") == 0) {
4783 res = os_snprintf(buf, buflen, "ERP");
4784 if (os_snprintf_error(buflen, res))
4785 return -1;
4786 return res;
4787 }
4788#endif /* CONFIG_EPR */
4789
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004790#ifdef CONFIG_FIPS
4791 if (os_strcmp(field, "fips") == 0) {
4792 res = os_snprintf(buf, buflen, "FIPS");
4793 if (os_snprintf_error(buflen, res))
4794 return -1;
4795 return res;
4796 }
4797#endif /* CONFIG_FIPS */
4798
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004799#ifdef CONFIG_ACS
4800 if (os_strcmp(field, "acs") == 0) {
4801 res = os_snprintf(buf, buflen, "ACS");
4802 if (os_snprintf_error(buflen, res))
4803 return -1;
4804 return res;
4805 }
4806#endif /* CONFIG_ACS */
4807
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004808#ifdef CONFIG_FILS
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004809 if (os_strcmp(field, "fils") == 0) {
4810#ifdef CONFIG_FILS_SK_PFS
4811 if (wpa_is_fils_supported(wpa_s) &&
4812 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4813 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4814 if (os_snprintf_error(buflen, res))
4815 return -1;
4816 return res;
4817 }
4818#endif /* CONFIG_FILS_SK_PFS */
4819
4820 if (wpa_is_fils_supported(wpa_s)) {
4821 res = os_snprintf(buf, buflen, "FILS");
4822 if (os_snprintf_error(buflen, res))
4823 return -1;
4824 return res;
4825 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004826 }
4827#endif /* CONFIG_FILS */
4828
Hai Shalom74f70d42019-02-11 14:42:39 -08004829 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
4830 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
4831 if (os_snprintf_error(buflen, res))
4832 return -1;
4833 return res;
4834 }
4835
Hai Shalom021b0b52019-04-10 11:17:58 -07004836#ifdef CONFIG_DPP
4837 if (os_strcmp(field, "dpp") == 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08004838#ifdef CONFIG_DPP3
4839 res = os_snprintf(buf, buflen, "DPP=3");
4840#elif defined(CONFIG_DPP2)
Hai Shalom021b0b52019-04-10 11:17:58 -07004841 res = os_snprintf(buf, buflen, "DPP=2");
4842#else /* CONFIG_DPP2 */
4843 res = os_snprintf(buf, buflen, "DPP=1");
4844#endif /* CONFIG_DPP2 */
4845 if (os_snprintf_error(buflen, res))
4846 return -1;
4847 return res;
4848 }
4849#endif /* CONFIG_DPP */
4850
Hai Shalom899fcc72020-10-19 14:38:18 -07004851#ifdef CONFIG_SAE
4852 if (os_strcmp(field, "sae") == 0 &&
4853 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4854#ifdef CONFIG_SAE_PK
4855 res = os_snprintf(buf, buflen, "H2E PK");
4856#else /* CONFIG_SAE_PK */
4857 res = os_snprintf(buf, buflen, "H2E");
4858#endif /* CONFIG_SAE_PK */
4859 if (os_snprintf_error(buflen, res))
4860 return -1;
4861 return res;
4862 }
4863#endif /* CONFIG_SAE */
4864
Hai Shalom60840252021-02-19 19:02:11 -08004865#ifdef CONFIG_OCV
4866 if (os_strcmp(field, "ocv") == 0) {
4867 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
4868 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV))
4869 res = os_snprintf(buf, buflen, "supported");
4870 else
4871 res = os_snprintf(buf, buflen, "not supported");
4872 if (os_snprintf_error(buflen, res))
4873 return -1;
4874 return res;
4875 }
4876#endif /* CONFIG_OCV */
4877
4878 if (os_strcmp(field, "beacon_prot") == 0) {
4879 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) ||
4880 (wpa_s->drv_flags2 &
4881 WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT))
4882 res = os_snprintf(buf, buflen, "supported");
4883 else
4884 res = os_snprintf(buf, buflen, "not supported");
4885 if (os_snprintf_error(buflen, res))
4886 return -1;
4887 return res;
4888 }
4889
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004890 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4891 field);
4892
4893 return -1;
4894}
4895
4896
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004897#ifdef CONFIG_INTERWORKING
4898static char * anqp_add_hex(char *pos, char *end, const char *title,
4899 struct wpabuf *data)
4900{
4901 char *start = pos;
4902 size_t i;
4903 int ret;
4904 const u8 *d;
4905
4906 if (data == NULL)
4907 return start;
4908
4909 ret = os_snprintf(pos, end - pos, "%s=", title);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004910 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004911 return start;
4912 pos += ret;
4913
4914 d = wpabuf_head_u8(data);
4915 for (i = 0; i < wpabuf_len(data); i++) {
4916 ret = os_snprintf(pos, end - pos, "%02x", *d++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004917 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004918 return start;
4919 pos += ret;
4920 }
4921
4922 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004923 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004924 return start;
4925 pos += ret;
4926
4927 return pos;
4928}
4929#endif /* CONFIG_INTERWORKING */
4930
4931
Dmitry Shmidt29333592017-01-09 12:27:11 -08004932#ifdef CONFIG_FILS
4933static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4934{
4935 char *start = pos;
4936 const u8 *ie, *ie_end;
4937 u16 info, realms;
4938 int ret;
4939
4940 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4941 if (!ie)
4942 return 0;
4943 ie_end = ie + 2 + ie[1];
4944 ie += 2;
4945 if (ie_end - ie < 2)
4946 return -1;
4947
4948 info = WPA_GET_LE16(ie);
4949 ie += 2;
4950 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4951 if (os_snprintf_error(end - pos, ret))
4952 return 0;
4953 pos += ret;
4954
4955 if (info & BIT(7)) {
4956 /* Cache Identifier Included */
4957 if (ie_end - ie < 2)
4958 return -1;
4959 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4960 ie[0], ie[1]);
4961 if (os_snprintf_error(end - pos, ret))
4962 return 0;
4963 pos += ret;
4964 ie += 2;
4965 }
4966
4967 if (info & BIT(8)) {
4968 /* HESSID Included */
4969 if (ie_end - ie < ETH_ALEN)
4970 return -1;
4971 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4972 MAC2STR(ie));
4973 if (os_snprintf_error(end - pos, ret))
4974 return 0;
4975 pos += ret;
4976 ie += ETH_ALEN;
4977 }
4978
4979 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4980 if (realms) {
4981 if (ie_end - ie < realms * 2)
4982 return -1;
4983 ret = os_snprintf(pos, end - pos, "fils_realms=");
4984 if (os_snprintf_error(end - pos, ret))
4985 return 0;
4986 pos += ret;
4987
4988 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
4989 if (ret <= 0)
4990 return 0;
4991 pos += ret;
4992 ie += realms * 2;
4993 ret = os_snprintf(pos, end - pos, "\n");
4994 if (os_snprintf_error(end - pos, ret))
4995 return 0;
4996 pos += ret;
4997 }
4998
4999 return pos - start;
5000}
5001#endif /* CONFIG_FILS */
5002
5003
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005004static int print_rnr(struct wpa_bss *bss, char *pos, char *end)
5005{
5006 char *start = pos;
5007 const u8 *ie, *ie_end;
5008 unsigned int n = 0;
5009 int ret;
5010
5011 ie = wpa_bss_get_ie(bss, WLAN_EID_REDUCED_NEIGHBOR_REPORT);
5012 if (!ie)
5013 return 0;
5014
5015 ie_end = ie + 2 + ie[1];
5016 ie += 2;
5017
5018 while (ie < ie_end) {
5019 const struct ieee80211_neighbor_ap_info *info =
5020 (const struct ieee80211_neighbor_ap_info *) ie;
5021 const u8 *tbtt_start;
5022 size_t left = ie_end - ie;
5023
5024 if (left < sizeof(struct ieee80211_neighbor_ap_info))
5025 return 0;
5026
5027 left -= sizeof(struct ieee80211_neighbor_ap_info);
5028 if (left < info->tbtt_info_len)
5029 return 0;
5030
5031 ret = os_snprintf(pos, end - pos,
5032 "ap_info[%u]: tbtt_info: hdr=0x%x, len=%u, op_c=%u, channel=%u, ",
5033 n, *ie, info->tbtt_info_len,
5034 info->op_class, info->channel);
5035 if (os_snprintf_error(end - pos, ret))
5036 return 0;
5037 pos += ret;
5038
5039 ie += sizeof(struct ieee80211_neighbor_ap_info);
5040 tbtt_start = ie;
5041 if (info->tbtt_info_len >= 1) {
5042 ret = os_snprintf(pos, end - pos,
5043 "tbtt_offset=%u, ", *ie);
5044 if (os_snprintf_error(end - pos, ret))
5045 return 0;
5046
5047 ie++;
5048 pos += ret;
5049 }
5050
5051 if (info->tbtt_info_len >= 7) {
5052 ret = os_snprintf(pos, end - pos,
5053 "bssid=" MACSTR ", ",
5054 MAC2STR(ie));
5055 if (os_snprintf_error(end - pos, ret))
5056 return 0;
5057
5058 ie += ETH_ALEN;
5059 pos += ret;
5060 }
5061
5062 if (info->tbtt_info_len >= 11) {
5063 ret = os_snprintf(pos, end - pos,
5064 "short SSID=0x%x, ",
5065 WPA_GET_LE32(ie));
5066 if (os_snprintf_error(end - pos, ret))
5067 return 0;
5068
5069 ie += 4;
5070 pos += ret;
5071 }
5072
5073 if (info->tbtt_info_len >= 12) {
5074 ret = os_snprintf(pos, end - pos,
5075 "bss_params=0x%x, ", *ie);
5076 if (os_snprintf_error(end - pos, ret))
5077 return 0;
5078
5079 ie++;
5080 pos += ret;
5081 }
5082
5083 if (info->tbtt_info_len >= 13) {
5084 ret = os_snprintf(pos, end - pos,
5085 "PSD=0x%x, ", *ie);
5086 if (os_snprintf_error(end - pos, ret))
5087 return 0;
5088
5089 ie++;
5090 pos += ret;
5091 }
5092
5093 if (info->tbtt_info_len >= 16) {
5094 ret = os_snprintf(pos, end - pos,
5095 "mld ID=%u, link ID=%u",
5096 *ie, *(ie + 1) & 0xF);
5097 if (os_snprintf_error(end - pos, ret))
5098 return 0;
5099
5100 ie += 3;
5101 pos += ret;
5102 }
5103
5104 ie = tbtt_start + info->tbtt_info_len;
5105
5106 ret = os_snprintf(pos, end - pos, "\n");
5107 if (os_snprintf_error(end - pos, ret))
5108 return 0;
5109 pos += ret;
5110
5111 n++;
5112 }
5113
5114 return pos - start;
5115}
5116
5117
5118static int print_ml(struct wpa_bss *bss, char *pos, char *end)
5119{
5120 const struct ieee80211_eht_ml *ml;
5121 char *start = pos;
5122 const u8 *ie, *ie_end;
5123 u16 ml_control;
5124 u8 common_info_length;
5125 int ret;
5126
5127 ie = get_ml_ie(wpa_bss_ie_ptr(bss), bss->ie_len,
5128 MULTI_LINK_CONTROL_TYPE_BASIC);
5129 if (!ie)
5130 return 0;
5131
5132 ie_end = ie + 2 + ie[1];
5133 ie += 3;
5134 ml = (const struct ieee80211_eht_ml *) ie;
5135
5136 /* control + common info length + MLD MAC Address */
5137 if (ie_end - ie < 2 + 1 + ETH_ALEN)
5138 return 0;
5139
5140 ml_control = le_to_host16(ml->ml_control);
5141
5142 common_info_length = *(ie + 2);
5143 ret = os_snprintf(pos, end - pos,
5144 "multi-link: control=0x%x, common info len=%u",
5145 ml_control, common_info_length);
5146 if (os_snprintf_error(end - pos, ret))
5147 return 0;
5148 pos += ret;
5149
5150 ie += 2;
5151 if (ie_end - ie < common_info_length)
5152 return 0;
5153
5154 ie++;
5155 common_info_length--;
5156
5157 if (common_info_length < ETH_ALEN)
5158 return 0;
5159
5160 ret = os_snprintf(pos, end - pos, ", MLD addr=" MACSTR, MAC2STR(ie));
5161 if (os_snprintf_error(end - pos, ret))
5162 return 0;
5163 pos += ret;
5164
5165 ie += ETH_ALEN;
5166 common_info_length -= ETH_ALEN;
5167
5168 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_LINK_ID) {
5169 if (common_info_length < 1)
5170 return 0;
5171
5172 ret = os_snprintf(pos, end - pos, ", link ID=%u", *ie & 0x0f);
5173 if (os_snprintf_error(end - pos, ret))
5174 return 0;
5175 pos += ret;
5176 ie++;
5177 common_info_length--;
5178 }
5179
5180 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT) {
5181 if (common_info_length < 1)
5182 return 0;
5183
5184 ret = os_snprintf(pos, end - pos,
5185 ", BSS change parameters=0x%x", *ie);
5186 if (os_snprintf_error(end - pos, ret))
5187 return 0;
5188 pos += ret;
5189 ie++;
5190 common_info_length--;
5191 }
5192
5193 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) {
5194 if (common_info_length < 2)
5195 return 0;
5196
5197 ret = os_snprintf(pos, end - pos, ", MSD Info=0x%x",
5198 WPA_GET_LE16(ie));
5199 if (os_snprintf_error(end - pos, ret))
5200 return 0;
5201 pos += ret;
5202 ie += 2;
5203 common_info_length -= 2;
5204 }
5205
5206 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) {
5207 if (common_info_length < 2)
5208 return 0;
5209
5210 ret = os_snprintf(pos, end - pos, ", EML capabilities=0x%x",
5211 WPA_GET_LE16(ie));
5212 if (os_snprintf_error(end - pos, ret))
5213 return 0;
5214 pos += ret;
5215 ie += 2;
5216 common_info_length -= 2;
5217 }
5218
5219 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) {
5220 if (common_info_length < 2)
5221 return 0;
5222
5223 ret = os_snprintf(pos, end - pos, ", MLD capabilities=0x%x",
5224 WPA_GET_LE16(ie));
5225 if (os_snprintf_error(end - pos, ret))
5226 return 0;
5227 pos += ret;
5228 ie += 2;
5229 common_info_length -= 2;
5230 }
5231
5232 if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) {
5233 if (common_info_length < 1)
5234 return 0;
5235
5236 ret = os_snprintf(pos, end - pos, ", MLD ID=0x%x\n", *ie);
5237 if (os_snprintf_error(end - pos, ret))
5238 return 0;
5239 pos += ret;
5240 ie += 1;
5241 common_info_length--;
5242 }
5243
5244 return pos - start;
5245}
5246
5247
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005248static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
5249 unsigned long mask, char *buf, size_t buflen)
5250{
5251 size_t i;
5252 int ret;
5253 char *pos, *end;
Hai Shalom899fcc72020-10-19 14:38:18 -07005254 const u8 *ie, *ie2, *osen_ie, *mesh, *owe, *rsnxe;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005255
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005256 pos = buf;
5257 end = buf + buflen;
5258
5259 if (mask & WPA_BSS_MASK_ID) {
5260 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005261 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005262 return 0;
5263 pos += ret;
5264 }
5265
5266 if (mask & WPA_BSS_MASK_BSSID) {
5267 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
5268 MAC2STR(bss->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005269 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005270 return 0;
5271 pos += ret;
5272 }
5273
5274 if (mask & WPA_BSS_MASK_FREQ) {
5275 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005276 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005277 return 0;
5278 pos += ret;
5279 }
5280
5281 if (mask & WPA_BSS_MASK_BEACON_INT) {
5282 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
5283 bss->beacon_int);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005284 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005285 return 0;
5286 pos += ret;
5287 }
5288
5289 if (mask & WPA_BSS_MASK_CAPABILITIES) {
5290 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
5291 bss->caps);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005292 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005293 return 0;
5294 pos += ret;
5295 }
5296
5297 if (mask & WPA_BSS_MASK_QUAL) {
5298 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005299 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005300 return 0;
5301 pos += ret;
5302 }
5303
5304 if (mask & WPA_BSS_MASK_NOISE) {
5305 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005306 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005307 return 0;
5308 pos += ret;
5309 }
5310
5311 if (mask & WPA_BSS_MASK_LEVEL) {
5312 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005313 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005314 return 0;
5315 pos += ret;
5316 }
5317
5318 if (mask & WPA_BSS_MASK_TSF) {
5319 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
5320 (unsigned long long) bss->tsf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005321 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005322 return 0;
5323 pos += ret;
5324 }
5325
5326 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005327 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005328
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005329 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005330 ret = os_snprintf(pos, end - pos, "age=%d\n",
5331 (int) (now.sec - bss->last_update.sec));
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_IE) {
5338 ret = os_snprintf(pos, end - pos, "ie=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005339 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005340 return 0;
5341 pos += ret;
5342
Hai Shalom60840252021-02-19 19:02:11 -08005343 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005344 for (i = 0; i < bss->ie_len; i++) {
5345 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005346 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005347 return 0;
5348 pos += ret;
5349 }
5350
5351 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005352 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005353 return 0;
5354 pos += ret;
5355 }
5356
5357 if (mask & WPA_BSS_MASK_FLAGS) {
5358 ret = os_snprintf(pos, end - pos, "flags=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005359 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005360 return 0;
5361 pos += ret;
5362
Dmitry Shmidt29333592017-01-09 12:27:11 -08005363 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
5364
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005365 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
5366 if (ie)
5367 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
5368 2 + ie[1]);
5369 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
5370 if (ie2)
Dmitry Shmidt29333592017-01-09 12:27:11 -08005371 pos = wpa_supplicant_ie_txt(pos, end,
5372 mesh ? "RSN" : "WPA2", ie2,
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005373 2 + ie2[1]);
Hai Shalom899fcc72020-10-19 14:38:18 -07005374 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shaloma20dcd72022-02-04 13:43:00 -08005375 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
5376 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
5377 if (os_snprintf_error(end - pos, ret))
5378 return -1;
5379 pos += ret;
5380 }
5381 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
5382 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
5383 if (os_snprintf_error(end - pos, ret))
5384 return -1;
5385 pos += ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07005386 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005387 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
5388 if (osen_ie)
5389 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
5390 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005391 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
5392 if (owe) {
5393 ret = os_snprintf(
5394 pos, end - pos,
5395 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
5396 if (os_snprintf_error(end - pos, ret))
5397 return 0;
5398 pos += ret;
5399 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005400 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005401 if (!ie && !ie2 && !osen_ie &&
5402 (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005403 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005404 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005405 return 0;
5406 pos += ret;
5407 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005408
5409 if (mesh) {
5410 ret = os_snprintf(pos, end - pos, "[MESH]");
5411 if (os_snprintf_error(end - pos, ret))
5412 return 0;
5413 pos += ret;
5414 }
5415
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005416 if (bss_is_dmg(bss)) {
5417 const char *s;
5418 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005419 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005420 return 0;
5421 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005422 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
5423 case IEEE80211_CAP_DMG_IBSS:
5424 s = "[IBSS]";
5425 break;
5426 case IEEE80211_CAP_DMG_AP:
5427 s = "[ESS]";
5428 break;
5429 case IEEE80211_CAP_DMG_PBSS:
5430 s = "[PBSS]";
5431 break;
5432 default:
5433 s = "";
5434 break;
5435 }
5436 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005437 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005438 return 0;
5439 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005440 } else {
5441 if (bss->caps & IEEE80211_CAP_IBSS) {
5442 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005443 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005444 return 0;
5445 pos += ret;
5446 }
5447 if (bss->caps & IEEE80211_CAP_ESS) {
5448 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005449 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005450 return 0;
5451 pos += ret;
5452 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005453 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07005454 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
5455 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005456 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005457 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005458 return 0;
5459 pos += ret;
5460 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005461#ifdef CONFIG_HS20
5462 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
5463 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005464 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005465 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005466 pos += ret;
5467 }
5468#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005469#ifdef CONFIG_FILS
5470 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
5471 ret = os_snprintf(pos, end - pos, "[FILS]");
5472 if (os_snprintf_error(end - pos, ret))
5473 return 0;
5474 pos += ret;
5475 }
5476#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08005477#ifdef CONFIG_FST
5478 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
5479 ret = os_snprintf(pos, end - pos, "[FST]");
5480 if (os_snprintf_error(end - pos, ret))
5481 return 0;
5482 pos += ret;
5483 }
5484#endif /* CONFIG_FST */
5485 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
5486 ret = os_snprintf(pos, end - pos, "[UTF-8]");
5487 if (os_snprintf_error(end - pos, ret))
5488 return 0;
5489 pos += ret;
5490 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005491
5492 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005493 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005494 return 0;
5495 pos += ret;
5496 }
5497
5498 if (mask & WPA_BSS_MASK_SSID) {
5499 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
5500 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005501 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005502 return 0;
5503 pos += ret;
5504 }
5505
5506#ifdef CONFIG_WPS
5507 if (mask & WPA_BSS_MASK_WPS_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005508 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005509 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005510 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005511 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005512 if (ret > 0)
5513 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005514 }
5515#endif /* CONFIG_WPS */
5516
5517#ifdef CONFIG_P2P
5518 if (mask & WPA_BSS_MASK_P2P_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_p2p_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005521 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005522 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005523 if (ret > 0)
5524 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005525 }
5526#endif /* CONFIG_P2P */
5527
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005528#ifdef CONFIG_WIFI_DISPLAY
5529 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
5530 struct wpabuf *wfd;
Hai Shalom60840252021-02-19 19:02:11 -08005531
5532 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005533 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
5534 WFD_IE_VENDOR_TYPE);
5535 if (wfd) {
5536 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005537 if (os_snprintf_error(end - pos, ret)) {
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005538 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005539 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005540 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005541 pos += ret;
5542
5543 pos += wpa_snprintf_hex(pos, end - pos,
5544 wpabuf_head(wfd),
5545 wpabuf_len(wfd));
5546 wpabuf_free(wfd);
5547
5548 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005549 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005550 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005551 pos += ret;
5552 }
5553 }
5554#endif /* CONFIG_WIFI_DISPLAY */
5555
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005556#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005557 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
5558 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005559 struct wpa_bss_anqp_elem *elem;
5560
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005561 pos = anqp_add_hex(pos, end, "anqp_capability_list",
5562 anqp->capability_list);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005563 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005564 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005565 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005566 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005567 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005568 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005569 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005570 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005571 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005572 anqp->nai_realm);
5573 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005574 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005575 anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005576 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
5577 anqp->fils_realm_info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005578#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005579 pos = anqp_add_hex(pos, end, "hs20_capability_list",
5580 anqp->hs20_capability_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005581 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005582 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005583 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005584 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005585 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005586 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005587 pos = anqp_add_hex(pos, end, "hs20_operating_class",
5588 anqp->hs20_operating_class);
5589 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
5590 anqp->hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005591 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
5592 anqp->hs20_operator_icon_metadata);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005593 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
5594 anqp->hs20_osu_providers_nai_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005595#endif /* CONFIG_HS20 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005596
5597 dl_list_for_each(elem, &anqp->anqp_elems,
5598 struct wpa_bss_anqp_elem, list) {
5599 char title[20];
5600
5601 os_snprintf(title, sizeof(title), "anqp[%u]",
5602 elem->infoid);
5603 pos = anqp_add_hex(pos, end, title, elem->payload);
Hai Shalom60840252021-02-19 19:02:11 -08005604 if (elem->protected_response) {
5605 ret = os_snprintf(pos, end - pos,
5606 "protected-anqp-info[%u]=1\n",
5607 elem->infoid);
5608 if (os_snprintf_error(end - pos, ret))
5609 return 0;
5610 pos += ret;
5611 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005612 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005613 }
5614#endif /* CONFIG_INTERWORKING */
5615
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005616#ifdef CONFIG_MESH
5617 if (mask & WPA_BSS_MASK_MESH_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005618 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005619 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005620 if (ret >= end - pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005621 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005622 if (ret > 0)
5623 pos += ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005624 }
5625#endif /* CONFIG_MESH */
5626
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005627 if (mask & WPA_BSS_MASK_SNR) {
5628 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
5629 if (os_snprintf_error(end - pos, ret))
5630 return 0;
5631 pos += ret;
5632 }
5633
5634 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
5635 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
5636 bss->est_throughput);
5637 if (os_snprintf_error(end - pos, ret))
5638 return 0;
5639 pos += ret;
5640 }
5641
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005642#ifdef CONFIG_FST
5643 if (mask & WPA_BSS_MASK_FST) {
5644 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
5645 if (ret < 0 || ret >= end - pos)
5646 return 0;
5647 pos += ret;
5648 }
5649#endif /* CONFIG_FST */
5650
Dmitry Shmidt29333592017-01-09 12:27:11 -08005651 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
5652 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
5653 bss->last_update_idx);
5654 if (os_snprintf_error(end - pos, ret))
5655 return 0;
5656 pos += ret;
5657 }
5658
5659 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
5660 ret = os_snprintf(pos, end - pos, "beacon_ie=");
5661 if (os_snprintf_error(end - pos, ret))
5662 return 0;
5663 pos += ret;
5664
Hai Shalom60840252021-02-19 19:02:11 -08005665 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005666 ie += bss->ie_len;
5667 for (i = 0; i < bss->beacon_ie_len; i++) {
5668 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
5669 if (os_snprintf_error(end - pos, ret))
5670 return 0;
5671 pos += ret;
5672 }
5673
5674 ret = os_snprintf(pos, end - pos, "\n");
5675 if (os_snprintf_error(end - pos, ret))
5676 return 0;
5677 pos += ret;
5678 }
5679
5680#ifdef CONFIG_FILS
5681 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
5682 ret = print_fils_indication(bss, pos, end);
5683 if (ret < 0)
5684 return 0;
5685 pos += ret;
5686 }
5687#endif /* CONFIG_FILS */
5688
Sunil Ravi89eba102022-09-13 21:04:37 -07005689 if (!is_zero_ether_addr(bss->mld_addr)) {
5690 ret = os_snprintf(pos, end - pos,
5691 "ap_mld_addr=" MACSTR "\n",
5692 MAC2STR(bss->mld_addr));
5693 if (os_snprintf_error(end - pos, ret))
5694 return 0;
5695 pos += ret;
5696 }
5697
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005698 if (mask & WPA_BSS_MASK_RNR)
5699 pos += print_rnr(bss, pos, end);
5700
5701 if (mask & WPA_BSS_MASK_ML)
5702 pos += print_ml(bss, pos, end);
5703
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005704 if (mask & WPA_BSS_MASK_DELIM) {
5705 ret = os_snprintf(pos, end - pos, "====\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005706 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005707 return 0;
5708 pos += ret;
5709 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07005710
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005711 return pos - buf;
5712}
5713
Dmitry Shmidt04949592012-07-19 12:16:46 -07005714
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005715static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
5716 const char *cmd, char *buf,
5717 size_t buflen)
5718{
5719 u8 bssid[ETH_ALEN];
5720 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005721 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005722 struct wpa_bss *bsslast = NULL;
5723 struct dl_list *next;
5724 int ret = 0;
5725 int len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005726 char *ctmp, *end = buf + buflen;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005727 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005728
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005729 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
5730 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
5731 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005732 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005733 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
5734 list_id);
5735 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005736 unsigned int id1, id2;
5737
5738 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
5739 wpa_printf(MSG_INFO, "Wrong BSS range "
5740 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005741 return 0;
5742 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005743
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005744 if (*(cmd + 6) == '-')
5745 id1 = 0;
5746 else
5747 id1 = atoi(cmd + 6);
5748 ctmp++;
5749 if (*ctmp >= '0' && *ctmp <= '9')
5750 id2 = atoi(ctmp);
5751 else
5752 id2 = (unsigned int) -1;
5753 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
5754 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005755 bsslast = dl_list_last(&wpa_s->bss_id,
5756 struct wpa_bss,
5757 list_id);
5758 else {
5759 bsslast = wpa_bss_get_id(wpa_s, id2);
5760 if (bsslast == NULL && bss && id2 > id1) {
5761 struct wpa_bss *tmp = bss;
5762 for (;;) {
5763 next = tmp->list_id.next;
5764 if (next == &wpa_s->bss_id)
5765 break;
5766 tmp = dl_list_entry(
5767 next, struct wpa_bss,
5768 list_id);
5769 if (tmp->id > id2)
5770 break;
5771 bsslast = tmp;
5772 }
5773 }
5774 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005775 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005776 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005777 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005778 else if (os_strncmp(cmd, "LAST", 4) == 0)
5779 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005780 else if (os_strncmp(cmd, "ID-", 3) == 0) {
5781 i = atoi(cmd + 3);
5782 bss = wpa_bss_get_id(wpa_s, i);
5783 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5784 i = atoi(cmd + 5);
5785 bss = wpa_bss_get_id(wpa_s, i);
5786 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005787 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005788 if (next == &wpa_s->bss_id)
5789 bss = NULL;
5790 else
5791 bss = dl_list_entry(next, struct wpa_bss,
5792 list_id);
5793 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005794 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5795 bss = wpa_s->current_bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005796#ifdef CONFIG_P2P
5797 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5798 if (hwaddr_aton(cmd + 13, bssid) == 0)
5799 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5800 else
5801 bss = NULL;
5802#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005803 } else if (hwaddr_aton(cmd, bssid) == 0)
5804 bss = wpa_bss_get_bssid(wpa_s, bssid);
5805 else {
5806 struct wpa_bss *tmp;
5807 i = atoi(cmd);
5808 bss = NULL;
5809 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5810 {
Hai Shalom021b0b52019-04-10 11:17:58 -07005811 if (i == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005812 bss = tmp;
5813 break;
5814 }
Hai Shalom021b0b52019-04-10 11:17:58 -07005815 i--;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005816 }
5817 }
5818
Dmitry Shmidt04949592012-07-19 12:16:46 -07005819 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5820 mask = strtoul(ctmp + 5, NULL, 0x10);
5821 if (mask == 0)
5822 mask = WPA_BSS_MASK_ALL;
5823 }
5824
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005825 if (bss == NULL)
5826 return 0;
5827
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005828 if (bsslast == NULL)
5829 bsslast = bss;
5830 do {
5831 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5832 ret += len;
5833 buf += len;
5834 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005835 if (bss == bsslast) {
5836 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5837 (bss == dl_list_last(&wpa_s->bss_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005838 struct wpa_bss, list_id))) {
5839 int res;
5840
5841 res = os_snprintf(buf - 5, end - buf + 5,
5842 "####\n");
5843 if (os_snprintf_error(end - buf + 5, res)) {
5844 wpa_printf(MSG_DEBUG,
5845 "Could not add end delim");
5846 }
5847 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005848 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005849 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005850 next = bss->list_id.next;
5851 if (next == &wpa_s->bss_id)
5852 break;
5853 bss = dl_list_entry(next, struct wpa_bss, list_id);
5854 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005855
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005856 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005857}
5858
5859
5860static int wpa_supplicant_ctrl_iface_ap_scan(
5861 struct wpa_supplicant *wpa_s, char *cmd)
5862{
5863 int ap_scan = atoi(cmd);
5864 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5865}
5866
5867
5868static int wpa_supplicant_ctrl_iface_scan_interval(
5869 struct wpa_supplicant *wpa_s, char *cmd)
5870{
5871 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005872 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005873}
5874
5875
5876static int wpa_supplicant_ctrl_iface_bss_expire_age(
5877 struct wpa_supplicant *wpa_s, char *cmd)
5878{
5879 int expire_age = atoi(cmd);
5880 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5881}
5882
5883
5884static int wpa_supplicant_ctrl_iface_bss_expire_count(
5885 struct wpa_supplicant *wpa_s, char *cmd)
5886{
5887 int expire_count = atoi(cmd);
5888 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5889}
5890
5891
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005892static void wpa_supplicant_ctrl_iface_bss_flush(
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005893 struct wpa_supplicant *wpa_s, char *cmd)
5894{
5895 int flush_age = atoi(cmd);
5896
5897 if (flush_age == 0)
5898 wpa_bss_flush(wpa_s);
5899 else
5900 wpa_bss_flush_by_age(wpa_s, flush_age);
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005901}
5902
5903
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005904#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005905static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5906{
5907 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5908 /* MLME-DELETEKEYS.request */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005909 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005910 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005911 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005912 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005913 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005914 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005915 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005916 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005917 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005918 0, KEY_FLAG_GROUP);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005919 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005920 0, KEY_FLAG_GROUP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005921
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005922 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0,
5923 NULL, 0, KEY_FLAG_PAIRWISE);
Hai Shalomfdcde762020-04-02 11:19:20 -07005924 if (wpa_sm_ext_key_id(wpa_s->wpa))
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00005925 wpa_drv_set_key(wpa_s, -1, WPA_ALG_NONE, wpa_s->bssid, 1, 0,
Hai Shalomfdcde762020-04-02 11:19:20 -07005926 NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005927 /* MLME-SETPROTECTION.request(None) */
5928 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5929 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5930 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5931 wpa_sm_drop_sa(wpa_s->wpa);
5932}
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005933#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005934
5935
5936static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5937 char *addr)
5938{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005939#ifdef CONFIG_NO_SCAN_PROCESSING
5940 return -1;
5941#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005942 u8 bssid[ETH_ALEN];
5943 struct wpa_bss *bss;
5944 struct wpa_ssid *ssid = wpa_s->current_ssid;
Hai Shaloma20dcd72022-02-04 13:43:00 -08005945 struct wpa_radio_work *already_connecting;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005946
5947 if (hwaddr_aton(addr, bssid)) {
5948 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5949 "address '%s'", addr);
5950 return -1;
5951 }
5952
5953 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5954
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005955 if (!ssid) {
5956 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5957 "configuration known for the target AP");
5958 return -1;
5959 }
5960
5961 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005962 if (!bss) {
5963 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
5964 "from BSS table");
5965 return -1;
5966 }
5967
5968 /*
5969 * TODO: Find best network configuration block from configuration to
5970 * allow roaming to other networks
5971 */
5972
Hai Shaloma20dcd72022-02-04 13:43:00 -08005973 already_connecting = radio_work_pending(wpa_s, "sme-connect");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005974 wpa_s->reassociate = 1;
5975 wpa_supplicant_connect(wpa_s, bss, ssid);
5976
Hai Shaloma20dcd72022-02-04 13:43:00 -08005977 /*
5978 * Indicate that an explicitly requested roam is in progress so scan
5979 * results that come in before the 'sme-connect' radio work gets
5980 * executed do not override the original connection attempt.
5981 */
5982 if (!already_connecting && radio_work_pending(wpa_s, "sme-connect"))
5983 wpa_s->roam_in_progress = true;
5984
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005985 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005986#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005987}
5988
5989
5990#ifdef CONFIG_P2P
5991static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
5992{
5993 unsigned int timeout = atoi(cmd);
5994 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005995 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005996 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005997 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005998 unsigned int search_delay;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005999 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006000 u8 seek_count = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006001 int freq = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006002 bool include_6ghz = false;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006003
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006004 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6005 wpa_dbg(wpa_s, MSG_INFO,
6006 "Reject P2P_FIND since interface is disabled");
6007 return -1;
6008 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08006009
6010 if (os_strstr(cmd, " include_6ghz"))
6011 include_6ghz = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006012 if (os_strstr(cmd, "type=social"))
6013 type = P2P_FIND_ONLY_SOCIAL;
6014 else if (os_strstr(cmd, "type=progressive"))
6015 type = P2P_FIND_PROGRESSIVE;
6016
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006017 pos = os_strstr(cmd, "dev_id=");
6018 if (pos) {
6019 pos += 7;
6020 if (hwaddr_aton(pos, dev_id))
6021 return -1;
6022 _dev_id = dev_id;
6023 }
6024
Dmitry Shmidt344abd32014-01-14 13:17:00 -08006025 pos = os_strstr(cmd, "dev_type=");
6026 if (pos) {
6027 pos += 9;
6028 if (wps_dev_type_str2bin(pos, dev_type) < 0)
6029 return -1;
6030 _dev_type = dev_type;
6031 }
6032
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006033 pos = os_strstr(cmd, "delay=");
6034 if (pos) {
6035 pos += 6;
6036 search_delay = atoi(pos);
6037 } else
6038 search_delay = wpas_p2p_search_delay(wpa_s);
6039
Dmitry Shmidt41712582015-06-29 11:02:15 -07006040 pos = os_strstr(cmd, "freq=");
6041 if (pos) {
6042 pos += 5;
6043 freq = atoi(pos);
6044 if (freq <= 0)
6045 return -1;
6046 }
6047
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006048 /* Must be searched for last, because it adds nul termination */
6049 pos = os_strstr(cmd, " seek=");
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006050 if (pos)
6051 pos += 6;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006052 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
6053 char *term;
6054
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006055 _seek[seek_count++] = pos;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006056 seek = _seek;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006057 term = os_strchr(pos, ' ');
6058 if (!term)
6059 break;
6060 *term = '\0';
6061 pos = os_strstr(term + 1, "seek=");
6062 if (pos)
6063 pos += 5;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006064 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006065 if (seek_count > P2P_MAX_QUERY_HASH) {
6066 seek[0] = NULL;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006067 seek_count = 1;
6068 }
6069
Dmitry Shmidt344abd32014-01-14 13:17:00 -08006070 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006071 _dev_id, search_delay, seek_count, seek, freq,
6072 include_6ghz);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006073}
6074
6075
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006076static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
6077{
6078 const char *last = NULL;
6079 const char *token;
6080 long int token_len;
6081 unsigned int i;
6082
6083 /* Expected predefined CPT names delimited by ':' */
6084 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
6085 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
6086 wpa_printf(MSG_ERROR,
6087 "P2PS: CPT name list is too long, expected up to %d names",
6088 P2PS_FEATURE_CAPAB_CPT_MAX);
6089 cpt[0] = 0;
6090 return -1;
6091 }
6092
6093 token_len = last - token;
6094
6095 if (token_len == 3 &&
6096 os_memcmp(token, "UDP", token_len) == 0) {
6097 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6098 } else if (token_len == 3 &&
6099 os_memcmp(token, "MAC", token_len) == 0) {
6100 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
6101 } else {
6102 wpa_printf(MSG_ERROR,
6103 "P2PS: Unsupported CPT name '%s'", token);
6104 cpt[0] = 0;
6105 return -1;
6106 }
6107
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006108 if (isblank((unsigned char) *last)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006109 i++;
6110 break;
6111 }
6112 }
6113 cpt[i] = 0;
6114 return 0;
6115}
6116
6117
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006118static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
6119{
6120 struct p2ps_provision *p2ps_prov;
6121 char *pos;
6122 size_t info_len = 0;
6123 char *info = NULL;
6124 u8 role = P2PS_SETUP_NONE;
6125 long long unsigned val;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006126 int i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006127
6128 pos = os_strstr(cmd, "info=");
6129 if (pos) {
6130 pos += 5;
6131 info_len = os_strlen(pos);
6132
6133 if (info_len) {
6134 info = os_malloc(info_len + 1);
6135 if (info) {
6136 info_len = utf8_unescape(pos, info_len,
6137 info, info_len + 1);
6138 } else
6139 info_len = 0;
6140 }
6141 }
6142
6143 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
6144 if (p2ps_prov == NULL) {
6145 os_free(info);
6146 return NULL;
6147 }
6148
6149 if (info) {
6150 os_memcpy(p2ps_prov->info, info, info_len);
6151 p2ps_prov->info[info_len] = '\0';
6152 os_free(info);
6153 }
6154
6155 pos = os_strstr(cmd, "status=");
6156 if (pos)
6157 p2ps_prov->status = atoi(pos + 7);
6158 else
6159 p2ps_prov->status = -1;
6160
6161 pos = os_strstr(cmd, "adv_id=");
6162 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
6163 goto invalid_args;
6164 p2ps_prov->adv_id = val;
6165
6166 pos = os_strstr(cmd, "method=");
6167 if (pos)
6168 p2ps_prov->method = strtol(pos + 7, NULL, 16);
6169 else
6170 p2ps_prov->method = 0;
6171
6172 pos = os_strstr(cmd, "session=");
6173 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
6174 goto invalid_args;
6175 p2ps_prov->session_id = val;
6176
6177 pos = os_strstr(cmd, "adv_mac=");
6178 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
6179 goto invalid_args;
6180
6181 pos = os_strstr(cmd, "session_mac=");
6182 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
6183 goto invalid_args;
6184
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006185 pos = os_strstr(cmd, "cpt=");
6186 if (pos) {
6187 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
6188 p2ps_prov->cpt_priority))
6189 goto invalid_args;
6190 } else {
6191 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6192 }
6193
6194 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
6195 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
6196
Hai Shaloma20dcd72022-02-04 13:43:00 -08006197 /* force conncap with tstCap (no validity checks) */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006198 pos = os_strstr(cmd, "tstCap=");
6199 if (pos) {
6200 role = strtol(pos + 7, NULL, 16);
6201 } else {
6202 pos = os_strstr(cmd, "role=");
6203 if (pos) {
6204 role = strtol(pos + 5, NULL, 16);
6205 if (role != P2PS_SETUP_CLIENT &&
6206 role != P2PS_SETUP_GROUP_OWNER)
6207 role = P2PS_SETUP_NONE;
6208 }
6209 }
6210 p2ps_prov->role = role;
6211
6212 return p2ps_prov;
6213
6214invalid_args:
6215 os_free(p2ps_prov);
6216 return NULL;
6217}
6218
6219
6220static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
6221{
6222 u8 addr[ETH_ALEN];
6223 struct p2ps_provision *p2ps_prov;
6224 char *pos;
6225
6226 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
6227
6228 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
6229
6230 if (hwaddr_aton(cmd, addr))
6231 return -1;
6232
6233 pos = cmd + 17;
6234 if (*pos != ' ')
6235 return -1;
6236
6237 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
6238 if (!p2ps_prov)
6239 return -1;
6240
6241 if (p2ps_prov->status < 0) {
6242 os_free(p2ps_prov);
6243 return -1;
6244 }
6245
6246 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
6247 p2ps_prov);
6248}
6249
6250
6251static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
6252{
6253 u8 addr[ETH_ALEN];
6254 struct p2ps_provision *p2ps_prov;
6255 char *pos;
6256
6257 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
6258 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
6259 */
6260
6261 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
6262 if (hwaddr_aton(cmd, addr))
6263 return -1;
6264
6265 pos = cmd + 17;
6266 if (*pos != ' ')
6267 return -1;
6268
6269 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
6270 if (!p2ps_prov)
6271 return -1;
6272
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006273 p2ps_prov->pd_seeker = 1;
6274
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006275 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
6276 p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006277}
6278
6279
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006280static int parse_freq(int chwidth, int freq2)
6281{
6282 if (freq2 < 0)
6283 return -1;
6284 if (freq2)
Sunil8cd6f4d2022-06-28 18:40:46 +00006285 return CONF_OPER_CHWIDTH_80P80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006286
6287 switch (chwidth) {
6288 case 0:
6289 case 20:
6290 case 40:
Sunil8cd6f4d2022-06-28 18:40:46 +00006291 return CONF_OPER_CHWIDTH_USE_HT;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006292 case 80:
Sunil8cd6f4d2022-06-28 18:40:46 +00006293 return CONF_OPER_CHWIDTH_80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006294 case 160:
Sunil8cd6f4d2022-06-28 18:40:46 +00006295 return CONF_OPER_CHWIDTH_160MHZ;
6296 case 320:
6297 return CONF_OPER_CHWIDTH_320MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006298 default:
6299 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
6300 chwidth);
6301 return -1;
6302 }
6303}
6304
6305
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006306static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
6307 char *buf, size_t buflen)
6308{
6309 u8 addr[ETH_ALEN];
6310 char *pos, *pos2;
6311 char *pin = NULL;
6312 enum p2p_wps_method wps_method;
6313 int new_pin;
6314 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006315 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006316 int join;
6317 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006318 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006319 int go_intent = -1;
6320 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006321 int pd;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006322 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006323 int edmg;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006324 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
6325 size_t group_ssid_len = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08006326 int he;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006327 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006328
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006329 if (!wpa_s->global->p2p_init_wpa_s)
6330 return -1;
6331 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
6332 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
6333 wpa_s->global->p2p_init_wpa_s->ifname);
6334 wpa_s = wpa_s->global->p2p_init_wpa_s;
6335 }
6336
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006337 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
Dmitry Shmidt04949592012-07-19 12:16:46 -07006338 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006339 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006340 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006341
6342 if (hwaddr_aton(cmd, addr))
6343 return -1;
6344
6345 pos = cmd + 17;
6346 if (*pos != ' ')
6347 return -1;
6348 pos++;
6349
6350 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006351 pos2 = os_strstr(pos, " persistent=");
6352 if (pos2) {
6353 struct wpa_ssid *ssid;
6354 persistent_id = atoi(pos2 + 12);
6355 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
6356 if (ssid == NULL || ssid->disabled != 2 ||
6357 ssid->mode != WPAS_MODE_P2P_GO) {
6358 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
6359 "SSID id=%d for persistent P2P group (GO)",
6360 persistent_id);
6361 return -1;
6362 }
6363 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006364 join = os_strstr(pos, " join") != NULL;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006365 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006366 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006367 automatic = os_strstr(pos, " auto") != NULL;
6368 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006369 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6370 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6371 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006372 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006373 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006374
6375 pos2 = os_strstr(pos, " go_intent=");
6376 if (pos2) {
6377 pos2 += 11;
6378 go_intent = atoi(pos2);
6379 if (go_intent < 0 || go_intent > 15)
6380 return -1;
6381 }
6382
6383 pos2 = os_strstr(pos, " freq=");
6384 if (pos2) {
6385 pos2 += 6;
6386 freq = atoi(pos2);
6387 if (freq <= 0)
6388 return -1;
6389 }
6390
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006391 pos2 = os_strstr(pos, " freq2=");
6392 if (pos2)
6393 freq2 = atoi(pos2 + 7);
6394
6395 pos2 = os_strstr(pos, " max_oper_chwidth=");
6396 if (pos2)
6397 chwidth = atoi(pos2 + 18);
6398
6399 max_oper_chwidth = parse_freq(chwidth, freq2);
6400 if (max_oper_chwidth < 0)
6401 return -1;
6402
Hai Shaloma20dcd72022-02-04 13:43:00 -08006403 if (allow_6ghz && chwidth == 40)
Sunil8cd6f4d2022-06-28 18:40:46 +00006404 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006405
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006406 pos2 = os_strstr(pos, " ssid=");
6407 if (pos2) {
6408 char *end;
6409
6410 pos2 += 6;
6411 end = os_strchr(pos2, ' ');
6412 if (!end)
6413 group_ssid_len = os_strlen(pos2) / 2;
6414 else
6415 group_ssid_len = (end - pos2) / 2;
6416 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
6417 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
6418 return -1;
6419 group_ssid = _group_ssid;
6420 }
6421
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006422 if (os_strncmp(pos, "pin", 3) == 0) {
6423 /* Request random PIN (to be displayed) and enable the PIN */
6424 wps_method = WPS_PIN_DISPLAY;
6425 } else if (os_strncmp(pos, "pbc", 3) == 0) {
6426 wps_method = WPS_PBC;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006427 } else if (os_strstr(pos, "p2ps") != NULL) {
6428 wps_method = WPS_P2PS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006429 } else {
6430 pin = pos;
6431 pos = os_strchr(pin, ' ');
6432 wps_method = WPS_PIN_KEYPAD;
6433 if (pos) {
6434 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006435 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006436 wps_method = WPS_PIN_DISPLAY;
6437 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006438 if (!wps_pin_str_valid(pin)) {
6439 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
6440 return 17;
6441 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006442 }
6443
6444 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006445 persistent_group, automatic, join,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006446 auth, go_intent, freq, freq2, persistent_id,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006447 pd, ht40, vht, max_oper_chwidth, he, edmg,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006448 group_ssid, group_ssid_len, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006449 if (new_pin == -2) {
6450 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
6451 return 25;
6452 }
6453 if (new_pin == -3) {
6454 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
6455 return 25;
6456 }
6457 if (new_pin < 0)
6458 return -1;
6459 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
6460 ret = os_snprintf(buf, buflen, "%08d", new_pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006461 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006462 return -1;
6463 return ret;
6464 }
6465
6466 os_memcpy(buf, "OK\n", 3);
6467 return 3;
6468}
6469
6470
6471static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
6472{
6473 unsigned int timeout = atoi(cmd);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006474 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6475 wpa_dbg(wpa_s, MSG_INFO,
6476 "Reject P2P_LISTEN since interface is disabled");
6477 return -1;
6478 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006479 return wpas_p2p_listen(wpa_s, timeout);
6480}
6481
6482
6483static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
6484{
6485 u8 addr[ETH_ALEN];
6486 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006487 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006488
Dmitry Shmidt04949592012-07-19 12:16:46 -07006489 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006490
6491 if (hwaddr_aton(cmd, addr))
6492 return -1;
6493
6494 pos = cmd + 17;
6495 if (*pos != ' ')
6496 return -1;
6497 pos++;
6498
Dmitry Shmidt04949592012-07-19 12:16:46 -07006499 if (os_strstr(pos, " join") != NULL)
6500 use = WPAS_P2P_PD_FOR_JOIN;
6501 else if (os_strstr(pos, " auto") != NULL)
6502 use = WPAS_P2P_PD_AUTO;
6503
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006504 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006505}
6506
6507
6508static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
6509 size_t buflen)
6510{
6511 struct wpa_ssid *ssid = wpa_s->current_ssid;
6512
6513 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
6514 ssid->passphrase == NULL)
6515 return -1;
6516
6517 os_strlcpy(buf, ssid->passphrase, buflen);
6518 return os_strlen(buf);
6519}
6520
6521
6522static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
6523 char *buf, size_t buflen)
6524{
6525 u64 ref;
6526 int res;
6527 u8 dst_buf[ETH_ALEN], *dst;
6528 struct wpabuf *tlvs;
6529 char *pos;
6530 size_t len;
6531
6532 if (hwaddr_aton(cmd, dst_buf))
6533 return -1;
6534 dst = dst_buf;
6535 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
6536 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
6537 dst = NULL;
6538 pos = cmd + 17;
6539 if (*pos != ' ')
6540 return -1;
6541 pos++;
6542
6543 if (os_strncmp(pos, "upnp ", 5) == 0) {
6544 u8 version;
6545 pos += 5;
6546 if (hexstr2bin(pos, &version, 1) < 0)
6547 return -1;
6548 pos += 2;
6549 if (*pos != ' ')
6550 return -1;
6551 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006552 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006553#ifdef CONFIG_WIFI_DISPLAY
6554 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
6555 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
6556#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006557 } else if (os_strncmp(pos, "asp ", 4) == 0) {
6558 char *svc_str;
6559 char *svc_info = NULL;
6560 u32 id;
6561
6562 pos += 4;
6563 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
6564 return -1;
6565
6566 pos = os_strchr(pos, ' ');
6567 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
6568 return -1;
6569
6570 svc_str = pos + 1;
6571
6572 pos = os_strchr(svc_str, ' ');
6573
6574 if (pos)
6575 *pos++ = '\0';
6576
6577 /* All remaining data is the svc_info string */
6578 if (pos && pos[0] && pos[0] != ' ') {
6579 len = os_strlen(pos);
6580
6581 /* Unescape in place */
6582 len = utf8_unescape(pos, len, pos, len);
6583 if (len > 0xff)
6584 return -1;
6585
6586 svc_info = pos;
6587 }
6588
6589 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
6590 svc_str, svc_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006591 } else {
6592 len = os_strlen(pos);
6593 if (len & 1)
6594 return -1;
6595 len /= 2;
6596 tlvs = wpabuf_alloc(len);
6597 if (tlvs == NULL)
6598 return -1;
6599 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
6600 wpabuf_free(tlvs);
6601 return -1;
6602 }
6603
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006604 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006605 wpabuf_free(tlvs);
6606 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006607 if (ref == 0)
6608 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006609 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006610 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006611 return -1;
6612 return res;
6613}
6614
6615
6616static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
6617 char *cmd)
6618{
6619 long long unsigned val;
6620 u64 req;
6621 if (sscanf(cmd, "%llx", &val) != 1)
6622 return -1;
6623 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006624 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006625}
6626
6627
6628static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
6629{
6630 int freq;
6631 u8 dst[ETH_ALEN];
6632 u8 dialog_token;
6633 struct wpabuf *resp_tlvs;
6634 char *pos, *pos2;
6635 size_t len;
6636
6637 pos = os_strchr(cmd, ' ');
6638 if (pos == NULL)
6639 return -1;
6640 *pos++ = '\0';
6641 freq = atoi(cmd);
6642 if (freq == 0)
6643 return -1;
6644
6645 if (hwaddr_aton(pos, dst))
6646 return -1;
6647 pos += 17;
6648 if (*pos != ' ')
6649 return -1;
6650 pos++;
6651
6652 pos2 = os_strchr(pos, ' ');
6653 if (pos2 == NULL)
6654 return -1;
6655 *pos2++ = '\0';
6656 dialog_token = atoi(pos);
6657
6658 len = os_strlen(pos2);
6659 if (len & 1)
6660 return -1;
6661 len /= 2;
6662 resp_tlvs = wpabuf_alloc(len);
6663 if (resp_tlvs == NULL)
6664 return -1;
6665 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
6666 wpabuf_free(resp_tlvs);
6667 return -1;
6668 }
6669
6670 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
6671 wpabuf_free(resp_tlvs);
6672 return 0;
6673}
6674
6675
6676static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
6677 char *cmd)
6678{
Dmitry Shmidt04949592012-07-19 12:16:46 -07006679 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
6680 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006681 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
6682 return 0;
6683}
6684
6685
6686static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
6687 char *cmd)
6688{
6689 char *pos;
6690 size_t len;
6691 struct wpabuf *query, *resp;
6692
6693 pos = os_strchr(cmd, ' ');
6694 if (pos == NULL)
6695 return -1;
6696 *pos++ = '\0';
6697
6698 len = os_strlen(cmd);
6699 if (len & 1)
6700 return -1;
6701 len /= 2;
6702 query = wpabuf_alloc(len);
6703 if (query == NULL)
6704 return -1;
6705 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6706 wpabuf_free(query);
6707 return -1;
6708 }
6709
6710 len = os_strlen(pos);
6711 if (len & 1) {
6712 wpabuf_free(query);
6713 return -1;
6714 }
6715 len /= 2;
6716 resp = wpabuf_alloc(len);
6717 if (resp == NULL) {
6718 wpabuf_free(query);
6719 return -1;
6720 }
6721 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
6722 wpabuf_free(query);
6723 wpabuf_free(resp);
6724 return -1;
6725 }
6726
6727 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
6728 wpabuf_free(query);
6729 wpabuf_free(resp);
6730 return -1;
6731 }
6732 return 0;
6733}
6734
6735
6736static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6737{
6738 char *pos;
6739 u8 version;
6740
6741 pos = os_strchr(cmd, ' ');
6742 if (pos == NULL)
6743 return -1;
6744 *pos++ = '\0';
6745
6746 if (hexstr2bin(cmd, &version, 1) < 0)
6747 return -1;
6748
6749 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
6750}
6751
6752
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006753static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
6754 u8 replace, char *cmd)
6755{
6756 char *pos;
6757 char *adv_str;
6758 u32 auto_accept, adv_id, svc_state, config_methods;
6759 char *svc_info = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006760 char *cpt_prio_str;
6761 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006762
6763 pos = os_strchr(cmd, ' ');
6764 if (pos == NULL)
6765 return -1;
6766 *pos++ = '\0';
6767
6768 /* Auto-Accept value is mandatory, and must be one of the
6769 * single values (0, 1, 2, 4) */
6770 auto_accept = atoi(cmd);
6771 switch (auto_accept) {
6772 case P2PS_SETUP_NONE: /* No auto-accept */
6773 case P2PS_SETUP_NEW:
6774 case P2PS_SETUP_CLIENT:
6775 case P2PS_SETUP_GROUP_OWNER:
6776 break;
6777 default:
6778 return -1;
6779 }
6780
6781 /* Advertisement ID is mandatory */
6782 cmd = pos;
6783 pos = os_strchr(cmd, ' ');
6784 if (pos == NULL)
6785 return -1;
6786 *pos++ = '\0';
6787
6788 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6789 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
6790 return -1;
6791
6792 /* Only allow replacements if exist, and adds if not */
6793 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
6794 if (!replace)
6795 return -1;
6796 } else {
6797 if (replace)
6798 return -1;
6799 }
6800
6801 /* svc_state between 0 - 0xff is mandatory */
6802 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
6803 return -1;
6804
6805 pos = os_strchr(pos, ' ');
6806 if (pos == NULL)
6807 return -1;
6808
6809 /* config_methods is mandatory */
6810 pos++;
6811 if (sscanf(pos, "%x", &config_methods) != 1)
6812 return -1;
6813
6814 if (!(config_methods &
6815 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
6816 return -1;
6817
6818 pos = os_strchr(pos, ' ');
6819 if (pos == NULL)
6820 return -1;
6821
6822 pos++;
6823 adv_str = pos;
6824
6825 /* Advertisement string is mandatory */
6826 if (!pos[0] || pos[0] == ' ')
6827 return -1;
6828
6829 /* Terminate svc string */
6830 pos = os_strchr(pos, ' ');
6831 if (pos != NULL)
6832 *pos++ = '\0';
6833
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006834 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6835 if (cpt_prio_str) {
6836 pos = os_strchr(pos, ' ');
6837 if (pos != NULL)
6838 *pos++ = '\0';
6839
6840 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6841 return -1;
6842 } else {
6843 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6844 cpt_prio[1] = 0;
6845 }
6846
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006847 /* Service and Response Information are optional */
6848 if (pos && pos[0]) {
6849 size_t len;
6850
6851 /* Note the bare ' included, which cannot exist legally
6852 * in unescaped string. */
6853 svc_info = os_strstr(pos, "svc_info='");
6854
6855 if (svc_info) {
6856 svc_info += 9;
6857 len = os_strlen(svc_info);
6858 utf8_unescape(svc_info, len, svc_info, len);
6859 }
6860 }
6861
6862 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6863 (u8) svc_state, (u16) config_methods,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006864 svc_info, cpt_prio);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006865}
6866
6867
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006868static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6869{
6870 char *pos;
6871
6872 pos = os_strchr(cmd, ' ');
6873 if (pos == NULL)
6874 return -1;
6875 *pos++ = '\0';
6876
6877 if (os_strcmp(cmd, "bonjour") == 0)
6878 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6879 if (os_strcmp(cmd, "upnp") == 0)
6880 return p2p_ctrl_service_add_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006881 if (os_strcmp(cmd, "asp") == 0)
6882 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006883 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6884 return -1;
6885}
6886
6887
6888static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6889 char *cmd)
6890{
6891 size_t len;
6892 struct wpabuf *query;
6893 int ret;
6894
6895 len = os_strlen(cmd);
6896 if (len & 1)
6897 return -1;
6898 len /= 2;
6899 query = wpabuf_alloc(len);
6900 if (query == NULL)
6901 return -1;
6902 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6903 wpabuf_free(query);
6904 return -1;
6905 }
6906
6907 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6908 wpabuf_free(query);
6909 return ret;
6910}
6911
6912
6913static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6914{
6915 char *pos;
6916 u8 version;
6917
6918 pos = os_strchr(cmd, ' ');
6919 if (pos == NULL)
6920 return -1;
6921 *pos++ = '\0';
6922
6923 if (hexstr2bin(cmd, &version, 1) < 0)
6924 return -1;
6925
6926 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6927}
6928
6929
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006930static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6931{
6932 u32 adv_id;
6933
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07006934 if (os_strcmp(cmd, "all") == 0) {
6935 wpas_p2p_service_flush_asp(wpa_s);
6936 return 0;
6937 }
6938
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006939 if (sscanf(cmd, "%x", &adv_id) != 1)
6940 return -1;
6941
6942 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6943}
6944
6945
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006946static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6947{
6948 char *pos;
6949
6950 pos = os_strchr(cmd, ' ');
6951 if (pos == NULL)
6952 return -1;
6953 *pos++ = '\0';
6954
6955 if (os_strcmp(cmd, "bonjour") == 0)
6956 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6957 if (os_strcmp(cmd, "upnp") == 0)
6958 return p2p_ctrl_service_del_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006959 if (os_strcmp(cmd, "asp") == 0)
6960 return p2p_ctrl_service_del_asp(wpa_s, pos);
6961 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6962 return -1;
6963}
6964
6965
6966static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6967{
6968 char *pos;
6969
6970 pos = os_strchr(cmd, ' ');
6971 if (pos == NULL)
6972 return -1;
6973 *pos++ = '\0';
6974
6975 if (os_strcmp(cmd, "asp") == 0)
6976 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6977
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006978 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6979 return -1;
6980}
6981
6982
6983static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
6984{
6985 u8 addr[ETH_ALEN];
6986
6987 /* <addr> */
6988
6989 if (hwaddr_aton(cmd, addr))
6990 return -1;
6991
6992 return wpas_p2p_reject(wpa_s, addr);
6993}
6994
6995
6996static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
6997{
6998 char *pos;
6999 int id;
7000 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007001 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08007002 int freq = 0, pref_freq = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08007003 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007004 int edmg;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007005 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007006
7007 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07007008 pos = os_strstr(cmd, " peer=");
7009 if (pos) {
7010 pos += 6;
7011 if (hwaddr_aton(pos, peer))
7012 return -1;
7013 _peer = peer;
7014 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007015 ssid = wpa_config_get_network(wpa_s->conf, id);
7016 if (ssid == NULL || ssid->disabled != 2) {
7017 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
7018 "for persistent P2P group",
7019 id);
7020 return -1;
7021 }
7022
Jouni Malinen31be0a42012-08-31 21:20:51 +03007023 pos = os_strstr(cmd, " freq=");
7024 if (pos) {
7025 pos += 6;
7026 freq = atoi(pos);
7027 if (freq <= 0)
7028 return -1;
7029 }
7030
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08007031 pos = os_strstr(cmd, " pref=");
7032 if (pos) {
7033 pos += 6;
7034 pref_freq = atoi(pos);
7035 if (pref_freq <= 0)
7036 return -1;
7037 }
7038
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007039 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
7040 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
7041 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08007042 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007043 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Jouni Malinen31be0a42012-08-31 21:20:51 +03007044
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007045 pos = os_strstr(cmd, "freq2=");
7046 if (pos)
7047 freq2 = atoi(pos + 6);
7048
7049 pos = os_strstr(cmd, " max_oper_chwidth=");
7050 if (pos)
7051 chwidth = atoi(pos + 18);
7052
7053 max_oper_chwidth = parse_freq(chwidth, freq2);
7054 if (max_oper_chwidth < 0)
7055 return -1;
7056
Hai Shaloma20dcd72022-02-04 13:43:00 -08007057 allow_6ghz = os_strstr(cmd, " allow_6ghz") != NULL;
7058
7059 if (allow_6ghz && chwidth == 40)
Sunil8cd6f4d2022-06-28 18:40:46 +00007060 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007061
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007062 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
Hai Shaloma20dcd72022-02-04 13:43:00 -08007063 max_oper_chwidth, pref_freq, he, edmg,
7064 allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007065}
7066
7067
7068static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
7069{
7070 char *pos;
7071 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007072 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007073
7074 pos = os_strstr(cmd, " peer=");
7075 if (!pos)
7076 return -1;
7077
7078 *pos = '\0';
7079 pos += 6;
7080 if (hwaddr_aton(pos, peer)) {
7081 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
7082 return -1;
7083 }
7084
Hai Shaloma20dcd72022-02-04 13:43:00 -08007085 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
7086
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007087 pos = os_strstr(pos, " go_dev_addr=");
7088 if (pos) {
7089 pos += 13;
7090 if (hwaddr_aton(pos, go_dev_addr)) {
7091 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
7092 pos);
7093 return -1;
7094 }
7095 go_dev = go_dev_addr;
7096 }
7097
Hai Shaloma20dcd72022-02-04 13:43:00 -08007098 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007099}
7100
7101
7102static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
7103{
7104 if (os_strncmp(cmd, "persistent=", 11) == 0)
7105 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
7106 if (os_strncmp(cmd, "group=", 6) == 0)
7107 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
7108
7109 return -1;
7110}
7111
7112
7113static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007114 int id, int freq, int vht_center_freq2,
Hai Shalom74f70d42019-02-11 14:42:39 -08007115 int ht40, int vht, int vht_chwidth,
Hai Shaloma20dcd72022-02-04 13:43:00 -08007116 int he, int edmg, bool allow_6ghz)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007117{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007118 struct wpa_ssid *ssid;
7119
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007120 ssid = wpa_config_get_network(wpa_s->conf, id);
7121 if (ssid == NULL || ssid->disabled != 2) {
7122 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
7123 "for persistent P2P group",
7124 id);
7125 return -1;
7126 }
7127
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007128 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
7129 vht_center_freq2, 0, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007130 vht_chwidth, he, edmg,
Matthew Wangafc981e2023-03-17 21:30:12 +00007131 NULL, 0, 0, allow_6ghz, 0, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007132}
7133
7134
7135static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
7136{
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007137 int freq = 0, persistent = 0, group_id = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007138 bool allow_6ghz = false;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007139 int vht = wpa_s->conf->p2p_go_vht;
7140 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08007141 int he = wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007142 int edmg = wpa_s->conf->p2p_go_edmg;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007143 int max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007144 char *token, *context = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007145#ifdef CONFIG_ACS
7146 int acs = 0;
7147#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007148
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007149 while ((token = str_token(cmd, " ", &context))) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07007150 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007151 sscanf(token, "persistent=%d", &group_id) == 1 ||
7152 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007153 continue;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007154#ifdef CONFIG_ACS
7155 } else if (os_strcmp(token, "freq=acs") == 0) {
7156 acs = 1;
7157#endif /* CONFIG_ACS */
7158 } else if (sscanf(token, "freq=%d", &freq) == 1) {
7159 continue;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007160 } else if (os_strcmp(token, "ht40") == 0) {
7161 ht40 = 1;
7162 } else if (os_strcmp(token, "vht") == 0) {
7163 vht = 1;
7164 ht40 = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08007165 } else if (os_strcmp(token, "he") == 0) {
7166 he = 1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007167 } else if (os_strcmp(token, "edmg") == 0) {
7168 edmg = 1;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007169 } else if (os_strcmp(token, "persistent") == 0) {
7170 persistent = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007171 } else if (os_strcmp(token, "allow_6ghz") == 0) {
7172 allow_6ghz = true;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007173 } else {
7174 wpa_printf(MSG_DEBUG,
7175 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
7176 token);
7177 return -1;
7178 }
7179 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007180
Roshan Pius3a1667e2018-07-03 15:17:14 -07007181#ifdef CONFIG_ACS
7182 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
7183 (acs || freq == 2 || freq == 5)) {
7184 if (freq == 2 && wpa_s->best_24_freq <= 0) {
7185 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
7186 wpa_s->p2p_go_do_acs = 1;
7187 freq = 0;
7188 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
7189 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
7190 wpa_s->p2p_go_do_acs = 1;
7191 freq = 0;
7192 } else {
7193 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
7194 wpa_s->p2p_go_do_acs = 1;
7195 }
Hai Shalom021b0b52019-04-10 11:17:58 -07007196 } else {
7197 wpa_s->p2p_go_do_acs = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007198 }
7199#endif /* CONFIG_ACS */
7200
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007201 max_oper_chwidth = parse_freq(chwidth, freq2);
7202 if (max_oper_chwidth < 0)
7203 return -1;
7204
Hai Shaloma20dcd72022-02-04 13:43:00 -08007205 if (allow_6ghz && chwidth == 40)
Sunil8cd6f4d2022-06-28 18:40:46 +00007206 max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
Hai Shaloma20dcd72022-02-04 13:43:00 -08007207
7208 /* Allow DFS to be used for Autonomous GO */
7209 wpa_s->p2p_go_allow_dfs = !!(wpa_s->drv_flags &
7210 WPA_DRIVER_FLAGS_DFS_OFFLOAD);
7211
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007212 if (group_id >= 0)
7213 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007214 freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08007215 max_oper_chwidth, he,
Hai Shaloma20dcd72022-02-04 13:43:00 -08007216 edmg, allow_6ghz);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007217
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007218 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
Hai Shaloma20dcd72022-02-04 13:43:00 -08007219 max_oper_chwidth, he, edmg, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007220}
7221
7222
Dmitry Shmidt849734c2016-05-27 09:59:01 -07007223static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
7224 char *buf, size_t buflen)
7225{
7226 u8 dev_addr[ETH_ALEN];
7227 struct wpa_ssid *ssid;
7228 int res;
7229 const u8 *iaddr;
7230
7231 ssid = wpa_s->current_ssid;
7232 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
7233 hwaddr_aton(cmd, dev_addr))
7234 return -1;
7235
7236 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
7237 if (!iaddr)
7238 return -1;
7239 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
7240 if (os_snprintf_error(buflen, res))
7241 return -1;
7242 return res;
7243}
7244
7245
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007246static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
7247 const u8 *p2p_dev_addr)
7248{
7249 struct wpa_supplicant *wpa_s;
7250
7251 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7252 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
7253 return 1;
7254 }
7255
7256 return 0;
7257}
7258
7259
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007260static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
7261 char *buf, size_t buflen)
7262{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007263 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007264 int next, res;
7265 const struct p2p_peer_info *info;
7266 char *pos, *end;
7267 char devtype[WPS_DEV_TYPE_BUFSIZE];
7268 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007269 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007270
7271 if (!wpa_s->global->p2p)
7272 return -1;
7273
7274 if (os_strcmp(cmd, "FIRST") == 0) {
7275 addr_ptr = NULL;
7276 next = 0;
7277 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
7278 if (hwaddr_aton(cmd + 5, addr) < 0)
7279 return -1;
7280 addr_ptr = addr;
7281 next = 1;
7282 } else {
7283 if (hwaddr_aton(cmd, addr) < 0)
7284 return -1;
7285 addr_ptr = addr;
7286 next = 0;
7287 }
7288
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007289 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
7290 if (info == NULL)
7291 return -1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007292 group_capab = info->group_capab;
7293
7294 if (group_capab &&
7295 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
7296 wpa_printf(MSG_DEBUG,
7297 "P2P: Could not find any BSS with p2p_dev_addr "
7298 MACSTR ", hence override group_capab from 0x%x to 0",
7299 MAC2STR(info->p2p_device_addr), group_capab);
7300 group_capab = 0;
7301 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007302
7303 pos = buf;
7304 end = buf + buflen;
7305
7306 res = os_snprintf(pos, end - pos, MACSTR "\n"
7307 "pri_dev_type=%s\n"
7308 "device_name=%s\n"
7309 "manufacturer=%s\n"
7310 "model_name=%s\n"
7311 "model_number=%s\n"
7312 "serial_number=%s\n"
7313 "config_methods=0x%x\n"
7314 "dev_capab=0x%x\n"
7315 "group_capab=0x%x\n"
7316 "level=%d\n",
7317 MAC2STR(info->p2p_device_addr),
7318 wps_dev_type_bin2str(info->pri_dev_type,
7319 devtype, sizeof(devtype)),
7320 info->device_name,
7321 info->manufacturer,
7322 info->model_name,
7323 info->model_number,
7324 info->serial_number,
7325 info->config_methods,
7326 info->dev_capab,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007327 group_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007328 info->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007329 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007330 return pos - buf;
7331 pos += res;
7332
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007333 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
7334 {
7335 const u8 *t;
7336 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
7337 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
7338 wps_dev_type_bin2str(t, devtype,
7339 sizeof(devtype)));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007340 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007341 return pos - buf;
7342 pos += res;
7343 }
7344
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007345 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007346 if (ssid) {
7347 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007348 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007349 return pos - buf;
7350 pos += res;
7351 }
7352
7353 res = p2p_get_peer_info_txt(info, pos, end - pos);
7354 if (res < 0)
7355 return pos - buf;
7356 pos += res;
7357
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007358 if (info->vendor_elems) {
7359 res = os_snprintf(pos, end - pos, "vendor_elems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007360 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007361 return pos - buf;
7362 pos += res;
7363
7364 pos += wpa_snprintf_hex(pos, end - pos,
7365 wpabuf_head(info->vendor_elems),
7366 wpabuf_len(info->vendor_elems));
7367
7368 res = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007369 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007370 return pos - buf;
7371 pos += res;
7372 }
7373
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007374 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007375}
7376
7377
Dmitry Shmidt04949592012-07-19 12:16:46 -07007378static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
7379 const char *param)
7380{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007381 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007382
7383 if (wpa_s->global->p2p == NULL)
7384 return -1;
7385
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007386 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
7387 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007388
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007389 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
7390 struct wpa_freq_range *freq;
7391 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07007392 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007393 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007394 }
7395
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007396 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007397 return 0;
7398}
7399
7400
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007401static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
7402{
7403 char *param;
7404
7405 if (wpa_s->global->p2p == NULL)
7406 return -1;
7407
7408 param = os_strchr(cmd, ' ');
7409 if (param == NULL)
7410 return -1;
7411 *param++ = '\0';
7412
7413 if (os_strcmp(cmd, "discoverability") == 0) {
7414 p2p_set_client_discoverability(wpa_s->global->p2p,
7415 atoi(param));
7416 return 0;
7417 }
7418
7419 if (os_strcmp(cmd, "managed") == 0) {
7420 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
7421 return 0;
7422 }
7423
7424 if (os_strcmp(cmd, "listen_channel") == 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08007425 char *pos;
7426 u8 channel, op_class;
7427
7428 channel = atoi(param);
7429 pos = os_strchr(param, ' ');
7430 op_class = pos ? atoi(pos) : 81;
7431
7432 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
7433 channel, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007434 }
7435
7436 if (os_strcmp(cmd, "ssid_postfix") == 0) {
7437 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
7438 os_strlen(param));
7439 }
7440
7441 if (os_strcmp(cmd, "noa") == 0) {
7442 char *pos;
7443 int count, start, duration;
7444 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
7445 count = atoi(param);
7446 pos = os_strchr(param, ',');
7447 if (pos == NULL)
7448 return -1;
7449 pos++;
7450 start = atoi(pos);
7451 pos = os_strchr(pos, ',');
7452 if (pos == NULL)
7453 return -1;
7454 pos++;
7455 duration = atoi(pos);
7456 if (count < 0 || count > 255 || start < 0 || duration < 0)
7457 return -1;
7458 if (count == 0 && duration > 0)
7459 return -1;
7460 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
7461 "start=%d duration=%d", count, start, duration);
7462 return wpas_p2p_set_noa(wpa_s, count, start, duration);
7463 }
7464
7465 if (os_strcmp(cmd, "ps") == 0)
7466 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
7467
7468 if (os_strcmp(cmd, "oppps") == 0)
7469 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
7470
7471 if (os_strcmp(cmd, "ctwindow") == 0)
7472 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
7473
7474 if (os_strcmp(cmd, "disabled") == 0) {
7475 wpa_s->global->p2p_disabled = atoi(param);
7476 wpa_printf(MSG_DEBUG, "P2P functionality %s",
7477 wpa_s->global->p2p_disabled ?
7478 "disabled" : "enabled");
7479 if (wpa_s->global->p2p_disabled) {
7480 wpas_p2p_stop_find(wpa_s);
7481 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7482 p2p_flush(wpa_s->global->p2p);
7483 }
7484 return 0;
7485 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007486
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007487 if (os_strcmp(cmd, "conc_pref") == 0) {
7488 if (os_strcmp(param, "sta") == 0)
7489 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
7490 else if (os_strcmp(param, "p2p") == 0)
7491 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007492 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007493 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007494 return -1;
7495 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007496 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07007497 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007498 return 0;
7499 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007500
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007501 if (os_strcmp(cmd, "force_long_sd") == 0) {
7502 wpa_s->force_long_sd = atoi(param);
7503 return 0;
7504 }
7505
7506 if (os_strcmp(cmd, "peer_filter") == 0) {
7507 u8 addr[ETH_ALEN];
7508 if (hwaddr_aton(param, addr))
7509 return -1;
7510 p2p_set_peer_filter(wpa_s->global->p2p, addr);
7511 return 0;
7512 }
7513
7514 if (os_strcmp(cmd, "cross_connect") == 0)
7515 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
7516
7517 if (os_strcmp(cmd, "go_apsd") == 0) {
7518 if (os_strcmp(param, "disable") == 0)
7519 wpa_s->set_ap_uapsd = 0;
7520 else {
7521 wpa_s->set_ap_uapsd = 1;
7522 wpa_s->ap_uapsd = atoi(param);
7523 }
7524 return 0;
7525 }
7526
7527 if (os_strcmp(cmd, "client_apsd") == 0) {
7528 if (os_strcmp(param, "disable") == 0)
7529 wpa_s->set_sta_uapsd = 0;
7530 else {
7531 int be, bk, vi, vo;
7532 char *pos;
7533 /* format: BE,BK,VI,VO;max SP Length */
7534 be = atoi(param);
7535 pos = os_strchr(param, ',');
7536 if (pos == NULL)
7537 return -1;
7538 pos++;
7539 bk = atoi(pos);
7540 pos = os_strchr(pos, ',');
7541 if (pos == NULL)
7542 return -1;
7543 pos++;
7544 vi = atoi(pos);
7545 pos = os_strchr(pos, ',');
7546 if (pos == NULL)
7547 return -1;
7548 pos++;
7549 vo = atoi(pos);
7550 /* ignore max SP Length for now */
7551
7552 wpa_s->set_sta_uapsd = 1;
7553 wpa_s->sta_uapsd = 0;
7554 if (be)
7555 wpa_s->sta_uapsd |= BIT(0);
7556 if (bk)
7557 wpa_s->sta_uapsd |= BIT(1);
7558 if (vi)
7559 wpa_s->sta_uapsd |= BIT(2);
7560 if (vo)
7561 wpa_s->sta_uapsd |= BIT(3);
7562 }
7563 return 0;
7564 }
7565
Dmitry Shmidt04949592012-07-19 12:16:46 -07007566 if (os_strcmp(cmd, "disallow_freq") == 0)
7567 return p2p_ctrl_disallow_freq(wpa_s, param);
7568
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007569 if (os_strcmp(cmd, "disc_int") == 0) {
7570 int min_disc_int, max_disc_int, max_disc_tu;
7571 char *pos;
7572
7573 pos = param;
7574
7575 min_disc_int = atoi(pos);
7576 pos = os_strchr(pos, ' ');
7577 if (pos == NULL)
7578 return -1;
7579 *pos++ = '\0';
7580
7581 max_disc_int = atoi(pos);
7582 pos = os_strchr(pos, ' ');
7583 if (pos == NULL)
7584 return -1;
7585 *pos++ = '\0';
7586
7587 max_disc_tu = atoi(pos);
7588
7589 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
7590 max_disc_int, max_disc_tu);
7591 }
7592
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007593 if (os_strcmp(cmd, "per_sta_psk") == 0) {
7594 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
7595 return 0;
7596 }
7597
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007598#ifdef CONFIG_WPS_NFC
7599 if (os_strcmp(cmd, "nfc_tag") == 0)
7600 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
7601#endif /* CONFIG_WPS_NFC */
7602
7603 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
7604 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
7605 return 0;
7606 }
7607
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007608 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
7609 int op_class, chan;
7610
7611 op_class = atoi(param);
7612 param = os_strchr(param, ':');
7613 if (!param)
7614 return -1;
7615 param++;
7616 chan = atoi(param);
7617 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
7618 chan);
7619 return 0;
7620 }
7621
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007622 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
7623 cmd);
7624
7625 return -1;
7626}
7627
7628
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007629static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
7630{
7631 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7632 wpa_s->force_long_sd = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007633
7634#ifdef CONFIG_TESTING_OPTIONS
7635 os_free(wpa_s->get_pref_freq_list_override);
7636 wpa_s->get_pref_freq_list_override = NULL;
7637#endif /* CONFIG_TESTING_OPTIONS */
7638
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007639 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007640 wpa_s->parent->p2ps_method_config_any = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007641 if (wpa_s->global->p2p)
7642 p2p_flush(wpa_s->global->p2p);
7643}
7644
7645
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007646static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
7647{
7648 char *pos, *pos2;
7649 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
7650
7651 if (cmd[0]) {
7652 pos = os_strchr(cmd, ' ');
7653 if (pos == NULL)
7654 return -1;
7655 *pos++ = '\0';
7656 dur1 = atoi(cmd);
7657
7658 pos2 = os_strchr(pos, ' ');
7659 if (pos2)
7660 *pos2++ = '\0';
7661 int1 = atoi(pos);
7662 } else
7663 pos2 = NULL;
7664
7665 if (pos2) {
7666 pos = os_strchr(pos2, ' ');
7667 if (pos == NULL)
7668 return -1;
7669 *pos++ = '\0';
7670 dur2 = atoi(pos2);
7671 int2 = atoi(pos);
7672 }
7673
7674 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
7675}
7676
7677
7678static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
7679{
7680 char *pos;
7681 unsigned int period = 0, interval = 0;
7682
7683 if (cmd[0]) {
7684 pos = os_strchr(cmd, ' ');
7685 if (pos == NULL)
7686 return -1;
7687 *pos++ = '\0';
7688 period = atoi(cmd);
7689 interval = atoi(pos);
7690 }
7691
7692 return wpas_p2p_ext_listen(wpa_s, period, interval);
7693}
7694
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007695
7696static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
7697{
7698 const char *pos;
7699 u8 peer[ETH_ALEN];
7700 int iface_addr = 0;
7701
7702 pos = cmd;
7703 if (os_strncmp(pos, "iface=", 6) == 0) {
7704 iface_addr = 1;
7705 pos += 6;
7706 }
7707 if (hwaddr_aton(pos, peer))
7708 return -1;
7709
7710 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
7711 return 0;
7712}
7713
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007714
7715static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
7716{
7717 int freq = 0, period = 0, interval = 0, count = 0;
7718
7719 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
7720 {
7721 wpa_printf(MSG_DEBUG,
7722 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
7723 return -1;
7724 }
7725
7726 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
7727}
7728
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007729#endif /* CONFIG_P2P */
7730
7731
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007732static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
7733{
7734 struct wpa_freq_range_list ranges;
7735 int *freqs = NULL;
7736 struct hostapd_hw_modes *mode;
7737 u16 i;
7738
7739 if (wpa_s->hw.modes == NULL)
7740 return NULL;
7741
7742 os_memset(&ranges, 0, sizeof(ranges));
7743 if (freq_range_list_parse(&ranges, val) < 0)
7744 return NULL;
7745
7746 for (i = 0; i < wpa_s->hw.num_modes; i++) {
7747 int j;
7748
7749 mode = &wpa_s->hw.modes[i];
7750 for (j = 0; j < mode->num_channels; j++) {
7751 unsigned int freq;
7752
7753 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
7754 continue;
7755
7756 freq = mode->channels[j].freq;
7757 if (!freq_range_list_includes(&ranges, freq))
7758 continue;
7759
7760 int_array_add_unique(&freqs, freq);
7761 }
7762 }
7763
7764 os_free(ranges.range);
7765 return freqs;
7766}
7767
7768
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007769#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007770
7771static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
7772{
7773 int auto_sel = 0;
7774 int *freqs = NULL;
7775
7776 if (param) {
7777 char *pos;
7778
7779 auto_sel = os_strstr(param, "auto") != NULL;
7780
7781 pos = os_strstr(param, "freq=");
7782 if (pos) {
7783 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
7784 if (freqs == NULL)
7785 return -1;
7786 }
7787
7788 }
7789
7790 return interworking_select(wpa_s, auto_sel, freqs);
7791}
7792
7793
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007794static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
7795 int only_add)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007796{
7797 u8 bssid[ETH_ALEN];
7798 struct wpa_bss *bss;
7799
7800 if (hwaddr_aton(dst, bssid)) {
7801 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
7802 return -1;
7803 }
7804
Hai Shalomfdcde762020-04-02 11:19:20 -07007805 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007806 if (bss == NULL) {
7807 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
7808 MAC2STR(bssid));
7809 return -1;
7810 }
7811
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007812 if (bss->ssid_len == 0) {
7813 int found = 0;
7814
7815 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
7816 " does not have SSID information", MAC2STR(bssid));
7817
7818 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
7819 list) {
7820 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
7821 bss->ssid_len > 0) {
7822 found = 1;
7823 break;
7824 }
7825 }
7826
7827 if (!found)
7828 return -1;
7829 wpa_printf(MSG_DEBUG,
7830 "Found another matching BSS entry with SSID");
7831 }
7832
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007833 return interworking_connect(wpa_s, bss, only_add);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007834}
7835
7836
7837static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
7838{
7839 u8 dst_addr[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07007840 int used, freq = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007841 char *pos;
7842#define MAX_ANQP_INFO_ID 100
7843 u16 id[MAX_ANQP_INFO_ID];
7844 size_t num_id = 0;
Dmitry Shmidt15907092014-03-25 10:42:57 -07007845 u32 subtypes = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007846 u32 mbo_subtypes = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007847
7848 used = hwaddr_aton2(dst, dst_addr);
7849 if (used < 0)
7850 return -1;
7851 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007852 if (*pos == ' ')
7853 pos++;
Hai Shalom899fcc72020-10-19 14:38:18 -07007854
7855 if (os_strncmp(pos, "freq=", 5) == 0) {
7856 freq = atoi(pos + 5);
7857 pos = os_strchr(pos, ' ');
7858 if (!pos)
7859 return -1;
7860 pos++;
7861 }
7862
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007863 while (num_id < MAX_ANQP_INFO_ID) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07007864 if (os_strncmp(pos, "hs20:", 5) == 0) {
7865#ifdef CONFIG_HS20
7866 int num = atoi(pos + 5);
7867 if (num <= 0 || num > 31)
7868 return -1;
7869 subtypes |= BIT(num);
7870#else /* CONFIG_HS20 */
7871 return -1;
7872#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007873 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7874#ifdef CONFIG_MBO
7875 int num = atoi(pos + 4);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007876
7877 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007878 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007879 mbo_subtypes |= BIT(num);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007880#else /* CONFIG_MBO */
7881 return -1;
7882#endif /* CONFIG_MBO */
Dmitry Shmidt15907092014-03-25 10:42:57 -07007883 } else {
7884 id[num_id] = atoi(pos);
7885 if (id[num_id])
7886 num_id++;
7887 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007888 pos = os_strchr(pos + 1, ',');
7889 if (pos == NULL)
7890 break;
7891 pos++;
7892 }
7893
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007894 if (num_id == 0 && !subtypes && !mbo_subtypes)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007895 return -1;
7896
Hai Shalom899fcc72020-10-19 14:38:18 -07007897 return anqp_send_req(wpa_s, dst_addr, freq, id, num_id, subtypes,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007898 mbo_subtypes);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007899}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007900
7901
7902static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7903{
7904 u8 dst_addr[ETH_ALEN];
7905 struct wpabuf *advproto, *query = NULL;
7906 int used, ret = -1;
7907 char *pos, *end;
7908 size_t len;
7909
7910 used = hwaddr_aton2(cmd, dst_addr);
7911 if (used < 0)
7912 return -1;
7913
7914 pos = cmd + used;
7915 while (*pos == ' ')
7916 pos++;
7917
7918 /* Advertisement Protocol ID */
7919 end = os_strchr(pos, ' ');
7920 if (end)
7921 len = end - pos;
7922 else
7923 len = os_strlen(pos);
7924 if (len & 0x01)
7925 return -1;
7926 len /= 2;
7927 if (len == 0)
7928 return -1;
7929 advproto = wpabuf_alloc(len);
7930 if (advproto == NULL)
7931 return -1;
7932 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7933 goto fail;
7934
7935 if (end) {
7936 /* Optional Query Request */
7937 pos = end + 1;
7938 while (*pos == ' ')
7939 pos++;
7940
7941 len = os_strlen(pos);
7942 if (len) {
7943 if (len & 0x01)
7944 goto fail;
7945 len /= 2;
7946 if (len == 0)
7947 goto fail;
7948 query = wpabuf_alloc(len);
7949 if (query == NULL)
7950 goto fail;
7951 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7952 goto fail;
7953 }
7954 }
7955
7956 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7957
7958fail:
7959 wpabuf_free(advproto);
7960 wpabuf_free(query);
7961
7962 return ret;
7963}
7964
7965
7966static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7967 size_t buflen)
7968{
7969 u8 addr[ETH_ALEN];
7970 int dialog_token;
7971 int used;
7972 char *pos;
7973 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007974 struct wpabuf *resp;
7975 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007976
7977 used = hwaddr_aton2(cmd, addr);
7978 if (used < 0)
7979 return -1;
7980
7981 pos = cmd + used;
7982 while (*pos == ' ')
7983 pos++;
7984 dialog_token = atoi(pos);
7985
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007986 if (wpa_s->last_gas_resp &&
7987 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
7988 dialog_token == wpa_s->last_gas_dialog_token)
7989 resp = wpa_s->last_gas_resp;
7990 else if (wpa_s->prev_gas_resp &&
7991 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
7992 dialog_token == wpa_s->prev_gas_dialog_token)
7993 resp = wpa_s->prev_gas_resp;
7994 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007995 return -1;
7996
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007997 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007998 start = 0;
7999 requested_len = resp_len;
8000
8001 pos = os_strchr(pos, ' ');
8002 if (pos) {
8003 start = atoi(pos);
8004 if (start > resp_len)
8005 return os_snprintf(buf, buflen, "FAIL-Invalid range");
8006 pos = os_strchr(pos, ',');
8007 if (pos == NULL)
8008 return -1;
8009 pos++;
8010 requested_len = atoi(pos);
8011 if (start + requested_len > resp_len)
8012 return os_snprintf(buf, buflen, "FAIL-Invalid range");
8013 }
8014
8015 if (requested_len * 2 + 1 > buflen)
8016 return os_snprintf(buf, buflen, "FAIL-Too long response");
8017
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008018 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
8019 requested_len);
8020
8021 if (start + requested_len == resp_len) {
8022 /*
8023 * Free memory by dropping the response after it has been
8024 * fetched.
8025 */
8026 if (resp == wpa_s->prev_gas_resp) {
8027 wpabuf_free(wpa_s->prev_gas_resp);
8028 wpa_s->prev_gas_resp = NULL;
8029 } else {
8030 wpabuf_free(wpa_s->last_gas_resp);
8031 wpa_s->last_gas_resp = NULL;
8032 }
8033 }
8034
8035 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07008036}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008037#endif /* CONFIG_INTERWORKING */
8038
8039
Dmitry Shmidt04949592012-07-19 12:16:46 -07008040#ifdef CONFIG_HS20
8041
8042static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
8043{
8044 u8 dst_addr[ETH_ALEN];
8045 int used;
8046 char *pos;
8047 u32 subtypes = 0;
8048
8049 used = hwaddr_aton2(dst, dst_addr);
8050 if (used < 0)
8051 return -1;
8052 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008053 if (*pos == ' ')
8054 pos++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07008055 for (;;) {
8056 int num = atoi(pos);
8057 if (num <= 0 || num > 31)
8058 return -1;
8059 subtypes |= BIT(num);
8060 pos = os_strchr(pos + 1, ',');
8061 if (pos == NULL)
8062 break;
8063 pos++;
8064 }
8065
8066 if (subtypes == 0)
8067 return -1;
8068
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008069 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008070}
8071
8072
8073static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
8074 const u8 *addr, const char *realm)
8075{
8076 u8 *buf;
8077 size_t rlen, len;
8078 int ret;
8079
8080 rlen = os_strlen(realm);
8081 len = 3 + rlen;
8082 buf = os_malloc(len);
8083 if (buf == NULL)
8084 return -1;
8085 buf[0] = 1; /* NAI Home Realm Count */
8086 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
8087 buf[2] = rlen;
8088 os_memcpy(buf + 3, realm, rlen);
8089
8090 ret = hs20_anqp_send_req(wpa_s, addr,
8091 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008092 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008093
8094 os_free(buf);
8095
8096 return ret;
8097}
8098
8099
8100static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
8101 char *dst)
8102{
8103 struct wpa_cred *cred = wpa_s->conf->cred;
8104 u8 dst_addr[ETH_ALEN];
8105 int used;
8106 u8 *buf;
8107 size_t len;
8108 int ret;
8109
8110 used = hwaddr_aton2(dst, dst_addr);
8111 if (used < 0)
8112 return -1;
8113
8114 while (dst[used] == ' ')
8115 used++;
8116 if (os_strncmp(dst + used, "realm=", 6) == 0)
8117 return hs20_nai_home_realm_list(wpa_s, dst_addr,
8118 dst + used + 6);
8119
8120 len = os_strlen(dst + used);
8121
8122 if (len == 0 && cred && cred->realm)
8123 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
8124
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07008125 if (len & 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07008126 return -1;
8127 len /= 2;
8128 buf = os_malloc(len);
8129 if (buf == NULL)
8130 return -1;
8131 if (hexstr2bin(dst + used, buf, len) < 0) {
8132 os_free(buf);
8133 return -1;
8134 }
8135
8136 ret = hs20_anqp_send_req(wpa_s, dst_addr,
8137 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008138 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07008139 os_free(buf);
8140
8141 return ret;
8142}
8143
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008144
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008145static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
8146 int buflen)
8147{
8148 u8 dst_addr[ETH_ALEN];
8149 int used;
8150 char *ctx = NULL, *icon, *poffset, *psize;
8151
8152 used = hwaddr_aton2(cmd, dst_addr);
8153 if (used < 0)
8154 return -1;
8155 cmd += used;
8156
8157 icon = str_token(cmd, " ", &ctx);
8158 poffset = str_token(cmd, " ", &ctx);
8159 psize = str_token(cmd, " ", &ctx);
8160 if (!icon || !poffset || !psize)
8161 return -1;
8162
8163 wpa_s->fetch_osu_icon_in_progress = 0;
8164 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
8165 reply, buflen);
8166}
8167
8168
8169static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
8170{
8171 u8 dst_addr[ETH_ALEN];
8172 int used;
8173 char *icon;
8174
8175 if (!cmd[0])
8176 return hs20_del_icon(wpa_s, NULL, NULL);
8177
8178 used = hwaddr_aton2(cmd, dst_addr);
8179 if (used < 0)
8180 return -1;
8181
8182 while (cmd[used] == ' ')
8183 used++;
8184 icon = cmd[used] ? &cmd[used] : NULL;
8185
8186 return hs20_del_icon(wpa_s, dst_addr, icon);
8187}
8188
8189
8190static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008191{
8192 u8 dst_addr[ETH_ALEN];
8193 int used;
8194 char *icon;
8195
8196 used = hwaddr_aton2(cmd, dst_addr);
8197 if (used < 0)
8198 return -1;
8199
8200 while (cmd[used] == ' ')
8201 used++;
8202 icon = &cmd[used];
8203
8204 wpa_s->fetch_osu_icon_in_progress = 0;
8205 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008206 (u8 *) icon, os_strlen(icon), inmem);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008207}
8208
Dmitry Shmidt04949592012-07-19 12:16:46 -07008209#endif /* CONFIG_HS20 */
8210
8211
Dmitry Shmidt04949592012-07-19 12:16:46 -07008212#ifdef CONFIG_AUTOSCAN
8213
8214static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
8215 char *cmd)
8216{
8217 enum wpa_states state = wpa_s->wpa_state;
8218 char *new_params = NULL;
8219
8220 if (os_strlen(cmd) > 0) {
8221 new_params = os_strdup(cmd);
8222 if (new_params == NULL)
8223 return -1;
8224 }
8225
8226 os_free(wpa_s->conf->autoscan);
8227 wpa_s->conf->autoscan = new_params;
8228
8229 if (wpa_s->conf->autoscan == NULL)
8230 autoscan_deinit(wpa_s);
8231 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
8232 autoscan_init(wpa_s, 1);
8233 else if (state == WPA_SCANNING)
8234 wpa_supplicant_reinit_autoscan(wpa_s);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08008235 else
8236 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
8237 wpa_supplicant_state_txt(state));
Dmitry Shmidt04949592012-07-19 12:16:46 -07008238
8239 return 0;
8240}
8241
8242#endif /* CONFIG_AUTOSCAN */
8243
8244
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08008245#ifdef CONFIG_WNM
8246
8247static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
8248{
8249 int enter;
8250 int intval = 0;
8251 char *pos;
8252 int ret;
8253 struct wpabuf *tfs_req = NULL;
8254
8255 if (os_strncmp(cmd, "enter", 5) == 0)
8256 enter = 1;
8257 else if (os_strncmp(cmd, "exit", 4) == 0)
8258 enter = 0;
8259 else
8260 return -1;
8261
8262 pos = os_strstr(cmd, " interval=");
8263 if (pos)
8264 intval = atoi(pos + 10);
8265
8266 pos = os_strstr(cmd, " tfs_req=");
8267 if (pos) {
8268 char *end;
8269 size_t len;
8270 pos += 9;
8271 end = os_strchr(pos, ' ');
8272 if (end)
8273 len = end - pos;
8274 else
8275 len = os_strlen(pos);
8276 if (len & 1)
8277 return -1;
8278 len /= 2;
8279 tfs_req = wpabuf_alloc(len);
8280 if (tfs_req == NULL)
8281 return -1;
8282 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
8283 wpabuf_free(tfs_req);
8284 return -1;
8285 }
8286 }
8287
8288 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
8289 WNM_SLEEP_MODE_EXIT, intval,
8290 tfs_req);
8291 wpabuf_free(tfs_req);
8292
8293 return ret;
8294}
8295
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008296
8297static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
8298{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008299 int query_reason, list = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008300 char *btm_candidates = NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008301
8302 query_reason = atoi(cmd);
8303
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008304 cmd = os_strchr(cmd, ' ');
8305 if (cmd) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008306 if (os_strncmp(cmd, " list", 5) == 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008307 list = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008308 else
8309 btm_candidates = cmd;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008310 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008311
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008312 wpa_printf(MSG_DEBUG,
8313 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
8314 query_reason, list ? " candidate list" : "");
8315
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008316 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
8317 btm_candidates,
8318 list);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008319}
8320
Hai Shalom39ba6fc2019-01-22 12:40:38 -08008321
8322static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
8323 char *cmd)
8324{
8325 struct wpabuf *elems;
8326 int ret;
8327
8328 elems = wpabuf_parse_bin(cmd);
8329 if (!elems)
8330 return -1;
8331
8332 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
8333 wpabuf_free(elems);
8334 return ret;
8335}
8336
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08008337#endif /* CONFIG_WNM */
8338
8339
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008340static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
8341 size_t buflen)
8342{
8343 struct wpa_signal_info si;
8344 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008345 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008346
8347 ret = wpa_drv_signal_poll(wpa_s, &si);
8348 if (ret)
8349 return -1;
8350
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008351 pos = buf;
8352 end = buf + buflen;
8353
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008354 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%lu\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008355 "NOISE=%d\nFREQUENCY=%u\n",
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008356 si.data.signal, si.data.current_tx_rate / 1000,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008357 si.current_noise, si.frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008358 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008359 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008360 pos += ret;
8361
8362 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
8363 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008364 channel_width_to_string(si.chanwidth));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008365 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008366 return -1;
8367 pos += ret;
8368 }
8369
Roshan Pius3a1667e2018-07-03 15:17:14 -07008370 if (si.center_frq1 > 0) {
8371 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
8372 si.center_frq1);
8373 if (os_snprintf_error(end - pos, ret))
8374 return -1;
8375 pos += ret;
8376 }
8377
8378 if (si.center_frq2 > 0) {
8379 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
8380 si.center_frq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008381 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008382 return -1;
8383 pos += ret;
8384 }
8385
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008386 if (si.data.avg_signal) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008387 ret = os_snprintf(pos, end - pos,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008388 "AVG_RSSI=%d\n", si.data.avg_signal);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008389 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008390 return -1;
8391 pos += ret;
8392 }
8393
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008394 if (si.data.avg_beacon_signal) {
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07008395 ret = os_snprintf(pos, end - pos,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +00008396 "AVG_BEACON_RSSI=%d\n",
8397 si.data.avg_beacon_signal);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07008398 if (os_snprintf_error(end - pos, ret))
8399 return -1;
8400 pos += ret;
8401 }
8402
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008403 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008404}
8405
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008406
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008407static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
8408 const char *cmd)
8409{
8410 const char *pos;
8411 int threshold = 0;
8412 int hysteresis = 0;
8413
8414 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
8415 wpa_printf(MSG_DEBUG,
8416 "Reject SIGNAL_MONITOR command - bgscan is active");
8417 return -1;
8418 }
8419 pos = os_strstr(cmd, "THRESHOLD=");
8420 if (pos)
8421 threshold = atoi(pos + 10);
8422 pos = os_strstr(cmd, "HYSTERESIS=");
8423 if (pos)
8424 hysteresis = atoi(pos + 11);
8425 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
8426}
8427
8428
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008429#ifdef CONFIG_TESTING_OPTIONS
8430int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
8431 enum wpa_driver_if_type if_type,
8432 unsigned int *num,
Sunil8cd6f4d2022-06-28 18:40:46 +00008433 struct weighted_pcl *freq_list)
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008434{
8435 char *pos = wpa_s->get_pref_freq_list_override;
8436 char *end;
8437 unsigned int count = 0;
8438
8439 /* Override string format:
8440 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
8441
8442 while (pos) {
8443 if (atoi(pos) == (int) if_type)
8444 break;
8445 pos = os_strchr(pos, ' ');
8446 if (pos)
8447 pos++;
8448 }
8449 if (!pos)
8450 return -1;
8451 pos = os_strchr(pos, ':');
8452 if (!pos)
8453 return -1;
8454 pos++;
8455 end = os_strchr(pos, ' ');
8456 while (pos && (!end || pos < end) && count < *num) {
Sunil8cd6f4d2022-06-28 18:40:46 +00008457 freq_list[count].freq = atoi(pos);
8458 freq_list[count++].flag = WEIGHTED_PCL_GO | WEIGHTED_PCL_CLI;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008459 pos = os_strchr(pos, ',');
8460 if (pos)
8461 pos++;
8462 }
8463
8464 *num = count;
8465 return 0;
8466}
8467#endif /* CONFIG_TESTING_OPTIONS */
8468
8469
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008470static int wpas_ctrl_iface_get_pref_freq_list(
8471 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
8472{
Sunil8cd6f4d2022-06-28 18:40:46 +00008473 unsigned int num = 100, i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008474 int ret;
8475 enum wpa_driver_if_type iface_type;
8476 char *pos, *end;
Sunil8cd6f4d2022-06-28 18:40:46 +00008477 struct weighted_pcl freq_list[100];
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008478
8479 pos = buf;
8480 end = buf + buflen;
8481
8482 /* buf: "<interface_type>" */
8483 if (os_strcmp(cmd, "STATION") == 0)
8484 iface_type = WPA_IF_STATION;
8485 else if (os_strcmp(cmd, "AP") == 0)
8486 iface_type = WPA_IF_AP_BSS;
8487 else if (os_strcmp(cmd, "P2P_GO") == 0)
8488 iface_type = WPA_IF_P2P_GO;
8489 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
8490 iface_type = WPA_IF_P2P_CLIENT;
8491 else if (os_strcmp(cmd, "IBSS") == 0)
8492 iface_type = WPA_IF_IBSS;
8493 else if (os_strcmp(cmd, "TDLS") == 0)
8494 iface_type = WPA_IF_TDLS;
8495 else
8496 return -1;
8497
8498 wpa_printf(MSG_DEBUG,
8499 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
Hai Shalom5f92bc92019-04-18 11:54:11 -07008500 iface_type, cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008501
8502 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
8503 if (ret)
8504 return -1;
8505
8506 for (i = 0; i < num; i++) {
8507 ret = os_snprintf(pos, end - pos, "%s%u",
Sunil8cd6f4d2022-06-28 18:40:46 +00008508 i > 0 ? "," : "", freq_list[i].freq);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008509 if (os_snprintf_error(end - pos, ret))
8510 return -1;
8511 pos += ret;
8512 }
8513
8514 return pos - buf;
8515}
8516
8517
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008518static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
8519 char *buf, size_t buflen)
8520{
8521 int ret, i;
8522 char *pos, *end;
8523
8524 ret = os_snprintf(buf, buflen, "%016llX:\n",
8525 (long long unsigned) wpa_s->drv_flags);
8526 if (os_snprintf_error(buflen, ret))
8527 return -1;
8528
8529 pos = buf + ret;
8530 end = buf + buflen;
8531
8532 for (i = 0; i < 64; i++) {
8533 if (wpa_s->drv_flags & (1LLU << i)) {
8534 ret = os_snprintf(pos, end - pos, "%s\n",
8535 driver_flag_to_string(1LLU << i));
8536 if (os_snprintf_error(end - pos, ret))
8537 return -1;
8538 pos += ret;
8539 }
8540 }
8541
8542 return pos - buf;
8543}
8544
8545
Hai Shalomb755a2a2020-04-23 21:49:02 -07008546static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s,
8547 char *buf, size_t buflen)
8548{
8549 int ret, i;
8550 char *pos, *end;
8551
8552 ret = os_snprintf(buf, buflen, "%016llX:\n",
8553 (long long unsigned) wpa_s->drv_flags2);
8554 if (os_snprintf_error(buflen, ret))
8555 return -1;
8556
8557 pos = buf + ret;
8558 end = buf + buflen;
8559
8560 for (i = 0; i < 64; i++) {
8561 if (wpa_s->drv_flags2 & (1LLU << i)) {
8562 ret = os_snprintf(pos, end - pos, "%s\n",
8563 driver_flag2_to_string(1LLU << i));
8564 if (os_snprintf_error(end - pos, ret))
8565 return -1;
8566 pos += ret;
8567 }
8568 }
8569
8570 return pos - buf;
8571}
8572
8573
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008574static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
8575 size_t buflen)
8576{
8577 struct hostap_sta_driver_data sta;
8578 int ret;
8579
8580 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
8581 if (ret)
8582 return -1;
8583
8584 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008585 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008586 if (os_snprintf_error(buflen, ret))
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008587 return -1;
8588 return ret;
8589}
8590
8591
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008592#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008593static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8594 char *buf, size_t buflen)
8595{
8596 int ret;
8597
8598 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008599 if (ret == 0) {
8600 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
8601 struct p2p_data *p2p = wpa_s->global->p2p;
8602 if (p2p) {
8603 char country[3];
8604 country[0] = cmd[8];
8605 country[1] = cmd[9];
8606 country[2] = 0x04;
8607 p2p_set_country(p2p, country);
8608 }
8609 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008610 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008611 if (os_snprintf_error(buflen, ret))
8612 ret = -1;
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008613 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008614 return ret;
8615}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008616#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008617
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07008618
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008619static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8620 char *buf, size_t buflen)
8621{
8622 int ret;
Hai Shalom60840252021-02-19 19:02:11 -08008623 char *pos, *temp = NULL;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008624 u8 *data = NULL;
8625 unsigned int vendor_id, subcmd;
Hai Shalom60840252021-02-19 19:02:11 -08008626 enum nested_attr nested_attr_flag = NESTED_ATTR_UNSPECIFIED;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008627 struct wpabuf *reply;
8628 size_t data_len = 0;
8629
Hai Shalom60840252021-02-19 19:02:11 -08008630 /**
8631 * cmd: <vendor id> <subcommand id> [<hex formatted data>]
8632 * [nested=<0|1>]
8633 */
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008634 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008635 if (!isblank((unsigned char) *pos))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008636 return -EINVAL;
8637
8638 subcmd = strtoul(pos, &pos, 10);
8639
8640 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008641 if (!isblank((unsigned char) *pos++))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008642 return -EINVAL;
Hai Shalom60840252021-02-19 19:02:11 -08008643
8644 temp = os_strchr(pos, ' ');
8645 data_len = temp ? (size_t) (temp - pos) : os_strlen(pos);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008646 }
8647
8648 if (data_len) {
8649 data_len /= 2;
8650 data = os_malloc(data_len);
8651 if (!data)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008652 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008653
8654 if (hexstr2bin(pos, data, data_len)) {
8655 wpa_printf(MSG_DEBUG,
8656 "Vendor command: wrong parameter format");
8657 os_free(data);
8658 return -EINVAL;
8659 }
8660 }
8661
Hai Shalom60840252021-02-19 19:02:11 -08008662 pos = os_strstr(cmd, "nested=");
8663 if (pos)
8664 nested_attr_flag = atoi(pos + 7) ? NESTED_ATTR_USED :
8665 NESTED_ATTR_NOT_USED;
8666
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008667 reply = wpabuf_alloc((buflen - 1) / 2);
8668 if (!reply) {
8669 os_free(data);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008670 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008671 }
8672
8673 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
Hai Shalom60840252021-02-19 19:02:11 -08008674 nested_attr_flag, reply);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008675
8676 if (ret == 0)
8677 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
8678 wpabuf_len(reply));
8679
8680 wpabuf_free(reply);
8681 os_free(data);
8682
8683 return ret;
8684}
8685
8686
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008687static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
8688{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008689#ifdef CONFIG_P2P
8690 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
8691 wpa_s->global->p2p_init_wpa_s : wpa_s;
8692#endif /* CONFIG_P2P */
8693
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008694 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
8695
Dmitry Shmidt29333592017-01-09 12:27:11 -08008696 if (wpas_abort_ongoing_scan(wpa_s) == 0)
8697 wpa_s->ignore_post_flush_scan_res = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008698
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008699 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
8700 /*
8701 * Avoid possible auto connect re-connection on getting
8702 * disconnected due to state flush.
8703 */
8704 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
8705 }
8706
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008707#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008708 wpas_p2p_group_remove(p2p_wpa_s, "*");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008709 wpas_p2p_cancel(p2p_wpa_s);
8710 p2p_ctrl_flush(p2p_wpa_s);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008711 wpas_p2p_service_flush(p2p_wpa_s);
8712 p2p_wpa_s->global->p2p_disabled = 0;
8713 p2p_wpa_s->global->p2p_per_sta_psk = 0;
8714 p2p_wpa_s->conf->num_sec_device_types = 0;
8715 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
8716 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
8717 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008718 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08008719 p2p_wpa_s->global->pending_p2ps_group = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008720 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008721#endif /* CONFIG_P2P */
8722
8723#ifdef CONFIG_WPS_TESTING
8724 wps_version_number = 0x20;
Hai Shaloma20dcd72022-02-04 13:43:00 -08008725 wps_testing_stub_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08008726 wps_corrupt_pkhash = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008727 wps_force_auth_types_in_use = 0;
8728 wps_force_encr_types_in_use = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008729#endif /* CONFIG_WPS_TESTING */
8730#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008731 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008732 wpas_wps_cancel(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008733 wps_registrar_flush(wpa_s->wps->registrar);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008734#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07008735 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008736 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008737
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008738#ifdef CONFIG_DPP
8739 wpas_dpp_deinit(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07008740 wpa_s->dpp_init_max_tries = 0;
8741 wpa_s->dpp_init_retry_time = 0;
8742 wpa_s->dpp_resp_wait_time = 0;
8743 wpa_s->dpp_resp_max_tries = 0;
8744 wpa_s->dpp_resp_retry_time = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008745#ifdef CONFIG_DPP2
8746 wpas_dpp_chirp_stop(wpa_s);
8747 wpa_s->dpp_pfs_fallback = 0;
8748#endif /* CONFIG_DPP2 */
Sunil Ravi89eba102022-09-13 21:04:37 -07008749#ifdef CONFIG_DPP3
8750 {
8751 int i;
8752
8753 for (i = 0; i < DPP_PB_INFO_COUNT; i++) {
8754 struct dpp_pb_info *info;
8755
8756 info = &wpa_s->dpp_pb[i];
8757 info->rx_time.sec = 0;
8758 info->rx_time.usec = 0;
8759 }
8760 }
8761#endif /* CONFIG_DPP3 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008762#ifdef CONFIG_TESTING_OPTIONS
8763 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
8764 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
8765 dpp_pkex_ephemeral_key_override_len = 0;
8766 dpp_protocol_key_override_len = 0;
8767 dpp_nonce_override_len = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08008768#ifdef CONFIG_DPP3
8769 dpp_version_override = 3;
8770#elif defined(CONFIG_DPP2)
Hai Shalom4fbc08f2020-05-18 12:37:00 -07008771 dpp_version_override = 2;
8772#else /* CONFIG_DPP2 */
8773 dpp_version_override = 1;
8774#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008775#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008776#endif /* CONFIG_DPP */
8777
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008778#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008779#ifdef CONFIG_TDLS_TESTING
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008780 tdls_testing = 0;
8781#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008782 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
8783 wpa_tdls_enable(wpa_s->wpa, 1);
8784#endif /* CONFIG_TDLS */
8785
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008786 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
8787 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07008788 wpa_s->last_michael_mic_error.sec = 0;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008789
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008790 wpa_s->no_keep_alive = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08008791 wpa_s->own_disconnect_req = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008792 wpa_s->own_reconnect_req = 0;
8793 wpa_s->deny_ptk0_rekey = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008794
8795 os_free(wpa_s->disallow_aps_bssid);
8796 wpa_s->disallow_aps_bssid = NULL;
8797 wpa_s->disallow_aps_bssid_count = 0;
8798 os_free(wpa_s->disallow_aps_ssid);
8799 wpa_s->disallow_aps_ssid = NULL;
8800 wpa_s->disallow_aps_ssid_count = 0;
8801
8802 wpa_s->set_sta_uapsd = 0;
8803 wpa_s->sta_uapsd = 0;
8804
Hai Shalom899fcc72020-10-19 14:38:18 -07008805 wpa_s->consecutive_conn_failures = 0;
8806
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008807 wpa_drv_radio_disable(wpa_s, 0);
Hai Shalom60840252021-02-19 19:02:11 -08008808 wpa_bssid_ignore_clear(wpa_s);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008809 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
8810 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08008811 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08008812 wpa_s->conf->auto_interworking = 0;
8813 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008814
Hai Shalom60840252021-02-19 19:02:11 -08008815 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008816 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
8817 rsn_preauth_deinit(wpa_s->wpa);
8818
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008819 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
8820 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
8821 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
Hai Shalome21d4e82020-04-29 16:34:06 -07008822 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008823
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008824 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008825 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008826
8827 wpa_s->next_ssid = NULL;
8828
8829#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008830#ifdef CONFIG_HS20
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008831 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008832 hs20_del_icon(wpa_s, NULL, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008833#endif /* CONFIG_HS20 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008834#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008835
8836 wpa_s->ext_mgmt_frame_handling = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008837 wpa_s->ext_eapol_frame_io = 0;
8838#ifdef CONFIG_TESTING_OPTIONS
8839 wpa_s->extra_roc_dur = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008840 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008841 wpa_s->p2p_go_csa_on_inv = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008842 wpa_s->ignore_auth_resp = 0;
8843 wpa_s->ignore_assoc_disallow = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008844 wpa_s->disable_sa_query = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008845 wpa_s->testing_resend_assoc = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008846 wpa_s->ignore_sae_h2e_only = 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07008847 wpa_s->ft_rsnxe_used = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008848 wpa_s->reject_btm_req_reason = 0;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008849 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008850 os_free(wpa_s->get_pref_freq_list_override);
8851 wpa_s->get_pref_freq_list_override = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008852 wpabuf_free(wpa_s->sae_commit_override);
8853 wpa_s->sae_commit_override = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008854 os_free(wpa_s->extra_sae_rejected_groups);
8855 wpa_s->extra_sae_rejected_groups = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008856 wpabuf_free(wpa_s->rsne_override_eapol);
8857 wpa_s->rsne_override_eapol = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008858 wpabuf_free(wpa_s->rsnxe_override_assoc);
8859 wpa_s->rsnxe_override_assoc = NULL;
8860 wpabuf_free(wpa_s->rsnxe_override_eapol);
8861 wpa_s->rsnxe_override_eapol = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008862 wpas_clear_driver_signal_override(wpa_s);
Hai Shaloma20dcd72022-02-04 13:43:00 -08008863 wpa_s->disable_scs_support = 0;
8864 wpa_s->disable_mscs_support = 0;
8865 wpa_s->enable_dscp_policy_capa = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07008866 wpa_s->oci_freq_override_eapol = 0;
8867 wpa_s->oci_freq_override_saquery_req = 0;
8868 wpa_s->oci_freq_override_saquery_resp = 0;
8869 wpa_s->oci_freq_override_eapol_g2 = 0;
8870 wpa_s->oci_freq_override_ft_assoc = 0;
8871 wpa_s->oci_freq_override_fils_assoc = 0;
8872 wpa_s->oci_freq_override_wnm_sleep = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -07008873 wpa_s->disable_eapol_g2_tx = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008874#ifdef CONFIG_DPP
8875 os_free(wpa_s->dpp_config_obj_override);
8876 wpa_s->dpp_config_obj_override = NULL;
8877 os_free(wpa_s->dpp_discovery_override);
8878 wpa_s->dpp_discovery_override = NULL;
8879 os_free(wpa_s->dpp_groups_override);
8880 wpa_s->dpp_groups_override = NULL;
Sunil8cd6f4d2022-06-28 18:40:46 +00008881 wpa_s->dpp_ignore_netaccesskey_mismatch = 0;
8882 wpa_s->dpp_discard_public_action = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008883 dpp_test = DPP_TEST_DISABLED;
8884#endif /* CONFIG_DPP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008885#endif /* CONFIG_TESTING_OPTIONS */
8886
8887 wpa_s->disconnected = 0;
8888 os_free(wpa_s->next_scan_freqs);
8889 wpa_s->next_scan_freqs = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008890 os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN);
8891 wpa_s->next_scan_bssid_wildcard_ssid = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008892 os_free(wpa_s->select_network_scan_freqs);
8893 wpa_s->select_network_scan_freqs = NULL;
Hai Shalom899fcc72020-10-19 14:38:18 -07008894 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008895
8896 wpa_bss_flush(wpa_s);
8897 if (!dl_list_empty(&wpa_s->bss)) {
8898 wpa_printf(MSG_DEBUG,
8899 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8900 MACSTR " pending_bssid=" MACSTR,
8901 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
8902 MAC2STR(wpa_s->bssid),
8903 MAC2STR(wpa_s->pending_bssid));
8904 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008905
8906 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -08008907 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008908
8909#ifdef CONFIG_SME
8910 wpa_s->sme.last_unprot_disconnect.sec = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008911 wpa_s->sme.auth_alg = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008912#endif /* CONFIG_SME */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008913
8914 wpabuf_free(wpa_s->ric_ies);
8915 wpa_s->ric_ies = NULL;
Hai Shalom74f70d42019-02-11 14:42:39 -08008916
8917 wpa_supplicant_update_channel_list(wpa_s, NULL);
8918
8919 free_bss_tmp_disallowed(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -07008920
8921 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Hai Shalom60840252021-02-19 19:02:11 -08008922
8923#ifdef CONFIG_PASN
8924 wpas_pasn_auth_stop(wpa_s);
8925#endif /* CONFIG_PASN */
8926
8927 if (wpa_s->mac_addr_changed && wpa_s->conf->mac_addr == 0)
8928 wpas_restore_permanent_mac_addr(wpa_s);
Sunil Ravia04bd252022-05-02 22:54:18 -07008929
8930 wpa_s->conf->ignore_old_scan_res = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008931}
8932
8933
8934static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
8935 char *buf, size_t buflen)
8936{
8937 struct wpa_radio_work *work;
8938 char *pos, *end;
8939 struct os_reltime now, diff;
8940
8941 pos = buf;
8942 end = buf + buflen;
8943
8944 os_get_reltime(&now);
8945
8946 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8947 {
8948 int ret;
8949
8950 os_reltime_sub(&now, &work->time, &diff);
8951 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
8952 work->type, work->wpa_s->ifname, work->freq,
8953 work->started, diff.sec, diff.usec);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008954 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008955 break;
8956 pos += ret;
8957 }
8958
8959 return pos - buf;
8960}
8961
8962
8963static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
8964{
8965 struct wpa_radio_work *work = eloop_ctx;
8966 struct wpa_external_work *ework = work->ctx;
8967
8968 wpa_dbg(work->wpa_s, MSG_DEBUG,
8969 "Timing out external radio work %u (%s)",
8970 ework->id, work->type);
8971 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008972 work->wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008973 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008974 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008975}
8976
8977
8978static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
8979{
8980 struct wpa_external_work *ework = work->ctx;
8981
8982 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008983 if (work->started)
8984 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8985 work, NULL);
8986
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008987 /*
8988 * work->type points to a buffer in ework, so need to replace
8989 * that here with a fixed string to avoid use of freed memory
8990 * in debug prints.
8991 */
8992 work->type = "freed-ext-work";
8993 work->ctx = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008994 os_free(ework);
8995 return;
8996 }
8997
8998 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
8999 ework->id, ework->type);
9000 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009001 work->wpa_s->ext_work_in_progress = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009002 if (!ework->timeout)
9003 ework->timeout = 10;
9004 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
9005 work, NULL);
9006}
9007
9008
9009static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
9010 char *buf, size_t buflen)
9011{
9012 struct wpa_external_work *ework;
9013 char *pos, *pos2;
9014 size_t type_len;
9015 int ret;
9016 unsigned int freq = 0;
9017
9018 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
9019
9020 ework = os_zalloc(sizeof(*ework));
9021 if (ework == NULL)
9022 return -1;
9023
9024 pos = os_strchr(cmd, ' ');
9025 if (pos) {
9026 type_len = pos - cmd;
9027 pos++;
9028
9029 pos2 = os_strstr(pos, "freq=");
9030 if (pos2)
9031 freq = atoi(pos2 + 5);
9032
9033 pos2 = os_strstr(pos, "timeout=");
9034 if (pos2)
9035 ework->timeout = atoi(pos2 + 8);
9036 } else {
9037 type_len = os_strlen(cmd);
9038 }
9039 if (4 + type_len >= sizeof(ework->type))
9040 type_len = sizeof(ework->type) - 4 - 1;
9041 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
9042 os_memcpy(ework->type + 4, cmd, type_len);
9043 ework->type[4 + type_len] = '\0';
9044
9045 wpa_s->ext_work_id++;
9046 if (wpa_s->ext_work_id == 0)
9047 wpa_s->ext_work_id++;
9048 ework->id = wpa_s->ext_work_id;
9049
9050 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
9051 ework) < 0) {
9052 os_free(ework);
9053 return -1;
9054 }
9055
9056 ret = os_snprintf(buf, buflen, "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009057 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009058 return -1;
9059 return ret;
9060}
9061
9062
9063static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
9064{
9065 struct wpa_radio_work *work;
9066 unsigned int id = atoi(cmd);
9067
9068 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
9069 {
9070 struct wpa_external_work *ework;
9071
9072 if (os_strncmp(work->type, "ext:", 4) != 0)
9073 continue;
9074 ework = work->ctx;
9075 if (id && ework->id != id)
9076 continue;
9077 wpa_dbg(wpa_s, MSG_DEBUG,
9078 "Completed external radio work %u (%s)",
9079 ework->id, ework->type);
9080 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009081 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009082 radio_work_done(work);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07009083 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009084 return 3; /* "OK\n" */
9085 }
9086
9087 return -1;
9088}
9089
9090
9091static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
9092 char *buf, size_t buflen)
9093{
9094 if (os_strcmp(cmd, "show") == 0)
9095 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
9096 if (os_strncmp(cmd, "add ", 4) == 0)
9097 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
9098 if (os_strncmp(cmd, "done ", 5) == 0)
9099 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
9100 return -1;
9101}
9102
9103
9104void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
9105{
9106 struct wpa_radio_work *work, *tmp;
9107
Dmitry Shmidt18463232014-01-24 12:29:41 -08009108 if (!wpa_s || !wpa_s->radio)
9109 return;
9110
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009111 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
9112 struct wpa_radio_work, list) {
9113 struct wpa_external_work *ework;
9114
9115 if (os_strncmp(work->type, "ext:", 4) != 0)
9116 continue;
9117 ework = work->ctx;
9118 wpa_dbg(wpa_s, MSG_DEBUG,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07009119 "Flushing%s external radio work %u (%s)",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009120 work->started ? " started" : "", ework->id,
9121 ework->type);
9122 if (work->started)
9123 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
9124 work, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009125 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07009126 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009127 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07009128}
9129
9130
Dmitry Shmidt051af732013-10-22 13:52:46 -07009131static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
9132{
9133 struct wpa_supplicant *wpa_s = eloop_ctx;
9134 eapol_sm_notify_ctrl_response(wpa_s->eapol);
9135}
9136
9137
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009138static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
9139 unsigned int *scan_id_count, int scan_id[])
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009140{
9141 const char *pos = value;
9142
9143 while (pos) {
9144 if (*pos == ' ' || *pos == '\0')
9145 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009146 if (*scan_id_count == MAX_SCAN_ID)
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009147 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009148 scan_id[(*scan_id_count)++] = atoi(pos);
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009149 pos = os_strchr(pos, ',');
9150 if (pos)
9151 pos++;
9152 }
9153
9154 return 0;
9155}
9156
9157
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009158static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
9159 char *reply, int reply_size, int *reply_len)
9160{
9161 char *pos;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009162 unsigned int manual_scan_passive = 0;
9163 unsigned int manual_scan_use_id = 0;
9164 unsigned int manual_scan_only_new = 0;
9165 unsigned int scan_only = 0;
9166 unsigned int scan_id_count = 0;
Sunil8cd6f4d2022-06-28 18:40:46 +00009167 unsigned int manual_non_coloc_6ghz = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009168 int scan_id[MAX_SCAN_ID];
9169 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
9170 struct wpa_scan_results *scan_res);
9171 int *manual_scan_freqs = NULL;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009172 struct wpa_ssid_value *ssid = NULL, *ns;
9173 unsigned int ssid_count = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009174
9175 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
9176 *reply_len = -1;
9177 return;
9178 }
9179
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009180 if (radio_work_pending(wpa_s, "scan")) {
9181 wpa_printf(MSG_DEBUG,
9182 "Pending scan scheduled - reject new request");
9183 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9184 return;
9185 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009186
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07009187#ifdef CONFIG_INTERWORKING
9188 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
9189 wpa_printf(MSG_DEBUG,
9190 "Interworking select in progress - reject new scan");
9191 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9192 return;
9193 }
9194#endif /* CONFIG_INTERWORKING */
9195
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009196 if (params) {
9197 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009198 scan_only = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009199
9200 pos = os_strstr(params, "freq=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009201 if (pos) {
9202 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
9203 pos + 5);
9204 if (manual_scan_freqs == NULL) {
9205 *reply_len = -1;
9206 goto done;
9207 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009208 }
9209
9210 pos = os_strstr(params, "passive=");
9211 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009212 manual_scan_passive = !!atoi(pos + 8);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009213
9214 pos = os_strstr(params, "use_id=");
9215 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009216 manual_scan_use_id = atoi(pos + 7);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009217
9218 pos = os_strstr(params, "only_new=1");
9219 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009220 manual_scan_only_new = 1;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009221
9222 pos = os_strstr(params, "scan_id=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009223 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
9224 scan_id) < 0) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009225 *reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009226 goto done;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07009227 }
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009228
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009229 pos = os_strstr(params, "bssid=");
9230 if (pos) {
9231 u8 bssid[ETH_ALEN];
9232
9233 pos += 6;
9234 if (hwaddr_aton(pos, bssid)) {
9235 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
9236 *reply_len = -1;
9237 goto done;
9238 }
9239 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
Hai Shalomfdcde762020-04-02 11:19:20 -07009240
9241 wpa_s->next_scan_bssid_wildcard_ssid =
9242 os_strstr(params, "wildcard_ssid=1") != NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009243 }
9244
Sunil8cd6f4d2022-06-28 18:40:46 +00009245 pos = os_strstr(params, "non_coloc_6ghz=");
9246 if (pos)
9247 manual_non_coloc_6ghz = !!atoi(pos + 15);
9248
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009249 pos = params;
9250 while (pos && *pos != '\0') {
9251 if (os_strncmp(pos, "ssid ", 5) == 0) {
9252 char *end;
9253
9254 pos += 5;
9255 end = pos;
9256 while (*end) {
9257 if (*end == '\0' || *end == ' ')
9258 break;
9259 end++;
9260 }
9261
9262 ns = os_realloc_array(
9263 ssid, ssid_count + 1,
9264 sizeof(struct wpa_ssid_value));
9265 if (ns == NULL) {
9266 *reply_len = -1;
9267 goto done;
9268 }
9269 ssid = ns;
9270
9271 if ((end - pos) & 0x01 ||
9272 end - pos > 2 * SSID_MAX_LEN ||
9273 hexstr2bin(pos, ssid[ssid_count].ssid,
9274 (end - pos) / 2) < 0) {
9275 wpa_printf(MSG_DEBUG,
9276 "Invalid SSID value '%s'",
9277 pos);
9278 *reply_len = -1;
9279 goto done;
9280 }
9281 ssid[ssid_count].ssid_len = (end - pos) / 2;
9282 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
9283 ssid[ssid_count].ssid,
9284 ssid[ssid_count].ssid_len);
9285 ssid_count++;
9286 pos = end;
9287 }
9288
9289 pos = os_strchr(pos, ' ');
9290 if (pos)
9291 pos++;
9292 }
9293 }
9294
9295 wpa_s->num_ssids_from_scan_req = ssid_count;
9296 os_free(wpa_s->ssids_from_scan_req);
9297 if (ssid_count) {
9298 wpa_s->ssids_from_scan_req = ssid;
9299 ssid = NULL;
9300 } else {
9301 wpa_s->ssids_from_scan_req = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009302 }
9303
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009304 if (scan_only)
9305 scan_res_handler = scan_only_handler;
9306 else if (wpa_s->scan_res_handler == scan_only_handler)
9307 scan_res_handler = NULL;
9308 else
9309 scan_res_handler = wpa_s->scan_res_handler;
9310
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009311 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
9312 ((wpa_s->wpa_state <= WPA_SCANNING) ||
9313 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009314 wpa_s->manual_scan_passive = manual_scan_passive;
9315 wpa_s->manual_scan_use_id = manual_scan_use_id;
9316 wpa_s->manual_scan_only_new = manual_scan_only_new;
9317 wpa_s->scan_id_count = scan_id_count;
Sunil8cd6f4d2022-06-28 18:40:46 +00009318 wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009319 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9320 wpa_s->scan_res_handler = scan_res_handler;
9321 os_free(wpa_s->manual_scan_freqs);
9322 wpa_s->manual_scan_freqs = manual_scan_freqs;
9323 manual_scan_freqs = NULL;
9324
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009325 wpa_s->normal_scans = 0;
9326 wpa_s->scan_req = MANUAL_SCAN_REQ;
9327 wpa_s->after_wps = 0;
9328 wpa_s->known_wps_freq = 0;
9329 wpa_supplicant_req_scan(wpa_s, 0, 0);
9330 if (wpa_s->manual_scan_use_id) {
9331 wpa_s->manual_scan_id++;
9332 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9333 wpa_s->manual_scan_id);
9334 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9335 wpa_s->manual_scan_id);
9336 }
9337 } else if (wpa_s->sched_scanning) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009338 wpa_s->manual_scan_passive = manual_scan_passive;
9339 wpa_s->manual_scan_use_id = manual_scan_use_id;
9340 wpa_s->manual_scan_only_new = manual_scan_only_new;
9341 wpa_s->scan_id_count = scan_id_count;
Sunil8cd6f4d2022-06-28 18:40:46 +00009342 wpa_s->manual_non_coloc_6ghz = manual_non_coloc_6ghz;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009343 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9344 wpa_s->scan_res_handler = scan_res_handler;
9345 os_free(wpa_s->manual_scan_freqs);
9346 wpa_s->manual_scan_freqs = manual_scan_freqs;
9347 manual_scan_freqs = NULL;
9348
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009349 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
9350 wpa_supplicant_cancel_sched_scan(wpa_s);
9351 wpa_s->scan_req = MANUAL_SCAN_REQ;
9352 wpa_supplicant_req_scan(wpa_s, 0, 0);
9353 if (wpa_s->manual_scan_use_id) {
9354 wpa_s->manual_scan_id++;
9355 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9356 wpa_s->manual_scan_id);
9357 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9358 wpa_s->manual_scan_id);
9359 }
9360 } else {
9361 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
9362 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9363 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009364
9365done:
9366 os_free(manual_scan_freqs);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009367 os_free(ssid);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009368}
9369
9370
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009371#ifdef CONFIG_TESTING_OPTIONS
9372
9373static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
9374 unsigned int freq, const u8 *dst,
9375 const u8 *src, const u8 *bssid,
9376 const u8 *data, size_t data_len,
9377 enum offchannel_send_action_result
9378 result)
9379{
9380 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
9381 " src=" MACSTR " bssid=" MACSTR " result=%s",
9382 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
9383 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
9384 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
9385 "NO_ACK" : "FAILED"));
9386}
9387
9388
9389static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
9390{
9391 char *pos, *param;
9392 size_t len;
9393 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
9394 int res, used;
9395 int freq = 0, no_cck = 0, wait_time = 0;
9396
9397 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
9398 * <action=Action frame payload> */
9399
9400 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
9401
9402 pos = cmd;
9403 used = hwaddr_aton2(pos, da);
9404 if (used < 0)
9405 return -1;
9406 pos += used;
9407 while (*pos == ' ')
9408 pos++;
9409 used = hwaddr_aton2(pos, bssid);
9410 if (used < 0)
9411 return -1;
9412 pos += used;
9413
9414 param = os_strstr(pos, " freq=");
9415 if (param) {
9416 param += 6;
9417 freq = atoi(param);
9418 }
9419
9420 param = os_strstr(pos, " no_cck=");
9421 if (param) {
9422 param += 8;
9423 no_cck = atoi(param);
9424 }
9425
9426 param = os_strstr(pos, " wait_time=");
9427 if (param) {
9428 param += 11;
9429 wait_time = atoi(param);
9430 }
9431
9432 param = os_strstr(pos, " action=");
9433 if (param == NULL)
9434 return -1;
9435 param += 8;
9436
9437 len = os_strlen(param);
9438 if (len & 1)
9439 return -1;
9440 len /= 2;
9441
9442 buf = os_malloc(len);
9443 if (buf == NULL)
9444 return -1;
9445
9446 if (hexstr2bin(param, buf, len) < 0) {
9447 os_free(buf);
9448 return -1;
9449 }
9450
9451 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
9452 buf, len, wait_time,
9453 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
9454 os_free(buf);
9455 return res;
9456}
9457
9458
9459static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
9460{
9461 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
9462 offchannel_send_action_done(wpa_s);
9463}
9464
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009465
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009466static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
9467 char *cmd)
9468{
9469 char *pos, *param;
9470 size_t len;
9471 u8 *buf;
9472 int freq = 0, datarate = 0, ssi_signal = 0;
9473 union wpa_event_data event;
9474
9475 if (!wpa_s->ext_mgmt_frame_handling)
9476 return -1;
9477
9478 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
9479
9480 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
9481
9482 pos = cmd;
9483 param = os_strstr(pos, "freq=");
9484 if (param) {
9485 param += 5;
9486 freq = atoi(param);
9487 }
9488
9489 param = os_strstr(pos, " datarate=");
9490 if (param) {
9491 param += 10;
9492 datarate = atoi(param);
9493 }
9494
9495 param = os_strstr(pos, " ssi_signal=");
9496 if (param) {
9497 param += 12;
9498 ssi_signal = atoi(param);
9499 }
9500
9501 param = os_strstr(pos, " frame=");
9502 if (param == NULL)
9503 return -1;
9504 param += 7;
9505
9506 len = os_strlen(param);
9507 if (len & 1)
9508 return -1;
9509 len /= 2;
9510
9511 buf = os_malloc(len);
9512 if (buf == NULL)
9513 return -1;
9514
9515 if (hexstr2bin(param, buf, len) < 0) {
9516 os_free(buf);
9517 return -1;
9518 }
9519
9520 os_memset(&event, 0, sizeof(event));
9521 event.rx_mgmt.freq = freq;
9522 event.rx_mgmt.frame = buf;
9523 event.rx_mgmt.frame_len = len;
9524 event.rx_mgmt.ssi_signal = ssi_signal;
9525 event.rx_mgmt.datarate = datarate;
9526 wpa_s->ext_mgmt_frame_handling = 0;
9527 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
9528 wpa_s->ext_mgmt_frame_handling = 1;
9529
9530 os_free(buf);
9531
9532 return 0;
9533}
9534
9535
Paul Stewart092955c2017-02-06 09:13:09 -08009536static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
9537 char *param)
9538{
9539 struct wpa_scan_res *res;
9540 struct os_reltime now;
9541 char *pos, *end;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009542 int ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08009543
9544 if (!param)
9545 return -1;
9546
9547 if (os_strcmp(param, "START") == 0) {
9548 wpa_bss_update_start(wpa_s);
9549 return 0;
9550 }
9551
9552 if (os_strcmp(param, "END") == 0) {
9553 wpa_bss_update_end(wpa_s, NULL, 1);
9554 return 0;
9555 }
9556
9557 if (os_strncmp(param, "BSS ", 4) != 0)
9558 return -1;
9559 param += 3;
9560
9561 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
9562 if (!res)
9563 return -1;
9564
9565 pos = os_strstr(param, " flags=");
9566 if (pos)
9567 res->flags = strtol(pos + 7, NULL, 16);
9568
9569 pos = os_strstr(param, " bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009570 if (pos && hwaddr_aton(pos + 7, res->bssid))
9571 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009572
9573 pos = os_strstr(param, " freq=");
9574 if (pos)
9575 res->freq = atoi(pos + 6);
9576
9577 pos = os_strstr(param, " beacon_int=");
9578 if (pos)
9579 res->beacon_int = atoi(pos + 12);
9580
9581 pos = os_strstr(param, " caps=");
9582 if (pos)
9583 res->caps = strtol(pos + 6, NULL, 16);
9584
9585 pos = os_strstr(param, " qual=");
9586 if (pos)
9587 res->qual = atoi(pos + 6);
9588
9589 pos = os_strstr(param, " noise=");
9590 if (pos)
9591 res->noise = atoi(pos + 7);
9592
9593 pos = os_strstr(param, " level=");
9594 if (pos)
9595 res->level = atoi(pos + 7);
9596
9597 pos = os_strstr(param, " tsf=");
9598 if (pos)
9599 res->tsf = strtoll(pos + 5, NULL, 16);
9600
9601 pos = os_strstr(param, " age=");
9602 if (pos)
9603 res->age = atoi(pos + 5);
9604
9605 pos = os_strstr(param, " est_throughput=");
9606 if (pos)
9607 res->est_throughput = atoi(pos + 16);
9608
9609 pos = os_strstr(param, " snr=");
9610 if (pos)
9611 res->snr = atoi(pos + 5);
9612
9613 pos = os_strstr(param, " parent_tsf=");
9614 if (pos)
9615 res->parent_tsf = strtoll(pos + 7, NULL, 16);
9616
9617 pos = os_strstr(param, " tsf_bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009618 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
9619 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009620
9621 pos = os_strstr(param, " ie=");
9622 if (pos) {
9623 pos += 4;
9624 end = os_strchr(pos, ' ');
9625 if (!end)
9626 end = pos + os_strlen(pos);
9627 res->ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009628 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
9629 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009630 }
9631
9632 pos = os_strstr(param, " beacon_ie=");
9633 if (pos) {
9634 pos += 11;
9635 end = os_strchr(pos, ' ');
9636 if (!end)
9637 end = pos + os_strlen(pos);
9638 res->beacon_ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009639 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
9640 res->beacon_ie_len))
9641 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009642 }
9643
9644 os_get_reltime(&now);
9645 wpa_bss_update_scan_res(wpa_s, res, &now);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009646 ret = 0;
9647fail:
Paul Stewart092955c2017-02-06 09:13:09 -08009648 os_free(res);
9649
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009650 return ret;
Paul Stewart092955c2017-02-06 09:13:09 -08009651}
9652
9653
Hai Shaloma20dcd72022-02-04 13:43:00 -08009654static int wpas_ctrl_iface_driver_event_assoc(struct wpa_supplicant *wpa_s,
9655 char *param)
9656{
9657 union wpa_event_data event;
9658 struct assoc_info *ai;
9659 char *ctx = NULL;
9660 int ret = -1;
9661 struct wpabuf *req_ies = NULL;
9662 struct wpabuf *resp_ies = NULL;
9663 struct wpabuf *resp_frame = NULL;
9664 struct wpabuf *beacon_ies = NULL;
9665 struct wpabuf *key_replay_ctr = NULL;
9666 struct wpabuf *ptk_kck = NULL;
9667 struct wpabuf *ptk_kek = NULL;
9668 struct wpabuf *fils_pmk = NULL;
9669 char *str, *pos;
9670 u8 addr[ETH_ALEN];
9671 u8 fils_pmkid[PMKID_LEN];
9672
9673 os_memset(&event, 0, sizeof(event));
9674 ai = &event.assoc_info;
9675
9676 while ((str = str_token(param, " ", &ctx))) {
9677 pos = os_strchr(str, '=');
9678 if (!pos)
9679 goto fail;
9680 *pos++ = '\0';
9681
9682 if (os_strcmp(str, "reassoc") == 0) {
9683 ai->reassoc = atoi(pos);
9684 } else if (os_strcmp(str, "req_ies") == 0) {
9685 wpabuf_free(req_ies);
9686 req_ies = wpabuf_parse_bin(pos);
9687 if (!req_ies)
9688 goto fail;
9689 ai->req_ies = wpabuf_head(req_ies);
9690 ai->req_ies_len = wpabuf_len(req_ies);
9691 } else if (os_strcmp(str, "resp_ies") == 0) {
9692 wpabuf_free(resp_ies);
9693 resp_ies = wpabuf_parse_bin(pos);
9694 if (!resp_ies)
9695 goto fail;
9696 ai->resp_ies = wpabuf_head(resp_ies);
9697 ai->resp_ies_len = wpabuf_len(resp_ies);
9698 } else if (os_strcmp(str, "resp_frame") == 0) {
9699 wpabuf_free(resp_frame);
9700 resp_frame = wpabuf_parse_bin(pos);
9701 if (!resp_frame)
9702 goto fail;
9703 ai->resp_frame = wpabuf_head(resp_frame);
9704 ai->resp_frame_len = wpabuf_len(resp_frame);
9705 } else if (os_strcmp(str, "beacon_ies") == 0) {
9706 wpabuf_free(beacon_ies);
9707 beacon_ies = wpabuf_parse_bin(pos);
9708 if (!beacon_ies)
9709 goto fail;
9710 ai->beacon_ies = wpabuf_head(beacon_ies);
9711 ai->beacon_ies_len = wpabuf_len(beacon_ies);
9712 } else if (os_strcmp(str, "freq") == 0) {
9713 ai->freq = atoi(pos);
9714 } else if (os_strcmp(str, "wmm::info_bitmap") == 0) {
9715 ai->wmm_params.info_bitmap = atoi(pos);
9716 } else if (os_strcmp(str, "wmm::uapsd_queues") == 0) {
9717 ai->wmm_params.uapsd_queues = atoi(pos);
9718 } else if (os_strcmp(str, "addr") == 0) {
9719 if (hwaddr_aton(pos, addr))
9720 goto fail;
9721 ai->addr = addr;
9722 } else if (os_strcmp(str, "authorized") == 0) {
9723 ai->authorized = atoi(pos);
9724 } else if (os_strcmp(str, "key_replay_ctr") == 0) {
9725 wpabuf_free(key_replay_ctr);
9726 key_replay_ctr = wpabuf_parse_bin(pos);
9727 if (!key_replay_ctr)
9728 goto fail;
9729 ai->key_replay_ctr = wpabuf_head(key_replay_ctr);
9730 ai->key_replay_ctr_len = wpabuf_len(key_replay_ctr);
9731 } else if (os_strcmp(str, "ptk_kck") == 0) {
9732 wpabuf_free(ptk_kck);
9733 ptk_kck = wpabuf_parse_bin(pos);
9734 if (!ptk_kck)
9735 goto fail;
9736 ai->ptk_kck = wpabuf_head(ptk_kck);
9737 ai->ptk_kck_len = wpabuf_len(ptk_kck);
9738 } else if (os_strcmp(str, "ptk_kek") == 0) {
9739 wpabuf_free(ptk_kek);
9740 ptk_kek = wpabuf_parse_bin(pos);
9741 if (!ptk_kek)
9742 goto fail;
9743 ai->ptk_kek = wpabuf_head(ptk_kek);
9744 ai->ptk_kek_len = wpabuf_len(ptk_kek);
9745 } else if (os_strcmp(str, "subnet_status") == 0) {
9746 ai->subnet_status = atoi(pos);
9747 } else if (os_strcmp(str, "fils_erp_next_seq_num") == 0) {
9748 ai->fils_erp_next_seq_num = atoi(pos);
9749 } else if (os_strcmp(str, "fils_pmk") == 0) {
9750 wpabuf_free(fils_pmk);
9751 fils_pmk = wpabuf_parse_bin(pos);
9752 if (!fils_pmk)
9753 goto fail;
9754 ai->fils_pmk = wpabuf_head(fils_pmk);
9755 ai->fils_pmk_len = wpabuf_len(fils_pmk);
9756 } else if (os_strcmp(str, "fils_pmkid") == 0) {
9757 if (hexstr2bin(pos, fils_pmkid, PMKID_LEN) < 0)
9758 goto fail;
9759 ai->fils_pmkid = fils_pmkid;
9760 } else {
9761 goto fail;
9762 }
9763 }
9764
9765 wpa_supplicant_event(wpa_s, EVENT_ASSOC, &event);
9766 ret = 0;
9767fail:
9768 wpabuf_free(req_ies);
9769 wpabuf_free(resp_ies);
9770 wpabuf_free(resp_frame);
9771 wpabuf_free(beacon_ies);
9772 wpabuf_free(key_replay_ctr);
9773 wpabuf_free(ptk_kck);
9774 wpabuf_free(ptk_kek);
9775 wpabuf_free(fils_pmk);
9776 return ret;
9777}
9778
9779
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009780static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
9781{
9782 char *pos, *param;
9783 union wpa_event_data event;
9784 enum wpa_event_type ev;
9785
9786 /* <event name> [parameters..] */
9787
9788 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
9789
9790 pos = cmd;
9791 param = os_strchr(pos, ' ');
9792 if (param)
9793 *param++ = '\0';
9794
9795 os_memset(&event, 0, sizeof(event));
9796
9797 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
9798 ev = EVENT_INTERFACE_ENABLED;
9799 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
9800 ev = EVENT_INTERFACE_DISABLED;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07009801 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
9802 ev = EVENT_AVOID_FREQUENCIES;
9803 if (param == NULL)
9804 param = "";
9805 if (freq_range_list_parse(&event.freq_range, param) < 0)
9806 return -1;
9807 wpa_supplicant_event(wpa_s, ev, &event);
9808 os_free(event.freq_range.range);
9809 return 0;
Paul Stewart092955c2017-02-06 09:13:09 -08009810 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
9811 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
Hai Shaloma20dcd72022-02-04 13:43:00 -08009812 } else if (os_strcmp(cmd, "ASSOC") == 0) {
9813 return wpas_ctrl_iface_driver_event_assoc(wpa_s, param);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009814 } else {
9815 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
9816 cmd);
9817 return -1;
9818 }
9819
9820 wpa_supplicant_event(wpa_s, ev, &event);
9821
9822 return 0;
9823}
9824
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009825
9826static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
9827{
9828 char *pos;
9829 u8 src[ETH_ALEN], *buf;
9830 int used;
9831 size_t len;
9832
9833 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
9834
9835 pos = cmd;
9836 used = hwaddr_aton2(pos, src);
9837 if (used < 0)
9838 return -1;
9839 pos += used;
9840 while (*pos == ' ')
9841 pos++;
9842
9843 len = os_strlen(pos);
9844 if (len & 1)
9845 return -1;
9846 len /= 2;
9847
9848 buf = os_malloc(len);
9849 if (buf == NULL)
9850 return -1;
9851
9852 if (hexstr2bin(pos, buf, len) < 0) {
9853 os_free(buf);
9854 return -1;
9855 }
9856
Sunil8cd6f4d2022-06-28 18:40:46 +00009857 wpa_supplicant_rx_eapol(wpa_s, src, buf, len, FRAME_ENCRYPTION_UNKNOWN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009858 os_free(buf);
9859
9860 return 0;
9861}
9862
9863
Hai Shaloma20dcd72022-02-04 13:43:00 -08009864static int wpas_ctrl_iface_eapol_tx(struct wpa_supplicant *wpa_s, char *cmd)
9865{
9866 char *pos;
9867 u8 dst[ETH_ALEN], *buf;
9868 int used, ret;
9869 size_t len;
9870 unsigned int prev;
9871
9872 wpa_printf(MSG_DEBUG, "External EAPOL TX: %s", cmd);
9873
9874 pos = cmd;
9875 used = hwaddr_aton2(pos, dst);
9876 if (used < 0)
9877 return -1;
9878 pos += used;
9879 while (*pos == ' ')
9880 pos++;
9881
9882 len = os_strlen(pos);
9883 if (len & 1)
9884 return -1;
9885 len /= 2;
9886
9887 buf = os_malloc(len);
9888 if (!buf || hexstr2bin(pos, buf, len) < 0) {
9889 os_free(buf);
9890 return -1;
9891 }
9892
9893 prev = wpa_s->ext_eapol_frame_io;
9894 wpa_s->ext_eapol_frame_io = 0;
9895 ret = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, buf, len);
9896 wpa_s->ext_eapol_frame_io = prev;
9897 os_free(buf);
9898
9899 return ret;
9900}
9901
9902
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009903static u16 ipv4_hdr_checksum(const void *buf, size_t len)
9904{
9905 size_t i;
9906 u32 sum = 0;
9907 const u16 *pos = buf;
9908
9909 for (i = 0; i < len / 2; i++)
9910 sum += *pos++;
9911
9912 while (sum >> 16)
9913 sum = (sum & 0xffff) + (sum >> 16);
9914
9915 return sum ^ 0xffff;
9916}
9917
9918
9919#define HWSIM_PACKETLEN 1500
9920#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
9921
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07009922static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
9923 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009924{
9925 struct wpa_supplicant *wpa_s = ctx;
9926 const struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07009927 struct ip ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009928 const u8 *pos;
9929 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08009930 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009931
Hai Shalom74f70d42019-02-11 14:42:39 -08009932 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
9933 wpa_printf(MSG_DEBUG,
9934 "test data: RX - ignore unexpected length %d",
9935 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009936 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08009937 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009938
9939 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009940 os_memcpy(&ip, eth + 1, sizeof(ip));
9941 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009942
Hai Shalomfdcde762020-04-02 11:19:20 -07009943 if (ip.ip_hl != 5 || ip.ip_v != 4 || ntohs(ip.ip_len) > HWSIM_IP_LEN) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009944 wpa_printf(MSG_DEBUG,
Hai Shalom899fcc72020-10-19 14:38:18 -07009945 "test data: RX - ignore unexpected IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009946 return;
Hai Shalom39bc25d2019-02-06 16:32:13 -08009947 }
Hai Shalombf6e0ba2019-02-11 12:01:50 -08009948
Hai Shalomfdcde762020-04-02 11:19:20 -07009949 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009950 if (*pos != (u8) i) {
9951 wpa_printf(MSG_DEBUG,
9952 "test data: RX - ignore mismatching payload");
9953 return;
9954 }
9955 pos++;
9956 }
9957 extra[0] = '\0';
Hai Shalomfdcde762020-04-02 11:19:20 -07009958 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
9959 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
Hai Shalom74f70d42019-02-11 14:42:39 -08009960 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
9961 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009962}
9963
9964
9965static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
9966 char *cmd)
9967{
9968 int enabled = atoi(cmd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009969 char *pos;
9970 const char *ifname;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009971
9972 if (!enabled) {
9973 if (wpa_s->l2_test) {
9974 l2_packet_deinit(wpa_s->l2_test);
9975 wpa_s->l2_test = NULL;
9976 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
9977 }
9978 return 0;
9979 }
9980
9981 if (wpa_s->l2_test)
9982 return 0;
9983
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009984 pos = os_strstr(cmd, " ifname=");
9985 if (pos)
9986 ifname = pos + 8;
9987 else
9988 ifname = wpa_s->ifname;
9989
9990 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009991 ETHERTYPE_IP, wpas_data_test_rx,
9992 wpa_s, 1);
9993 if (wpa_s->l2_test == NULL)
9994 return -1;
9995
9996 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
9997
9998 return 0;
9999}
10000
10001
10002static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
10003{
10004 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom74f70d42019-02-11 14:42:39 -080010005 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010006 int used;
10007 long int val;
10008 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010009 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010010 struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -070010011 struct ip *ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010012 u8 *dpos;
10013 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -080010014 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010015
10016 if (wpa_s->l2_test == NULL)
10017 return -1;
10018
Hai Shalom74f70d42019-02-11 14:42:39 -080010019 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010020
10021 pos = cmd;
10022 used = hwaddr_aton2(pos, dst);
10023 if (used < 0)
10024 return -1;
10025 pos += used;
10026 while (*pos == ' ')
10027 pos++;
10028 used = hwaddr_aton2(pos, src);
10029 if (used < 0)
10030 return -1;
10031 pos += used;
10032
Hai Shalom74f70d42019-02-11 14:42:39 -080010033 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010034 if (val < 0 || val > 0xff)
10035 return -1;
10036 tos = val;
10037
Hai Shalom74f70d42019-02-11 14:42:39 -080010038 pos = os_strstr(pos2, " len=");
10039 if (pos) {
10040 i = atoi(pos + 5);
10041 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
10042 return -1;
10043 send_len = i;
10044 }
10045
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010046 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010047 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
10048 os_memcpy(eth->ether_shost, src, ETH_ALEN);
10049 eth->ether_type = htons(ETHERTYPE_IP);
Hai Shalomfdcde762020-04-02 11:19:20 -070010050 ip = (struct ip *) (eth + 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010051 os_memset(ip, 0, sizeof(*ip));
Hai Shalomfdcde762020-04-02 11:19:20 -070010052 ip->ip_hl = 5;
10053 ip->ip_v = 4;
10054 ip->ip_ttl = 64;
10055 ip->ip_tos = tos;
10056 ip->ip_len = htons(send_len);
10057 ip->ip_p = 1;
10058 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
10059 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
10060 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010061 dpos = (u8 *) (ip + 1);
Hai Shalom74f70d42019-02-11 14:42:39 -080010062 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010063 *dpos++ = i;
10064
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010065 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom74f70d42019-02-11 14:42:39 -080010066 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010067 return -1;
10068
10069 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
10070 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
10071
10072 return 0;
10073}
10074
10075
10076static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
10077 char *cmd)
10078{
10079 u8 *buf;
10080 struct ether_header *eth;
10081 struct l2_packet_data *l2 = NULL;
10082 size_t len;
10083 u16 ethertype;
10084 int res = -1;
10085
10086 len = os_strlen(cmd);
10087 if (len & 1 || len < ETH_HLEN * 2)
10088 return -1;
10089 len /= 2;
10090
10091 buf = os_malloc(len);
10092 if (buf == NULL)
10093 return -1;
10094
10095 if (hexstr2bin(cmd, buf, len) < 0)
10096 goto done;
10097
10098 eth = (struct ether_header *) buf;
10099 ethertype = ntohs(eth->ether_type);
10100
10101 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
10102 wpas_data_test_rx, wpa_s, 1);
10103 if (l2 == NULL)
10104 goto done;
10105
10106 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
10107 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
10108done:
10109 if (l2)
10110 l2_packet_deinit(l2);
10111 os_free(buf);
10112
10113 return res < 0 ? -1 : 0;
10114}
10115
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010116
10117static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
10118{
10119#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010120 char *pos;
10121
10122 wpa_trace_fail_after = atoi(cmd);
10123 pos = os_strchr(cmd, ':');
10124 if (pos) {
10125 pos++;
10126 os_strlcpy(wpa_trace_fail_func, pos,
10127 sizeof(wpa_trace_fail_func));
10128 } else {
10129 wpa_trace_fail_after = 0;
10130 }
10131 return 0;
10132#else /* WPA_TRACE_BFD */
10133 return -1;
10134#endif /* WPA_TRACE_BFD */
10135}
10136
10137
10138static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
10139 char *buf, size_t buflen)
10140{
10141#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010142 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
10143 wpa_trace_fail_func);
10144#else /* WPA_TRACE_BFD */
10145 return -1;
10146#endif /* WPA_TRACE_BFD */
10147}
10148
Jouni Malinenc4818362015-10-04 11:45:13 +030010149
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010150static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
10151{
10152#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010153 char *pos;
10154
10155 wpa_trace_test_fail_after = atoi(cmd);
10156 pos = os_strchr(cmd, ':');
10157 if (pos) {
10158 pos++;
10159 os_strlcpy(wpa_trace_test_fail_func, pos,
10160 sizeof(wpa_trace_test_fail_func));
10161 } else {
10162 wpa_trace_test_fail_after = 0;
10163 }
10164 return 0;
10165#else /* WPA_TRACE_BFD */
10166 return -1;
10167#endif /* WPA_TRACE_BFD */
10168}
10169
10170
10171static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
10172 char *buf, size_t buflen)
10173{
10174#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010175 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
10176 wpa_trace_test_fail_func);
10177#else /* WPA_TRACE_BFD */
10178 return -1;
10179#endif /* WPA_TRACE_BFD */
10180}
10181
10182
Jouni Malinenc4818362015-10-04 11:45:13 +030010183static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
10184{
10185 struct wpa_supplicant *wpa_s = eloop_ctx;
10186 int i, count = (intptr_t) timeout_ctx;
10187
10188 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
10189 count);
10190 for (i = 0; i < count; i++) {
10191 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
10192 i + 1, count);
10193 }
10194}
10195
10196
10197static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
10198{
10199 int count;
10200
10201 count = atoi(cmd);
10202 if (count <= 0)
10203 return -1;
10204
10205 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
10206 (void *) (intptr_t) count);
10207}
10208
Dmitry Shmidt818ea482014-03-10 13:15:21 -070010209
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010210static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
10211 const char *cmd)
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010212{
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010213 struct wpabuf *buf;
10214 size_t len;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010215
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010216 len = os_strlen(cmd);
10217 if (len & 1)
10218 return -1;
10219 len /= 2;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010220
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010221 if (len == 0) {
10222 buf = NULL;
10223 } else {
10224 buf = wpabuf_alloc(len);
10225 if (buf == NULL)
10226 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010227
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010228 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
10229 wpabuf_free(buf);
10230 return -1;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010231 }
10232 }
10233
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010234 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
10235 return 0;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010236}
10237
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010238
10239static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
10240{
10241 u8 zero[WPA_TK_MAX_LEN];
10242
10243 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
10244 return -1;
10245
10246 wpa_printf(MSG_INFO, "TESTING: Reset PN");
10247 os_memset(zero, 0, sizeof(zero));
10248
10249 /* First, use a zero key to avoid any possible duplicate key avoidance
10250 * in the driver. */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000010251 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 -070010252 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -070010253 zero, wpa_s->last_tk_len,
10254 KEY_FLAG_PAIRWISE_RX_TX) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010255 return -1;
10256
10257 /* Set the previously configured key to reset its TSC/RSC */
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000010258 return wpa_drv_set_key(wpa_s, -1, wpa_s->last_tk_alg,
10259 wpa_s->last_tk_addr,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010260 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -070010261 wpa_s->last_tk, wpa_s->last_tk_len,
10262 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010263}
10264
10265
10266static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
10267{
10268 const char *pos = cmd;
10269 int error, pairwise;
10270
10271 error = atoi(pos);
10272 pos = os_strchr(pos, ' ');
10273 if (!pos)
10274 return -1;
10275 pairwise = atoi(pos);
10276 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
10277 return 0;
10278}
10279
10280
10281static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
10282{
10283#ifdef CONFIG_SME
10284 struct wpa_driver_associate_params params;
10285 int ret;
10286
10287 os_memset(&params, 0, sizeof(params));
10288 params.bssid = wpa_s->bssid;
10289 params.ssid = wpa_s->sme.ssid;
10290 params.ssid_len = wpa_s->sme.ssid_len;
10291 params.freq.freq = wpa_s->sme.freq;
10292 if (wpa_s->last_assoc_req_wpa_ie) {
10293 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
10294 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
10295 }
10296 params.pairwise_suite = wpa_s->pairwise_cipher;
10297 params.group_suite = wpa_s->group_cipher;
10298 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
10299 params.key_mgmt_suite = wpa_s->key_mgmt;
10300 params.wpa_proto = wpa_s->wpa_proto;
10301 params.mgmt_frame_protection = wpa_s->sme.mfp;
10302 params.rrm_used = wpa_s->rrm.rrm_used;
10303 if (wpa_s->sme.prev_bssid_set)
10304 params.prev_bssid = wpa_s->sme.prev_bssid;
10305 wpa_printf(MSG_INFO, "TESTING: Resend association request");
10306 ret = wpa_drv_associate(wpa_s, &params);
10307 wpa_s->testing_resend_assoc = 1;
10308 return ret;
10309#else /* CONFIG_SME */
10310 return -1;
10311#endif /* CONFIG_SME */
10312}
10313
Hai Shaloma20dcd72022-02-04 13:43:00 -080010314
10315static int wpas_ctrl_iface_send_twt_setup(struct wpa_supplicant *wpa_s,
10316 const char *cmd)
10317{
10318 u8 dtok = 1;
10319 int exponent = 10;
10320 int mantissa = 8192;
10321 u8 min_twt = 255;
10322 unsigned long long twt = 0;
10323 bool requestor = true;
10324 int setup_cmd = 0;
10325 bool trigger = true;
10326 bool implicit = true;
10327 bool flow_type = true;
10328 int flow_id = 0;
10329 bool protection = false;
10330 u8 twt_channel = 0;
Sunil Ravia04bd252022-05-02 22:54:18 -070010331 u8 control = BIT(4); /* Control field (IEEE Std 802.11ax-2021,
10332 * Figure 9-687 - Control field format):
10333 * B4 = TWT Information Frame Disabled */
Hai Shaloma20dcd72022-02-04 13:43:00 -080010334 const char *tok_s;
10335
10336 tok_s = os_strstr(cmd, " dialog=");
10337 if (tok_s)
10338 dtok = atoi(tok_s + os_strlen(" dialog="));
10339
10340 tok_s = os_strstr(cmd, " exponent=");
10341 if (tok_s)
10342 exponent = atoi(tok_s + os_strlen(" exponent="));
10343
10344 tok_s = os_strstr(cmd, " mantissa=");
10345 if (tok_s)
10346 mantissa = atoi(tok_s + os_strlen(" mantissa="));
10347
10348 tok_s = os_strstr(cmd, " min_twt=");
10349 if (tok_s)
10350 min_twt = atoi(tok_s + os_strlen(" min_twt="));
10351
10352 tok_s = os_strstr(cmd, " setup_cmd=");
10353 if (tok_s)
10354 setup_cmd = atoi(tok_s + os_strlen(" setup_cmd="));
10355
10356 tok_s = os_strstr(cmd, " twt=");
Sunil8cd6f4d2022-06-28 18:40:46 +000010357 if (tok_s &&
10358 sscanf(tok_s + os_strlen(" twt="), "%llu", &twt) != 1)
10359 return -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080010360
10361 tok_s = os_strstr(cmd, " requestor=");
10362 if (tok_s)
10363 requestor = atoi(tok_s + os_strlen(" requestor="));
10364
10365 tok_s = os_strstr(cmd, " trigger=");
10366 if (tok_s)
10367 trigger = atoi(tok_s + os_strlen(" trigger="));
10368
10369 tok_s = os_strstr(cmd, " implicit=");
10370 if (tok_s)
10371 implicit = atoi(tok_s + os_strlen(" implicit="));
10372
10373 tok_s = os_strstr(cmd, " flow_type=");
10374 if (tok_s)
10375 flow_type = atoi(tok_s + os_strlen(" flow_type="));
10376
10377 tok_s = os_strstr(cmd, " flow_id=");
10378 if (tok_s)
10379 flow_id = atoi(tok_s + os_strlen(" flow_id="));
10380
10381 tok_s = os_strstr(cmd, " protection=");
10382 if (tok_s)
10383 protection = atoi(tok_s + os_strlen(" protection="));
10384
10385 tok_s = os_strstr(cmd, " twt_channel=");
10386 if (tok_s)
10387 twt_channel = atoi(tok_s + os_strlen(" twt_channel="));
10388
10389 tok_s = os_strstr(cmd, " control=");
10390 if (tok_s)
10391 control = atoi(tok_s + os_strlen(" control="));
10392
10393 return wpas_twt_send_setup(wpa_s, dtok, exponent, mantissa, min_twt,
10394 setup_cmd, twt, requestor, trigger, implicit,
10395 flow_type, flow_id, protection, twt_channel,
10396 control);
10397}
10398
10399
10400static int wpas_ctrl_iface_send_twt_teardown(struct wpa_supplicant *wpa_s,
10401 const char *cmd)
10402{
10403 u8 flags = 0x1;
10404 const char *tok_s;
10405
10406 tok_s = os_strstr(cmd, " flags=");
10407 if (tok_s)
10408 flags = atoi(tok_s + os_strlen(" flags="));
10409
10410 return wpas_twt_send_teardown(wpa_s, flags);
10411}
10412
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010413#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010414
10415
10416static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
10417{
10418 char *pos = cmd;
10419 int frame;
10420 size_t len;
10421 struct wpabuf *buf;
10422 struct ieee802_11_elems elems;
10423
10424 frame = atoi(pos);
10425 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10426 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010427 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010428
10429 pos = os_strchr(pos, ' ');
10430 if (pos == NULL)
10431 return -1;
10432 pos++;
10433
10434 len = os_strlen(pos);
10435 if (len == 0)
10436 return 0;
10437 if (len & 1)
10438 return -1;
10439 len /= 2;
10440
10441 buf = wpabuf_alloc(len);
10442 if (buf == NULL)
10443 return -1;
10444
10445 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
10446 wpabuf_free(buf);
10447 return -1;
10448 }
10449
10450 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
10451 ParseFailed) {
10452 wpabuf_free(buf);
10453 return -1;
10454 }
10455
10456 if (wpa_s->vendor_elem[frame] == NULL) {
10457 wpa_s->vendor_elem[frame] = buf;
Hai Shalom60840252021-02-19 19:02:11 -080010458 goto update_ies;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010459 }
10460
10461 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
10462 wpabuf_free(buf);
10463 return -1;
10464 }
10465
10466 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
10467 wpabuf_free(buf);
Hai Shalom60840252021-02-19 19:02:11 -080010468
10469update_ies:
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010470 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010471
Hai Shalom60840252021-02-19 19:02:11 -080010472 if (frame == VENDOR_ELEM_PROBE_REQ ||
10473 frame == VENDOR_ELEM_PROBE_REQ_P2P)
10474 wpa_supplicant_set_default_scan_ies(wpa_s);
10475
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010476 return 0;
10477}
10478
10479
10480static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
10481 char *buf, size_t buflen)
10482{
10483 int frame = atoi(cmd);
10484
10485 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10486 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010487 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010488
10489 if (wpa_s->vendor_elem[frame] == NULL)
10490 return 0;
10491
10492 return wpa_snprintf_hex(buf, buflen,
10493 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
10494 wpabuf_len(wpa_s->vendor_elem[frame]));
10495}
10496
10497
10498static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
10499{
10500 char *pos = cmd;
10501 int frame;
10502 size_t len;
10503 u8 *buf;
10504 struct ieee802_11_elems elems;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010505 int res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010506
10507 frame = atoi(pos);
10508 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10509 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010510 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010511
10512 pos = os_strchr(pos, ' ');
10513 if (pos == NULL)
10514 return -1;
10515 pos++;
10516
10517 if (*pos == '*') {
10518 wpabuf_free(wpa_s->vendor_elem[frame]);
10519 wpa_s->vendor_elem[frame] = NULL;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010520 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010521 return 0;
10522 }
10523
10524 if (wpa_s->vendor_elem[frame] == NULL)
10525 return -1;
10526
10527 len = os_strlen(pos);
10528 if (len == 0)
10529 return 0;
10530 if (len & 1)
10531 return -1;
10532 len /= 2;
10533
10534 buf = os_malloc(len);
10535 if (buf == NULL)
10536 return -1;
10537
10538 if (hexstr2bin(pos, buf, len) < 0) {
10539 os_free(buf);
10540 return -1;
10541 }
10542
10543 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
10544 os_free(buf);
10545 return -1;
10546 }
10547
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010548 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010549 os_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010550 return res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010551}
10552
10553
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010554static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
10555{
10556 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010557 size_t len;
10558 const u8 *data;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010559
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010560 /*
10561 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
10562 * BSSID[6]
10563 * BSSID Information[4]
10564 * Operating Class[1]
10565 * Channel Number[1]
10566 * PHY Type[1]
10567 * Optional Subelements[variable]
10568 */
10569#define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
10570
10571 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010572 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010573 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010574 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010575
10576 data = wpabuf_head_u8(neighbor_rep);
10577 len = wpabuf_len(neighbor_rep);
10578
10579 while (len >= 2 + NR_IE_MIN_LEN) {
10580 const u8 *nr;
10581 char lci[256 * 2 + 1];
10582 char civic[256 * 2 + 1];
10583 u8 nr_len = data[1];
10584 const u8 *pos = data, *end;
10585
10586 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
10587 nr_len < NR_IE_MIN_LEN) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010588 wpa_dbg(wpa_s, MSG_DEBUG,
10589 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
10590 data[0], nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010591 goto out;
10592 }
10593
10594 if (2U + nr_len > len) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010595 wpa_dbg(wpa_s, MSG_DEBUG,
10596 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
10597 data[0], len, nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010598 goto out;
10599 }
10600 pos += 2;
10601 end = pos + nr_len;
10602
10603 nr = pos;
10604 pos += NR_IE_MIN_LEN;
10605
10606 lci[0] = '\0';
10607 civic[0] = '\0';
10608 while (end - pos > 2) {
10609 u8 s_id, s_len;
10610
10611 s_id = *pos++;
10612 s_len = *pos++;
10613 if (s_len > end - pos)
10614 goto out;
10615 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
10616 /* Measurement Token[1] */
10617 /* Measurement Report Mode[1] */
10618 /* Measurement Type[1] */
10619 /* Measurement Report[variable] */
10620 switch (pos[2]) {
10621 case MEASURE_TYPE_LCI:
10622 if (lci[0])
10623 break;
10624 wpa_snprintf_hex(lci, sizeof(lci),
10625 pos, s_len);
10626 break;
10627 case MEASURE_TYPE_LOCATION_CIVIC:
10628 if (civic[0])
10629 break;
10630 wpa_snprintf_hex(civic, sizeof(civic),
10631 pos, s_len);
10632 break;
10633 }
10634 }
10635
10636 pos += s_len;
10637 }
10638
10639 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
10640 "bssid=" MACSTR
10641 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
10642 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
10643 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
10644 nr[ETH_ALEN + 6],
10645 lci[0] ? " lci=" : "", lci,
10646 civic[0] ? " civic=" : "", civic);
10647
10648 data = end;
10649 len -= 2 + nr_len;
10650 }
10651
10652out:
10653 wpabuf_free(neighbor_rep);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010654}
10655
10656
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010657static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
10658 char *cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010659{
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010660 struct wpa_ssid_value ssid, *ssid_p = NULL;
10661 int ret, lci = 0, civic = 0;
10662 char *ssid_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010663
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010664 ssid_s = os_strstr(cmd, "ssid=");
10665 if (ssid_s) {
10666 if (ssid_parse(ssid_s + 5, &ssid)) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010667 wpa_msg(wpa_s, MSG_INFO,
10668 "CTRL: Send Neighbor Report: bad SSID");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010669 return -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010670 }
10671
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010672 ssid_p = &ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010673
10674 /*
10675 * Move cmd after the SSID text that may include "lci" or
10676 * "civic".
10677 */
10678 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
10679 if (cmd)
10680 cmd++;
10681
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010682 }
10683
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010684 if (cmd && os_strstr(cmd, "lci"))
10685 lci = 1;
10686
10687 if (cmd && os_strstr(cmd, "civic"))
10688 civic = 1;
10689
10690 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010691 wpas_ctrl_neighbor_rep_cb,
10692 wpa_s);
10693
10694 return ret;
10695}
10696
10697
10698static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
10699{
10700 eapol_sm_erp_flush(wpa_s->eapol);
10701 return 0;
10702}
10703
10704
10705static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
10706 char *cmd)
10707{
10708 char *token, *context = NULL;
10709 unsigned int enable = ~0, type = 0;
10710 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
10711 u8 *addr = NULL, *mask = NULL;
10712
10713 while ((token = str_token(cmd, " ", &context))) {
10714 if (os_strcasecmp(token, "scan") == 0) {
10715 type |= MAC_ADDR_RAND_SCAN;
10716 } else if (os_strcasecmp(token, "sched") == 0) {
10717 type |= MAC_ADDR_RAND_SCHED_SCAN;
10718 } else if (os_strcasecmp(token, "pno") == 0) {
10719 type |= MAC_ADDR_RAND_PNO;
10720 } else if (os_strcasecmp(token, "all") == 0) {
10721 type = wpa_s->mac_addr_rand_supported;
10722 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
10723 enable = atoi(token + 7);
10724 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
10725 addr = _addr;
10726 if (hwaddr_aton(token + 5, addr)) {
10727 wpa_printf(MSG_INFO,
10728 "CTRL: Invalid MAC address: %s",
10729 token);
10730 return -1;
10731 }
10732 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
10733 mask = _mask;
10734 if (hwaddr_aton(token + 5, mask)) {
10735 wpa_printf(MSG_INFO,
10736 "CTRL: Invalid MAC address mask: %s",
10737 token);
10738 return -1;
10739 }
10740 } else {
10741 wpa_printf(MSG_INFO,
10742 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
10743 token);
10744 return -1;
10745 }
10746 }
10747
10748 if (!type) {
10749 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
10750 return -1;
10751 }
10752
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010753 if (enable > 1) {
10754 wpa_printf(MSG_INFO,
10755 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
10756 return -1;
10757 }
10758
Hai Shalom81f62d82019-07-22 12:10:00 -070010759 if (!enable)
10760 return wpas_disable_mac_addr_randomization(wpa_s, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010761
Hai Shalom81f62d82019-07-22 12:10:00 -070010762 return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010763}
10764
10765
Dmitry Shmidte4663042016-04-04 10:07:49 -070010766static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
10767 char *buf, size_t buflen)
10768{
10769 size_t reply_len;
10770
10771 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
10772#ifdef CONFIG_AP
10773 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
10774 buflen - reply_len);
10775#endif /* CONFIG_AP */
10776 return reply_len;
10777}
10778
10779
10780static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
10781{
Hai Shalom60840252021-02-19 19:02:11 -080010782 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
Dmitry Shmidte4663042016-04-04 10:07:49 -070010783 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
10784#ifdef CONFIG_AP
10785 wpas_ap_pmksa_cache_flush(wpa_s);
10786#endif /* CONFIG_AP */
10787}
10788
10789
Dmitry Shmidt29333592017-01-09 12:27:11 -080010790#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10791
10792static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
10793 const char *cmd, char *buf, size_t buflen)
10794{
10795 struct rsn_pmksa_cache_entry *entry;
10796 struct wpa_ssid *ssid;
10797 char *pos, *pos2, *end;
10798 int ret;
10799 struct os_reltime now;
10800
10801 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10802 if (!ssid)
10803 return -1;
10804
10805 pos = buf;
10806 end = buf + buflen;
10807
10808 os_get_reltime(&now);
10809
10810 /*
10811 * Entry format:
10812 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10813 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010814 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010815 */
10816
10817 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
10818 entry = entry->next) {
10819 if (entry->network_ctx != ssid)
10820 continue;
10821
10822 pos2 = pos;
10823 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
10824 MAC2STR(entry->aa));
10825 if (os_snprintf_error(end - pos2, ret))
10826 break;
10827 pos2 += ret;
10828
10829 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
10830 PMKID_LEN);
10831
10832 ret = os_snprintf(pos2, end - pos2, " ");
10833 if (os_snprintf_error(end - pos2, ret))
10834 break;
10835 pos2 += ret;
10836
10837 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
10838 entry->pmk_len);
10839
10840 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
10841 (int) (entry->reauth_time - now.sec),
10842 (int) (entry->expiration - now.sec),
10843 entry->akmp,
10844 entry->opportunistic);
10845 if (os_snprintf_error(end - pos2, ret))
10846 break;
10847 pos2 += ret;
10848
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010849 if (entry->fils_cache_id_set) {
10850 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
10851 entry->fils_cache_id[0],
10852 entry->fils_cache_id[1]);
10853 if (os_snprintf_error(end - pos2, ret))
10854 break;
10855 pos2 += ret;
10856 }
10857
Dmitry Shmidt29333592017-01-09 12:27:11 -080010858 ret = os_snprintf(pos2, end - pos2, "\n");
10859 if (os_snprintf_error(end - pos2, ret))
10860 break;
10861 pos2 += ret;
10862
10863 pos = pos2;
10864 }
10865
10866 return pos - buf;
10867}
10868
10869
10870static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
10871 char *cmd)
10872{
10873 struct rsn_pmksa_cache_entry *entry;
10874 struct wpa_ssid *ssid;
10875 char *pos, *pos2;
10876 int ret = -1;
10877 struct os_reltime now;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010878 int reauth_time = 0, expiration = 0, i;
Dmitry Shmidt29333592017-01-09 12:27:11 -080010879
10880 /*
10881 * Entry format:
10882 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10883 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010884 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010885 */
10886
10887 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10888 if (!ssid)
10889 return -1;
10890
10891 pos = os_strchr(cmd, ' ');
10892 if (!pos)
10893 return -1;
10894 pos++;
10895
10896 entry = os_zalloc(sizeof(*entry));
10897 if (!entry)
10898 return -1;
10899
10900 if (hwaddr_aton(pos, entry->aa))
10901 goto fail;
10902
10903 pos = os_strchr(pos, ' ');
10904 if (!pos)
10905 goto fail;
10906 pos++;
10907
10908 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
10909 goto fail;
10910
10911 pos = os_strchr(pos, ' ');
10912 if (!pos)
10913 goto fail;
10914 pos++;
10915
10916 pos2 = os_strchr(pos, ' ');
10917 if (!pos2)
10918 goto fail;
10919 entry->pmk_len = (pos2 - pos) / 2;
10920 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
10921 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
10922 goto fail;
10923
10924 pos = os_strchr(pos, ' ');
10925 if (!pos)
10926 goto fail;
10927 pos++;
10928
10929 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
10930 &entry->akmp, &entry->opportunistic) != 4)
10931 goto fail;
Hai Shaloma20dcd72022-02-04 13:43:00 -080010932 if (reauth_time > expiration)
10933 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010934 for (i = 0; i < 4; i++) {
10935 pos = os_strchr(pos, ' ');
10936 if (!pos) {
10937 if (i < 3)
10938 goto fail;
10939 break;
10940 }
10941 pos++;
10942 }
10943 if (pos) {
10944 if (hexstr2bin(pos, entry->fils_cache_id,
10945 FILS_CACHE_ID_LEN) < 0)
10946 goto fail;
10947 entry->fils_cache_id_set = 1;
10948 }
Dmitry Shmidt29333592017-01-09 12:27:11 -080010949 os_get_reltime(&now);
10950 entry->expiration = now.sec + expiration;
10951 entry->reauth_time = now.sec + reauth_time;
10952
10953 entry->network_ctx = ssid;
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000010954 os_memcpy(entry->spa, wpa_s->own_addr, ETH_ALEN);
Dmitry Shmidt29333592017-01-09 12:27:11 -080010955
Hai Shaloma20dcd72022-02-04 13:43:00 -080010956 entry->external = true;
10957
Dmitry Shmidt29333592017-01-09 12:27:11 -080010958 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
10959 entry = NULL;
10960 ret = 0;
10961fail:
10962 os_free(entry);
10963 return ret;
10964}
10965
Paul Stewart092955c2017-02-06 09:13:09 -080010966
10967#ifdef CONFIG_MESH
10968
10969static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
10970 const char *cmd, char *buf,
10971 size_t buflen)
10972{
10973 u8 spa[ETH_ALEN];
10974
10975 if (!wpa_s->ifmsh)
10976 return -1;
10977
10978 if (os_strcasecmp(cmd, "any") == 0)
10979 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
10980
10981 if (hwaddr_aton(cmd, spa))
10982 return -1;
10983
10984 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
10985}
10986
10987
10988static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
10989 char *cmd)
10990{
10991 /*
Hai Shalom60840252021-02-19 19:02:11 -080010992 * We do not check mesh interface existence because PMKSA should be
Paul Stewart092955c2017-02-06 09:13:09 -080010993 * stored before wpa_s->ifmsh creation to suppress commit message
10994 * creation.
10995 */
10996 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
10997}
10998
10999#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080011000#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
11001
11002
Paul Stewart092955c2017-02-06 09:13:09 -080011003#ifdef CONFIG_FILS
11004static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
11005 const char *cmd)
11006{
11007 struct fils_hlp_req *req;
11008 const char *pos;
11009
11010 /* format: <dst> <packet starting from ethertype> */
11011
11012 req = os_zalloc(sizeof(*req));
11013 if (!req)
11014 return -1;
11015
11016 if (hwaddr_aton(cmd, req->dst))
11017 goto fail;
11018
11019 pos = os_strchr(cmd, ' ');
11020 if (!pos)
11021 goto fail;
11022 pos++;
11023 req->pkt = wpabuf_parse_bin(pos);
11024 if (!req->pkt)
11025 goto fail;
11026
11027 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
11028 return 0;
11029fail:
11030 wpabuf_free(req->pkt);
11031 os_free(req);
11032 return -1;
11033}
11034#endif /* CONFIG_FILS */
11035
11036
Sunil Ravia04bd252022-05-02 22:54:18 -070011037int wpas_ctrl_cmd_debug_level(const char *cmd)
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011038{
11039 if (os_strcmp(cmd, "PING") == 0 ||
11040 os_strncmp(cmd, "BSS ", 4) == 0 ||
11041 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
11042 os_strncmp(cmd, "STATUS", 6) == 0 ||
11043 os_strncmp(cmd, "STA ", 4) == 0 ||
11044 os_strncmp(cmd, "STA-", 4) == 0)
11045 return MSG_EXCESSIVE;
11046 return MSG_DEBUG;
11047}
11048
11049
Hai Shalom899fcc72020-10-19 14:38:18 -070011050static int wpas_ctrl_iface_configure_mscs(struct wpa_supplicant *wpa_s,
11051 const char *cmd)
11052{
11053 size_t frame_classifier_len;
11054 const char *pos, *end;
11055 struct robust_av_data *robust_av = &wpa_s->robust_av;
11056 int val;
11057
11058 /*
11059 * format:
11060 * <add|remove|change> [up_bitmap=<hex byte>] [up_limit=<integer>]
11061 * [stream_timeout=<in TUs>] [frame_classifier=<hex bytes>]
11062 */
11063 os_memset(robust_av, 0, sizeof(struct robust_av_data));
11064 if (os_strncmp(cmd, "add ", 4) == 0) {
11065 robust_av->request_type = SCS_REQ_ADD;
11066 } else if (os_strcmp(cmd, "remove") == 0) {
11067 robust_av->request_type = SCS_REQ_REMOVE;
11068 robust_av->valid_config = false;
11069 return wpas_send_mscs_req(wpa_s);
11070 } else if (os_strncmp(cmd, "change ", 7) == 0) {
11071 robust_av->request_type = SCS_REQ_CHANGE;
11072 } else {
11073 return -1;
11074 }
11075
11076 pos = os_strstr(cmd, "up_bitmap=");
11077 if (!pos)
11078 return -1;
11079
11080 val = hex2byte(pos + 10);
11081 if (val < 0)
11082 return -1;
11083 robust_av->up_bitmap = val;
11084
11085 pos = os_strstr(cmd, "up_limit=");
11086 if (!pos)
11087 return -1;
11088
11089 robust_av->up_limit = atoi(pos + 9);
11090
11091 pos = os_strstr(cmd, "stream_timeout=");
11092 if (!pos)
11093 return -1;
11094
11095 robust_av->stream_timeout = atoi(pos + 15);
11096 if (robust_av->stream_timeout == 0)
11097 return -1;
11098
11099 pos = os_strstr(cmd, "frame_classifier=");
11100 if (!pos)
11101 return -1;
11102
11103 pos += 17;
11104 end = os_strchr(pos, ' ');
11105 if (!end)
11106 end = pos + os_strlen(pos);
11107
11108 frame_classifier_len = (end - pos) / 2;
11109 if (frame_classifier_len > sizeof(robust_av->frame_classifier) ||
11110 hexstr2bin(pos, robust_av->frame_classifier, frame_classifier_len))
11111 return -1;
11112
11113 robust_av->frame_classifier_len = frame_classifier_len;
11114 robust_av->valid_config = true;
11115
11116 return wpas_send_mscs_req(wpa_s);
11117}
11118
11119
Hai Shalom60840252021-02-19 19:02:11 -080011120#ifdef CONFIG_PASN
11121static int wpas_ctrl_iface_pasn_start(struct wpa_supplicant *wpa_s, char *cmd)
11122{
11123 char *token, *context = NULL;
11124 u8 bssid[ETH_ALEN];
11125 int akmp = -1, cipher = -1, got_bssid = 0;
11126 u16 group = 0xFFFF;
Hai Shaloma20dcd72022-02-04 13:43:00 -080011127 u8 *comeback = NULL;
11128 size_t comeback_len = 0;
11129 int id = 0, ret = -1;
Hai Shalom60840252021-02-19 19:02:11 -080011130
11131 /*
11132 * Entry format: bssid=<BSSID> akmp=<AKMP> cipher=<CIPHER> group=<group>
Hai Shaloma20dcd72022-02-04 13:43:00 -080011133 * [comeback=<hexdump>]
Hai Shalom60840252021-02-19 19:02:11 -080011134 */
11135 while ((token = str_token(cmd, " ", &context))) {
11136 if (os_strncmp(token, "bssid=", 6) == 0) {
11137 if (hwaddr_aton(token + 6, bssid))
Hai Shaloma20dcd72022-02-04 13:43:00 -080011138 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080011139 got_bssid = 1;
11140 } else if (os_strcmp(token, "akmp=PASN") == 0) {
11141 akmp = WPA_KEY_MGMT_PASN;
11142#ifdef CONFIG_IEEE80211R
11143 } else if (os_strcmp(token, "akmp=FT-PSK") == 0) {
11144 akmp = WPA_KEY_MGMT_FT_PSK;
11145 } else if (os_strcmp(token, "akmp=FT-EAP-SHA384") == 0) {
11146 akmp = WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
11147 } else if (os_strcmp(token, "akmp=FT-EAP") == 0) {
11148 akmp = WPA_KEY_MGMT_FT_IEEE8021X;
11149#endif /* CONFIG_IEEE80211R */
11150#ifdef CONFIG_SAE
11151 } else if (os_strcmp(token, "akmp=SAE") == 0) {
11152 akmp = WPA_KEY_MGMT_SAE;
Sunil Ravi89eba102022-09-13 21:04:37 -070011153 } else if (os_strcmp(token, "akmp=SAE-EXT-KEY") == 0) {
11154 akmp = WPA_KEY_MGMT_SAE_EXT_KEY;
Hai Shalom60840252021-02-19 19:02:11 -080011155#endif /* CONFIG_SAE */
11156#ifdef CONFIG_FILS
11157 } else if (os_strcmp(token, "akmp=FILS-SHA256") == 0) {
11158 akmp = WPA_KEY_MGMT_FILS_SHA256;
11159 } else if (os_strcmp(token, "akmp=FILS-SHA384") == 0) {
11160 akmp = WPA_KEY_MGMT_FILS_SHA384;
11161#endif /* CONFIG_FILS */
11162 } else if (os_strcmp(token, "cipher=CCMP-256") == 0) {
11163 cipher = WPA_CIPHER_CCMP_256;
11164 } else if (os_strcmp(token, "cipher=GCMP-256") == 0) {
11165 cipher = WPA_CIPHER_GCMP_256;
11166 } else if (os_strcmp(token, "cipher=CCMP") == 0) {
11167 cipher = WPA_CIPHER_CCMP;
11168 } else if (os_strcmp(token, "cipher=GCMP") == 0) {
11169 cipher = WPA_CIPHER_GCMP;
11170 } else if (os_strncmp(token, "group=", 6) == 0) {
11171 group = atoi(token + 6);
11172 } else if (os_strncmp(token, "nid=", 4) == 0) {
11173 id = atoi(token + 4);
Hai Shaloma20dcd72022-02-04 13:43:00 -080011174 } else if (os_strncmp(token, "comeback=", 9) == 0) {
11175 comeback_len = os_strlen(token + 9);
11176 if (comeback || !comeback_len || comeback_len % 2)
11177 goto out;
11178
11179 comeback_len /= 2;
11180 comeback = os_malloc(comeback_len);
11181 if (!comeback ||
11182 hexstr2bin(token + 9, comeback, comeback_len))
11183 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080011184 } else {
11185 wpa_printf(MSG_DEBUG,
11186 "CTRL: PASN Invalid parameter: '%s'",
11187 token);
Hai Shaloma20dcd72022-02-04 13:43:00 -080011188 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080011189 }
11190 }
11191
11192 if (!got_bssid || akmp == -1 || cipher == -1 || group == 0xFFFF) {
11193 wpa_printf(MSG_DEBUG,"CTRL: PASN missing parameter");
Hai Shaloma20dcd72022-02-04 13:43:00 -080011194 goto out;
11195 }
11196
Sunil Ravi89eba102022-09-13 21:04:37 -070011197 ret = wpas_pasn_auth_start(wpa_s, wpa_s->own_addr, bssid, akmp, cipher,
11198 group, id, comeback, comeback_len);
Hai Shaloma20dcd72022-02-04 13:43:00 -080011199out:
11200 os_free(comeback);
11201 return ret;
11202}
11203
11204
11205static int wpas_ctrl_iface_pasn_deauthenticate(struct wpa_supplicant *wpa_s,
11206 const char *cmd)
11207{
11208 u8 bssid[ETH_ALEN];
11209
11210 if (os_strncmp(cmd, "bssid=", 6) != 0 || hwaddr_aton(cmd + 6, bssid)) {
11211 wpa_printf(MSG_DEBUG,
11212 "CTRL: PASN_DEAUTH without valid BSSID");
Hai Shalom60840252021-02-19 19:02:11 -080011213 return -1;
11214 }
11215
Sunil Ravi89eba102022-09-13 21:04:37 -070011216 return wpas_pasn_deauthenticate(wpa_s, wpa_s->own_addr, bssid);
Hai Shalom60840252021-02-19 19:02:11 -080011217}
Hai Shaloma20dcd72022-02-04 13:43:00 -080011218
Hai Shalom60840252021-02-19 19:02:11 -080011219#endif /* CONFIG_PASN */
11220
11221
Hai Shaloma20dcd72022-02-04 13:43:00 -080011222static int set_type4_frame_classifier(const char *cmd,
11223 struct type4_params *param)
11224{
11225 const char *pos, *end;
11226 u8 classifier_mask = 0;
11227 int ret;
11228 char addr[INET6_ADDRSTRLEN];
11229 size_t alen;
11230
11231 if (os_strstr(cmd, "ip_version=ipv4")) {
11232 param->ip_version = IPV4;
11233 } else if (os_strstr(cmd, "ip_version=ipv6")) {
11234 param->ip_version = IPV6;
11235 } else {
11236 wpa_printf(MSG_ERROR, "IP version missing/invalid");
11237 return -1;
11238 }
11239
11240 classifier_mask |= BIT(0);
11241
11242 pos = os_strstr(cmd, "src_ip=");
11243 if (pos) {
11244 pos += 7;
11245 end = os_strchr(pos, ' ');
11246 if (!end)
11247 end = pos + os_strlen(pos);
11248
11249 alen = end - pos;
11250 if (alen >= INET6_ADDRSTRLEN)
11251 return -1;
11252 os_memcpy(addr, pos, alen);
11253 addr[alen] = '\0';
11254 if (param->ip_version == IPV4)
11255 ret = inet_pton(AF_INET, addr,
11256 &param->ip_params.v4.src_ip);
11257 else
11258 ret = inet_pton(AF_INET6, addr,
11259 &param->ip_params.v6.src_ip);
11260
11261 if (ret != 1) {
11262 wpa_printf(MSG_ERROR,
11263 "Error converting src IP address to binary ret=%d",
11264 ret);
11265 return -1;
11266 }
11267
11268 classifier_mask |= BIT(1);
11269 }
11270
11271 pos = os_strstr(cmd, "dst_ip=");
11272 if (pos) {
11273 pos += 7;
11274 end = os_strchr(pos, ' ');
11275 if (!end)
11276 end = pos + os_strlen(pos);
11277
11278 alen = end - pos;
11279 if (alen >= INET6_ADDRSTRLEN)
11280 return -1;
11281 os_memcpy(addr, pos, alen);
11282 addr[alen] = '\0';
11283 if (param->ip_version == IPV4)
11284 ret = inet_pton(AF_INET, addr,
11285 &param->ip_params.v4.dst_ip);
11286 else
11287 ret = inet_pton(AF_INET6, addr,
11288 &param->ip_params.v6.dst_ip);
11289
11290 if (ret != 1) {
11291 wpa_printf(MSG_ERROR,
11292 "Error converting dst IP address to binary ret=%d",
11293 ret);
11294 return -1;
11295 }
11296
11297 classifier_mask |= BIT(2);
11298 }
11299
11300 pos = os_strstr(cmd, "src_port=");
11301 if (pos && atoi(pos + 9) > 0) {
11302 if (param->ip_version == IPV4)
11303 param->ip_params.v4.src_port = atoi(pos + 9);
11304 else
11305 param->ip_params.v6.src_port = atoi(pos + 9);
11306 classifier_mask |= BIT(3);
11307 }
11308
11309 pos = os_strstr(cmd, "dst_port=");
11310 if (pos && atoi(pos + 9) > 0) {
11311 if (param->ip_version == IPV4)
11312 param->ip_params.v4.dst_port = atoi(pos + 9);
11313 else
11314 param->ip_params.v6.dst_port = atoi(pos + 9);
11315 classifier_mask |= BIT(4);
11316 }
11317
11318 pos = os_strstr(cmd, "dscp=");
11319 if (pos && atoi(pos + 5) > 0) {
11320 if (param->ip_version == IPV4)
11321 param->ip_params.v4.dscp = atoi(pos + 5);
11322 else
11323 param->ip_params.v6.dscp = atoi(pos + 5);
11324 classifier_mask |= BIT(5);
11325 }
11326
11327 if (param->ip_version == IPV4) {
11328 pos = os_strstr(cmd, "protocol=");
11329 if (pos) {
11330 if (os_strstr(pos, "udp")) {
11331 param->ip_params.v4.protocol = 17;
11332 } else if (os_strstr(pos, "tcp")) {
11333 param->ip_params.v4.protocol = 6;
11334 } else if (os_strstr(pos, "esp")) {
11335 param->ip_params.v4.protocol = 50;
11336 } else {
11337 wpa_printf(MSG_ERROR, "Invalid protocol");
11338 return -1;
11339 }
11340 classifier_mask |= BIT(6);
11341 }
11342 } else {
11343 pos = os_strstr(cmd, "next_header=");
11344 if (pos) {
11345 if (os_strstr(pos, "udp")) {
11346 param->ip_params.v6.next_header = 17;
11347 } else if (os_strstr(pos, "tcp")) {
11348 param->ip_params.v6.next_header = 6;
11349 } else if (os_strstr(pos, "esp")) {
11350 param->ip_params.v6.next_header = 50;
11351 } else {
11352 wpa_printf(MSG_ERROR, "Invalid next header");
11353 return -1;
11354 }
11355
11356 classifier_mask |= BIT(6);
11357 }
11358
11359 pos = os_strstr(cmd, "flow_label=");
11360 if (pos) {
11361 pos += 11;
11362 end = os_strchr(pos, ' ');
11363 if (!end)
11364 end = pos + os_strlen(pos);
11365
11366 if (end - pos != 6 ||
11367 hexstr2bin(pos, param->ip_params.v6.flow_label,
11368 3) ||
11369 param->ip_params.v6.flow_label[0] > 0x0F) {
11370 wpa_printf(MSG_ERROR, "Invalid flow label");
11371 return -1;
11372 }
11373
11374 classifier_mask |= BIT(7);
11375 }
11376 }
11377
11378 param->classifier_mask = classifier_mask;
11379 return 0;
11380}
11381
11382
11383static int set_type10_frame_classifier(const char *cmd,
11384 struct type10_params *param)
11385{
11386 const char *pos, *end;
11387 size_t filter_len;
11388
11389 pos = os_strstr(cmd, "prot_instance=");
11390 if (!pos) {
11391 wpa_printf(MSG_ERROR, "Protocol instance missing");
11392 return -1;
11393 }
11394 param->prot_instance = atoi(pos + 14);
11395
11396 pos = os_strstr(cmd, "prot_number=");
11397 if (!pos) {
11398 wpa_printf(MSG_ERROR, "Protocol number missing");
11399 return -1;
11400 }
11401 if (os_strstr(pos, "udp")) {
11402 param->prot_number = 17;
11403 } else if (os_strstr(pos, "tcp")) {
11404 param->prot_number = 6;
11405 } else if (os_strstr(pos, "esp")) {
11406 param->prot_number = 50;
11407 } else {
11408 wpa_printf(MSG_ERROR, "Invalid protocol number");
11409 return -1;
11410 }
11411
11412 pos = os_strstr(cmd, "filter_value=");
11413 if (!pos) {
11414 wpa_printf(MSG_ERROR,
11415 "Classifier parameter filter_value missing");
11416 return -1;
11417 }
11418
11419 pos += 13;
11420 end = os_strchr(pos, ' ');
11421 if (!end)
11422 end = pos + os_strlen(pos);
11423
11424 filter_len = (end - pos) / 2;
11425 param->filter_value = os_malloc(filter_len);
11426 if (!param->filter_value)
11427 return -1;
11428
11429 if (hexstr2bin(pos, param->filter_value, filter_len)) {
11430 wpa_printf(MSG_ERROR, "Invalid filter_value %s", pos);
11431 goto free;
11432 }
11433
11434 pos = os_strstr(cmd, "filter_mask=");
11435 if (!pos) {
11436 wpa_printf(MSG_ERROR,
11437 "Classifier parameter filter_mask missing");
11438 goto free;
11439 }
11440
11441 pos += 12;
11442 end = os_strchr(pos, ' ');
11443 if (!end)
11444 end = pos + os_strlen(pos);
11445
11446 if (filter_len != (size_t) (end - pos) / 2) {
11447 wpa_printf(MSG_ERROR,
11448 "Filter mask length mismatch expected=%zu received=%zu",
11449 filter_len, (size_t) (end - pos) / 2);
11450 goto free;
11451 }
11452
11453 param->filter_mask = os_malloc(filter_len);
11454 if (!param->filter_mask)
11455 goto free;
11456
11457 if (hexstr2bin(pos, param->filter_mask, filter_len)) {
11458 wpa_printf(MSG_ERROR, "Invalid filter mask %s", pos);
11459 os_free(param->filter_mask);
11460 param->filter_mask = NULL;
11461 goto free;
11462 }
11463
11464 param->filter_len = filter_len;
11465 return 0;
11466free:
11467 os_free(param->filter_value);
11468 param->filter_value = NULL;
11469 return -1;
11470}
11471
11472
11473static int scs_parse_type4(struct tclas_element *elem, const char *pos)
11474{
11475 struct type4_params type4_param = { 0 };
11476
11477 if (set_type4_frame_classifier(pos, &type4_param) == -1) {
11478 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 4");
11479 return -1;
11480 }
11481
11482 os_memcpy(&elem->frame_classifier.type4_param,
11483 &type4_param, sizeof(struct type4_params));
11484 return 0;
11485}
11486
11487
11488static int scs_parse_type10(struct tclas_element *elem, const char *pos)
11489{
11490 struct type10_params type10_param = { 0 };
11491
11492 if (set_type10_frame_classifier(pos, &type10_param) == -1) {
11493 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 10");
11494 return -1;
11495 }
11496
11497 os_memcpy(&elem->frame_classifier.type10_param,
11498 &type10_param, sizeof(struct type10_params));
11499 return 0;
11500}
11501
11502
11503static int wpas_ctrl_iface_configure_scs(struct wpa_supplicant *wpa_s,
11504 char *cmd)
11505{
11506 char *pos1, *pos;
11507 struct scs_robust_av_data *scs_data = &wpa_s->scs_robust_av_req;
11508 struct scs_desc_elem desc_elem = { 0 };
11509 int val;
11510 unsigned int num_scs_desc = 0;
11511
11512 if (wpa_s->ongoing_scs_req) {
11513 wpa_printf(MSG_ERROR, "%s: SCS Request already in queue",
11514 __func__);
11515 return -1;
11516 }
11517
11518 /**
11519 * format:
11520 * [scs_id=<decimal number>] <add|remove|change> [scs_up=<0-7>]
11521 * [classifier_type=<4|10>]
11522 * [classifier params based on classifier type]
11523 * [tclas_processing=<0|1>] [scs_id=<decimal number>] ...
11524 */
11525 pos1 = os_strstr(cmd, "scs_id=");
11526 if (!pos1) {
11527 wpa_printf(MSG_ERROR, "SCSID not present");
11528 return -1;
11529 }
11530
11531 free_up_scs_desc(scs_data);
11532
11533 while (pos1) {
11534 struct scs_desc_elem *n1;
11535 struct active_scs_elem *active_scs_desc;
11536 char *next_scs_desc;
11537 unsigned int num_tclas_elem = 0;
11538 bool scsid_active = false;
11539
11540 desc_elem.scs_id = atoi(pos1 + 7);
11541 pos1 += 7;
11542
11543 next_scs_desc = os_strstr(pos1, "scs_id=");
11544 if (next_scs_desc) {
11545 char temp[20];
11546
11547 os_snprintf(temp, sizeof(temp), "scs_id=%d ",
11548 desc_elem.scs_id);
11549 if (os_strstr(next_scs_desc, temp)) {
11550 wpa_printf(MSG_ERROR,
11551 "Multiple SCS descriptors configured with same SCSID(=%d)",
11552 desc_elem.scs_id);
11553 goto free_scs_desc;
11554 }
11555 pos1[next_scs_desc - pos1 - 1] = '\0';
11556 }
11557
11558 dl_list_for_each(active_scs_desc, &wpa_s->active_scs_ids,
11559 struct active_scs_elem, list) {
11560 if (desc_elem.scs_id == active_scs_desc->scs_id) {
11561 scsid_active = true;
11562 break;
11563 }
11564 }
11565
11566 if (os_strstr(pos1, "add ")) {
11567 desc_elem.request_type = SCS_REQ_ADD;
11568 if (scsid_active) {
11569 wpa_printf(MSG_ERROR, "SCSID %d already active",
11570 desc_elem.scs_id);
11571 return -1;
11572 }
11573 } else if (os_strstr(pos1, "remove")) {
11574 desc_elem.request_type = SCS_REQ_REMOVE;
11575 if (!scsid_active) {
11576 wpa_printf(MSG_ERROR, "SCSID %d not active",
11577 desc_elem.scs_id);
11578 return -1;
11579 }
11580 goto scs_desc_end;
11581 } else if (os_strstr(pos1, "change ")) {
11582 desc_elem.request_type = SCS_REQ_CHANGE;
11583 if (!scsid_active) {
11584 wpa_printf(MSG_ERROR, "SCSID %d not active",
11585 desc_elem.scs_id);
11586 return -1;
11587 }
11588 } else {
11589 wpa_printf(MSG_ERROR, "SCS Request type invalid");
11590 goto free_scs_desc;
11591 }
11592
11593 pos1 = os_strstr(pos1, "scs_up=");
11594 if (!pos1) {
11595 wpa_printf(MSG_ERROR,
11596 "Intra-Access user priority not present");
11597 goto free_scs_desc;
11598 }
11599
11600 val = atoi(pos1 + 7);
11601 if (val < 0 || val > 7) {
11602 wpa_printf(MSG_ERROR,
11603 "Intra-Access user priority invalid %d",
11604 val);
11605 goto free_scs_desc;
11606 }
11607
11608 desc_elem.intra_access_priority = val;
11609 desc_elem.scs_up_avail = true;
11610
11611 pos = os_strstr(pos1, "classifier_type=");
11612 if (!pos) {
11613 wpa_printf(MSG_ERROR, "classifier type empty");
11614 goto free_scs_desc;
11615 }
11616
11617 while (pos) {
11618 struct tclas_element elem = { 0 }, *n;
11619 char *next_tclas_elem;
11620
11621 val = atoi(pos + 16);
11622 if (val != 4 && val != 10) {
11623 wpa_printf(MSG_ERROR,
11624 "classifier type invalid %d", val);
11625 goto free_scs_desc;
11626 }
11627
11628 elem.classifier_type = val;
11629 pos += 16;
11630
11631 next_tclas_elem = os_strstr(pos, "classifier_type=");
11632 if (next_tclas_elem) {
11633 pos1 = next_tclas_elem;
11634 pos[next_tclas_elem - pos - 1] = '\0';
11635 }
11636
11637 switch (val) {
11638 case 4:
11639 if (scs_parse_type4(&elem, pos) < 0)
11640 goto free_scs_desc;
11641 break;
11642 case 10:
11643 if (scs_parse_type10(&elem, pos) < 0)
11644 goto free_scs_desc;
11645 break;
11646 }
11647
11648 n = os_realloc(desc_elem.tclas_elems,
11649 (num_tclas_elem + 1) * sizeof(elem));
11650 if (!n)
11651 goto free_scs_desc;
11652
11653 desc_elem.tclas_elems = n;
11654 os_memcpy((u8 *) desc_elem.tclas_elems +
11655 num_tclas_elem * sizeof(elem),
11656 &elem, sizeof(elem));
11657 num_tclas_elem++;
11658 desc_elem.num_tclas_elem = num_tclas_elem;
11659 pos = next_tclas_elem;
11660 }
11661
11662 if (desc_elem.num_tclas_elem > 1) {
11663 pos1 = os_strstr(pos1, "tclas_processing=");
11664 if (!pos1) {
11665 wpa_printf(MSG_ERROR, "tclas_processing empty");
11666 goto free_scs_desc;
11667 }
11668
11669 val = atoi(pos1 + 17);
11670 if (val != 0 && val != 1) {
11671 wpa_printf(MSG_ERROR,
11672 "tclas_processing invalid");
11673 goto free_scs_desc;
11674 }
11675
11676 desc_elem.tclas_processing = val;
11677 }
11678
11679scs_desc_end:
11680 n1 = os_realloc(scs_data->scs_desc_elems, (num_scs_desc + 1) *
11681 sizeof(struct scs_desc_elem));
11682 if (!n1)
11683 goto free_scs_desc;
11684
11685 scs_data->scs_desc_elems = n1;
11686 os_memcpy((u8 *) scs_data->scs_desc_elems + num_scs_desc *
11687 sizeof(desc_elem), &desc_elem, sizeof(desc_elem));
11688 num_scs_desc++;
11689 scs_data->num_scs_desc = num_scs_desc;
11690 pos1 = next_scs_desc;
11691 os_memset(&desc_elem, 0, sizeof(desc_elem));
11692 }
11693
11694 return wpas_send_scs_req(wpa_s);
11695
11696free_scs_desc:
11697 free_up_tclas_elem(&desc_elem);
11698 free_up_scs_desc(scs_data);
11699 return -1;
11700}
11701
11702
11703static int wpas_ctrl_iface_send_dscp_resp(struct wpa_supplicant *wpa_s,
11704 const char *cmd)
11705{
11706 char *pos;
11707 struct dscp_policy_status *policy = NULL, *n;
11708 int num_policies = 0, ret = -1;
11709 struct dscp_resp_data resp_data;
11710
11711 /*
11712 * format:
11713 * <[reset]>/<[solicited] [policy_id=1 status=0...]> [more]
11714 */
11715
11716 os_memset(&resp_data, 0, sizeof(resp_data));
11717
11718 resp_data.more = os_strstr(cmd, "more") != NULL;
11719
11720 if (os_strstr(cmd, "reset")) {
11721 resp_data.reset = true;
11722 resp_data.solicited = false;
11723 goto send_resp;
11724 }
11725
11726 resp_data.solicited = os_strstr(cmd, "solicited") != NULL;
11727
11728 pos = os_strstr(cmd, "policy_id=");
11729 while (pos) {
11730 n = os_realloc(policy, (num_policies + 1) * sizeof(*policy));
11731 if (!n)
11732 goto fail;
11733
11734 policy = n;
11735 pos += 10;
11736 policy[num_policies].id = atoi(pos);
11737 if (policy[num_policies].id == 0) {
11738 wpa_printf(MSG_ERROR, "DSCP: Invalid policy id");
11739 goto fail;
11740 }
11741
11742 pos = os_strstr(pos, "status=");
11743 if (!pos) {
11744 wpa_printf(MSG_ERROR,
11745 "DSCP: Status is not found for a policy");
11746 goto fail;
11747 }
11748
11749 pos += 7;
11750 policy[num_policies].status = atoi(pos);
11751 num_policies++;
11752
11753 pos = os_strstr(pos, "policy_id");
11754 }
11755
11756 resp_data.policy = policy;
11757 resp_data.num_policies = num_policies;
11758send_resp:
11759 ret = wpas_send_dscp_response(wpa_s, &resp_data);
11760 if (ret)
11761 wpa_printf(MSG_ERROR, "DSCP: Failed to send DSCP response");
11762fail:
11763 os_free(policy);
11764 return ret;
11765}
11766
11767
11768static int wpas_ctrl_iface_send_dscp_query(struct wpa_supplicant *wpa_s,
11769 const char *cmd)
11770{
11771 char *pos;
11772
11773 /*
11774 * format:
11775 * Wildcard DSCP query
11776 * <wildcard>
11777 *
11778 * DSCP query with a domain name attribute:
11779 * [domain_name=<string>]
11780 */
11781
11782 if (os_strstr(cmd, "wildcard")) {
11783 wpa_printf(MSG_DEBUG, "QM: Send wildcard DSCP policy query");
11784 return wpas_send_dscp_query(wpa_s, NULL, 0);
11785 }
11786
11787 pos = os_strstr(cmd, "domain_name=");
11788 if (!pos || !os_strlen(pos + 12)) {
11789 wpa_printf(MSG_ERROR, "QM: Domain name not preset");
11790 return -1;
11791 }
11792
11793 return wpas_send_dscp_query(wpa_s, pos + 12, os_strlen(pos + 12));
11794}
11795
11796
Sunil Ravi89eba102022-09-13 21:04:37 -070011797static int wpas_ctrl_iface_mlo_signal_poll(struct wpa_supplicant *wpa_s,
11798 char *buf, size_t buflen)
11799{
11800 int ret, i;
11801 char *pos, *end;
11802 struct wpa_mlo_signal_info mlo_si;
11803
11804 if (!wpa_s->valid_links)
11805 return -1;
11806
11807 ret = wpa_drv_mlo_signal_poll(wpa_s, &mlo_si);
11808 if (ret)
11809 return -1;
11810
11811 pos = buf;
11812 end = buf + buflen;
11813
11814 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
11815 if (!(mlo_si.valid_links & BIT(i)))
11816 continue;
11817
11818 ret = os_snprintf(pos, end - pos,
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000011819 "LINK_ID=%d\nRSSI=%d\nLINKSPEED=%lu\n"
Sunil Ravi89eba102022-09-13 21:04:37 -070011820 "NOISE=%d\nFREQUENCY=%u\n",
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000011821 i, mlo_si.links[i].data.signal,
11822 mlo_si.links[i].data.current_tx_rate / 1000,
Sunil Ravi89eba102022-09-13 21:04:37 -070011823 mlo_si.links[i].current_noise,
11824 mlo_si.links[i].frequency);
11825 if (os_snprintf_error(end - pos, ret))
11826 return -1;
11827 pos += ret;
11828
11829 if (mlo_si.links[i].chanwidth != CHAN_WIDTH_UNKNOWN) {
11830 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
11831 channel_width_to_string(
11832 mlo_si.links[i].chanwidth));
11833 if (os_snprintf_error(end - pos, ret))
11834 return -1;
11835 pos += ret;
11836 }
11837
11838 if (mlo_si.links[i].center_frq1 > 0) {
11839 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
11840 mlo_si.links[i].center_frq1);
11841 if (os_snprintf_error(end - pos, ret))
11842 return -1;
11843 pos += ret;
11844 }
11845
11846 if (mlo_si.links[i].center_frq2 > 0) {
11847 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
11848 mlo_si.links[i].center_frq2);
11849 if (os_snprintf_error(end - pos, ret))
11850 return -1;
11851 pos += ret;
11852 }
11853
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000011854 if (mlo_si.links[i].data.avg_signal) {
Sunil Ravi89eba102022-09-13 21:04:37 -070011855 ret = os_snprintf(pos, end - pos,
11856 "AVG_RSSI=%d\n",
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000011857 mlo_si.links[i].data.avg_signal);
Sunil Ravi89eba102022-09-13 21:04:37 -070011858 if (os_snprintf_error(end - pos, ret))
11859 return -1;
11860 pos += ret;
11861 }
11862
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000011863 if (mlo_si.links[i].data.avg_beacon_signal) {
11864 ret = os_snprintf(
11865 pos, end - pos, "AVG_BEACON_RSSI=%d\n",
11866 mlo_si.links[i].data.avg_beacon_signal);
Sunil Ravi89eba102022-09-13 21:04:37 -070011867 if (os_snprintf_error(end - pos, ret))
11868 return -1;
11869 pos += ret;
11870 }
11871 }
11872
11873 return pos - buf;
11874}
11875
11876
11877static int wpas_ctrl_iface_mlo_status(struct wpa_supplicant *wpa_s,
11878 char *buf, size_t buflen)
11879{
11880 int ret, i;
11881 char *pos, *end;
11882
11883 if (!wpa_s->valid_links)
11884 return -1;
11885
11886 pos = buf;
11887 end = buf + buflen;
11888
11889 for (i = 0; i < MAX_NUM_MLD_LINKS; i++) {
11890 if (!(wpa_s->valid_links & BIT(i)))
11891 continue;
11892
11893 ret = os_snprintf(pos, end - pos, "link_id=%d\nfreq=%u\n"
11894 "ap_link_addr=" MACSTR
11895 "\nsta_link_addr=" MACSTR "\n",
11896 i, wpa_s->links[i].freq,
11897 MAC2STR(wpa_s->links[i].bssid),
11898 MAC2STR(wpa_s->links[i].addr));
11899 if (os_snprintf_error(end - pos, ret))
11900 return pos - buf;
11901 pos += ret;
11902 }
11903
11904 return pos - buf;
11905}
11906
11907
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011908char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
11909 char *buf, size_t *resp_len)
11910{
11911 char *reply;
11912 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011913 int reply_len;
11914
11915 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011916 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
11917 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
11918 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011919 if (wpa_debug_show_keys)
11920 wpa_dbg(wpa_s, MSG_DEBUG,
11921 "Control interface command '%s'", buf);
11922 else
11923 wpa_dbg(wpa_s, MSG_DEBUG,
11924 "Control interface command '%s [REMOVED]'",
11925 os_strncmp(buf, WPA_CTRL_RSP,
11926 os_strlen(WPA_CTRL_RSP)) == 0 ?
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011927 WPA_CTRL_RSP :
11928 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
11929 "SET_NETWORK" : "key-add"));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011930 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
Dmitry Shmidt21de2142014-04-08 10:50:52 -070011931 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011932 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
11933 (const u8 *) buf, os_strlen(buf));
11934 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011935 int level = wpas_ctrl_cmd_debug_level(buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -070011936 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011937 }
11938
11939 reply = os_malloc(reply_size);
11940 if (reply == NULL) {
11941 *resp_len = 1;
11942 return NULL;
11943 }
11944
11945 os_memcpy(reply, "OK\n", 3);
11946 reply_len = 3;
11947
11948 if (os_strcmp(buf, "PING") == 0) {
11949 os_memcpy(reply, "PONG\n", 5);
11950 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070011951 } else if (os_strcmp(buf, "IFNAME") == 0) {
11952 reply_len = os_strlen(wpa_s->ifname);
11953 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011954 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
11955 if (wpa_debug_reopen_file() < 0)
11956 reply_len = -1;
11957 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
11958 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
11959 } else if (os_strcmp(buf, "MIB") == 0) {
11960 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
11961 if (reply_len >= 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011962 reply_len += eapol_sm_get_mib(wpa_s->eapol,
11963 reply + reply_len,
11964 reply_size - reply_len);
Hai Shalom74f70d42019-02-11 14:42:39 -080011965#ifdef CONFIG_MACSEC
11966 reply_len += ieee802_1x_kay_get_mib(
11967 wpa_s->kay, reply + reply_len,
11968 reply_size - reply_len);
11969#endif /* CONFIG_MACSEC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011970 }
11971 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
11972 reply_len = wpa_supplicant_ctrl_iface_status(
11973 wpa_s, buf + 6, reply, reply_size);
11974 } else if (os_strcmp(buf, "PMKSA") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070011975 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011976 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070011977 wpas_ctrl_iface_pmksa_flush(wpa_s);
Dmitry Shmidt29333592017-01-09 12:27:11 -080011978#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
11979 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
11980 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
11981 reply, reply_size);
11982 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
11983 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
11984 reply_len = -1;
Paul Stewart092955c2017-02-06 09:13:09 -080011985#ifdef CONFIG_MESH
11986 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
11987 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
11988 reply, reply_size);
11989 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
11990 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
11991 reply_len = -1;
11992#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080011993#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011994 } else if (os_strncmp(buf, "SET ", 4) == 0) {
11995 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
11996 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080011997 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
11998 reply_len = wpa_config_dump_values(wpa_s->conf,
11999 reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012000 } else if (os_strncmp(buf, "GET ", 4) == 0) {
12001 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
12002 reply, reply_size);
12003 } else if (os_strcmp(buf, "LOGON") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070012004 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012005 } else if (os_strcmp(buf, "LOGOFF") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070012006 eapol_sm_notify_logoff(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012007 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
12008 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
12009 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012010 else
12011 wpas_request_connection(wpa_s);
Dmitry Shmidt98660862014-03-11 17:26:21 -070012012 } else if (os_strcmp(buf, "REATTACH") == 0) {
12013 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
12014 !wpa_s->current_ssid)
12015 reply_len = -1;
12016 else {
12017 wpa_s->reattach = 1;
12018 wpas_request_connection(wpa_s);
12019 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012020 } else if (os_strcmp(buf, "RECONNECT") == 0) {
12021 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
12022 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012023 else if (wpa_s->disconnected)
12024 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012025#ifdef IEEE8021X_EAPOL
12026 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
12027 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
12028 reply_len = -1;
12029#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012030#ifdef CONFIG_IEEE80211R
12031 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
12032 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
12033 reply_len = -1;
12034#endif /* CONFIG_IEEE80211R */
12035#ifdef CONFIG_WPS
12036 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
12037 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
12038 if (res == -2) {
12039 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12040 reply_len = 17;
12041 } else if (res)
12042 reply_len = -1;
12043 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
12044 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
12045 if (res == -2) {
12046 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12047 reply_len = 17;
12048 } else if (res)
12049 reply_len = -1;
12050 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
12051 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
12052 reply,
12053 reply_size);
12054 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
12055 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
12056 wpa_s, buf + 14, reply, reply_size);
12057 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
12058 if (wpas_wps_cancel(wpa_s))
12059 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012060#ifdef CONFIG_WPS_NFC
12061 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
12062 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
12063 reply_len = -1;
12064 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
12065 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
12066 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -080012067 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
12068 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
12069 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012070 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
12071 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
12072 wpa_s, buf + 14, reply, reply_size);
12073 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
12074 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
12075 buf + 17))
12076 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012077 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
12078 reply_len = wpas_ctrl_nfc_get_handover_req(
12079 wpa_s, buf + 21, reply, reply_size);
12080 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
12081 reply_len = wpas_ctrl_nfc_get_handover_sel(
12082 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -080012083 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
12084 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
12085 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012086#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012087 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
12088 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
12089 reply_len = -1;
12090#ifdef CONFIG_AP
12091 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
12092 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
12093 wpa_s, buf + 11, reply, reply_size);
12094#endif /* CONFIG_AP */
12095#ifdef CONFIG_WPS_ER
12096 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
12097 if (wpas_wps_er_start(wpa_s, NULL))
12098 reply_len = -1;
12099 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
12100 if (wpas_wps_er_start(wpa_s, buf + 13))
12101 reply_len = -1;
12102 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012103 wpas_wps_er_stop(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012104 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
12105 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
12106 reply_len = -1;
12107 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
12108 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
12109 if (ret == -2) {
12110 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
12111 reply_len = 17;
12112 } else if (ret == -3) {
12113 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
12114 reply_len = 18;
12115 } else if (ret == -4) {
12116 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
12117 reply_len = 20;
12118 } else if (ret)
12119 reply_len = -1;
12120 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
12121 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
12122 reply_len = -1;
12123 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
12124 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
12125 buf + 18))
12126 reply_len = -1;
12127 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
12128 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
12129 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012130#ifdef CONFIG_WPS_NFC
12131 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
12132 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
12133 wpa_s, buf + 24, reply, reply_size);
12134#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012135#endif /* CONFIG_WPS_ER */
12136#endif /* CONFIG_WPS */
12137#ifdef CONFIG_IBSS_RSN
12138 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
12139 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
12140 reply_len = -1;
12141#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012142#ifdef CONFIG_MESH
12143 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
12144 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
12145 wpa_s, buf + 19, reply, reply_size);
12146 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
12147 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
12148 wpa_s, "", reply, reply_size);
12149 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
12150 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
12151 reply_len = -1;
12152 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
12153 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
12154 buf + 18))
12155 reply_len = -1;
Dmitry Shmidte4663042016-04-04 10:07:49 -070012156 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
12157 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
12158 reply_len = -1;
12159 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
12160 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
12161 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070012162 } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) {
12163 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16))
12164 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012165#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012166#ifdef CONFIG_P2P
12167 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012168 if (p2p_ctrl_find(wpa_s, buf + 8))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012169 reply_len = -1;
12170 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
12171 if (p2p_ctrl_find(wpa_s, ""))
12172 reply_len = -1;
12173 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
12174 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012175 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
12176 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
12177 reply_len = -1;
12178 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
12179 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
12180 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012181 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
12182 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
12183 reply_size);
12184 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
12185 if (p2p_ctrl_listen(wpa_s, buf + 11))
12186 reply_len = -1;
12187 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
12188 if (p2p_ctrl_listen(wpa_s, ""))
12189 reply_len = -1;
12190 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
12191 if (wpas_p2p_group_remove(wpa_s, buf + 17))
12192 reply_len = -1;
12193 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070012194 if (p2p_ctrl_group_add(wpa_s, ""))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012195 reply_len = -1;
12196 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
12197 if (p2p_ctrl_group_add(wpa_s, buf + 14))
12198 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070012199 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
12200 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
12201 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012202 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
12203 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
12204 reply_len = -1;
12205 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
12206 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
12207 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
12208 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
12209 reply_size);
12210 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
12211 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
12212 reply_len = -1;
12213 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
12214 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
12215 reply_len = -1;
12216 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
12217 wpas_p2p_sd_service_update(wpa_s);
12218 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
12219 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
12220 reply_len = -1;
12221 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
12222 wpas_p2p_service_flush(wpa_s);
12223 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
12224 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
12225 reply_len = -1;
12226 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
12227 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
12228 reply_len = -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012229 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
12230 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
12231 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012232 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
12233 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
12234 reply_len = -1;
12235 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
12236 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
12237 reply_len = -1;
12238 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
12239 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
12240 reply_size);
12241 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
12242 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
12243 reply_len = -1;
12244 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -070012245 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012246 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
12247 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
12248 reply_len = -1;
12249 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
12250 if (wpas_p2p_cancel(wpa_s))
12251 reply_len = -1;
12252 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
12253 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
12254 reply_len = -1;
12255 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
12256 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
12257 reply_len = -1;
12258 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
12259 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
12260 reply_len = -1;
12261 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
12262 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
12263 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070012264 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
12265 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
12266 reply_len = -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070012267 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
12268 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
12269 reply_len = -1;
12270 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
12271 if (wpas_p2p_lo_stop(wpa_s))
12272 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012273#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070012274#ifdef CONFIG_WIFI_DISPLAY
12275 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
12276 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
12277 reply_len = -1;
12278 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
12279 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
12280 reply, reply_size);
12281#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012282#ifdef CONFIG_INTERWORKING
12283 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
12284 if (interworking_fetch_anqp(wpa_s) < 0)
12285 reply_len = -1;
12286 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
12287 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012288 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
12289 if (ctrl_interworking_select(wpa_s, NULL) < 0)
12290 reply_len = -1;
12291 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
12292 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012293 reply_len = -1;
12294 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012295 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012296 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012297 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
12298 int id;
12299
12300 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
12301 if (id < 0)
12302 reply_len = -1;
12303 else {
12304 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
12305 if (os_snprintf_error(reply_size, reply_len))
12306 reply_len = -1;
12307 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012308 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
12309 if (get_anqp(wpa_s, buf + 9) < 0)
12310 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070012311 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
12312 if (gas_request(wpa_s, buf + 12) < 0)
12313 reply_len = -1;
12314 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
12315 reply_len = gas_response_get(wpa_s, buf + 17, reply,
12316 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012317#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -070012318#ifdef CONFIG_HS20
12319 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
12320 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
12321 reply_len = -1;
12322 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
12323 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
12324 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080012325 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080012326 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
12327 reply_len = -1;
12328 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
12329 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
12330 reply_len = -1;
12331 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
12332 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
12333 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
12334 if (del_hs20_icon(wpa_s, buf + 14) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080012335 reply_len = -1;
12336 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070012337 if (hs20_fetch_osu(wpa_s, 0) < 0)
12338 reply_len = -1;
12339 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
12340 if (hs20_fetch_osu(wpa_s, 1) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080012341 reply_len = -1;
12342 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
12343 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012344#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012345 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
12346 {
12347 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
12348 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
12349 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -070012350 else {
12351 /*
12352 * Notify response from timeout to allow the control
12353 * interface response to be sent first.
12354 */
12355 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
12356 wpa_s, NULL);
12357 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012358 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
12359 if (wpa_supplicant_reload_configuration(wpa_s))
12360 reply_len = -1;
12361 } else if (os_strcmp(buf, "TERMINATE") == 0) {
12362 wpa_supplicant_terminate_proc(wpa_s->global);
12363 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
12364 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
12365 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080012366 } else if (os_strncmp(buf, "BSSID_IGNORE", 12) == 0) {
12367 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
12368 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidte19501d2011-03-16 14:32:18 -070012369 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -080012370 /* deprecated backwards compatibility alias for BSSID_IGNORE */
12371 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012372 wpa_s, buf + 9, reply, reply_size);
12373 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
12374 reply_len = wpa_supplicant_ctrl_iface_log_level(
12375 wpa_s, buf + 9, reply, reply_size);
Vinit Deshpandeda134e92014-12-02 10:59:29 -080012376 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
12377 reply_len = wpa_supplicant_ctrl_iface_list_networks(
12378 wpa_s, buf + 14, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012379 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
12380 reply_len = wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -080012381 wpa_s, NULL, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012382 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070012383 wpas_request_disconnection(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012384 } else if (os_strcmp(buf, "SCAN") == 0) {
12385 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
12386 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
12387 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012388 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
12389 reply_len = wpa_supplicant_ctrl_iface_scan_results(
12390 wpa_s, reply, reply_size);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080012391 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
12392 if (wpas_abort_ongoing_scan(wpa_s) < 0)
12393 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012394 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
12395 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
12396 reply_len = -1;
12397 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
12398 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
12399 reply_len = -1;
12400 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
12401 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
12402 reply_len = -1;
12403 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
12404 reply_len = wpa_supplicant_ctrl_iface_add_network(
12405 wpa_s, reply, reply_size);
12406 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
12407 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
12408 reply_len = -1;
12409 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
12410 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
12411 reply_len = -1;
12412 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
12413 reply_len = wpa_supplicant_ctrl_iface_get_network(
12414 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt684785c2014-05-12 13:34:29 -070012415 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012416 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
12417 wpa_s))
Dmitry Shmidt684785c2014-05-12 13:34:29 -070012418 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070012419 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
12420 reply_len = wpa_supplicant_ctrl_iface_list_creds(
12421 wpa_s, reply, reply_size);
12422 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
12423 reply_len = wpa_supplicant_ctrl_iface_add_cred(
12424 wpa_s, reply, reply_size);
12425 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
12426 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
12427 reply_len = -1;
12428 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
12429 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
12430 reply_len = -1;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -070012431 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
12432 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
12433 reply,
12434 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012435#ifndef CONFIG_NO_CONFIG_WRITE
12436 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
12437 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
12438 reply_len = -1;
12439#endif /* CONFIG_NO_CONFIG_WRITE */
12440 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
12441 reply_len = wpa_supplicant_ctrl_iface_get_capability(
12442 wpa_s, buf + 15, reply, reply_size);
12443 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
12444 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
12445 reply_len = -1;
12446 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
12447 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
12448 reply_len = -1;
12449 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
12450 reply_len = wpa_supplicant_global_iface_list(
12451 wpa_s->global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080012452 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012453 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080012454 wpa_s->global, buf + 10, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012455 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
12456 reply_len = wpa_supplicant_ctrl_iface_bss(
12457 wpa_s, buf + 4, reply, reply_size);
12458#ifdef CONFIG_AP
12459 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
12460 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
12461 } else if (os_strncmp(buf, "STA ", 4) == 0) {
12462 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
12463 reply_size);
12464 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
12465 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
12466 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012467 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
12468 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
12469 reply_len = -1;
12470 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
12471 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
12472 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080012473 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
12474 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
12475 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012476 } else if (os_strcmp(buf, "STOP_AP") == 0) {
12477 if (wpas_ap_stop_ap(wpa_s))
12478 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080012479 } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) {
12480 if (wpas_ap_update_beacon(wpa_s))
12481 reply_len = -1;
Sunil Ravia04bd252022-05-02 22:54:18 -070012482 } else if (os_strncmp(buf, "ACCEPT_ACL ", 11) == 0) {
12483 if (os_strncmp(buf + 11, "ADD_MAC ", 8) == 0) {
12484 if (ap_ctrl_iface_acl_add_mac(wpa_s,
12485 DENY_UNLESS_ACCEPTED,
12486 buf + 19) ||
12487 ap_ctrl_iface_set_acl(wpa_s))
12488 reply_len = -1;
12489 } else if (os_strncmp((buf + 11), "DEL_MAC ", 8) == 0) {
12490 if (ap_ctrl_iface_acl_del_mac(wpa_s,
12491 DENY_UNLESS_ACCEPTED,
12492 buf + 19) ||
12493 ap_ctrl_iface_set_acl(wpa_s) ||
12494 ap_ctrl_iface_disassoc_accept_mac(wpa_s))
12495 reply_len = -1;
12496 } else if (os_strcmp(buf + 11, "SHOW") == 0) {
12497 reply_len = ap_ctrl_iface_acl_show_mac(
12498 wpa_s, DENY_UNLESS_ACCEPTED,
12499 reply, reply_size);
12500 } else if (os_strcmp(buf + 11, "CLEAR") == 0) {
12501 ap_ctrl_iface_acl_clear_list(wpa_s,
12502 DENY_UNLESS_ACCEPTED);
12503 if (ap_ctrl_iface_set_acl(wpa_s) ||
12504 ap_ctrl_iface_disassoc_accept_mac(wpa_s))
12505 reply_len = -1;
12506 } else {
12507 reply_len = -1;
12508 }
12509 } else if (os_strncmp(buf, "DENY_ACL ", 9) == 0) {
12510 if (os_strncmp(buf + 9, "ADD_MAC ", 8) == 0) {
12511 if (ap_ctrl_iface_acl_add_mac(wpa_s,
12512 ACCEPT_UNLESS_DENIED,
12513 buf + 17) ||
12514 ap_ctrl_iface_set_acl(wpa_s) ||
12515 ap_ctrl_iface_disassoc_deny_mac(wpa_s))
12516 reply_len = -1;
12517 } else if (os_strncmp(buf + 9, "DEL_MAC ", 8) == 0) {
12518 if (ap_ctrl_iface_acl_del_mac(wpa_s,
12519 ACCEPT_UNLESS_DENIED,
12520 buf + 17) ||
12521 ap_ctrl_iface_set_acl(wpa_s))
12522 reply_len = -1;
12523 } else if (os_strcmp(buf + 9, "SHOW") == 0) {
12524 reply_len = ap_ctrl_iface_acl_show_mac(
12525 wpa_s, ACCEPT_UNLESS_DENIED, reply, reply_size);
12526 } else if (os_strcmp(buf + 9, "CLEAR") == 0) {
12527 ap_ctrl_iface_acl_clear_list(wpa_s,
12528 ACCEPT_UNLESS_DENIED);
12529 if (ap_ctrl_iface_set_acl(wpa_s))
12530 reply_len = -1;
12531 } else {
12532 reply_len = -1;
12533 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012534#endif /* CONFIG_AP */
12535 } else if (os_strcmp(buf, "SUSPEND") == 0) {
12536 wpas_notify_suspend(wpa_s->global);
12537 } else if (os_strcmp(buf, "RESUME") == 0) {
12538 wpas_notify_resume(wpa_s->global);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070012539#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012540 } else if (os_strcmp(buf, "DROP_SA") == 0) {
12541 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070012542#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012543 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
12544 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
12545 reply_len = -1;
12546 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012547 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012548 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
12549 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
12550 reply_len = -1;
12551 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
12552 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
12553 buf + 17))
12554 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -070012555 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012556 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012557#ifdef CONFIG_TDLS
12558 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
12559 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
12560 reply_len = -1;
12561 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
12562 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
12563 reply_len = -1;
12564 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
12565 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
12566 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012567 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
12568 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
12569 buf + 17))
12570 reply_len = -1;
12571 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
12572 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
12573 buf + 24))
12574 reply_len = -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -070012575 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
12576 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
12577 wpa_s, buf + 17, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012578#endif /* CONFIG_TDLS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012579 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
12580 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
12581 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
12582 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
12583 reply_len = -1;
12584 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
12585 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
12586 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012587 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
12588 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
12589 reply_size);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080012590 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
12591 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
12592 reply_len = -1;
Yuhao Zhengfcd6f212012-07-27 10:37:52 -070012593 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
12594 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
12595 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012596#ifdef CONFIG_AUTOSCAN
12597 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
12598 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
12599 reply_len = -1;
12600#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070012601 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
12602 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
12603 reply_size);
Hai Shalomb755a2a2020-04-23 21:49:02 -070012604 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
12605 reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply,
12606 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080012607#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -070012608 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
12609 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
12610 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080012611#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080012612 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
12613 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
12614 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012615 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012616 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012617 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080012618#ifdef CONFIG_WNM
12619 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
12620 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
12621 reply_len = -1;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080012622 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
12623 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
Dmitry Shmidt44c95782013-05-17 09:51:35 -070012624 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -080012625 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
12626 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
12627 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080012628#endif /* CONFIG_WNM */
Sunil Ravia04bd252022-05-02 22:54:18 -070012629#ifdef CONFIG_WNM_AP
12630 } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
12631 if (ap_ctrl_iface_disassoc_imminent(wpa_s, buf + 18))
12632 reply_len = -1;
12633 } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
12634 if (ap_ctrl_iface_ess_disassoc(wpa_s, buf + 13))
12635 reply_len = -1;
12636 } else if (os_strncmp(buf, "BSS_TM_REQ ", 11) == 0) {
12637 if (ap_ctrl_iface_bss_tm_req(wpa_s, buf + 11))
12638 reply_len = -1;
12639#endif /* CONFIG_WNM_AP */
Dmitry Shmidt444d5672013-04-01 13:08:44 -070012640 } else if (os_strcmp(buf, "FLUSH") == 0) {
12641 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012642 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
12643 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
12644 reply_size);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070012645#ifdef CONFIG_TESTING_OPTIONS
12646 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
12647 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
12648 reply_len = -1;
12649 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
12650 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070012651 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
12652 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
12653 reply_len = -1;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -070012654 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
12655 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
12656 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012657 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
12658 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
12659 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080012660 } else if (os_strncmp(buf, "EAPOL_TX ", 9) == 0) {
12661 if (wpas_ctrl_iface_eapol_tx(wpa_s, buf + 9) < 0)
12662 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012663 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
12664 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
12665 reply_len = -1;
12666 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
12667 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
12668 reply_len = -1;
12669 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
12670 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
12671 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -080012672 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
12673 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
12674 reply_len = -1;
12675 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
12676 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012677 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
12678 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
12679 reply_len = -1;
12680 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
12681 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
Jouni Malinenc4818362015-10-04 11:45:13 +030012682 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
12683 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
12684 reply_len = -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080012685 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
12686 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
12687 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012688 } else if (os_strcmp(buf, "RESET_PN") == 0) {
12689 if (wpas_ctrl_reset_pn(wpa_s) < 0)
12690 reply_len = -1;
12691 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
12692 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
12693 reply_len = -1;
12694 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
12695 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
12696 reply_len = -1;
Hai Shalom74f70d42019-02-11 14:42:39 -080012697 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
12698 sme_event_unprot_disconnect(
12699 wpa_s, wpa_s->bssid, NULL,
12700 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
Hai Shaloma20dcd72022-02-04 13:43:00 -080012701 } else if (os_strncmp(buf, "TWT_SETUP ", 10) == 0) {
12702 if (wpas_ctrl_iface_send_twt_setup(wpa_s, buf + 9))
12703 reply_len = -1;
12704 } else if (os_strcmp(buf, "TWT_SETUP") == 0) {
12705 if (wpas_ctrl_iface_send_twt_setup(wpa_s, ""))
12706 reply_len = -1;
12707 } else if (os_strncmp(buf, "TWT_TEARDOWN ", 13) == 0) {
12708 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, buf + 12))
12709 reply_len = -1;
12710 } else if (os_strcmp(buf, "TWT_TEARDOWN") == 0) {
12711 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, ""))
12712 reply_len = -1;
Dmitry Shmidt818ea482014-03-10 13:15:21 -070012713#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070012714 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
12715 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
12716 reply_len = -1;
12717 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
12718 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
12719 reply_size);
12720 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
12721 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
12722 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012723 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -070012724 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012725 reply_len = -1;
12726 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
12727 wpas_ctrl_iface_erp_flush(wpa_s);
12728 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
12729 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
12730 reply_len = -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012731 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
12732 reply_len = wpas_ctrl_iface_get_pref_freq_list(
12733 wpa_s, buf + 19, reply, reply_size);
Paul Stewart092955c2017-02-06 09:13:09 -080012734#ifdef CONFIG_FILS
12735 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
12736 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
12737 reply_len = -1;
12738 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
12739 wpas_flush_fils_hlp_req(wpa_s);
12740#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012741#ifdef CONFIG_DPP
12742 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
12743 int res;
12744
12745 res = wpas_dpp_qr_code(wpa_s, buf + 12);
12746 if (res < 0) {
12747 reply_len = -1;
12748 } else {
12749 reply_len = os_snprintf(reply, reply_size, "%d", res);
12750 if (os_snprintf_error(reply_size, reply_len))
12751 reply_len = -1;
12752 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080012753 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
12754 int res;
12755
12756 res = wpas_dpp_nfc_uri(wpa_s, buf + 12);
12757 if (res < 0) {
12758 reply_len = -1;
12759 } else {
12760 reply_len = os_snprintf(reply, reply_size, "%d", res);
12761 if (os_snprintf_error(reply_size, reply_len))
12762 reply_len = -1;
12763 }
Hai Shalomfdcde762020-04-02 11:19:20 -070012764 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
12765 int res;
12766
12767 res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20);
12768 if (res < 0) {
12769 reply_len = -1;
12770 } else {
12771 reply_len = os_snprintf(reply, reply_size, "%d", res);
12772 if (os_snprintf_error(reply_size, reply_len))
12773 reply_len = -1;
12774 }
12775 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
12776 int res;
12777
12778 res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20);
12779 if (res < 0) {
12780 reply_len = -1;
12781 } else {
12782 reply_len = os_snprintf(reply, reply_size, "%d", res);
12783 if (os_snprintf_error(reply_size, reply_len))
12784 reply_len = -1;
12785 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012786 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
12787 int res;
12788
Hai Shalom021b0b52019-04-10 11:17:58 -070012789 res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012790 if (res < 0) {
12791 reply_len = -1;
12792 } else {
12793 reply_len = os_snprintf(reply, reply_size, "%d", res);
12794 if (os_snprintf_error(reply_size, reply_len))
12795 reply_len = -1;
12796 }
12797 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070012798 if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012799 reply_len = -1;
12800 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
12801 const char *uri;
12802
Hai Shalom021b0b52019-04-10 11:17:58 -070012803 uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012804 if (!uri) {
12805 reply_len = -1;
12806 } else {
12807 reply_len = os_snprintf(reply, reply_size, "%s", uri);
12808 if (os_snprintf_error(reply_size, reply_len))
12809 reply_len = -1;
12810 }
12811 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070012812 reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19),
12813 reply, reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -070012814 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
12815 if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18),
12816 os_strchr(buf + 18, ' ')) < 0)
12817 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012818 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
12819 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
12820 reply_len = -1;
12821 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
12822 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
12823 reply_len = -1;
12824 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -070012825 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012826 wpas_dpp_listen_stop(wpa_s);
12827 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
12828 int res;
12829
Hai Shalom021b0b52019-04-10 11:17:58 -070012830 res = dpp_configurator_add(wpa_s->dpp, buf + 20);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012831 if (res < 0) {
12832 reply_len = -1;
12833 } else {
12834 reply_len = os_snprintf(reply, reply_size, "%d", res);
12835 if (os_snprintf_error(reply_size, reply_len))
12836 reply_len = -1;
12837 }
Sunil Ravia04bd252022-05-02 22:54:18 -070012838 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SET ", 21) == 0) {
12839 if (dpp_configurator_set(wpa_s->dpp, buf + 20) < 0)
12840 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012841 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070012842 if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012843 reply_len = -1;
12844 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -080012845 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012846 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -070012847 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070012848 reply_len = dpp_configurator_get_key_id(wpa_s->dpp,
12849 atoi(buf + 25),
12850 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012851 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
12852 int res;
12853
12854 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
12855 if (res < 0) {
12856 reply_len = -1;
12857 } else {
12858 reply_len = os_snprintf(reply, reply_size, "%d", res);
12859 if (os_snprintf_error(reply_size, reply_len))
12860 reply_len = -1;
12861 }
12862 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
12863 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
12864 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080012865 } else if (os_strncmp(buf, "DPP_CONF_SET ", 13) == 0) {
12866 if (wpas_dpp_conf_set(wpa_s, buf + 12) < 0)
12867 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070012868#ifdef CONFIG_DPP2
12869 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
12870 if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0)
12871 reply_len = -1;
12872 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
12873 if (wpas_dpp_controller_start(wpa_s, NULL) < 0)
12874 reply_len = -1;
12875 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
12876 dpp_controller_stop(wpa_s->dpp);
Hai Shalomfdcde762020-04-02 11:19:20 -070012877 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
12878 if (wpas_dpp_chirp(wpa_s, buf + 9) < 0)
12879 reply_len = -1;
12880 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
12881 wpas_dpp_chirp_stop(wpa_s);
Hai Shalom4fbc08f2020-05-18 12:37:00 -070012882 } else if (os_strncmp(buf, "DPP_RECONFIG ", 13) == 0) {
Hai Shalom899fcc72020-10-19 14:38:18 -070012883 if (wpas_dpp_reconfig(wpa_s, buf + 13) < 0)
12884 reply_len = -1;
12885 } else if (os_strncmp(buf, "DPP_CA_SET ", 11) == 0) {
12886 if (wpas_dpp_ca_set(wpa_s, buf + 10) < 0)
Hai Shalom4fbc08f2020-05-18 12:37:00 -070012887 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070012888#endif /* CONFIG_DPP2 */
Sunil Ravi89eba102022-09-13 21:04:37 -070012889#ifdef CONFIG_DPP3
12890 } else if (os_strcmp(buf, "DPP_PUSH_BUTTON") == 0) {
12891 if (wpas_dpp_push_button(wpa_s, NULL) < 0)
12892 reply_len = -1;
12893 } else if (os_strncmp(buf, "DPP_PUSH_BUTTON ", 16) == 0) {
12894 if (wpas_dpp_push_button(wpa_s, buf + 15) < 0)
12895 reply_len = -1;
12896#endif /* CONFIG_DPP3 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012897#endif /* CONFIG_DPP */
Hai Shalom899fcc72020-10-19 14:38:18 -070012898 } else if (os_strncmp(buf, "MSCS ", 5) == 0) {
12899 if (wpas_ctrl_iface_configure_mscs(wpa_s, buf + 5))
12900 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080012901#ifdef CONFIG_PASN
12902 } else if (os_strncmp(buf, "PASN_START ", 11) == 0) {
12903 if (wpas_ctrl_iface_pasn_start(wpa_s, buf + 11) < 0)
12904 reply_len = -1;
12905 } else if (os_strcmp(buf, "PASN_STOP") == 0) {
12906 wpas_pasn_auth_stop(wpa_s);
12907 } else if (os_strcmp(buf, "PTKSA_CACHE_LIST") == 0) {
12908 reply_len = ptksa_cache_list(wpa_s->ptksa, reply, reply_size);
Hai Shaloma20dcd72022-02-04 13:43:00 -080012909 } else if (os_strncmp(buf, "PASN_DEAUTH ", 12) == 0) {
12910 if (wpas_ctrl_iface_pasn_deauthenticate(wpa_s, buf + 12) < 0)
12911 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080012912#endif /* CONFIG_PASN */
Hai Shaloma20dcd72022-02-04 13:43:00 -080012913 } else if (os_strncmp(buf, "SCS ", 4) == 0) {
12914 if (wpas_ctrl_iface_configure_scs(wpa_s, buf + 4))
12915 reply_len = -1;
12916 } else if (os_strncmp(buf, "DSCP_RESP ", 10) == 0) {
12917 if (wpas_ctrl_iface_send_dscp_resp(wpa_s, buf + 10))
12918 reply_len = -1;
12919 } else if (os_strncmp(buf, "DSCP_QUERY ", 11) == 0) {
12920 if (wpas_ctrl_iface_send_dscp_query(wpa_s, buf + 11))
12921 reply_len = -1;
Sunil Ravi89eba102022-09-13 21:04:37 -070012922 } else if (os_strcmp(buf, "MLO_STATUS") == 0) {
12923 reply_len = wpas_ctrl_iface_mlo_status(wpa_s, reply,
12924 reply_size);
12925 } else if (os_strcmp(buf, "MLO_SIGNAL_POLL") == 0) {
12926 reply_len = wpas_ctrl_iface_mlo_signal_poll(wpa_s, reply,
12927 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012928 } else {
12929 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
12930 reply_len = 16;
12931 }
12932
12933 if (reply_len < 0) {
12934 os_memcpy(reply, "FAIL\n", 5);
12935 reply_len = 5;
12936 }
12937
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012938 *resp_len = reply_len;
12939 return reply;
12940}
12941
12942
12943static int wpa_supplicant_global_iface_add(struct wpa_global *global,
12944 char *cmd)
12945{
12946 struct wpa_interface iface;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070012947 char *pos, *extra;
12948 struct wpa_supplicant *wpa_s;
12949 unsigned int create_iface = 0;
12950 u8 mac_addr[ETH_ALEN];
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080012951 enum wpa_driver_if_type type = WPA_IF_STATION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012952
12953 /*
12954 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080012955 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012956 */
12957 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
12958
12959 os_memset(&iface, 0, sizeof(iface));
12960
12961 do {
12962 iface.ifname = pos = cmd;
12963 pos = os_strchr(pos, '\t');
12964 if (pos)
12965 *pos++ = '\0';
12966 if (iface.ifname[0] == '\0')
12967 return -1;
12968 if (pos == NULL)
12969 break;
12970
12971 iface.confname = pos;
12972 pos = os_strchr(pos, '\t');
12973 if (pos)
12974 *pos++ = '\0';
12975 if (iface.confname[0] == '\0')
12976 iface.confname = NULL;
12977 if (pos == NULL)
12978 break;
12979
12980 iface.driver = pos;
12981 pos = os_strchr(pos, '\t');
12982 if (pos)
12983 *pos++ = '\0';
12984 if (iface.driver[0] == '\0')
12985 iface.driver = NULL;
12986 if (pos == NULL)
12987 break;
12988
12989 iface.ctrl_interface = pos;
12990 pos = os_strchr(pos, '\t');
12991 if (pos)
12992 *pos++ = '\0';
12993 if (iface.ctrl_interface[0] == '\0')
12994 iface.ctrl_interface = NULL;
12995 if (pos == NULL)
12996 break;
12997
12998 iface.driver_param = pos;
12999 pos = os_strchr(pos, '\t');
13000 if (pos)
13001 *pos++ = '\0';
13002 if (iface.driver_param[0] == '\0')
13003 iface.driver_param = NULL;
13004 if (pos == NULL)
13005 break;
13006
13007 iface.bridge_ifname = pos;
13008 pos = os_strchr(pos, '\t');
13009 if (pos)
13010 *pos++ = '\0';
13011 if (iface.bridge_ifname[0] == '\0')
13012 iface.bridge_ifname = NULL;
13013 if (pos == NULL)
13014 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013015
13016 extra = pos;
13017 pos = os_strchr(pos, '\t');
13018 if (pos)
13019 *pos++ = '\0';
Dmitry Shmidt83474442015-04-15 13:47:09 -070013020 if (!extra[0])
13021 break;
13022
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013023 if (os_strcmp(extra, "create") == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013024 create_iface = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013025 if (!pos)
13026 break;
13027
13028 if (os_strcmp(pos, "sta") == 0) {
13029 type = WPA_IF_STATION;
13030 } else if (os_strcmp(pos, "ap") == 0) {
13031 type = WPA_IF_AP_BSS;
13032 } else {
13033 wpa_printf(MSG_DEBUG,
13034 "INTERFACE_ADD unsupported interface type: '%s'",
13035 pos);
13036 return -1;
13037 }
13038 } else {
Dmitry Shmidt83474442015-04-15 13:47:09 -070013039 wpa_printf(MSG_DEBUG,
13040 "INTERFACE_ADD unsupported extra parameter: '%s'",
13041 extra);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013042 return -1;
Dmitry Shmidt83474442015-04-15 13:47:09 -070013043 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013044 } while (0);
13045
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013046 if (create_iface) {
13047 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
13048 iface.ifname);
13049 if (!global->ifaces)
13050 return -1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080013051 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013052 NULL, NULL, NULL, mac_addr, NULL) < 0) {
13053 wpa_printf(MSG_ERROR,
13054 "CTRL_IFACE interface creation failed");
13055 return -1;
13056 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013057
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013058 wpa_printf(MSG_DEBUG,
13059 "CTRL_IFACE interface '%s' created with MAC addr: "
13060 MACSTR, iface.ifname, MAC2STR(mac_addr));
13061 }
13062
13063 if (wpa_supplicant_get_iface(global, iface.ifname))
13064 goto fail;
13065
13066 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
13067 if (!wpa_s)
13068 goto fail;
13069 wpa_s->added_vif = create_iface;
13070 return 0;
13071
13072fail:
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000013073 if (create_iface) {
13074 /* wpa_supplicant does not create multi-BSS AP, so collapse to
13075 * WPA_IF_STATION to avoid unwanted clean up in the driver. */
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013076 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000013077 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013078 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013079}
13080
13081
13082static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
13083 char *cmd)
13084{
13085 struct wpa_supplicant *wpa_s;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013086 int ret;
13087 unsigned int delete_iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013088
13089 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
13090
13091 wpa_s = wpa_supplicant_get_iface(global, cmd);
13092 if (wpa_s == NULL)
13093 return -1;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013094 delete_iface = wpa_s->added_vif;
13095 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
13096 if (!ret && delete_iface) {
13097 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
13098 cmd);
Sunil Ravi38ad1ed2023-01-17 23:58:31 +000013099 /* wpa_supplicant does not create multi-BSS AP, so collapse to
13100 * WPA_IF_STATION to avoid unwanted clean up in the driver. */
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070013101 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
13102 }
13103 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013104}
13105
13106
13107static void wpa_free_iface_info(struct wpa_interface_info *iface)
13108{
13109 struct wpa_interface_info *prev;
13110
13111 while (iface) {
13112 prev = iface;
13113 iface = iface->next;
13114
13115 os_free(prev->ifname);
13116 os_free(prev->desc);
13117 os_free(prev);
13118 }
13119}
13120
13121
13122static int wpa_supplicant_global_iface_list(struct wpa_global *global,
13123 char *buf, int len)
13124{
13125 int i, res;
13126 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
13127 char *pos, *end;
13128
13129 for (i = 0; wpa_drivers[i]; i++) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070013130 const struct wpa_driver_ops *drv = wpa_drivers[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013131 if (drv->get_interfaces == NULL)
13132 continue;
13133 tmp = drv->get_interfaces(global->drv_priv[i]);
13134 if (tmp == NULL)
13135 continue;
13136
13137 if (last == NULL)
13138 iface = last = tmp;
13139 else
13140 last->next = tmp;
13141 while (last->next)
13142 last = last->next;
13143 }
13144
13145 pos = buf;
13146 end = buf + len;
13147 for (tmp = iface; tmp; tmp = tmp->next) {
13148 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
13149 tmp->drv_name, tmp->ifname,
13150 tmp->desc ? tmp->desc : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013151 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013152 *pos = '\0';
13153 break;
13154 }
13155 pos += res;
13156 }
13157
13158 wpa_free_iface_info(iface);
13159
13160 return pos - buf;
13161}
13162
13163
13164static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013165 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013166 char *buf, int len)
13167{
13168 int res;
13169 char *pos, *end;
13170 struct wpa_supplicant *wpa_s;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013171 int show_ctrl = 0;
13172
13173 if (input)
13174 show_ctrl = !!os_strstr(input, "ctrl");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013175
13176 wpa_s = global->ifaces;
13177 pos = buf;
13178 end = buf + len;
13179
13180 while (wpa_s) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013181 if (show_ctrl)
13182 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
13183 wpa_s->ifname,
13184 wpa_s->conf->ctrl_interface ?
13185 wpa_s->conf->ctrl_interface : "N/A");
13186 else
13187 res = os_snprintf(pos, end - pos, "%s\n",
13188 wpa_s->ifname);
13189
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013190 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013191 *pos = '\0';
13192 break;
13193 }
13194 pos += res;
13195 wpa_s = wpa_s->next;
13196 }
13197 return pos - buf;
13198}
13199
13200
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013201static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
13202 const char *ifname,
13203 char *cmd, size_t *resp_len)
13204{
13205 struct wpa_supplicant *wpa_s;
13206
13207 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
13208 if (os_strcmp(ifname, wpa_s->ifname) == 0)
13209 break;
13210 }
13211
13212 if (wpa_s == NULL) {
13213 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
13214 if (resp)
13215 *resp_len = os_strlen(resp);
13216 else
13217 *resp_len = 1;
13218 return resp;
13219 }
13220
13221 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
13222}
13223
13224
13225static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
13226 char *buf, size_t *resp_len)
13227{
13228#ifdef CONFIG_P2P
13229 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070013230 "LIST_NETWORKS",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013231 "P2P_FIND",
13232 "P2P_STOP_FIND",
13233 "P2P_LISTEN",
13234 "P2P_GROUP_ADD",
13235 "P2P_GET_PASSPHRASE",
13236 "P2P_SERVICE_UPDATE",
13237 "P2P_SERVICE_FLUSH",
13238 "P2P_FLUSH",
13239 "P2P_CANCEL",
13240 "P2P_PRESENCE_REQ",
13241 "P2P_EXT_LISTEN",
Paul Stewart092955c2017-02-06 09:13:09 -080013242#ifdef CONFIG_AP
13243 "STA-FIRST",
13244#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013245 NULL
13246 };
13247 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080013248#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070013249 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080013250#endif /* ANDROID */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070013251 "GET_CAPABILITY ",
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070013252 "GET_NETWORK ",
13253 "REMOVE_NETWORK ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013254 "P2P_FIND ",
13255 "P2P_CONNECT ",
13256 "P2P_LISTEN ",
13257 "P2P_GROUP_REMOVE ",
13258 "P2P_GROUP_ADD ",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070013259 "P2P_GROUP_MEMBER ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013260 "P2P_PROV_DISC ",
13261 "P2P_SERV_DISC_REQ ",
13262 "P2P_SERV_DISC_CANCEL_REQ ",
13263 "P2P_SERV_DISC_RESP ",
13264 "P2P_SERV_DISC_EXTERNAL ",
13265 "P2P_SERVICE_ADD ",
13266 "P2P_SERVICE_DEL ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080013267 "P2P_SERVICE_REP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013268 "P2P_REJECT ",
13269 "P2P_INVITE ",
13270 "P2P_PEER ",
13271 "P2P_SET ",
13272 "P2P_UNAUTHORIZE ",
13273 "P2P_PRESENCE_REQ ",
13274 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070013275 "P2P_REMOVE_CLIENT ",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080013276 "WPS_NFC_TOKEN ",
13277 "WPS_NFC_TAG_READ ",
Dmitry Shmidt413dde72014-04-11 10:23:22 -070013278 "NFC_GET_HANDOVER_SEL ",
13279 "NFC_GET_HANDOVER_REQ ",
13280 "NFC_REPORT_HANDOVER ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080013281 "P2P_ASP_PROVISION ",
13282 "P2P_ASP_PROVISION_RESP ",
Paul Stewart092955c2017-02-06 09:13:09 -080013283#ifdef CONFIG_AP
13284 "STA ",
13285 "STA-NEXT ",
13286#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013287 NULL
13288 };
13289 int found = 0;
13290 int i;
13291
13292 if (global->p2p_init_wpa_s == NULL)
13293 return NULL;
13294
13295 for (i = 0; !found && cmd[i]; i++) {
13296 if (os_strcmp(buf, cmd[i]) == 0)
13297 found = 1;
13298 }
13299
13300 for (i = 0; !found && prefix[i]; i++) {
13301 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
13302 found = 1;
13303 }
13304
13305 if (found)
13306 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
13307 buf, resp_len);
13308#endif /* CONFIG_P2P */
13309 return NULL;
13310}
13311
13312
13313static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
13314 char *buf, size_t *resp_len)
13315{
13316#ifdef CONFIG_WIFI_DISPLAY
13317 if (global->p2p_init_wpa_s == NULL)
13318 return NULL;
13319 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
13320 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
13321 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
13322 buf, resp_len);
13323#endif /* CONFIG_WIFI_DISPLAY */
13324 return NULL;
13325}
13326
13327
13328static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
13329 char *buf, size_t *resp_len)
13330{
13331 char *ret;
13332
13333 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
13334 if (ret)
13335 return ret;
13336
13337 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
13338 if (ret)
13339 return ret;
13340
13341 return NULL;
13342}
13343
13344
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013345static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
13346{
13347 char *value;
13348
13349 value = os_strchr(cmd, ' ');
13350 if (value == NULL)
13351 return -1;
13352 *value++ = '\0';
13353
13354 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
13355
13356#ifdef CONFIG_WIFI_DISPLAY
13357 if (os_strcasecmp(cmd, "wifi_display") == 0) {
13358 wifi_display_enable(global, !!atoi(value));
13359 return 0;
13360 }
13361#endif /* CONFIG_WIFI_DISPLAY */
13362
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013363 /* Restore cmd to its original value to allow redirection */
13364 value[-1] = ' ';
13365
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013366 return -1;
13367}
13368
13369
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013370static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
13371 char *cmd)
13372{
13373 struct wpa_supplicant *wpa_s[2]; /* src, dst */
13374 char *p;
13375 unsigned int i;
13376
13377 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
13378 * <variable name> */
13379
13380 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
13381 p = os_strchr(cmd, ' ');
13382 if (p == NULL)
13383 return -1;
13384 *p = '\0';
13385
13386 wpa_s[i] = global->ifaces;
13387 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
13388 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
13389 break;
13390 }
13391
13392 if (!wpa_s[i]) {
13393 wpa_printf(MSG_DEBUG,
13394 "CTRL_IFACE: Could not find iface=%s", cmd);
13395 return -1;
13396 }
13397
13398 cmd = p + 1;
13399 }
13400
13401 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
13402}
13403
13404
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013405#ifndef CONFIG_NO_CONFIG_WRITE
13406static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
13407{
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013408 int ret = 0, saved = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013409 struct wpa_supplicant *wpa_s;
13410
13411 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
13412 if (!wpa_s->conf->update_config) {
13413 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
13414 continue;
13415 }
13416
13417 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
13418 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
13419 ret = 1;
13420 } else {
13421 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013422 saved++;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013423 }
13424 }
13425
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013426 if (!saved && !ret) {
13427 wpa_dbg(wpa_s, MSG_DEBUG,
13428 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
13429 ret = 1;
13430 }
13431
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013432 return ret;
13433}
13434#endif /* CONFIG_NO_CONFIG_WRITE */
13435
13436
13437static int wpas_global_ctrl_iface_status(struct wpa_global *global,
13438 char *buf, size_t buflen)
13439{
13440 char *pos, *end;
13441 int ret;
13442 struct wpa_supplicant *wpa_s;
13443
13444 pos = buf;
13445 end = buf + buflen;
13446
13447#ifdef CONFIG_P2P
13448 if (global->p2p && !global->p2p_disabled) {
13449 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
13450 "\n"
13451 "p2p_state=%s\n",
13452 MAC2STR(global->p2p_dev_addr),
13453 p2p_get_state_txt(global->p2p));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013454 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013455 return pos - buf;
13456 pos += ret;
13457 } else if (global->p2p) {
13458 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013459 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013460 return pos - buf;
13461 pos += ret;
13462 }
13463#endif /* CONFIG_P2P */
13464
13465#ifdef CONFIG_WIFI_DISPLAY
13466 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
13467 !!global->wifi_display);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013468 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013469 return pos - buf;
13470 pos += ret;
13471#endif /* CONFIG_WIFI_DISPLAY */
13472
13473 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
13474 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
13475 "address=" MACSTR "\n",
13476 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013477 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013478 return pos - buf;
13479 pos += ret;
13480 }
13481
13482 return pos - buf;
13483}
13484
13485
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013486#ifdef CONFIG_FST
13487
13488static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
13489 char *cmd, char *buf,
13490 size_t reply_size)
13491{
13492 char ifname[IFNAMSIZ + 1];
13493 struct fst_iface_cfg cfg;
13494 struct wpa_supplicant *wpa_s;
13495 struct fst_wpa_obj iface_obj;
13496
13497 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
13498 wpa_s = wpa_supplicant_get_iface(global, ifname);
13499 if (wpa_s) {
13500 if (wpa_s->fst) {
13501 wpa_printf(MSG_INFO, "FST: Already attached");
13502 return -1;
13503 }
13504 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
13505 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
13506 &iface_obj, &cfg);
13507 if (wpa_s->fst)
13508 return os_snprintf(buf, reply_size, "OK\n");
13509 }
13510 }
13511
13512 return -1;
13513}
13514
13515
13516static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
13517 char *cmd, char *buf,
13518 size_t reply_size)
13519{
13520 char ifname[IFNAMSIZ + 1];
13521 struct wpa_supplicant *wpa_s;
13522
13523 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
13524 wpa_s = wpa_supplicant_get_iface(global, ifname);
13525 if (wpa_s) {
13526 if (!fst_iface_detach(ifname)) {
13527 wpa_s->fst = NULL;
13528 return os_snprintf(buf, reply_size, "OK\n");
13529 }
13530 }
13531 }
13532
13533 return -1;
13534}
13535
13536#endif /* CONFIG_FST */
13537
13538
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013539char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
13540 char *buf, size_t *resp_len)
13541{
13542 char *reply;
13543 const int reply_size = 2048;
13544 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080013545 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013546
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013547 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
13548 char *pos = os_strchr(buf + 7, ' ');
13549 if (pos) {
13550 *pos++ = '\0';
13551 return wpas_global_ctrl_iface_ifname(global,
13552 buf + 7, pos,
13553 resp_len);
13554 }
13555 }
13556
13557 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
13558 if (reply)
13559 return reply;
13560
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080013561 if (os_strcmp(buf, "PING") == 0)
13562 level = MSG_EXCESSIVE;
13563 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013564 (const u8 *) buf, os_strlen(buf));
13565
13566 reply = os_malloc(reply_size);
13567 if (reply == NULL) {
13568 *resp_len = 1;
13569 return NULL;
13570 }
13571
13572 os_memcpy(reply, "OK\n", 3);
13573 reply_len = 3;
13574
13575 if (os_strcmp(buf, "PING") == 0) {
13576 os_memcpy(reply, "PONG\n", 5);
13577 reply_len = 5;
13578 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
13579 if (wpa_supplicant_global_iface_add(global, buf + 14))
13580 reply_len = -1;
13581 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
13582 if (wpa_supplicant_global_iface_remove(global, buf + 17))
13583 reply_len = -1;
13584 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
13585 reply_len = wpa_supplicant_global_iface_list(
13586 global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013587 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013588 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013589 global, buf + 10, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013590#ifdef CONFIG_FST
13591 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
13592 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
13593 reply,
13594 reply_size);
13595 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
13596 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
13597 reply,
13598 reply_size);
13599 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
13600 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
13601#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013602 } else if (os_strcmp(buf, "TERMINATE") == 0) {
13603 wpa_supplicant_terminate_proc(global);
13604 } else if (os_strcmp(buf, "SUSPEND") == 0) {
13605 wpas_notify_suspend(global);
13606 } else if (os_strcmp(buf, "RESUME") == 0) {
13607 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013608 } else if (os_strncmp(buf, "SET ", 4) == 0) {
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013609 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
13610#ifdef CONFIG_P2P
13611 if (global->p2p_init_wpa_s) {
13612 os_free(reply);
13613 /* Check if P2P redirection would work for this
13614 * command. */
13615 return wpa_supplicant_ctrl_iface_process(
13616 global->p2p_init_wpa_s,
13617 buf, resp_len);
13618 }
13619#endif /* CONFIG_P2P */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013620 reply_len = -1;
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013621 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013622 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
13623 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
13624 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013625#ifndef CONFIG_NO_CONFIG_WRITE
13626 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
13627 if (wpas_global_ctrl_iface_save_config(global))
13628 reply_len = -1;
13629#endif /* CONFIG_NO_CONFIG_WRITE */
13630 } else if (os_strcmp(buf, "STATUS") == 0) {
13631 reply_len = wpas_global_ctrl_iface_status(global, reply,
13632 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080013633#ifdef CONFIG_MODULE_TESTS
13634 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080013635 if (wpas_module_tests() < 0)
13636 reply_len = -1;
13637#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013638 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
13639 if (wpa_debug_reopen_file() < 0)
13640 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013641 } else {
13642 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
13643 reply_len = 16;
13644 }
13645
13646 if (reply_len < 0) {
13647 os_memcpy(reply, "FAIL\n", 5);
13648 reply_len = 5;
13649 }
13650
13651 *resp_len = reply_len;
13652 return reply;
13653}