blob: dc6c772fab31e4dded767e65ff232030e9689580 [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);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700677 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
678 wpa_s->dpp_init_max_tries = atoi(value);
679 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
680 wpa_s->dpp_init_retry_time = atoi(value);
681 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
682 wpa_s->dpp_resp_wait_time = atoi(value);
683 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
684 wpa_s->dpp_resp_max_tries = atoi(value);
685 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
686 wpa_s->dpp_resp_retry_time = atoi(value);
687#ifdef CONFIG_TESTING_OPTIONS
688 } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
689 if (hwaddr_aton(value, dpp_pkex_own_mac_override))
690 ret = -1;
691 } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
692 if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
693 ret = -1;
694 } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
695 size_t hex_len = os_strlen(value);
696
697 if (hex_len >
698 2 * sizeof(dpp_pkex_ephemeral_key_override))
699 ret = -1;
700 else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
701 hex_len / 2))
702 ret = -1;
703 else
704 dpp_pkex_ephemeral_key_override_len = hex_len / 2;
705 } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) {
706 size_t hex_len = os_strlen(value);
707
708 if (hex_len > 2 * sizeof(dpp_protocol_key_override))
709 ret = -1;
710 else if (hexstr2bin(value, dpp_protocol_key_override,
711 hex_len / 2))
712 ret = -1;
713 else
714 dpp_protocol_key_override_len = hex_len / 2;
715 } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) {
716 size_t hex_len = os_strlen(value);
717
718 if (hex_len > 2 * sizeof(dpp_nonce_override))
719 ret = -1;
720 else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2))
721 ret = -1;
722 else
723 dpp_nonce_override_len = hex_len / 2;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700724 } else if (os_strcasecmp(cmd, "dpp_version_override") == 0) {
725 dpp_version_override = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700726#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700727#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700728#ifdef CONFIG_TESTING_OPTIONS
729 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
730 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800731 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
732 wpa_s->ext_eapol_frame_io = !!atoi(value);
733#ifdef CONFIG_AP
734 if (wpa_s->ap_iface) {
735 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
736 wpa_s->ext_eapol_frame_io;
737 }
738#endif /* CONFIG_AP */
739 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
740 wpa_s->extra_roc_dur = atoi(value);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800741 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
742 wpa_s->test_failure = atoi(value);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800743 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
744 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700745 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
746 wpa_s->ignore_auth_resp = !!atoi(value);
747 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
748 wpa_s->ignore_assoc_disallow = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700749 wpa_drv_ignore_assoc_disallow(wpa_s,
750 wpa_s->ignore_assoc_disallow);
Hai Shalomfdcde762020-04-02 11:19:20 -0700751 } else if (os_strcasecmp(cmd, "disable_sa_query") == 0) {
752 wpa_s->disable_sa_query = !!atoi(value);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800753 } else if (os_strcasecmp(cmd, "ignore_sae_h2e_only") == 0) {
754 wpa_s->ignore_sae_h2e_only = !!atoi(value);
755 } else if (os_strcasecmp(cmd, "extra_sae_rejected_groups") == 0) {
756 char *pos;
757
758 os_free(wpa_s->extra_sae_rejected_groups);
759 wpa_s->extra_sae_rejected_groups = NULL;
760 pos = value;
761 while (pos && pos[0]) {
762 int group;
763
764 group = atoi(pos);
765 wpa_printf(MSG_DEBUG,
766 "TESTING: Extra rejection of SAE group %d",
767 group);
768 if (group)
769 int_array_add_unique(
770 &wpa_s->extra_sae_rejected_groups,
771 group);
772 pos = os_strchr(pos, ' ');
773 if (!pos)
774 break;
775 pos++;
776 }
Hai Shalomb755a2a2020-04-23 21:49:02 -0700777 } else if (os_strcasecmp(cmd, "ft_rsnxe_used") == 0) {
778 wpa_s->ft_rsnxe_used = atoi(value);
Hai Shalom899fcc72020-10-19 14:38:18 -0700779 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol") == 0) {
780 wpa_s->oci_freq_override_eapol = atoi(value);
781 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_req") == 0) {
782 wpa_s->oci_freq_override_saquery_req = atoi(value);
783 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_resp") == 0) {
784 wpa_s->oci_freq_override_saquery_resp = atoi(value);
785 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol_g2") == 0) {
786 wpa_s->oci_freq_override_eapol_g2 = atoi(value);
787 /* Populate value to wpa_sm if already associated. */
788 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_EAPOL_G2,
789 wpa_s->oci_freq_override_eapol_g2);
790 } else if (os_strcasecmp(cmd, "oci_freq_override_ft_assoc") == 0) {
791 wpa_s->oci_freq_override_ft_assoc = atoi(value);
792 /* Populate value to wpa_sm if already associated. */
793 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_FT_ASSOC,
794 wpa_s->oci_freq_override_ft_assoc);
795 } else if (os_strcasecmp(cmd, "oci_freq_override_fils_assoc") == 0) {
796 wpa_s->oci_freq_override_fils_assoc = atoi(value);
797 } else if (os_strcasecmp(cmd, "oci_freq_override_wnm_sleep") == 0) {
798 wpa_s->oci_freq_override_wnm_sleep = atoi(value);
Hai Shalomfdcde762020-04-02 11:19:20 -0700799 } else if (os_strcasecmp(cmd, "rsne_override_eapol") == 0) {
800 wpabuf_free(wpa_s->rsne_override_eapol);
801 if (os_strcmp(value, "NULL") == 0)
802 wpa_s->rsne_override_eapol = NULL;
803 else
804 wpa_s->rsne_override_eapol = wpabuf_parse_bin(value);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800805 } else if (os_strcasecmp(cmd, "rsnxe_override_assoc") == 0) {
806 wpabuf_free(wpa_s->rsnxe_override_assoc);
807 if (os_strcmp(value, "NULL") == 0)
808 wpa_s->rsnxe_override_assoc = NULL;
809 else
810 wpa_s->rsnxe_override_assoc = wpabuf_parse_bin(value);
811 } else if (os_strcasecmp(cmd, "rsnxe_override_eapol") == 0) {
812 wpabuf_free(wpa_s->rsnxe_override_eapol);
813 if (os_strcmp(value, "NULL") == 0)
814 wpa_s->rsnxe_override_eapol = NULL;
815 else
816 wpa_s->rsnxe_override_eapol = wpabuf_parse_bin(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700817 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
818 wpa_s->reject_btm_req_reason = atoi(value);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800819 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
820 os_free(wpa_s->get_pref_freq_list_override);
821 if (!value[0])
822 wpa_s->get_pref_freq_list_override = NULL;
823 else
824 wpa_s->get_pref_freq_list_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700825 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
826 wpabuf_free(wpa_s->sae_commit_override);
827 if (value[0] == '\0')
828 wpa_s->sae_commit_override = NULL;
829 else
830 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
Hai Shalomfdcde762020-04-02 11:19:20 -0700831 } else if (os_strcasecmp(cmd, "driver_signal_override") == 0) {
832 ret = wpas_ctrl_iface_set_dso(wpa_s, value);
Jimmy Chenaace8cd2021-04-13 14:55:52 +0800833 } else if (os_strcasecmp(cmd, "force_hunting_and_pecking_pwe") == 0) {
834 wpa_s->force_hunting_and_pecking_pwe = (atoi(value) != 0) ? 1 : 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800835 } else if (os_strcasecmp(cmd, "disable_scs_support") == 0) {
836 wpa_s->disable_scs_support = !!atoi(value);
837 } else if (os_strcasecmp(cmd, "disable_mscs_support") == 0) {
838 wpa_s->disable_mscs_support = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700839#ifdef CONFIG_DPP
840 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
841 os_free(wpa_s->dpp_config_obj_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700842 if (value[0] == '\0')
843 wpa_s->dpp_config_obj_override = NULL;
844 else
845 wpa_s->dpp_config_obj_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700846 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
847 os_free(wpa_s->dpp_discovery_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700848 if (value[0] == '\0')
849 wpa_s->dpp_discovery_override = NULL;
850 else
851 wpa_s->dpp_discovery_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700852 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
853 os_free(wpa_s->dpp_groups_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700854 if (value[0] == '\0')
855 wpa_s->dpp_groups_override = NULL;
856 else
857 wpa_s->dpp_groups_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700858 } else if (os_strcasecmp(cmd,
859 "dpp_ignore_netaccesskey_mismatch") == 0) {
860 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700861 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
862 dpp_test = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700863#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700864#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700865#ifdef CONFIG_FILS
866 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
867 wpa_s->disable_fils = !!atoi(value);
868 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
869 wpa_supplicant_set_default_scan_ies(wpa_s);
870#endif /* CONFIG_FILS */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700871#ifndef CONFIG_NO_CONFIG_BLOBS
872 } else if (os_strcmp(cmd, "blob") == 0) {
873 ret = wpas_ctrl_set_blob(wpa_s, value);
874#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800875 } else if (os_strcasecmp(cmd, "setband") == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700876 ret = wpas_ctrl_set_band(wpa_s, value);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800877#ifdef CONFIG_MBO
878 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
879 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
Paul Stewart092955c2017-02-06 09:13:09 -0800880 if (ret == 0) {
881 value[-1] = '=';
882 wpa_config_process_global(wpa_s->conf, cmd, -1);
883 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800884 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
885 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700886 } else if (os_strcasecmp(cmd, "oce") == 0) {
887 wpa_s->conf->oce = atoi(value);
888 if (wpa_s->conf->oce) {
889 if ((wpa_s->conf->oce & OCE_STA) &&
890 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
891 wpa_s->enable_oce = OCE_STA;
892
893 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
894 (wpa_s->drv_flags &
895 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
896 /* TODO: Need to add STA-CFON support */
897 wpa_printf(MSG_ERROR,
898 "OCE STA-CFON feature is not yet supported");
899 return -1;
900 }
901 } else {
902 wpa_s->enable_oce = 0;
903 }
904 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800905#endif /* CONFIG_MBO */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700906 } else if (os_strcasecmp(cmd, "lci") == 0) {
907 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800908 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
909 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800910 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
911 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
912 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
913 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
914 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
915 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700916 } else if (os_strcasecmp(cmd, "roaming") == 0) {
917 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800918#ifdef CONFIG_WNM
919 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
920 struct wpabuf *elems;
921
922 elems = wpabuf_parse_bin(value);
923 if (!elems)
924 return -1;
925 wnm_set_coloc_intf_elems(wpa_s, elems);
926#endif /* CONFIG_WNM */
Hai Shaloma20dcd72022-02-04 13:43:00 -0800927 } else if (os_strcasecmp(cmd, "enable_dscp_policy_capa") == 0) {
928 wpa_s->enable_dscp_policy_capa = !!atoi(value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700929 } else {
930 value[-1] = '=';
931 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
932 if (ret == 0)
933 wpa_supplicant_update_config(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -0700934 else if (ret == 1)
935 ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700936 }
937
938 return ret;
939}
940
941
942static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
943 char *cmd, char *buf, size_t buflen)
944{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700945 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946
947 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
948
949 if (os_strcmp(cmd, "version") == 0) {
950 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700951 } else if (os_strcasecmp(cmd, "max_command_len") == 0) {
952 res = os_snprintf(buf, buflen, "%u", CTRL_IFACE_MAX_LEN);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700953 } else if (os_strcasecmp(cmd, "country") == 0) {
954 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
955 res = os_snprintf(buf, buflen, "%c%c",
956 wpa_s->conf->country[0],
957 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700958#ifdef CONFIG_WIFI_DISPLAY
959 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800960 int enabled;
961 if (wpa_s->global->p2p == NULL ||
962 wpa_s->global->p2p_disabled)
963 enabled = 0;
964 else
965 enabled = wpa_s->global->wifi_display;
966 res = os_snprintf(buf, buflen, "%d", enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700967#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700968#ifdef CONFIG_TESTING_GET_GTK
969 } else if (os_strcmp(cmd, "gtk") == 0) {
970 if (wpa_s->last_gtk_len == 0)
971 return -1;
972 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
973 wpa_s->last_gtk_len);
974 return res;
975#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800976 } else if (os_strcmp(cmd, "tls_library") == 0) {
977 res = tls_get_library_version(buf, buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700978#ifdef CONFIG_TESTING_OPTIONS
979 } else if (os_strcmp(cmd, "anonce") == 0) {
980 return wpa_snprintf_hex(buf, buflen,
981 wpa_sm_get_anonce(wpa_s->wpa),
982 WPA_NONCE_LEN);
Hai Shalomfdcde762020-04-02 11:19:20 -0700983 } else if (os_strcasecmp(cmd, "last_tk_key_idx") == 0) {
984 res = os_snprintf(buf, buflen, "%d", wpa_s->last_tk_key_idx);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700985#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800986 } else {
987 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988 }
989
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800990 if (os_snprintf_error(buflen, res))
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700991 return -1;
992 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700993}
994
995
996#ifdef IEEE8021X_EAPOL
997static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
998 char *addr)
999{
1000 u8 bssid[ETH_ALEN];
1001 struct wpa_ssid *ssid = wpa_s->current_ssid;
1002
1003 if (hwaddr_aton(addr, bssid)) {
1004 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
1005 "'%s'", addr);
1006 return -1;
1007 }
1008
1009 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
1010 rsn_preauth_deinit(wpa_s->wpa);
1011 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
1012 return -1;
1013
1014 return 0;
1015}
1016#endif /* IEEE8021X_EAPOL */
1017
1018
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001019#ifdef CONFIG_TDLS
1020
1021static int wpa_supplicant_ctrl_iface_tdls_discover(
1022 struct wpa_supplicant *wpa_s, char *addr)
1023{
1024 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001025 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001026
1027 if (hwaddr_aton(addr, peer)) {
1028 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
1029 "address '%s'", addr);
1030 return -1;
1031 }
1032
1033 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
1034 MAC2STR(peer));
1035
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001036 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1037 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
1038 else
1039 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
1040
1041 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001042}
1043
1044
1045static int wpa_supplicant_ctrl_iface_tdls_setup(
1046 struct wpa_supplicant *wpa_s, char *addr)
1047{
1048 u8 peer[ETH_ALEN];
1049 int ret;
1050
1051 if (hwaddr_aton(addr, peer)) {
1052 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
1053 "address '%s'", addr);
1054 return -1;
1055 }
1056
1057 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
1058 MAC2STR(peer));
1059
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001060 if ((wpa_s->conf->tdls_external_control) &&
1061 wpa_tdls_is_external_setup(wpa_s->wpa))
1062 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
1063
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001064 wpa_tdls_remove(wpa_s->wpa, peer);
1065
1066 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1067 ret = wpa_tdls_start(wpa_s->wpa, peer);
1068 else
1069 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001070
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071 return ret;
1072}
1073
1074
1075static int wpa_supplicant_ctrl_iface_tdls_teardown(
1076 struct wpa_supplicant *wpa_s, char *addr)
1077{
1078 u8 peer[ETH_ALEN];
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001079 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001080
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001081 if (os_strcmp(addr, "*") == 0) {
1082 /* remove everyone */
1083 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
1084 wpa_tdls_teardown_peers(wpa_s->wpa);
1085 return 0;
1086 }
1087
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088 if (hwaddr_aton(addr, peer)) {
1089 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
1090 "address '%s'", addr);
1091 return -1;
1092 }
1093
1094 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
1095 MAC2STR(peer));
1096
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001097 if ((wpa_s->conf->tdls_external_control) &&
1098 wpa_tdls_is_external_setup(wpa_s->wpa))
1099 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1100
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001101 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1102 ret = wpa_tdls_teardown_link(
1103 wpa_s->wpa, peer,
1104 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
1105 else
1106 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1107
1108 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001109}
1110
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001111
1112static int ctrl_iface_get_capability_tdls(
1113 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1114{
1115 int ret;
1116
1117 ret = os_snprintf(buf, buflen, "%s\n",
1118 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
1119 (wpa_s->drv_flags &
1120 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
1121 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001122 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001123 return -1;
1124 return ret;
1125}
1126
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001127
1128static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
1129 struct wpa_supplicant *wpa_s, char *cmd)
1130{
1131 u8 peer[ETH_ALEN];
1132 struct hostapd_freq_params freq_params;
1133 u8 oper_class;
1134 char *pos, *end;
1135
1136 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1137 wpa_printf(MSG_INFO,
1138 "tdls_chanswitch: Only supported with external setup");
1139 return -1;
1140 }
1141
1142 os_memset(&freq_params, 0, sizeof(freq_params));
1143
1144 pos = os_strchr(cmd, ' ');
1145 if (pos == NULL)
1146 return -1;
1147 *pos++ = '\0';
1148
1149 oper_class = strtol(pos, &end, 10);
1150 if (pos == end) {
1151 wpa_printf(MSG_INFO,
1152 "tdls_chanswitch: Invalid op class provided");
1153 return -1;
1154 }
1155
1156 pos = end;
1157 freq_params.freq = atoi(pos);
1158 if (freq_params.freq == 0) {
1159 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
1160 return -1;
1161 }
1162
1163#define SET_FREQ_SETTING(str) \
1164 do { \
1165 const char *pos2 = os_strstr(pos, " " #str "="); \
1166 if (pos2) { \
1167 pos2 += sizeof(" " #str "=") - 1; \
1168 freq_params.str = atoi(pos2); \
1169 } \
1170 } while (0)
1171
1172 SET_FREQ_SETTING(center_freq1);
1173 SET_FREQ_SETTING(center_freq2);
1174 SET_FREQ_SETTING(bandwidth);
1175 SET_FREQ_SETTING(sec_channel_offset);
1176#undef SET_FREQ_SETTING
1177
1178 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1179 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1180
1181 if (hwaddr_aton(cmd, peer)) {
1182 wpa_printf(MSG_DEBUG,
1183 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1184 cmd);
1185 return -1;
1186 }
1187
1188 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1189 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1190 MAC2STR(peer), oper_class, freq_params.freq,
1191 freq_params.center_freq1, freq_params.center_freq2,
1192 freq_params.bandwidth, freq_params.sec_channel_offset,
1193 freq_params.ht_enabled ? " HT" : "",
1194 freq_params.vht_enabled ? " VHT" : "");
1195
1196 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1197 &freq_params);
1198}
1199
1200
1201static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1202 struct wpa_supplicant *wpa_s, char *cmd)
1203{
1204 u8 peer[ETH_ALEN];
1205
1206 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1207 wpa_printf(MSG_INFO,
1208 "tdls_chanswitch: Only supported with external setup");
1209 return -1;
1210 }
1211
1212 if (hwaddr_aton(cmd, peer)) {
1213 wpa_printf(MSG_DEBUG,
1214 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1215 cmd);
1216 return -1;
1217 }
1218
1219 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1220 MAC2STR(peer));
1221
1222 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1223}
1224
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07001225
1226static int wpa_supplicant_ctrl_iface_tdls_link_status(
1227 struct wpa_supplicant *wpa_s, const char *addr,
1228 char *buf, size_t buflen)
1229{
1230 u8 peer[ETH_ALEN];
1231 const char *tdls_status;
1232 int ret;
1233
1234 if (hwaddr_aton(addr, peer)) {
1235 wpa_printf(MSG_DEBUG,
1236 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1237 addr);
1238 return -1;
1239 }
1240 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1241 MAC2STR(peer));
1242
1243 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1244 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1245 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1246 if (os_snprintf_error(buflen, ret))
1247 return -1;
1248
1249 return ret;
1250}
1251
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001252#endif /* CONFIG_TDLS */
1253
1254
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001255static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1256{
1257 char *token, *context = NULL;
1258 struct wmm_ac_ts_setup_params params = {
1259 .tsid = 0xff,
1260 .direction = 0xff,
1261 };
1262
1263 while ((token = str_token(cmd, " ", &context))) {
1264 if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
1265 sscanf(token, "up=%i", &params.user_priority) == 1 ||
1266 sscanf(token, "nominal_msdu_size=%i",
1267 &params.nominal_msdu_size) == 1 ||
1268 sscanf(token, "mean_data_rate=%i",
1269 &params.mean_data_rate) == 1 ||
1270 sscanf(token, "min_phy_rate=%i",
1271 &params.minimum_phy_rate) == 1 ||
1272 sscanf(token, "sba=%i",
1273 &params.surplus_bandwidth_allowance) == 1)
1274 continue;
1275
1276 if (os_strcasecmp(token, "downlink") == 0) {
1277 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1278 } else if (os_strcasecmp(token, "uplink") == 0) {
1279 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1280 } else if (os_strcasecmp(token, "bidi") == 0) {
1281 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1282 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1283 params.fixed_nominal_msdu = 1;
1284 } else {
1285 wpa_printf(MSG_DEBUG,
1286 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1287 token);
1288 return -1;
1289 }
1290
1291 }
1292
1293 return wpas_wmm_ac_addts(wpa_s, &params);
1294}
1295
1296
1297static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1298{
1299 u8 tsid = atoi(cmd);
1300
1301 return wpas_wmm_ac_delts(wpa_s, tsid);
1302}
1303
1304
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001305#ifdef CONFIG_IEEE80211R
1306static int wpa_supplicant_ctrl_iface_ft_ds(
1307 struct wpa_supplicant *wpa_s, char *addr)
1308{
1309 u8 target_ap[ETH_ALEN];
1310 struct wpa_bss *bss;
1311 const u8 *mdie;
1312
1313 if (hwaddr_aton(addr, target_ap)) {
1314 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1315 "address '%s'", addr);
1316 return -1;
1317 }
1318
1319 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1320
1321 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1322 if (bss)
1323 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1324 else
1325 mdie = NULL;
1326
1327 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
1328}
1329#endif /* CONFIG_IEEE80211R */
1330
1331
1332#ifdef CONFIG_WPS
1333static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1334 char *cmd)
1335{
1336 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001337#ifdef CONFIG_P2P
1338 u8 p2p_dev_addr[ETH_ALEN];
1339#endif /* CONFIG_P2P */
1340#ifdef CONFIG_AP
1341 u8 *_p2p_dev_addr = NULL;
1342#endif /* CONFIG_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001343 char *pos;
1344 int multi_ap = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001345
Hai Shalom021b0b52019-04-10 11:17:58 -07001346 if (!cmd || os_strcmp(cmd, "any") == 0 ||
1347 os_strncmp(cmd, "any ", 4) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001348 _bssid = NULL;
1349#ifdef CONFIG_P2P
1350 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1351 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1352 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1353 "P2P Device Address '%s'",
1354 cmd + 13);
1355 return -1;
1356 }
1357 _p2p_dev_addr = p2p_dev_addr;
1358#endif /* CONFIG_P2P */
Hai Shalom021b0b52019-04-10 11:17:58 -07001359 } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) {
1360 _bssid = NULL;
1361 multi_ap = atoi(cmd + 9);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001362 } else if (hwaddr_aton(cmd, bssid)) {
1363 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1364 cmd);
1365 return -1;
1366 }
1367
Hai Shalom021b0b52019-04-10 11:17:58 -07001368 if (cmd) {
1369 pos = os_strstr(cmd, " multi_ap=");
1370 if (pos) {
1371 pos += 10;
1372 multi_ap = atoi(pos);
1373 }
1374 }
1375
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001376#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001377 if (wpa_s->ap_iface)
1378 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1379#endif /* CONFIG_AP */
1380
Hai Shalom021b0b52019-04-10 11:17:58 -07001381 return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001382}
1383
1384
1385static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1386 char *cmd, char *buf,
1387 size_t buflen)
1388{
1389 u8 bssid[ETH_ALEN], *_bssid = bssid;
1390 char *pin;
1391 int ret;
1392
1393 pin = os_strchr(cmd, ' ');
1394 if (pin)
1395 *pin++ = '\0';
1396
1397 if (os_strcmp(cmd, "any") == 0)
1398 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001399 else if (os_strcmp(cmd, "get") == 0) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001400 if (wps_generate_pin((unsigned int *) &ret) < 0)
1401 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001402 goto done;
1403 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001404 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1405 cmd);
1406 return -1;
1407 }
1408
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001409#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001410 if (wpa_s->ap_iface) {
1411 int timeout = 0;
1412 char *pos;
1413
1414 if (pin) {
1415 pos = os_strchr(pin, ' ');
1416 if (pos) {
1417 *pos++ = '\0';
1418 timeout = atoi(pos);
1419 }
1420 }
1421
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001422 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001423 buf, buflen, timeout);
1424 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001425#endif /* CONFIG_AP */
1426
1427 if (pin) {
1428 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1429 DEV_PW_DEFAULT);
1430 if (ret < 0)
1431 return -1;
1432 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001433 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001434 return -1;
1435 return ret;
1436 }
1437
1438 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1439 if (ret < 0)
1440 return -1;
1441
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001442done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001443 /* Return the generated PIN */
1444 ret = os_snprintf(buf, buflen, "%08d", ret);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001445 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001446 return -1;
1447 return ret;
1448}
1449
1450
1451static int wpa_supplicant_ctrl_iface_wps_check_pin(
1452 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1453{
1454 char pin[9];
1455 size_t len;
1456 char *pos;
1457 int ret;
1458
1459 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1460 (u8 *) cmd, os_strlen(cmd));
1461 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1462 if (*pos < '0' || *pos > '9')
1463 continue;
1464 pin[len++] = *pos;
1465 if (len == 9) {
1466 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1467 return -1;
1468 }
1469 }
1470 if (len != 4 && len != 8) {
1471 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1472 return -1;
1473 }
1474 pin[len] = '\0';
1475
1476 if (len == 8) {
1477 unsigned int pin_val;
1478 pin_val = atoi(pin);
1479 if (!wps_pin_valid(pin_val)) {
1480 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1481 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001482 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001483 return -1;
1484 return ret;
1485 }
1486 }
1487
1488 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001489 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001490 return -1;
1491
1492 return ret;
1493}
1494
1495
Dmitry Shmidt04949592012-07-19 12:16:46 -07001496#ifdef CONFIG_WPS_NFC
1497
1498static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1499 char *cmd)
1500{
1501 u8 bssid[ETH_ALEN], *_bssid = bssid;
1502
1503 if (cmd == NULL || cmd[0] == '\0')
1504 _bssid = NULL;
1505 else if (hwaddr_aton(cmd, bssid))
1506 return -1;
1507
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001508 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1509 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001510}
1511
1512
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001513static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1514 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1515{
1516 int ndef;
1517 struct wpabuf *buf;
1518 int res;
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001519 char *pos;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001520
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001521 pos = os_strchr(cmd, ' ');
1522 if (pos)
1523 *pos++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001524 if (os_strcmp(cmd, "WPS") == 0)
1525 ndef = 0;
1526 else if (os_strcmp(cmd, "NDEF") == 0)
1527 ndef = 1;
1528 else
1529 return -1;
1530
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001531 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001532 if (buf == NULL)
1533 return -1;
1534
1535 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1536 wpabuf_len(buf));
1537 reply[res++] = '\n';
1538 reply[res] = '\0';
1539
1540 wpabuf_free(buf);
1541
1542 return res;
1543}
1544
1545
Dmitry Shmidt04949592012-07-19 12:16:46 -07001546static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1547 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1548{
1549 int ndef;
1550 struct wpabuf *buf;
1551 int res;
1552
1553 if (os_strcmp(cmd, "WPS") == 0)
1554 ndef = 0;
1555 else if (os_strcmp(cmd, "NDEF") == 0)
1556 ndef = 1;
1557 else
1558 return -1;
1559
1560 buf = wpas_wps_nfc_token(wpa_s, ndef);
1561 if (buf == NULL)
1562 return -1;
1563
1564 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1565 wpabuf_len(buf));
1566 reply[res++] = '\n';
1567 reply[res] = '\0';
1568
1569 wpabuf_free(buf);
1570
1571 return res;
1572}
1573
1574
1575static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1576 struct wpa_supplicant *wpa_s, char *pos)
1577{
1578 size_t len;
1579 struct wpabuf *buf;
1580 int ret;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001581 char *freq;
1582 int forced_freq = 0;
1583
1584 freq = strstr(pos, " freq=");
1585 if (freq) {
1586 *freq = '\0';
1587 freq += 6;
1588 forced_freq = atoi(freq);
1589 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001590
1591 len = os_strlen(pos);
1592 if (len & 0x01)
1593 return -1;
1594 len /= 2;
1595
1596 buf = wpabuf_alloc(len);
1597 if (buf == NULL)
1598 return -1;
1599 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1600 wpabuf_free(buf);
1601 return -1;
1602 }
1603
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001604 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001605 wpabuf_free(buf);
1606
1607 return ret;
1608}
1609
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001610
1611static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001612 char *reply, size_t max_len,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001613 int ndef)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001614{
1615 struct wpabuf *buf;
1616 int res;
1617
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001618 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001619 if (buf == NULL)
1620 return -1;
1621
1622 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1623 wpabuf_len(buf));
1624 reply[res++] = '\n';
1625 reply[res] = '\0';
1626
1627 wpabuf_free(buf);
1628
1629 return res;
1630}
1631
1632
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001633#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001634static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1635 char *reply, size_t max_len,
1636 int ndef)
1637{
1638 struct wpabuf *buf;
1639 int res;
1640
1641 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1642 if (buf == NULL) {
1643 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1644 return -1;
1645 }
1646
1647 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1648 wpabuf_len(buf));
1649 reply[res++] = '\n';
1650 reply[res] = '\0';
1651
1652 wpabuf_free(buf);
1653
1654 return res;
1655}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001656#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001657
1658
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001659static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1660 char *cmd, char *reply,
1661 size_t max_len)
1662{
1663 char *pos;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001664 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001665
1666 pos = os_strchr(cmd, ' ');
1667 if (pos == NULL)
1668 return -1;
1669 *pos++ = '\0';
1670
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001671 if (os_strcmp(cmd, "WPS") == 0)
1672 ndef = 0;
1673 else if (os_strcmp(cmd, "NDEF") == 0)
1674 ndef = 1;
1675 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001676 return -1;
1677
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001678 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001679 if (!ndef)
1680 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001681 return wpas_ctrl_nfc_get_handover_req_wps(
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001682 wpa_s, reply, max_len, ndef);
1683 }
1684
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001685#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001686 if (os_strcmp(pos, "P2P-CR") == 0) {
1687 return wpas_ctrl_nfc_get_handover_req_p2p(
1688 wpa_s, reply, max_len, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001689 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001690#endif /* CONFIG_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001691
1692 return -1;
1693}
1694
1695
1696static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001697 char *reply, size_t max_len,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001698 int ndef, int cr, char *uuid)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001699{
1700 struct wpabuf *buf;
1701 int res;
1702
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001703 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001704 if (buf == NULL)
1705 return -1;
1706
1707 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1708 wpabuf_len(buf));
1709 reply[res++] = '\n';
1710 reply[res] = '\0';
1711
1712 wpabuf_free(buf);
1713
1714 return res;
1715}
1716
1717
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001718#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001719static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1720 char *reply, size_t max_len,
1721 int ndef, int tag)
1722{
1723 struct wpabuf *buf;
1724 int res;
1725
1726 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1727 if (buf == NULL)
1728 return -1;
1729
1730 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1731 wpabuf_len(buf));
1732 reply[res++] = '\n';
1733 reply[res] = '\0';
1734
1735 wpabuf_free(buf);
1736
1737 return res;
1738}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001739#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001740
1741
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001742static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1743 char *cmd, char *reply,
1744 size_t max_len)
1745{
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001746 char *pos, *pos2;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001747 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001748
1749 pos = os_strchr(cmd, ' ');
1750 if (pos == NULL)
1751 return -1;
1752 *pos++ = '\0';
1753
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001754 if (os_strcmp(cmd, "WPS") == 0)
1755 ndef = 0;
1756 else if (os_strcmp(cmd, "NDEF") == 0)
1757 ndef = 1;
1758 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001759 return -1;
1760
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001761 pos2 = os_strchr(pos, ' ');
1762 if (pos2)
1763 *pos2++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001764 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001765 if (!ndef)
1766 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001767 return wpas_ctrl_nfc_get_handover_sel_wps(
1768 wpa_s, reply, max_len, ndef,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001769 os_strcmp(pos, "WPS-CR") == 0, pos2);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001770 }
1771
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001772#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001773 if (os_strcmp(pos, "P2P-CR") == 0) {
1774 return wpas_ctrl_nfc_get_handover_sel_p2p(
1775 wpa_s, reply, max_len, ndef, 0);
1776 }
1777
1778 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1779 return wpas_ctrl_nfc_get_handover_sel_p2p(
1780 wpa_s, reply, max_len, ndef, 1);
1781 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001782#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001783
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001784 return -1;
1785}
1786
1787
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001788static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1789 char *cmd)
1790{
1791 size_t len;
1792 struct wpabuf *req, *sel;
1793 int ret;
1794 char *pos, *role, *type, *pos2;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001795#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001796 char *freq;
1797 int forced_freq = 0;
1798
1799 freq = strstr(cmd, " freq=");
1800 if (freq) {
1801 *freq = '\0';
1802 freq += 6;
1803 forced_freq = atoi(freq);
1804 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001805#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001806
1807 role = cmd;
1808 pos = os_strchr(role, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001809 if (pos == NULL) {
1810 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001811 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001812 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001813 *pos++ = '\0';
1814
1815 type = pos;
1816 pos = os_strchr(type, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001817 if (pos == NULL) {
1818 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001819 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001820 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001821 *pos++ = '\0';
1822
1823 pos2 = os_strchr(pos, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001824 if (pos2 == NULL) {
1825 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001826 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001827 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001828 *pos2++ = '\0';
1829
1830 len = os_strlen(pos);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001831 if (len & 0x01) {
1832 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001833 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001834 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001835 len /= 2;
1836
1837 req = wpabuf_alloc(len);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001838 if (req == NULL) {
1839 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001840 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001841 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001842 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001843 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001844 wpabuf_free(req);
1845 return -1;
1846 }
1847
1848 len = os_strlen(pos2);
1849 if (len & 0x01) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001850 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001851 wpabuf_free(req);
1852 return -1;
1853 }
1854 len /= 2;
1855
1856 sel = wpabuf_alloc(len);
1857 if (sel == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001858 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001859 wpabuf_free(req);
1860 return -1;
1861 }
1862 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001863 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001864 wpabuf_free(req);
1865 wpabuf_free(sel);
1866 return -1;
1867 }
1868
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001869 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1870 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1871
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001872 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1873 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001874#ifdef CONFIG_AP
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001875 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1876 {
1877 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1878 if (ret < 0)
1879 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001880#endif /* CONFIG_AP */
1881#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001882 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1883 {
1884 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1885 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1886 {
1887 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1888 forced_freq);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001889#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001890 } else {
1891 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1892 "reported: role=%s type=%s", role, type);
1893 ret = -1;
1894 }
1895 wpabuf_free(req);
1896 wpabuf_free(sel);
1897
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001898 if (ret)
1899 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1900
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001901 return ret;
1902}
1903
Dmitry Shmidt04949592012-07-19 12:16:46 -07001904#endif /* CONFIG_WPS_NFC */
1905
1906
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001907static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1908 char *cmd)
1909{
1910 u8 bssid[ETH_ALEN];
1911 char *pin;
1912 char *new_ssid;
1913 char *new_auth;
1914 char *new_encr;
1915 char *new_key;
1916 struct wps_new_ap_settings ap;
1917
1918 pin = os_strchr(cmd, ' ');
1919 if (pin == NULL)
1920 return -1;
1921 *pin++ = '\0';
1922
1923 if (hwaddr_aton(cmd, bssid)) {
1924 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1925 cmd);
1926 return -1;
1927 }
1928
1929 new_ssid = os_strchr(pin, ' ');
1930 if (new_ssid == NULL)
1931 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1932 *new_ssid++ = '\0';
1933
1934 new_auth = os_strchr(new_ssid, ' ');
1935 if (new_auth == NULL)
1936 return -1;
1937 *new_auth++ = '\0';
1938
1939 new_encr = os_strchr(new_auth, ' ');
1940 if (new_encr == NULL)
1941 return -1;
1942 *new_encr++ = '\0';
1943
1944 new_key = os_strchr(new_encr, ' ');
1945 if (new_key == NULL)
1946 return -1;
1947 *new_key++ = '\0';
1948
1949 os_memset(&ap, 0, sizeof(ap));
1950 ap.ssid_hex = new_ssid;
1951 ap.auth = new_auth;
1952 ap.encr = new_encr;
1953 ap.key_hex = new_key;
1954 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1955}
1956
1957
1958#ifdef CONFIG_AP
1959static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1960 char *cmd, char *buf,
1961 size_t buflen)
1962{
1963 int timeout = 300;
1964 char *pos;
1965 const char *pin_txt;
1966
1967 if (!wpa_s->ap_iface)
1968 return -1;
1969
1970 pos = os_strchr(cmd, ' ');
1971 if (pos)
1972 *pos++ = '\0';
1973
1974 if (os_strcmp(cmd, "disable") == 0) {
1975 wpas_wps_ap_pin_disable(wpa_s);
1976 return os_snprintf(buf, buflen, "OK\n");
1977 }
1978
1979 if (os_strcmp(cmd, "random") == 0) {
1980 if (pos)
1981 timeout = atoi(pos);
1982 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1983 if (pin_txt == NULL)
1984 return -1;
1985 return os_snprintf(buf, buflen, "%s", pin_txt);
1986 }
1987
1988 if (os_strcmp(cmd, "get") == 0) {
1989 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1990 if (pin_txt == NULL)
1991 return -1;
1992 return os_snprintf(buf, buflen, "%s", pin_txt);
1993 }
1994
1995 if (os_strcmp(cmd, "set") == 0) {
1996 char *pin;
1997 if (pos == NULL)
1998 return -1;
1999 pin = pos;
2000 pos = os_strchr(pos, ' ');
2001 if (pos) {
2002 *pos++ = '\0';
2003 timeout = atoi(pos);
2004 }
2005 if (os_strlen(pin) > buflen)
2006 return -1;
2007 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
2008 return -1;
2009 return os_snprintf(buf, buflen, "%s", pin);
2010 }
2011
2012 return -1;
2013}
2014#endif /* CONFIG_AP */
2015
2016
2017#ifdef CONFIG_WPS_ER
2018static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
2019 char *cmd)
2020{
2021 char *uuid = cmd, *pin, *pos;
2022 u8 addr_buf[ETH_ALEN], *addr = NULL;
2023 pin = os_strchr(uuid, ' ');
2024 if (pin == NULL)
2025 return -1;
2026 *pin++ = '\0';
2027 pos = os_strchr(pin, ' ');
2028 if (pos) {
2029 *pos++ = '\0';
2030 if (hwaddr_aton(pos, addr_buf) == 0)
2031 addr = addr_buf;
2032 }
2033 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
2034}
2035
2036
2037static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
2038 char *cmd)
2039{
2040 char *uuid = cmd, *pin;
2041 pin = os_strchr(uuid, ' ');
2042 if (pin == NULL)
2043 return -1;
2044 *pin++ = '\0';
2045 return wpas_wps_er_learn(wpa_s, uuid, pin);
2046}
2047
2048
2049static int wpa_supplicant_ctrl_iface_wps_er_set_config(
2050 struct wpa_supplicant *wpa_s, char *cmd)
2051{
2052 char *uuid = cmd, *id;
2053 id = os_strchr(uuid, ' ');
2054 if (id == NULL)
2055 return -1;
2056 *id++ = '\0';
2057 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
2058}
2059
2060
2061static int wpa_supplicant_ctrl_iface_wps_er_config(
2062 struct wpa_supplicant *wpa_s, char *cmd)
2063{
2064 char *pin;
2065 char *new_ssid;
2066 char *new_auth;
2067 char *new_encr;
2068 char *new_key;
2069 struct wps_new_ap_settings ap;
2070
2071 pin = os_strchr(cmd, ' ');
2072 if (pin == NULL)
2073 return -1;
2074 *pin++ = '\0';
2075
2076 new_ssid = os_strchr(pin, ' ');
2077 if (new_ssid == NULL)
2078 return -1;
2079 *new_ssid++ = '\0';
2080
2081 new_auth = os_strchr(new_ssid, ' ');
2082 if (new_auth == NULL)
2083 return -1;
2084 *new_auth++ = '\0';
2085
2086 new_encr = os_strchr(new_auth, ' ');
2087 if (new_encr == NULL)
2088 return -1;
2089 *new_encr++ = '\0';
2090
2091 new_key = os_strchr(new_encr, ' ');
2092 if (new_key == NULL)
2093 return -1;
2094 *new_key++ = '\0';
2095
2096 os_memset(&ap, 0, sizeof(ap));
2097 ap.ssid_hex = new_ssid;
2098 ap.auth = new_auth;
2099 ap.encr = new_encr;
2100 ap.key_hex = new_key;
2101 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
2102}
Dmitry Shmidt04949592012-07-19 12:16:46 -07002103
2104
2105#ifdef CONFIG_WPS_NFC
2106static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
2107 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2108{
2109 int ndef;
2110 struct wpabuf *buf;
2111 int res;
2112 char *uuid;
2113
2114 uuid = os_strchr(cmd, ' ');
2115 if (uuid == NULL)
2116 return -1;
2117 *uuid++ = '\0';
2118
2119 if (os_strcmp(cmd, "WPS") == 0)
2120 ndef = 0;
2121 else if (os_strcmp(cmd, "NDEF") == 0)
2122 ndef = 1;
2123 else
2124 return -1;
2125
2126 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
2127 if (buf == NULL)
2128 return -1;
2129
2130 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
2131 wpabuf_len(buf));
2132 reply[res++] = '\n';
2133 reply[res] = '\0';
2134
2135 wpabuf_free(buf);
2136
2137 return res;
2138}
2139#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002140#endif /* CONFIG_WPS_ER */
2141
2142#endif /* CONFIG_WPS */
2143
2144
2145#ifdef CONFIG_IBSS_RSN
2146static int wpa_supplicant_ctrl_iface_ibss_rsn(
2147 struct wpa_supplicant *wpa_s, char *addr)
2148{
2149 u8 peer[ETH_ALEN];
2150
2151 if (hwaddr_aton(addr, peer)) {
2152 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
2153 "address '%s'", addr);
2154 return -1;
2155 }
2156
2157 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
2158 MAC2STR(peer));
2159
2160 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
2161}
2162#endif /* CONFIG_IBSS_RSN */
2163
2164
2165static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
2166 char *rsp)
2167{
2168#ifdef IEEE8021X_EAPOL
2169 char *pos, *id_pos;
2170 int id;
2171 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002172
2173 pos = os_strchr(rsp, '-');
2174 if (pos == NULL)
2175 return -1;
2176 *pos++ = '\0';
2177 id_pos = pos;
2178 pos = os_strchr(pos, ':');
2179 if (pos == NULL)
2180 return -1;
2181 *pos++ = '\0';
2182 id = atoi(id_pos);
2183 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
2184 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2185 (u8 *) pos, os_strlen(pos));
2186
2187 ssid = wpa_config_get_network(wpa_s->conf, id);
2188 if (ssid == NULL) {
2189 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2190 "to update", id);
2191 return -1;
2192 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002193
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002194 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2195 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002196#else /* IEEE8021X_EAPOL */
2197 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2198 return -1;
2199#endif /* IEEE8021X_EAPOL */
2200}
2201
2202
2203static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2204 const char *params,
2205 char *buf, size_t buflen)
2206{
2207 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002208 int res, verbose, wps, ret;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002209#ifdef CONFIG_HS20
2210 const u8 *hs20;
2211#endif /* CONFIG_HS20 */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002212 const u8 *sess_id;
2213 size_t sess_id_len;
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002214
Dmitry Shmidt56052862013-10-04 10:23:25 -07002215 if (os_strcmp(params, "-DRIVER") == 0)
2216 return wpa_drv_status(wpa_s, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002217 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002218 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002219 pos = buf;
2220 end = buf + buflen;
2221 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2222 struct wpa_ssid *ssid = wpa_s->current_ssid;
2223 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2224 MAC2STR(wpa_s->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002225 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002226 return pos - buf;
2227 pos += ret;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002228 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2229 wpa_s->assoc_freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002230 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002231 return pos - buf;
2232 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002233 if (ssid) {
2234 u8 *_ssid = ssid->ssid;
2235 size_t ssid_len = ssid->ssid_len;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002236 u8 ssid_buf[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002237 if (ssid_len == 0) {
2238 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2239 if (_res < 0)
2240 ssid_len = 0;
2241 else
2242 ssid_len = _res;
2243 _ssid = ssid_buf;
2244 }
2245 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2246 wpa_ssid_txt(_ssid, ssid_len),
2247 ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002248 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002249 return pos - buf;
2250 pos += ret;
2251
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002252 if (wps && ssid->passphrase &&
2253 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2254 (ssid->mode == WPAS_MODE_AP ||
2255 ssid->mode == WPAS_MODE_P2P_GO)) {
2256 ret = os_snprintf(pos, end - pos,
2257 "passphrase=%s\n",
2258 ssid->passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002259 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002260 return pos - buf;
2261 pos += ret;
2262 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002263 if (ssid->id_str) {
2264 ret = os_snprintf(pos, end - pos,
2265 "id_str=%s\n",
2266 ssid->id_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002267 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002268 return pos - buf;
2269 pos += ret;
2270 }
2271
2272 switch (ssid->mode) {
2273 case WPAS_MODE_INFRA:
2274 ret = os_snprintf(pos, end - pos,
2275 "mode=station\n");
2276 break;
2277 case WPAS_MODE_IBSS:
2278 ret = os_snprintf(pos, end - pos,
2279 "mode=IBSS\n");
2280 break;
2281 case WPAS_MODE_AP:
2282 ret = os_snprintf(pos, end - pos,
2283 "mode=AP\n");
2284 break;
2285 case WPAS_MODE_P2P_GO:
2286 ret = os_snprintf(pos, end - pos,
2287 "mode=P2P GO\n");
2288 break;
2289 case WPAS_MODE_P2P_GROUP_FORMATION:
2290 ret = os_snprintf(pos, end - pos,
2291 "mode=P2P GO - group "
2292 "formation\n");
2293 break;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002294 case WPAS_MODE_MESH:
2295 ret = os_snprintf(pos, end - pos,
2296 "mode=mesh\n");
2297 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002298 default:
2299 ret = 0;
2300 break;
2301 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002302 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002303 return pos - buf;
2304 pos += ret;
2305 }
2306
Hai Shalom021b0b52019-04-10 11:17:58 -07002307 if (wpa_s->connection_set &&
2308 (wpa_s->connection_ht || wpa_s->connection_vht ||
2309 wpa_s->connection_he)) {
2310 ret = os_snprintf(pos, end - pos,
2311 "wifi_generation=%u\n",
2312 wpa_s->connection_he ? 6 :
2313 (wpa_s->connection_vht ? 5 : 4));
2314 if (os_snprintf_error(end - pos, ret))
2315 return pos - buf;
2316 pos += ret;
2317 }
2318
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002319#ifdef CONFIG_AP
2320 if (wpa_s->ap_iface) {
2321 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2322 end - pos,
2323 verbose);
2324 } else
2325#endif /* CONFIG_AP */
2326 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2327 }
Paul Stewart092955c2017-02-06 09:13:09 -08002328#ifdef CONFIG_SME
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002329#ifdef CONFIG_SAE
2330 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002331#ifdef CONFIG_AP
2332 !wpa_s->ap_iface &&
2333#endif /* CONFIG_AP */
2334 wpa_s->sme.sae.state == SAE_ACCEPTED) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002335 ret = os_snprintf(pos, end - pos, "sae_group=%d\n"
2336 "sae_h2e=%d\n"
2337 "sae_pk=%d\n",
2338 wpa_s->sme.sae.group,
2339 wpa_s->sme.sae.h2e,
2340 wpa_s->sme.sae.pk);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002341 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002342 return pos - buf;
2343 pos += ret;
2344 }
2345#endif /* CONFIG_SAE */
Paul Stewart092955c2017-02-06 09:13:09 -08002346#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002347 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2348 wpa_supplicant_state_txt(wpa_s->wpa_state));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002349 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002350 return pos - buf;
2351 pos += ret;
2352
2353 if (wpa_s->l2 &&
2354 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2355 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002356 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002357 return pos - buf;
2358 pos += ret;
2359 }
2360
2361#ifdef CONFIG_P2P
2362 if (wpa_s->global->p2p) {
2363 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2364 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002365 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002366 return pos - buf;
2367 pos += ret;
2368 }
2369#endif /* CONFIG_P2P */
2370
2371 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2372 MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002373 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002374 return pos - buf;
2375 pos += ret;
2376
Dmitry Shmidt04949592012-07-19 12:16:46 -07002377#ifdef CONFIG_HS20
2378 if (wpa_s->current_bss &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002379 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2380 HS20_IE_VENDOR_TYPE)) &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002381 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2382 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002383 int release = 1;
2384 if (hs20[1] >= 5) {
2385 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2386 release = rel_num + 1;
2387 }
2388 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002389 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002390 return pos - buf;
2391 pos += ret;
2392 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002393
2394 if (wpa_s->current_ssid) {
2395 struct wpa_cred *cred;
2396 char *type;
2397
2398 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002399 size_t i;
2400
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002401 if (wpa_s->current_ssid->parent_cred != cred)
2402 continue;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002403
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002404 if (cred->provisioning_sp) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002405 ret = os_snprintf(pos, end - pos,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002406 "provisioning_sp=%s\n",
2407 cred->provisioning_sp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002408 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt051af732013-10-22 13:52:46 -07002409 return pos - buf;
2410 pos += ret;
2411 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002412
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002413 if (!cred->domain)
2414 goto no_domain;
2415
2416 i = 0;
2417 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2418 struct wpabuf *names =
2419 wpa_s->current_bss->anqp->domain_name;
2420 for (i = 0; names && i < cred->num_domain; i++)
2421 {
2422 if (domain_name_list_contains(
2423 names, cred->domain[i], 1))
2424 break;
2425 }
2426 if (i == cred->num_domain)
2427 i = 0; /* show first entry by default */
2428 }
2429 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2430 cred->domain[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002431 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002432 return pos - buf;
2433 pos += ret;
2434
2435 no_domain:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002436 if (wpa_s->current_bss == NULL ||
2437 wpa_s->current_bss->anqp == NULL)
2438 res = -1;
2439 else
2440 res = interworking_home_sp_cred(
2441 wpa_s, cred,
2442 wpa_s->current_bss->anqp->domain_name);
2443 if (res > 0)
2444 type = "home";
2445 else if (res == 0)
2446 type = "roaming";
2447 else
2448 type = "unknown";
2449
2450 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002451 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002452 return pos - buf;
2453 pos += ret;
2454
2455 break;
2456 }
2457 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002458#endif /* CONFIG_HS20 */
2459
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002460 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2461 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2462 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2463 verbose);
2464 if (res >= 0)
2465 pos += res;
2466 }
2467
Dmitry Shmidt29333592017-01-09 12:27:11 -08002468#ifdef CONFIG_MACSEC
2469 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2470 if (res > 0)
2471 pos += res;
2472#endif /* CONFIG_MACSEC */
2473
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002474 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2475 if (sess_id) {
2476 char *start = pos;
2477
2478 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2479 if (os_snprintf_error(end - pos, ret))
2480 return start - buf;
2481 pos += ret;
2482 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2483 if (ret <= 0)
2484 return start - buf;
2485 pos += ret;
2486 ret = os_snprintf(pos, end - pos, "\n");
2487 if (os_snprintf_error(end - pos, ret))
2488 return start - buf;
2489 pos += ret;
2490 }
2491
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002492 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2493 if (res >= 0)
2494 pos += res;
2495
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002496#ifdef CONFIG_WPS
2497 {
2498 char uuid_str[100];
2499 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2500 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002501 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002502 return pos - buf;
2503 pos += ret;
2504 }
2505#endif /* CONFIG_WPS */
2506
Roshan Pius3a1667e2018-07-03 15:17:14 -07002507 if (wpa_s->ieee80211ac) {
2508 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2509 if (os_snprintf_error(end - pos, ret))
2510 return pos - buf;
2511 pos += ret;
2512 }
2513
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002514#ifdef ANDROID
vandwalleffc70182014-09-11 11:40:14 -07002515 /*
2516 * Allow using the STATUS command with default behavior, say for debug,
2517 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2518 * events with STATUS-NO_EVENTS.
2519 */
2520 if (os_strcmp(params, "-NO_EVENTS")) {
2521 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2522 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2523 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2524 wpa_s->wpa_state,
2525 MAC2STR(wpa_s->bssid),
2526 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2527 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2528 wpa_s->current_ssid->ssid_len) : "");
2529 if (wpa_s->wpa_state == WPA_COMPLETED) {
2530 struct wpa_ssid *ssid = wpa_s->current_ssid;
2531 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2532 "- connection to " MACSTR
2533 " completed %s [id=%d id_str=%s]",
2534 MAC2STR(wpa_s->bssid), "(auth)",
2535 ssid ? ssid->id : -1,
2536 ssid && ssid->id_str ? ssid->id_str : "");
2537 }
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08002538 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002539#endif /* ANDROID */
2540
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002541 return pos - buf;
2542}
2543
2544
2545static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2546 char *cmd)
2547{
2548 char *pos;
2549 int id;
2550 struct wpa_ssid *ssid;
2551 u8 bssid[ETH_ALEN];
2552
2553 /* cmd: "<network id> <BSSID>" */
2554 pos = os_strchr(cmd, ' ');
2555 if (pos == NULL)
2556 return -1;
2557 *pos++ = '\0';
2558 id = atoi(cmd);
2559 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2560 if (hwaddr_aton(pos, bssid)) {
2561 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2562 return -1;
2563 }
2564
2565 ssid = wpa_config_get_network(wpa_s->conf, id);
2566 if (ssid == NULL) {
2567 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2568 "to update", id);
2569 return -1;
2570 }
2571
2572 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2573 ssid->bssid_set = !is_zero_ether_addr(bssid);
2574
2575 return 0;
2576}
2577
2578
Hai Shalom60840252021-02-19 19:02:11 -08002579static int wpa_supplicant_ctrl_iface_bssid_ignore(struct wpa_supplicant *wpa_s,
2580 char *cmd, char *buf,
2581 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002582{
2583 u8 bssid[ETH_ALEN];
Hai Shalom60840252021-02-19 19:02:11 -08002584 struct wpa_bssid_ignore *e;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002585 char *pos, *end;
2586 int ret;
2587
Hai Shalom60840252021-02-19 19:02:11 -08002588 /* cmd: "BSSID_IGNORE [<BSSID>]" */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002589 if (*cmd == '\0') {
2590 pos = buf;
2591 end = buf + buflen;
Hai Shalom60840252021-02-19 19:02:11 -08002592 e = wpa_s->bssid_ignore;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002593 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002594 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2595 MAC2STR(e->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002596 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002597 return pos - buf;
2598 pos += ret;
2599 e = e->next;
2600 }
2601 return pos - buf;
2602 }
2603
2604 cmd++;
2605 if (os_strncmp(cmd, "clear", 5) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -08002606 wpa_bssid_ignore_clear(wpa_s);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002607 os_memcpy(buf, "OK\n", 3);
2608 return 3;
2609 }
2610
Hai Shalom60840252021-02-19 19:02:11 -08002611 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BSSID_IGNORE bssid='%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002612 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002613 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002614 return -1;
2615 }
2616
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002617 /*
2618 * Add the BSSID twice, so its count will be 2, causing it to be
2619 * skipped when processing scan results.
2620 */
Hai Shalom60840252021-02-19 19:02:11 -08002621 ret = wpa_bssid_ignore_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002622 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002623 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002624 ret = wpa_bssid_ignore_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002625 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002626 return -1;
2627 os_memcpy(buf, "OK\n", 3);
2628 return 3;
2629}
2630
2631
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002632static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2633 char *cmd, char *buf,
2634 size_t buflen)
2635{
2636 char *pos, *end, *stamp;
2637 int ret;
2638
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002639 /* cmd: "LOG_LEVEL [<level>]" */
2640 if (*cmd == '\0') {
2641 pos = buf;
2642 end = buf + buflen;
2643 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2644 "Timestamp: %d\n",
2645 debug_level_str(wpa_debug_level),
2646 wpa_debug_timestamp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002647 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002648 ret = 0;
2649
2650 return ret;
2651 }
2652
2653 while (*cmd == ' ')
2654 cmd++;
2655
2656 stamp = os_strchr(cmd, ' ');
2657 if (stamp) {
2658 *stamp++ = '\0';
2659 while (*stamp == ' ') {
2660 stamp++;
2661 }
2662 }
2663
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002664 if (os_strlen(cmd)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002665 int level = str_to_debug_level(cmd);
2666 if (level < 0)
2667 return -1;
2668 wpa_debug_level = level;
2669 }
2670
2671 if (stamp && os_strlen(stamp))
2672 wpa_debug_timestamp = atoi(stamp);
2673
2674 os_memcpy(buf, "OK\n", 3);
2675 return 3;
2676}
2677
2678
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002679static int wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002680 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002681{
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002682 char *pos, *end, *prev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002683 struct wpa_ssid *ssid;
2684 int ret;
2685
2686 pos = buf;
2687 end = buf + buflen;
2688 ret = os_snprintf(pos, end - pos,
2689 "network id / ssid / bssid / flags\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002690 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002691 return pos - buf;
2692 pos += ret;
2693
2694 ssid = wpa_s->conf->ssid;
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002695
2696 /* skip over ssids until we find next one */
2697 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2698 int last_id = atoi(cmd + 8);
2699 if (last_id != -1) {
2700 while (ssid != NULL && ssid->id <= last_id) {
2701 ssid = ssid->next;
2702 }
2703 }
2704 }
2705
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002706 while (ssid) {
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002707 prev = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002708 ret = os_snprintf(pos, end - pos, "%d\t%s",
2709 ssid->id,
2710 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002711 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002712 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002713 pos += ret;
2714 if (ssid->bssid_set) {
2715 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2716 MAC2STR(ssid->bssid));
2717 } else {
2718 ret = os_snprintf(pos, end - pos, "\tany");
2719 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002720 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002721 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002722 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002723 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002724 ssid == wpa_s->current_ssid ?
2725 "[CURRENT]" : "",
2726 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002727 ssid->disabled_until.sec ?
2728 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002729 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2730 "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002731 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002732 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002733 pos += ret;
2734 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002735 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002736 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002737 pos += ret;
2738
2739 ssid = ssid->next;
2740 }
2741
2742 return pos - buf;
2743}
2744
2745
2746static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2747{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002748 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002749 ret = os_snprintf(pos, end - pos, "-");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002750 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002751 return pos;
2752 pos += ret;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002753 ret = wpa_write_ciphers(pos, end, cipher, "+");
2754 if (ret < 0)
2755 return pos;
2756 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002757 return pos;
2758}
2759
2760
2761static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2762 const u8 *ie, size_t ie_len)
2763{
2764 struct wpa_ie_data data;
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002765 char *start;
2766 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002767
2768 ret = os_snprintf(pos, end - pos, "[%s-", proto);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002769 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002770 return pos;
2771 pos += ret;
2772
2773 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2774 ret = os_snprintf(pos, end - pos, "?]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002775 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002776 return pos;
2777 pos += ret;
2778 return pos;
2779 }
2780
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002781 start = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002782 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002783 ret = os_snprintf(pos, end - pos, "%sEAP",
2784 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002785 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002786 return pos;
2787 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002788 }
2789 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002790 ret = os_snprintf(pos, end - pos, "%sPSK",
2791 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002792 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002793 return pos;
2794 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002795 }
2796 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002797 ret = os_snprintf(pos, end - pos, "%sNone",
2798 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002799 if (os_snprintf_error(end - pos, ret))
2800 return pos;
2801 pos += ret;
2802 }
2803 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2804 ret = os_snprintf(pos, end - pos, "%sSAE",
2805 pos == start ? "" : "+");
2806 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002807 return pos;
2808 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002809 }
2810#ifdef CONFIG_IEEE80211R
2811 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2812 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002813 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002814 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002815 return pos;
2816 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002817 }
2818 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2819 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002820 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002821 if (os_snprintf_error(end - pos, ret))
2822 return pos;
2823 pos += ret;
2824 }
2825 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2826 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2827 pos == start ? "" : "+");
2828 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002829 return pos;
2830 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002831 }
2832#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002833 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2834 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002835 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002836 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002837 return pos;
2838 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002839 }
2840 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2841 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002842 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002843 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002844 return pos;
2845 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002846 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002847
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002848#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002849 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2850 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2851 pos == start ? "" : "+");
2852 if (os_snprintf_error(end - pos, ret))
2853 return pos;
2854 pos += ret;
2855 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002856#endif /* CONFIG_SUITEB */
2857
2858#ifdef CONFIG_SUITEB192
2859 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2860 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2861 pos == start ? "" : "+");
2862 if (os_snprintf_error(end - pos, ret))
2863 return pos;
2864 pos += ret;
2865 }
2866#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002867
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002868#ifdef CONFIG_FILS
2869 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2870 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2871 pos == start ? "" : "+");
2872 if (os_snprintf_error(end - pos, ret))
2873 return pos;
2874 pos += ret;
2875 }
2876 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2877 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2878 pos == start ? "" : "+");
2879 if (os_snprintf_error(end - pos, ret))
2880 return pos;
2881 pos += ret;
2882 }
2883#ifdef CONFIG_IEEE80211R
2884 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2885 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2886 pos == start ? "" : "+");
2887 if (os_snprintf_error(end - pos, ret))
2888 return pos;
2889 pos += ret;
2890 }
2891 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2892 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2893 pos == start ? "" : "+");
2894 if (os_snprintf_error(end - pos, ret))
2895 return pos;
2896 pos += ret;
2897 }
2898#endif /* CONFIG_IEEE80211R */
2899#endif /* CONFIG_FILS */
2900
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002901#ifdef CONFIG_OWE
2902 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2903 ret = os_snprintf(pos, end - pos, "%sOWE",
2904 pos == start ? "" : "+");
2905 if (os_snprintf_error(end - pos, ret))
2906 return pos;
2907 pos += ret;
2908 }
2909#endif /* CONFIG_OWE */
2910
2911#ifdef CONFIG_DPP
2912 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
2913 ret = os_snprintf(pos, end - pos, "%sDPP",
2914 pos == start ? "" : "+");
2915 if (os_snprintf_error(end - pos, ret))
2916 return pos;
2917 pos += ret;
2918 }
2919#endif /* CONFIG_DPP */
2920
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002921 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2922 ret = os_snprintf(pos, end - pos, "%sOSEN",
2923 pos == start ? "" : "+");
2924 if (os_snprintf_error(end - pos, ret))
2925 return pos;
2926 pos += ret;
2927 }
2928
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002929 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2930
2931 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2932 ret = os_snprintf(pos, end - pos, "-preauth");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002933 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002934 return pos;
2935 pos += ret;
2936 }
2937
2938 ret = os_snprintf(pos, end - pos, "]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002939 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002940 return pos;
2941 pos += ret;
2942
2943 return pos;
2944}
2945
2946
2947#ifdef CONFIG_WPS
2948static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2949 char *pos, char *end,
2950 struct wpabuf *wps_ie)
2951{
2952 int ret;
2953 const char *txt;
2954
2955 if (wps_ie == NULL)
2956 return pos;
2957 if (wps_is_selected_pbc_registrar(wps_ie))
2958 txt = "[WPS-PBC]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002959 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2960 txt = "[WPS-AUTH]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002961 else if (wps_is_selected_pin_registrar(wps_ie))
2962 txt = "[WPS-PIN]";
2963 else
2964 txt = "[WPS]";
2965
2966 ret = os_snprintf(pos, end - pos, "%s", txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002967 if (!os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002968 pos += ret;
2969 wpabuf_free(wps_ie);
2970 return pos;
2971}
2972#endif /* CONFIG_WPS */
2973
2974
2975static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2976 char *pos, char *end,
2977 const struct wpa_bss *bss)
2978{
2979#ifdef CONFIG_WPS
2980 struct wpabuf *wps_ie;
2981 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2982 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2983#else /* CONFIG_WPS */
2984 return pos;
2985#endif /* CONFIG_WPS */
2986}
2987
2988
2989/* Format one result on one text line into a buffer. */
2990static int wpa_supplicant_ctrl_iface_scan_result(
2991 struct wpa_supplicant *wpa_s,
2992 const struct wpa_bss *bss, char *buf, size_t buflen)
2993{
2994 char *pos, *end;
2995 int ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07002996 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe, *rsnxe;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002997
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002998 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002999 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07003000 if (!p2p)
3001 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003002 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
3003 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
3004 0)
3005 return 0; /* Do not show P2P listen discovery results here */
3006
3007 pos = buf;
3008 end = buf + buflen;
3009
3010 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
3011 MAC2STR(bss->bssid), bss->freq, bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003012 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003013 return -1;
3014 pos += ret;
3015 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3016 if (ie)
3017 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
3018 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003019 if (ie2) {
3020 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
3021 ie2, 2 + ie2[1]);
3022 }
Hai Shalom899fcc72020-10-19 14:38:18 -07003023 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003024 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
3025 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
3026 if (os_snprintf_error(end - pos, ret))
3027 return -1;
3028 pos += ret;
3029 }
3030 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
3031 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
3032 if (os_snprintf_error(end - pos, ret))
3033 return -1;
3034 pos += ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07003035 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003036 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
3037 if (osen_ie)
3038 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
3039 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003040 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
3041 if (owe) {
3042 ret = os_snprintf(pos, end - pos,
3043 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
3044 if (os_snprintf_error(end - pos, ret))
3045 return -1;
3046 pos += ret;
3047 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003048 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003049 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003050 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003051 if (os_snprintf_error(end - pos, ret))
3052 return -1;
3053 pos += ret;
3054 }
3055 if (mesh) {
3056 ret = os_snprintf(pos, end - pos, "[MESH]");
3057 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003058 return -1;
3059 pos += ret;
3060 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003061 if (bss_is_dmg(bss)) {
3062 const char *s;
Hai Shalomc3565922019-10-28 11:58:20 -07003063
Hai Shalom60840252021-02-19 19:02:11 -08003064 if (wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_EDMG_OPERATION)) {
Hai Shalomc3565922019-10-28 11:58:20 -07003065 ret = os_snprintf(pos, end - pos, "[EDMG]");
3066 if (os_snprintf_error(end - pos, ret))
3067 return -1;
3068 pos += ret;
3069 }
3070
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003071 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003072 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003073 return -1;
3074 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003075 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3076 case IEEE80211_CAP_DMG_IBSS:
3077 s = "[IBSS]";
3078 break;
3079 case IEEE80211_CAP_DMG_AP:
3080 s = "[ESS]";
3081 break;
3082 case IEEE80211_CAP_DMG_PBSS:
3083 s = "[PBSS]";
3084 break;
3085 default:
3086 s = "";
3087 break;
3088 }
3089 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003090 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003091 return -1;
3092 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003093 } else {
3094 if (bss->caps & IEEE80211_CAP_IBSS) {
3095 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003096 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003097 return -1;
3098 pos += ret;
3099 }
3100 if (bss->caps & IEEE80211_CAP_ESS) {
3101 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003102 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003103 return -1;
3104 pos += ret;
3105 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003106 }
3107 if (p2p) {
3108 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003109 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003110 return -1;
3111 pos += ret;
3112 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003113#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003114 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003115 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003116 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003117 return -1;
3118 pos += ret;
3119 }
3120#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003121#ifdef CONFIG_FILS
3122 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
3123 ret = os_snprintf(pos, end - pos, "[FILS]");
3124 if (os_snprintf_error(end - pos, ret))
3125 return -1;
3126 pos += ret;
3127 }
3128#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003129#ifdef CONFIG_FST
3130 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
3131 ret = os_snprintf(pos, end - pos, "[FST]");
3132 if (os_snprintf_error(end - pos, ret))
3133 return -1;
3134 pos += ret;
3135 }
3136#endif /* CONFIG_FST */
Hai Shalom74f70d42019-02-11 14:42:39 -08003137 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
3138 ret = os_snprintf(pos, end - pos, "[UTF-8]");
3139 if (os_snprintf_error(end - pos, ret))
3140 return -1;
3141 pos += ret;
3142 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003143
3144 ret = os_snprintf(pos, end - pos, "\t%s",
3145 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003146 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003147 return -1;
3148 pos += ret;
3149
3150 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003151 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003152 return -1;
3153 pos += ret;
3154
3155 return pos - buf;
3156}
3157
3158
3159static int wpa_supplicant_ctrl_iface_scan_results(
3160 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3161{
3162 char *pos, *end;
3163 struct wpa_bss *bss;
3164 int ret;
3165
3166 pos = buf;
3167 end = buf + buflen;
3168 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
3169 "flags / ssid\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003170 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003171 return pos - buf;
3172 pos += ret;
3173
3174 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3175 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
3176 end - pos);
3177 if (ret < 0 || ret >= end - pos)
3178 return pos - buf;
3179 pos += ret;
3180 }
3181
3182 return pos - buf;
3183}
3184
3185
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003186#ifdef CONFIG_MESH
3187
3188static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3189 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
3190{
3191 char *pos, ifname[IFNAMSIZ + 1];
3192
3193 ifname[0] = '\0';
3194
3195 pos = os_strstr(cmd, "ifname=");
3196 if (pos) {
3197 pos += 7;
3198 os_strlcpy(ifname, pos, sizeof(ifname));
3199 }
3200
3201 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
3202 return -1;
3203
3204 os_strlcpy(reply, ifname, max_len);
3205 return os_strlen(ifname);
3206}
3207
3208
3209static int wpa_supplicant_ctrl_iface_mesh_group_add(
3210 struct wpa_supplicant *wpa_s, char *cmd)
3211{
3212 int id;
3213 struct wpa_ssid *ssid;
3214
3215 id = atoi(cmd);
3216 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
3217
3218 ssid = wpa_config_get_network(wpa_s->conf, id);
3219 if (ssid == NULL) {
3220 wpa_printf(MSG_DEBUG,
3221 "CTRL_IFACE: Could not find network id=%d", id);
3222 return -1;
3223 }
3224 if (ssid->mode != WPAS_MODE_MESH) {
3225 wpa_printf(MSG_DEBUG,
3226 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3227 return -1;
3228 }
3229 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
3230 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
3231 wpa_printf(MSG_ERROR,
3232 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3233 return -1;
3234 }
3235
3236 /*
3237 * TODO: If necessary write our own group_add function,
3238 * for now we can reuse select_network
3239 */
3240 wpa_supplicant_select_network(wpa_s, ssid);
3241
3242 return 0;
3243}
3244
3245
3246static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3247 struct wpa_supplicant *wpa_s, char *cmd)
3248{
3249 struct wpa_supplicant *orig;
3250 struct wpa_global *global;
3251 int found = 0;
3252
3253 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3254
3255 global = wpa_s->global;
3256 orig = wpa_s;
3257
3258 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3259 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3260 found = 1;
3261 break;
3262 }
3263 }
3264 if (!found) {
3265 wpa_printf(MSG_ERROR,
3266 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3267 cmd);
3268 return -1;
3269 }
3270 if (wpa_s->mesh_if_created && wpa_s == orig) {
3271 wpa_printf(MSG_ERROR,
3272 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3273 return -1;
3274 }
3275
3276 wpa_s->reassociate = 0;
3277 wpa_s->disconnected = 1;
3278 wpa_supplicant_cancel_sched_scan(wpa_s);
3279 wpa_supplicant_cancel_scan(wpa_s);
3280
3281 /*
3282 * TODO: If necessary write our own group_remove function,
3283 * for now we can reuse deauthenticate
3284 */
3285 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3286
3287 if (wpa_s->mesh_if_created)
3288 wpa_supplicant_remove_iface(global, wpa_s, 0);
3289
3290 return 0;
3291}
3292
Dmitry Shmidte4663042016-04-04 10:07:49 -07003293
3294static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3295 struct wpa_supplicant *wpa_s, char *cmd)
3296{
3297 u8 addr[ETH_ALEN];
3298
3299 if (hwaddr_aton(cmd, addr) < 0)
3300 return -1;
3301
3302 return wpas_mesh_peer_remove(wpa_s, addr);
3303}
3304
3305
3306static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3307 struct wpa_supplicant *wpa_s, char *cmd)
3308{
3309 u8 addr[ETH_ALEN];
3310 int duration;
3311 char *pos;
3312
3313 pos = os_strstr(cmd, " duration=");
3314 if (pos) {
3315 *pos = '\0';
3316 duration = atoi(pos + 10);
3317 } else {
3318 duration = -1;
3319 }
3320
3321 if (hwaddr_aton(cmd, addr))
3322 return -1;
3323
3324 return wpas_mesh_peer_add(wpa_s, addr, duration);
3325}
3326
Hai Shalom81f62d82019-07-22 12:10:00 -07003327
3328static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3329 struct wpa_supplicant *wpa_s, char *cmd)
3330{
3331 struct ether_header *eth;
3332 u8 addr[ETH_ALEN];
3333 u8 *buf;
3334 char *pos;
3335 size_t payload_len = 0, len;
3336 int ret = -1;
3337
3338 if (hwaddr_aton(cmd, addr))
3339 return -1;
3340
3341 pos = os_strstr(cmd, " payload=");
3342 if (pos) {
3343 pos = pos + 9;
3344 payload_len = os_strlen(pos);
3345 if (payload_len & 1)
3346 return -1;
3347
3348 payload_len /= 2;
3349 }
3350
3351 len = ETH_HLEN + payload_len;
3352 buf = os_malloc(len);
3353 if (!buf)
3354 return -1;
3355
3356 eth = (struct ether_header *) buf;
3357 os_memcpy(eth->ether_dhost, addr, ETH_ALEN);
3358 os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN);
3359 eth->ether_type = htons(ETH_P_802_3);
3360
3361 if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0)
3362 goto fail;
3363
3364 ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len);
3365fail:
3366 os_free(buf);
3367 return -ret;
3368}
3369
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003370#endif /* CONFIG_MESH */
3371
3372
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003373static int wpa_supplicant_ctrl_iface_select_network(
3374 struct wpa_supplicant *wpa_s, char *cmd)
3375{
3376 int id;
3377 struct wpa_ssid *ssid;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003378 char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003379
3380 /* cmd: "<network id>" or "any" */
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003381 if (os_strncmp(cmd, "any", 3) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003382 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3383 ssid = NULL;
3384 } else {
3385 id = atoi(cmd);
3386 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3387
3388 ssid = wpa_config_get_network(wpa_s->conf, id);
3389 if (ssid == NULL) {
3390 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3391 "network id=%d", id);
3392 return -1;
3393 }
3394 if (ssid->disabled == 2) {
3395 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3396 "SELECT_NETWORK with persistent P2P group");
3397 return -1;
3398 }
3399 }
3400
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003401 pos = os_strstr(cmd, " freq=");
3402 if (pos) {
3403 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3404 if (freqs) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003405 os_free(wpa_s->select_network_scan_freqs);
3406 wpa_s->select_network_scan_freqs = freqs;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003407 }
3408 }
3409
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003410 wpa_s->scan_min_time.sec = 0;
3411 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003412 wpa_supplicant_select_network(wpa_s, ssid);
3413
3414 return 0;
3415}
3416
3417
3418static int wpa_supplicant_ctrl_iface_enable_network(
3419 struct wpa_supplicant *wpa_s, char *cmd)
3420{
3421 int id;
3422 struct wpa_ssid *ssid;
3423
3424 /* cmd: "<network id>" or "all" */
3425 if (os_strcmp(cmd, "all") == 0) {
3426 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3427 ssid = NULL;
3428 } else {
3429 id = atoi(cmd);
3430 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3431
3432 ssid = wpa_config_get_network(wpa_s->conf, id);
3433 if (ssid == NULL) {
3434 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3435 "network id=%d", id);
3436 return -1;
3437 }
3438 if (ssid->disabled == 2) {
3439 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3440 "ENABLE_NETWORK with persistent P2P group");
3441 return -1;
3442 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003443
3444 if (os_strstr(cmd, " no-connect")) {
3445 ssid->disabled = 0;
3446 return 0;
3447 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003448 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003449 wpa_s->scan_min_time.sec = 0;
3450 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003451 wpa_supplicant_enable_network(wpa_s, ssid);
3452
3453 return 0;
3454}
3455
3456
3457static int wpa_supplicant_ctrl_iface_disable_network(
3458 struct wpa_supplicant *wpa_s, char *cmd)
3459{
3460 int id;
3461 struct wpa_ssid *ssid;
3462
3463 /* cmd: "<network id>" or "all" */
3464 if (os_strcmp(cmd, "all") == 0) {
3465 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3466 ssid = NULL;
3467 } else {
3468 id = atoi(cmd);
3469 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3470
3471 ssid = wpa_config_get_network(wpa_s->conf, id);
3472 if (ssid == NULL) {
3473 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3474 "network id=%d", id);
3475 return -1;
3476 }
3477 if (ssid->disabled == 2) {
3478 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3479 "DISABLE_NETWORK with persistent P2P "
3480 "group");
3481 return -1;
3482 }
3483 }
3484 wpa_supplicant_disable_network(wpa_s, ssid);
3485
3486 return 0;
3487}
3488
3489
3490static int wpa_supplicant_ctrl_iface_add_network(
3491 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3492{
3493 struct wpa_ssid *ssid;
3494 int ret;
3495
3496 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3497
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003498 ssid = wpa_supplicant_add_network(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003499 if (ssid == NULL)
3500 return -1;
3501
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003502 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003503 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003504 return -1;
3505 return ret;
3506}
3507
3508
3509static int wpa_supplicant_ctrl_iface_remove_network(
3510 struct wpa_supplicant *wpa_s, char *cmd)
3511{
3512 int id;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003513 int result;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003514
3515 /* cmd: "<network id>" or "all" */
3516 if (os_strcmp(cmd, "all") == 0) {
3517 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Hai Shalom899fcc72020-10-19 14:38:18 -07003518 return wpa_supplicant_remove_all_networks(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003519 }
3520
3521 id = atoi(cmd);
3522 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3523
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003524 result = wpa_supplicant_remove_network(wpa_s, id);
3525 if (result == -1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003526 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3527 "id=%d", id);
3528 return -1;
3529 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003530 if (result == -2) {
Deepthi Gowria831d782012-09-03 11:55:38 +03003531 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3532 "network id=%d", id);
3533 return -1;
3534 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003535 return 0;
3536}
3537
3538
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003539static int wpa_supplicant_ctrl_iface_update_network(
3540 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3541 char *name, char *value)
3542{
Dmitry Shmidte4663042016-04-04 10:07:49 -07003543 int ret;
3544
3545 ret = wpa_config_set(ssid, name, value, 0);
3546 if (ret < 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003547 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3548 "variable '%s'", name);
3549 return -1;
3550 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07003551 if (ret == 1)
3552 return 0; /* No change to the previously configured value */
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003553
Hai Shalom899fcc72020-10-19 14:38:18 -07003554#ifdef CONFIG_BGSCAN
3555 if (os_strcmp(name, "bgscan") == 0) {
3556 /*
3557 * Reset the bgscan parameters for the current network and
3558 * return. There's no need to flush caches for bgscan parameter
3559 * changes.
3560 */
3561 if (wpa_s->current_ssid == ssid &&
3562 wpa_s->wpa_state == WPA_COMPLETED)
3563 wpa_supplicant_reset_bgscan(wpa_s);
3564 return 0;
3565 }
3566#endif /* CONFIG_BGSCAN */
3567
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003568 if (os_strcmp(name, "bssid") != 0 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003569 os_strcmp(name, "bssid_hint") != 0 &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003570 os_strcmp(name, "priority") != 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003571 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3572
Dmitry Shmidte4663042016-04-04 10:07:49 -07003573 if (wpa_s->current_ssid == ssid ||
3574 wpa_s->current_ssid == NULL) {
3575 /*
3576 * Invalidate the EAP session cache if anything in the
3577 * current or previously used configuration changes.
3578 */
3579 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3580 }
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003581 }
3582
3583 if ((os_strcmp(name, "psk") == 0 &&
3584 value[0] == '"' && ssid->ssid_len) ||
3585 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3586 wpa_config_update_psk(ssid);
3587 else if (os_strcmp(name, "priority") == 0)
3588 wpa_config_update_prio_list(wpa_s->conf);
3589
3590 return 0;
3591}
3592
3593
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003594static int wpa_supplicant_ctrl_iface_set_network(
3595 struct wpa_supplicant *wpa_s, char *cmd)
3596{
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003597 int id, ret, prev_bssid_set, prev_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003598 struct wpa_ssid *ssid;
3599 char *name, *value;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003600 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003601
3602 /* cmd: "<network id> <variable name> <value>" */
3603 name = os_strchr(cmd, ' ');
3604 if (name == NULL)
3605 return -1;
3606 *name++ = '\0';
3607
3608 value = os_strchr(name, ' ');
3609 if (value == NULL)
3610 return -1;
3611 *value++ = '\0';
3612
3613 id = atoi(cmd);
3614 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3615 id, name);
3616 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3617 (u8 *) value, os_strlen(value));
3618
3619 ssid = wpa_config_get_network(wpa_s->conf, id);
3620 if (ssid == NULL) {
3621 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3622 "id=%d", id);
3623 return -1;
3624 }
3625
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003626 prev_bssid_set = ssid->bssid_set;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003627 prev_disabled = ssid->disabled;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003628 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3629 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3630 value);
3631 if (ret == 0 &&
3632 (ssid->bssid_set != prev_bssid_set ||
3633 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3634 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003635
3636 if (prev_disabled != ssid->disabled &&
3637 (prev_disabled == 2 || ssid->disabled == 2))
3638 wpas_notify_network_type_changed(wpa_s, ssid);
3639
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003640 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003641}
3642
3643
3644static int wpa_supplicant_ctrl_iface_get_network(
3645 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3646{
3647 int id;
3648 size_t res;
3649 struct wpa_ssid *ssid;
3650 char *name, *value;
3651
3652 /* cmd: "<network id> <variable name>" */
3653 name = os_strchr(cmd, ' ');
3654 if (name == NULL || buflen == 0)
3655 return -1;
3656 *name++ = '\0';
3657
3658 id = atoi(cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003659 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003660 id, name);
3661
3662 ssid = wpa_config_get_network(wpa_s->conf, id);
3663 if (ssid == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003664 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003665 "id=%d", id);
3666 return -1;
3667 }
3668
3669 value = wpa_config_get_no_key(ssid, name);
3670 if (value == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003671 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003672 "variable '%s'", name);
3673 return -1;
3674 }
3675
3676 res = os_strlcpy(buf, value, buflen);
3677 if (res >= buflen) {
3678 os_free(value);
3679 return -1;
3680 }
3681
3682 os_free(value);
3683
3684 return res;
3685}
3686
3687
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003688static int wpa_supplicant_ctrl_iface_dup_network(
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003689 struct wpa_supplicant *wpa_s, char *cmd,
3690 struct wpa_supplicant *dst_wpa_s)
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003691{
3692 struct wpa_ssid *ssid_s, *ssid_d;
3693 char *name, *id, *value;
3694 int id_s, id_d, ret;
3695
3696 /* cmd: "<src network id> <dst network id> <variable name>" */
3697 id = os_strchr(cmd, ' ');
3698 if (id == NULL)
3699 return -1;
3700 *id++ = '\0';
3701
3702 name = os_strchr(id, ' ');
3703 if (name == NULL)
3704 return -1;
3705 *name++ = '\0';
3706
3707 id_s = atoi(cmd);
3708 id_d = atoi(id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003709
3710 wpa_printf(MSG_DEBUG,
3711 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3712 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003713
3714 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3715 if (ssid_s == NULL) {
3716 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3717 "network id=%d", id_s);
3718 return -1;
3719 }
3720
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003721 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003722 if (ssid_d == NULL) {
3723 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003724 "network id=%d", id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003725 return -1;
3726 }
3727
3728 value = wpa_config_get(ssid_s, name);
3729 if (value == NULL) {
3730 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3731 "variable '%s'", name);
3732 return -1;
3733 }
3734
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003735 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003736 value);
3737
3738 os_free(value);
3739
3740 return ret;
3741}
3742
3743
Dmitry Shmidt04949592012-07-19 12:16:46 -07003744static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3745 char *buf, size_t buflen)
3746{
3747 char *pos, *end;
3748 struct wpa_cred *cred;
3749 int ret;
3750
3751 pos = buf;
3752 end = buf + buflen;
3753 ret = os_snprintf(pos, end - pos,
3754 "cred id / realm / username / domain / imsi\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003755 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003756 return pos - buf;
3757 pos += ret;
3758
3759 cred = wpa_s->conf->cred;
3760 while (cred) {
3761 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3762 cred->id, cred->realm ? cred->realm : "",
3763 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07003764 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003765 cred->imsi ? cred->imsi : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003766 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003767 return pos - buf;
3768 pos += ret;
3769
3770 cred = cred->next;
3771 }
3772
3773 return pos - buf;
3774}
3775
3776
3777static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3778 char *buf, size_t buflen)
3779{
3780 struct wpa_cred *cred;
3781 int ret;
3782
3783 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3784
3785 cred = wpa_config_add_cred(wpa_s->conf);
3786 if (cred == NULL)
3787 return -1;
3788
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003789 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3790
Dmitry Shmidt04949592012-07-19 12:16:46 -07003791 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003792 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003793 return -1;
3794 return ret;
3795}
3796
3797
3798static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3799 char *cmd)
3800{
3801 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003802 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003803
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003804 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3805 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003806 if (os_strcmp(cmd, "all") == 0) {
3807 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
Hai Shaloma20dcd72022-02-04 13:43:00 -08003808 return wpas_remove_all_creds(wpa_s);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003809 }
3810
3811 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3812 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3813 cmd + 8);
3814 cred = wpa_s->conf->cred;
3815 while (cred) {
3816 prev = cred;
3817 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003818 if (prev->domain) {
3819 size_t i;
3820 for (i = 0; i < prev->num_domain; i++) {
3821 if (os_strcmp(prev->domain[i], cmd + 8)
3822 != 0)
3823 continue;
Hai Shaloma20dcd72022-02-04 13:43:00 -08003824 wpas_remove_cred(wpa_s, prev);
Dmitry Shmidt051af732013-10-22 13:52:46 -07003825 break;
3826 }
3827 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003828 }
3829 return 0;
3830 }
3831
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003832 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3833 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3834 cmd + 16);
3835 cred = wpa_s->conf->cred;
3836 while (cred) {
3837 prev = cred;
3838 cred = cred->next;
3839 if (prev->provisioning_sp &&
3840 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
Hai Shaloma20dcd72022-02-04 13:43:00 -08003841 wpas_remove_cred(wpa_s, prev);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003842 }
3843 return 0;
3844 }
3845
Dmitry Shmidt04949592012-07-19 12:16:46 -07003846 id = atoi(cmd);
3847 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3848
3849 cred = wpa_config_get_cred(wpa_s->conf, id);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003850 return wpas_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003851}
3852
3853
3854static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3855 char *cmd)
3856{
3857 int id;
3858 struct wpa_cred *cred;
3859 char *name, *value;
3860
3861 /* cmd: "<cred id> <variable name> <value>" */
3862 name = os_strchr(cmd, ' ');
3863 if (name == NULL)
3864 return -1;
3865 *name++ = '\0';
3866
3867 value = os_strchr(name, ' ');
3868 if (value == NULL)
3869 return -1;
3870 *value++ = '\0';
3871
3872 id = atoi(cmd);
3873 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3874 id, name);
3875 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3876 (u8 *) value, os_strlen(value));
3877
3878 cred = wpa_config_get_cred(wpa_s->conf, id);
3879 if (cred == NULL) {
3880 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3881 id);
3882 return -1;
3883 }
3884
3885 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3886 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3887 "variable '%s'", name);
3888 return -1;
3889 }
3890
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003891 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3892
Dmitry Shmidt04949592012-07-19 12:16:46 -07003893 return 0;
3894}
3895
3896
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003897static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3898 char *cmd, char *buf,
3899 size_t buflen)
3900{
3901 int id;
3902 size_t res;
3903 struct wpa_cred *cred;
3904 char *name, *value;
3905
3906 /* cmd: "<cred id> <variable name>" */
3907 name = os_strchr(cmd, ' ');
3908 if (name == NULL)
3909 return -1;
3910 *name++ = '\0';
3911
3912 id = atoi(cmd);
3913 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3914 id, name);
3915
3916 cred = wpa_config_get_cred(wpa_s->conf, id);
3917 if (cred == NULL) {
3918 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3919 id);
3920 return -1;
3921 }
3922
3923 value = wpa_config_get_cred_no_key(cred, name);
3924 if (value == NULL) {
3925 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3926 name);
3927 return -1;
3928 }
3929
3930 res = os_strlcpy(buf, value, buflen);
3931 if (res >= buflen) {
3932 os_free(value);
3933 return -1;
3934 }
3935
3936 os_free(value);
3937
3938 return res;
3939}
3940
3941
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003942#ifndef CONFIG_NO_CONFIG_WRITE
3943static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3944{
3945 int ret;
3946
3947 if (!wpa_s->conf->update_config) {
3948 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3949 "to update configuration (update_config=0)");
3950 return -1;
3951 }
3952
3953 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3954 if (ret) {
3955 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3956 "update configuration");
3957 } else {
3958 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3959 " updated");
3960 }
3961
3962 return ret;
3963}
3964#endif /* CONFIG_NO_CONFIG_WRITE */
3965
3966
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003967struct cipher_info {
3968 unsigned int capa;
3969 const char *name;
3970 int group_only;
3971};
3972
3973static const struct cipher_info ciphers[] = {
3974 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3975 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3976 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3977 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07003978#ifndef CONFIG_NO_TKIP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003979 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07003980#endif /* CONFIG_NO_TKIP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003981 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
Hai Shalomfdcde762020-04-02 11:19:20 -07003982#ifdef CONFIG_WEP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003983 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3984 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003985#endif /* CONFIG_WEP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003986};
3987
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003988static const struct cipher_info ciphers_group_mgmt[] = {
3989 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
3990 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
3991 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
3992 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
3993};
3994
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003995
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003996static int ctrl_iface_get_capability_pairwise(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003997 struct wpa_driver_capa *capa,
3998 char *buf, size_t buflen)
3999{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004000 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004001 char *pos, *end;
4002 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004003 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004004
4005 pos = buf;
4006 end = pos + buflen;
4007
4008 if (res < 0) {
4009 if (strict)
4010 return 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07004011#ifdef CONFIG_NO_TKIP
4012 len = os_strlcpy(buf, "CCMP NONE", buflen);
4013#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004014 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004015#endif /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004016 if (len >= buflen)
4017 return -1;
4018 return len;
4019 }
4020
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004021 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4022 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
4023 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004024 pos == buf ? "" : " ",
4025 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004026 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004027 return pos - buf;
4028 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004029 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004030 }
4031
4032 return pos - buf;
4033}
4034
4035
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004036static int ctrl_iface_get_capability_group(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004037 struct wpa_driver_capa *capa,
4038 char *buf, size_t buflen)
4039{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004040 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004041 char *pos, *end;
4042 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004043 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004044
4045 pos = buf;
4046 end = pos + buflen;
4047
4048 if (res < 0) {
4049 if (strict)
4050 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07004051#ifdef CONFIG_WEP
Hai Shalomb755a2a2020-04-23 21:49:02 -07004052#ifdef CONFIG_NO_TKIP
4053 len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen);
4054#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004055 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004056#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004057#else /* CONFIG_WEP */
Hai Shalomb755a2a2020-04-23 21:49:02 -07004058#ifdef CONFIG_NO_TKIP
4059 len = os_strlcpy(buf, "CCMP", buflen);
4060#else /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004061 len = os_strlcpy(buf, "CCMP TKIP", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004062#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004063#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004064 if (len >= buflen)
4065 return -1;
4066 return len;
4067 }
4068
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004069 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4070 if (capa->enc & ciphers[i].capa) {
4071 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004072 pos == buf ? "" : " ",
4073 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004074 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004075 return pos - buf;
4076 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004077 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004078 }
4079
4080 return pos - buf;
4081}
4082
4083
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004084static int ctrl_iface_get_capability_group_mgmt(int res, bool strict,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004085 struct wpa_driver_capa *capa,
4086 char *buf, size_t buflen)
4087{
4088 int ret;
4089 char *pos, *end;
4090 unsigned int i;
4091
4092 pos = buf;
4093 end = pos + buflen;
4094
4095 if (res < 0)
4096 return 0;
4097
4098 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
4099 if (capa->enc & ciphers_group_mgmt[i].capa) {
4100 ret = os_snprintf(pos, end - pos, "%s%s",
4101 pos == buf ? "" : " ",
4102 ciphers_group_mgmt[i].name);
4103 if (os_snprintf_error(end - pos, ret))
4104 return pos - buf;
4105 pos += ret;
4106 }
4107 }
4108
4109 return pos - buf;
4110}
4111
4112
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004113static int iftype_str_to_index(const char *iftype_str)
4114{
4115 if (!iftype_str)
4116 return WPA_IF_MAX;
4117
4118 if (os_strcmp(iftype_str, "STATION") == 0)
4119 return WPA_IF_STATION;
4120
4121 if (os_strcmp(iftype_str, "AP_VLAN") == 0)
4122 return WPA_IF_AP_VLAN;
4123
4124 if (os_strcmp(iftype_str, "AP") == 0)
4125 return WPA_IF_AP_BSS;
4126
4127 if (os_strcmp(iftype_str, "P2P_GO") == 0)
4128 return WPA_IF_P2P_GO;
4129
4130 if (os_strcmp(iftype_str, "P2P_CLIENT") == 0)
4131 return WPA_IF_P2P_CLIENT;
4132
4133 if (os_strcmp(iftype_str, "P2P_DEVICE") == 0)
4134 return WPA_IF_P2P_DEVICE;
4135
4136 if (os_strcmp(iftype_str, "MESH") == 0)
4137 return WPA_IF_MESH;
4138
4139 if (os_strcmp(iftype_str, "IBSS") == 0)
4140 return WPA_IF_IBSS;
4141
4142 if (os_strcmp(iftype_str, "NAN") == 0)
4143 return WPA_IF_NAN;
4144
4145 return WPA_IF_MAX;
4146}
4147
4148
4149static int ctrl_iface_get_capability_key_mgmt(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004150 struct wpa_driver_capa *capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004151 const char *iftype_str,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004152 char *buf, size_t buflen)
4153{
4154 int ret;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004155 unsigned int key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004156 char *pos, *end;
4157 size_t len;
4158
4159 pos = buf;
4160 end = pos + buflen;
4161
4162 if (res < 0) {
4163 if (strict)
4164 return 0;
4165 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4166 "NONE", buflen);
4167 if (len >= buflen)
4168 return -1;
4169 return len;
4170 }
4171
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004172 if (iftype_str) {
4173 enum wpa_driver_if_type iftype;
4174
4175 iftype = iftype_str_to_index(iftype_str);
4176 if (iftype == WPA_IF_MAX)
4177 return -1;
4178 key_mgmt = capa->key_mgmt_iftype[iftype];
4179 } else {
4180 key_mgmt = capa->key_mgmt;
4181 }
4182
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004183 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004184 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004185 return pos - buf;
4186 pos += ret;
4187
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004188 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4189 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004190 ret = os_snprintf(pos, end - pos, " WPA-EAP");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004191 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004192 return pos - buf;
4193 pos += ret;
4194 }
4195
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004196 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
4197 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004198 ret = os_snprintf(pos, end - pos, " WPA-PSK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004199 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004200 return pos - buf;
4201 pos += ret;
4202 }
4203
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004204 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004205 ret = os_snprintf(pos, end - pos, " WPA-NONE");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004206 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004207 return pos - buf;
4208 pos += ret;
4209 }
4210
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304211 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WAPI_PSK) {
4212 ret = os_snprintf(pos, end - pos, " WAPI-PSK");
4213 if (os_snprintf_error(end - pos, ret))
4214 return pos - buf;
4215 pos += ret;
4216 }
4217
4218 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE) {
4219 ret = os_snprintf(pos, end - pos, " TPK-HANDSHAKE");
4220 if (os_snprintf_error(end - pos, ret))
4221 return pos - buf;
4222 pos += ret;
4223 }
4224
4225 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_CCKM) {
4226 ret = os_snprintf(pos, end - pos, " CCKM");
4227 if (os_snprintf_error(end - pos, ret))
4228 return pos - buf;
4229 pos += ret;
4230 }
4231
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004232#ifdef CONFIG_SUITEB
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004233 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004234 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
4235 if (os_snprintf_error(end - pos, ret))
4236 return pos - buf;
4237 pos += ret;
4238 }
4239#endif /* CONFIG_SUITEB */
4240#ifdef CONFIG_SUITEB192
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004241 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004242 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
4243 if (os_snprintf_error(end - pos, ret))
4244 return pos - buf;
4245 pos += ret;
4246 }
4247#endif /* CONFIG_SUITEB192 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004248#ifdef CONFIG_OWE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004249 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004250 ret = os_snprintf(pos, end - pos, " OWE");
4251 if (os_snprintf_error(end - pos, ret))
4252 return pos - buf;
4253 pos += ret;
4254 }
4255#endif /* CONFIG_OWE */
4256#ifdef CONFIG_DPP
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004257 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004258 ret = os_snprintf(pos, end - pos, " DPP");
4259 if (os_snprintf_error(end - pos, ret))
4260 return pos - buf;
4261 pos += ret;
4262 }
4263#endif /* CONFIG_DPP */
4264#ifdef CONFIG_FILS
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004265 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004266 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
4267 if (os_snprintf_error(end - pos, ret))
4268 return pos - buf;
4269 pos += ret;
4270 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004271 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004272 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
4273 if (os_snprintf_error(end - pos, ret))
4274 return pos - buf;
4275 pos += ret;
4276 }
4277#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004278 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004279 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
4280 if (os_snprintf_error(end - pos, ret))
4281 return pos - buf;
4282 pos += ret;
4283 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004284 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004285 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
4286 if (os_snprintf_error(end - pos, ret))
4287 return pos - buf;
4288 pos += ret;
4289 }
4290#endif /* CONFIG_IEEE80211R */
4291#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08004292#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004293 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004294 ret = os_snprintf(pos, end - pos, " FT-PSK");
4295 if (os_snprintf_error(end - pos, ret))
4296 return pos - buf;
4297 pos += ret;
4298 }
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304299 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) {
4300 ret = os_snprintf(pos, end - pos, " FT-EAP");
4301 if (os_snprintf_error(end - pos, ret))
4302 return pos - buf;
4303 pos += ret;
4304 }
4305#ifdef CONFIG_SAE
4306 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE) {
4307 ret = os_snprintf(pos, end - pos, " FT-SAE");
4308 if (os_snprintf_error(end - pos, ret))
4309 return pos - buf;
4310 pos += ret;
4311 }
4312#endif /* CONFIG_SAE */
4313#ifdef CONFIG_SHA384
4314 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384) {
4315 ret = os_snprintf(pos, end - pos, " FT-EAP-SHA384");
4316 if (os_snprintf_error(end - pos, ret))
4317 return pos - buf;
4318 pos += ret;
4319 }
4320#endif /* CONFIG_SHA384 */
Hai Shalom74f70d42019-02-11 14:42:39 -08004321#endif /* CONFIG_IEEE80211R */
4322#ifdef CONFIG_SAE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004323 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004324 ret = os_snprintf(pos, end - pos, " SAE");
4325 if (os_snprintf_error(end - pos, ret))
4326 return pos - buf;
4327 pos += ret;
4328 }
4329#endif /* CONFIG_SAE */
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304330#ifdef CONFIG_SHA256
4331 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256) {
4332 ret = os_snprintf(pos, end - pos, " WPA-EAP-SHA256");
4333 if (os_snprintf_error(end - pos, ret))
4334 return pos - buf;
4335 pos += ret;
4336 }
4337
4338 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256) {
4339 ret = os_snprintf(pos, end - pos, " WPA-PSK-SHA256");
4340 if (os_snprintf_error(end - pos, ret))
4341 return pos - buf;
4342 pos += ret;
4343 }
4344#endif /* CONFIG_SHA256 */
4345#ifdef CONFIG_HS20
4346 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OSEN) {
4347 ret = os_snprintf(pos, end - pos, " OSEN");
4348 if (os_snprintf_error(end - pos, ret))
4349 return pos - buf;
4350 pos += ret;
4351 }
4352#endif /* CONFIG_HS20 */
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004353
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004354 return pos - buf;
4355}
4356
4357
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004358static int ctrl_iface_get_capability_proto(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004359 struct wpa_driver_capa *capa,
4360 char *buf, size_t buflen)
4361{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004362 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004363 char *pos, *end;
4364 size_t len;
4365
4366 pos = buf;
4367 end = pos + buflen;
4368
4369 if (res < 0) {
4370 if (strict)
4371 return 0;
4372 len = os_strlcpy(buf, "RSN WPA", buflen);
4373 if (len >= buflen)
4374 return -1;
4375 return len;
4376 }
4377
4378 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4379 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004380 ret = os_snprintf(pos, end - pos, "%sRSN",
4381 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004382 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004383 return pos - buf;
4384 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004385 }
4386
4387 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4388 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004389 ret = os_snprintf(pos, end - pos, "%sWPA",
4390 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004391 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004392 return pos - buf;
4393 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004394 }
4395
4396 return pos - buf;
4397}
4398
4399
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004400static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004401 int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004402 struct wpa_driver_capa *capa,
4403 char *buf, size_t buflen)
4404{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004405 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004406 char *pos, *end;
4407 size_t len;
4408
4409 pos = buf;
4410 end = pos + buflen;
4411
4412 if (res < 0) {
4413 if (strict)
4414 return 0;
4415 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4416 if (len >= buflen)
4417 return -1;
4418 return len;
4419 }
4420
4421 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004422 ret = os_snprintf(pos, end - pos, "%sOPEN",
4423 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004424 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004425 return pos - buf;
4426 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004427 }
4428
4429 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4430 ret = os_snprintf(pos, end - pos, "%sSHARED",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004431 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004432 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004433 return pos - buf;
4434 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004435 }
4436
4437 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004438 ret = os_snprintf(pos, end - pos, "%sLEAP",
4439 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004440 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004441 return pos - buf;
4442 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004443 }
4444
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004445#ifdef CONFIG_SAE
4446 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4447 ret = os_snprintf(pos, end - pos, "%sSAE",
4448 pos == buf ? "" : " ");
4449 if (os_snprintf_error(end - pos, ret))
4450 return pos - buf;
4451 pos += ret;
4452 }
4453#endif /* CONFIG_SAE */
4454
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004455#ifdef CONFIG_FILS
4456 if (wpa_is_fils_supported(wpa_s)) {
4457 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4458 pos == buf ? "" : " ");
4459 if (os_snprintf_error(end - pos, ret))
4460 return pos - buf;
4461 pos += ret;
4462 }
4463
4464#ifdef CONFIG_FILS_SK_PFS
4465 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4466 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4467 pos == buf ? "" : " ");
4468 if (os_snprintf_error(end - pos, ret))
4469 return pos - buf;
4470 pos += ret;
4471 }
4472#endif /* CONFIG_FILS_SK_PFS */
4473#endif /* CONFIG_FILS */
4474
Hai Shalom60840252021-02-19 19:02:11 -08004475#ifdef CONFIG_PASN
4476 ret = os_snprintf(pos, end - pos, "%sPASN",
4477 pos == buf ? "" : " ");
4478 if (os_snprintf_error(end - pos, ret))
4479 return pos - buf;
4480 pos += ret;
4481
4482#endif /* CONFIG_PASN */
4483
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004484 return pos - buf;
4485}
4486
4487
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004488static int ctrl_iface_get_capability_modes(int res, bool strict,
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004489 struct wpa_driver_capa *capa,
4490 char *buf, size_t buflen)
4491{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004492 int ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004493 char *pos, *end;
4494 size_t len;
4495
4496 pos = buf;
4497 end = pos + buflen;
4498
4499 if (res < 0) {
4500 if (strict)
4501 return 0;
4502 len = os_strlcpy(buf, "IBSS AP", buflen);
4503 if (len >= buflen)
4504 return -1;
4505 return len;
4506 }
4507
4508 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004509 ret = os_snprintf(pos, end - pos, "%sIBSS",
4510 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004511 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004512 return pos - buf;
4513 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004514 }
4515
4516 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004517 ret = os_snprintf(pos, end - pos, "%sAP",
4518 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004519 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004520 return pos - buf;
4521 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004522 }
4523
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004524#ifdef CONFIG_MESH
4525 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4526 ret = os_snprintf(pos, end - pos, "%sMESH",
4527 pos == buf ? "" : " ");
4528 if (os_snprintf_error(end - pos, ret))
4529 return pos - buf;
4530 pos += ret;
4531 }
4532#endif /* CONFIG_MESH */
4533
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004534 return pos - buf;
4535}
4536
4537
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004538static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4539 char *buf, size_t buflen)
4540{
4541 struct hostapd_channel_data *chnl;
4542 int ret, i, j;
4543 char *pos, *end, *hmode;
4544
4545 pos = buf;
4546 end = pos + buflen;
4547
4548 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4549 switch (wpa_s->hw.modes[j].mode) {
4550 case HOSTAPD_MODE_IEEE80211B:
4551 hmode = "B";
4552 break;
4553 case HOSTAPD_MODE_IEEE80211G:
4554 hmode = "G";
4555 break;
4556 case HOSTAPD_MODE_IEEE80211A:
4557 hmode = "A";
4558 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004559 case HOSTAPD_MODE_IEEE80211AD:
4560 hmode = "AD";
4561 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004562 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004563 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004564 }
4565 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004566 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004567 return pos - buf;
4568 pos += ret;
4569 chnl = wpa_s->hw.modes[j].channels;
4570 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004571 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4572 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004573 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004574 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004575 return pos - buf;
4576 pos += ret;
4577 }
4578 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004579 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004580 return pos - buf;
4581 pos += ret;
4582 }
4583
4584 return pos - buf;
4585}
4586
4587
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004588static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4589 char *buf, size_t buflen)
4590{
4591 struct hostapd_channel_data *chnl;
4592 int ret, i, j;
4593 char *pos, *end, *hmode;
4594
4595 pos = buf;
4596 end = pos + buflen;
4597
4598 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4599 switch (wpa_s->hw.modes[j].mode) {
4600 case HOSTAPD_MODE_IEEE80211B:
4601 hmode = "B";
4602 break;
4603 case HOSTAPD_MODE_IEEE80211G:
4604 hmode = "G";
4605 break;
4606 case HOSTAPD_MODE_IEEE80211A:
4607 hmode = "A";
4608 break;
4609 case HOSTAPD_MODE_IEEE80211AD:
4610 hmode = "AD";
4611 break;
4612 default:
4613 continue;
4614 }
4615 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4616 hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004617 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004618 return pos - buf;
4619 pos += ret;
4620 chnl = wpa_s->hw.modes[j].channels;
4621 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4622 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4623 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004624 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004625 chnl[i].chan, chnl[i].freq,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004626 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4627 " (NO_IR)" : "",
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004628 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4629 " (DFS)" : "");
4630
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004631 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004632 return pos - buf;
4633 pos += ret;
4634 }
4635 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004636 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004637 return pos - buf;
4638 pos += ret;
4639 }
4640
4641 return pos - buf;
4642}
4643
4644
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004645static int wpa_supplicant_ctrl_iface_get_capability(
4646 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4647 size_t buflen)
4648{
4649 struct wpa_driver_capa capa;
4650 int res;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004651 char *next_param, *curr_param, *iftype = NULL;
4652 bool strict = false;
4653 char field[50];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004654 size_t len;
4655
4656 /* Determine whether or not strict checking was requested */
4657 len = os_strlcpy(field, _field, sizeof(field));
4658 if (len >= sizeof(field))
4659 return -1;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004660
4661 next_param = os_strchr(field, ' ');
4662 while (next_param) {
4663 *next_param++ = '\0';
4664 curr_param = next_param;
4665 next_param = os_strchr(next_param, ' ');
4666
4667 if (next_param)
4668 *next_param = '\0';
4669
4670 if (os_strcmp(curr_param, "strict") == 0)
4671 strict = true;
4672 else if (os_strncmp(curr_param, "iftype=", 7) == 0)
4673 iftype = curr_param + 7;
4674 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004675 return -1;
4676 }
4677
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004678 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'%s%s%s",
4679 field, iftype ? " iftype=" : "", iftype ? iftype : "",
4680 strict ? " strict" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004681
4682 if (os_strcmp(field, "eap") == 0) {
4683 return eap_get_names(buf, buflen);
4684 }
4685
4686 res = wpa_drv_get_capa(wpa_s, &capa);
4687
4688 if (os_strcmp(field, "pairwise") == 0)
4689 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4690 buf, buflen);
4691
4692 if (os_strcmp(field, "group") == 0)
4693 return ctrl_iface_get_capability_group(res, strict, &capa,
4694 buf, buflen);
4695
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004696 if (os_strcmp(field, "group_mgmt") == 0)
4697 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4698 buf, buflen);
4699
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004700 if (os_strcmp(field, "key_mgmt") == 0)
4701 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004702 iftype, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004703
4704 if (os_strcmp(field, "proto") == 0)
4705 return ctrl_iface_get_capability_proto(res, strict, &capa,
4706 buf, buflen);
4707
4708 if (os_strcmp(field, "auth_alg") == 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004709 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4710 &capa, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004711
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004712 if (os_strcmp(field, "modes") == 0)
4713 return ctrl_iface_get_capability_modes(res, strict, &capa,
4714 buf, buflen);
4715
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004716 if (os_strcmp(field, "channels") == 0)
4717 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4718
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004719 if (os_strcmp(field, "freq") == 0)
4720 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4721
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004722#ifdef CONFIG_TDLS
4723 if (os_strcmp(field, "tdls") == 0)
4724 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4725#endif /* CONFIG_TDLS */
4726
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004727#ifdef CONFIG_ERP
4728 if (os_strcmp(field, "erp") == 0) {
4729 res = os_snprintf(buf, buflen, "ERP");
4730 if (os_snprintf_error(buflen, res))
4731 return -1;
4732 return res;
4733 }
4734#endif /* CONFIG_EPR */
4735
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004736#ifdef CONFIG_FIPS
4737 if (os_strcmp(field, "fips") == 0) {
4738 res = os_snprintf(buf, buflen, "FIPS");
4739 if (os_snprintf_error(buflen, res))
4740 return -1;
4741 return res;
4742 }
4743#endif /* CONFIG_FIPS */
4744
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004745#ifdef CONFIG_ACS
4746 if (os_strcmp(field, "acs") == 0) {
4747 res = os_snprintf(buf, buflen, "ACS");
4748 if (os_snprintf_error(buflen, res))
4749 return -1;
4750 return res;
4751 }
4752#endif /* CONFIG_ACS */
4753
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004754#ifdef CONFIG_FILS
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004755 if (os_strcmp(field, "fils") == 0) {
4756#ifdef CONFIG_FILS_SK_PFS
4757 if (wpa_is_fils_supported(wpa_s) &&
4758 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4759 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4760 if (os_snprintf_error(buflen, res))
4761 return -1;
4762 return res;
4763 }
4764#endif /* CONFIG_FILS_SK_PFS */
4765
4766 if (wpa_is_fils_supported(wpa_s)) {
4767 res = os_snprintf(buf, buflen, "FILS");
4768 if (os_snprintf_error(buflen, res))
4769 return -1;
4770 return res;
4771 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004772 }
4773#endif /* CONFIG_FILS */
4774
Hai Shalom74f70d42019-02-11 14:42:39 -08004775 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
4776 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
4777 if (os_snprintf_error(buflen, res))
4778 return -1;
4779 return res;
4780 }
4781
Hai Shalom021b0b52019-04-10 11:17:58 -07004782#ifdef CONFIG_DPP
4783 if (os_strcmp(field, "dpp") == 0) {
Hai Shaloma20dcd72022-02-04 13:43:00 -08004784#ifdef CONFIG_DPP3
4785 res = os_snprintf(buf, buflen, "DPP=3");
4786#elif defined(CONFIG_DPP2)
Hai Shalom021b0b52019-04-10 11:17:58 -07004787 res = os_snprintf(buf, buflen, "DPP=2");
4788#else /* CONFIG_DPP2 */
4789 res = os_snprintf(buf, buflen, "DPP=1");
4790#endif /* CONFIG_DPP2 */
4791 if (os_snprintf_error(buflen, res))
4792 return -1;
4793 return res;
4794 }
4795#endif /* CONFIG_DPP */
4796
Hai Shalom899fcc72020-10-19 14:38:18 -07004797#ifdef CONFIG_SAE
4798 if (os_strcmp(field, "sae") == 0 &&
4799 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4800#ifdef CONFIG_SAE_PK
4801 res = os_snprintf(buf, buflen, "H2E PK");
4802#else /* CONFIG_SAE_PK */
4803 res = os_snprintf(buf, buflen, "H2E");
4804#endif /* CONFIG_SAE_PK */
4805 if (os_snprintf_error(buflen, res))
4806 return -1;
4807 return res;
4808 }
4809#endif /* CONFIG_SAE */
4810
Hai Shalom60840252021-02-19 19:02:11 -08004811#ifdef CONFIG_OCV
4812 if (os_strcmp(field, "ocv") == 0) {
4813 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
4814 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV))
4815 res = os_snprintf(buf, buflen, "supported");
4816 else
4817 res = os_snprintf(buf, buflen, "not supported");
4818 if (os_snprintf_error(buflen, res))
4819 return -1;
4820 return res;
4821 }
4822#endif /* CONFIG_OCV */
4823
4824 if (os_strcmp(field, "beacon_prot") == 0) {
4825 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) ||
4826 (wpa_s->drv_flags2 &
4827 WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT))
4828 res = os_snprintf(buf, buflen, "supported");
4829 else
4830 res = os_snprintf(buf, buflen, "not supported");
4831 if (os_snprintf_error(buflen, res))
4832 return -1;
4833 return res;
4834 }
4835
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004836 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4837 field);
4838
4839 return -1;
4840}
4841
4842
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004843#ifdef CONFIG_INTERWORKING
4844static char * anqp_add_hex(char *pos, char *end, const char *title,
4845 struct wpabuf *data)
4846{
4847 char *start = pos;
4848 size_t i;
4849 int ret;
4850 const u8 *d;
4851
4852 if (data == NULL)
4853 return start;
4854
4855 ret = os_snprintf(pos, end - pos, "%s=", title);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004856 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004857 return start;
4858 pos += ret;
4859
4860 d = wpabuf_head_u8(data);
4861 for (i = 0; i < wpabuf_len(data); i++) {
4862 ret = os_snprintf(pos, end - pos, "%02x", *d++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004863 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004864 return start;
4865 pos += ret;
4866 }
4867
4868 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004869 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004870 return start;
4871 pos += ret;
4872
4873 return pos;
4874}
4875#endif /* CONFIG_INTERWORKING */
4876
4877
Dmitry Shmidt29333592017-01-09 12:27:11 -08004878#ifdef CONFIG_FILS
4879static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4880{
4881 char *start = pos;
4882 const u8 *ie, *ie_end;
4883 u16 info, realms;
4884 int ret;
4885
4886 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4887 if (!ie)
4888 return 0;
4889 ie_end = ie + 2 + ie[1];
4890 ie += 2;
4891 if (ie_end - ie < 2)
4892 return -1;
4893
4894 info = WPA_GET_LE16(ie);
4895 ie += 2;
4896 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4897 if (os_snprintf_error(end - pos, ret))
4898 return 0;
4899 pos += ret;
4900
4901 if (info & BIT(7)) {
4902 /* Cache Identifier Included */
4903 if (ie_end - ie < 2)
4904 return -1;
4905 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4906 ie[0], ie[1]);
4907 if (os_snprintf_error(end - pos, ret))
4908 return 0;
4909 pos += ret;
4910 ie += 2;
4911 }
4912
4913 if (info & BIT(8)) {
4914 /* HESSID Included */
4915 if (ie_end - ie < ETH_ALEN)
4916 return -1;
4917 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4918 MAC2STR(ie));
4919 if (os_snprintf_error(end - pos, ret))
4920 return 0;
4921 pos += ret;
4922 ie += ETH_ALEN;
4923 }
4924
4925 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4926 if (realms) {
4927 if (ie_end - ie < realms * 2)
4928 return -1;
4929 ret = os_snprintf(pos, end - pos, "fils_realms=");
4930 if (os_snprintf_error(end - pos, ret))
4931 return 0;
4932 pos += ret;
4933
4934 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
4935 if (ret <= 0)
4936 return 0;
4937 pos += ret;
4938 ie += realms * 2;
4939 ret = os_snprintf(pos, end - pos, "\n");
4940 if (os_snprintf_error(end - pos, ret))
4941 return 0;
4942 pos += ret;
4943 }
4944
4945 return pos - start;
4946}
4947#endif /* CONFIG_FILS */
4948
4949
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004950static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
4951 unsigned long mask, char *buf, size_t buflen)
4952{
4953 size_t i;
4954 int ret;
4955 char *pos, *end;
Hai Shalom899fcc72020-10-19 14:38:18 -07004956 const u8 *ie, *ie2, *osen_ie, *mesh, *owe, *rsnxe;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004957
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004958 pos = buf;
4959 end = buf + buflen;
4960
4961 if (mask & WPA_BSS_MASK_ID) {
4962 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004963 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004964 return 0;
4965 pos += ret;
4966 }
4967
4968 if (mask & WPA_BSS_MASK_BSSID) {
4969 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
4970 MAC2STR(bss->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004971 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004972 return 0;
4973 pos += ret;
4974 }
4975
4976 if (mask & WPA_BSS_MASK_FREQ) {
4977 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004978 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004979 return 0;
4980 pos += ret;
4981 }
4982
4983 if (mask & WPA_BSS_MASK_BEACON_INT) {
4984 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
4985 bss->beacon_int);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004986 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004987 return 0;
4988 pos += ret;
4989 }
4990
4991 if (mask & WPA_BSS_MASK_CAPABILITIES) {
4992 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
4993 bss->caps);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004994 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004995 return 0;
4996 pos += ret;
4997 }
4998
4999 if (mask & WPA_BSS_MASK_QUAL) {
5000 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005001 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005002 return 0;
5003 pos += ret;
5004 }
5005
5006 if (mask & WPA_BSS_MASK_NOISE) {
5007 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005008 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005009 return 0;
5010 pos += ret;
5011 }
5012
5013 if (mask & WPA_BSS_MASK_LEVEL) {
5014 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005015 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005016 return 0;
5017 pos += ret;
5018 }
5019
5020 if (mask & WPA_BSS_MASK_TSF) {
5021 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
5022 (unsigned long long) bss->tsf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005023 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005024 return 0;
5025 pos += ret;
5026 }
5027
5028 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005029 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005030
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005031 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005032 ret = os_snprintf(pos, end - pos, "age=%d\n",
5033 (int) (now.sec - bss->last_update.sec));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005034 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005035 return 0;
5036 pos += ret;
5037 }
5038
5039 if (mask & WPA_BSS_MASK_IE) {
5040 ret = os_snprintf(pos, end - pos, "ie=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005041 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005042 return 0;
5043 pos += ret;
5044
Hai Shalom60840252021-02-19 19:02:11 -08005045 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005046 for (i = 0; i < bss->ie_len; i++) {
5047 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005048 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005049 return 0;
5050 pos += ret;
5051 }
5052
5053 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005054 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005055 return 0;
5056 pos += ret;
5057 }
5058
5059 if (mask & WPA_BSS_MASK_FLAGS) {
5060 ret = os_snprintf(pos, end - pos, "flags=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005061 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005062 return 0;
5063 pos += ret;
5064
Dmitry Shmidt29333592017-01-09 12:27:11 -08005065 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
5066
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005067 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
5068 if (ie)
5069 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
5070 2 + ie[1]);
5071 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
5072 if (ie2)
Dmitry Shmidt29333592017-01-09 12:27:11 -08005073 pos = wpa_supplicant_ie_txt(pos, end,
5074 mesh ? "RSN" : "WPA2", ie2,
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005075 2 + ie2[1]);
Hai Shalom899fcc72020-10-19 14:38:18 -07005076 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
Hai Shaloma20dcd72022-02-04 13:43:00 -08005077 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_H2E)) {
5078 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
5079 if (os_snprintf_error(end - pos, ret))
5080 return -1;
5081 pos += ret;
5082 }
5083 if (ieee802_11_rsnx_capab(rsnxe, WLAN_RSNX_CAPAB_SAE_PK)) {
5084 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
5085 if (os_snprintf_error(end - pos, ret))
5086 return -1;
5087 pos += ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07005088 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005089 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
5090 if (osen_ie)
5091 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
5092 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005093 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
5094 if (owe) {
5095 ret = os_snprintf(
5096 pos, end - pos,
5097 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
5098 if (os_snprintf_error(end - pos, ret))
5099 return 0;
5100 pos += ret;
5101 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005102 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005103 if (!ie && !ie2 && !osen_ie &&
5104 (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005105 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005106 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005107 return 0;
5108 pos += ret;
5109 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005110
5111 if (mesh) {
5112 ret = os_snprintf(pos, end - pos, "[MESH]");
5113 if (os_snprintf_error(end - pos, ret))
5114 return 0;
5115 pos += ret;
5116 }
5117
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005118 if (bss_is_dmg(bss)) {
5119 const char *s;
5120 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005121 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005122 return 0;
5123 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005124 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
5125 case IEEE80211_CAP_DMG_IBSS:
5126 s = "[IBSS]";
5127 break;
5128 case IEEE80211_CAP_DMG_AP:
5129 s = "[ESS]";
5130 break;
5131 case IEEE80211_CAP_DMG_PBSS:
5132 s = "[PBSS]";
5133 break;
5134 default:
5135 s = "";
5136 break;
5137 }
5138 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005139 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005140 return 0;
5141 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005142 } else {
5143 if (bss->caps & IEEE80211_CAP_IBSS) {
5144 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005145 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005146 return 0;
5147 pos += ret;
5148 }
5149 if (bss->caps & IEEE80211_CAP_ESS) {
5150 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005151 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005152 return 0;
5153 pos += ret;
5154 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005155 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07005156 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
5157 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005158 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005159 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005160 return 0;
5161 pos += ret;
5162 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005163#ifdef CONFIG_HS20
5164 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
5165 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005166 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005167 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005168 pos += ret;
5169 }
5170#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005171#ifdef CONFIG_FILS
5172 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
5173 ret = os_snprintf(pos, end - pos, "[FILS]");
5174 if (os_snprintf_error(end - pos, ret))
5175 return 0;
5176 pos += ret;
5177 }
5178#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08005179#ifdef CONFIG_FST
5180 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
5181 ret = os_snprintf(pos, end - pos, "[FST]");
5182 if (os_snprintf_error(end - pos, ret))
5183 return 0;
5184 pos += ret;
5185 }
5186#endif /* CONFIG_FST */
5187 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
5188 ret = os_snprintf(pos, end - pos, "[UTF-8]");
5189 if (os_snprintf_error(end - pos, ret))
5190 return 0;
5191 pos += ret;
5192 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005193
5194 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005195 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005196 return 0;
5197 pos += ret;
5198 }
5199
5200 if (mask & WPA_BSS_MASK_SSID) {
5201 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
5202 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005203 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005204 return 0;
5205 pos += ret;
5206 }
5207
5208#ifdef CONFIG_WPS
5209 if (mask & WPA_BSS_MASK_WPS_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005210 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005211 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005212 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005213 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005214 if (ret > 0)
5215 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005216 }
5217#endif /* CONFIG_WPS */
5218
5219#ifdef CONFIG_P2P
5220 if (mask & WPA_BSS_MASK_P2P_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005221 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005222 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005223 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005224 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005225 if (ret > 0)
5226 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005227 }
5228#endif /* CONFIG_P2P */
5229
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005230#ifdef CONFIG_WIFI_DISPLAY
5231 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
5232 struct wpabuf *wfd;
Hai Shalom60840252021-02-19 19:02:11 -08005233
5234 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005235 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
5236 WFD_IE_VENDOR_TYPE);
5237 if (wfd) {
5238 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005239 if (os_snprintf_error(end - pos, ret)) {
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005240 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005241 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005242 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005243 pos += ret;
5244
5245 pos += wpa_snprintf_hex(pos, end - pos,
5246 wpabuf_head(wfd),
5247 wpabuf_len(wfd));
5248 wpabuf_free(wfd);
5249
5250 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005251 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005252 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005253 pos += ret;
5254 }
5255 }
5256#endif /* CONFIG_WIFI_DISPLAY */
5257
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005258#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005259 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
5260 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005261 struct wpa_bss_anqp_elem *elem;
5262
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005263 pos = anqp_add_hex(pos, end, "anqp_capability_list",
5264 anqp->capability_list);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005265 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005266 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005267 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005268 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005269 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005270 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005271 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005272 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005273 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005274 anqp->nai_realm);
5275 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005276 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005277 anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005278 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
5279 anqp->fils_realm_info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005280#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005281 pos = anqp_add_hex(pos, end, "hs20_capability_list",
5282 anqp->hs20_capability_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005283 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005284 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005285 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005286 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005287 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005288 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005289 pos = anqp_add_hex(pos, end, "hs20_operating_class",
5290 anqp->hs20_operating_class);
5291 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
5292 anqp->hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005293 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
5294 anqp->hs20_operator_icon_metadata);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005295 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
5296 anqp->hs20_osu_providers_nai_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005297#endif /* CONFIG_HS20 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005298
5299 dl_list_for_each(elem, &anqp->anqp_elems,
5300 struct wpa_bss_anqp_elem, list) {
5301 char title[20];
5302
5303 os_snprintf(title, sizeof(title), "anqp[%u]",
5304 elem->infoid);
5305 pos = anqp_add_hex(pos, end, title, elem->payload);
Hai Shalom60840252021-02-19 19:02:11 -08005306 if (elem->protected_response) {
5307 ret = os_snprintf(pos, end - pos,
5308 "protected-anqp-info[%u]=1\n",
5309 elem->infoid);
5310 if (os_snprintf_error(end - pos, ret))
5311 return 0;
5312 pos += ret;
5313 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005314 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005315 }
5316#endif /* CONFIG_INTERWORKING */
5317
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005318#ifdef CONFIG_MESH
5319 if (mask & WPA_BSS_MASK_MESH_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005320 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005321 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005322 if (ret >= end - pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005323 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005324 if (ret > 0)
5325 pos += ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005326 }
5327#endif /* CONFIG_MESH */
5328
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005329 if (mask & WPA_BSS_MASK_SNR) {
5330 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
5331 if (os_snprintf_error(end - pos, ret))
5332 return 0;
5333 pos += ret;
5334 }
5335
5336 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
5337 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
5338 bss->est_throughput);
5339 if (os_snprintf_error(end - pos, ret))
5340 return 0;
5341 pos += ret;
5342 }
5343
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005344#ifdef CONFIG_FST
5345 if (mask & WPA_BSS_MASK_FST) {
5346 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
5347 if (ret < 0 || ret >= end - pos)
5348 return 0;
5349 pos += ret;
5350 }
5351#endif /* CONFIG_FST */
5352
Dmitry Shmidt29333592017-01-09 12:27:11 -08005353 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
5354 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
5355 bss->last_update_idx);
5356 if (os_snprintf_error(end - pos, ret))
5357 return 0;
5358 pos += ret;
5359 }
5360
5361 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
5362 ret = os_snprintf(pos, end - pos, "beacon_ie=");
5363 if (os_snprintf_error(end - pos, ret))
5364 return 0;
5365 pos += ret;
5366
Hai Shalom60840252021-02-19 19:02:11 -08005367 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005368 ie += bss->ie_len;
5369 for (i = 0; i < bss->beacon_ie_len; i++) {
5370 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
5371 if (os_snprintf_error(end - pos, ret))
5372 return 0;
5373 pos += ret;
5374 }
5375
5376 ret = os_snprintf(pos, end - pos, "\n");
5377 if (os_snprintf_error(end - pos, ret))
5378 return 0;
5379 pos += ret;
5380 }
5381
5382#ifdef CONFIG_FILS
5383 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
5384 ret = print_fils_indication(bss, pos, end);
5385 if (ret < 0)
5386 return 0;
5387 pos += ret;
5388 }
5389#endif /* CONFIG_FILS */
5390
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005391 if (mask & WPA_BSS_MASK_DELIM) {
5392 ret = os_snprintf(pos, end - pos, "====\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005393 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005394 return 0;
5395 pos += ret;
5396 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07005397
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005398 return pos - buf;
5399}
5400
Dmitry Shmidt04949592012-07-19 12:16:46 -07005401
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005402static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
5403 const char *cmd, char *buf,
5404 size_t buflen)
5405{
5406 u8 bssid[ETH_ALEN];
5407 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005408 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005409 struct wpa_bss *bsslast = NULL;
5410 struct dl_list *next;
5411 int ret = 0;
5412 int len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005413 char *ctmp, *end = buf + buflen;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005414 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005415
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005416 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
5417 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
5418 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005419 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005420 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
5421 list_id);
5422 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005423 unsigned int id1, id2;
5424
5425 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
5426 wpa_printf(MSG_INFO, "Wrong BSS range "
5427 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005428 return 0;
5429 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005430
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005431 if (*(cmd + 6) == '-')
5432 id1 = 0;
5433 else
5434 id1 = atoi(cmd + 6);
5435 ctmp++;
5436 if (*ctmp >= '0' && *ctmp <= '9')
5437 id2 = atoi(ctmp);
5438 else
5439 id2 = (unsigned int) -1;
5440 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
5441 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005442 bsslast = dl_list_last(&wpa_s->bss_id,
5443 struct wpa_bss,
5444 list_id);
5445 else {
5446 bsslast = wpa_bss_get_id(wpa_s, id2);
5447 if (bsslast == NULL && bss && id2 > id1) {
5448 struct wpa_bss *tmp = bss;
5449 for (;;) {
5450 next = tmp->list_id.next;
5451 if (next == &wpa_s->bss_id)
5452 break;
5453 tmp = dl_list_entry(
5454 next, struct wpa_bss,
5455 list_id);
5456 if (tmp->id > id2)
5457 break;
5458 bsslast = tmp;
5459 }
5460 }
5461 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005462 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005463 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005464 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005465 else if (os_strncmp(cmd, "LAST", 4) == 0)
5466 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005467 else if (os_strncmp(cmd, "ID-", 3) == 0) {
5468 i = atoi(cmd + 3);
5469 bss = wpa_bss_get_id(wpa_s, i);
5470 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5471 i = atoi(cmd + 5);
5472 bss = wpa_bss_get_id(wpa_s, i);
5473 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005474 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005475 if (next == &wpa_s->bss_id)
5476 bss = NULL;
5477 else
5478 bss = dl_list_entry(next, struct wpa_bss,
5479 list_id);
5480 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005481 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5482 bss = wpa_s->current_bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005483#ifdef CONFIG_P2P
5484 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5485 if (hwaddr_aton(cmd + 13, bssid) == 0)
5486 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5487 else
5488 bss = NULL;
5489#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005490 } else if (hwaddr_aton(cmd, bssid) == 0)
5491 bss = wpa_bss_get_bssid(wpa_s, bssid);
5492 else {
5493 struct wpa_bss *tmp;
5494 i = atoi(cmd);
5495 bss = NULL;
5496 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5497 {
Hai Shalom021b0b52019-04-10 11:17:58 -07005498 if (i == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005499 bss = tmp;
5500 break;
5501 }
Hai Shalom021b0b52019-04-10 11:17:58 -07005502 i--;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005503 }
5504 }
5505
Dmitry Shmidt04949592012-07-19 12:16:46 -07005506 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5507 mask = strtoul(ctmp + 5, NULL, 0x10);
5508 if (mask == 0)
5509 mask = WPA_BSS_MASK_ALL;
5510 }
5511
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005512 if (bss == NULL)
5513 return 0;
5514
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005515 if (bsslast == NULL)
5516 bsslast = bss;
5517 do {
5518 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5519 ret += len;
5520 buf += len;
5521 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005522 if (bss == bsslast) {
5523 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5524 (bss == dl_list_last(&wpa_s->bss_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005525 struct wpa_bss, list_id))) {
5526 int res;
5527
5528 res = os_snprintf(buf - 5, end - buf + 5,
5529 "####\n");
5530 if (os_snprintf_error(end - buf + 5, res)) {
5531 wpa_printf(MSG_DEBUG,
5532 "Could not add end delim");
5533 }
5534 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005535 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005536 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005537 next = bss->list_id.next;
5538 if (next == &wpa_s->bss_id)
5539 break;
5540 bss = dl_list_entry(next, struct wpa_bss, list_id);
5541 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005542
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005543 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005544}
5545
5546
5547static int wpa_supplicant_ctrl_iface_ap_scan(
5548 struct wpa_supplicant *wpa_s, char *cmd)
5549{
5550 int ap_scan = atoi(cmd);
5551 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5552}
5553
5554
5555static int wpa_supplicant_ctrl_iface_scan_interval(
5556 struct wpa_supplicant *wpa_s, char *cmd)
5557{
5558 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005559 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005560}
5561
5562
5563static int wpa_supplicant_ctrl_iface_bss_expire_age(
5564 struct wpa_supplicant *wpa_s, char *cmd)
5565{
5566 int expire_age = atoi(cmd);
5567 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5568}
5569
5570
5571static int wpa_supplicant_ctrl_iface_bss_expire_count(
5572 struct wpa_supplicant *wpa_s, char *cmd)
5573{
5574 int expire_count = atoi(cmd);
5575 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5576}
5577
5578
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005579static void wpa_supplicant_ctrl_iface_bss_flush(
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005580 struct wpa_supplicant *wpa_s, char *cmd)
5581{
5582 int flush_age = atoi(cmd);
5583
5584 if (flush_age == 0)
5585 wpa_bss_flush(wpa_s);
5586 else
5587 wpa_bss_flush_by_age(wpa_s, flush_age);
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005588}
5589
5590
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005591#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005592static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5593{
5594 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5595 /* MLME-DELETEKEYS.request */
Hai Shalomfdcde762020-04-02 11:19:20 -07005596 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL,
5597 0, KEY_FLAG_GROUP);
5598 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL,
5599 0, KEY_FLAG_GROUP);
5600 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL,
5601 0, KEY_FLAG_GROUP);
5602 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL,
5603 0, KEY_FLAG_GROUP);
5604 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL,
5605 0, KEY_FLAG_GROUP);
5606 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL,
5607 0, KEY_FLAG_GROUP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005608
5609 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005610 0, KEY_FLAG_PAIRWISE);
5611 if (wpa_sm_ext_key_id(wpa_s->wpa))
5612 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 1, 0,
5613 NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005614 /* MLME-SETPROTECTION.request(None) */
5615 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5616 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5617 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5618 wpa_sm_drop_sa(wpa_s->wpa);
5619}
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005620#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005621
5622
5623static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5624 char *addr)
5625{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005626#ifdef CONFIG_NO_SCAN_PROCESSING
5627 return -1;
5628#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005629 u8 bssid[ETH_ALEN];
5630 struct wpa_bss *bss;
5631 struct wpa_ssid *ssid = wpa_s->current_ssid;
Hai Shaloma20dcd72022-02-04 13:43:00 -08005632 struct wpa_radio_work *already_connecting;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005633
5634 if (hwaddr_aton(addr, bssid)) {
5635 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5636 "address '%s'", addr);
5637 return -1;
5638 }
5639
5640 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5641
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005642 if (!ssid) {
5643 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5644 "configuration known for the target AP");
5645 return -1;
5646 }
5647
5648 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005649 if (!bss) {
5650 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
5651 "from BSS table");
5652 return -1;
5653 }
5654
5655 /*
5656 * TODO: Find best network configuration block from configuration to
5657 * allow roaming to other networks
5658 */
5659
Hai Shaloma20dcd72022-02-04 13:43:00 -08005660 already_connecting = radio_work_pending(wpa_s, "sme-connect");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005661 wpa_s->reassociate = 1;
5662 wpa_supplicant_connect(wpa_s, bss, ssid);
5663
Hai Shaloma20dcd72022-02-04 13:43:00 -08005664 /*
5665 * Indicate that an explicitly requested roam is in progress so scan
5666 * results that come in before the 'sme-connect' radio work gets
5667 * executed do not override the original connection attempt.
5668 */
5669 if (!already_connecting && radio_work_pending(wpa_s, "sme-connect"))
5670 wpa_s->roam_in_progress = true;
5671
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005672 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005673#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005674}
5675
5676
5677#ifdef CONFIG_P2P
5678static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
5679{
5680 unsigned int timeout = atoi(cmd);
5681 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005682 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005683 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005684 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005685 unsigned int search_delay;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005686 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005687 u8 seek_count = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005688 int freq = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08005689 bool include_6ghz = false;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005690
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005691 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5692 wpa_dbg(wpa_s, MSG_INFO,
5693 "Reject P2P_FIND since interface is disabled");
5694 return -1;
5695 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08005696
5697 if (os_strstr(cmd, " include_6ghz"))
5698 include_6ghz = true;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005699 if (os_strstr(cmd, "type=social"))
5700 type = P2P_FIND_ONLY_SOCIAL;
5701 else if (os_strstr(cmd, "type=progressive"))
5702 type = P2P_FIND_PROGRESSIVE;
5703
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005704 pos = os_strstr(cmd, "dev_id=");
5705 if (pos) {
5706 pos += 7;
5707 if (hwaddr_aton(pos, dev_id))
5708 return -1;
5709 _dev_id = dev_id;
5710 }
5711
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005712 pos = os_strstr(cmd, "dev_type=");
5713 if (pos) {
5714 pos += 9;
5715 if (wps_dev_type_str2bin(pos, dev_type) < 0)
5716 return -1;
5717 _dev_type = dev_type;
5718 }
5719
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005720 pos = os_strstr(cmd, "delay=");
5721 if (pos) {
5722 pos += 6;
5723 search_delay = atoi(pos);
5724 } else
5725 search_delay = wpas_p2p_search_delay(wpa_s);
5726
Dmitry Shmidt41712582015-06-29 11:02:15 -07005727 pos = os_strstr(cmd, "freq=");
5728 if (pos) {
5729 pos += 5;
5730 freq = atoi(pos);
5731 if (freq <= 0)
5732 return -1;
5733 }
5734
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005735 /* Must be searched for last, because it adds nul termination */
5736 pos = os_strstr(cmd, " seek=");
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005737 if (pos)
5738 pos += 6;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005739 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
5740 char *term;
5741
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005742 _seek[seek_count++] = pos;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005743 seek = _seek;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005744 term = os_strchr(pos, ' ');
5745 if (!term)
5746 break;
5747 *term = '\0';
5748 pos = os_strstr(term + 1, "seek=");
5749 if (pos)
5750 pos += 5;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005751 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005752 if (seek_count > P2P_MAX_QUERY_HASH) {
5753 seek[0] = NULL;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005754 seek_count = 1;
5755 }
5756
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005757 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
Hai Shaloma20dcd72022-02-04 13:43:00 -08005758 _dev_id, search_delay, seek_count, seek, freq,
5759 include_6ghz);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005760}
5761
5762
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005763static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
5764{
5765 const char *last = NULL;
5766 const char *token;
5767 long int token_len;
5768 unsigned int i;
5769
5770 /* Expected predefined CPT names delimited by ':' */
5771 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
5772 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
5773 wpa_printf(MSG_ERROR,
5774 "P2PS: CPT name list is too long, expected up to %d names",
5775 P2PS_FEATURE_CAPAB_CPT_MAX);
5776 cpt[0] = 0;
5777 return -1;
5778 }
5779
5780 token_len = last - token;
5781
5782 if (token_len == 3 &&
5783 os_memcmp(token, "UDP", token_len) == 0) {
5784 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5785 } else if (token_len == 3 &&
5786 os_memcmp(token, "MAC", token_len) == 0) {
5787 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
5788 } else {
5789 wpa_printf(MSG_ERROR,
5790 "P2PS: Unsupported CPT name '%s'", token);
5791 cpt[0] = 0;
5792 return -1;
5793 }
5794
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005795 if (isblank((unsigned char) *last)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005796 i++;
5797 break;
5798 }
5799 }
5800 cpt[i] = 0;
5801 return 0;
5802}
5803
5804
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005805static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
5806{
5807 struct p2ps_provision *p2ps_prov;
5808 char *pos;
5809 size_t info_len = 0;
5810 char *info = NULL;
5811 u8 role = P2PS_SETUP_NONE;
5812 long long unsigned val;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005813 int i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005814
5815 pos = os_strstr(cmd, "info=");
5816 if (pos) {
5817 pos += 5;
5818 info_len = os_strlen(pos);
5819
5820 if (info_len) {
5821 info = os_malloc(info_len + 1);
5822 if (info) {
5823 info_len = utf8_unescape(pos, info_len,
5824 info, info_len + 1);
5825 } else
5826 info_len = 0;
5827 }
5828 }
5829
5830 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
5831 if (p2ps_prov == NULL) {
5832 os_free(info);
5833 return NULL;
5834 }
5835
5836 if (info) {
5837 os_memcpy(p2ps_prov->info, info, info_len);
5838 p2ps_prov->info[info_len] = '\0';
5839 os_free(info);
5840 }
5841
5842 pos = os_strstr(cmd, "status=");
5843 if (pos)
5844 p2ps_prov->status = atoi(pos + 7);
5845 else
5846 p2ps_prov->status = -1;
5847
5848 pos = os_strstr(cmd, "adv_id=");
5849 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
5850 goto invalid_args;
5851 p2ps_prov->adv_id = val;
5852
5853 pos = os_strstr(cmd, "method=");
5854 if (pos)
5855 p2ps_prov->method = strtol(pos + 7, NULL, 16);
5856 else
5857 p2ps_prov->method = 0;
5858
5859 pos = os_strstr(cmd, "session=");
5860 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
5861 goto invalid_args;
5862 p2ps_prov->session_id = val;
5863
5864 pos = os_strstr(cmd, "adv_mac=");
5865 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
5866 goto invalid_args;
5867
5868 pos = os_strstr(cmd, "session_mac=");
5869 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
5870 goto invalid_args;
5871
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005872 pos = os_strstr(cmd, "cpt=");
5873 if (pos) {
5874 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
5875 p2ps_prov->cpt_priority))
5876 goto invalid_args;
5877 } else {
5878 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5879 }
5880
5881 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
5882 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
5883
Hai Shaloma20dcd72022-02-04 13:43:00 -08005884 /* force conncap with tstCap (no validity checks) */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005885 pos = os_strstr(cmd, "tstCap=");
5886 if (pos) {
5887 role = strtol(pos + 7, NULL, 16);
5888 } else {
5889 pos = os_strstr(cmd, "role=");
5890 if (pos) {
5891 role = strtol(pos + 5, NULL, 16);
5892 if (role != P2PS_SETUP_CLIENT &&
5893 role != P2PS_SETUP_GROUP_OWNER)
5894 role = P2PS_SETUP_NONE;
5895 }
5896 }
5897 p2ps_prov->role = role;
5898
5899 return p2ps_prov;
5900
5901invalid_args:
5902 os_free(p2ps_prov);
5903 return NULL;
5904}
5905
5906
5907static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
5908{
5909 u8 addr[ETH_ALEN];
5910 struct p2ps_provision *p2ps_prov;
5911 char *pos;
5912
5913 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5914
5915 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5916
5917 if (hwaddr_aton(cmd, addr))
5918 return -1;
5919
5920 pos = cmd + 17;
5921 if (*pos != ' ')
5922 return -1;
5923
5924 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5925 if (!p2ps_prov)
5926 return -1;
5927
5928 if (p2ps_prov->status < 0) {
5929 os_free(p2ps_prov);
5930 return -1;
5931 }
5932
5933 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5934 p2ps_prov);
5935}
5936
5937
5938static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
5939{
5940 u8 addr[ETH_ALEN];
5941 struct p2ps_provision *p2ps_prov;
5942 char *pos;
5943
5944 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5945 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5946 */
5947
5948 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5949 if (hwaddr_aton(cmd, addr))
5950 return -1;
5951
5952 pos = cmd + 17;
5953 if (*pos != ' ')
5954 return -1;
5955
5956 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5957 if (!p2ps_prov)
5958 return -1;
5959
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005960 p2ps_prov->pd_seeker = 1;
5961
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005962 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5963 p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005964}
5965
5966
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005967static int parse_freq(int chwidth, int freq2)
5968{
5969 if (freq2 < 0)
5970 return -1;
5971 if (freq2)
Hai Shalom81f62d82019-07-22 12:10:00 -07005972 return CHANWIDTH_80P80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005973
5974 switch (chwidth) {
5975 case 0:
5976 case 20:
5977 case 40:
Hai Shalom81f62d82019-07-22 12:10:00 -07005978 return CHANWIDTH_USE_HT;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005979 case 80:
Hai Shalom81f62d82019-07-22 12:10:00 -07005980 return CHANWIDTH_80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005981 case 160:
Hai Shalom81f62d82019-07-22 12:10:00 -07005982 return CHANWIDTH_160MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005983 default:
5984 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
5985 chwidth);
5986 return -1;
5987 }
5988}
5989
5990
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005991static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
5992 char *buf, size_t buflen)
5993{
5994 u8 addr[ETH_ALEN];
5995 char *pos, *pos2;
5996 char *pin = NULL;
5997 enum p2p_wps_method wps_method;
5998 int new_pin;
5999 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006000 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006001 int join;
6002 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006003 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006004 int go_intent = -1;
6005 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006006 int pd;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006007 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006008 int edmg;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006009 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
6010 size_t group_ssid_len = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08006011 int he;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006012 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006013
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006014 if (!wpa_s->global->p2p_init_wpa_s)
6015 return -1;
6016 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
6017 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
6018 wpa_s->global->p2p_init_wpa_s->ifname);
6019 wpa_s = wpa_s->global->p2p_init_wpa_s;
6020 }
6021
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006022 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
Dmitry Shmidt04949592012-07-19 12:16:46 -07006023 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006024 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006025 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006026
6027 if (hwaddr_aton(cmd, addr))
6028 return -1;
6029
6030 pos = cmd + 17;
6031 if (*pos != ' ')
6032 return -1;
6033 pos++;
6034
6035 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006036 pos2 = os_strstr(pos, " persistent=");
6037 if (pos2) {
6038 struct wpa_ssid *ssid;
6039 persistent_id = atoi(pos2 + 12);
6040 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
6041 if (ssid == NULL || ssid->disabled != 2 ||
6042 ssid->mode != WPAS_MODE_P2P_GO) {
6043 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
6044 "SSID id=%d for persistent P2P group (GO)",
6045 persistent_id);
6046 return -1;
6047 }
6048 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006049 join = os_strstr(pos, " join") != NULL;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006050 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006051 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006052 automatic = os_strstr(pos, " auto") != NULL;
6053 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006054 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6055 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6056 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006057 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006058 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006059
6060 pos2 = os_strstr(pos, " go_intent=");
6061 if (pos2) {
6062 pos2 += 11;
6063 go_intent = atoi(pos2);
6064 if (go_intent < 0 || go_intent > 15)
6065 return -1;
6066 }
6067
6068 pos2 = os_strstr(pos, " freq=");
6069 if (pos2) {
6070 pos2 += 6;
6071 freq = atoi(pos2);
6072 if (freq <= 0)
6073 return -1;
6074 }
6075
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006076 pos2 = os_strstr(pos, " freq2=");
6077 if (pos2)
6078 freq2 = atoi(pos2 + 7);
6079
6080 pos2 = os_strstr(pos, " max_oper_chwidth=");
6081 if (pos2)
6082 chwidth = atoi(pos2 + 18);
6083
6084 max_oper_chwidth = parse_freq(chwidth, freq2);
6085 if (max_oper_chwidth < 0)
6086 return -1;
6087
Hai Shaloma20dcd72022-02-04 13:43:00 -08006088 if (allow_6ghz && chwidth == 40)
6089 max_oper_chwidth = CHANWIDTH_40MHZ_6GHZ;
6090
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006091 pos2 = os_strstr(pos, " ssid=");
6092 if (pos2) {
6093 char *end;
6094
6095 pos2 += 6;
6096 end = os_strchr(pos2, ' ');
6097 if (!end)
6098 group_ssid_len = os_strlen(pos2) / 2;
6099 else
6100 group_ssid_len = (end - pos2) / 2;
6101 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
6102 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
6103 return -1;
6104 group_ssid = _group_ssid;
6105 }
6106
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006107 if (os_strncmp(pos, "pin", 3) == 0) {
6108 /* Request random PIN (to be displayed) and enable the PIN */
6109 wps_method = WPS_PIN_DISPLAY;
6110 } else if (os_strncmp(pos, "pbc", 3) == 0) {
6111 wps_method = WPS_PBC;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006112 } else if (os_strstr(pos, "p2ps") != NULL) {
6113 wps_method = WPS_P2PS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006114 } else {
6115 pin = pos;
6116 pos = os_strchr(pin, ' ');
6117 wps_method = WPS_PIN_KEYPAD;
6118 if (pos) {
6119 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006120 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006121 wps_method = WPS_PIN_DISPLAY;
6122 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006123 if (!wps_pin_str_valid(pin)) {
6124 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
6125 return 17;
6126 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006127 }
6128
6129 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006130 persistent_group, automatic, join,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006131 auth, go_intent, freq, freq2, persistent_id,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006132 pd, ht40, vht, max_oper_chwidth, he, edmg,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006133 group_ssid, group_ssid_len, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006134 if (new_pin == -2) {
6135 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
6136 return 25;
6137 }
6138 if (new_pin == -3) {
6139 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
6140 return 25;
6141 }
6142 if (new_pin < 0)
6143 return -1;
6144 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
6145 ret = os_snprintf(buf, buflen, "%08d", new_pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006146 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006147 return -1;
6148 return ret;
6149 }
6150
6151 os_memcpy(buf, "OK\n", 3);
6152 return 3;
6153}
6154
6155
6156static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
6157{
6158 unsigned int timeout = atoi(cmd);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006159 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6160 wpa_dbg(wpa_s, MSG_INFO,
6161 "Reject P2P_LISTEN since interface is disabled");
6162 return -1;
6163 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006164 return wpas_p2p_listen(wpa_s, timeout);
6165}
6166
6167
6168static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
6169{
6170 u8 addr[ETH_ALEN];
6171 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006172 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006173
Dmitry Shmidt04949592012-07-19 12:16:46 -07006174 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006175
6176 if (hwaddr_aton(cmd, addr))
6177 return -1;
6178
6179 pos = cmd + 17;
6180 if (*pos != ' ')
6181 return -1;
6182 pos++;
6183
Dmitry Shmidt04949592012-07-19 12:16:46 -07006184 if (os_strstr(pos, " join") != NULL)
6185 use = WPAS_P2P_PD_FOR_JOIN;
6186 else if (os_strstr(pos, " auto") != NULL)
6187 use = WPAS_P2P_PD_AUTO;
6188
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006189 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006190}
6191
6192
6193static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
6194 size_t buflen)
6195{
6196 struct wpa_ssid *ssid = wpa_s->current_ssid;
6197
6198 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
6199 ssid->passphrase == NULL)
6200 return -1;
6201
6202 os_strlcpy(buf, ssid->passphrase, buflen);
6203 return os_strlen(buf);
6204}
6205
6206
6207static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
6208 char *buf, size_t buflen)
6209{
6210 u64 ref;
6211 int res;
6212 u8 dst_buf[ETH_ALEN], *dst;
6213 struct wpabuf *tlvs;
6214 char *pos;
6215 size_t len;
6216
6217 if (hwaddr_aton(cmd, dst_buf))
6218 return -1;
6219 dst = dst_buf;
6220 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
6221 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
6222 dst = NULL;
6223 pos = cmd + 17;
6224 if (*pos != ' ')
6225 return -1;
6226 pos++;
6227
6228 if (os_strncmp(pos, "upnp ", 5) == 0) {
6229 u8 version;
6230 pos += 5;
6231 if (hexstr2bin(pos, &version, 1) < 0)
6232 return -1;
6233 pos += 2;
6234 if (*pos != ' ')
6235 return -1;
6236 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006237 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006238#ifdef CONFIG_WIFI_DISPLAY
6239 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
6240 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
6241#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006242 } else if (os_strncmp(pos, "asp ", 4) == 0) {
6243 char *svc_str;
6244 char *svc_info = NULL;
6245 u32 id;
6246
6247 pos += 4;
6248 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
6249 return -1;
6250
6251 pos = os_strchr(pos, ' ');
6252 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
6253 return -1;
6254
6255 svc_str = pos + 1;
6256
6257 pos = os_strchr(svc_str, ' ');
6258
6259 if (pos)
6260 *pos++ = '\0';
6261
6262 /* All remaining data is the svc_info string */
6263 if (pos && pos[0] && pos[0] != ' ') {
6264 len = os_strlen(pos);
6265
6266 /* Unescape in place */
6267 len = utf8_unescape(pos, len, pos, len);
6268 if (len > 0xff)
6269 return -1;
6270
6271 svc_info = pos;
6272 }
6273
6274 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
6275 svc_str, svc_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006276 } else {
6277 len = os_strlen(pos);
6278 if (len & 1)
6279 return -1;
6280 len /= 2;
6281 tlvs = wpabuf_alloc(len);
6282 if (tlvs == NULL)
6283 return -1;
6284 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
6285 wpabuf_free(tlvs);
6286 return -1;
6287 }
6288
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006289 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006290 wpabuf_free(tlvs);
6291 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006292 if (ref == 0)
6293 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006294 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006295 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006296 return -1;
6297 return res;
6298}
6299
6300
6301static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
6302 char *cmd)
6303{
6304 long long unsigned val;
6305 u64 req;
6306 if (sscanf(cmd, "%llx", &val) != 1)
6307 return -1;
6308 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006309 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006310}
6311
6312
6313static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
6314{
6315 int freq;
6316 u8 dst[ETH_ALEN];
6317 u8 dialog_token;
6318 struct wpabuf *resp_tlvs;
6319 char *pos, *pos2;
6320 size_t len;
6321
6322 pos = os_strchr(cmd, ' ');
6323 if (pos == NULL)
6324 return -1;
6325 *pos++ = '\0';
6326 freq = atoi(cmd);
6327 if (freq == 0)
6328 return -1;
6329
6330 if (hwaddr_aton(pos, dst))
6331 return -1;
6332 pos += 17;
6333 if (*pos != ' ')
6334 return -1;
6335 pos++;
6336
6337 pos2 = os_strchr(pos, ' ');
6338 if (pos2 == NULL)
6339 return -1;
6340 *pos2++ = '\0';
6341 dialog_token = atoi(pos);
6342
6343 len = os_strlen(pos2);
6344 if (len & 1)
6345 return -1;
6346 len /= 2;
6347 resp_tlvs = wpabuf_alloc(len);
6348 if (resp_tlvs == NULL)
6349 return -1;
6350 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
6351 wpabuf_free(resp_tlvs);
6352 return -1;
6353 }
6354
6355 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
6356 wpabuf_free(resp_tlvs);
6357 return 0;
6358}
6359
6360
6361static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
6362 char *cmd)
6363{
Dmitry Shmidt04949592012-07-19 12:16:46 -07006364 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
6365 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006366 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
6367 return 0;
6368}
6369
6370
6371static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
6372 char *cmd)
6373{
6374 char *pos;
6375 size_t len;
6376 struct wpabuf *query, *resp;
6377
6378 pos = os_strchr(cmd, ' ');
6379 if (pos == NULL)
6380 return -1;
6381 *pos++ = '\0';
6382
6383 len = os_strlen(cmd);
6384 if (len & 1)
6385 return -1;
6386 len /= 2;
6387 query = wpabuf_alloc(len);
6388 if (query == NULL)
6389 return -1;
6390 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6391 wpabuf_free(query);
6392 return -1;
6393 }
6394
6395 len = os_strlen(pos);
6396 if (len & 1) {
6397 wpabuf_free(query);
6398 return -1;
6399 }
6400 len /= 2;
6401 resp = wpabuf_alloc(len);
6402 if (resp == NULL) {
6403 wpabuf_free(query);
6404 return -1;
6405 }
6406 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
6407 wpabuf_free(query);
6408 wpabuf_free(resp);
6409 return -1;
6410 }
6411
6412 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
6413 wpabuf_free(query);
6414 wpabuf_free(resp);
6415 return -1;
6416 }
6417 return 0;
6418}
6419
6420
6421static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6422{
6423 char *pos;
6424 u8 version;
6425
6426 pos = os_strchr(cmd, ' ');
6427 if (pos == NULL)
6428 return -1;
6429 *pos++ = '\0';
6430
6431 if (hexstr2bin(cmd, &version, 1) < 0)
6432 return -1;
6433
6434 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
6435}
6436
6437
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006438static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
6439 u8 replace, char *cmd)
6440{
6441 char *pos;
6442 char *adv_str;
6443 u32 auto_accept, adv_id, svc_state, config_methods;
6444 char *svc_info = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006445 char *cpt_prio_str;
6446 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006447
6448 pos = os_strchr(cmd, ' ');
6449 if (pos == NULL)
6450 return -1;
6451 *pos++ = '\0';
6452
6453 /* Auto-Accept value is mandatory, and must be one of the
6454 * single values (0, 1, 2, 4) */
6455 auto_accept = atoi(cmd);
6456 switch (auto_accept) {
6457 case P2PS_SETUP_NONE: /* No auto-accept */
6458 case P2PS_SETUP_NEW:
6459 case P2PS_SETUP_CLIENT:
6460 case P2PS_SETUP_GROUP_OWNER:
6461 break;
6462 default:
6463 return -1;
6464 }
6465
6466 /* Advertisement ID is mandatory */
6467 cmd = pos;
6468 pos = os_strchr(cmd, ' ');
6469 if (pos == NULL)
6470 return -1;
6471 *pos++ = '\0';
6472
6473 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6474 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
6475 return -1;
6476
6477 /* Only allow replacements if exist, and adds if not */
6478 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
6479 if (!replace)
6480 return -1;
6481 } else {
6482 if (replace)
6483 return -1;
6484 }
6485
6486 /* svc_state between 0 - 0xff is mandatory */
6487 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
6488 return -1;
6489
6490 pos = os_strchr(pos, ' ');
6491 if (pos == NULL)
6492 return -1;
6493
6494 /* config_methods is mandatory */
6495 pos++;
6496 if (sscanf(pos, "%x", &config_methods) != 1)
6497 return -1;
6498
6499 if (!(config_methods &
6500 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
6501 return -1;
6502
6503 pos = os_strchr(pos, ' ');
6504 if (pos == NULL)
6505 return -1;
6506
6507 pos++;
6508 adv_str = pos;
6509
6510 /* Advertisement string is mandatory */
6511 if (!pos[0] || pos[0] == ' ')
6512 return -1;
6513
6514 /* Terminate svc string */
6515 pos = os_strchr(pos, ' ');
6516 if (pos != NULL)
6517 *pos++ = '\0';
6518
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006519 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6520 if (cpt_prio_str) {
6521 pos = os_strchr(pos, ' ');
6522 if (pos != NULL)
6523 *pos++ = '\0';
6524
6525 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6526 return -1;
6527 } else {
6528 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6529 cpt_prio[1] = 0;
6530 }
6531
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006532 /* Service and Response Information are optional */
6533 if (pos && pos[0]) {
6534 size_t len;
6535
6536 /* Note the bare ' included, which cannot exist legally
6537 * in unescaped string. */
6538 svc_info = os_strstr(pos, "svc_info='");
6539
6540 if (svc_info) {
6541 svc_info += 9;
6542 len = os_strlen(svc_info);
6543 utf8_unescape(svc_info, len, svc_info, len);
6544 }
6545 }
6546
6547 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6548 (u8) svc_state, (u16) config_methods,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006549 svc_info, cpt_prio);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006550}
6551
6552
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006553static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6554{
6555 char *pos;
6556
6557 pos = os_strchr(cmd, ' ');
6558 if (pos == NULL)
6559 return -1;
6560 *pos++ = '\0';
6561
6562 if (os_strcmp(cmd, "bonjour") == 0)
6563 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6564 if (os_strcmp(cmd, "upnp") == 0)
6565 return p2p_ctrl_service_add_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006566 if (os_strcmp(cmd, "asp") == 0)
6567 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006568 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6569 return -1;
6570}
6571
6572
6573static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6574 char *cmd)
6575{
6576 size_t len;
6577 struct wpabuf *query;
6578 int ret;
6579
6580 len = os_strlen(cmd);
6581 if (len & 1)
6582 return -1;
6583 len /= 2;
6584 query = wpabuf_alloc(len);
6585 if (query == NULL)
6586 return -1;
6587 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6588 wpabuf_free(query);
6589 return -1;
6590 }
6591
6592 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6593 wpabuf_free(query);
6594 return ret;
6595}
6596
6597
6598static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6599{
6600 char *pos;
6601 u8 version;
6602
6603 pos = os_strchr(cmd, ' ');
6604 if (pos == NULL)
6605 return -1;
6606 *pos++ = '\0';
6607
6608 if (hexstr2bin(cmd, &version, 1) < 0)
6609 return -1;
6610
6611 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6612}
6613
6614
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006615static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6616{
6617 u32 adv_id;
6618
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07006619 if (os_strcmp(cmd, "all") == 0) {
6620 wpas_p2p_service_flush_asp(wpa_s);
6621 return 0;
6622 }
6623
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006624 if (sscanf(cmd, "%x", &adv_id) != 1)
6625 return -1;
6626
6627 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6628}
6629
6630
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006631static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6632{
6633 char *pos;
6634
6635 pos = os_strchr(cmd, ' ');
6636 if (pos == NULL)
6637 return -1;
6638 *pos++ = '\0';
6639
6640 if (os_strcmp(cmd, "bonjour") == 0)
6641 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6642 if (os_strcmp(cmd, "upnp") == 0)
6643 return p2p_ctrl_service_del_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006644 if (os_strcmp(cmd, "asp") == 0)
6645 return p2p_ctrl_service_del_asp(wpa_s, pos);
6646 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6647 return -1;
6648}
6649
6650
6651static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6652{
6653 char *pos;
6654
6655 pos = os_strchr(cmd, ' ');
6656 if (pos == NULL)
6657 return -1;
6658 *pos++ = '\0';
6659
6660 if (os_strcmp(cmd, "asp") == 0)
6661 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6662
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006663 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6664 return -1;
6665}
6666
6667
6668static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
6669{
6670 u8 addr[ETH_ALEN];
6671
6672 /* <addr> */
6673
6674 if (hwaddr_aton(cmd, addr))
6675 return -1;
6676
6677 return wpas_p2p_reject(wpa_s, addr);
6678}
6679
6680
6681static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
6682{
6683 char *pos;
6684 int id;
6685 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006686 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006687 int freq = 0, pref_freq = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08006688 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006689 int edmg;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006690 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006691
6692 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006693 pos = os_strstr(cmd, " peer=");
6694 if (pos) {
6695 pos += 6;
6696 if (hwaddr_aton(pos, peer))
6697 return -1;
6698 _peer = peer;
6699 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006700 ssid = wpa_config_get_network(wpa_s->conf, id);
6701 if (ssid == NULL || ssid->disabled != 2) {
6702 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6703 "for persistent P2P group",
6704 id);
6705 return -1;
6706 }
6707
Jouni Malinen31be0a42012-08-31 21:20:51 +03006708 pos = os_strstr(cmd, " freq=");
6709 if (pos) {
6710 pos += 6;
6711 freq = atoi(pos);
6712 if (freq <= 0)
6713 return -1;
6714 }
6715
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006716 pos = os_strstr(cmd, " pref=");
6717 if (pos) {
6718 pos += 6;
6719 pref_freq = atoi(pos);
6720 if (pref_freq <= 0)
6721 return -1;
6722 }
6723
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006724 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6725 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6726 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006727 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006728 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Jouni Malinen31be0a42012-08-31 21:20:51 +03006729
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006730 pos = os_strstr(cmd, "freq2=");
6731 if (pos)
6732 freq2 = atoi(pos + 6);
6733
6734 pos = os_strstr(cmd, " max_oper_chwidth=");
6735 if (pos)
6736 chwidth = atoi(pos + 18);
6737
6738 max_oper_chwidth = parse_freq(chwidth, freq2);
6739 if (max_oper_chwidth < 0)
6740 return -1;
6741
Hai Shaloma20dcd72022-02-04 13:43:00 -08006742 allow_6ghz = os_strstr(cmd, " allow_6ghz") != NULL;
6743
6744 if (allow_6ghz && chwidth == 40)
6745 max_oper_chwidth = CHANWIDTH_40MHZ_6GHZ;
6746
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006747 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006748 max_oper_chwidth, pref_freq, he, edmg,
6749 allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006750}
6751
6752
6753static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
6754{
6755 char *pos;
6756 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006757 bool allow_6ghz;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006758
6759 pos = os_strstr(cmd, " peer=");
6760 if (!pos)
6761 return -1;
6762
6763 *pos = '\0';
6764 pos += 6;
6765 if (hwaddr_aton(pos, peer)) {
6766 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
6767 return -1;
6768 }
6769
Hai Shaloma20dcd72022-02-04 13:43:00 -08006770 allow_6ghz = os_strstr(pos, " allow_6ghz") != NULL;
6771
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006772 pos = os_strstr(pos, " go_dev_addr=");
6773 if (pos) {
6774 pos += 13;
6775 if (hwaddr_aton(pos, go_dev_addr)) {
6776 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
6777 pos);
6778 return -1;
6779 }
6780 go_dev = go_dev_addr;
6781 }
6782
Hai Shaloma20dcd72022-02-04 13:43:00 -08006783 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006784}
6785
6786
6787static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
6788{
6789 if (os_strncmp(cmd, "persistent=", 11) == 0)
6790 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
6791 if (os_strncmp(cmd, "group=", 6) == 0)
6792 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
6793
6794 return -1;
6795}
6796
6797
6798static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006799 int id, int freq, int vht_center_freq2,
Hai Shalom74f70d42019-02-11 14:42:39 -08006800 int ht40, int vht, int vht_chwidth,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006801 int he, int edmg, bool allow_6ghz)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006802{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006803 struct wpa_ssid *ssid;
6804
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006805 ssid = wpa_config_get_network(wpa_s->conf, id);
6806 if (ssid == NULL || ssid->disabled != 2) {
6807 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6808 "for persistent P2P group",
6809 id);
6810 return -1;
6811 }
6812
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006813 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
6814 vht_center_freq2, 0, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006815 vht_chwidth, he, edmg,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006816 NULL, 0, 0, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006817}
6818
6819
6820static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
6821{
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006822 int freq = 0, persistent = 0, group_id = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006823 bool allow_6ghz = false;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006824 int vht = wpa_s->conf->p2p_go_vht;
6825 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006826 int he = wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006827 int edmg = wpa_s->conf->p2p_go_edmg;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006828 int max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006829 char *token, *context = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006830#ifdef CONFIG_ACS
6831 int acs = 0;
6832#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006833
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006834 while ((token = str_token(cmd, " ", &context))) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07006835 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006836 sscanf(token, "persistent=%d", &group_id) == 1 ||
6837 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006838 continue;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006839#ifdef CONFIG_ACS
6840 } else if (os_strcmp(token, "freq=acs") == 0) {
6841 acs = 1;
6842#endif /* CONFIG_ACS */
6843 } else if (sscanf(token, "freq=%d", &freq) == 1) {
6844 continue;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006845 } else if (os_strcmp(token, "ht40") == 0) {
6846 ht40 = 1;
6847 } else if (os_strcmp(token, "vht") == 0) {
6848 vht = 1;
6849 ht40 = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08006850 } else if (os_strcmp(token, "he") == 0) {
6851 he = 1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006852 } else if (os_strcmp(token, "edmg") == 0) {
6853 edmg = 1;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006854 } else if (os_strcmp(token, "persistent") == 0) {
6855 persistent = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08006856 } else if (os_strcmp(token, "allow_6ghz") == 0) {
6857 allow_6ghz = true;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006858 } else {
6859 wpa_printf(MSG_DEBUG,
6860 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6861 token);
6862 return -1;
6863 }
6864 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006865
Roshan Pius3a1667e2018-07-03 15:17:14 -07006866#ifdef CONFIG_ACS
6867 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
6868 (acs || freq == 2 || freq == 5)) {
6869 if (freq == 2 && wpa_s->best_24_freq <= 0) {
6870 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
6871 wpa_s->p2p_go_do_acs = 1;
6872 freq = 0;
6873 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
6874 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
6875 wpa_s->p2p_go_do_acs = 1;
6876 freq = 0;
6877 } else {
6878 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
6879 wpa_s->p2p_go_do_acs = 1;
6880 }
Hai Shalom021b0b52019-04-10 11:17:58 -07006881 } else {
6882 wpa_s->p2p_go_do_acs = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006883 }
6884#endif /* CONFIG_ACS */
6885
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006886 max_oper_chwidth = parse_freq(chwidth, freq2);
6887 if (max_oper_chwidth < 0)
6888 return -1;
6889
Hai Shaloma20dcd72022-02-04 13:43:00 -08006890 if (allow_6ghz && chwidth == 40)
6891 max_oper_chwidth = CHANWIDTH_40MHZ_6GHZ;
6892
6893 /* Allow DFS to be used for Autonomous GO */
6894 wpa_s->p2p_go_allow_dfs = !!(wpa_s->drv_flags &
6895 WPA_DRIVER_FLAGS_DFS_OFFLOAD);
6896
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006897 if (group_id >= 0)
6898 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006899 freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006900 max_oper_chwidth, he,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006901 edmg, allow_6ghz);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006902
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006903 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
Hai Shaloma20dcd72022-02-04 13:43:00 -08006904 max_oper_chwidth, he, edmg, allow_6ghz);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006905}
6906
6907
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006908static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
6909 char *buf, size_t buflen)
6910{
6911 u8 dev_addr[ETH_ALEN];
6912 struct wpa_ssid *ssid;
6913 int res;
6914 const u8 *iaddr;
6915
6916 ssid = wpa_s->current_ssid;
6917 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
6918 hwaddr_aton(cmd, dev_addr))
6919 return -1;
6920
6921 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
6922 if (!iaddr)
6923 return -1;
6924 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
6925 if (os_snprintf_error(buflen, res))
6926 return -1;
6927 return res;
6928}
6929
6930
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006931static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
6932 const u8 *p2p_dev_addr)
6933{
6934 struct wpa_supplicant *wpa_s;
6935
6936 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6937 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
6938 return 1;
6939 }
6940
6941 return 0;
6942}
6943
6944
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006945static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
6946 char *buf, size_t buflen)
6947{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006948 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006949 int next, res;
6950 const struct p2p_peer_info *info;
6951 char *pos, *end;
6952 char devtype[WPS_DEV_TYPE_BUFSIZE];
6953 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006954 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006955
6956 if (!wpa_s->global->p2p)
6957 return -1;
6958
6959 if (os_strcmp(cmd, "FIRST") == 0) {
6960 addr_ptr = NULL;
6961 next = 0;
6962 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
6963 if (hwaddr_aton(cmd + 5, addr) < 0)
6964 return -1;
6965 addr_ptr = addr;
6966 next = 1;
6967 } else {
6968 if (hwaddr_aton(cmd, addr) < 0)
6969 return -1;
6970 addr_ptr = addr;
6971 next = 0;
6972 }
6973
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006974 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
6975 if (info == NULL)
6976 return -1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006977 group_capab = info->group_capab;
6978
6979 if (group_capab &&
6980 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
6981 wpa_printf(MSG_DEBUG,
6982 "P2P: Could not find any BSS with p2p_dev_addr "
6983 MACSTR ", hence override group_capab from 0x%x to 0",
6984 MAC2STR(info->p2p_device_addr), group_capab);
6985 group_capab = 0;
6986 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006987
6988 pos = buf;
6989 end = buf + buflen;
6990
6991 res = os_snprintf(pos, end - pos, MACSTR "\n"
6992 "pri_dev_type=%s\n"
6993 "device_name=%s\n"
6994 "manufacturer=%s\n"
6995 "model_name=%s\n"
6996 "model_number=%s\n"
6997 "serial_number=%s\n"
6998 "config_methods=0x%x\n"
6999 "dev_capab=0x%x\n"
7000 "group_capab=0x%x\n"
7001 "level=%d\n",
7002 MAC2STR(info->p2p_device_addr),
7003 wps_dev_type_bin2str(info->pri_dev_type,
7004 devtype, sizeof(devtype)),
7005 info->device_name,
7006 info->manufacturer,
7007 info->model_name,
7008 info->model_number,
7009 info->serial_number,
7010 info->config_methods,
7011 info->dev_capab,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007012 group_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007013 info->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007014 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007015 return pos - buf;
7016 pos += res;
7017
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007018 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
7019 {
7020 const u8 *t;
7021 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
7022 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
7023 wps_dev_type_bin2str(t, devtype,
7024 sizeof(devtype)));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007025 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007026 return pos - buf;
7027 pos += res;
7028 }
7029
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007030 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007031 if (ssid) {
7032 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007033 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007034 return pos - buf;
7035 pos += res;
7036 }
7037
7038 res = p2p_get_peer_info_txt(info, pos, end - pos);
7039 if (res < 0)
7040 return pos - buf;
7041 pos += res;
7042
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007043 if (info->vendor_elems) {
7044 res = os_snprintf(pos, end - pos, "vendor_elems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007045 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007046 return pos - buf;
7047 pos += res;
7048
7049 pos += wpa_snprintf_hex(pos, end - pos,
7050 wpabuf_head(info->vendor_elems),
7051 wpabuf_len(info->vendor_elems));
7052
7053 res = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007054 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007055 return pos - buf;
7056 pos += res;
7057 }
7058
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007059 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007060}
7061
7062
Dmitry Shmidt04949592012-07-19 12:16:46 -07007063static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
7064 const char *param)
7065{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007066 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007067
7068 if (wpa_s->global->p2p == NULL)
7069 return -1;
7070
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007071 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
7072 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007073
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007074 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
7075 struct wpa_freq_range *freq;
7076 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07007077 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007078 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007079 }
7080
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007081 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007082 return 0;
7083}
7084
7085
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007086static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
7087{
7088 char *param;
7089
7090 if (wpa_s->global->p2p == NULL)
7091 return -1;
7092
7093 param = os_strchr(cmd, ' ');
7094 if (param == NULL)
7095 return -1;
7096 *param++ = '\0';
7097
7098 if (os_strcmp(cmd, "discoverability") == 0) {
7099 p2p_set_client_discoverability(wpa_s->global->p2p,
7100 atoi(param));
7101 return 0;
7102 }
7103
7104 if (os_strcmp(cmd, "managed") == 0) {
7105 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
7106 return 0;
7107 }
7108
7109 if (os_strcmp(cmd, "listen_channel") == 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08007110 char *pos;
7111 u8 channel, op_class;
7112
7113 channel = atoi(param);
7114 pos = os_strchr(param, ' ');
7115 op_class = pos ? atoi(pos) : 81;
7116
7117 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
7118 channel, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007119 }
7120
7121 if (os_strcmp(cmd, "ssid_postfix") == 0) {
7122 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
7123 os_strlen(param));
7124 }
7125
7126 if (os_strcmp(cmd, "noa") == 0) {
7127 char *pos;
7128 int count, start, duration;
7129 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
7130 count = atoi(param);
7131 pos = os_strchr(param, ',');
7132 if (pos == NULL)
7133 return -1;
7134 pos++;
7135 start = atoi(pos);
7136 pos = os_strchr(pos, ',');
7137 if (pos == NULL)
7138 return -1;
7139 pos++;
7140 duration = atoi(pos);
7141 if (count < 0 || count > 255 || start < 0 || duration < 0)
7142 return -1;
7143 if (count == 0 && duration > 0)
7144 return -1;
7145 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
7146 "start=%d duration=%d", count, start, duration);
7147 return wpas_p2p_set_noa(wpa_s, count, start, duration);
7148 }
7149
7150 if (os_strcmp(cmd, "ps") == 0)
7151 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
7152
7153 if (os_strcmp(cmd, "oppps") == 0)
7154 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
7155
7156 if (os_strcmp(cmd, "ctwindow") == 0)
7157 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
7158
7159 if (os_strcmp(cmd, "disabled") == 0) {
7160 wpa_s->global->p2p_disabled = atoi(param);
7161 wpa_printf(MSG_DEBUG, "P2P functionality %s",
7162 wpa_s->global->p2p_disabled ?
7163 "disabled" : "enabled");
7164 if (wpa_s->global->p2p_disabled) {
7165 wpas_p2p_stop_find(wpa_s);
7166 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7167 p2p_flush(wpa_s->global->p2p);
7168 }
7169 return 0;
7170 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007171
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007172 if (os_strcmp(cmd, "conc_pref") == 0) {
7173 if (os_strcmp(param, "sta") == 0)
7174 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
7175 else if (os_strcmp(param, "p2p") == 0)
7176 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007177 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007178 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007179 return -1;
7180 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007181 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07007182 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007183 return 0;
7184 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007185
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007186 if (os_strcmp(cmd, "force_long_sd") == 0) {
7187 wpa_s->force_long_sd = atoi(param);
7188 return 0;
7189 }
7190
7191 if (os_strcmp(cmd, "peer_filter") == 0) {
7192 u8 addr[ETH_ALEN];
7193 if (hwaddr_aton(param, addr))
7194 return -1;
7195 p2p_set_peer_filter(wpa_s->global->p2p, addr);
7196 return 0;
7197 }
7198
7199 if (os_strcmp(cmd, "cross_connect") == 0)
7200 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
7201
7202 if (os_strcmp(cmd, "go_apsd") == 0) {
7203 if (os_strcmp(param, "disable") == 0)
7204 wpa_s->set_ap_uapsd = 0;
7205 else {
7206 wpa_s->set_ap_uapsd = 1;
7207 wpa_s->ap_uapsd = atoi(param);
7208 }
7209 return 0;
7210 }
7211
7212 if (os_strcmp(cmd, "client_apsd") == 0) {
7213 if (os_strcmp(param, "disable") == 0)
7214 wpa_s->set_sta_uapsd = 0;
7215 else {
7216 int be, bk, vi, vo;
7217 char *pos;
7218 /* format: BE,BK,VI,VO;max SP Length */
7219 be = atoi(param);
7220 pos = os_strchr(param, ',');
7221 if (pos == NULL)
7222 return -1;
7223 pos++;
7224 bk = atoi(pos);
7225 pos = os_strchr(pos, ',');
7226 if (pos == NULL)
7227 return -1;
7228 pos++;
7229 vi = atoi(pos);
7230 pos = os_strchr(pos, ',');
7231 if (pos == NULL)
7232 return -1;
7233 pos++;
7234 vo = atoi(pos);
7235 /* ignore max SP Length for now */
7236
7237 wpa_s->set_sta_uapsd = 1;
7238 wpa_s->sta_uapsd = 0;
7239 if (be)
7240 wpa_s->sta_uapsd |= BIT(0);
7241 if (bk)
7242 wpa_s->sta_uapsd |= BIT(1);
7243 if (vi)
7244 wpa_s->sta_uapsd |= BIT(2);
7245 if (vo)
7246 wpa_s->sta_uapsd |= BIT(3);
7247 }
7248 return 0;
7249 }
7250
Dmitry Shmidt04949592012-07-19 12:16:46 -07007251 if (os_strcmp(cmd, "disallow_freq") == 0)
7252 return p2p_ctrl_disallow_freq(wpa_s, param);
7253
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007254 if (os_strcmp(cmd, "disc_int") == 0) {
7255 int min_disc_int, max_disc_int, max_disc_tu;
7256 char *pos;
7257
7258 pos = param;
7259
7260 min_disc_int = atoi(pos);
7261 pos = os_strchr(pos, ' ');
7262 if (pos == NULL)
7263 return -1;
7264 *pos++ = '\0';
7265
7266 max_disc_int = atoi(pos);
7267 pos = os_strchr(pos, ' ');
7268 if (pos == NULL)
7269 return -1;
7270 *pos++ = '\0';
7271
7272 max_disc_tu = atoi(pos);
7273
7274 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
7275 max_disc_int, max_disc_tu);
7276 }
7277
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007278 if (os_strcmp(cmd, "per_sta_psk") == 0) {
7279 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
7280 return 0;
7281 }
7282
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007283#ifdef CONFIG_WPS_NFC
7284 if (os_strcmp(cmd, "nfc_tag") == 0)
7285 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
7286#endif /* CONFIG_WPS_NFC */
7287
7288 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
7289 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
7290 return 0;
7291 }
7292
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007293 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
7294 int op_class, chan;
7295
7296 op_class = atoi(param);
7297 param = os_strchr(param, ':');
7298 if (!param)
7299 return -1;
7300 param++;
7301 chan = atoi(param);
7302 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
7303 chan);
7304 return 0;
7305 }
7306
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007307 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
7308 cmd);
7309
7310 return -1;
7311}
7312
7313
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007314static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
7315{
7316 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7317 wpa_s->force_long_sd = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007318
7319#ifdef CONFIG_TESTING_OPTIONS
7320 os_free(wpa_s->get_pref_freq_list_override);
7321 wpa_s->get_pref_freq_list_override = NULL;
7322#endif /* CONFIG_TESTING_OPTIONS */
7323
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007324 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007325 wpa_s->parent->p2ps_method_config_any = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007326 if (wpa_s->global->p2p)
7327 p2p_flush(wpa_s->global->p2p);
7328}
7329
7330
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007331static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
7332{
7333 char *pos, *pos2;
7334 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
7335
7336 if (cmd[0]) {
7337 pos = os_strchr(cmd, ' ');
7338 if (pos == NULL)
7339 return -1;
7340 *pos++ = '\0';
7341 dur1 = atoi(cmd);
7342
7343 pos2 = os_strchr(pos, ' ');
7344 if (pos2)
7345 *pos2++ = '\0';
7346 int1 = atoi(pos);
7347 } else
7348 pos2 = NULL;
7349
7350 if (pos2) {
7351 pos = os_strchr(pos2, ' ');
7352 if (pos == NULL)
7353 return -1;
7354 *pos++ = '\0';
7355 dur2 = atoi(pos2);
7356 int2 = atoi(pos);
7357 }
7358
7359 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
7360}
7361
7362
7363static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
7364{
7365 char *pos;
7366 unsigned int period = 0, interval = 0;
7367
7368 if (cmd[0]) {
7369 pos = os_strchr(cmd, ' ');
7370 if (pos == NULL)
7371 return -1;
7372 *pos++ = '\0';
7373 period = atoi(cmd);
7374 interval = atoi(pos);
7375 }
7376
7377 return wpas_p2p_ext_listen(wpa_s, period, interval);
7378}
7379
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007380
7381static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
7382{
7383 const char *pos;
7384 u8 peer[ETH_ALEN];
7385 int iface_addr = 0;
7386
7387 pos = cmd;
7388 if (os_strncmp(pos, "iface=", 6) == 0) {
7389 iface_addr = 1;
7390 pos += 6;
7391 }
7392 if (hwaddr_aton(pos, peer))
7393 return -1;
7394
7395 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
7396 return 0;
7397}
7398
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007399
7400static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
7401{
7402 int freq = 0, period = 0, interval = 0, count = 0;
7403
7404 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
7405 {
7406 wpa_printf(MSG_DEBUG,
7407 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
7408 return -1;
7409 }
7410
7411 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
7412}
7413
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007414#endif /* CONFIG_P2P */
7415
7416
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007417static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
7418{
7419 struct wpa_freq_range_list ranges;
7420 int *freqs = NULL;
7421 struct hostapd_hw_modes *mode;
7422 u16 i;
7423
7424 if (wpa_s->hw.modes == NULL)
7425 return NULL;
7426
7427 os_memset(&ranges, 0, sizeof(ranges));
7428 if (freq_range_list_parse(&ranges, val) < 0)
7429 return NULL;
7430
7431 for (i = 0; i < wpa_s->hw.num_modes; i++) {
7432 int j;
7433
7434 mode = &wpa_s->hw.modes[i];
7435 for (j = 0; j < mode->num_channels; j++) {
7436 unsigned int freq;
7437
7438 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
7439 continue;
7440
7441 freq = mode->channels[j].freq;
7442 if (!freq_range_list_includes(&ranges, freq))
7443 continue;
7444
7445 int_array_add_unique(&freqs, freq);
7446 }
7447 }
7448
7449 os_free(ranges.range);
7450 return freqs;
7451}
7452
7453
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007454#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007455
7456static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
7457{
7458 int auto_sel = 0;
7459 int *freqs = NULL;
7460
7461 if (param) {
7462 char *pos;
7463
7464 auto_sel = os_strstr(param, "auto") != NULL;
7465
7466 pos = os_strstr(param, "freq=");
7467 if (pos) {
7468 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
7469 if (freqs == NULL)
7470 return -1;
7471 }
7472
7473 }
7474
7475 return interworking_select(wpa_s, auto_sel, freqs);
7476}
7477
7478
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007479static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
7480 int only_add)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007481{
7482 u8 bssid[ETH_ALEN];
7483 struct wpa_bss *bss;
7484
7485 if (hwaddr_aton(dst, bssid)) {
7486 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
7487 return -1;
7488 }
7489
Hai Shalomfdcde762020-04-02 11:19:20 -07007490 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007491 if (bss == NULL) {
7492 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
7493 MAC2STR(bssid));
7494 return -1;
7495 }
7496
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007497 if (bss->ssid_len == 0) {
7498 int found = 0;
7499
7500 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
7501 " does not have SSID information", MAC2STR(bssid));
7502
7503 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
7504 list) {
7505 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
7506 bss->ssid_len > 0) {
7507 found = 1;
7508 break;
7509 }
7510 }
7511
7512 if (!found)
7513 return -1;
7514 wpa_printf(MSG_DEBUG,
7515 "Found another matching BSS entry with SSID");
7516 }
7517
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007518 return interworking_connect(wpa_s, bss, only_add);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007519}
7520
7521
7522static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
7523{
7524 u8 dst_addr[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07007525 int used, freq = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007526 char *pos;
7527#define MAX_ANQP_INFO_ID 100
7528 u16 id[MAX_ANQP_INFO_ID];
7529 size_t num_id = 0;
Dmitry Shmidt15907092014-03-25 10:42:57 -07007530 u32 subtypes = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007531 u32 mbo_subtypes = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007532
7533 used = hwaddr_aton2(dst, dst_addr);
7534 if (used < 0)
7535 return -1;
7536 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007537 if (*pos == ' ')
7538 pos++;
Hai Shalom899fcc72020-10-19 14:38:18 -07007539
7540 if (os_strncmp(pos, "freq=", 5) == 0) {
7541 freq = atoi(pos + 5);
7542 pos = os_strchr(pos, ' ');
7543 if (!pos)
7544 return -1;
7545 pos++;
7546 }
7547
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007548 while (num_id < MAX_ANQP_INFO_ID) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07007549 if (os_strncmp(pos, "hs20:", 5) == 0) {
7550#ifdef CONFIG_HS20
7551 int num = atoi(pos + 5);
7552 if (num <= 0 || num > 31)
7553 return -1;
7554 subtypes |= BIT(num);
7555#else /* CONFIG_HS20 */
7556 return -1;
7557#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007558 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7559#ifdef CONFIG_MBO
7560 int num = atoi(pos + 4);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007561
7562 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007563 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007564 mbo_subtypes |= BIT(num);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007565#else /* CONFIG_MBO */
7566 return -1;
7567#endif /* CONFIG_MBO */
Dmitry Shmidt15907092014-03-25 10:42:57 -07007568 } else {
7569 id[num_id] = atoi(pos);
7570 if (id[num_id])
7571 num_id++;
7572 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007573 pos = os_strchr(pos + 1, ',');
7574 if (pos == NULL)
7575 break;
7576 pos++;
7577 }
7578
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007579 if (num_id == 0 && !subtypes && !mbo_subtypes)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007580 return -1;
7581
Hai Shalom899fcc72020-10-19 14:38:18 -07007582 return anqp_send_req(wpa_s, dst_addr, freq, id, num_id, subtypes,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007583 mbo_subtypes);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007584}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007585
7586
7587static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7588{
7589 u8 dst_addr[ETH_ALEN];
7590 struct wpabuf *advproto, *query = NULL;
7591 int used, ret = -1;
7592 char *pos, *end;
7593 size_t len;
7594
7595 used = hwaddr_aton2(cmd, dst_addr);
7596 if (used < 0)
7597 return -1;
7598
7599 pos = cmd + used;
7600 while (*pos == ' ')
7601 pos++;
7602
7603 /* Advertisement Protocol ID */
7604 end = os_strchr(pos, ' ');
7605 if (end)
7606 len = end - pos;
7607 else
7608 len = os_strlen(pos);
7609 if (len & 0x01)
7610 return -1;
7611 len /= 2;
7612 if (len == 0)
7613 return -1;
7614 advproto = wpabuf_alloc(len);
7615 if (advproto == NULL)
7616 return -1;
7617 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7618 goto fail;
7619
7620 if (end) {
7621 /* Optional Query Request */
7622 pos = end + 1;
7623 while (*pos == ' ')
7624 pos++;
7625
7626 len = os_strlen(pos);
7627 if (len) {
7628 if (len & 0x01)
7629 goto fail;
7630 len /= 2;
7631 if (len == 0)
7632 goto fail;
7633 query = wpabuf_alloc(len);
7634 if (query == NULL)
7635 goto fail;
7636 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7637 goto fail;
7638 }
7639 }
7640
7641 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7642
7643fail:
7644 wpabuf_free(advproto);
7645 wpabuf_free(query);
7646
7647 return ret;
7648}
7649
7650
7651static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7652 size_t buflen)
7653{
7654 u8 addr[ETH_ALEN];
7655 int dialog_token;
7656 int used;
7657 char *pos;
7658 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007659 struct wpabuf *resp;
7660 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007661
7662 used = hwaddr_aton2(cmd, addr);
7663 if (used < 0)
7664 return -1;
7665
7666 pos = cmd + used;
7667 while (*pos == ' ')
7668 pos++;
7669 dialog_token = atoi(pos);
7670
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007671 if (wpa_s->last_gas_resp &&
7672 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
7673 dialog_token == wpa_s->last_gas_dialog_token)
7674 resp = wpa_s->last_gas_resp;
7675 else if (wpa_s->prev_gas_resp &&
7676 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
7677 dialog_token == wpa_s->prev_gas_dialog_token)
7678 resp = wpa_s->prev_gas_resp;
7679 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007680 return -1;
7681
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007682 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007683 start = 0;
7684 requested_len = resp_len;
7685
7686 pos = os_strchr(pos, ' ');
7687 if (pos) {
7688 start = atoi(pos);
7689 if (start > resp_len)
7690 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7691 pos = os_strchr(pos, ',');
7692 if (pos == NULL)
7693 return -1;
7694 pos++;
7695 requested_len = atoi(pos);
7696 if (start + requested_len > resp_len)
7697 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7698 }
7699
7700 if (requested_len * 2 + 1 > buflen)
7701 return os_snprintf(buf, buflen, "FAIL-Too long response");
7702
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007703 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
7704 requested_len);
7705
7706 if (start + requested_len == resp_len) {
7707 /*
7708 * Free memory by dropping the response after it has been
7709 * fetched.
7710 */
7711 if (resp == wpa_s->prev_gas_resp) {
7712 wpabuf_free(wpa_s->prev_gas_resp);
7713 wpa_s->prev_gas_resp = NULL;
7714 } else {
7715 wpabuf_free(wpa_s->last_gas_resp);
7716 wpa_s->last_gas_resp = NULL;
7717 }
7718 }
7719
7720 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007721}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007722#endif /* CONFIG_INTERWORKING */
7723
7724
Dmitry Shmidt04949592012-07-19 12:16:46 -07007725#ifdef CONFIG_HS20
7726
7727static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
7728{
7729 u8 dst_addr[ETH_ALEN];
7730 int used;
7731 char *pos;
7732 u32 subtypes = 0;
7733
7734 used = hwaddr_aton2(dst, dst_addr);
7735 if (used < 0)
7736 return -1;
7737 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007738 if (*pos == ' ')
7739 pos++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007740 for (;;) {
7741 int num = atoi(pos);
7742 if (num <= 0 || num > 31)
7743 return -1;
7744 subtypes |= BIT(num);
7745 pos = os_strchr(pos + 1, ',');
7746 if (pos == NULL)
7747 break;
7748 pos++;
7749 }
7750
7751 if (subtypes == 0)
7752 return -1;
7753
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007754 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007755}
7756
7757
7758static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7759 const u8 *addr, const char *realm)
7760{
7761 u8 *buf;
7762 size_t rlen, len;
7763 int ret;
7764
7765 rlen = os_strlen(realm);
7766 len = 3 + rlen;
7767 buf = os_malloc(len);
7768 if (buf == NULL)
7769 return -1;
7770 buf[0] = 1; /* NAI Home Realm Count */
7771 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
7772 buf[2] = rlen;
7773 os_memcpy(buf + 3, realm, rlen);
7774
7775 ret = hs20_anqp_send_req(wpa_s, addr,
7776 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007777 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007778
7779 os_free(buf);
7780
7781 return ret;
7782}
7783
7784
7785static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7786 char *dst)
7787{
7788 struct wpa_cred *cred = wpa_s->conf->cred;
7789 u8 dst_addr[ETH_ALEN];
7790 int used;
7791 u8 *buf;
7792 size_t len;
7793 int ret;
7794
7795 used = hwaddr_aton2(dst, dst_addr);
7796 if (used < 0)
7797 return -1;
7798
7799 while (dst[used] == ' ')
7800 used++;
7801 if (os_strncmp(dst + used, "realm=", 6) == 0)
7802 return hs20_nai_home_realm_list(wpa_s, dst_addr,
7803 dst + used + 6);
7804
7805 len = os_strlen(dst + used);
7806
7807 if (len == 0 && cred && cred->realm)
7808 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
7809
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07007810 if (len & 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07007811 return -1;
7812 len /= 2;
7813 buf = os_malloc(len);
7814 if (buf == NULL)
7815 return -1;
7816 if (hexstr2bin(dst + used, buf, len) < 0) {
7817 os_free(buf);
7818 return -1;
7819 }
7820
7821 ret = hs20_anqp_send_req(wpa_s, dst_addr,
7822 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007823 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007824 os_free(buf);
7825
7826 return ret;
7827}
7828
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007829
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007830static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
7831 int buflen)
7832{
7833 u8 dst_addr[ETH_ALEN];
7834 int used;
7835 char *ctx = NULL, *icon, *poffset, *psize;
7836
7837 used = hwaddr_aton2(cmd, dst_addr);
7838 if (used < 0)
7839 return -1;
7840 cmd += used;
7841
7842 icon = str_token(cmd, " ", &ctx);
7843 poffset = str_token(cmd, " ", &ctx);
7844 psize = str_token(cmd, " ", &ctx);
7845 if (!icon || !poffset || !psize)
7846 return -1;
7847
7848 wpa_s->fetch_osu_icon_in_progress = 0;
7849 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
7850 reply, buflen);
7851}
7852
7853
7854static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
7855{
7856 u8 dst_addr[ETH_ALEN];
7857 int used;
7858 char *icon;
7859
7860 if (!cmd[0])
7861 return hs20_del_icon(wpa_s, NULL, NULL);
7862
7863 used = hwaddr_aton2(cmd, dst_addr);
7864 if (used < 0)
7865 return -1;
7866
7867 while (cmd[used] == ' ')
7868 used++;
7869 icon = cmd[used] ? &cmd[used] : NULL;
7870
7871 return hs20_del_icon(wpa_s, dst_addr, icon);
7872}
7873
7874
7875static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007876{
7877 u8 dst_addr[ETH_ALEN];
7878 int used;
7879 char *icon;
7880
7881 used = hwaddr_aton2(cmd, dst_addr);
7882 if (used < 0)
7883 return -1;
7884
7885 while (cmd[used] == ' ')
7886 used++;
7887 icon = &cmd[used];
7888
7889 wpa_s->fetch_osu_icon_in_progress = 0;
7890 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007891 (u8 *) icon, os_strlen(icon), inmem);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007892}
7893
Dmitry Shmidt04949592012-07-19 12:16:46 -07007894#endif /* CONFIG_HS20 */
7895
7896
Dmitry Shmidt04949592012-07-19 12:16:46 -07007897#ifdef CONFIG_AUTOSCAN
7898
7899static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
7900 char *cmd)
7901{
7902 enum wpa_states state = wpa_s->wpa_state;
7903 char *new_params = NULL;
7904
7905 if (os_strlen(cmd) > 0) {
7906 new_params = os_strdup(cmd);
7907 if (new_params == NULL)
7908 return -1;
7909 }
7910
7911 os_free(wpa_s->conf->autoscan);
7912 wpa_s->conf->autoscan = new_params;
7913
7914 if (wpa_s->conf->autoscan == NULL)
7915 autoscan_deinit(wpa_s);
7916 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
7917 autoscan_init(wpa_s, 1);
7918 else if (state == WPA_SCANNING)
7919 wpa_supplicant_reinit_autoscan(wpa_s);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007920 else
7921 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
7922 wpa_supplicant_state_txt(state));
Dmitry Shmidt04949592012-07-19 12:16:46 -07007923
7924 return 0;
7925}
7926
7927#endif /* CONFIG_AUTOSCAN */
7928
7929
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007930#ifdef CONFIG_WNM
7931
7932static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
7933{
7934 int enter;
7935 int intval = 0;
7936 char *pos;
7937 int ret;
7938 struct wpabuf *tfs_req = NULL;
7939
7940 if (os_strncmp(cmd, "enter", 5) == 0)
7941 enter = 1;
7942 else if (os_strncmp(cmd, "exit", 4) == 0)
7943 enter = 0;
7944 else
7945 return -1;
7946
7947 pos = os_strstr(cmd, " interval=");
7948 if (pos)
7949 intval = atoi(pos + 10);
7950
7951 pos = os_strstr(cmd, " tfs_req=");
7952 if (pos) {
7953 char *end;
7954 size_t len;
7955 pos += 9;
7956 end = os_strchr(pos, ' ');
7957 if (end)
7958 len = end - pos;
7959 else
7960 len = os_strlen(pos);
7961 if (len & 1)
7962 return -1;
7963 len /= 2;
7964 tfs_req = wpabuf_alloc(len);
7965 if (tfs_req == NULL)
7966 return -1;
7967 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
7968 wpabuf_free(tfs_req);
7969 return -1;
7970 }
7971 }
7972
7973 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
7974 WNM_SLEEP_MODE_EXIT, intval,
7975 tfs_req);
7976 wpabuf_free(tfs_req);
7977
7978 return ret;
7979}
7980
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007981
7982static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
7983{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007984 int query_reason, list = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007985 char *btm_candidates = NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007986
7987 query_reason = atoi(cmd);
7988
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007989 cmd = os_strchr(cmd, ' ');
7990 if (cmd) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007991 if (os_strncmp(cmd, " list", 5) == 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007992 list = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007993 else
7994 btm_candidates = cmd;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007995 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007996
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007997 wpa_printf(MSG_DEBUG,
7998 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7999 query_reason, list ? " candidate list" : "");
8000
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008001 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
8002 btm_candidates,
8003 list);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07008004}
8005
Hai Shalom39ba6fc2019-01-22 12:40:38 -08008006
8007static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
8008 char *cmd)
8009{
8010 struct wpabuf *elems;
8011 int ret;
8012
8013 elems = wpabuf_parse_bin(cmd);
8014 if (!elems)
8015 return -1;
8016
8017 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
8018 wpabuf_free(elems);
8019 return ret;
8020}
8021
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08008022#endif /* CONFIG_WNM */
8023
8024
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008025static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
8026 size_t buflen)
8027{
8028 struct wpa_signal_info si;
8029 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008030 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008031
8032 ret = wpa_drv_signal_poll(wpa_s, &si);
8033 if (ret)
8034 return -1;
8035
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008036 pos = buf;
8037 end = buf + buflen;
8038
8039 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008040 "NOISE=%d\nFREQUENCY=%u\n",
8041 si.current_signal, si.current_txrate / 1000,
8042 si.current_noise, si.frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008043 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008044 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008045 pos += ret;
8046
8047 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
8048 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008049 channel_width_to_string(si.chanwidth));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008050 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008051 return -1;
8052 pos += ret;
8053 }
8054
Roshan Pius3a1667e2018-07-03 15:17:14 -07008055 if (si.center_frq1 > 0) {
8056 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
8057 si.center_frq1);
8058 if (os_snprintf_error(end - pos, ret))
8059 return -1;
8060 pos += ret;
8061 }
8062
8063 if (si.center_frq2 > 0) {
8064 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
8065 si.center_frq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008066 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008067 return -1;
8068 pos += ret;
8069 }
8070
8071 if (si.avg_signal) {
8072 ret = os_snprintf(pos, end - pos,
8073 "AVG_RSSI=%d\n", si.avg_signal);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008074 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008075 return -1;
8076 pos += ret;
8077 }
8078
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07008079 if (si.avg_beacon_signal) {
8080 ret = os_snprintf(pos, end - pos,
8081 "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
8082 if (os_snprintf_error(end - pos, ret))
8083 return -1;
8084 pos += ret;
8085 }
8086
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008087 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008088}
8089
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008090
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008091static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
8092 const char *cmd)
8093{
8094 const char *pos;
8095 int threshold = 0;
8096 int hysteresis = 0;
8097
8098 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
8099 wpa_printf(MSG_DEBUG,
8100 "Reject SIGNAL_MONITOR command - bgscan is active");
8101 return -1;
8102 }
8103 pos = os_strstr(cmd, "THRESHOLD=");
8104 if (pos)
8105 threshold = atoi(pos + 10);
8106 pos = os_strstr(cmd, "HYSTERESIS=");
8107 if (pos)
8108 hysteresis = atoi(pos + 11);
8109 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
8110}
8111
8112
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008113#ifdef CONFIG_TESTING_OPTIONS
8114int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
8115 enum wpa_driver_if_type if_type,
8116 unsigned int *num,
8117 unsigned int *freq_list)
8118{
8119 char *pos = wpa_s->get_pref_freq_list_override;
8120 char *end;
8121 unsigned int count = 0;
8122
8123 /* Override string format:
8124 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
8125
8126 while (pos) {
8127 if (atoi(pos) == (int) if_type)
8128 break;
8129 pos = os_strchr(pos, ' ');
8130 if (pos)
8131 pos++;
8132 }
8133 if (!pos)
8134 return -1;
8135 pos = os_strchr(pos, ':');
8136 if (!pos)
8137 return -1;
8138 pos++;
8139 end = os_strchr(pos, ' ');
8140 while (pos && (!end || pos < end) && count < *num) {
8141 freq_list[count++] = atoi(pos);
8142 pos = os_strchr(pos, ',');
8143 if (pos)
8144 pos++;
8145 }
8146
8147 *num = count;
8148 return 0;
8149}
8150#endif /* CONFIG_TESTING_OPTIONS */
8151
8152
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008153static int wpas_ctrl_iface_get_pref_freq_list(
8154 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
8155{
8156 unsigned int freq_list[100], num = 100, i;
8157 int ret;
8158 enum wpa_driver_if_type iface_type;
8159 char *pos, *end;
8160
8161 pos = buf;
8162 end = buf + buflen;
8163
8164 /* buf: "<interface_type>" */
8165 if (os_strcmp(cmd, "STATION") == 0)
8166 iface_type = WPA_IF_STATION;
8167 else if (os_strcmp(cmd, "AP") == 0)
8168 iface_type = WPA_IF_AP_BSS;
8169 else if (os_strcmp(cmd, "P2P_GO") == 0)
8170 iface_type = WPA_IF_P2P_GO;
8171 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
8172 iface_type = WPA_IF_P2P_CLIENT;
8173 else if (os_strcmp(cmd, "IBSS") == 0)
8174 iface_type = WPA_IF_IBSS;
8175 else if (os_strcmp(cmd, "TDLS") == 0)
8176 iface_type = WPA_IF_TDLS;
8177 else
8178 return -1;
8179
8180 wpa_printf(MSG_DEBUG,
8181 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
Hai Shalom5f92bc92019-04-18 11:54:11 -07008182 iface_type, cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008183
8184 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
8185 if (ret)
8186 return -1;
8187
8188 for (i = 0; i < num; i++) {
8189 ret = os_snprintf(pos, end - pos, "%s%u",
8190 i > 0 ? "," : "", freq_list[i]);
8191 if (os_snprintf_error(end - pos, ret))
8192 return -1;
8193 pos += ret;
8194 }
8195
8196 return pos - buf;
8197}
8198
8199
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008200static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
8201 char *buf, size_t buflen)
8202{
8203 int ret, i;
8204 char *pos, *end;
8205
8206 ret = os_snprintf(buf, buflen, "%016llX:\n",
8207 (long long unsigned) wpa_s->drv_flags);
8208 if (os_snprintf_error(buflen, ret))
8209 return -1;
8210
8211 pos = buf + ret;
8212 end = buf + buflen;
8213
8214 for (i = 0; i < 64; i++) {
8215 if (wpa_s->drv_flags & (1LLU << i)) {
8216 ret = os_snprintf(pos, end - pos, "%s\n",
8217 driver_flag_to_string(1LLU << i));
8218 if (os_snprintf_error(end - pos, ret))
8219 return -1;
8220 pos += ret;
8221 }
8222 }
8223
8224 return pos - buf;
8225}
8226
8227
Hai Shalomb755a2a2020-04-23 21:49:02 -07008228static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s,
8229 char *buf, size_t buflen)
8230{
8231 int ret, i;
8232 char *pos, *end;
8233
8234 ret = os_snprintf(buf, buflen, "%016llX:\n",
8235 (long long unsigned) wpa_s->drv_flags2);
8236 if (os_snprintf_error(buflen, ret))
8237 return -1;
8238
8239 pos = buf + ret;
8240 end = buf + buflen;
8241
8242 for (i = 0; i < 64; i++) {
8243 if (wpa_s->drv_flags2 & (1LLU << i)) {
8244 ret = os_snprintf(pos, end - pos, "%s\n",
8245 driver_flag2_to_string(1LLU << i));
8246 if (os_snprintf_error(end - pos, ret))
8247 return -1;
8248 pos += ret;
8249 }
8250 }
8251
8252 return pos - buf;
8253}
8254
8255
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008256static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
8257 size_t buflen)
8258{
8259 struct hostap_sta_driver_data sta;
8260 int ret;
8261
8262 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
8263 if (ret)
8264 return -1;
8265
8266 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008267 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008268 if (os_snprintf_error(buflen, ret))
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008269 return -1;
8270 return ret;
8271}
8272
8273
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008274#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008275static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8276 char *buf, size_t buflen)
8277{
8278 int ret;
8279
8280 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008281 if (ret == 0) {
8282 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
8283 struct p2p_data *p2p = wpa_s->global->p2p;
8284 if (p2p) {
8285 char country[3];
8286 country[0] = cmd[8];
8287 country[1] = cmd[9];
8288 country[2] = 0x04;
8289 p2p_set_country(p2p, country);
8290 }
8291 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008292 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008293 if (os_snprintf_error(buflen, ret))
8294 ret = -1;
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008295 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008296 return ret;
8297}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008298#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008299
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07008300
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008301static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8302 char *buf, size_t buflen)
8303{
8304 int ret;
Hai Shalom60840252021-02-19 19:02:11 -08008305 char *pos, *temp = NULL;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008306 u8 *data = NULL;
8307 unsigned int vendor_id, subcmd;
Hai Shalom60840252021-02-19 19:02:11 -08008308 enum nested_attr nested_attr_flag = NESTED_ATTR_UNSPECIFIED;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008309 struct wpabuf *reply;
8310 size_t data_len = 0;
8311
Hai Shalom60840252021-02-19 19:02:11 -08008312 /**
8313 * cmd: <vendor id> <subcommand id> [<hex formatted data>]
8314 * [nested=<0|1>]
8315 */
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008316 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008317 if (!isblank((unsigned char) *pos))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008318 return -EINVAL;
8319
8320 subcmd = strtoul(pos, &pos, 10);
8321
8322 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008323 if (!isblank((unsigned char) *pos++))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008324 return -EINVAL;
Hai Shalom60840252021-02-19 19:02:11 -08008325
8326 temp = os_strchr(pos, ' ');
8327 data_len = temp ? (size_t) (temp - pos) : os_strlen(pos);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008328 }
8329
8330 if (data_len) {
8331 data_len /= 2;
8332 data = os_malloc(data_len);
8333 if (!data)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008334 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008335
8336 if (hexstr2bin(pos, data, data_len)) {
8337 wpa_printf(MSG_DEBUG,
8338 "Vendor command: wrong parameter format");
8339 os_free(data);
8340 return -EINVAL;
8341 }
8342 }
8343
Hai Shalom60840252021-02-19 19:02:11 -08008344 pos = os_strstr(cmd, "nested=");
8345 if (pos)
8346 nested_attr_flag = atoi(pos + 7) ? NESTED_ATTR_USED :
8347 NESTED_ATTR_NOT_USED;
8348
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008349 reply = wpabuf_alloc((buflen - 1) / 2);
8350 if (!reply) {
8351 os_free(data);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008352 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008353 }
8354
8355 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
Hai Shalom60840252021-02-19 19:02:11 -08008356 nested_attr_flag, reply);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008357
8358 if (ret == 0)
8359 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
8360 wpabuf_len(reply));
8361
8362 wpabuf_free(reply);
8363 os_free(data);
8364
8365 return ret;
8366}
8367
8368
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008369static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
8370{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008371#ifdef CONFIG_P2P
8372 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
8373 wpa_s->global->p2p_init_wpa_s : wpa_s;
8374#endif /* CONFIG_P2P */
8375
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008376 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
8377
Dmitry Shmidt29333592017-01-09 12:27:11 -08008378 if (wpas_abort_ongoing_scan(wpa_s) == 0)
8379 wpa_s->ignore_post_flush_scan_res = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008380
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008381 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
8382 /*
8383 * Avoid possible auto connect re-connection on getting
8384 * disconnected due to state flush.
8385 */
8386 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
8387 }
8388
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008389#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008390 wpas_p2p_group_remove(p2p_wpa_s, "*");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008391 wpas_p2p_cancel(p2p_wpa_s);
8392 p2p_ctrl_flush(p2p_wpa_s);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008393 wpas_p2p_service_flush(p2p_wpa_s);
8394 p2p_wpa_s->global->p2p_disabled = 0;
8395 p2p_wpa_s->global->p2p_per_sta_psk = 0;
8396 p2p_wpa_s->conf->num_sec_device_types = 0;
8397 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
8398 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
8399 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008400 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08008401 p2p_wpa_s->global->pending_p2ps_group = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008402 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008403#endif /* CONFIG_P2P */
8404
8405#ifdef CONFIG_WPS_TESTING
8406 wps_version_number = 0x20;
Hai Shaloma20dcd72022-02-04 13:43:00 -08008407 wps_testing_stub_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08008408 wps_corrupt_pkhash = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008409 wps_force_auth_types_in_use = 0;
8410 wps_force_encr_types_in_use = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008411#endif /* CONFIG_WPS_TESTING */
8412#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008413 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008414 wpas_wps_cancel(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008415 wps_registrar_flush(wpa_s->wps->registrar);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008416#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07008417 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008418 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008419
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008420#ifdef CONFIG_DPP
8421 wpas_dpp_deinit(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07008422 wpa_s->dpp_init_max_tries = 0;
8423 wpa_s->dpp_init_retry_time = 0;
8424 wpa_s->dpp_resp_wait_time = 0;
8425 wpa_s->dpp_resp_max_tries = 0;
8426 wpa_s->dpp_resp_retry_time = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008427#ifdef CONFIG_DPP2
8428 wpas_dpp_chirp_stop(wpa_s);
8429 wpa_s->dpp_pfs_fallback = 0;
8430#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008431#ifdef CONFIG_TESTING_OPTIONS
8432 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
8433 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
8434 dpp_pkex_ephemeral_key_override_len = 0;
8435 dpp_protocol_key_override_len = 0;
8436 dpp_nonce_override_len = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08008437#ifdef CONFIG_DPP3
8438 dpp_version_override = 3;
8439#elif defined(CONFIG_DPP2)
Hai Shalom4fbc08f2020-05-18 12:37:00 -07008440 dpp_version_override = 2;
8441#else /* CONFIG_DPP2 */
8442 dpp_version_override = 1;
8443#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008444#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008445#endif /* CONFIG_DPP */
8446
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008447#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008448#ifdef CONFIG_TDLS_TESTING
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008449 tdls_testing = 0;
8450#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008451 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
8452 wpa_tdls_enable(wpa_s->wpa, 1);
8453#endif /* CONFIG_TDLS */
8454
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008455 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
8456 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07008457 wpa_s->last_michael_mic_error.sec = 0;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008458
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008459 wpa_s->no_keep_alive = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08008460 wpa_s->own_disconnect_req = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008461 wpa_s->own_reconnect_req = 0;
8462 wpa_s->deny_ptk0_rekey = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008463
8464 os_free(wpa_s->disallow_aps_bssid);
8465 wpa_s->disallow_aps_bssid = NULL;
8466 wpa_s->disallow_aps_bssid_count = 0;
8467 os_free(wpa_s->disallow_aps_ssid);
8468 wpa_s->disallow_aps_ssid = NULL;
8469 wpa_s->disallow_aps_ssid_count = 0;
8470
8471 wpa_s->set_sta_uapsd = 0;
8472 wpa_s->sta_uapsd = 0;
8473
Hai Shalom899fcc72020-10-19 14:38:18 -07008474 wpa_s->consecutive_conn_failures = 0;
8475
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008476 wpa_drv_radio_disable(wpa_s, 0);
Hai Shalom60840252021-02-19 19:02:11 -08008477 wpa_bssid_ignore_clear(wpa_s);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008478 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
8479 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08008480 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08008481 wpa_s->conf->auto_interworking = 0;
8482 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008483
Hai Shalom60840252021-02-19 19:02:11 -08008484 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008485 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
8486 rsn_preauth_deinit(wpa_s->wpa);
8487
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008488 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
8489 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
8490 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
Hai Shalome21d4e82020-04-29 16:34:06 -07008491 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008492
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008493 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008494 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008495
8496 wpa_s->next_ssid = NULL;
8497
8498#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008499#ifdef CONFIG_HS20
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008500 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008501 hs20_del_icon(wpa_s, NULL, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008502#endif /* CONFIG_HS20 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008503#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008504
8505 wpa_s->ext_mgmt_frame_handling = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008506 wpa_s->ext_eapol_frame_io = 0;
8507#ifdef CONFIG_TESTING_OPTIONS
8508 wpa_s->extra_roc_dur = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008509 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008510 wpa_s->p2p_go_csa_on_inv = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008511 wpa_s->ignore_auth_resp = 0;
8512 wpa_s->ignore_assoc_disallow = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008513 wpa_s->disable_sa_query = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008514 wpa_s->testing_resend_assoc = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008515 wpa_s->ignore_sae_h2e_only = 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07008516 wpa_s->ft_rsnxe_used = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008517 wpa_s->reject_btm_req_reason = 0;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008518 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008519 os_free(wpa_s->get_pref_freq_list_override);
8520 wpa_s->get_pref_freq_list_override = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008521 wpabuf_free(wpa_s->sae_commit_override);
8522 wpa_s->sae_commit_override = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008523 os_free(wpa_s->extra_sae_rejected_groups);
8524 wpa_s->extra_sae_rejected_groups = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008525 wpabuf_free(wpa_s->rsne_override_eapol);
8526 wpa_s->rsne_override_eapol = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008527 wpabuf_free(wpa_s->rsnxe_override_assoc);
8528 wpa_s->rsnxe_override_assoc = NULL;
8529 wpabuf_free(wpa_s->rsnxe_override_eapol);
8530 wpa_s->rsnxe_override_eapol = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008531 wpas_clear_driver_signal_override(wpa_s);
Hai Shaloma20dcd72022-02-04 13:43:00 -08008532 wpa_s->disable_scs_support = 0;
8533 wpa_s->disable_mscs_support = 0;
8534 wpa_s->enable_dscp_policy_capa = 0;
Hai Shalom899fcc72020-10-19 14:38:18 -07008535 wpa_s->oci_freq_override_eapol = 0;
8536 wpa_s->oci_freq_override_saquery_req = 0;
8537 wpa_s->oci_freq_override_saquery_resp = 0;
8538 wpa_s->oci_freq_override_eapol_g2 = 0;
8539 wpa_s->oci_freq_override_ft_assoc = 0;
8540 wpa_s->oci_freq_override_fils_assoc = 0;
8541 wpa_s->oci_freq_override_wnm_sleep = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008542#ifdef CONFIG_DPP
8543 os_free(wpa_s->dpp_config_obj_override);
8544 wpa_s->dpp_config_obj_override = NULL;
8545 os_free(wpa_s->dpp_discovery_override);
8546 wpa_s->dpp_discovery_override = NULL;
8547 os_free(wpa_s->dpp_groups_override);
8548 wpa_s->dpp_groups_override = NULL;
8549 dpp_test = DPP_TEST_DISABLED;
8550#endif /* CONFIG_DPP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008551#endif /* CONFIG_TESTING_OPTIONS */
8552
8553 wpa_s->disconnected = 0;
8554 os_free(wpa_s->next_scan_freqs);
8555 wpa_s->next_scan_freqs = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008556 os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN);
8557 wpa_s->next_scan_bssid_wildcard_ssid = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008558 os_free(wpa_s->select_network_scan_freqs);
8559 wpa_s->select_network_scan_freqs = NULL;
Hai Shalom899fcc72020-10-19 14:38:18 -07008560 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008561
8562 wpa_bss_flush(wpa_s);
8563 if (!dl_list_empty(&wpa_s->bss)) {
8564 wpa_printf(MSG_DEBUG,
8565 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8566 MACSTR " pending_bssid=" MACSTR,
8567 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
8568 MAC2STR(wpa_s->bssid),
8569 MAC2STR(wpa_s->pending_bssid));
8570 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008571
8572 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -08008573 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008574
8575#ifdef CONFIG_SME
8576 wpa_s->sme.last_unprot_disconnect.sec = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008577 wpa_s->sme.auth_alg = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008578#endif /* CONFIG_SME */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008579
8580 wpabuf_free(wpa_s->ric_ies);
8581 wpa_s->ric_ies = NULL;
Hai Shalom74f70d42019-02-11 14:42:39 -08008582
8583 wpa_supplicant_update_channel_list(wpa_s, NULL);
8584
8585 free_bss_tmp_disallowed(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -07008586
8587 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Hai Shalom60840252021-02-19 19:02:11 -08008588
8589#ifdef CONFIG_PASN
8590 wpas_pasn_auth_stop(wpa_s);
8591#endif /* CONFIG_PASN */
8592
8593 if (wpa_s->mac_addr_changed && wpa_s->conf->mac_addr == 0)
8594 wpas_restore_permanent_mac_addr(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008595}
8596
8597
8598static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
8599 char *buf, size_t buflen)
8600{
8601 struct wpa_radio_work *work;
8602 char *pos, *end;
8603 struct os_reltime now, diff;
8604
8605 pos = buf;
8606 end = buf + buflen;
8607
8608 os_get_reltime(&now);
8609
8610 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8611 {
8612 int ret;
8613
8614 os_reltime_sub(&now, &work->time, &diff);
8615 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
8616 work->type, work->wpa_s->ifname, work->freq,
8617 work->started, diff.sec, diff.usec);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008618 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008619 break;
8620 pos += ret;
8621 }
8622
8623 return pos - buf;
8624}
8625
8626
8627static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
8628{
8629 struct wpa_radio_work *work = eloop_ctx;
8630 struct wpa_external_work *ework = work->ctx;
8631
8632 wpa_dbg(work->wpa_s, MSG_DEBUG,
8633 "Timing out external radio work %u (%s)",
8634 ework->id, work->type);
8635 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008636 work->wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008637 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008638 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008639}
8640
8641
8642static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
8643{
8644 struct wpa_external_work *ework = work->ctx;
8645
8646 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008647 if (work->started)
8648 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8649 work, NULL);
8650
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008651 /*
8652 * work->type points to a buffer in ework, so need to replace
8653 * that here with a fixed string to avoid use of freed memory
8654 * in debug prints.
8655 */
8656 work->type = "freed-ext-work";
8657 work->ctx = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008658 os_free(ework);
8659 return;
8660 }
8661
8662 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
8663 ework->id, ework->type);
8664 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008665 work->wpa_s->ext_work_in_progress = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008666 if (!ework->timeout)
8667 ework->timeout = 10;
8668 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
8669 work, NULL);
8670}
8671
8672
8673static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
8674 char *buf, size_t buflen)
8675{
8676 struct wpa_external_work *ework;
8677 char *pos, *pos2;
8678 size_t type_len;
8679 int ret;
8680 unsigned int freq = 0;
8681
8682 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8683
8684 ework = os_zalloc(sizeof(*ework));
8685 if (ework == NULL)
8686 return -1;
8687
8688 pos = os_strchr(cmd, ' ');
8689 if (pos) {
8690 type_len = pos - cmd;
8691 pos++;
8692
8693 pos2 = os_strstr(pos, "freq=");
8694 if (pos2)
8695 freq = atoi(pos2 + 5);
8696
8697 pos2 = os_strstr(pos, "timeout=");
8698 if (pos2)
8699 ework->timeout = atoi(pos2 + 8);
8700 } else {
8701 type_len = os_strlen(cmd);
8702 }
8703 if (4 + type_len >= sizeof(ework->type))
8704 type_len = sizeof(ework->type) - 4 - 1;
8705 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
8706 os_memcpy(ework->type + 4, cmd, type_len);
8707 ework->type[4 + type_len] = '\0';
8708
8709 wpa_s->ext_work_id++;
8710 if (wpa_s->ext_work_id == 0)
8711 wpa_s->ext_work_id++;
8712 ework->id = wpa_s->ext_work_id;
8713
8714 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
8715 ework) < 0) {
8716 os_free(ework);
8717 return -1;
8718 }
8719
8720 ret = os_snprintf(buf, buflen, "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008721 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008722 return -1;
8723 return ret;
8724}
8725
8726
8727static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
8728{
8729 struct wpa_radio_work *work;
8730 unsigned int id = atoi(cmd);
8731
8732 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8733 {
8734 struct wpa_external_work *ework;
8735
8736 if (os_strncmp(work->type, "ext:", 4) != 0)
8737 continue;
8738 ework = work->ctx;
8739 if (id && ework->id != id)
8740 continue;
8741 wpa_dbg(wpa_s, MSG_DEBUG,
8742 "Completed external radio work %u (%s)",
8743 ework->id, ework->type);
8744 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008745 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008746 radio_work_done(work);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07008747 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008748 return 3; /* "OK\n" */
8749 }
8750
8751 return -1;
8752}
8753
8754
8755static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
8756 char *buf, size_t buflen)
8757{
8758 if (os_strcmp(cmd, "show") == 0)
8759 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
8760 if (os_strncmp(cmd, "add ", 4) == 0)
8761 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
8762 if (os_strncmp(cmd, "done ", 5) == 0)
8763 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
8764 return -1;
8765}
8766
8767
8768void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
8769{
8770 struct wpa_radio_work *work, *tmp;
8771
Dmitry Shmidt18463232014-01-24 12:29:41 -08008772 if (!wpa_s || !wpa_s->radio)
8773 return;
8774
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008775 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
8776 struct wpa_radio_work, list) {
8777 struct wpa_external_work *ework;
8778
8779 if (os_strncmp(work->type, "ext:", 4) != 0)
8780 continue;
8781 ework = work->ctx;
8782 wpa_dbg(wpa_s, MSG_DEBUG,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07008783 "Flushing%s external radio work %u (%s)",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008784 work->started ? " started" : "", ework->id,
8785 ework->type);
8786 if (work->started)
8787 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8788 work, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008789 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008790 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008791 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008792}
8793
8794
Dmitry Shmidt051af732013-10-22 13:52:46 -07008795static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
8796{
8797 struct wpa_supplicant *wpa_s = eloop_ctx;
8798 eapol_sm_notify_ctrl_response(wpa_s->eapol);
8799}
8800
8801
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008802static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
8803 unsigned int *scan_id_count, int scan_id[])
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008804{
8805 const char *pos = value;
8806
8807 while (pos) {
8808 if (*pos == ' ' || *pos == '\0')
8809 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008810 if (*scan_id_count == MAX_SCAN_ID)
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008811 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008812 scan_id[(*scan_id_count)++] = atoi(pos);
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008813 pos = os_strchr(pos, ',');
8814 if (pos)
8815 pos++;
8816 }
8817
8818 return 0;
8819}
8820
8821
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008822static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
8823 char *reply, int reply_size, int *reply_len)
8824{
8825 char *pos;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008826 unsigned int manual_scan_passive = 0;
8827 unsigned int manual_scan_use_id = 0;
8828 unsigned int manual_scan_only_new = 0;
8829 unsigned int scan_only = 0;
8830 unsigned int scan_id_count = 0;
8831 int scan_id[MAX_SCAN_ID];
8832 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
8833 struct wpa_scan_results *scan_res);
8834 int *manual_scan_freqs = NULL;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008835 struct wpa_ssid_value *ssid = NULL, *ns;
8836 unsigned int ssid_count = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008837
8838 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
8839 *reply_len = -1;
8840 return;
8841 }
8842
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008843 if (radio_work_pending(wpa_s, "scan")) {
8844 wpa_printf(MSG_DEBUG,
8845 "Pending scan scheduled - reject new request");
8846 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8847 return;
8848 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008849
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008850#ifdef CONFIG_INTERWORKING
8851 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
8852 wpa_printf(MSG_DEBUG,
8853 "Interworking select in progress - reject new scan");
8854 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8855 return;
8856 }
8857#endif /* CONFIG_INTERWORKING */
8858
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008859 if (params) {
8860 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008861 scan_only = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008862
8863 pos = os_strstr(params, "freq=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008864 if (pos) {
8865 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
8866 pos + 5);
8867 if (manual_scan_freqs == NULL) {
8868 *reply_len = -1;
8869 goto done;
8870 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008871 }
8872
8873 pos = os_strstr(params, "passive=");
8874 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008875 manual_scan_passive = !!atoi(pos + 8);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008876
8877 pos = os_strstr(params, "use_id=");
8878 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008879 manual_scan_use_id = atoi(pos + 7);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008880
8881 pos = os_strstr(params, "only_new=1");
8882 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008883 manual_scan_only_new = 1;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008884
8885 pos = os_strstr(params, "scan_id=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008886 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
8887 scan_id) < 0) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008888 *reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008889 goto done;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008890 }
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008891
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008892 pos = os_strstr(params, "bssid=");
8893 if (pos) {
8894 u8 bssid[ETH_ALEN];
8895
8896 pos += 6;
8897 if (hwaddr_aton(pos, bssid)) {
8898 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
8899 *reply_len = -1;
8900 goto done;
8901 }
8902 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
Hai Shalomfdcde762020-04-02 11:19:20 -07008903
8904 wpa_s->next_scan_bssid_wildcard_ssid =
8905 os_strstr(params, "wildcard_ssid=1") != NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008906 }
8907
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008908 pos = params;
8909 while (pos && *pos != '\0') {
8910 if (os_strncmp(pos, "ssid ", 5) == 0) {
8911 char *end;
8912
8913 pos += 5;
8914 end = pos;
8915 while (*end) {
8916 if (*end == '\0' || *end == ' ')
8917 break;
8918 end++;
8919 }
8920
8921 ns = os_realloc_array(
8922 ssid, ssid_count + 1,
8923 sizeof(struct wpa_ssid_value));
8924 if (ns == NULL) {
8925 *reply_len = -1;
8926 goto done;
8927 }
8928 ssid = ns;
8929
8930 if ((end - pos) & 0x01 ||
8931 end - pos > 2 * SSID_MAX_LEN ||
8932 hexstr2bin(pos, ssid[ssid_count].ssid,
8933 (end - pos) / 2) < 0) {
8934 wpa_printf(MSG_DEBUG,
8935 "Invalid SSID value '%s'",
8936 pos);
8937 *reply_len = -1;
8938 goto done;
8939 }
8940 ssid[ssid_count].ssid_len = (end - pos) / 2;
8941 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
8942 ssid[ssid_count].ssid,
8943 ssid[ssid_count].ssid_len);
8944 ssid_count++;
8945 pos = end;
8946 }
8947
8948 pos = os_strchr(pos, ' ');
8949 if (pos)
8950 pos++;
8951 }
8952 }
8953
8954 wpa_s->num_ssids_from_scan_req = ssid_count;
8955 os_free(wpa_s->ssids_from_scan_req);
8956 if (ssid_count) {
8957 wpa_s->ssids_from_scan_req = ssid;
8958 ssid = NULL;
8959 } else {
8960 wpa_s->ssids_from_scan_req = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008961 }
8962
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008963 if (scan_only)
8964 scan_res_handler = scan_only_handler;
8965 else if (wpa_s->scan_res_handler == scan_only_handler)
8966 scan_res_handler = NULL;
8967 else
8968 scan_res_handler = wpa_s->scan_res_handler;
8969
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008970 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
8971 ((wpa_s->wpa_state <= WPA_SCANNING) ||
8972 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008973 wpa_s->manual_scan_passive = manual_scan_passive;
8974 wpa_s->manual_scan_use_id = manual_scan_use_id;
8975 wpa_s->manual_scan_only_new = manual_scan_only_new;
8976 wpa_s->scan_id_count = scan_id_count;
8977 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8978 wpa_s->scan_res_handler = scan_res_handler;
8979 os_free(wpa_s->manual_scan_freqs);
8980 wpa_s->manual_scan_freqs = manual_scan_freqs;
8981 manual_scan_freqs = NULL;
8982
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008983 wpa_s->normal_scans = 0;
8984 wpa_s->scan_req = MANUAL_SCAN_REQ;
8985 wpa_s->after_wps = 0;
8986 wpa_s->known_wps_freq = 0;
8987 wpa_supplicant_req_scan(wpa_s, 0, 0);
8988 if (wpa_s->manual_scan_use_id) {
8989 wpa_s->manual_scan_id++;
8990 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8991 wpa_s->manual_scan_id);
8992 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8993 wpa_s->manual_scan_id);
8994 }
8995 } else if (wpa_s->sched_scanning) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008996 wpa_s->manual_scan_passive = manual_scan_passive;
8997 wpa_s->manual_scan_use_id = manual_scan_use_id;
8998 wpa_s->manual_scan_only_new = manual_scan_only_new;
8999 wpa_s->scan_id_count = scan_id_count;
9000 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
9001 wpa_s->scan_res_handler = scan_res_handler;
9002 os_free(wpa_s->manual_scan_freqs);
9003 wpa_s->manual_scan_freqs = manual_scan_freqs;
9004 manual_scan_freqs = NULL;
9005
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009006 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
9007 wpa_supplicant_cancel_sched_scan(wpa_s);
9008 wpa_s->scan_req = MANUAL_SCAN_REQ;
9009 wpa_supplicant_req_scan(wpa_s, 0, 0);
9010 if (wpa_s->manual_scan_use_id) {
9011 wpa_s->manual_scan_id++;
9012 *reply_len = os_snprintf(reply, reply_size, "%u\n",
9013 wpa_s->manual_scan_id);
9014 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
9015 wpa_s->manual_scan_id);
9016 }
9017 } else {
9018 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
9019 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9020 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009021
9022done:
9023 os_free(manual_scan_freqs);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009024 os_free(ssid);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009025}
9026
9027
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009028#ifdef CONFIG_TESTING_OPTIONS
9029
9030static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
9031 unsigned int freq, const u8 *dst,
9032 const u8 *src, const u8 *bssid,
9033 const u8 *data, size_t data_len,
9034 enum offchannel_send_action_result
9035 result)
9036{
9037 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
9038 " src=" MACSTR " bssid=" MACSTR " result=%s",
9039 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
9040 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
9041 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
9042 "NO_ACK" : "FAILED"));
9043}
9044
9045
9046static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
9047{
9048 char *pos, *param;
9049 size_t len;
9050 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
9051 int res, used;
9052 int freq = 0, no_cck = 0, wait_time = 0;
9053
9054 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
9055 * <action=Action frame payload> */
9056
9057 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
9058
9059 pos = cmd;
9060 used = hwaddr_aton2(pos, da);
9061 if (used < 0)
9062 return -1;
9063 pos += used;
9064 while (*pos == ' ')
9065 pos++;
9066 used = hwaddr_aton2(pos, bssid);
9067 if (used < 0)
9068 return -1;
9069 pos += used;
9070
9071 param = os_strstr(pos, " freq=");
9072 if (param) {
9073 param += 6;
9074 freq = atoi(param);
9075 }
9076
9077 param = os_strstr(pos, " no_cck=");
9078 if (param) {
9079 param += 8;
9080 no_cck = atoi(param);
9081 }
9082
9083 param = os_strstr(pos, " wait_time=");
9084 if (param) {
9085 param += 11;
9086 wait_time = atoi(param);
9087 }
9088
9089 param = os_strstr(pos, " action=");
9090 if (param == NULL)
9091 return -1;
9092 param += 8;
9093
9094 len = os_strlen(param);
9095 if (len & 1)
9096 return -1;
9097 len /= 2;
9098
9099 buf = os_malloc(len);
9100 if (buf == NULL)
9101 return -1;
9102
9103 if (hexstr2bin(param, buf, len) < 0) {
9104 os_free(buf);
9105 return -1;
9106 }
9107
9108 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
9109 buf, len, wait_time,
9110 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
9111 os_free(buf);
9112 return res;
9113}
9114
9115
9116static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
9117{
9118 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
9119 offchannel_send_action_done(wpa_s);
9120}
9121
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009122
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009123static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
9124 char *cmd)
9125{
9126 char *pos, *param;
9127 size_t len;
9128 u8 *buf;
9129 int freq = 0, datarate = 0, ssi_signal = 0;
9130 union wpa_event_data event;
9131
9132 if (!wpa_s->ext_mgmt_frame_handling)
9133 return -1;
9134
9135 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
9136
9137 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
9138
9139 pos = cmd;
9140 param = os_strstr(pos, "freq=");
9141 if (param) {
9142 param += 5;
9143 freq = atoi(param);
9144 }
9145
9146 param = os_strstr(pos, " datarate=");
9147 if (param) {
9148 param += 10;
9149 datarate = atoi(param);
9150 }
9151
9152 param = os_strstr(pos, " ssi_signal=");
9153 if (param) {
9154 param += 12;
9155 ssi_signal = atoi(param);
9156 }
9157
9158 param = os_strstr(pos, " frame=");
9159 if (param == NULL)
9160 return -1;
9161 param += 7;
9162
9163 len = os_strlen(param);
9164 if (len & 1)
9165 return -1;
9166 len /= 2;
9167
9168 buf = os_malloc(len);
9169 if (buf == NULL)
9170 return -1;
9171
9172 if (hexstr2bin(param, buf, len) < 0) {
9173 os_free(buf);
9174 return -1;
9175 }
9176
9177 os_memset(&event, 0, sizeof(event));
9178 event.rx_mgmt.freq = freq;
9179 event.rx_mgmt.frame = buf;
9180 event.rx_mgmt.frame_len = len;
9181 event.rx_mgmt.ssi_signal = ssi_signal;
9182 event.rx_mgmt.datarate = datarate;
9183 wpa_s->ext_mgmt_frame_handling = 0;
9184 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
9185 wpa_s->ext_mgmt_frame_handling = 1;
9186
9187 os_free(buf);
9188
9189 return 0;
9190}
9191
9192
Paul Stewart092955c2017-02-06 09:13:09 -08009193static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
9194 char *param)
9195{
9196 struct wpa_scan_res *res;
9197 struct os_reltime now;
9198 char *pos, *end;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009199 int ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08009200
9201 if (!param)
9202 return -1;
9203
9204 if (os_strcmp(param, "START") == 0) {
9205 wpa_bss_update_start(wpa_s);
9206 return 0;
9207 }
9208
9209 if (os_strcmp(param, "END") == 0) {
9210 wpa_bss_update_end(wpa_s, NULL, 1);
9211 return 0;
9212 }
9213
9214 if (os_strncmp(param, "BSS ", 4) != 0)
9215 return -1;
9216 param += 3;
9217
9218 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
9219 if (!res)
9220 return -1;
9221
9222 pos = os_strstr(param, " flags=");
9223 if (pos)
9224 res->flags = strtol(pos + 7, NULL, 16);
9225
9226 pos = os_strstr(param, " bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009227 if (pos && hwaddr_aton(pos + 7, res->bssid))
9228 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009229
9230 pos = os_strstr(param, " freq=");
9231 if (pos)
9232 res->freq = atoi(pos + 6);
9233
9234 pos = os_strstr(param, " beacon_int=");
9235 if (pos)
9236 res->beacon_int = atoi(pos + 12);
9237
9238 pos = os_strstr(param, " caps=");
9239 if (pos)
9240 res->caps = strtol(pos + 6, NULL, 16);
9241
9242 pos = os_strstr(param, " qual=");
9243 if (pos)
9244 res->qual = atoi(pos + 6);
9245
9246 pos = os_strstr(param, " noise=");
9247 if (pos)
9248 res->noise = atoi(pos + 7);
9249
9250 pos = os_strstr(param, " level=");
9251 if (pos)
9252 res->level = atoi(pos + 7);
9253
9254 pos = os_strstr(param, " tsf=");
9255 if (pos)
9256 res->tsf = strtoll(pos + 5, NULL, 16);
9257
9258 pos = os_strstr(param, " age=");
9259 if (pos)
9260 res->age = atoi(pos + 5);
9261
9262 pos = os_strstr(param, " est_throughput=");
9263 if (pos)
9264 res->est_throughput = atoi(pos + 16);
9265
9266 pos = os_strstr(param, " snr=");
9267 if (pos)
9268 res->snr = atoi(pos + 5);
9269
9270 pos = os_strstr(param, " parent_tsf=");
9271 if (pos)
9272 res->parent_tsf = strtoll(pos + 7, NULL, 16);
9273
9274 pos = os_strstr(param, " tsf_bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009275 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
9276 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009277
9278 pos = os_strstr(param, " ie=");
9279 if (pos) {
9280 pos += 4;
9281 end = os_strchr(pos, ' ');
9282 if (!end)
9283 end = pos + os_strlen(pos);
9284 res->ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009285 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
9286 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009287 }
9288
9289 pos = os_strstr(param, " beacon_ie=");
9290 if (pos) {
9291 pos += 11;
9292 end = os_strchr(pos, ' ');
9293 if (!end)
9294 end = pos + os_strlen(pos);
9295 res->beacon_ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009296 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
9297 res->beacon_ie_len))
9298 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009299 }
9300
9301 os_get_reltime(&now);
9302 wpa_bss_update_scan_res(wpa_s, res, &now);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009303 ret = 0;
9304fail:
Paul Stewart092955c2017-02-06 09:13:09 -08009305 os_free(res);
9306
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009307 return ret;
Paul Stewart092955c2017-02-06 09:13:09 -08009308}
9309
9310
Hai Shaloma20dcd72022-02-04 13:43:00 -08009311static int wpas_ctrl_iface_driver_event_assoc(struct wpa_supplicant *wpa_s,
9312 char *param)
9313{
9314 union wpa_event_data event;
9315 struct assoc_info *ai;
9316 char *ctx = NULL;
9317 int ret = -1;
9318 struct wpabuf *req_ies = NULL;
9319 struct wpabuf *resp_ies = NULL;
9320 struct wpabuf *resp_frame = NULL;
9321 struct wpabuf *beacon_ies = NULL;
9322 struct wpabuf *key_replay_ctr = NULL;
9323 struct wpabuf *ptk_kck = NULL;
9324 struct wpabuf *ptk_kek = NULL;
9325 struct wpabuf *fils_pmk = NULL;
9326 char *str, *pos;
9327 u8 addr[ETH_ALEN];
9328 u8 fils_pmkid[PMKID_LEN];
9329
9330 os_memset(&event, 0, sizeof(event));
9331 ai = &event.assoc_info;
9332
9333 while ((str = str_token(param, " ", &ctx))) {
9334 pos = os_strchr(str, '=');
9335 if (!pos)
9336 goto fail;
9337 *pos++ = '\0';
9338
9339 if (os_strcmp(str, "reassoc") == 0) {
9340 ai->reassoc = atoi(pos);
9341 } else if (os_strcmp(str, "req_ies") == 0) {
9342 wpabuf_free(req_ies);
9343 req_ies = wpabuf_parse_bin(pos);
9344 if (!req_ies)
9345 goto fail;
9346 ai->req_ies = wpabuf_head(req_ies);
9347 ai->req_ies_len = wpabuf_len(req_ies);
9348 } else if (os_strcmp(str, "resp_ies") == 0) {
9349 wpabuf_free(resp_ies);
9350 resp_ies = wpabuf_parse_bin(pos);
9351 if (!resp_ies)
9352 goto fail;
9353 ai->resp_ies = wpabuf_head(resp_ies);
9354 ai->resp_ies_len = wpabuf_len(resp_ies);
9355 } else if (os_strcmp(str, "resp_frame") == 0) {
9356 wpabuf_free(resp_frame);
9357 resp_frame = wpabuf_parse_bin(pos);
9358 if (!resp_frame)
9359 goto fail;
9360 ai->resp_frame = wpabuf_head(resp_frame);
9361 ai->resp_frame_len = wpabuf_len(resp_frame);
9362 } else if (os_strcmp(str, "beacon_ies") == 0) {
9363 wpabuf_free(beacon_ies);
9364 beacon_ies = wpabuf_parse_bin(pos);
9365 if (!beacon_ies)
9366 goto fail;
9367 ai->beacon_ies = wpabuf_head(beacon_ies);
9368 ai->beacon_ies_len = wpabuf_len(beacon_ies);
9369 } else if (os_strcmp(str, "freq") == 0) {
9370 ai->freq = atoi(pos);
9371 } else if (os_strcmp(str, "wmm::info_bitmap") == 0) {
9372 ai->wmm_params.info_bitmap = atoi(pos);
9373 } else if (os_strcmp(str, "wmm::uapsd_queues") == 0) {
9374 ai->wmm_params.uapsd_queues = atoi(pos);
9375 } else if (os_strcmp(str, "addr") == 0) {
9376 if (hwaddr_aton(pos, addr))
9377 goto fail;
9378 ai->addr = addr;
9379 } else if (os_strcmp(str, "authorized") == 0) {
9380 ai->authorized = atoi(pos);
9381 } else if (os_strcmp(str, "key_replay_ctr") == 0) {
9382 wpabuf_free(key_replay_ctr);
9383 key_replay_ctr = wpabuf_parse_bin(pos);
9384 if (!key_replay_ctr)
9385 goto fail;
9386 ai->key_replay_ctr = wpabuf_head(key_replay_ctr);
9387 ai->key_replay_ctr_len = wpabuf_len(key_replay_ctr);
9388 } else if (os_strcmp(str, "ptk_kck") == 0) {
9389 wpabuf_free(ptk_kck);
9390 ptk_kck = wpabuf_parse_bin(pos);
9391 if (!ptk_kck)
9392 goto fail;
9393 ai->ptk_kck = wpabuf_head(ptk_kck);
9394 ai->ptk_kck_len = wpabuf_len(ptk_kck);
9395 } else if (os_strcmp(str, "ptk_kek") == 0) {
9396 wpabuf_free(ptk_kek);
9397 ptk_kek = wpabuf_parse_bin(pos);
9398 if (!ptk_kek)
9399 goto fail;
9400 ai->ptk_kek = wpabuf_head(ptk_kek);
9401 ai->ptk_kek_len = wpabuf_len(ptk_kek);
9402 } else if (os_strcmp(str, "subnet_status") == 0) {
9403 ai->subnet_status = atoi(pos);
9404 } else if (os_strcmp(str, "fils_erp_next_seq_num") == 0) {
9405 ai->fils_erp_next_seq_num = atoi(pos);
9406 } else if (os_strcmp(str, "fils_pmk") == 0) {
9407 wpabuf_free(fils_pmk);
9408 fils_pmk = wpabuf_parse_bin(pos);
9409 if (!fils_pmk)
9410 goto fail;
9411 ai->fils_pmk = wpabuf_head(fils_pmk);
9412 ai->fils_pmk_len = wpabuf_len(fils_pmk);
9413 } else if (os_strcmp(str, "fils_pmkid") == 0) {
9414 if (hexstr2bin(pos, fils_pmkid, PMKID_LEN) < 0)
9415 goto fail;
9416 ai->fils_pmkid = fils_pmkid;
9417 } else {
9418 goto fail;
9419 }
9420 }
9421
9422 wpa_supplicant_event(wpa_s, EVENT_ASSOC, &event);
9423 ret = 0;
9424fail:
9425 wpabuf_free(req_ies);
9426 wpabuf_free(resp_ies);
9427 wpabuf_free(resp_frame);
9428 wpabuf_free(beacon_ies);
9429 wpabuf_free(key_replay_ctr);
9430 wpabuf_free(ptk_kck);
9431 wpabuf_free(ptk_kek);
9432 wpabuf_free(fils_pmk);
9433 return ret;
9434}
9435
9436
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009437static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
9438{
9439 char *pos, *param;
9440 union wpa_event_data event;
9441 enum wpa_event_type ev;
9442
9443 /* <event name> [parameters..] */
9444
9445 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
9446
9447 pos = cmd;
9448 param = os_strchr(pos, ' ');
9449 if (param)
9450 *param++ = '\0';
9451
9452 os_memset(&event, 0, sizeof(event));
9453
9454 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
9455 ev = EVENT_INTERFACE_ENABLED;
9456 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
9457 ev = EVENT_INTERFACE_DISABLED;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07009458 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
9459 ev = EVENT_AVOID_FREQUENCIES;
9460 if (param == NULL)
9461 param = "";
9462 if (freq_range_list_parse(&event.freq_range, param) < 0)
9463 return -1;
9464 wpa_supplicant_event(wpa_s, ev, &event);
9465 os_free(event.freq_range.range);
9466 return 0;
Paul Stewart092955c2017-02-06 09:13:09 -08009467 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
9468 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
Hai Shaloma20dcd72022-02-04 13:43:00 -08009469 } else if (os_strcmp(cmd, "ASSOC") == 0) {
9470 return wpas_ctrl_iface_driver_event_assoc(wpa_s, param);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009471 } else {
9472 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
9473 cmd);
9474 return -1;
9475 }
9476
9477 wpa_supplicant_event(wpa_s, ev, &event);
9478
9479 return 0;
9480}
9481
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009482
9483static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
9484{
9485 char *pos;
9486 u8 src[ETH_ALEN], *buf;
9487 int used;
9488 size_t len;
9489
9490 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
9491
9492 pos = cmd;
9493 used = hwaddr_aton2(pos, src);
9494 if (used < 0)
9495 return -1;
9496 pos += used;
9497 while (*pos == ' ')
9498 pos++;
9499
9500 len = os_strlen(pos);
9501 if (len & 1)
9502 return -1;
9503 len /= 2;
9504
9505 buf = os_malloc(len);
9506 if (buf == NULL)
9507 return -1;
9508
9509 if (hexstr2bin(pos, buf, len) < 0) {
9510 os_free(buf);
9511 return -1;
9512 }
9513
9514 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
9515 os_free(buf);
9516
9517 return 0;
9518}
9519
9520
Hai Shaloma20dcd72022-02-04 13:43:00 -08009521static int wpas_ctrl_iface_eapol_tx(struct wpa_supplicant *wpa_s, char *cmd)
9522{
9523 char *pos;
9524 u8 dst[ETH_ALEN], *buf;
9525 int used, ret;
9526 size_t len;
9527 unsigned int prev;
9528
9529 wpa_printf(MSG_DEBUG, "External EAPOL TX: %s", cmd);
9530
9531 pos = cmd;
9532 used = hwaddr_aton2(pos, dst);
9533 if (used < 0)
9534 return -1;
9535 pos += used;
9536 while (*pos == ' ')
9537 pos++;
9538
9539 len = os_strlen(pos);
9540 if (len & 1)
9541 return -1;
9542 len /= 2;
9543
9544 buf = os_malloc(len);
9545 if (!buf || hexstr2bin(pos, buf, len) < 0) {
9546 os_free(buf);
9547 return -1;
9548 }
9549
9550 prev = wpa_s->ext_eapol_frame_io;
9551 wpa_s->ext_eapol_frame_io = 0;
9552 ret = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, buf, len);
9553 wpa_s->ext_eapol_frame_io = prev;
9554 os_free(buf);
9555
9556 return ret;
9557}
9558
9559
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009560static u16 ipv4_hdr_checksum(const void *buf, size_t len)
9561{
9562 size_t i;
9563 u32 sum = 0;
9564 const u16 *pos = buf;
9565
9566 for (i = 0; i < len / 2; i++)
9567 sum += *pos++;
9568
9569 while (sum >> 16)
9570 sum = (sum & 0xffff) + (sum >> 16);
9571
9572 return sum ^ 0xffff;
9573}
9574
9575
9576#define HWSIM_PACKETLEN 1500
9577#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
9578
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07009579static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
9580 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009581{
9582 struct wpa_supplicant *wpa_s = ctx;
9583 const struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07009584 struct ip ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009585 const u8 *pos;
9586 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08009587 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009588
Hai Shalom74f70d42019-02-11 14:42:39 -08009589 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
9590 wpa_printf(MSG_DEBUG,
9591 "test data: RX - ignore unexpected length %d",
9592 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009593 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08009594 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009595
9596 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009597 os_memcpy(&ip, eth + 1, sizeof(ip));
9598 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009599
Hai Shalomfdcde762020-04-02 11:19:20 -07009600 if (ip.ip_hl != 5 || ip.ip_v != 4 || ntohs(ip.ip_len) > HWSIM_IP_LEN) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009601 wpa_printf(MSG_DEBUG,
Hai Shalom899fcc72020-10-19 14:38:18 -07009602 "test data: RX - ignore unexpected IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009603 return;
Hai Shalom39bc25d2019-02-06 16:32:13 -08009604 }
Hai Shalombf6e0ba2019-02-11 12:01:50 -08009605
Hai Shalomfdcde762020-04-02 11:19:20 -07009606 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009607 if (*pos != (u8) i) {
9608 wpa_printf(MSG_DEBUG,
9609 "test data: RX - ignore mismatching payload");
9610 return;
9611 }
9612 pos++;
9613 }
9614 extra[0] = '\0';
Hai Shalomfdcde762020-04-02 11:19:20 -07009615 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
9616 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
Hai Shalom74f70d42019-02-11 14:42:39 -08009617 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
9618 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009619}
9620
9621
9622static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
9623 char *cmd)
9624{
9625 int enabled = atoi(cmd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009626 char *pos;
9627 const char *ifname;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009628
9629 if (!enabled) {
9630 if (wpa_s->l2_test) {
9631 l2_packet_deinit(wpa_s->l2_test);
9632 wpa_s->l2_test = NULL;
9633 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
9634 }
9635 return 0;
9636 }
9637
9638 if (wpa_s->l2_test)
9639 return 0;
9640
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009641 pos = os_strstr(cmd, " ifname=");
9642 if (pos)
9643 ifname = pos + 8;
9644 else
9645 ifname = wpa_s->ifname;
9646
9647 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009648 ETHERTYPE_IP, wpas_data_test_rx,
9649 wpa_s, 1);
9650 if (wpa_s->l2_test == NULL)
9651 return -1;
9652
9653 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
9654
9655 return 0;
9656}
9657
9658
9659static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
9660{
9661 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom74f70d42019-02-11 14:42:39 -08009662 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009663 int used;
9664 long int val;
9665 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009666 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009667 struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07009668 struct ip *ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009669 u8 *dpos;
9670 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08009671 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009672
9673 if (wpa_s->l2_test == NULL)
9674 return -1;
9675
Hai Shalom74f70d42019-02-11 14:42:39 -08009676 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009677
9678 pos = cmd;
9679 used = hwaddr_aton2(pos, dst);
9680 if (used < 0)
9681 return -1;
9682 pos += used;
9683 while (*pos == ' ')
9684 pos++;
9685 used = hwaddr_aton2(pos, src);
9686 if (used < 0)
9687 return -1;
9688 pos += used;
9689
Hai Shalom74f70d42019-02-11 14:42:39 -08009690 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009691 if (val < 0 || val > 0xff)
9692 return -1;
9693 tos = val;
9694
Hai Shalom74f70d42019-02-11 14:42:39 -08009695 pos = os_strstr(pos2, " len=");
9696 if (pos) {
9697 i = atoi(pos + 5);
9698 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
9699 return -1;
9700 send_len = i;
9701 }
9702
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009703 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009704 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
9705 os_memcpy(eth->ether_shost, src, ETH_ALEN);
9706 eth->ether_type = htons(ETHERTYPE_IP);
Hai Shalomfdcde762020-04-02 11:19:20 -07009707 ip = (struct ip *) (eth + 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009708 os_memset(ip, 0, sizeof(*ip));
Hai Shalomfdcde762020-04-02 11:19:20 -07009709 ip->ip_hl = 5;
9710 ip->ip_v = 4;
9711 ip->ip_ttl = 64;
9712 ip->ip_tos = tos;
9713 ip->ip_len = htons(send_len);
9714 ip->ip_p = 1;
9715 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
9716 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
9717 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009718 dpos = (u8 *) (ip + 1);
Hai Shalom74f70d42019-02-11 14:42:39 -08009719 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009720 *dpos++ = i;
9721
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009722 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom74f70d42019-02-11 14:42:39 -08009723 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009724 return -1;
9725
9726 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
9727 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
9728
9729 return 0;
9730}
9731
9732
9733static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
9734 char *cmd)
9735{
9736 u8 *buf;
9737 struct ether_header *eth;
9738 struct l2_packet_data *l2 = NULL;
9739 size_t len;
9740 u16 ethertype;
9741 int res = -1;
9742
9743 len = os_strlen(cmd);
9744 if (len & 1 || len < ETH_HLEN * 2)
9745 return -1;
9746 len /= 2;
9747
9748 buf = os_malloc(len);
9749 if (buf == NULL)
9750 return -1;
9751
9752 if (hexstr2bin(cmd, buf, len) < 0)
9753 goto done;
9754
9755 eth = (struct ether_header *) buf;
9756 ethertype = ntohs(eth->ether_type);
9757
9758 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
9759 wpas_data_test_rx, wpa_s, 1);
9760 if (l2 == NULL)
9761 goto done;
9762
9763 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
9764 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
9765done:
9766 if (l2)
9767 l2_packet_deinit(l2);
9768 os_free(buf);
9769
9770 return res < 0 ? -1 : 0;
9771}
9772
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009773
9774static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
9775{
9776#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009777 char *pos;
9778
9779 wpa_trace_fail_after = atoi(cmd);
9780 pos = os_strchr(cmd, ':');
9781 if (pos) {
9782 pos++;
9783 os_strlcpy(wpa_trace_fail_func, pos,
9784 sizeof(wpa_trace_fail_func));
9785 } else {
9786 wpa_trace_fail_after = 0;
9787 }
9788 return 0;
9789#else /* WPA_TRACE_BFD */
9790 return -1;
9791#endif /* WPA_TRACE_BFD */
9792}
9793
9794
9795static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
9796 char *buf, size_t buflen)
9797{
9798#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009799 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
9800 wpa_trace_fail_func);
9801#else /* WPA_TRACE_BFD */
9802 return -1;
9803#endif /* WPA_TRACE_BFD */
9804}
9805
Jouni Malinenc4818362015-10-04 11:45:13 +03009806
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009807static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
9808{
9809#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009810 char *pos;
9811
9812 wpa_trace_test_fail_after = atoi(cmd);
9813 pos = os_strchr(cmd, ':');
9814 if (pos) {
9815 pos++;
9816 os_strlcpy(wpa_trace_test_fail_func, pos,
9817 sizeof(wpa_trace_test_fail_func));
9818 } else {
9819 wpa_trace_test_fail_after = 0;
9820 }
9821 return 0;
9822#else /* WPA_TRACE_BFD */
9823 return -1;
9824#endif /* WPA_TRACE_BFD */
9825}
9826
9827
9828static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
9829 char *buf, size_t buflen)
9830{
9831#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009832 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
9833 wpa_trace_test_fail_func);
9834#else /* WPA_TRACE_BFD */
9835 return -1;
9836#endif /* WPA_TRACE_BFD */
9837}
9838
9839
Jouni Malinenc4818362015-10-04 11:45:13 +03009840static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
9841{
9842 struct wpa_supplicant *wpa_s = eloop_ctx;
9843 int i, count = (intptr_t) timeout_ctx;
9844
9845 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
9846 count);
9847 for (i = 0; i < count; i++) {
9848 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
9849 i + 1, count);
9850 }
9851}
9852
9853
9854static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
9855{
9856 int count;
9857
9858 count = atoi(cmd);
9859 if (count <= 0)
9860 return -1;
9861
9862 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
9863 (void *) (intptr_t) count);
9864}
9865
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009866
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009867static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
9868 const char *cmd)
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009869{
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009870 struct wpabuf *buf;
9871 size_t len;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009872
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009873 len = os_strlen(cmd);
9874 if (len & 1)
9875 return -1;
9876 len /= 2;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009877
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009878 if (len == 0) {
9879 buf = NULL;
9880 } else {
9881 buf = wpabuf_alloc(len);
9882 if (buf == NULL)
9883 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009884
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009885 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
9886 wpabuf_free(buf);
9887 return -1;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009888 }
9889 }
9890
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009891 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
9892 return 0;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009893}
9894
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009895
9896static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
9897{
9898 u8 zero[WPA_TK_MAX_LEN];
9899
9900 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
9901 return -1;
9902
9903 wpa_printf(MSG_INFO, "TESTING: Reset PN");
9904 os_memset(zero, 0, sizeof(zero));
9905
9906 /* First, use a zero key to avoid any possible duplicate key avoidance
9907 * in the driver. */
9908 if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9909 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -07009910 zero, wpa_s->last_tk_len,
9911 KEY_FLAG_PAIRWISE_RX_TX) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009912 return -1;
9913
9914 /* Set the previously configured key to reset its TSC/RSC */
9915 return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9916 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -07009917 wpa_s->last_tk, wpa_s->last_tk_len,
9918 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009919}
9920
9921
9922static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
9923{
9924 const char *pos = cmd;
9925 int error, pairwise;
9926
9927 error = atoi(pos);
9928 pos = os_strchr(pos, ' ');
9929 if (!pos)
9930 return -1;
9931 pairwise = atoi(pos);
9932 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
9933 return 0;
9934}
9935
9936
9937static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
9938{
9939#ifdef CONFIG_SME
9940 struct wpa_driver_associate_params params;
9941 int ret;
9942
9943 os_memset(&params, 0, sizeof(params));
9944 params.bssid = wpa_s->bssid;
9945 params.ssid = wpa_s->sme.ssid;
9946 params.ssid_len = wpa_s->sme.ssid_len;
9947 params.freq.freq = wpa_s->sme.freq;
9948 if (wpa_s->last_assoc_req_wpa_ie) {
9949 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
9950 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
9951 }
9952 params.pairwise_suite = wpa_s->pairwise_cipher;
9953 params.group_suite = wpa_s->group_cipher;
9954 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
9955 params.key_mgmt_suite = wpa_s->key_mgmt;
9956 params.wpa_proto = wpa_s->wpa_proto;
9957 params.mgmt_frame_protection = wpa_s->sme.mfp;
9958 params.rrm_used = wpa_s->rrm.rrm_used;
9959 if (wpa_s->sme.prev_bssid_set)
9960 params.prev_bssid = wpa_s->sme.prev_bssid;
9961 wpa_printf(MSG_INFO, "TESTING: Resend association request");
9962 ret = wpa_drv_associate(wpa_s, &params);
9963 wpa_s->testing_resend_assoc = 1;
9964 return ret;
9965#else /* CONFIG_SME */
9966 return -1;
9967#endif /* CONFIG_SME */
9968}
9969
Hai Shaloma20dcd72022-02-04 13:43:00 -08009970
9971static int wpas_ctrl_iface_send_twt_setup(struct wpa_supplicant *wpa_s,
9972 const char *cmd)
9973{
9974 u8 dtok = 1;
9975 int exponent = 10;
9976 int mantissa = 8192;
9977 u8 min_twt = 255;
9978 unsigned long long twt = 0;
9979 bool requestor = true;
9980 int setup_cmd = 0;
9981 bool trigger = true;
9982 bool implicit = true;
9983 bool flow_type = true;
9984 int flow_id = 0;
9985 bool protection = false;
9986 u8 twt_channel = 0;
9987 u8 control = BIT(4); /* Control field (IEEE P802.11ax/D8.0 Figure
9988 * 9-687): B4 = TWT Information Frame Disabled */
9989 const char *tok_s;
9990
9991 tok_s = os_strstr(cmd, " dialog=");
9992 if (tok_s)
9993 dtok = atoi(tok_s + os_strlen(" dialog="));
9994
9995 tok_s = os_strstr(cmd, " exponent=");
9996 if (tok_s)
9997 exponent = atoi(tok_s + os_strlen(" exponent="));
9998
9999 tok_s = os_strstr(cmd, " mantissa=");
10000 if (tok_s)
10001 mantissa = atoi(tok_s + os_strlen(" mantissa="));
10002
10003 tok_s = os_strstr(cmd, " min_twt=");
10004 if (tok_s)
10005 min_twt = atoi(tok_s + os_strlen(" min_twt="));
10006
10007 tok_s = os_strstr(cmd, " setup_cmd=");
10008 if (tok_s)
10009 setup_cmd = atoi(tok_s + os_strlen(" setup_cmd="));
10010
10011 tok_s = os_strstr(cmd, " twt=");
10012 if (tok_s)
10013 sscanf(tok_s + os_strlen(" twt="), "%llu", &twt);
10014
10015 tok_s = os_strstr(cmd, " requestor=");
10016 if (tok_s)
10017 requestor = atoi(tok_s + os_strlen(" requestor="));
10018
10019 tok_s = os_strstr(cmd, " trigger=");
10020 if (tok_s)
10021 trigger = atoi(tok_s + os_strlen(" trigger="));
10022
10023 tok_s = os_strstr(cmd, " implicit=");
10024 if (tok_s)
10025 implicit = atoi(tok_s + os_strlen(" implicit="));
10026
10027 tok_s = os_strstr(cmd, " flow_type=");
10028 if (tok_s)
10029 flow_type = atoi(tok_s + os_strlen(" flow_type="));
10030
10031 tok_s = os_strstr(cmd, " flow_id=");
10032 if (tok_s)
10033 flow_id = atoi(tok_s + os_strlen(" flow_id="));
10034
10035 tok_s = os_strstr(cmd, " protection=");
10036 if (tok_s)
10037 protection = atoi(tok_s + os_strlen(" protection="));
10038
10039 tok_s = os_strstr(cmd, " twt_channel=");
10040 if (tok_s)
10041 twt_channel = atoi(tok_s + os_strlen(" twt_channel="));
10042
10043 tok_s = os_strstr(cmd, " control=");
10044 if (tok_s)
10045 control = atoi(tok_s + os_strlen(" control="));
10046
10047 return wpas_twt_send_setup(wpa_s, dtok, exponent, mantissa, min_twt,
10048 setup_cmd, twt, requestor, trigger, implicit,
10049 flow_type, flow_id, protection, twt_channel,
10050 control);
10051}
10052
10053
10054static int wpas_ctrl_iface_send_twt_teardown(struct wpa_supplicant *wpa_s,
10055 const char *cmd)
10056{
10057 u8 flags = 0x1;
10058 const char *tok_s;
10059
10060 tok_s = os_strstr(cmd, " flags=");
10061 if (tok_s)
10062 flags = atoi(tok_s + os_strlen(" flags="));
10063
10064 return wpas_twt_send_teardown(wpa_s, flags);
10065}
10066
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010067#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010068
10069
10070static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
10071{
10072 char *pos = cmd;
10073 int frame;
10074 size_t len;
10075 struct wpabuf *buf;
10076 struct ieee802_11_elems elems;
10077
10078 frame = atoi(pos);
10079 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10080 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010081 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010082
10083 pos = os_strchr(pos, ' ');
10084 if (pos == NULL)
10085 return -1;
10086 pos++;
10087
10088 len = os_strlen(pos);
10089 if (len == 0)
10090 return 0;
10091 if (len & 1)
10092 return -1;
10093 len /= 2;
10094
10095 buf = wpabuf_alloc(len);
10096 if (buf == NULL)
10097 return -1;
10098
10099 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
10100 wpabuf_free(buf);
10101 return -1;
10102 }
10103
10104 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
10105 ParseFailed) {
10106 wpabuf_free(buf);
10107 return -1;
10108 }
10109
10110 if (wpa_s->vendor_elem[frame] == NULL) {
10111 wpa_s->vendor_elem[frame] = buf;
Hai Shalom60840252021-02-19 19:02:11 -080010112 goto update_ies;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010113 }
10114
10115 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
10116 wpabuf_free(buf);
10117 return -1;
10118 }
10119
10120 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
10121 wpabuf_free(buf);
Hai Shalom60840252021-02-19 19:02:11 -080010122
10123update_ies:
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010124 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010125
Hai Shalom60840252021-02-19 19:02:11 -080010126 if (frame == VENDOR_ELEM_PROBE_REQ ||
10127 frame == VENDOR_ELEM_PROBE_REQ_P2P)
10128 wpa_supplicant_set_default_scan_ies(wpa_s);
10129
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010130 return 0;
10131}
10132
10133
10134static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
10135 char *buf, size_t buflen)
10136{
10137 int frame = atoi(cmd);
10138
10139 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10140 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010141 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010142
10143 if (wpa_s->vendor_elem[frame] == NULL)
10144 return 0;
10145
10146 return wpa_snprintf_hex(buf, buflen,
10147 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
10148 wpabuf_len(wpa_s->vendor_elem[frame]));
10149}
10150
10151
10152static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
10153{
10154 char *pos = cmd;
10155 int frame;
10156 size_t len;
10157 u8 *buf;
10158 struct ieee802_11_elems elems;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010159 int res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010160
10161 frame = atoi(pos);
10162 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
10163 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010164 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010165
10166 pos = os_strchr(pos, ' ');
10167 if (pos == NULL)
10168 return -1;
10169 pos++;
10170
10171 if (*pos == '*') {
10172 wpabuf_free(wpa_s->vendor_elem[frame]);
10173 wpa_s->vendor_elem[frame] = NULL;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010174 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010175 return 0;
10176 }
10177
10178 if (wpa_s->vendor_elem[frame] == NULL)
10179 return -1;
10180
10181 len = os_strlen(pos);
10182 if (len == 0)
10183 return 0;
10184 if (len & 1)
10185 return -1;
10186 len /= 2;
10187
10188 buf = os_malloc(len);
10189 if (buf == NULL)
10190 return -1;
10191
10192 if (hexstr2bin(pos, buf, len) < 0) {
10193 os_free(buf);
10194 return -1;
10195 }
10196
10197 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
10198 os_free(buf);
10199 return -1;
10200 }
10201
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010202 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010203 os_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010204 return res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010205}
10206
10207
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010208static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
10209{
10210 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010211 size_t len;
10212 const u8 *data;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010213
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010214 /*
10215 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
10216 * BSSID[6]
10217 * BSSID Information[4]
10218 * Operating Class[1]
10219 * Channel Number[1]
10220 * PHY Type[1]
10221 * Optional Subelements[variable]
10222 */
10223#define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
10224
10225 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010226 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010227 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010228 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010229
10230 data = wpabuf_head_u8(neighbor_rep);
10231 len = wpabuf_len(neighbor_rep);
10232
10233 while (len >= 2 + NR_IE_MIN_LEN) {
10234 const u8 *nr;
10235 char lci[256 * 2 + 1];
10236 char civic[256 * 2 + 1];
10237 u8 nr_len = data[1];
10238 const u8 *pos = data, *end;
10239
10240 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
10241 nr_len < NR_IE_MIN_LEN) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010242 wpa_dbg(wpa_s, MSG_DEBUG,
10243 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
10244 data[0], nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010245 goto out;
10246 }
10247
10248 if (2U + nr_len > len) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010249 wpa_dbg(wpa_s, MSG_DEBUG,
10250 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
10251 data[0], len, nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010252 goto out;
10253 }
10254 pos += 2;
10255 end = pos + nr_len;
10256
10257 nr = pos;
10258 pos += NR_IE_MIN_LEN;
10259
10260 lci[0] = '\0';
10261 civic[0] = '\0';
10262 while (end - pos > 2) {
10263 u8 s_id, s_len;
10264
10265 s_id = *pos++;
10266 s_len = *pos++;
10267 if (s_len > end - pos)
10268 goto out;
10269 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
10270 /* Measurement Token[1] */
10271 /* Measurement Report Mode[1] */
10272 /* Measurement Type[1] */
10273 /* Measurement Report[variable] */
10274 switch (pos[2]) {
10275 case MEASURE_TYPE_LCI:
10276 if (lci[0])
10277 break;
10278 wpa_snprintf_hex(lci, sizeof(lci),
10279 pos, s_len);
10280 break;
10281 case MEASURE_TYPE_LOCATION_CIVIC:
10282 if (civic[0])
10283 break;
10284 wpa_snprintf_hex(civic, sizeof(civic),
10285 pos, s_len);
10286 break;
10287 }
10288 }
10289
10290 pos += s_len;
10291 }
10292
10293 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
10294 "bssid=" MACSTR
10295 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
10296 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
10297 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
10298 nr[ETH_ALEN + 6],
10299 lci[0] ? " lci=" : "", lci,
10300 civic[0] ? " civic=" : "", civic);
10301
10302 data = end;
10303 len -= 2 + nr_len;
10304 }
10305
10306out:
10307 wpabuf_free(neighbor_rep);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010308}
10309
10310
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010311static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
10312 char *cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010313{
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010314 struct wpa_ssid_value ssid, *ssid_p = NULL;
10315 int ret, lci = 0, civic = 0;
10316 char *ssid_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010317
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010318 ssid_s = os_strstr(cmd, "ssid=");
10319 if (ssid_s) {
10320 if (ssid_parse(ssid_s + 5, &ssid)) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010321 wpa_msg(wpa_s, MSG_INFO,
10322 "CTRL: Send Neighbor Report: bad SSID");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010323 return -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010324 }
10325
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010326 ssid_p = &ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010327
10328 /*
10329 * Move cmd after the SSID text that may include "lci" or
10330 * "civic".
10331 */
10332 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
10333 if (cmd)
10334 cmd++;
10335
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010336 }
10337
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010338 if (cmd && os_strstr(cmd, "lci"))
10339 lci = 1;
10340
10341 if (cmd && os_strstr(cmd, "civic"))
10342 civic = 1;
10343
10344 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010345 wpas_ctrl_neighbor_rep_cb,
10346 wpa_s);
10347
10348 return ret;
10349}
10350
10351
10352static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
10353{
10354 eapol_sm_erp_flush(wpa_s->eapol);
10355 return 0;
10356}
10357
10358
10359static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
10360 char *cmd)
10361{
10362 char *token, *context = NULL;
10363 unsigned int enable = ~0, type = 0;
10364 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
10365 u8 *addr = NULL, *mask = NULL;
10366
10367 while ((token = str_token(cmd, " ", &context))) {
10368 if (os_strcasecmp(token, "scan") == 0) {
10369 type |= MAC_ADDR_RAND_SCAN;
10370 } else if (os_strcasecmp(token, "sched") == 0) {
10371 type |= MAC_ADDR_RAND_SCHED_SCAN;
10372 } else if (os_strcasecmp(token, "pno") == 0) {
10373 type |= MAC_ADDR_RAND_PNO;
10374 } else if (os_strcasecmp(token, "all") == 0) {
10375 type = wpa_s->mac_addr_rand_supported;
10376 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
10377 enable = atoi(token + 7);
10378 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
10379 addr = _addr;
10380 if (hwaddr_aton(token + 5, addr)) {
10381 wpa_printf(MSG_INFO,
10382 "CTRL: Invalid MAC address: %s",
10383 token);
10384 return -1;
10385 }
10386 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
10387 mask = _mask;
10388 if (hwaddr_aton(token + 5, mask)) {
10389 wpa_printf(MSG_INFO,
10390 "CTRL: Invalid MAC address mask: %s",
10391 token);
10392 return -1;
10393 }
10394 } else {
10395 wpa_printf(MSG_INFO,
10396 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
10397 token);
10398 return -1;
10399 }
10400 }
10401
10402 if (!type) {
10403 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
10404 return -1;
10405 }
10406
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010407 if (enable > 1) {
10408 wpa_printf(MSG_INFO,
10409 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
10410 return -1;
10411 }
10412
Hai Shalom81f62d82019-07-22 12:10:00 -070010413 if (!enable)
10414 return wpas_disable_mac_addr_randomization(wpa_s, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010415
Hai Shalom81f62d82019-07-22 12:10:00 -070010416 return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010417}
10418
10419
Dmitry Shmidte4663042016-04-04 10:07:49 -070010420static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
10421 char *buf, size_t buflen)
10422{
10423 size_t reply_len;
10424
10425 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
10426#ifdef CONFIG_AP
10427 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
10428 buflen - reply_len);
10429#endif /* CONFIG_AP */
10430 return reply_len;
10431}
10432
10433
10434static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
10435{
Hai Shalom60840252021-02-19 19:02:11 -080010436 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
Dmitry Shmidte4663042016-04-04 10:07:49 -070010437 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
10438#ifdef CONFIG_AP
10439 wpas_ap_pmksa_cache_flush(wpa_s);
10440#endif /* CONFIG_AP */
10441}
10442
10443
Dmitry Shmidt29333592017-01-09 12:27:11 -080010444#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10445
10446static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
10447 const char *cmd, char *buf, size_t buflen)
10448{
10449 struct rsn_pmksa_cache_entry *entry;
10450 struct wpa_ssid *ssid;
10451 char *pos, *pos2, *end;
10452 int ret;
10453 struct os_reltime now;
10454
10455 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10456 if (!ssid)
10457 return -1;
10458
10459 pos = buf;
10460 end = buf + buflen;
10461
10462 os_get_reltime(&now);
10463
10464 /*
10465 * Entry format:
10466 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10467 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010468 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010469 */
10470
10471 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
10472 entry = entry->next) {
10473 if (entry->network_ctx != ssid)
10474 continue;
10475
10476 pos2 = pos;
10477 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
10478 MAC2STR(entry->aa));
10479 if (os_snprintf_error(end - pos2, ret))
10480 break;
10481 pos2 += ret;
10482
10483 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
10484 PMKID_LEN);
10485
10486 ret = os_snprintf(pos2, end - pos2, " ");
10487 if (os_snprintf_error(end - pos2, ret))
10488 break;
10489 pos2 += ret;
10490
10491 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
10492 entry->pmk_len);
10493
10494 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
10495 (int) (entry->reauth_time - now.sec),
10496 (int) (entry->expiration - now.sec),
10497 entry->akmp,
10498 entry->opportunistic);
10499 if (os_snprintf_error(end - pos2, ret))
10500 break;
10501 pos2 += ret;
10502
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010503 if (entry->fils_cache_id_set) {
10504 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
10505 entry->fils_cache_id[0],
10506 entry->fils_cache_id[1]);
10507 if (os_snprintf_error(end - pos2, ret))
10508 break;
10509 pos2 += ret;
10510 }
10511
Dmitry Shmidt29333592017-01-09 12:27:11 -080010512 ret = os_snprintf(pos2, end - pos2, "\n");
10513 if (os_snprintf_error(end - pos2, ret))
10514 break;
10515 pos2 += ret;
10516
10517 pos = pos2;
10518 }
10519
10520 return pos - buf;
10521}
10522
10523
10524static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
10525 char *cmd)
10526{
10527 struct rsn_pmksa_cache_entry *entry;
10528 struct wpa_ssid *ssid;
10529 char *pos, *pos2;
10530 int ret = -1;
10531 struct os_reltime now;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010532 int reauth_time = 0, expiration = 0, i;
Dmitry Shmidt29333592017-01-09 12:27:11 -080010533
10534 /*
10535 * Entry format:
10536 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10537 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010538 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010539 */
10540
10541 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10542 if (!ssid)
10543 return -1;
10544
10545 pos = os_strchr(cmd, ' ');
10546 if (!pos)
10547 return -1;
10548 pos++;
10549
10550 entry = os_zalloc(sizeof(*entry));
10551 if (!entry)
10552 return -1;
10553
10554 if (hwaddr_aton(pos, entry->aa))
10555 goto fail;
10556
10557 pos = os_strchr(pos, ' ');
10558 if (!pos)
10559 goto fail;
10560 pos++;
10561
10562 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
10563 goto fail;
10564
10565 pos = os_strchr(pos, ' ');
10566 if (!pos)
10567 goto fail;
10568 pos++;
10569
10570 pos2 = os_strchr(pos, ' ');
10571 if (!pos2)
10572 goto fail;
10573 entry->pmk_len = (pos2 - pos) / 2;
10574 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
10575 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
10576 goto fail;
10577
10578 pos = os_strchr(pos, ' ');
10579 if (!pos)
10580 goto fail;
10581 pos++;
10582
10583 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
10584 &entry->akmp, &entry->opportunistic) != 4)
10585 goto fail;
Hai Shaloma20dcd72022-02-04 13:43:00 -080010586 if (reauth_time > expiration)
10587 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010588 for (i = 0; i < 4; i++) {
10589 pos = os_strchr(pos, ' ');
10590 if (!pos) {
10591 if (i < 3)
10592 goto fail;
10593 break;
10594 }
10595 pos++;
10596 }
10597 if (pos) {
10598 if (hexstr2bin(pos, entry->fils_cache_id,
10599 FILS_CACHE_ID_LEN) < 0)
10600 goto fail;
10601 entry->fils_cache_id_set = 1;
10602 }
Dmitry Shmidt29333592017-01-09 12:27:11 -080010603 os_get_reltime(&now);
10604 entry->expiration = now.sec + expiration;
10605 entry->reauth_time = now.sec + reauth_time;
10606
10607 entry->network_ctx = ssid;
10608
Hai Shaloma20dcd72022-02-04 13:43:00 -080010609 entry->external = true;
10610
Dmitry Shmidt29333592017-01-09 12:27:11 -080010611 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
10612 entry = NULL;
10613 ret = 0;
10614fail:
10615 os_free(entry);
10616 return ret;
10617}
10618
Paul Stewart092955c2017-02-06 09:13:09 -080010619
10620#ifdef CONFIG_MESH
10621
10622static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
10623 const char *cmd, char *buf,
10624 size_t buflen)
10625{
10626 u8 spa[ETH_ALEN];
10627
10628 if (!wpa_s->ifmsh)
10629 return -1;
10630
10631 if (os_strcasecmp(cmd, "any") == 0)
10632 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
10633
10634 if (hwaddr_aton(cmd, spa))
10635 return -1;
10636
10637 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
10638}
10639
10640
10641static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
10642 char *cmd)
10643{
10644 /*
Hai Shalom60840252021-02-19 19:02:11 -080010645 * We do not check mesh interface existence because PMKSA should be
Paul Stewart092955c2017-02-06 09:13:09 -080010646 * stored before wpa_s->ifmsh creation to suppress commit message
10647 * creation.
10648 */
10649 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
10650}
10651
10652#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080010653#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10654
10655
Paul Stewart092955c2017-02-06 09:13:09 -080010656#ifdef CONFIG_FILS
10657static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
10658 const char *cmd)
10659{
10660 struct fils_hlp_req *req;
10661 const char *pos;
10662
10663 /* format: <dst> <packet starting from ethertype> */
10664
10665 req = os_zalloc(sizeof(*req));
10666 if (!req)
10667 return -1;
10668
10669 if (hwaddr_aton(cmd, req->dst))
10670 goto fail;
10671
10672 pos = os_strchr(cmd, ' ');
10673 if (!pos)
10674 goto fail;
10675 pos++;
10676 req->pkt = wpabuf_parse_bin(pos);
10677 if (!req->pkt)
10678 goto fail;
10679
10680 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
10681 return 0;
10682fail:
10683 wpabuf_free(req->pkt);
10684 os_free(req);
10685 return -1;
10686}
10687#endif /* CONFIG_FILS */
10688
10689
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010690static int wpas_ctrl_cmd_debug_level(const char *cmd)
10691{
10692 if (os_strcmp(cmd, "PING") == 0 ||
10693 os_strncmp(cmd, "BSS ", 4) == 0 ||
10694 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
10695 os_strncmp(cmd, "STATUS", 6) == 0 ||
10696 os_strncmp(cmd, "STA ", 4) == 0 ||
10697 os_strncmp(cmd, "STA-", 4) == 0)
10698 return MSG_EXCESSIVE;
10699 return MSG_DEBUG;
10700}
10701
10702
Hai Shalom899fcc72020-10-19 14:38:18 -070010703static int wpas_ctrl_iface_configure_mscs(struct wpa_supplicant *wpa_s,
10704 const char *cmd)
10705{
10706 size_t frame_classifier_len;
10707 const char *pos, *end;
10708 struct robust_av_data *robust_av = &wpa_s->robust_av;
10709 int val;
10710
10711 /*
10712 * format:
10713 * <add|remove|change> [up_bitmap=<hex byte>] [up_limit=<integer>]
10714 * [stream_timeout=<in TUs>] [frame_classifier=<hex bytes>]
10715 */
10716 os_memset(robust_av, 0, sizeof(struct robust_av_data));
10717 if (os_strncmp(cmd, "add ", 4) == 0) {
10718 robust_av->request_type = SCS_REQ_ADD;
10719 } else if (os_strcmp(cmd, "remove") == 0) {
10720 robust_av->request_type = SCS_REQ_REMOVE;
10721 robust_av->valid_config = false;
10722 return wpas_send_mscs_req(wpa_s);
10723 } else if (os_strncmp(cmd, "change ", 7) == 0) {
10724 robust_av->request_type = SCS_REQ_CHANGE;
10725 } else {
10726 return -1;
10727 }
10728
10729 pos = os_strstr(cmd, "up_bitmap=");
10730 if (!pos)
10731 return -1;
10732
10733 val = hex2byte(pos + 10);
10734 if (val < 0)
10735 return -1;
10736 robust_av->up_bitmap = val;
10737
10738 pos = os_strstr(cmd, "up_limit=");
10739 if (!pos)
10740 return -1;
10741
10742 robust_av->up_limit = atoi(pos + 9);
10743
10744 pos = os_strstr(cmd, "stream_timeout=");
10745 if (!pos)
10746 return -1;
10747
10748 robust_av->stream_timeout = atoi(pos + 15);
10749 if (robust_av->stream_timeout == 0)
10750 return -1;
10751
10752 pos = os_strstr(cmd, "frame_classifier=");
10753 if (!pos)
10754 return -1;
10755
10756 pos += 17;
10757 end = os_strchr(pos, ' ');
10758 if (!end)
10759 end = pos + os_strlen(pos);
10760
10761 frame_classifier_len = (end - pos) / 2;
10762 if (frame_classifier_len > sizeof(robust_av->frame_classifier) ||
10763 hexstr2bin(pos, robust_av->frame_classifier, frame_classifier_len))
10764 return -1;
10765
10766 robust_av->frame_classifier_len = frame_classifier_len;
10767 robust_av->valid_config = true;
10768
10769 return wpas_send_mscs_req(wpa_s);
10770}
10771
10772
Hai Shalom60840252021-02-19 19:02:11 -080010773#ifdef CONFIG_PASN
10774static int wpas_ctrl_iface_pasn_start(struct wpa_supplicant *wpa_s, char *cmd)
10775{
10776 char *token, *context = NULL;
10777 u8 bssid[ETH_ALEN];
10778 int akmp = -1, cipher = -1, got_bssid = 0;
10779 u16 group = 0xFFFF;
Hai Shaloma20dcd72022-02-04 13:43:00 -080010780 u8 *comeback = NULL;
10781 size_t comeback_len = 0;
10782 int id = 0, ret = -1;
Hai Shalom60840252021-02-19 19:02:11 -080010783
10784 /*
10785 * Entry format: bssid=<BSSID> akmp=<AKMP> cipher=<CIPHER> group=<group>
Hai Shaloma20dcd72022-02-04 13:43:00 -080010786 * [comeback=<hexdump>]
Hai Shalom60840252021-02-19 19:02:11 -080010787 */
10788 while ((token = str_token(cmd, " ", &context))) {
10789 if (os_strncmp(token, "bssid=", 6) == 0) {
10790 if (hwaddr_aton(token + 6, bssid))
Hai Shaloma20dcd72022-02-04 13:43:00 -080010791 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080010792 got_bssid = 1;
10793 } else if (os_strcmp(token, "akmp=PASN") == 0) {
10794 akmp = WPA_KEY_MGMT_PASN;
10795#ifdef CONFIG_IEEE80211R
10796 } else if (os_strcmp(token, "akmp=FT-PSK") == 0) {
10797 akmp = WPA_KEY_MGMT_FT_PSK;
10798 } else if (os_strcmp(token, "akmp=FT-EAP-SHA384") == 0) {
10799 akmp = WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
10800 } else if (os_strcmp(token, "akmp=FT-EAP") == 0) {
10801 akmp = WPA_KEY_MGMT_FT_IEEE8021X;
10802#endif /* CONFIG_IEEE80211R */
10803#ifdef CONFIG_SAE
10804 } else if (os_strcmp(token, "akmp=SAE") == 0) {
10805 akmp = WPA_KEY_MGMT_SAE;
10806#endif /* CONFIG_SAE */
10807#ifdef CONFIG_FILS
10808 } else if (os_strcmp(token, "akmp=FILS-SHA256") == 0) {
10809 akmp = WPA_KEY_MGMT_FILS_SHA256;
10810 } else if (os_strcmp(token, "akmp=FILS-SHA384") == 0) {
10811 akmp = WPA_KEY_MGMT_FILS_SHA384;
10812#endif /* CONFIG_FILS */
10813 } else if (os_strcmp(token, "cipher=CCMP-256") == 0) {
10814 cipher = WPA_CIPHER_CCMP_256;
10815 } else if (os_strcmp(token, "cipher=GCMP-256") == 0) {
10816 cipher = WPA_CIPHER_GCMP_256;
10817 } else if (os_strcmp(token, "cipher=CCMP") == 0) {
10818 cipher = WPA_CIPHER_CCMP;
10819 } else if (os_strcmp(token, "cipher=GCMP") == 0) {
10820 cipher = WPA_CIPHER_GCMP;
10821 } else if (os_strncmp(token, "group=", 6) == 0) {
10822 group = atoi(token + 6);
10823 } else if (os_strncmp(token, "nid=", 4) == 0) {
10824 id = atoi(token + 4);
Hai Shaloma20dcd72022-02-04 13:43:00 -080010825 } else if (os_strncmp(token, "comeback=", 9) == 0) {
10826 comeback_len = os_strlen(token + 9);
10827 if (comeback || !comeback_len || comeback_len % 2)
10828 goto out;
10829
10830 comeback_len /= 2;
10831 comeback = os_malloc(comeback_len);
10832 if (!comeback ||
10833 hexstr2bin(token + 9, comeback, comeback_len))
10834 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080010835 } else {
10836 wpa_printf(MSG_DEBUG,
10837 "CTRL: PASN Invalid parameter: '%s'",
10838 token);
Hai Shaloma20dcd72022-02-04 13:43:00 -080010839 goto out;
Hai Shalom60840252021-02-19 19:02:11 -080010840 }
10841 }
10842
10843 if (!got_bssid || akmp == -1 || cipher == -1 || group == 0xFFFF) {
10844 wpa_printf(MSG_DEBUG,"CTRL: PASN missing parameter");
Hai Shaloma20dcd72022-02-04 13:43:00 -080010845 goto out;
10846 }
10847
10848 ret = wpas_pasn_auth_start(wpa_s, bssid, akmp, cipher, group, id,
10849 comeback, comeback_len);
10850out:
10851 os_free(comeback);
10852 return ret;
10853}
10854
10855
10856static int wpas_ctrl_iface_pasn_deauthenticate(struct wpa_supplicant *wpa_s,
10857 const char *cmd)
10858{
10859 u8 bssid[ETH_ALEN];
10860
10861 if (os_strncmp(cmd, "bssid=", 6) != 0 || hwaddr_aton(cmd + 6, bssid)) {
10862 wpa_printf(MSG_DEBUG,
10863 "CTRL: PASN_DEAUTH without valid BSSID");
Hai Shalom60840252021-02-19 19:02:11 -080010864 return -1;
10865 }
10866
Hai Shaloma20dcd72022-02-04 13:43:00 -080010867 return wpas_pasn_deauthenticate(wpa_s, bssid);
Hai Shalom60840252021-02-19 19:02:11 -080010868}
Hai Shaloma20dcd72022-02-04 13:43:00 -080010869
Hai Shalom60840252021-02-19 19:02:11 -080010870#endif /* CONFIG_PASN */
10871
10872
Hai Shaloma20dcd72022-02-04 13:43:00 -080010873static int set_type4_frame_classifier(const char *cmd,
10874 struct type4_params *param)
10875{
10876 const char *pos, *end;
10877 u8 classifier_mask = 0;
10878 int ret;
10879 char addr[INET6_ADDRSTRLEN];
10880 size_t alen;
10881
10882 if (os_strstr(cmd, "ip_version=ipv4")) {
10883 param->ip_version = IPV4;
10884 } else if (os_strstr(cmd, "ip_version=ipv6")) {
10885 param->ip_version = IPV6;
10886 } else {
10887 wpa_printf(MSG_ERROR, "IP version missing/invalid");
10888 return -1;
10889 }
10890
10891 classifier_mask |= BIT(0);
10892
10893 pos = os_strstr(cmd, "src_ip=");
10894 if (pos) {
10895 pos += 7;
10896 end = os_strchr(pos, ' ');
10897 if (!end)
10898 end = pos + os_strlen(pos);
10899
10900 alen = end - pos;
10901 if (alen >= INET6_ADDRSTRLEN)
10902 return -1;
10903 os_memcpy(addr, pos, alen);
10904 addr[alen] = '\0';
10905 if (param->ip_version == IPV4)
10906 ret = inet_pton(AF_INET, addr,
10907 &param->ip_params.v4.src_ip);
10908 else
10909 ret = inet_pton(AF_INET6, addr,
10910 &param->ip_params.v6.src_ip);
10911
10912 if (ret != 1) {
10913 wpa_printf(MSG_ERROR,
10914 "Error converting src IP address to binary ret=%d",
10915 ret);
10916 return -1;
10917 }
10918
10919 classifier_mask |= BIT(1);
10920 }
10921
10922 pos = os_strstr(cmd, "dst_ip=");
10923 if (pos) {
10924 pos += 7;
10925 end = os_strchr(pos, ' ');
10926 if (!end)
10927 end = pos + os_strlen(pos);
10928
10929 alen = end - pos;
10930 if (alen >= INET6_ADDRSTRLEN)
10931 return -1;
10932 os_memcpy(addr, pos, alen);
10933 addr[alen] = '\0';
10934 if (param->ip_version == IPV4)
10935 ret = inet_pton(AF_INET, addr,
10936 &param->ip_params.v4.dst_ip);
10937 else
10938 ret = inet_pton(AF_INET6, addr,
10939 &param->ip_params.v6.dst_ip);
10940
10941 if (ret != 1) {
10942 wpa_printf(MSG_ERROR,
10943 "Error converting dst IP address to binary ret=%d",
10944 ret);
10945 return -1;
10946 }
10947
10948 classifier_mask |= BIT(2);
10949 }
10950
10951 pos = os_strstr(cmd, "src_port=");
10952 if (pos && atoi(pos + 9) > 0) {
10953 if (param->ip_version == IPV4)
10954 param->ip_params.v4.src_port = atoi(pos + 9);
10955 else
10956 param->ip_params.v6.src_port = atoi(pos + 9);
10957 classifier_mask |= BIT(3);
10958 }
10959
10960 pos = os_strstr(cmd, "dst_port=");
10961 if (pos && atoi(pos + 9) > 0) {
10962 if (param->ip_version == IPV4)
10963 param->ip_params.v4.dst_port = atoi(pos + 9);
10964 else
10965 param->ip_params.v6.dst_port = atoi(pos + 9);
10966 classifier_mask |= BIT(4);
10967 }
10968
10969 pos = os_strstr(cmd, "dscp=");
10970 if (pos && atoi(pos + 5) > 0) {
10971 if (param->ip_version == IPV4)
10972 param->ip_params.v4.dscp = atoi(pos + 5);
10973 else
10974 param->ip_params.v6.dscp = atoi(pos + 5);
10975 classifier_mask |= BIT(5);
10976 }
10977
10978 if (param->ip_version == IPV4) {
10979 pos = os_strstr(cmd, "protocol=");
10980 if (pos) {
10981 if (os_strstr(pos, "udp")) {
10982 param->ip_params.v4.protocol = 17;
10983 } else if (os_strstr(pos, "tcp")) {
10984 param->ip_params.v4.protocol = 6;
10985 } else if (os_strstr(pos, "esp")) {
10986 param->ip_params.v4.protocol = 50;
10987 } else {
10988 wpa_printf(MSG_ERROR, "Invalid protocol");
10989 return -1;
10990 }
10991 classifier_mask |= BIT(6);
10992 }
10993 } else {
10994 pos = os_strstr(cmd, "next_header=");
10995 if (pos) {
10996 if (os_strstr(pos, "udp")) {
10997 param->ip_params.v6.next_header = 17;
10998 } else if (os_strstr(pos, "tcp")) {
10999 param->ip_params.v6.next_header = 6;
11000 } else if (os_strstr(pos, "esp")) {
11001 param->ip_params.v6.next_header = 50;
11002 } else {
11003 wpa_printf(MSG_ERROR, "Invalid next header");
11004 return -1;
11005 }
11006
11007 classifier_mask |= BIT(6);
11008 }
11009
11010 pos = os_strstr(cmd, "flow_label=");
11011 if (pos) {
11012 pos += 11;
11013 end = os_strchr(pos, ' ');
11014 if (!end)
11015 end = pos + os_strlen(pos);
11016
11017 if (end - pos != 6 ||
11018 hexstr2bin(pos, param->ip_params.v6.flow_label,
11019 3) ||
11020 param->ip_params.v6.flow_label[0] > 0x0F) {
11021 wpa_printf(MSG_ERROR, "Invalid flow label");
11022 return -1;
11023 }
11024
11025 classifier_mask |= BIT(7);
11026 }
11027 }
11028
11029 param->classifier_mask = classifier_mask;
11030 return 0;
11031}
11032
11033
11034static int set_type10_frame_classifier(const char *cmd,
11035 struct type10_params *param)
11036{
11037 const char *pos, *end;
11038 size_t filter_len;
11039
11040 pos = os_strstr(cmd, "prot_instance=");
11041 if (!pos) {
11042 wpa_printf(MSG_ERROR, "Protocol instance missing");
11043 return -1;
11044 }
11045 param->prot_instance = atoi(pos + 14);
11046
11047 pos = os_strstr(cmd, "prot_number=");
11048 if (!pos) {
11049 wpa_printf(MSG_ERROR, "Protocol number missing");
11050 return -1;
11051 }
11052 if (os_strstr(pos, "udp")) {
11053 param->prot_number = 17;
11054 } else if (os_strstr(pos, "tcp")) {
11055 param->prot_number = 6;
11056 } else if (os_strstr(pos, "esp")) {
11057 param->prot_number = 50;
11058 } else {
11059 wpa_printf(MSG_ERROR, "Invalid protocol number");
11060 return -1;
11061 }
11062
11063 pos = os_strstr(cmd, "filter_value=");
11064 if (!pos) {
11065 wpa_printf(MSG_ERROR,
11066 "Classifier parameter filter_value missing");
11067 return -1;
11068 }
11069
11070 pos += 13;
11071 end = os_strchr(pos, ' ');
11072 if (!end)
11073 end = pos + os_strlen(pos);
11074
11075 filter_len = (end - pos) / 2;
11076 param->filter_value = os_malloc(filter_len);
11077 if (!param->filter_value)
11078 return -1;
11079
11080 if (hexstr2bin(pos, param->filter_value, filter_len)) {
11081 wpa_printf(MSG_ERROR, "Invalid filter_value %s", pos);
11082 goto free;
11083 }
11084
11085 pos = os_strstr(cmd, "filter_mask=");
11086 if (!pos) {
11087 wpa_printf(MSG_ERROR,
11088 "Classifier parameter filter_mask missing");
11089 goto free;
11090 }
11091
11092 pos += 12;
11093 end = os_strchr(pos, ' ');
11094 if (!end)
11095 end = pos + os_strlen(pos);
11096
11097 if (filter_len != (size_t) (end - pos) / 2) {
11098 wpa_printf(MSG_ERROR,
11099 "Filter mask length mismatch expected=%zu received=%zu",
11100 filter_len, (size_t) (end - pos) / 2);
11101 goto free;
11102 }
11103
11104 param->filter_mask = os_malloc(filter_len);
11105 if (!param->filter_mask)
11106 goto free;
11107
11108 if (hexstr2bin(pos, param->filter_mask, filter_len)) {
11109 wpa_printf(MSG_ERROR, "Invalid filter mask %s", pos);
11110 os_free(param->filter_mask);
11111 param->filter_mask = NULL;
11112 goto free;
11113 }
11114
11115 param->filter_len = filter_len;
11116 return 0;
11117free:
11118 os_free(param->filter_value);
11119 param->filter_value = NULL;
11120 return -1;
11121}
11122
11123
11124static int scs_parse_type4(struct tclas_element *elem, const char *pos)
11125{
11126 struct type4_params type4_param = { 0 };
11127
11128 if (set_type4_frame_classifier(pos, &type4_param) == -1) {
11129 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 4");
11130 return -1;
11131 }
11132
11133 os_memcpy(&elem->frame_classifier.type4_param,
11134 &type4_param, sizeof(struct type4_params));
11135 return 0;
11136}
11137
11138
11139static int scs_parse_type10(struct tclas_element *elem, const char *pos)
11140{
11141 struct type10_params type10_param = { 0 };
11142
11143 if (set_type10_frame_classifier(pos, &type10_param) == -1) {
11144 wpa_printf(MSG_ERROR, "Failed to set frame_classifier 10");
11145 return -1;
11146 }
11147
11148 os_memcpy(&elem->frame_classifier.type10_param,
11149 &type10_param, sizeof(struct type10_params));
11150 return 0;
11151}
11152
11153
11154static int wpas_ctrl_iface_configure_scs(struct wpa_supplicant *wpa_s,
11155 char *cmd)
11156{
11157 char *pos1, *pos;
11158 struct scs_robust_av_data *scs_data = &wpa_s->scs_robust_av_req;
11159 struct scs_desc_elem desc_elem = { 0 };
11160 int val;
11161 unsigned int num_scs_desc = 0;
11162
11163 if (wpa_s->ongoing_scs_req) {
11164 wpa_printf(MSG_ERROR, "%s: SCS Request already in queue",
11165 __func__);
11166 return -1;
11167 }
11168
11169 /**
11170 * format:
11171 * [scs_id=<decimal number>] <add|remove|change> [scs_up=<0-7>]
11172 * [classifier_type=<4|10>]
11173 * [classifier params based on classifier type]
11174 * [tclas_processing=<0|1>] [scs_id=<decimal number>] ...
11175 */
11176 pos1 = os_strstr(cmd, "scs_id=");
11177 if (!pos1) {
11178 wpa_printf(MSG_ERROR, "SCSID not present");
11179 return -1;
11180 }
11181
11182 free_up_scs_desc(scs_data);
11183
11184 while (pos1) {
11185 struct scs_desc_elem *n1;
11186 struct active_scs_elem *active_scs_desc;
11187 char *next_scs_desc;
11188 unsigned int num_tclas_elem = 0;
11189 bool scsid_active = false;
11190
11191 desc_elem.scs_id = atoi(pos1 + 7);
11192 pos1 += 7;
11193
11194 next_scs_desc = os_strstr(pos1, "scs_id=");
11195 if (next_scs_desc) {
11196 char temp[20];
11197
11198 os_snprintf(temp, sizeof(temp), "scs_id=%d ",
11199 desc_elem.scs_id);
11200 if (os_strstr(next_scs_desc, temp)) {
11201 wpa_printf(MSG_ERROR,
11202 "Multiple SCS descriptors configured with same SCSID(=%d)",
11203 desc_elem.scs_id);
11204 goto free_scs_desc;
11205 }
11206 pos1[next_scs_desc - pos1 - 1] = '\0';
11207 }
11208
11209 dl_list_for_each(active_scs_desc, &wpa_s->active_scs_ids,
11210 struct active_scs_elem, list) {
11211 if (desc_elem.scs_id == active_scs_desc->scs_id) {
11212 scsid_active = true;
11213 break;
11214 }
11215 }
11216
11217 if (os_strstr(pos1, "add ")) {
11218 desc_elem.request_type = SCS_REQ_ADD;
11219 if (scsid_active) {
11220 wpa_printf(MSG_ERROR, "SCSID %d already active",
11221 desc_elem.scs_id);
11222 return -1;
11223 }
11224 } else if (os_strstr(pos1, "remove")) {
11225 desc_elem.request_type = SCS_REQ_REMOVE;
11226 if (!scsid_active) {
11227 wpa_printf(MSG_ERROR, "SCSID %d not active",
11228 desc_elem.scs_id);
11229 return -1;
11230 }
11231 goto scs_desc_end;
11232 } else if (os_strstr(pos1, "change ")) {
11233 desc_elem.request_type = SCS_REQ_CHANGE;
11234 if (!scsid_active) {
11235 wpa_printf(MSG_ERROR, "SCSID %d not active",
11236 desc_elem.scs_id);
11237 return -1;
11238 }
11239 } else {
11240 wpa_printf(MSG_ERROR, "SCS Request type invalid");
11241 goto free_scs_desc;
11242 }
11243
11244 pos1 = os_strstr(pos1, "scs_up=");
11245 if (!pos1) {
11246 wpa_printf(MSG_ERROR,
11247 "Intra-Access user priority not present");
11248 goto free_scs_desc;
11249 }
11250
11251 val = atoi(pos1 + 7);
11252 if (val < 0 || val > 7) {
11253 wpa_printf(MSG_ERROR,
11254 "Intra-Access user priority invalid %d",
11255 val);
11256 goto free_scs_desc;
11257 }
11258
11259 desc_elem.intra_access_priority = val;
11260 desc_elem.scs_up_avail = true;
11261
11262 pos = os_strstr(pos1, "classifier_type=");
11263 if (!pos) {
11264 wpa_printf(MSG_ERROR, "classifier type empty");
11265 goto free_scs_desc;
11266 }
11267
11268 while (pos) {
11269 struct tclas_element elem = { 0 }, *n;
11270 char *next_tclas_elem;
11271
11272 val = atoi(pos + 16);
11273 if (val != 4 && val != 10) {
11274 wpa_printf(MSG_ERROR,
11275 "classifier type invalid %d", val);
11276 goto free_scs_desc;
11277 }
11278
11279 elem.classifier_type = val;
11280 pos += 16;
11281
11282 next_tclas_elem = os_strstr(pos, "classifier_type=");
11283 if (next_tclas_elem) {
11284 pos1 = next_tclas_elem;
11285 pos[next_tclas_elem - pos - 1] = '\0';
11286 }
11287
11288 switch (val) {
11289 case 4:
11290 if (scs_parse_type4(&elem, pos) < 0)
11291 goto free_scs_desc;
11292 break;
11293 case 10:
11294 if (scs_parse_type10(&elem, pos) < 0)
11295 goto free_scs_desc;
11296 break;
11297 }
11298
11299 n = os_realloc(desc_elem.tclas_elems,
11300 (num_tclas_elem + 1) * sizeof(elem));
11301 if (!n)
11302 goto free_scs_desc;
11303
11304 desc_elem.tclas_elems = n;
11305 os_memcpy((u8 *) desc_elem.tclas_elems +
11306 num_tclas_elem * sizeof(elem),
11307 &elem, sizeof(elem));
11308 num_tclas_elem++;
11309 desc_elem.num_tclas_elem = num_tclas_elem;
11310 pos = next_tclas_elem;
11311 }
11312
11313 if (desc_elem.num_tclas_elem > 1) {
11314 pos1 = os_strstr(pos1, "tclas_processing=");
11315 if (!pos1) {
11316 wpa_printf(MSG_ERROR, "tclas_processing empty");
11317 goto free_scs_desc;
11318 }
11319
11320 val = atoi(pos1 + 17);
11321 if (val != 0 && val != 1) {
11322 wpa_printf(MSG_ERROR,
11323 "tclas_processing invalid");
11324 goto free_scs_desc;
11325 }
11326
11327 desc_elem.tclas_processing = val;
11328 }
11329
11330scs_desc_end:
11331 n1 = os_realloc(scs_data->scs_desc_elems, (num_scs_desc + 1) *
11332 sizeof(struct scs_desc_elem));
11333 if (!n1)
11334 goto free_scs_desc;
11335
11336 scs_data->scs_desc_elems = n1;
11337 os_memcpy((u8 *) scs_data->scs_desc_elems + num_scs_desc *
11338 sizeof(desc_elem), &desc_elem, sizeof(desc_elem));
11339 num_scs_desc++;
11340 scs_data->num_scs_desc = num_scs_desc;
11341 pos1 = next_scs_desc;
11342 os_memset(&desc_elem, 0, sizeof(desc_elem));
11343 }
11344
11345 return wpas_send_scs_req(wpa_s);
11346
11347free_scs_desc:
11348 free_up_tclas_elem(&desc_elem);
11349 free_up_scs_desc(scs_data);
11350 return -1;
11351}
11352
11353
11354static int wpas_ctrl_iface_send_dscp_resp(struct wpa_supplicant *wpa_s,
11355 const char *cmd)
11356{
11357 char *pos;
11358 struct dscp_policy_status *policy = NULL, *n;
11359 int num_policies = 0, ret = -1;
11360 struct dscp_resp_data resp_data;
11361
11362 /*
11363 * format:
11364 * <[reset]>/<[solicited] [policy_id=1 status=0...]> [more]
11365 */
11366
11367 os_memset(&resp_data, 0, sizeof(resp_data));
11368
11369 resp_data.more = os_strstr(cmd, "more") != NULL;
11370
11371 if (os_strstr(cmd, "reset")) {
11372 resp_data.reset = true;
11373 resp_data.solicited = false;
11374 goto send_resp;
11375 }
11376
11377 resp_data.solicited = os_strstr(cmd, "solicited") != NULL;
11378
11379 pos = os_strstr(cmd, "policy_id=");
11380 while (pos) {
11381 n = os_realloc(policy, (num_policies + 1) * sizeof(*policy));
11382 if (!n)
11383 goto fail;
11384
11385 policy = n;
11386 pos += 10;
11387 policy[num_policies].id = atoi(pos);
11388 if (policy[num_policies].id == 0) {
11389 wpa_printf(MSG_ERROR, "DSCP: Invalid policy id");
11390 goto fail;
11391 }
11392
11393 pos = os_strstr(pos, "status=");
11394 if (!pos) {
11395 wpa_printf(MSG_ERROR,
11396 "DSCP: Status is not found for a policy");
11397 goto fail;
11398 }
11399
11400 pos += 7;
11401 policy[num_policies].status = atoi(pos);
11402 num_policies++;
11403
11404 pos = os_strstr(pos, "policy_id");
11405 }
11406
11407 resp_data.policy = policy;
11408 resp_data.num_policies = num_policies;
11409send_resp:
11410 ret = wpas_send_dscp_response(wpa_s, &resp_data);
11411 if (ret)
11412 wpa_printf(MSG_ERROR, "DSCP: Failed to send DSCP response");
11413fail:
11414 os_free(policy);
11415 return ret;
11416}
11417
11418
11419static int wpas_ctrl_iface_send_dscp_query(struct wpa_supplicant *wpa_s,
11420 const char *cmd)
11421{
11422 char *pos;
11423
11424 /*
11425 * format:
11426 * Wildcard DSCP query
11427 * <wildcard>
11428 *
11429 * DSCP query with a domain name attribute:
11430 * [domain_name=<string>]
11431 */
11432
11433 if (os_strstr(cmd, "wildcard")) {
11434 wpa_printf(MSG_DEBUG, "QM: Send wildcard DSCP policy query");
11435 return wpas_send_dscp_query(wpa_s, NULL, 0);
11436 }
11437
11438 pos = os_strstr(cmd, "domain_name=");
11439 if (!pos || !os_strlen(pos + 12)) {
11440 wpa_printf(MSG_ERROR, "QM: Domain name not preset");
11441 return -1;
11442 }
11443
11444 return wpas_send_dscp_query(wpa_s, pos + 12, os_strlen(pos + 12));
11445}
11446
11447
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011448char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
11449 char *buf, size_t *resp_len)
11450{
11451 char *reply;
11452 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011453 int reply_len;
11454
11455 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011456 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
11457 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
11458 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011459 if (wpa_debug_show_keys)
11460 wpa_dbg(wpa_s, MSG_DEBUG,
11461 "Control interface command '%s'", buf);
11462 else
11463 wpa_dbg(wpa_s, MSG_DEBUG,
11464 "Control interface command '%s [REMOVED]'",
11465 os_strncmp(buf, WPA_CTRL_RSP,
11466 os_strlen(WPA_CTRL_RSP)) == 0 ?
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011467 WPA_CTRL_RSP :
11468 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
11469 "SET_NETWORK" : "key-add"));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011470 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
Dmitry Shmidt21de2142014-04-08 10:50:52 -070011471 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011472 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
11473 (const u8 *) buf, os_strlen(buf));
11474 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011475 int level = wpas_ctrl_cmd_debug_level(buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -070011476 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011477 }
11478
11479 reply = os_malloc(reply_size);
11480 if (reply == NULL) {
11481 *resp_len = 1;
11482 return NULL;
11483 }
11484
11485 os_memcpy(reply, "OK\n", 3);
11486 reply_len = 3;
11487
11488 if (os_strcmp(buf, "PING") == 0) {
11489 os_memcpy(reply, "PONG\n", 5);
11490 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070011491 } else if (os_strcmp(buf, "IFNAME") == 0) {
11492 reply_len = os_strlen(wpa_s->ifname);
11493 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011494 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
11495 if (wpa_debug_reopen_file() < 0)
11496 reply_len = -1;
11497 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
11498 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
11499 } else if (os_strcmp(buf, "MIB") == 0) {
11500 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
11501 if (reply_len >= 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011502 reply_len += eapol_sm_get_mib(wpa_s->eapol,
11503 reply + reply_len,
11504 reply_size - reply_len);
Hai Shalom74f70d42019-02-11 14:42:39 -080011505#ifdef CONFIG_MACSEC
11506 reply_len += ieee802_1x_kay_get_mib(
11507 wpa_s->kay, reply + reply_len,
11508 reply_size - reply_len);
11509#endif /* CONFIG_MACSEC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011510 }
11511 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
11512 reply_len = wpa_supplicant_ctrl_iface_status(
11513 wpa_s, buf + 6, reply, reply_size);
11514 } else if (os_strcmp(buf, "PMKSA") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070011515 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070011516 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070011517 wpas_ctrl_iface_pmksa_flush(wpa_s);
Dmitry Shmidt29333592017-01-09 12:27:11 -080011518#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
11519 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
11520 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
11521 reply, reply_size);
11522 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
11523 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
11524 reply_len = -1;
Paul Stewart092955c2017-02-06 09:13:09 -080011525#ifdef CONFIG_MESH
11526 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
11527 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
11528 reply, reply_size);
11529 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
11530 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
11531 reply_len = -1;
11532#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080011533#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011534 } else if (os_strncmp(buf, "SET ", 4) == 0) {
11535 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
11536 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080011537 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
11538 reply_len = wpa_config_dump_values(wpa_s->conf,
11539 reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011540 } else if (os_strncmp(buf, "GET ", 4) == 0) {
11541 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
11542 reply, reply_size);
11543 } else if (os_strcmp(buf, "LOGON") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070011544 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011545 } else if (os_strcmp(buf, "LOGOFF") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070011546 eapol_sm_notify_logoff(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011547 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
11548 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
11549 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080011550 else
11551 wpas_request_connection(wpa_s);
Dmitry Shmidt98660862014-03-11 17:26:21 -070011552 } else if (os_strcmp(buf, "REATTACH") == 0) {
11553 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
11554 !wpa_s->current_ssid)
11555 reply_len = -1;
11556 else {
11557 wpa_s->reattach = 1;
11558 wpas_request_connection(wpa_s);
11559 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011560 } else if (os_strcmp(buf, "RECONNECT") == 0) {
11561 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
11562 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080011563 else if (wpa_s->disconnected)
11564 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011565#ifdef IEEE8021X_EAPOL
11566 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
11567 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
11568 reply_len = -1;
11569#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011570#ifdef CONFIG_IEEE80211R
11571 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
11572 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
11573 reply_len = -1;
11574#endif /* CONFIG_IEEE80211R */
11575#ifdef CONFIG_WPS
11576 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
11577 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
11578 if (res == -2) {
11579 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
11580 reply_len = 17;
11581 } else if (res)
11582 reply_len = -1;
11583 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
11584 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
11585 if (res == -2) {
11586 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
11587 reply_len = 17;
11588 } else if (res)
11589 reply_len = -1;
11590 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
11591 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
11592 reply,
11593 reply_size);
11594 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
11595 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
11596 wpa_s, buf + 14, reply, reply_size);
11597 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
11598 if (wpas_wps_cancel(wpa_s))
11599 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070011600#ifdef CONFIG_WPS_NFC
11601 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
11602 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
11603 reply_len = -1;
11604 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
11605 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
11606 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -080011607 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
11608 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
11609 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070011610 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
11611 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
11612 wpa_s, buf + 14, reply, reply_size);
11613 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
11614 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
11615 buf + 17))
11616 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080011617 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
11618 reply_len = wpas_ctrl_nfc_get_handover_req(
11619 wpa_s, buf + 21, reply, reply_size);
11620 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
11621 reply_len = wpas_ctrl_nfc_get_handover_sel(
11622 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -080011623 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
11624 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
11625 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070011626#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011627 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
11628 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
11629 reply_len = -1;
11630#ifdef CONFIG_AP
11631 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
11632 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
11633 wpa_s, buf + 11, reply, reply_size);
11634#endif /* CONFIG_AP */
11635#ifdef CONFIG_WPS_ER
11636 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
11637 if (wpas_wps_er_start(wpa_s, NULL))
11638 reply_len = -1;
11639 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
11640 if (wpas_wps_er_start(wpa_s, buf + 13))
11641 reply_len = -1;
11642 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011643 wpas_wps_er_stop(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011644 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
11645 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
11646 reply_len = -1;
11647 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
11648 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
11649 if (ret == -2) {
11650 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
11651 reply_len = 17;
11652 } else if (ret == -3) {
11653 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
11654 reply_len = 18;
11655 } else if (ret == -4) {
11656 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
11657 reply_len = 20;
11658 } else if (ret)
11659 reply_len = -1;
11660 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
11661 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
11662 reply_len = -1;
11663 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
11664 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
11665 buf + 18))
11666 reply_len = -1;
11667 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
11668 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
11669 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070011670#ifdef CONFIG_WPS_NFC
11671 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
11672 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
11673 wpa_s, buf + 24, reply, reply_size);
11674#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011675#endif /* CONFIG_WPS_ER */
11676#endif /* CONFIG_WPS */
11677#ifdef CONFIG_IBSS_RSN
11678 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
11679 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
11680 reply_len = -1;
11681#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011682#ifdef CONFIG_MESH
11683 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
11684 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
11685 wpa_s, buf + 19, reply, reply_size);
11686 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
11687 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
11688 wpa_s, "", reply, reply_size);
11689 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
11690 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
11691 reply_len = -1;
11692 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
11693 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
11694 buf + 18))
11695 reply_len = -1;
Dmitry Shmidte4663042016-04-04 10:07:49 -070011696 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
11697 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
11698 reply_len = -1;
11699 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
11700 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
11701 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070011702 } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) {
11703 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16))
11704 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011705#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011706#ifdef CONFIG_P2P
11707 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011708 if (p2p_ctrl_find(wpa_s, buf + 8))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011709 reply_len = -1;
11710 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
11711 if (p2p_ctrl_find(wpa_s, ""))
11712 reply_len = -1;
11713 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
11714 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011715 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
11716 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
11717 reply_len = -1;
11718 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
11719 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
11720 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011721 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
11722 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
11723 reply_size);
11724 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
11725 if (p2p_ctrl_listen(wpa_s, buf + 11))
11726 reply_len = -1;
11727 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
11728 if (p2p_ctrl_listen(wpa_s, ""))
11729 reply_len = -1;
11730 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
11731 if (wpas_p2p_group_remove(wpa_s, buf + 17))
11732 reply_len = -1;
11733 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070011734 if (p2p_ctrl_group_add(wpa_s, ""))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011735 reply_len = -1;
11736 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
11737 if (p2p_ctrl_group_add(wpa_s, buf + 14))
11738 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011739 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
11740 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
11741 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011742 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
11743 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
11744 reply_len = -1;
11745 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
11746 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
11747 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
11748 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
11749 reply_size);
11750 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
11751 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
11752 reply_len = -1;
11753 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
11754 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
11755 reply_len = -1;
11756 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
11757 wpas_p2p_sd_service_update(wpa_s);
11758 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
11759 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
11760 reply_len = -1;
11761 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
11762 wpas_p2p_service_flush(wpa_s);
11763 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
11764 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
11765 reply_len = -1;
11766 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
11767 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
11768 reply_len = -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011769 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
11770 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
11771 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011772 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
11773 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
11774 reply_len = -1;
11775 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
11776 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
11777 reply_len = -1;
11778 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
11779 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
11780 reply_size);
11781 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
11782 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
11783 reply_len = -1;
11784 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -070011785 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011786 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
11787 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
11788 reply_len = -1;
11789 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
11790 if (wpas_p2p_cancel(wpa_s))
11791 reply_len = -1;
11792 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
11793 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
11794 reply_len = -1;
11795 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
11796 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
11797 reply_len = -1;
11798 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
11799 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
11800 reply_len = -1;
11801 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
11802 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
11803 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070011804 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
11805 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
11806 reply_len = -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070011807 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
11808 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
11809 reply_len = -1;
11810 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
11811 if (wpas_p2p_lo_stop(wpa_s))
11812 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011813#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070011814#ifdef CONFIG_WIFI_DISPLAY
11815 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
11816 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
11817 reply_len = -1;
11818 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
11819 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
11820 reply, reply_size);
11821#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011822#ifdef CONFIG_INTERWORKING
11823 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
11824 if (interworking_fetch_anqp(wpa_s) < 0)
11825 reply_len = -1;
11826 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
11827 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011828 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
11829 if (ctrl_interworking_select(wpa_s, NULL) < 0)
11830 reply_len = -1;
11831 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
11832 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011833 reply_len = -1;
11834 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -080011835 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011836 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080011837 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
11838 int id;
11839
11840 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
11841 if (id < 0)
11842 reply_len = -1;
11843 else {
11844 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
11845 if (os_snprintf_error(reply_size, reply_len))
11846 reply_len = -1;
11847 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011848 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
11849 if (get_anqp(wpa_s, buf + 9) < 0)
11850 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070011851 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
11852 if (gas_request(wpa_s, buf + 12) < 0)
11853 reply_len = -1;
11854 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
11855 reply_len = gas_response_get(wpa_s, buf + 17, reply,
11856 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011857#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -070011858#ifdef CONFIG_HS20
11859 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
11860 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
11861 reply_len = -1;
11862 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
11863 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
11864 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080011865 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080011866 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
11867 reply_len = -1;
11868 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
11869 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
11870 reply_len = -1;
11871 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
11872 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
11873 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
11874 if (del_hs20_icon(wpa_s, buf + 14) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080011875 reply_len = -1;
11876 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070011877 if (hs20_fetch_osu(wpa_s, 0) < 0)
11878 reply_len = -1;
11879 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
11880 if (hs20_fetch_osu(wpa_s, 1) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080011881 reply_len = -1;
11882 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
11883 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -070011884#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011885 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
11886 {
11887 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
11888 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
11889 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -070011890 else {
11891 /*
11892 * Notify response from timeout to allow the control
11893 * interface response to be sent first.
11894 */
11895 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
11896 wpa_s, NULL);
11897 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011898 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
11899 if (wpa_supplicant_reload_configuration(wpa_s))
11900 reply_len = -1;
11901 } else if (os_strcmp(buf, "TERMINATE") == 0) {
11902 wpa_supplicant_terminate_proc(wpa_s->global);
11903 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
11904 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
11905 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080011906 } else if (os_strncmp(buf, "BSSID_IGNORE", 12) == 0) {
11907 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
11908 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidte19501d2011-03-16 14:32:18 -070011909 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -080011910 /* deprecated backwards compatibility alias for BSSID_IGNORE */
11911 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011912 wpa_s, buf + 9, reply, reply_size);
11913 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
11914 reply_len = wpa_supplicant_ctrl_iface_log_level(
11915 wpa_s, buf + 9, reply, reply_size);
Vinit Deshpandeda134e92014-12-02 10:59:29 -080011916 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
11917 reply_len = wpa_supplicant_ctrl_iface_list_networks(
11918 wpa_s, buf + 14, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011919 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
11920 reply_len = wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -080011921 wpa_s, NULL, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011922 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070011923 wpas_request_disconnection(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011924 } else if (os_strcmp(buf, "SCAN") == 0) {
11925 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
11926 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
11927 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011928 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
11929 reply_len = wpa_supplicant_ctrl_iface_scan_results(
11930 wpa_s, reply, reply_size);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011931 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
11932 if (wpas_abort_ongoing_scan(wpa_s) < 0)
11933 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011934 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
11935 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
11936 reply_len = -1;
11937 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
11938 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
11939 reply_len = -1;
11940 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
11941 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
11942 reply_len = -1;
11943 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
11944 reply_len = wpa_supplicant_ctrl_iface_add_network(
11945 wpa_s, reply, reply_size);
11946 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
11947 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
11948 reply_len = -1;
11949 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
11950 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
11951 reply_len = -1;
11952 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
11953 reply_len = wpa_supplicant_ctrl_iface_get_network(
11954 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt684785c2014-05-12 13:34:29 -070011955 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011956 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
11957 wpa_s))
Dmitry Shmidt684785c2014-05-12 13:34:29 -070011958 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070011959 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
11960 reply_len = wpa_supplicant_ctrl_iface_list_creds(
11961 wpa_s, reply, reply_size);
11962 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
11963 reply_len = wpa_supplicant_ctrl_iface_add_cred(
11964 wpa_s, reply, reply_size);
11965 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
11966 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
11967 reply_len = -1;
11968 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
11969 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
11970 reply_len = -1;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -070011971 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
11972 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
11973 reply,
11974 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011975#ifndef CONFIG_NO_CONFIG_WRITE
11976 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
11977 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
11978 reply_len = -1;
11979#endif /* CONFIG_NO_CONFIG_WRITE */
11980 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
11981 reply_len = wpa_supplicant_ctrl_iface_get_capability(
11982 wpa_s, buf + 15, reply, reply_size);
11983 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
11984 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
11985 reply_len = -1;
11986 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
11987 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
11988 reply_len = -1;
11989 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
11990 reply_len = wpa_supplicant_global_iface_list(
11991 wpa_s->global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011992 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011993 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011994 wpa_s->global, buf + 10, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011995 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
11996 reply_len = wpa_supplicant_ctrl_iface_bss(
11997 wpa_s, buf + 4, reply, reply_size);
11998#ifdef CONFIG_AP
11999 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
12000 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
12001 } else if (os_strncmp(buf, "STA ", 4) == 0) {
12002 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
12003 reply_size);
12004 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
12005 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
12006 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012007 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
12008 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
12009 reply_len = -1;
12010 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
12011 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
12012 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080012013 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
12014 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
12015 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080012016 } else if (os_strcmp(buf, "STOP_AP") == 0) {
12017 if (wpas_ap_stop_ap(wpa_s))
12018 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080012019 } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) {
12020 if (wpas_ap_update_beacon(wpa_s))
12021 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012022#endif /* CONFIG_AP */
12023 } else if (os_strcmp(buf, "SUSPEND") == 0) {
12024 wpas_notify_suspend(wpa_s->global);
12025 } else if (os_strcmp(buf, "RESUME") == 0) {
12026 wpas_notify_resume(wpa_s->global);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070012027#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012028 } else if (os_strcmp(buf, "DROP_SA") == 0) {
12029 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070012030#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012031 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
12032 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
12033 reply_len = -1;
12034 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012035 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012036 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
12037 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
12038 reply_len = -1;
12039 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
12040 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
12041 buf + 17))
12042 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -070012043 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012044 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012045#ifdef CONFIG_TDLS
12046 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
12047 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
12048 reply_len = -1;
12049 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
12050 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
12051 reply_len = -1;
12052 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
12053 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
12054 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012055 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
12056 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
12057 buf + 17))
12058 reply_len = -1;
12059 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
12060 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
12061 buf + 24))
12062 reply_len = -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -070012063 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
12064 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
12065 wpa_s, buf + 17, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012066#endif /* CONFIG_TDLS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012067 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
12068 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
12069 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
12070 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
12071 reply_len = -1;
12072 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
12073 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
12074 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012075 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
12076 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
12077 reply_size);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080012078 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
12079 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
12080 reply_len = -1;
Yuhao Zhengfcd6f212012-07-27 10:37:52 -070012081 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
12082 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
12083 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070012084#ifdef CONFIG_AUTOSCAN
12085 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
12086 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
12087 reply_len = -1;
12088#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070012089 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
12090 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
12091 reply_size);
Hai Shalomb755a2a2020-04-23 21:49:02 -070012092 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
12093 reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply,
12094 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080012095#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -070012096 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
12097 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
12098 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080012099#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080012100 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
12101 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
12102 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012103 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080012104 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012105 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080012106#ifdef CONFIG_WNM
12107 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
12108 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
12109 reply_len = -1;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080012110 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
12111 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
Dmitry Shmidt44c95782013-05-17 09:51:35 -070012112 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -080012113 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
12114 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
12115 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080012116#endif /* CONFIG_WNM */
Dmitry Shmidt444d5672013-04-01 13:08:44 -070012117 } else if (os_strcmp(buf, "FLUSH") == 0) {
12118 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080012119 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
12120 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
12121 reply_size);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070012122#ifdef CONFIG_TESTING_OPTIONS
12123 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
12124 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
12125 reply_len = -1;
12126 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
12127 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070012128 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
12129 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
12130 reply_len = -1;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -070012131 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
12132 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
12133 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012134 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
12135 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
12136 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080012137 } else if (os_strncmp(buf, "EAPOL_TX ", 9) == 0) {
12138 if (wpas_ctrl_iface_eapol_tx(wpa_s, buf + 9) < 0)
12139 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012140 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
12141 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
12142 reply_len = -1;
12143 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
12144 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
12145 reply_len = -1;
12146 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
12147 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
12148 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -080012149 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
12150 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
12151 reply_len = -1;
12152 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
12153 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012154 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
12155 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
12156 reply_len = -1;
12157 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
12158 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
Jouni Malinenc4818362015-10-04 11:45:13 +030012159 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
12160 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
12161 reply_len = -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080012162 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
12163 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
12164 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012165 } else if (os_strcmp(buf, "RESET_PN") == 0) {
12166 if (wpas_ctrl_reset_pn(wpa_s) < 0)
12167 reply_len = -1;
12168 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
12169 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
12170 reply_len = -1;
12171 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
12172 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
12173 reply_len = -1;
Hai Shalom74f70d42019-02-11 14:42:39 -080012174 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
12175 sme_event_unprot_disconnect(
12176 wpa_s, wpa_s->bssid, NULL,
12177 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
Hai Shaloma20dcd72022-02-04 13:43:00 -080012178 } else if (os_strncmp(buf, "TWT_SETUP ", 10) == 0) {
12179 if (wpas_ctrl_iface_send_twt_setup(wpa_s, buf + 9))
12180 reply_len = -1;
12181 } else if (os_strcmp(buf, "TWT_SETUP") == 0) {
12182 if (wpas_ctrl_iface_send_twt_setup(wpa_s, ""))
12183 reply_len = -1;
12184 } else if (os_strncmp(buf, "TWT_TEARDOWN ", 13) == 0) {
12185 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, buf + 12))
12186 reply_len = -1;
12187 } else if (os_strcmp(buf, "TWT_TEARDOWN") == 0) {
12188 if (wpas_ctrl_iface_send_twt_teardown(wpa_s, ""))
12189 reply_len = -1;
Dmitry Shmidt818ea482014-03-10 13:15:21 -070012190#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070012191 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
12192 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
12193 reply_len = -1;
12194 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
12195 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
12196 reply_size);
12197 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
12198 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
12199 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012200 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -070012201 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012202 reply_len = -1;
12203 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
12204 wpas_ctrl_iface_erp_flush(wpa_s);
12205 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
12206 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
12207 reply_len = -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012208 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
12209 reply_len = wpas_ctrl_iface_get_pref_freq_list(
12210 wpa_s, buf + 19, reply, reply_size);
Paul Stewart092955c2017-02-06 09:13:09 -080012211#ifdef CONFIG_FILS
12212 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
12213 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
12214 reply_len = -1;
12215 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
12216 wpas_flush_fils_hlp_req(wpa_s);
12217#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012218#ifdef CONFIG_DPP
12219 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
12220 int res;
12221
12222 res = wpas_dpp_qr_code(wpa_s, buf + 12);
12223 if (res < 0) {
12224 reply_len = -1;
12225 } else {
12226 reply_len = os_snprintf(reply, reply_size, "%d", res);
12227 if (os_snprintf_error(reply_size, reply_len))
12228 reply_len = -1;
12229 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080012230 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
12231 int res;
12232
12233 res = wpas_dpp_nfc_uri(wpa_s, buf + 12);
12234 if (res < 0) {
12235 reply_len = -1;
12236 } else {
12237 reply_len = os_snprintf(reply, reply_size, "%d", res);
12238 if (os_snprintf_error(reply_size, reply_len))
12239 reply_len = -1;
12240 }
Hai Shalomfdcde762020-04-02 11:19:20 -070012241 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
12242 int res;
12243
12244 res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20);
12245 if (res < 0) {
12246 reply_len = -1;
12247 } else {
12248 reply_len = os_snprintf(reply, reply_size, "%d", res);
12249 if (os_snprintf_error(reply_size, reply_len))
12250 reply_len = -1;
12251 }
12252 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
12253 int res;
12254
12255 res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20);
12256 if (res < 0) {
12257 reply_len = -1;
12258 } else {
12259 reply_len = os_snprintf(reply, reply_size, "%d", res);
12260 if (os_snprintf_error(reply_size, reply_len))
12261 reply_len = -1;
12262 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012263 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
12264 int res;
12265
Hai Shalom021b0b52019-04-10 11:17:58 -070012266 res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012267 if (res < 0) {
12268 reply_len = -1;
12269 } else {
12270 reply_len = os_snprintf(reply, reply_size, "%d", res);
12271 if (os_snprintf_error(reply_size, reply_len))
12272 reply_len = -1;
12273 }
12274 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070012275 if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012276 reply_len = -1;
12277 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
12278 const char *uri;
12279
Hai Shalom021b0b52019-04-10 11:17:58 -070012280 uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012281 if (!uri) {
12282 reply_len = -1;
12283 } else {
12284 reply_len = os_snprintf(reply, reply_size, "%s", uri);
12285 if (os_snprintf_error(reply_size, reply_len))
12286 reply_len = -1;
12287 }
12288 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070012289 reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19),
12290 reply, reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -070012291 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
12292 if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18),
12293 os_strchr(buf + 18, ' ')) < 0)
12294 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012295 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
12296 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
12297 reply_len = -1;
12298 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
12299 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
12300 reply_len = -1;
12301 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -070012302 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012303 wpas_dpp_listen_stop(wpa_s);
12304 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
12305 int res;
12306
Hai Shalom021b0b52019-04-10 11:17:58 -070012307 res = dpp_configurator_add(wpa_s->dpp, buf + 20);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012308 if (res < 0) {
12309 reply_len = -1;
12310 } else {
12311 reply_len = os_snprintf(reply, reply_size, "%d", res);
12312 if (os_snprintf_error(reply_size, reply_len))
12313 reply_len = -1;
12314 }
12315 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070012316 if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012317 reply_len = -1;
12318 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -080012319 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012320 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -070012321 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070012322 reply_len = dpp_configurator_get_key_id(wpa_s->dpp,
12323 atoi(buf + 25),
12324 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012325 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
12326 int res;
12327
12328 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
12329 if (res < 0) {
12330 reply_len = -1;
12331 } else {
12332 reply_len = os_snprintf(reply, reply_size, "%d", res);
12333 if (os_snprintf_error(reply_size, reply_len))
12334 reply_len = -1;
12335 }
12336 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
12337 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
12338 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -080012339 } else if (os_strncmp(buf, "DPP_CONF_SET ", 13) == 0) {
12340 if (wpas_dpp_conf_set(wpa_s, buf + 12) < 0)
12341 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070012342#ifdef CONFIG_DPP2
12343 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
12344 if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0)
12345 reply_len = -1;
12346 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
12347 if (wpas_dpp_controller_start(wpa_s, NULL) < 0)
12348 reply_len = -1;
12349 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
12350 dpp_controller_stop(wpa_s->dpp);
Hai Shalomfdcde762020-04-02 11:19:20 -070012351 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
12352 if (wpas_dpp_chirp(wpa_s, buf + 9) < 0)
12353 reply_len = -1;
12354 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
12355 wpas_dpp_chirp_stop(wpa_s);
Hai Shalom4fbc08f2020-05-18 12:37:00 -070012356 } else if (os_strncmp(buf, "DPP_RECONFIG ", 13) == 0) {
Hai Shalom899fcc72020-10-19 14:38:18 -070012357 if (wpas_dpp_reconfig(wpa_s, buf + 13) < 0)
12358 reply_len = -1;
12359 } else if (os_strncmp(buf, "DPP_CA_SET ", 11) == 0) {
12360 if (wpas_dpp_ca_set(wpa_s, buf + 10) < 0)
Hai Shalom4fbc08f2020-05-18 12:37:00 -070012361 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070012362#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012363#endif /* CONFIG_DPP */
Hai Shalom899fcc72020-10-19 14:38:18 -070012364 } else if (os_strncmp(buf, "MSCS ", 5) == 0) {
12365 if (wpas_ctrl_iface_configure_mscs(wpa_s, buf + 5))
12366 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080012367#ifdef CONFIG_PASN
12368 } else if (os_strncmp(buf, "PASN_START ", 11) == 0) {
12369 if (wpas_ctrl_iface_pasn_start(wpa_s, buf + 11) < 0)
12370 reply_len = -1;
12371 } else if (os_strcmp(buf, "PASN_STOP") == 0) {
12372 wpas_pasn_auth_stop(wpa_s);
12373 } else if (os_strcmp(buf, "PTKSA_CACHE_LIST") == 0) {
12374 reply_len = ptksa_cache_list(wpa_s->ptksa, reply, reply_size);
Hai Shaloma20dcd72022-02-04 13:43:00 -080012375 } else if (os_strncmp(buf, "PASN_DEAUTH ", 12) == 0) {
12376 if (wpas_ctrl_iface_pasn_deauthenticate(wpa_s, buf + 12) < 0)
12377 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080012378#endif /* CONFIG_PASN */
Hai Shaloma20dcd72022-02-04 13:43:00 -080012379 } else if (os_strncmp(buf, "SCS ", 4) == 0) {
12380 if (wpas_ctrl_iface_configure_scs(wpa_s, buf + 4))
12381 reply_len = -1;
12382 } else if (os_strncmp(buf, "DSCP_RESP ", 10) == 0) {
12383 if (wpas_ctrl_iface_send_dscp_resp(wpa_s, buf + 10))
12384 reply_len = -1;
12385 } else if (os_strncmp(buf, "DSCP_QUERY ", 11) == 0) {
12386 if (wpas_ctrl_iface_send_dscp_query(wpa_s, buf + 11))
12387 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012388 } else {
12389 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
12390 reply_len = 16;
12391 }
12392
12393 if (reply_len < 0) {
12394 os_memcpy(reply, "FAIL\n", 5);
12395 reply_len = 5;
12396 }
12397
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012398 *resp_len = reply_len;
12399 return reply;
12400}
12401
12402
12403static int wpa_supplicant_global_iface_add(struct wpa_global *global,
12404 char *cmd)
12405{
12406 struct wpa_interface iface;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070012407 char *pos, *extra;
12408 struct wpa_supplicant *wpa_s;
12409 unsigned int create_iface = 0;
12410 u8 mac_addr[ETH_ALEN];
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080012411 enum wpa_driver_if_type type = WPA_IF_STATION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012412
12413 /*
12414 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080012415 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012416 */
12417 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
12418
12419 os_memset(&iface, 0, sizeof(iface));
12420
12421 do {
12422 iface.ifname = pos = cmd;
12423 pos = os_strchr(pos, '\t');
12424 if (pos)
12425 *pos++ = '\0';
12426 if (iface.ifname[0] == '\0')
12427 return -1;
12428 if (pos == NULL)
12429 break;
12430
12431 iface.confname = pos;
12432 pos = os_strchr(pos, '\t');
12433 if (pos)
12434 *pos++ = '\0';
12435 if (iface.confname[0] == '\0')
12436 iface.confname = NULL;
12437 if (pos == NULL)
12438 break;
12439
12440 iface.driver = pos;
12441 pos = os_strchr(pos, '\t');
12442 if (pos)
12443 *pos++ = '\0';
12444 if (iface.driver[0] == '\0')
12445 iface.driver = NULL;
12446 if (pos == NULL)
12447 break;
12448
12449 iface.ctrl_interface = pos;
12450 pos = os_strchr(pos, '\t');
12451 if (pos)
12452 *pos++ = '\0';
12453 if (iface.ctrl_interface[0] == '\0')
12454 iface.ctrl_interface = NULL;
12455 if (pos == NULL)
12456 break;
12457
12458 iface.driver_param = pos;
12459 pos = os_strchr(pos, '\t');
12460 if (pos)
12461 *pos++ = '\0';
12462 if (iface.driver_param[0] == '\0')
12463 iface.driver_param = NULL;
12464 if (pos == NULL)
12465 break;
12466
12467 iface.bridge_ifname = pos;
12468 pos = os_strchr(pos, '\t');
12469 if (pos)
12470 *pos++ = '\0';
12471 if (iface.bridge_ifname[0] == '\0')
12472 iface.bridge_ifname = NULL;
12473 if (pos == NULL)
12474 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070012475
12476 extra = pos;
12477 pos = os_strchr(pos, '\t');
12478 if (pos)
12479 *pos++ = '\0';
Dmitry Shmidt83474442015-04-15 13:47:09 -070012480 if (!extra[0])
12481 break;
12482
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080012483 if (os_strcmp(extra, "create") == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070012484 create_iface = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080012485 if (!pos)
12486 break;
12487
12488 if (os_strcmp(pos, "sta") == 0) {
12489 type = WPA_IF_STATION;
12490 } else if (os_strcmp(pos, "ap") == 0) {
12491 type = WPA_IF_AP_BSS;
12492 } else {
12493 wpa_printf(MSG_DEBUG,
12494 "INTERFACE_ADD unsupported interface type: '%s'",
12495 pos);
12496 return -1;
12497 }
12498 } else {
Dmitry Shmidt83474442015-04-15 13:47:09 -070012499 wpa_printf(MSG_DEBUG,
12500 "INTERFACE_ADD unsupported extra parameter: '%s'",
12501 extra);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070012502 return -1;
Dmitry Shmidt83474442015-04-15 13:47:09 -070012503 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012504 } while (0);
12505
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070012506 if (create_iface) {
12507 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
12508 iface.ifname);
12509 if (!global->ifaces)
12510 return -1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080012511 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070012512 NULL, NULL, NULL, mac_addr, NULL) < 0) {
12513 wpa_printf(MSG_ERROR,
12514 "CTRL_IFACE interface creation failed");
12515 return -1;
12516 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012517
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070012518 wpa_printf(MSG_DEBUG,
12519 "CTRL_IFACE interface '%s' created with MAC addr: "
12520 MACSTR, iface.ifname, MAC2STR(mac_addr));
12521 }
12522
12523 if (wpa_supplicant_get_iface(global, iface.ifname))
12524 goto fail;
12525
12526 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
12527 if (!wpa_s)
12528 goto fail;
12529 wpa_s->added_vif = create_iface;
12530 return 0;
12531
12532fail:
12533 if (create_iface)
12534 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
12535 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012536}
12537
12538
12539static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
12540 char *cmd)
12541{
12542 struct wpa_supplicant *wpa_s;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070012543 int ret;
12544 unsigned int delete_iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012545
12546 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
12547
12548 wpa_s = wpa_supplicant_get_iface(global, cmd);
12549 if (wpa_s == NULL)
12550 return -1;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070012551 delete_iface = wpa_s->added_vif;
12552 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
12553 if (!ret && delete_iface) {
12554 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
12555 cmd);
12556 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
12557 }
12558 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012559}
12560
12561
12562static void wpa_free_iface_info(struct wpa_interface_info *iface)
12563{
12564 struct wpa_interface_info *prev;
12565
12566 while (iface) {
12567 prev = iface;
12568 iface = iface->next;
12569
12570 os_free(prev->ifname);
12571 os_free(prev->desc);
12572 os_free(prev);
12573 }
12574}
12575
12576
12577static int wpa_supplicant_global_iface_list(struct wpa_global *global,
12578 char *buf, int len)
12579{
12580 int i, res;
12581 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
12582 char *pos, *end;
12583
12584 for (i = 0; wpa_drivers[i]; i++) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070012585 const struct wpa_driver_ops *drv = wpa_drivers[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012586 if (drv->get_interfaces == NULL)
12587 continue;
12588 tmp = drv->get_interfaces(global->drv_priv[i]);
12589 if (tmp == NULL)
12590 continue;
12591
12592 if (last == NULL)
12593 iface = last = tmp;
12594 else
12595 last->next = tmp;
12596 while (last->next)
12597 last = last->next;
12598 }
12599
12600 pos = buf;
12601 end = buf + len;
12602 for (tmp = iface; tmp; tmp = tmp->next) {
12603 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
12604 tmp->drv_name, tmp->ifname,
12605 tmp->desc ? tmp->desc : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012606 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012607 *pos = '\0';
12608 break;
12609 }
12610 pos += res;
12611 }
12612
12613 wpa_free_iface_info(iface);
12614
12615 return pos - buf;
12616}
12617
12618
12619static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080012620 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012621 char *buf, int len)
12622{
12623 int res;
12624 char *pos, *end;
12625 struct wpa_supplicant *wpa_s;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080012626 int show_ctrl = 0;
12627
12628 if (input)
12629 show_ctrl = !!os_strstr(input, "ctrl");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012630
12631 wpa_s = global->ifaces;
12632 pos = buf;
12633 end = buf + len;
12634
12635 while (wpa_s) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080012636 if (show_ctrl)
12637 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
12638 wpa_s->ifname,
12639 wpa_s->conf->ctrl_interface ?
12640 wpa_s->conf->ctrl_interface : "N/A");
12641 else
12642 res = os_snprintf(pos, end - pos, "%s\n",
12643 wpa_s->ifname);
12644
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012645 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012646 *pos = '\0';
12647 break;
12648 }
12649 pos += res;
12650 wpa_s = wpa_s->next;
12651 }
12652 return pos - buf;
12653}
12654
12655
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070012656static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
12657 const char *ifname,
12658 char *cmd, size_t *resp_len)
12659{
12660 struct wpa_supplicant *wpa_s;
12661
12662 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
12663 if (os_strcmp(ifname, wpa_s->ifname) == 0)
12664 break;
12665 }
12666
12667 if (wpa_s == NULL) {
12668 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
12669 if (resp)
12670 *resp_len = os_strlen(resp);
12671 else
12672 *resp_len = 1;
12673 return resp;
12674 }
12675
12676 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
12677}
12678
12679
12680static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
12681 char *buf, size_t *resp_len)
12682{
12683#ifdef CONFIG_P2P
12684 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070012685 "LIST_NETWORKS",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070012686 "P2P_FIND",
12687 "P2P_STOP_FIND",
12688 "P2P_LISTEN",
12689 "P2P_GROUP_ADD",
12690 "P2P_GET_PASSPHRASE",
12691 "P2P_SERVICE_UPDATE",
12692 "P2P_SERVICE_FLUSH",
12693 "P2P_FLUSH",
12694 "P2P_CANCEL",
12695 "P2P_PRESENCE_REQ",
12696 "P2P_EXT_LISTEN",
Paul Stewart092955c2017-02-06 09:13:09 -080012697#ifdef CONFIG_AP
12698 "STA-FIRST",
12699#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070012700 NULL
12701 };
12702 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080012703#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070012704 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080012705#endif /* ANDROID */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070012706 "GET_CAPABILITY ",
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070012707 "GET_NETWORK ",
12708 "REMOVE_NETWORK ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070012709 "P2P_FIND ",
12710 "P2P_CONNECT ",
12711 "P2P_LISTEN ",
12712 "P2P_GROUP_REMOVE ",
12713 "P2P_GROUP_ADD ",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070012714 "P2P_GROUP_MEMBER ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070012715 "P2P_PROV_DISC ",
12716 "P2P_SERV_DISC_REQ ",
12717 "P2P_SERV_DISC_CANCEL_REQ ",
12718 "P2P_SERV_DISC_RESP ",
12719 "P2P_SERV_DISC_EXTERNAL ",
12720 "P2P_SERVICE_ADD ",
12721 "P2P_SERVICE_DEL ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012722 "P2P_SERVICE_REP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070012723 "P2P_REJECT ",
12724 "P2P_INVITE ",
12725 "P2P_PEER ",
12726 "P2P_SET ",
12727 "P2P_UNAUTHORIZE ",
12728 "P2P_PRESENCE_REQ ",
12729 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070012730 "P2P_REMOVE_CLIENT ",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080012731 "WPS_NFC_TOKEN ",
12732 "WPS_NFC_TAG_READ ",
Dmitry Shmidt413dde72014-04-11 10:23:22 -070012733 "NFC_GET_HANDOVER_SEL ",
12734 "NFC_GET_HANDOVER_REQ ",
12735 "NFC_REPORT_HANDOVER ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080012736 "P2P_ASP_PROVISION ",
12737 "P2P_ASP_PROVISION_RESP ",
Paul Stewart092955c2017-02-06 09:13:09 -080012738#ifdef CONFIG_AP
12739 "STA ",
12740 "STA-NEXT ",
12741#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070012742 NULL
12743 };
12744 int found = 0;
12745 int i;
12746
12747 if (global->p2p_init_wpa_s == NULL)
12748 return NULL;
12749
12750 for (i = 0; !found && cmd[i]; i++) {
12751 if (os_strcmp(buf, cmd[i]) == 0)
12752 found = 1;
12753 }
12754
12755 for (i = 0; !found && prefix[i]; i++) {
12756 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
12757 found = 1;
12758 }
12759
12760 if (found)
12761 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
12762 buf, resp_len);
12763#endif /* CONFIG_P2P */
12764 return NULL;
12765}
12766
12767
12768static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
12769 char *buf, size_t *resp_len)
12770{
12771#ifdef CONFIG_WIFI_DISPLAY
12772 if (global->p2p_init_wpa_s == NULL)
12773 return NULL;
12774 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
12775 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
12776 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
12777 buf, resp_len);
12778#endif /* CONFIG_WIFI_DISPLAY */
12779 return NULL;
12780}
12781
12782
12783static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
12784 char *buf, size_t *resp_len)
12785{
12786 char *ret;
12787
12788 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
12789 if (ret)
12790 return ret;
12791
12792 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
12793 if (ret)
12794 return ret;
12795
12796 return NULL;
12797}
12798
12799
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012800static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
12801{
12802 char *value;
12803
12804 value = os_strchr(cmd, ' ');
12805 if (value == NULL)
12806 return -1;
12807 *value++ = '\0';
12808
12809 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
12810
12811#ifdef CONFIG_WIFI_DISPLAY
12812 if (os_strcasecmp(cmd, "wifi_display") == 0) {
12813 wifi_display_enable(global, !!atoi(value));
12814 return 0;
12815 }
12816#endif /* CONFIG_WIFI_DISPLAY */
12817
Dmitry Shmidt61593f02014-04-21 16:27:35 -070012818 /* Restore cmd to its original value to allow redirection */
12819 value[-1] = ' ';
12820
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012821 return -1;
12822}
12823
12824
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012825static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
12826 char *cmd)
12827{
12828 struct wpa_supplicant *wpa_s[2]; /* src, dst */
12829 char *p;
12830 unsigned int i;
12831
12832 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
12833 * <variable name> */
12834
12835 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
12836 p = os_strchr(cmd, ' ');
12837 if (p == NULL)
12838 return -1;
12839 *p = '\0';
12840
12841 wpa_s[i] = global->ifaces;
12842 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
12843 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
12844 break;
12845 }
12846
12847 if (!wpa_s[i]) {
12848 wpa_printf(MSG_DEBUG,
12849 "CTRL_IFACE: Could not find iface=%s", cmd);
12850 return -1;
12851 }
12852
12853 cmd = p + 1;
12854 }
12855
12856 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
12857}
12858
12859
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012860#ifndef CONFIG_NO_CONFIG_WRITE
12861static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
12862{
Dmitry Shmidt61593f02014-04-21 16:27:35 -070012863 int ret = 0, saved = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012864 struct wpa_supplicant *wpa_s;
12865
12866 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
12867 if (!wpa_s->conf->update_config) {
12868 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
12869 continue;
12870 }
12871
12872 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
12873 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
12874 ret = 1;
12875 } else {
12876 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
Dmitry Shmidt61593f02014-04-21 16:27:35 -070012877 saved++;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012878 }
12879 }
12880
Dmitry Shmidt61593f02014-04-21 16:27:35 -070012881 if (!saved && !ret) {
12882 wpa_dbg(wpa_s, MSG_DEBUG,
12883 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
12884 ret = 1;
12885 }
12886
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012887 return ret;
12888}
12889#endif /* CONFIG_NO_CONFIG_WRITE */
12890
12891
12892static int wpas_global_ctrl_iface_status(struct wpa_global *global,
12893 char *buf, size_t buflen)
12894{
12895 char *pos, *end;
12896 int ret;
12897 struct wpa_supplicant *wpa_s;
12898
12899 pos = buf;
12900 end = buf + buflen;
12901
12902#ifdef CONFIG_P2P
12903 if (global->p2p && !global->p2p_disabled) {
12904 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
12905 "\n"
12906 "p2p_state=%s\n",
12907 MAC2STR(global->p2p_dev_addr),
12908 p2p_get_state_txt(global->p2p));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012909 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012910 return pos - buf;
12911 pos += ret;
12912 } else if (global->p2p) {
12913 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012914 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012915 return pos - buf;
12916 pos += ret;
12917 }
12918#endif /* CONFIG_P2P */
12919
12920#ifdef CONFIG_WIFI_DISPLAY
12921 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
12922 !!global->wifi_display);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012923 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012924 return pos - buf;
12925 pos += ret;
12926#endif /* CONFIG_WIFI_DISPLAY */
12927
12928 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
12929 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
12930 "address=" MACSTR "\n",
12931 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012932 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012933 return pos - buf;
12934 pos += ret;
12935 }
12936
12937 return pos - buf;
12938}
12939
12940
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012941#ifdef CONFIG_FST
12942
12943static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
12944 char *cmd, char *buf,
12945 size_t reply_size)
12946{
12947 char ifname[IFNAMSIZ + 1];
12948 struct fst_iface_cfg cfg;
12949 struct wpa_supplicant *wpa_s;
12950 struct fst_wpa_obj iface_obj;
12951
12952 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
12953 wpa_s = wpa_supplicant_get_iface(global, ifname);
12954 if (wpa_s) {
12955 if (wpa_s->fst) {
12956 wpa_printf(MSG_INFO, "FST: Already attached");
12957 return -1;
12958 }
12959 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
12960 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
12961 &iface_obj, &cfg);
12962 if (wpa_s->fst)
12963 return os_snprintf(buf, reply_size, "OK\n");
12964 }
12965 }
12966
12967 return -1;
12968}
12969
12970
12971static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
12972 char *cmd, char *buf,
12973 size_t reply_size)
12974{
12975 char ifname[IFNAMSIZ + 1];
12976 struct wpa_supplicant *wpa_s;
12977
12978 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
12979 wpa_s = wpa_supplicant_get_iface(global, ifname);
12980 if (wpa_s) {
12981 if (!fst_iface_detach(ifname)) {
12982 wpa_s->fst = NULL;
12983 return os_snprintf(buf, reply_size, "OK\n");
12984 }
12985 }
12986 }
12987
12988 return -1;
12989}
12990
12991#endif /* CONFIG_FST */
12992
12993
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012994char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
12995 char *buf, size_t *resp_len)
12996{
12997 char *reply;
12998 const int reply_size = 2048;
12999 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080013000 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013001
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070013002 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
13003 char *pos = os_strchr(buf + 7, ' ');
13004 if (pos) {
13005 *pos++ = '\0';
13006 return wpas_global_ctrl_iface_ifname(global,
13007 buf + 7, pos,
13008 resp_len);
13009 }
13010 }
13011
13012 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
13013 if (reply)
13014 return reply;
13015
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080013016 if (os_strcmp(buf, "PING") == 0)
13017 level = MSG_EXCESSIVE;
13018 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013019 (const u8 *) buf, os_strlen(buf));
13020
13021 reply = os_malloc(reply_size);
13022 if (reply == NULL) {
13023 *resp_len = 1;
13024 return NULL;
13025 }
13026
13027 os_memcpy(reply, "OK\n", 3);
13028 reply_len = 3;
13029
13030 if (os_strcmp(buf, "PING") == 0) {
13031 os_memcpy(reply, "PONG\n", 5);
13032 reply_len = 5;
13033 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
13034 if (wpa_supplicant_global_iface_add(global, buf + 14))
13035 reply_len = -1;
13036 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
13037 if (wpa_supplicant_global_iface_remove(global, buf + 17))
13038 reply_len = -1;
13039 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
13040 reply_len = wpa_supplicant_global_iface_list(
13041 global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013042 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013043 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080013044 global, buf + 10, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013045#ifdef CONFIG_FST
13046 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
13047 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
13048 reply,
13049 reply_size);
13050 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
13051 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
13052 reply,
13053 reply_size);
13054 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
13055 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
13056#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013057 } else if (os_strcmp(buf, "TERMINATE") == 0) {
13058 wpa_supplicant_terminate_proc(global);
13059 } else if (os_strcmp(buf, "SUSPEND") == 0) {
13060 wpas_notify_suspend(global);
13061 } else if (os_strcmp(buf, "RESUME") == 0) {
13062 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013063 } else if (os_strncmp(buf, "SET ", 4) == 0) {
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013064 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
13065#ifdef CONFIG_P2P
13066 if (global->p2p_init_wpa_s) {
13067 os_free(reply);
13068 /* Check if P2P redirection would work for this
13069 * command. */
13070 return wpa_supplicant_ctrl_iface_process(
13071 global->p2p_init_wpa_s,
13072 buf, resp_len);
13073 }
13074#endif /* CONFIG_P2P */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013075 reply_len = -1;
Dmitry Shmidt61593f02014-04-21 16:27:35 -070013076 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080013077 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
13078 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
13079 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070013080#ifndef CONFIG_NO_CONFIG_WRITE
13081 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
13082 if (wpas_global_ctrl_iface_save_config(global))
13083 reply_len = -1;
13084#endif /* CONFIG_NO_CONFIG_WRITE */
13085 } else if (os_strcmp(buf, "STATUS") == 0) {
13086 reply_len = wpas_global_ctrl_iface_status(global, reply,
13087 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080013088#ifdef CONFIG_MODULE_TESTS
13089 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080013090 if (wpas_module_tests() < 0)
13091 reply_len = -1;
13092#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013093 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
13094 if (wpa_debug_reopen_file() < 0)
13095 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013096 } else {
13097 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
13098 reply_len = 16;
13099 }
13100
13101 if (reply_len < 0) {
13102 os_memcpy(reply, "FAIL\n", 5);
13103 reply_len = 5;
13104 }
13105
13106 *resp_len = reply_len;
13107 return reply;
13108}