blob: 0d4c2bc8f0bb3291fe4449657badbcbbdb1f361e [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"
42#include "ap.h"
43#include "p2p_supplicant.h"
44#include "p2p/p2p.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070045#include "hs20_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070046#include "wifi_display.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070047#include "notify.h"
48#include "bss.h"
49#include "scan.h"
50#include "ctrl_iface.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080051#include "interworking.h"
Hai Shalom60840252021-02-19 19:02:11 -080052#include "bssid_ignore.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070053#include "autoscan.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080054#include "wnm_sta.h"
Dmitry Shmidt818ea482014-03-10 13:15:21 -070055#include "offchannel.h"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070056#include "drivers/driver.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080057#include "mesh.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070058#include "dpp_supplicant.h"
Hai Shalom74f70d42019-02-11 14:42:39 -080059#include "sme.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070060
Hai Shalomc3565922019-10-28 11:58:20 -070061#ifdef __NetBSD__
62#include <net/if_ether.h>
63#elif !defined(__CYGWIN__) && !defined(CONFIG_NATIVE_WINDOWS)
64#include <net/ethernet.h>
65#endif
66
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070067static int wpa_supplicant_global_iface_list(struct wpa_global *global,
68 char *buf, int len);
69static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080070 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070071 char *buf, int len);
Dmitry Shmidtd11f0192014-03-24 12:09:47 -070072static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
73 char *val);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070074
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070075
Dmitry Shmidt04949592012-07-19 12:16:46 -070076static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
77{
78 char *pos;
79 u8 addr[ETH_ALEN], *filter = NULL, *n;
80 size_t count = 0;
81
82 pos = val;
83 while (pos) {
84 if (*pos == '\0')
85 break;
86 if (hwaddr_aton(pos, addr)) {
87 os_free(filter);
88 return -1;
89 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070090 n = os_realloc_array(filter, count + 1, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -070091 if (n == NULL) {
92 os_free(filter);
93 return -1;
94 }
95 filter = n;
96 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
97 count++;
98
99 pos = os_strchr(pos, ' ');
100 if (pos)
101 pos++;
102 }
103
104 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
105 os_free(wpa_s->bssid_filter);
106 wpa_s->bssid_filter = filter;
107 wpa_s->bssid_filter_count = count;
108
109 return 0;
110}
111
112
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800113static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
114{
115 char *pos;
116 u8 addr[ETH_ALEN], *bssid = NULL, *n;
117 struct wpa_ssid_value *ssid = NULL, *ns;
118 size_t count = 0, ssid_count = 0;
119 struct wpa_ssid *c;
120
121 /*
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800122 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800123 * SSID_SPEC ::= ssid <SSID_HEX>
124 * BSSID_SPEC ::= bssid <BSSID_HEX>
125 */
126
127 pos = val;
128 while (pos) {
129 if (*pos == '\0')
130 break;
131 if (os_strncmp(pos, "bssid ", 6) == 0) {
132 int res;
133 pos += 6;
134 res = hwaddr_aton2(pos, addr);
135 if (res < 0) {
136 os_free(ssid);
137 os_free(bssid);
138 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
139 "BSSID value '%s'", pos);
140 return -1;
141 }
142 pos += res;
143 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
144 if (n == NULL) {
145 os_free(ssid);
146 os_free(bssid);
147 return -1;
148 }
149 bssid = n;
150 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
151 count++;
152 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
153 char *end;
154 pos += 5;
155
156 end = pos;
157 while (*end) {
158 if (*end == '\0' || *end == ' ')
159 break;
160 end++;
161 }
162
163 ns = os_realloc_array(ssid, ssid_count + 1,
164 sizeof(struct wpa_ssid_value));
165 if (ns == NULL) {
166 os_free(ssid);
167 os_free(bssid);
168 return -1;
169 }
170 ssid = ns;
171
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700172 if ((end - pos) & 0x01 ||
173 end - pos > 2 * SSID_MAX_LEN ||
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800174 hexstr2bin(pos, ssid[ssid_count].ssid,
175 (end - pos) / 2) < 0) {
176 os_free(ssid);
177 os_free(bssid);
178 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
179 "SSID value '%s'", pos);
180 return -1;
181 }
182 ssid[ssid_count].ssid_len = (end - pos) / 2;
183 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
184 ssid[ssid_count].ssid,
185 ssid[ssid_count].ssid_len);
186 ssid_count++;
187 pos = end;
188 } else {
189 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
190 "'%s'", pos);
191 os_free(ssid);
192 os_free(bssid);
193 return -1;
194 }
195
196 pos = os_strchr(pos, ' ');
197 if (pos)
198 pos++;
199 }
200
201 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
202 os_free(wpa_s->disallow_aps_bssid);
203 wpa_s->disallow_aps_bssid = bssid;
204 wpa_s->disallow_aps_bssid_count = count;
205
206 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
207 os_free(wpa_s->disallow_aps_ssid);
208 wpa_s->disallow_aps_ssid = ssid;
209 wpa_s->disallow_aps_ssid_count = ssid_count;
210
211 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
212 return 0;
213
214 c = wpa_s->current_ssid;
215 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
216 return 0;
217
218 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
219 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
220 return 0;
221
222 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
223 "because current AP was marked disallowed");
224
225#ifdef CONFIG_SME
226 wpa_s->sme.prev_bssid_set = 0;
227#endif /* CONFIG_SME */
228 wpa_s->reassociate = 1;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800229 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800230 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
231 wpa_supplicant_req_scan(wpa_s, 0, 0);
232
233 return 0;
234}
235
236
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700237#ifndef CONFIG_NO_CONFIG_BLOBS
238static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
239{
240 char *name = pos;
241 struct wpa_config_blob *blob;
242 size_t len;
243
244 pos = os_strchr(pos, ' ');
245 if (pos == NULL)
246 return -1;
247 *pos++ = '\0';
248 len = os_strlen(pos);
249 if (len & 1)
250 return -1;
251
252 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
253 blob = os_zalloc(sizeof(*blob));
254 if (blob == NULL)
255 return -1;
256 blob->name = os_strdup(name);
257 blob->data = os_malloc(len / 2);
258 if (blob->name == NULL || blob->data == NULL) {
259 wpa_config_free_blob(blob);
260 return -1;
261 }
262
263 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
264 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
265 wpa_config_free_blob(blob);
266 return -1;
267 }
268 blob->len = len / 2;
269
270 wpa_config_set_blob(wpa_s->conf, blob);
271
272 return 0;
273}
274#endif /* CONFIG_NO_CONFIG_BLOBS */
275
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700276
277static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
278{
279 char *params;
280 char *pos;
281 int *freqs = NULL;
282 int ret;
283
284 if (atoi(cmd)) {
285 params = os_strchr(cmd, ' ');
286 os_free(wpa_s->manual_sched_scan_freqs);
287 if (params) {
288 params++;
289 pos = os_strstr(params, "freq=");
290 if (pos)
291 freqs = freq_range_to_channel_list(wpa_s,
292 pos + 5);
293 }
294 wpa_s->manual_sched_scan_freqs = freqs;
295 ret = wpas_start_pno(wpa_s);
296 } else {
297 ret = wpas_stop_pno(wpa_s);
298 }
299 return ret;
300}
301
302
Hai Shalom60840252021-02-19 19:02:11 -0800303static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *bands)
Ravi Joshie6ccb162015-07-16 17:45:41 -0700304{
305 union wpa_event_data event;
Hai Shalom60840252021-02-19 19:02:11 -0800306 u32 setband_mask = WPA_SETBAND_AUTO;
Ravi Joshie6ccb162015-07-16 17:45:41 -0700307
Hai Shalom60840252021-02-19 19:02:11 -0800308 /*
309 * For example:
310 * SET setband 2G,6G
311 * SET setband 5G
312 * SET setband AUTO
313 */
314 if (!os_strstr(bands, "AUTO")) {
315 if (os_strstr(bands, "5G"))
316 setband_mask |= WPA_SETBAND_5G;
317 if (os_strstr(bands, "6G"))
318 setband_mask |= WPA_SETBAND_6G;
319 if (os_strstr(bands, "2G"))
320 setband_mask |= WPA_SETBAND_2G;
321 if (setband_mask == WPA_SETBAND_AUTO)
322 return -1;
323 }
Ravi Joshie6ccb162015-07-16 17:45:41 -0700324
Hai Shalom60840252021-02-19 19:02:11 -0800325 wpa_s->setband_mask = setband_mask;
326 if (wpa_drv_setband(wpa_s, wpa_s->setband_mask) == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700327 os_memset(&event, 0, sizeof(event));
328 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
329 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
330 wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
331 }
332
333 return 0;
334}
335
336
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700337static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s,
338 const char *cmd)
339{
340 struct wpabuf *lci;
341
342 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
343 wpabuf_free(wpa_s->lci);
344 wpa_s->lci = NULL;
345 return 0;
346 }
347
348 lci = wpabuf_parse_bin(cmd);
349 if (!lci)
350 return -1;
351
352 if (os_get_reltime(&wpa_s->lci_time)) {
353 wpabuf_free(lci);
354 return -1;
355 }
356
357 wpabuf_free(wpa_s->lci);
358 wpa_s->lci = lci;
359
360 return 0;
361}
362
363
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800364static int
365wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd)
366{
367 int relative_rssi;
368
369 if (os_strcmp(cmd, "disable") == 0) {
370 wpa_s->srp.relative_rssi_set = 0;
371 return 0;
372 }
373
374 relative_rssi = atoi(cmd);
375 if (relative_rssi < 0 || relative_rssi > 100)
376 return -1;
377 wpa_s->srp.relative_rssi = relative_rssi;
378 wpa_s->srp.relative_rssi_set = 1;
379 return 0;
380}
381
382
383static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s,
384 const char *cmd)
385{
386 char *pos;
387 int adjust_rssi;
388
389 /* <band>:adjust_value */
390 pos = os_strchr(cmd, ':');
391 if (!pos)
392 return -1;
393 pos++;
394 adjust_rssi = atoi(pos);
395 if (adjust_rssi < -100 || adjust_rssi > 100)
396 return -1;
397
398 if (os_strncmp(cmd, "2G", 2) == 0)
399 wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G;
400 else if (os_strncmp(cmd, "5G", 2) == 0)
401 wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G;
402 else
403 return -1;
404
405 wpa_s->srp.relative_adjust_rssi = adjust_rssi;
406
407 return 0;
408}
409
410
411static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s,
412 const char *cmd)
413{
414 struct wpabuf *ric_ies;
415
416 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
417 wpabuf_free(wpa_s->ric_ies);
418 wpa_s->ric_ies = NULL;
419 return 0;
420 }
421
422 ric_ies = wpabuf_parse_bin(cmd);
423 if (!ric_ies)
424 return -1;
425
426 wpabuf_free(wpa_s->ric_ies);
427 wpa_s->ric_ies = ric_ies;
428
429 return 0;
430}
431
432
Hai Shalomfdcde762020-04-02 11:19:20 -0700433#ifdef CONFIG_TESTING_OPTIONS
434static int wpas_ctrl_iface_set_dso(struct wpa_supplicant *wpa_s,
435 const char *val)
436{
437 u8 bssid[ETH_ALEN];
438 const char *pos = val;
439 struct driver_signal_override *dso = NULL, *tmp, parsed;
440
441 if (hwaddr_aton(pos, bssid))
442 return -1;
443 pos = os_strchr(pos, ' ');
444
445 dl_list_for_each(tmp, &wpa_s->drv_signal_override,
446 struct driver_signal_override, list) {
447 if (os_memcmp(bssid, tmp->bssid, ETH_ALEN) == 0) {
448 dso = tmp;
449 break;
450 }
451 }
452
453 if (!pos) {
454 /* Remove existing entry */
455 if (dso) {
456 dl_list_del(&dso->list);
457 os_free(dso);
458 }
459 return 0;
460 }
461 pos++;
462
463 /* Update an existing entry or add a new one */
464 os_memset(&parsed, 0, sizeof(parsed));
465 if (sscanf(pos, "%d %d %d %d %d",
466 &parsed.si_current_signal,
467 &parsed.si_avg_signal,
468 &parsed.si_avg_beacon_signal,
469 &parsed.si_current_noise,
470 &parsed.scan_level) != 5)
471 return -1;
472
473 if (!dso) {
474 dso = os_zalloc(sizeof(*dso));
475 if (!dso)
476 return -1;
477 os_memcpy(dso->bssid, bssid, ETH_ALEN);
478 dl_list_add(&wpa_s->drv_signal_override, &dso->list);
479 }
480 dso->si_current_signal = parsed.si_current_signal;
481 dso->si_avg_signal = parsed.si_avg_signal;
482 dso->si_avg_beacon_signal = parsed.si_avg_beacon_signal;
483 dso->si_current_noise = parsed.si_current_noise;
484 dso->scan_level = parsed.scan_level;
485
486 return 0;
487}
488#endif /* CONFIG_TESTING_OPTIONS */
489
490
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700491static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
492 char *cmd)
493{
494 char *value;
495 int ret = 0;
496
497 value = os_strchr(cmd, ' ');
498 if (value == NULL)
499 return -1;
500 *value++ = '\0';
501
502 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
503 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
504 eapol_sm_configure(wpa_s->eapol,
505 atoi(value), -1, -1, -1);
506 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
507 eapol_sm_configure(wpa_s->eapol,
508 -1, atoi(value), -1, -1);
509 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
510 eapol_sm_configure(wpa_s->eapol,
511 -1, -1, atoi(value), -1);
512 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
513 eapol_sm_configure(wpa_s->eapol,
514 -1, -1, -1, atoi(value));
515 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
516 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
Paul Stewart092955c2017-02-06 09:13:09 -0800517 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800519 } else {
520 value[-1] = '=';
521 wpa_config_process_global(wpa_s->conf, cmd, -1);
522 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700523 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
524 0) {
525 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
Paul Stewart092955c2017-02-06 09:13:09 -0800526 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700527 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800528 } else {
529 value[-1] = '=';
530 wpa_config_process_global(wpa_s->conf, cmd, -1);
531 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700532 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
Paul Stewart092955c2017-02-06 09:13:09 -0800533 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
534 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700535 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800536 } else {
537 value[-1] = '=';
538 wpa_config_process_global(wpa_s->conf, cmd, -1);
539 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700540 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
541 wpa_s->wps_fragment_size = atoi(value);
542#ifdef CONFIG_WPS_TESTING
543 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
544 long int val;
545 val = strtol(value, NULL, 0);
546 if (val < 0 || val > 0xff) {
547 ret = -1;
548 wpa_printf(MSG_DEBUG, "WPS: Invalid "
549 "wps_version_number %ld", val);
550 } else {
551 wps_version_number = val;
552 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
553 "version %u.%u",
554 (wps_version_number & 0xf0) >> 4,
555 wps_version_number & 0x0f);
556 }
557 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
558 wps_testing_dummy_cred = atoi(value);
559 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
560 wps_testing_dummy_cred);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800561 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
562 wps_corrupt_pkhash = atoi(value);
563 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
564 wps_corrupt_pkhash);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800565 } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
566 if (value[0] == '\0') {
567 wps_force_auth_types_in_use = 0;
568 } else {
569 wps_force_auth_types = strtol(value, NULL, 0);
570 wps_force_auth_types_in_use = 1;
571 }
572 } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
573 if (value[0] == '\0') {
574 wps_force_encr_types_in_use = 0;
575 } else {
576 wps_force_encr_types = strtol(value, NULL, 0);
577 wps_force_encr_types_in_use = 1;
578 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700579#endif /* CONFIG_WPS_TESTING */
580 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
581 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
582 ret = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800583#ifdef CONFIG_TDLS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584#ifdef CONFIG_TDLS_TESTING
585 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700586 tdls_testing = strtol(value, NULL, 0);
587 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
588#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
590 int disabled = atoi(value);
591 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
592 if (disabled) {
593 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
594 ret = -1;
595 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
596 ret = -1;
597 wpa_tdls_enable(wpa_s->wpa, !disabled);
598#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800599 } else if (os_strcasecmp(cmd, "pno") == 0) {
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700600 ret = wpas_ctrl_pno(wpa_s, value);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700601 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
602 int disabled = atoi(value);
603 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
604 ret = -1;
605 else if (disabled)
606 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
607 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
608 if (os_strcmp(value, "disable") == 0)
609 wpa_s->set_sta_uapsd = 0;
610 else {
611 int be, bk, vi, vo;
612 char *pos;
613 /* format: BE,BK,VI,VO;max SP Length */
614 be = atoi(value);
615 pos = os_strchr(value, ',');
616 if (pos == NULL)
617 return -1;
618 pos++;
619 bk = atoi(pos);
620 pos = os_strchr(pos, ',');
621 if (pos == NULL)
622 return -1;
623 pos++;
624 vi = atoi(pos);
625 pos = os_strchr(pos, ',');
626 if (pos == NULL)
627 return -1;
628 pos++;
629 vo = atoi(pos);
630 /* ignore max SP Length for now */
631
632 wpa_s->set_sta_uapsd = 1;
633 wpa_s->sta_uapsd = 0;
634 if (be)
635 wpa_s->sta_uapsd |= BIT(0);
636 if (bk)
637 wpa_s->sta_uapsd |= BIT(1);
638 if (vi)
639 wpa_s->sta_uapsd |= BIT(2);
640 if (vo)
641 wpa_s->sta_uapsd |= BIT(3);
642 }
Jouni Malinen21d6bc82012-04-10 16:17:59 -0700643 } else if (os_strcasecmp(cmd, "ps") == 0) {
644 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700645#ifdef CONFIG_WIFI_DISPLAY
646 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800647 int enabled = !!atoi(value);
648 if (enabled && !wpa_s->global->p2p)
649 ret = -1;
650 else
651 wifi_display_enable(wpa_s->global, enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700652#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700653 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
654 ret = set_bssid_filter(wpa_s, value);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800655 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
656 ret = set_disallow_aps(wpa_s, value);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800657 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
658 wpa_s->no_keep_alive = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700659#ifdef CONFIG_DPP
660 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
661 os_free(wpa_s->dpp_configurator_params);
662 wpa_s->dpp_configurator_params = os_strdup(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700663 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
664 wpa_s->dpp_init_max_tries = atoi(value);
665 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
666 wpa_s->dpp_init_retry_time = atoi(value);
667 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
668 wpa_s->dpp_resp_wait_time = atoi(value);
669 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
670 wpa_s->dpp_resp_max_tries = atoi(value);
671 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
672 wpa_s->dpp_resp_retry_time = atoi(value);
673#ifdef CONFIG_TESTING_OPTIONS
674 } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
675 if (hwaddr_aton(value, dpp_pkex_own_mac_override))
676 ret = -1;
677 } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
678 if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
679 ret = -1;
680 } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
681 size_t hex_len = os_strlen(value);
682
683 if (hex_len >
684 2 * sizeof(dpp_pkex_ephemeral_key_override))
685 ret = -1;
686 else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
687 hex_len / 2))
688 ret = -1;
689 else
690 dpp_pkex_ephemeral_key_override_len = hex_len / 2;
691 } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) {
692 size_t hex_len = os_strlen(value);
693
694 if (hex_len > 2 * sizeof(dpp_protocol_key_override))
695 ret = -1;
696 else if (hexstr2bin(value, dpp_protocol_key_override,
697 hex_len / 2))
698 ret = -1;
699 else
700 dpp_protocol_key_override_len = hex_len / 2;
701 } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) {
702 size_t hex_len = os_strlen(value);
703
704 if (hex_len > 2 * sizeof(dpp_nonce_override))
705 ret = -1;
706 else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2))
707 ret = -1;
708 else
709 dpp_nonce_override_len = hex_len / 2;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700710 } else if (os_strcasecmp(cmd, "dpp_version_override") == 0) {
711 dpp_version_override = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700712#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700713#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700714#ifdef CONFIG_TESTING_OPTIONS
715 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
716 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800717 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
718 wpa_s->ext_eapol_frame_io = !!atoi(value);
719#ifdef CONFIG_AP
720 if (wpa_s->ap_iface) {
721 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
722 wpa_s->ext_eapol_frame_io;
723 }
724#endif /* CONFIG_AP */
725 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
726 wpa_s->extra_roc_dur = atoi(value);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800727 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
728 wpa_s->test_failure = atoi(value);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800729 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
730 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700731 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
732 wpa_s->ignore_auth_resp = !!atoi(value);
733 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
734 wpa_s->ignore_assoc_disallow = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700735 wpa_drv_ignore_assoc_disallow(wpa_s,
736 wpa_s->ignore_assoc_disallow);
Hai Shalomfdcde762020-04-02 11:19:20 -0700737 } else if (os_strcasecmp(cmd, "disable_sa_query") == 0) {
738 wpa_s->disable_sa_query = !!atoi(value);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800739 } else if (os_strcasecmp(cmd, "ignore_sae_h2e_only") == 0) {
740 wpa_s->ignore_sae_h2e_only = !!atoi(value);
741 } else if (os_strcasecmp(cmd, "extra_sae_rejected_groups") == 0) {
742 char *pos;
743
744 os_free(wpa_s->extra_sae_rejected_groups);
745 wpa_s->extra_sae_rejected_groups = NULL;
746 pos = value;
747 while (pos && pos[0]) {
748 int group;
749
750 group = atoi(pos);
751 wpa_printf(MSG_DEBUG,
752 "TESTING: Extra rejection of SAE group %d",
753 group);
754 if (group)
755 int_array_add_unique(
756 &wpa_s->extra_sae_rejected_groups,
757 group);
758 pos = os_strchr(pos, ' ');
759 if (!pos)
760 break;
761 pos++;
762 }
Hai Shalomb755a2a2020-04-23 21:49:02 -0700763 } else if (os_strcasecmp(cmd, "ft_rsnxe_used") == 0) {
764 wpa_s->ft_rsnxe_used = atoi(value);
Hai Shalom899fcc72020-10-19 14:38:18 -0700765 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol") == 0) {
766 wpa_s->oci_freq_override_eapol = atoi(value);
767 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_req") == 0) {
768 wpa_s->oci_freq_override_saquery_req = atoi(value);
769 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_resp") == 0) {
770 wpa_s->oci_freq_override_saquery_resp = atoi(value);
771 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol_g2") == 0) {
772 wpa_s->oci_freq_override_eapol_g2 = atoi(value);
773 /* Populate value to wpa_sm if already associated. */
774 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_EAPOL_G2,
775 wpa_s->oci_freq_override_eapol_g2);
776 } else if (os_strcasecmp(cmd, "oci_freq_override_ft_assoc") == 0) {
777 wpa_s->oci_freq_override_ft_assoc = atoi(value);
778 /* Populate value to wpa_sm if already associated. */
779 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_FT_ASSOC,
780 wpa_s->oci_freq_override_ft_assoc);
781 } else if (os_strcasecmp(cmd, "oci_freq_override_fils_assoc") == 0) {
782 wpa_s->oci_freq_override_fils_assoc = atoi(value);
783 } else if (os_strcasecmp(cmd, "oci_freq_override_wnm_sleep") == 0) {
784 wpa_s->oci_freq_override_wnm_sleep = atoi(value);
Hai Shalomfdcde762020-04-02 11:19:20 -0700785 } else if (os_strcasecmp(cmd, "rsne_override_eapol") == 0) {
786 wpabuf_free(wpa_s->rsne_override_eapol);
787 if (os_strcmp(value, "NULL") == 0)
788 wpa_s->rsne_override_eapol = NULL;
789 else
790 wpa_s->rsne_override_eapol = wpabuf_parse_bin(value);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800791 } else if (os_strcasecmp(cmd, "rsnxe_override_assoc") == 0) {
792 wpabuf_free(wpa_s->rsnxe_override_assoc);
793 if (os_strcmp(value, "NULL") == 0)
794 wpa_s->rsnxe_override_assoc = NULL;
795 else
796 wpa_s->rsnxe_override_assoc = wpabuf_parse_bin(value);
797 } else if (os_strcasecmp(cmd, "rsnxe_override_eapol") == 0) {
798 wpabuf_free(wpa_s->rsnxe_override_eapol);
799 if (os_strcmp(value, "NULL") == 0)
800 wpa_s->rsnxe_override_eapol = NULL;
801 else
802 wpa_s->rsnxe_override_eapol = wpabuf_parse_bin(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700803 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
804 wpa_s->reject_btm_req_reason = atoi(value);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800805 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
806 os_free(wpa_s->get_pref_freq_list_override);
807 if (!value[0])
808 wpa_s->get_pref_freq_list_override = NULL;
809 else
810 wpa_s->get_pref_freq_list_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700811 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
812 wpabuf_free(wpa_s->sae_commit_override);
813 if (value[0] == '\0')
814 wpa_s->sae_commit_override = NULL;
815 else
816 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
Hai Shalomfdcde762020-04-02 11:19:20 -0700817 } else if (os_strcasecmp(cmd, "driver_signal_override") == 0) {
818 ret = wpas_ctrl_iface_set_dso(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700819#ifdef CONFIG_DPP
820 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
821 os_free(wpa_s->dpp_config_obj_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700822 if (value[0] == '\0')
823 wpa_s->dpp_config_obj_override = NULL;
824 else
825 wpa_s->dpp_config_obj_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700826 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
827 os_free(wpa_s->dpp_discovery_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700828 if (value[0] == '\0')
829 wpa_s->dpp_discovery_override = NULL;
830 else
831 wpa_s->dpp_discovery_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700832 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
833 os_free(wpa_s->dpp_groups_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700834 if (value[0] == '\0')
835 wpa_s->dpp_groups_override = NULL;
836 else
837 wpa_s->dpp_groups_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700838 } else if (os_strcasecmp(cmd,
839 "dpp_ignore_netaccesskey_mismatch") == 0) {
840 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700841 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
842 dpp_test = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700843#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700844#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700845#ifdef CONFIG_FILS
846 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
847 wpa_s->disable_fils = !!atoi(value);
848 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
849 wpa_supplicant_set_default_scan_ies(wpa_s);
850#endif /* CONFIG_FILS */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700851#ifndef CONFIG_NO_CONFIG_BLOBS
852 } else if (os_strcmp(cmd, "blob") == 0) {
853 ret = wpas_ctrl_set_blob(wpa_s, value);
854#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800855 } else if (os_strcasecmp(cmd, "setband") == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700856 ret = wpas_ctrl_set_band(wpa_s, value);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800857#ifdef CONFIG_MBO
858 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
859 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
Paul Stewart092955c2017-02-06 09:13:09 -0800860 if (ret == 0) {
861 value[-1] = '=';
862 wpa_config_process_global(wpa_s->conf, cmd, -1);
863 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800864 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
865 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700866 } else if (os_strcasecmp(cmd, "oce") == 0) {
867 wpa_s->conf->oce = atoi(value);
868 if (wpa_s->conf->oce) {
869 if ((wpa_s->conf->oce & OCE_STA) &&
870 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
871 wpa_s->enable_oce = OCE_STA;
872
873 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
874 (wpa_s->drv_flags &
875 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
876 /* TODO: Need to add STA-CFON support */
877 wpa_printf(MSG_ERROR,
878 "OCE STA-CFON feature is not yet supported");
879 return -1;
880 }
881 } else {
882 wpa_s->enable_oce = 0;
883 }
884 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800885#endif /* CONFIG_MBO */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700886 } else if (os_strcasecmp(cmd, "lci") == 0) {
887 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800888 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
889 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800890 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
891 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
892 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
893 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
894 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
895 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700896 } else if (os_strcasecmp(cmd, "roaming") == 0) {
897 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800898#ifdef CONFIG_WNM
899 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
900 struct wpabuf *elems;
901
902 elems = wpabuf_parse_bin(value);
903 if (!elems)
904 return -1;
905 wnm_set_coloc_intf_elems(wpa_s, elems);
906#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700907 } else {
908 value[-1] = '=';
909 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
910 if (ret == 0)
911 wpa_supplicant_update_config(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -0700912 else if (ret == 1)
913 ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700914 }
915
916 return ret;
917}
918
919
920static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
921 char *cmd, char *buf, size_t buflen)
922{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700923 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700924
925 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
926
927 if (os_strcmp(cmd, "version") == 0) {
928 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700929 } else if (os_strcasecmp(cmd, "max_command_len") == 0) {
930 res = os_snprintf(buf, buflen, "%u", CTRL_IFACE_MAX_LEN);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700931 } else if (os_strcasecmp(cmd, "country") == 0) {
932 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
933 res = os_snprintf(buf, buflen, "%c%c",
934 wpa_s->conf->country[0],
935 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700936#ifdef CONFIG_WIFI_DISPLAY
937 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800938 int enabled;
939 if (wpa_s->global->p2p == NULL ||
940 wpa_s->global->p2p_disabled)
941 enabled = 0;
942 else
943 enabled = wpa_s->global->wifi_display;
944 res = os_snprintf(buf, buflen, "%d", enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700945#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700946#ifdef CONFIG_TESTING_GET_GTK
947 } else if (os_strcmp(cmd, "gtk") == 0) {
948 if (wpa_s->last_gtk_len == 0)
949 return -1;
950 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
951 wpa_s->last_gtk_len);
952 return res;
953#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800954 } else if (os_strcmp(cmd, "tls_library") == 0) {
955 res = tls_get_library_version(buf, buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700956#ifdef CONFIG_TESTING_OPTIONS
957 } else if (os_strcmp(cmd, "anonce") == 0) {
958 return wpa_snprintf_hex(buf, buflen,
959 wpa_sm_get_anonce(wpa_s->wpa),
960 WPA_NONCE_LEN);
Hai Shalomfdcde762020-04-02 11:19:20 -0700961 } else if (os_strcasecmp(cmd, "last_tk_key_idx") == 0) {
962 res = os_snprintf(buf, buflen, "%d", wpa_s->last_tk_key_idx);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700963#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800964 } else {
965 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700966 }
967
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800968 if (os_snprintf_error(buflen, res))
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700969 return -1;
970 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700971}
972
973
974#ifdef IEEE8021X_EAPOL
975static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
976 char *addr)
977{
978 u8 bssid[ETH_ALEN];
979 struct wpa_ssid *ssid = wpa_s->current_ssid;
980
981 if (hwaddr_aton(addr, bssid)) {
982 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
983 "'%s'", addr);
984 return -1;
985 }
986
987 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
988 rsn_preauth_deinit(wpa_s->wpa);
989 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
990 return -1;
991
992 return 0;
993}
994#endif /* IEEE8021X_EAPOL */
995
996
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700997#ifdef CONFIG_TDLS
998
999static int wpa_supplicant_ctrl_iface_tdls_discover(
1000 struct wpa_supplicant *wpa_s, char *addr)
1001{
1002 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001003 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001004
1005 if (hwaddr_aton(addr, peer)) {
1006 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
1007 "address '%s'", addr);
1008 return -1;
1009 }
1010
1011 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
1012 MAC2STR(peer));
1013
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001014 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1015 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
1016 else
1017 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
1018
1019 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020}
1021
1022
1023static int wpa_supplicant_ctrl_iface_tdls_setup(
1024 struct wpa_supplicant *wpa_s, char *addr)
1025{
1026 u8 peer[ETH_ALEN];
1027 int ret;
1028
1029 if (hwaddr_aton(addr, peer)) {
1030 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
1031 "address '%s'", addr);
1032 return -1;
1033 }
1034
1035 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
1036 MAC2STR(peer));
1037
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001038 if ((wpa_s->conf->tdls_external_control) &&
1039 wpa_tdls_is_external_setup(wpa_s->wpa))
1040 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
1041
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001042 wpa_tdls_remove(wpa_s->wpa, peer);
1043
1044 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1045 ret = wpa_tdls_start(wpa_s->wpa, peer);
1046 else
1047 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001048
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001049 return ret;
1050}
1051
1052
1053static int wpa_supplicant_ctrl_iface_tdls_teardown(
1054 struct wpa_supplicant *wpa_s, char *addr)
1055{
1056 u8 peer[ETH_ALEN];
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001057 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001058
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001059 if (os_strcmp(addr, "*") == 0) {
1060 /* remove everyone */
1061 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
1062 wpa_tdls_teardown_peers(wpa_s->wpa);
1063 return 0;
1064 }
1065
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001066 if (hwaddr_aton(addr, peer)) {
1067 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
1068 "address '%s'", addr);
1069 return -1;
1070 }
1071
1072 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
1073 MAC2STR(peer));
1074
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001075 if ((wpa_s->conf->tdls_external_control) &&
1076 wpa_tdls_is_external_setup(wpa_s->wpa))
1077 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1078
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001079 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1080 ret = wpa_tdls_teardown_link(
1081 wpa_s->wpa, peer,
1082 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
1083 else
1084 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1085
1086 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087}
1088
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001089
1090static int ctrl_iface_get_capability_tdls(
1091 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1092{
1093 int ret;
1094
1095 ret = os_snprintf(buf, buflen, "%s\n",
1096 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
1097 (wpa_s->drv_flags &
1098 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
1099 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001100 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001101 return -1;
1102 return ret;
1103}
1104
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001105
1106static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
1107 struct wpa_supplicant *wpa_s, char *cmd)
1108{
1109 u8 peer[ETH_ALEN];
1110 struct hostapd_freq_params freq_params;
1111 u8 oper_class;
1112 char *pos, *end;
1113
1114 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1115 wpa_printf(MSG_INFO,
1116 "tdls_chanswitch: Only supported with external setup");
1117 return -1;
1118 }
1119
1120 os_memset(&freq_params, 0, sizeof(freq_params));
1121
1122 pos = os_strchr(cmd, ' ');
1123 if (pos == NULL)
1124 return -1;
1125 *pos++ = '\0';
1126
1127 oper_class = strtol(pos, &end, 10);
1128 if (pos == end) {
1129 wpa_printf(MSG_INFO,
1130 "tdls_chanswitch: Invalid op class provided");
1131 return -1;
1132 }
1133
1134 pos = end;
1135 freq_params.freq = atoi(pos);
1136 if (freq_params.freq == 0) {
1137 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
1138 return -1;
1139 }
1140
1141#define SET_FREQ_SETTING(str) \
1142 do { \
1143 const char *pos2 = os_strstr(pos, " " #str "="); \
1144 if (pos2) { \
1145 pos2 += sizeof(" " #str "=") - 1; \
1146 freq_params.str = atoi(pos2); \
1147 } \
1148 } while (0)
1149
1150 SET_FREQ_SETTING(center_freq1);
1151 SET_FREQ_SETTING(center_freq2);
1152 SET_FREQ_SETTING(bandwidth);
1153 SET_FREQ_SETTING(sec_channel_offset);
1154#undef SET_FREQ_SETTING
1155
1156 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1157 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1158
1159 if (hwaddr_aton(cmd, peer)) {
1160 wpa_printf(MSG_DEBUG,
1161 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1162 cmd);
1163 return -1;
1164 }
1165
1166 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1167 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1168 MAC2STR(peer), oper_class, freq_params.freq,
1169 freq_params.center_freq1, freq_params.center_freq2,
1170 freq_params.bandwidth, freq_params.sec_channel_offset,
1171 freq_params.ht_enabled ? " HT" : "",
1172 freq_params.vht_enabled ? " VHT" : "");
1173
1174 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1175 &freq_params);
1176}
1177
1178
1179static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1180 struct wpa_supplicant *wpa_s, char *cmd)
1181{
1182 u8 peer[ETH_ALEN];
1183
1184 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1185 wpa_printf(MSG_INFO,
1186 "tdls_chanswitch: Only supported with external setup");
1187 return -1;
1188 }
1189
1190 if (hwaddr_aton(cmd, peer)) {
1191 wpa_printf(MSG_DEBUG,
1192 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1193 cmd);
1194 return -1;
1195 }
1196
1197 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1198 MAC2STR(peer));
1199
1200 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1201}
1202
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07001203
1204static int wpa_supplicant_ctrl_iface_tdls_link_status(
1205 struct wpa_supplicant *wpa_s, const char *addr,
1206 char *buf, size_t buflen)
1207{
1208 u8 peer[ETH_ALEN];
1209 const char *tdls_status;
1210 int ret;
1211
1212 if (hwaddr_aton(addr, peer)) {
1213 wpa_printf(MSG_DEBUG,
1214 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1215 addr);
1216 return -1;
1217 }
1218 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1219 MAC2STR(peer));
1220
1221 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1222 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1223 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1224 if (os_snprintf_error(buflen, ret))
1225 return -1;
1226
1227 return ret;
1228}
1229
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001230#endif /* CONFIG_TDLS */
1231
1232
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001233static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1234{
1235 char *token, *context = NULL;
1236 struct wmm_ac_ts_setup_params params = {
1237 .tsid = 0xff,
1238 .direction = 0xff,
1239 };
1240
1241 while ((token = str_token(cmd, " ", &context))) {
1242 if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
1243 sscanf(token, "up=%i", &params.user_priority) == 1 ||
1244 sscanf(token, "nominal_msdu_size=%i",
1245 &params.nominal_msdu_size) == 1 ||
1246 sscanf(token, "mean_data_rate=%i",
1247 &params.mean_data_rate) == 1 ||
1248 sscanf(token, "min_phy_rate=%i",
1249 &params.minimum_phy_rate) == 1 ||
1250 sscanf(token, "sba=%i",
1251 &params.surplus_bandwidth_allowance) == 1)
1252 continue;
1253
1254 if (os_strcasecmp(token, "downlink") == 0) {
1255 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1256 } else if (os_strcasecmp(token, "uplink") == 0) {
1257 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1258 } else if (os_strcasecmp(token, "bidi") == 0) {
1259 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1260 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1261 params.fixed_nominal_msdu = 1;
1262 } else {
1263 wpa_printf(MSG_DEBUG,
1264 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1265 token);
1266 return -1;
1267 }
1268
1269 }
1270
1271 return wpas_wmm_ac_addts(wpa_s, &params);
1272}
1273
1274
1275static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1276{
1277 u8 tsid = atoi(cmd);
1278
1279 return wpas_wmm_ac_delts(wpa_s, tsid);
1280}
1281
1282
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001283#ifdef CONFIG_IEEE80211R
1284static int wpa_supplicant_ctrl_iface_ft_ds(
1285 struct wpa_supplicant *wpa_s, char *addr)
1286{
1287 u8 target_ap[ETH_ALEN];
1288 struct wpa_bss *bss;
1289 const u8 *mdie;
1290
1291 if (hwaddr_aton(addr, target_ap)) {
1292 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1293 "address '%s'", addr);
1294 return -1;
1295 }
1296
1297 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1298
1299 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1300 if (bss)
1301 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1302 else
1303 mdie = NULL;
1304
1305 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
1306}
1307#endif /* CONFIG_IEEE80211R */
1308
1309
1310#ifdef CONFIG_WPS
1311static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1312 char *cmd)
1313{
1314 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001315#ifdef CONFIG_P2P
1316 u8 p2p_dev_addr[ETH_ALEN];
1317#endif /* CONFIG_P2P */
1318#ifdef CONFIG_AP
1319 u8 *_p2p_dev_addr = NULL;
1320#endif /* CONFIG_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001321 char *pos;
1322 int multi_ap = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001323
Hai Shalom021b0b52019-04-10 11:17:58 -07001324 if (!cmd || os_strcmp(cmd, "any") == 0 ||
1325 os_strncmp(cmd, "any ", 4) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001326 _bssid = NULL;
1327#ifdef CONFIG_P2P
1328 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1329 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1330 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1331 "P2P Device Address '%s'",
1332 cmd + 13);
1333 return -1;
1334 }
1335 _p2p_dev_addr = p2p_dev_addr;
1336#endif /* CONFIG_P2P */
Hai Shalom021b0b52019-04-10 11:17:58 -07001337 } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) {
1338 _bssid = NULL;
1339 multi_ap = atoi(cmd + 9);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001340 } else if (hwaddr_aton(cmd, bssid)) {
1341 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1342 cmd);
1343 return -1;
1344 }
1345
Hai Shalom021b0b52019-04-10 11:17:58 -07001346 if (cmd) {
1347 pos = os_strstr(cmd, " multi_ap=");
1348 if (pos) {
1349 pos += 10;
1350 multi_ap = atoi(pos);
1351 }
1352 }
1353
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001354#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001355 if (wpa_s->ap_iface)
1356 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1357#endif /* CONFIG_AP */
1358
Hai Shalom021b0b52019-04-10 11:17:58 -07001359 return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001360}
1361
1362
1363static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1364 char *cmd, char *buf,
1365 size_t buflen)
1366{
1367 u8 bssid[ETH_ALEN], *_bssid = bssid;
1368 char *pin;
1369 int ret;
1370
1371 pin = os_strchr(cmd, ' ');
1372 if (pin)
1373 *pin++ = '\0';
1374
1375 if (os_strcmp(cmd, "any") == 0)
1376 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001377 else if (os_strcmp(cmd, "get") == 0) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001378 if (wps_generate_pin((unsigned int *) &ret) < 0)
1379 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001380 goto done;
1381 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001382 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1383 cmd);
1384 return -1;
1385 }
1386
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001387#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001388 if (wpa_s->ap_iface) {
1389 int timeout = 0;
1390 char *pos;
1391
1392 if (pin) {
1393 pos = os_strchr(pin, ' ');
1394 if (pos) {
1395 *pos++ = '\0';
1396 timeout = atoi(pos);
1397 }
1398 }
1399
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001400 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001401 buf, buflen, timeout);
1402 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001403#endif /* CONFIG_AP */
1404
1405 if (pin) {
1406 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1407 DEV_PW_DEFAULT);
1408 if (ret < 0)
1409 return -1;
1410 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001411 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001412 return -1;
1413 return ret;
1414 }
1415
1416 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1417 if (ret < 0)
1418 return -1;
1419
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001420done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001421 /* Return the generated PIN */
1422 ret = os_snprintf(buf, buflen, "%08d", ret);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001423 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001424 return -1;
1425 return ret;
1426}
1427
1428
1429static int wpa_supplicant_ctrl_iface_wps_check_pin(
1430 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1431{
1432 char pin[9];
1433 size_t len;
1434 char *pos;
1435 int ret;
1436
1437 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1438 (u8 *) cmd, os_strlen(cmd));
1439 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1440 if (*pos < '0' || *pos > '9')
1441 continue;
1442 pin[len++] = *pos;
1443 if (len == 9) {
1444 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1445 return -1;
1446 }
1447 }
1448 if (len != 4 && len != 8) {
1449 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1450 return -1;
1451 }
1452 pin[len] = '\0';
1453
1454 if (len == 8) {
1455 unsigned int pin_val;
1456 pin_val = atoi(pin);
1457 if (!wps_pin_valid(pin_val)) {
1458 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1459 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001460 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001461 return -1;
1462 return ret;
1463 }
1464 }
1465
1466 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001467 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001468 return -1;
1469
1470 return ret;
1471}
1472
1473
Dmitry Shmidt04949592012-07-19 12:16:46 -07001474#ifdef CONFIG_WPS_NFC
1475
1476static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1477 char *cmd)
1478{
1479 u8 bssid[ETH_ALEN], *_bssid = bssid;
1480
1481 if (cmd == NULL || cmd[0] == '\0')
1482 _bssid = NULL;
1483 else if (hwaddr_aton(cmd, bssid))
1484 return -1;
1485
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001486 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1487 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001488}
1489
1490
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001491static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1492 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1493{
1494 int ndef;
1495 struct wpabuf *buf;
1496 int res;
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001497 char *pos;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001498
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001499 pos = os_strchr(cmd, ' ');
1500 if (pos)
1501 *pos++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001502 if (os_strcmp(cmd, "WPS") == 0)
1503 ndef = 0;
1504 else if (os_strcmp(cmd, "NDEF") == 0)
1505 ndef = 1;
1506 else
1507 return -1;
1508
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001509 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001510 if (buf == NULL)
1511 return -1;
1512
1513 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1514 wpabuf_len(buf));
1515 reply[res++] = '\n';
1516 reply[res] = '\0';
1517
1518 wpabuf_free(buf);
1519
1520 return res;
1521}
1522
1523
Dmitry Shmidt04949592012-07-19 12:16:46 -07001524static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1525 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1526{
1527 int ndef;
1528 struct wpabuf *buf;
1529 int res;
1530
1531 if (os_strcmp(cmd, "WPS") == 0)
1532 ndef = 0;
1533 else if (os_strcmp(cmd, "NDEF") == 0)
1534 ndef = 1;
1535 else
1536 return -1;
1537
1538 buf = wpas_wps_nfc_token(wpa_s, ndef);
1539 if (buf == NULL)
1540 return -1;
1541
1542 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1543 wpabuf_len(buf));
1544 reply[res++] = '\n';
1545 reply[res] = '\0';
1546
1547 wpabuf_free(buf);
1548
1549 return res;
1550}
1551
1552
1553static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1554 struct wpa_supplicant *wpa_s, char *pos)
1555{
1556 size_t len;
1557 struct wpabuf *buf;
1558 int ret;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001559 char *freq;
1560 int forced_freq = 0;
1561
1562 freq = strstr(pos, " freq=");
1563 if (freq) {
1564 *freq = '\0';
1565 freq += 6;
1566 forced_freq = atoi(freq);
1567 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001568
1569 len = os_strlen(pos);
1570 if (len & 0x01)
1571 return -1;
1572 len /= 2;
1573
1574 buf = wpabuf_alloc(len);
1575 if (buf == NULL)
1576 return -1;
1577 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1578 wpabuf_free(buf);
1579 return -1;
1580 }
1581
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001582 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001583 wpabuf_free(buf);
1584
1585 return ret;
1586}
1587
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001588
1589static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001590 char *reply, size_t max_len,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001591 int ndef)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001592{
1593 struct wpabuf *buf;
1594 int res;
1595
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001596 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001597 if (buf == NULL)
1598 return -1;
1599
1600 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1601 wpabuf_len(buf));
1602 reply[res++] = '\n';
1603 reply[res] = '\0';
1604
1605 wpabuf_free(buf);
1606
1607 return res;
1608}
1609
1610
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001611#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001612static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1613 char *reply, size_t max_len,
1614 int ndef)
1615{
1616 struct wpabuf *buf;
1617 int res;
1618
1619 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1620 if (buf == NULL) {
1621 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1622 return -1;
1623 }
1624
1625 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1626 wpabuf_len(buf));
1627 reply[res++] = '\n';
1628 reply[res] = '\0';
1629
1630 wpabuf_free(buf);
1631
1632 return res;
1633}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001634#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001635
1636
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001637static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1638 char *cmd, char *reply,
1639 size_t max_len)
1640{
1641 char *pos;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001642 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001643
1644 pos = os_strchr(cmd, ' ');
1645 if (pos == NULL)
1646 return -1;
1647 *pos++ = '\0';
1648
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001649 if (os_strcmp(cmd, "WPS") == 0)
1650 ndef = 0;
1651 else if (os_strcmp(cmd, "NDEF") == 0)
1652 ndef = 1;
1653 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001654 return -1;
1655
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001656 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001657 if (!ndef)
1658 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001659 return wpas_ctrl_nfc_get_handover_req_wps(
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001660 wpa_s, reply, max_len, ndef);
1661 }
1662
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001663#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001664 if (os_strcmp(pos, "P2P-CR") == 0) {
1665 return wpas_ctrl_nfc_get_handover_req_p2p(
1666 wpa_s, reply, max_len, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001667 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001668#endif /* CONFIG_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001669
1670 return -1;
1671}
1672
1673
1674static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001675 char *reply, size_t max_len,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001676 int ndef, int cr, char *uuid)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001677{
1678 struct wpabuf *buf;
1679 int res;
1680
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001681 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001682 if (buf == NULL)
1683 return -1;
1684
1685 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1686 wpabuf_len(buf));
1687 reply[res++] = '\n';
1688 reply[res] = '\0';
1689
1690 wpabuf_free(buf);
1691
1692 return res;
1693}
1694
1695
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001696#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001697static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1698 char *reply, size_t max_len,
1699 int ndef, int tag)
1700{
1701 struct wpabuf *buf;
1702 int res;
1703
1704 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1705 if (buf == NULL)
1706 return -1;
1707
1708 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1709 wpabuf_len(buf));
1710 reply[res++] = '\n';
1711 reply[res] = '\0';
1712
1713 wpabuf_free(buf);
1714
1715 return res;
1716}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001717#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001718
1719
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001720static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1721 char *cmd, char *reply,
1722 size_t max_len)
1723{
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001724 char *pos, *pos2;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001725 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001726
1727 pos = os_strchr(cmd, ' ');
1728 if (pos == NULL)
1729 return -1;
1730 *pos++ = '\0';
1731
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001732 if (os_strcmp(cmd, "WPS") == 0)
1733 ndef = 0;
1734 else if (os_strcmp(cmd, "NDEF") == 0)
1735 ndef = 1;
1736 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001737 return -1;
1738
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001739 pos2 = os_strchr(pos, ' ');
1740 if (pos2)
1741 *pos2++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001742 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001743 if (!ndef)
1744 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001745 return wpas_ctrl_nfc_get_handover_sel_wps(
1746 wpa_s, reply, max_len, ndef,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001747 os_strcmp(pos, "WPS-CR") == 0, pos2);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001748 }
1749
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001750#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001751 if (os_strcmp(pos, "P2P-CR") == 0) {
1752 return wpas_ctrl_nfc_get_handover_sel_p2p(
1753 wpa_s, reply, max_len, ndef, 0);
1754 }
1755
1756 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1757 return wpas_ctrl_nfc_get_handover_sel_p2p(
1758 wpa_s, reply, max_len, ndef, 1);
1759 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001760#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001761
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001762 return -1;
1763}
1764
1765
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001766static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1767 char *cmd)
1768{
1769 size_t len;
1770 struct wpabuf *req, *sel;
1771 int ret;
1772 char *pos, *role, *type, *pos2;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001773#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001774 char *freq;
1775 int forced_freq = 0;
1776
1777 freq = strstr(cmd, " freq=");
1778 if (freq) {
1779 *freq = '\0';
1780 freq += 6;
1781 forced_freq = atoi(freq);
1782 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001783#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001784
1785 role = cmd;
1786 pos = os_strchr(role, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001787 if (pos == NULL) {
1788 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001789 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001790 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001791 *pos++ = '\0';
1792
1793 type = pos;
1794 pos = os_strchr(type, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001795 if (pos == NULL) {
1796 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001797 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001798 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001799 *pos++ = '\0';
1800
1801 pos2 = os_strchr(pos, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001802 if (pos2 == NULL) {
1803 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001804 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001805 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001806 *pos2++ = '\0';
1807
1808 len = os_strlen(pos);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001809 if (len & 0x01) {
1810 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length 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 len /= 2;
1814
1815 req = wpabuf_alloc(len);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001816 if (req == NULL) {
1817 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001818 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001819 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001820 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001821 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001822 wpabuf_free(req);
1823 return -1;
1824 }
1825
1826 len = os_strlen(pos2);
1827 if (len & 0x01) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001828 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001829 wpabuf_free(req);
1830 return -1;
1831 }
1832 len /= 2;
1833
1834 sel = wpabuf_alloc(len);
1835 if (sel == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001836 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001837 wpabuf_free(req);
1838 return -1;
1839 }
1840 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001841 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001842 wpabuf_free(req);
1843 wpabuf_free(sel);
1844 return -1;
1845 }
1846
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001847 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1848 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1849
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001850 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1851 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001852#ifdef CONFIG_AP
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001853 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1854 {
1855 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1856 if (ret < 0)
1857 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001858#endif /* CONFIG_AP */
1859#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001860 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1861 {
1862 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1863 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1864 {
1865 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1866 forced_freq);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001867#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001868 } else {
1869 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1870 "reported: role=%s type=%s", role, type);
1871 ret = -1;
1872 }
1873 wpabuf_free(req);
1874 wpabuf_free(sel);
1875
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001876 if (ret)
1877 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1878
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001879 return ret;
1880}
1881
Dmitry Shmidt04949592012-07-19 12:16:46 -07001882#endif /* CONFIG_WPS_NFC */
1883
1884
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001885static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1886 char *cmd)
1887{
1888 u8 bssid[ETH_ALEN];
1889 char *pin;
1890 char *new_ssid;
1891 char *new_auth;
1892 char *new_encr;
1893 char *new_key;
1894 struct wps_new_ap_settings ap;
1895
1896 pin = os_strchr(cmd, ' ');
1897 if (pin == NULL)
1898 return -1;
1899 *pin++ = '\0';
1900
1901 if (hwaddr_aton(cmd, bssid)) {
1902 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1903 cmd);
1904 return -1;
1905 }
1906
1907 new_ssid = os_strchr(pin, ' ');
1908 if (new_ssid == NULL)
1909 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1910 *new_ssid++ = '\0';
1911
1912 new_auth = os_strchr(new_ssid, ' ');
1913 if (new_auth == NULL)
1914 return -1;
1915 *new_auth++ = '\0';
1916
1917 new_encr = os_strchr(new_auth, ' ');
1918 if (new_encr == NULL)
1919 return -1;
1920 *new_encr++ = '\0';
1921
1922 new_key = os_strchr(new_encr, ' ');
1923 if (new_key == NULL)
1924 return -1;
1925 *new_key++ = '\0';
1926
1927 os_memset(&ap, 0, sizeof(ap));
1928 ap.ssid_hex = new_ssid;
1929 ap.auth = new_auth;
1930 ap.encr = new_encr;
1931 ap.key_hex = new_key;
1932 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1933}
1934
1935
1936#ifdef CONFIG_AP
1937static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1938 char *cmd, char *buf,
1939 size_t buflen)
1940{
1941 int timeout = 300;
1942 char *pos;
1943 const char *pin_txt;
1944
1945 if (!wpa_s->ap_iface)
1946 return -1;
1947
1948 pos = os_strchr(cmd, ' ');
1949 if (pos)
1950 *pos++ = '\0';
1951
1952 if (os_strcmp(cmd, "disable") == 0) {
1953 wpas_wps_ap_pin_disable(wpa_s);
1954 return os_snprintf(buf, buflen, "OK\n");
1955 }
1956
1957 if (os_strcmp(cmd, "random") == 0) {
1958 if (pos)
1959 timeout = atoi(pos);
1960 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1961 if (pin_txt == NULL)
1962 return -1;
1963 return os_snprintf(buf, buflen, "%s", pin_txt);
1964 }
1965
1966 if (os_strcmp(cmd, "get") == 0) {
1967 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1968 if (pin_txt == NULL)
1969 return -1;
1970 return os_snprintf(buf, buflen, "%s", pin_txt);
1971 }
1972
1973 if (os_strcmp(cmd, "set") == 0) {
1974 char *pin;
1975 if (pos == NULL)
1976 return -1;
1977 pin = pos;
1978 pos = os_strchr(pos, ' ');
1979 if (pos) {
1980 *pos++ = '\0';
1981 timeout = atoi(pos);
1982 }
1983 if (os_strlen(pin) > buflen)
1984 return -1;
1985 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1986 return -1;
1987 return os_snprintf(buf, buflen, "%s", pin);
1988 }
1989
1990 return -1;
1991}
1992#endif /* CONFIG_AP */
1993
1994
1995#ifdef CONFIG_WPS_ER
1996static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1997 char *cmd)
1998{
1999 char *uuid = cmd, *pin, *pos;
2000 u8 addr_buf[ETH_ALEN], *addr = NULL;
2001 pin = os_strchr(uuid, ' ');
2002 if (pin == NULL)
2003 return -1;
2004 *pin++ = '\0';
2005 pos = os_strchr(pin, ' ');
2006 if (pos) {
2007 *pos++ = '\0';
2008 if (hwaddr_aton(pos, addr_buf) == 0)
2009 addr = addr_buf;
2010 }
2011 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
2012}
2013
2014
2015static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
2016 char *cmd)
2017{
2018 char *uuid = cmd, *pin;
2019 pin = os_strchr(uuid, ' ');
2020 if (pin == NULL)
2021 return -1;
2022 *pin++ = '\0';
2023 return wpas_wps_er_learn(wpa_s, uuid, pin);
2024}
2025
2026
2027static int wpa_supplicant_ctrl_iface_wps_er_set_config(
2028 struct wpa_supplicant *wpa_s, char *cmd)
2029{
2030 char *uuid = cmd, *id;
2031 id = os_strchr(uuid, ' ');
2032 if (id == NULL)
2033 return -1;
2034 *id++ = '\0';
2035 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
2036}
2037
2038
2039static int wpa_supplicant_ctrl_iface_wps_er_config(
2040 struct wpa_supplicant *wpa_s, char *cmd)
2041{
2042 char *pin;
2043 char *new_ssid;
2044 char *new_auth;
2045 char *new_encr;
2046 char *new_key;
2047 struct wps_new_ap_settings ap;
2048
2049 pin = os_strchr(cmd, ' ');
2050 if (pin == NULL)
2051 return -1;
2052 *pin++ = '\0';
2053
2054 new_ssid = os_strchr(pin, ' ');
2055 if (new_ssid == NULL)
2056 return -1;
2057 *new_ssid++ = '\0';
2058
2059 new_auth = os_strchr(new_ssid, ' ');
2060 if (new_auth == NULL)
2061 return -1;
2062 *new_auth++ = '\0';
2063
2064 new_encr = os_strchr(new_auth, ' ');
2065 if (new_encr == NULL)
2066 return -1;
2067 *new_encr++ = '\0';
2068
2069 new_key = os_strchr(new_encr, ' ');
2070 if (new_key == NULL)
2071 return -1;
2072 *new_key++ = '\0';
2073
2074 os_memset(&ap, 0, sizeof(ap));
2075 ap.ssid_hex = new_ssid;
2076 ap.auth = new_auth;
2077 ap.encr = new_encr;
2078 ap.key_hex = new_key;
2079 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
2080}
Dmitry Shmidt04949592012-07-19 12:16:46 -07002081
2082
2083#ifdef CONFIG_WPS_NFC
2084static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
2085 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2086{
2087 int ndef;
2088 struct wpabuf *buf;
2089 int res;
2090 char *uuid;
2091
2092 uuid = os_strchr(cmd, ' ');
2093 if (uuid == NULL)
2094 return -1;
2095 *uuid++ = '\0';
2096
2097 if (os_strcmp(cmd, "WPS") == 0)
2098 ndef = 0;
2099 else if (os_strcmp(cmd, "NDEF") == 0)
2100 ndef = 1;
2101 else
2102 return -1;
2103
2104 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
2105 if (buf == NULL)
2106 return -1;
2107
2108 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
2109 wpabuf_len(buf));
2110 reply[res++] = '\n';
2111 reply[res] = '\0';
2112
2113 wpabuf_free(buf);
2114
2115 return res;
2116}
2117#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002118#endif /* CONFIG_WPS_ER */
2119
2120#endif /* CONFIG_WPS */
2121
2122
2123#ifdef CONFIG_IBSS_RSN
2124static int wpa_supplicant_ctrl_iface_ibss_rsn(
2125 struct wpa_supplicant *wpa_s, char *addr)
2126{
2127 u8 peer[ETH_ALEN];
2128
2129 if (hwaddr_aton(addr, peer)) {
2130 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
2131 "address '%s'", addr);
2132 return -1;
2133 }
2134
2135 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
2136 MAC2STR(peer));
2137
2138 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
2139}
2140#endif /* CONFIG_IBSS_RSN */
2141
2142
2143static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
2144 char *rsp)
2145{
2146#ifdef IEEE8021X_EAPOL
2147 char *pos, *id_pos;
2148 int id;
2149 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002150
2151 pos = os_strchr(rsp, '-');
2152 if (pos == NULL)
2153 return -1;
2154 *pos++ = '\0';
2155 id_pos = pos;
2156 pos = os_strchr(pos, ':');
2157 if (pos == NULL)
2158 return -1;
2159 *pos++ = '\0';
2160 id = atoi(id_pos);
2161 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
2162 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2163 (u8 *) pos, os_strlen(pos));
2164
2165 ssid = wpa_config_get_network(wpa_s->conf, id);
2166 if (ssid == NULL) {
2167 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2168 "to update", id);
2169 return -1;
2170 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002171
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002172 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2173 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002174#else /* IEEE8021X_EAPOL */
2175 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2176 return -1;
2177#endif /* IEEE8021X_EAPOL */
2178}
2179
2180
2181static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2182 const char *params,
2183 char *buf, size_t buflen)
2184{
2185 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002186 int res, verbose, wps, ret;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002187#ifdef CONFIG_HS20
2188 const u8 *hs20;
2189#endif /* CONFIG_HS20 */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002190 const u8 *sess_id;
2191 size_t sess_id_len;
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002192
Dmitry Shmidt56052862013-10-04 10:23:25 -07002193 if (os_strcmp(params, "-DRIVER") == 0)
2194 return wpa_drv_status(wpa_s, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002195 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002196 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002197 pos = buf;
2198 end = buf + buflen;
2199 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2200 struct wpa_ssid *ssid = wpa_s->current_ssid;
2201 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2202 MAC2STR(wpa_s->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002203 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002204 return pos - buf;
2205 pos += ret;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002206 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2207 wpa_s->assoc_freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002208 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002209 return pos - buf;
2210 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002211 if (ssid) {
2212 u8 *_ssid = ssid->ssid;
2213 size_t ssid_len = ssid->ssid_len;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002214 u8 ssid_buf[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002215 if (ssid_len == 0) {
2216 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2217 if (_res < 0)
2218 ssid_len = 0;
2219 else
2220 ssid_len = _res;
2221 _ssid = ssid_buf;
2222 }
2223 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2224 wpa_ssid_txt(_ssid, ssid_len),
2225 ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002226 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002227 return pos - buf;
2228 pos += ret;
2229
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002230 if (wps && ssid->passphrase &&
2231 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2232 (ssid->mode == WPAS_MODE_AP ||
2233 ssid->mode == WPAS_MODE_P2P_GO)) {
2234 ret = os_snprintf(pos, end - pos,
2235 "passphrase=%s\n",
2236 ssid->passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002237 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002238 return pos - buf;
2239 pos += ret;
2240 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002241 if (ssid->id_str) {
2242 ret = os_snprintf(pos, end - pos,
2243 "id_str=%s\n",
2244 ssid->id_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002245 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002246 return pos - buf;
2247 pos += ret;
2248 }
2249
2250 switch (ssid->mode) {
2251 case WPAS_MODE_INFRA:
2252 ret = os_snprintf(pos, end - pos,
2253 "mode=station\n");
2254 break;
2255 case WPAS_MODE_IBSS:
2256 ret = os_snprintf(pos, end - pos,
2257 "mode=IBSS\n");
2258 break;
2259 case WPAS_MODE_AP:
2260 ret = os_snprintf(pos, end - pos,
2261 "mode=AP\n");
2262 break;
2263 case WPAS_MODE_P2P_GO:
2264 ret = os_snprintf(pos, end - pos,
2265 "mode=P2P GO\n");
2266 break;
2267 case WPAS_MODE_P2P_GROUP_FORMATION:
2268 ret = os_snprintf(pos, end - pos,
2269 "mode=P2P GO - group "
2270 "formation\n");
2271 break;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002272 case WPAS_MODE_MESH:
2273 ret = os_snprintf(pos, end - pos,
2274 "mode=mesh\n");
2275 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002276 default:
2277 ret = 0;
2278 break;
2279 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002280 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002281 return pos - buf;
2282 pos += ret;
2283 }
2284
Hai Shalom021b0b52019-04-10 11:17:58 -07002285 if (wpa_s->connection_set &&
2286 (wpa_s->connection_ht || wpa_s->connection_vht ||
2287 wpa_s->connection_he)) {
2288 ret = os_snprintf(pos, end - pos,
2289 "wifi_generation=%u\n",
2290 wpa_s->connection_he ? 6 :
2291 (wpa_s->connection_vht ? 5 : 4));
2292 if (os_snprintf_error(end - pos, ret))
2293 return pos - buf;
2294 pos += ret;
2295 }
2296
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002297#ifdef CONFIG_AP
2298 if (wpa_s->ap_iface) {
2299 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2300 end - pos,
2301 verbose);
2302 } else
2303#endif /* CONFIG_AP */
2304 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2305 }
Paul Stewart092955c2017-02-06 09:13:09 -08002306#ifdef CONFIG_SME
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002307#ifdef CONFIG_SAE
2308 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002309#ifdef CONFIG_AP
2310 !wpa_s->ap_iface &&
2311#endif /* CONFIG_AP */
2312 wpa_s->sme.sae.state == SAE_ACCEPTED) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002313 ret = os_snprintf(pos, end - pos, "sae_group=%d\n"
2314 "sae_h2e=%d\n"
2315 "sae_pk=%d\n",
2316 wpa_s->sme.sae.group,
2317 wpa_s->sme.sae.h2e,
2318 wpa_s->sme.sae.pk);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002319 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002320 return pos - buf;
2321 pos += ret;
2322 }
2323#endif /* CONFIG_SAE */
Paul Stewart092955c2017-02-06 09:13:09 -08002324#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002325 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2326 wpa_supplicant_state_txt(wpa_s->wpa_state));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002327 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002328 return pos - buf;
2329 pos += ret;
2330
2331 if (wpa_s->l2 &&
2332 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2333 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002334 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002335 return pos - buf;
2336 pos += ret;
2337 }
2338
2339#ifdef CONFIG_P2P
2340 if (wpa_s->global->p2p) {
2341 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2342 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002343 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002344 return pos - buf;
2345 pos += ret;
2346 }
2347#endif /* CONFIG_P2P */
2348
2349 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2350 MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002351 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002352 return pos - buf;
2353 pos += ret;
2354
Dmitry Shmidt04949592012-07-19 12:16:46 -07002355#ifdef CONFIG_HS20
2356 if (wpa_s->current_bss &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002357 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2358 HS20_IE_VENDOR_TYPE)) &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002359 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2360 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002361 int release = 1;
2362 if (hs20[1] >= 5) {
2363 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2364 release = rel_num + 1;
2365 }
2366 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002367 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002368 return pos - buf;
2369 pos += ret;
2370 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002371
2372 if (wpa_s->current_ssid) {
2373 struct wpa_cred *cred;
2374 char *type;
2375
2376 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002377 size_t i;
2378
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002379 if (wpa_s->current_ssid->parent_cred != cred)
2380 continue;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002381
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002382 if (cred->provisioning_sp) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002383 ret = os_snprintf(pos, end - pos,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002384 "provisioning_sp=%s\n",
2385 cred->provisioning_sp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002386 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt051af732013-10-22 13:52:46 -07002387 return pos - buf;
2388 pos += ret;
2389 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002390
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002391 if (!cred->domain)
2392 goto no_domain;
2393
2394 i = 0;
2395 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2396 struct wpabuf *names =
2397 wpa_s->current_bss->anqp->domain_name;
2398 for (i = 0; names && i < cred->num_domain; i++)
2399 {
2400 if (domain_name_list_contains(
2401 names, cred->domain[i], 1))
2402 break;
2403 }
2404 if (i == cred->num_domain)
2405 i = 0; /* show first entry by default */
2406 }
2407 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2408 cred->domain[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002409 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002410 return pos - buf;
2411 pos += ret;
2412
2413 no_domain:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002414 if (wpa_s->current_bss == NULL ||
2415 wpa_s->current_bss->anqp == NULL)
2416 res = -1;
2417 else
2418 res = interworking_home_sp_cred(
2419 wpa_s, cred,
2420 wpa_s->current_bss->anqp->domain_name);
2421 if (res > 0)
2422 type = "home";
2423 else if (res == 0)
2424 type = "roaming";
2425 else
2426 type = "unknown";
2427
2428 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002429 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002430 return pos - buf;
2431 pos += ret;
2432
2433 break;
2434 }
2435 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002436#endif /* CONFIG_HS20 */
2437
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002438 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2439 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2440 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2441 verbose);
2442 if (res >= 0)
2443 pos += res;
2444 }
2445
Dmitry Shmidt29333592017-01-09 12:27:11 -08002446#ifdef CONFIG_MACSEC
2447 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2448 if (res > 0)
2449 pos += res;
2450#endif /* CONFIG_MACSEC */
2451
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002452 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2453 if (sess_id) {
2454 char *start = pos;
2455
2456 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2457 if (os_snprintf_error(end - pos, ret))
2458 return start - buf;
2459 pos += ret;
2460 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2461 if (ret <= 0)
2462 return start - buf;
2463 pos += ret;
2464 ret = os_snprintf(pos, end - pos, "\n");
2465 if (os_snprintf_error(end - pos, ret))
2466 return start - buf;
2467 pos += ret;
2468 }
2469
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002470 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2471 if (res >= 0)
2472 pos += res;
2473
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002474#ifdef CONFIG_WPS
2475 {
2476 char uuid_str[100];
2477 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2478 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002479 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002480 return pos - buf;
2481 pos += ret;
2482 }
2483#endif /* CONFIG_WPS */
2484
Roshan Pius3a1667e2018-07-03 15:17:14 -07002485 if (wpa_s->ieee80211ac) {
2486 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2487 if (os_snprintf_error(end - pos, ret))
2488 return pos - buf;
2489 pos += ret;
2490 }
2491
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002492#ifdef ANDROID
vandwalleffc70182014-09-11 11:40:14 -07002493 /*
2494 * Allow using the STATUS command with default behavior, say for debug,
2495 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2496 * events with STATUS-NO_EVENTS.
2497 */
2498 if (os_strcmp(params, "-NO_EVENTS")) {
2499 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2500 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2501 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2502 wpa_s->wpa_state,
2503 MAC2STR(wpa_s->bssid),
2504 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2505 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2506 wpa_s->current_ssid->ssid_len) : "");
2507 if (wpa_s->wpa_state == WPA_COMPLETED) {
2508 struct wpa_ssid *ssid = wpa_s->current_ssid;
2509 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2510 "- connection to " MACSTR
2511 " completed %s [id=%d id_str=%s]",
2512 MAC2STR(wpa_s->bssid), "(auth)",
2513 ssid ? ssid->id : -1,
2514 ssid && ssid->id_str ? ssid->id_str : "");
2515 }
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08002516 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002517#endif /* ANDROID */
2518
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002519 return pos - buf;
2520}
2521
2522
2523static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2524 char *cmd)
2525{
2526 char *pos;
2527 int id;
2528 struct wpa_ssid *ssid;
2529 u8 bssid[ETH_ALEN];
2530
2531 /* cmd: "<network id> <BSSID>" */
2532 pos = os_strchr(cmd, ' ');
2533 if (pos == NULL)
2534 return -1;
2535 *pos++ = '\0';
2536 id = atoi(cmd);
2537 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2538 if (hwaddr_aton(pos, bssid)) {
2539 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2540 return -1;
2541 }
2542
2543 ssid = wpa_config_get_network(wpa_s->conf, id);
2544 if (ssid == NULL) {
2545 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2546 "to update", id);
2547 return -1;
2548 }
2549
2550 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2551 ssid->bssid_set = !is_zero_ether_addr(bssid);
2552
2553 return 0;
2554}
2555
2556
Hai Shalom60840252021-02-19 19:02:11 -08002557static int wpa_supplicant_ctrl_iface_bssid_ignore(struct wpa_supplicant *wpa_s,
2558 char *cmd, char *buf,
2559 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002560{
2561 u8 bssid[ETH_ALEN];
Hai Shalom60840252021-02-19 19:02:11 -08002562 struct wpa_bssid_ignore *e;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002563 char *pos, *end;
2564 int ret;
2565
Hai Shalom60840252021-02-19 19:02:11 -08002566 /* cmd: "BSSID_IGNORE [<BSSID>]" */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002567 if (*cmd == '\0') {
2568 pos = buf;
2569 end = buf + buflen;
Hai Shalom60840252021-02-19 19:02:11 -08002570 e = wpa_s->bssid_ignore;
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002571 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002572 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2573 MAC2STR(e->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002574 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002575 return pos - buf;
2576 pos += ret;
2577 e = e->next;
2578 }
2579 return pos - buf;
2580 }
2581
2582 cmd++;
2583 if (os_strncmp(cmd, "clear", 5) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -08002584 wpa_bssid_ignore_clear(wpa_s);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002585 os_memcpy(buf, "OK\n", 3);
2586 return 3;
2587 }
2588
Hai Shalom60840252021-02-19 19:02:11 -08002589 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BSSID_IGNORE bssid='%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002590 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002591 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002592 return -1;
2593 }
2594
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002595 /*
2596 * Add the BSSID twice, so its count will be 2, causing it to be
2597 * skipped when processing scan results.
2598 */
Hai Shalom60840252021-02-19 19:02:11 -08002599 ret = wpa_bssid_ignore_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002600 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002601 return -1;
Hai Shalom60840252021-02-19 19:02:11 -08002602 ret = wpa_bssid_ignore_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002603 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002604 return -1;
2605 os_memcpy(buf, "OK\n", 3);
2606 return 3;
2607}
2608
2609
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002610static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2611 char *cmd, char *buf,
2612 size_t buflen)
2613{
2614 char *pos, *end, *stamp;
2615 int ret;
2616
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002617 /* cmd: "LOG_LEVEL [<level>]" */
2618 if (*cmd == '\0') {
2619 pos = buf;
2620 end = buf + buflen;
2621 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2622 "Timestamp: %d\n",
2623 debug_level_str(wpa_debug_level),
2624 wpa_debug_timestamp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002625 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002626 ret = 0;
2627
2628 return ret;
2629 }
2630
2631 while (*cmd == ' ')
2632 cmd++;
2633
2634 stamp = os_strchr(cmd, ' ');
2635 if (stamp) {
2636 *stamp++ = '\0';
2637 while (*stamp == ' ') {
2638 stamp++;
2639 }
2640 }
2641
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002642 if (os_strlen(cmd)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002643 int level = str_to_debug_level(cmd);
2644 if (level < 0)
2645 return -1;
2646 wpa_debug_level = level;
2647 }
2648
2649 if (stamp && os_strlen(stamp))
2650 wpa_debug_timestamp = atoi(stamp);
2651
2652 os_memcpy(buf, "OK\n", 3);
2653 return 3;
2654}
2655
2656
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002657static int wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002658 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002659{
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002660 char *pos, *end, *prev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002661 struct wpa_ssid *ssid;
2662 int ret;
2663
2664 pos = buf;
2665 end = buf + buflen;
2666 ret = os_snprintf(pos, end - pos,
2667 "network id / ssid / bssid / flags\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002668 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002669 return pos - buf;
2670 pos += ret;
2671
2672 ssid = wpa_s->conf->ssid;
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002673
2674 /* skip over ssids until we find next one */
2675 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2676 int last_id = atoi(cmd + 8);
2677 if (last_id != -1) {
2678 while (ssid != NULL && ssid->id <= last_id) {
2679 ssid = ssid->next;
2680 }
2681 }
2682 }
2683
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002684 while (ssid) {
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002685 prev = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002686 ret = os_snprintf(pos, end - pos, "%d\t%s",
2687 ssid->id,
2688 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002689 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002690 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002691 pos += ret;
2692 if (ssid->bssid_set) {
2693 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2694 MAC2STR(ssid->bssid));
2695 } else {
2696 ret = os_snprintf(pos, end - pos, "\tany");
2697 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002698 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002699 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002700 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002701 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002702 ssid == wpa_s->current_ssid ?
2703 "[CURRENT]" : "",
2704 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002705 ssid->disabled_until.sec ?
2706 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002707 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2708 "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002709 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002710 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002711 pos += ret;
2712 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002713 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002714 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002715 pos += ret;
2716
2717 ssid = ssid->next;
2718 }
2719
2720 return pos - buf;
2721}
2722
2723
2724static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2725{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002726 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002727 ret = os_snprintf(pos, end - pos, "-");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002728 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002729 return pos;
2730 pos += ret;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002731 ret = wpa_write_ciphers(pos, end, cipher, "+");
2732 if (ret < 0)
2733 return pos;
2734 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002735 return pos;
2736}
2737
2738
2739static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2740 const u8 *ie, size_t ie_len)
2741{
2742 struct wpa_ie_data data;
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002743 char *start;
2744 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002745
2746 ret = os_snprintf(pos, end - pos, "[%s-", proto);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002747 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002748 return pos;
2749 pos += ret;
2750
2751 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2752 ret = os_snprintf(pos, end - pos, "?]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002753 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002754 return pos;
2755 pos += ret;
2756 return pos;
2757 }
2758
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002759 start = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002760 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002761 ret = os_snprintf(pos, end - pos, "%sEAP",
2762 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002763 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002764 return pos;
2765 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002766 }
2767 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002768 ret = os_snprintf(pos, end - pos, "%sPSK",
2769 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002770 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002771 return pos;
2772 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002773 }
2774 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002775 ret = os_snprintf(pos, end - pos, "%sNone",
2776 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002777 if (os_snprintf_error(end - pos, ret))
2778 return pos;
2779 pos += ret;
2780 }
2781 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2782 ret = os_snprintf(pos, end - pos, "%sSAE",
2783 pos == start ? "" : "+");
2784 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002785 return pos;
2786 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002787 }
2788#ifdef CONFIG_IEEE80211R
2789 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2790 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002791 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_FT_PSK) {
2797 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002798 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_FT_SAE) {
2804 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
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#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002811 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2812 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
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_PSK_SHA256) {
2819 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
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))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002822 return pos;
2823 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002824 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002825
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002826#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002827 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2828 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2829 pos == start ? "" : "+");
2830 if (os_snprintf_error(end - pos, ret))
2831 return pos;
2832 pos += ret;
2833 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002834#endif /* CONFIG_SUITEB */
2835
2836#ifdef CONFIG_SUITEB192
2837 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2838 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2839 pos == start ? "" : "+");
2840 if (os_snprintf_error(end - pos, ret))
2841 return pos;
2842 pos += ret;
2843 }
2844#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002845
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002846#ifdef CONFIG_FILS
2847 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2848 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2849 pos == start ? "" : "+");
2850 if (os_snprintf_error(end - pos, ret))
2851 return pos;
2852 pos += ret;
2853 }
2854 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2855 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2856 pos == start ? "" : "+");
2857 if (os_snprintf_error(end - pos, ret))
2858 return pos;
2859 pos += ret;
2860 }
2861#ifdef CONFIG_IEEE80211R
2862 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2863 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2864 pos == start ? "" : "+");
2865 if (os_snprintf_error(end - pos, ret))
2866 return pos;
2867 pos += ret;
2868 }
2869 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2870 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2871 pos == start ? "" : "+");
2872 if (os_snprintf_error(end - pos, ret))
2873 return pos;
2874 pos += ret;
2875 }
2876#endif /* CONFIG_IEEE80211R */
2877#endif /* CONFIG_FILS */
2878
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002879#ifdef CONFIG_OWE
2880 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2881 ret = os_snprintf(pos, end - pos, "%sOWE",
2882 pos == start ? "" : "+");
2883 if (os_snprintf_error(end - pos, ret))
2884 return pos;
2885 pos += ret;
2886 }
2887#endif /* CONFIG_OWE */
2888
2889#ifdef CONFIG_DPP
2890 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
2891 ret = os_snprintf(pos, end - pos, "%sDPP",
2892 pos == start ? "" : "+");
2893 if (os_snprintf_error(end - pos, ret))
2894 return pos;
2895 pos += ret;
2896 }
2897#endif /* CONFIG_DPP */
2898
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002899 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2900 ret = os_snprintf(pos, end - pos, "%sOSEN",
2901 pos == start ? "" : "+");
2902 if (os_snprintf_error(end - pos, ret))
2903 return pos;
2904 pos += ret;
2905 }
2906
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002907 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2908
2909 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2910 ret = os_snprintf(pos, end - pos, "-preauth");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002911 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002912 return pos;
2913 pos += ret;
2914 }
2915
2916 ret = os_snprintf(pos, end - pos, "]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002917 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002918 return pos;
2919 pos += ret;
2920
2921 return pos;
2922}
2923
2924
2925#ifdef CONFIG_WPS
2926static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2927 char *pos, char *end,
2928 struct wpabuf *wps_ie)
2929{
2930 int ret;
2931 const char *txt;
2932
2933 if (wps_ie == NULL)
2934 return pos;
2935 if (wps_is_selected_pbc_registrar(wps_ie))
2936 txt = "[WPS-PBC]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002937 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2938 txt = "[WPS-AUTH]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002939 else if (wps_is_selected_pin_registrar(wps_ie))
2940 txt = "[WPS-PIN]";
2941 else
2942 txt = "[WPS]";
2943
2944 ret = os_snprintf(pos, end - pos, "%s", txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002945 if (!os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002946 pos += ret;
2947 wpabuf_free(wps_ie);
2948 return pos;
2949}
2950#endif /* CONFIG_WPS */
2951
2952
2953static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2954 char *pos, char *end,
2955 const struct wpa_bss *bss)
2956{
2957#ifdef CONFIG_WPS
2958 struct wpabuf *wps_ie;
2959 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2960 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2961#else /* CONFIG_WPS */
2962 return pos;
2963#endif /* CONFIG_WPS */
2964}
2965
2966
2967/* Format one result on one text line into a buffer. */
2968static int wpa_supplicant_ctrl_iface_scan_result(
2969 struct wpa_supplicant *wpa_s,
2970 const struct wpa_bss *bss, char *buf, size_t buflen)
2971{
2972 char *pos, *end;
2973 int ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07002974 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe, *rsnxe;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002975
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002976 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002977 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07002978 if (!p2p)
2979 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002980 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2981 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2982 0)
2983 return 0; /* Do not show P2P listen discovery results here */
2984
2985 pos = buf;
2986 end = buf + buflen;
2987
2988 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2989 MAC2STR(bss->bssid), bss->freq, bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002990 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002991 return -1;
2992 pos += ret;
2993 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2994 if (ie)
2995 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2996 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002997 if (ie2) {
2998 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2999 ie2, 2 + ie2[1]);
3000 }
Hai Shalom899fcc72020-10-19 14:38:18 -07003001 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
3002 if (rsnxe && rsnxe[1] >= 1) {
3003 if (rsnxe[2] & BIT(WLAN_RSNX_CAPAB_SAE_H2E)) {
3004 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
3005 if (os_snprintf_error(end - pos, ret))
3006 return -1;
3007 pos += ret;
3008 }
3009 if (rsnxe[2] & BIT(WLAN_RSNX_CAPAB_SAE_PK)) {
3010 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
3011 if (os_snprintf_error(end - pos, ret))
3012 return -1;
3013 pos += ret;
3014 }
3015 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003016 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
3017 if (osen_ie)
3018 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
3019 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003020 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
3021 if (owe) {
3022 ret = os_snprintf(pos, end - pos,
3023 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
3024 if (os_snprintf_error(end - pos, ret))
3025 return -1;
3026 pos += ret;
3027 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003028 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003029 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003030 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003031 if (os_snprintf_error(end - pos, ret))
3032 return -1;
3033 pos += ret;
3034 }
3035 if (mesh) {
3036 ret = os_snprintf(pos, end - pos, "[MESH]");
3037 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003038 return -1;
3039 pos += ret;
3040 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003041 if (bss_is_dmg(bss)) {
3042 const char *s;
Hai Shalomc3565922019-10-28 11:58:20 -07003043
Hai Shalom60840252021-02-19 19:02:11 -08003044 if (wpa_bss_get_ie_ext(bss, WLAN_EID_EXT_EDMG_OPERATION)) {
Hai Shalomc3565922019-10-28 11:58:20 -07003045 ret = os_snprintf(pos, end - pos, "[EDMG]");
3046 if (os_snprintf_error(end - pos, ret))
3047 return -1;
3048 pos += ret;
3049 }
3050
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003051 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003052 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003053 return -1;
3054 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003055 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3056 case IEEE80211_CAP_DMG_IBSS:
3057 s = "[IBSS]";
3058 break;
3059 case IEEE80211_CAP_DMG_AP:
3060 s = "[ESS]";
3061 break;
3062 case IEEE80211_CAP_DMG_PBSS:
3063 s = "[PBSS]";
3064 break;
3065 default:
3066 s = "";
3067 break;
3068 }
3069 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003070 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003071 return -1;
3072 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003073 } else {
3074 if (bss->caps & IEEE80211_CAP_IBSS) {
3075 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003076 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003077 return -1;
3078 pos += ret;
3079 }
3080 if (bss->caps & IEEE80211_CAP_ESS) {
3081 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003082 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003083 return -1;
3084 pos += ret;
3085 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003086 }
3087 if (p2p) {
3088 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003089 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003090 return -1;
3091 pos += ret;
3092 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003093#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003094 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003095 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003096 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003097 return -1;
3098 pos += ret;
3099 }
3100#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003101#ifdef CONFIG_FILS
3102 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
3103 ret = os_snprintf(pos, end - pos, "[FILS]");
3104 if (os_snprintf_error(end - pos, ret))
3105 return -1;
3106 pos += ret;
3107 }
3108#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003109#ifdef CONFIG_FST
3110 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
3111 ret = os_snprintf(pos, end - pos, "[FST]");
3112 if (os_snprintf_error(end - pos, ret))
3113 return -1;
3114 pos += ret;
3115 }
3116#endif /* CONFIG_FST */
Hai Shalom74f70d42019-02-11 14:42:39 -08003117 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
3118 ret = os_snprintf(pos, end - pos, "[UTF-8]");
3119 if (os_snprintf_error(end - pos, ret))
3120 return -1;
3121 pos += ret;
3122 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003123
3124 ret = os_snprintf(pos, end - pos, "\t%s",
3125 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003126 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003127 return -1;
3128 pos += ret;
3129
3130 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003131 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003132 return -1;
3133 pos += ret;
3134
3135 return pos - buf;
3136}
3137
3138
3139static int wpa_supplicant_ctrl_iface_scan_results(
3140 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3141{
3142 char *pos, *end;
3143 struct wpa_bss *bss;
3144 int ret;
3145
3146 pos = buf;
3147 end = buf + buflen;
3148 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
3149 "flags / ssid\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003150 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003151 return pos - buf;
3152 pos += ret;
3153
3154 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3155 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
3156 end - pos);
3157 if (ret < 0 || ret >= end - pos)
3158 return pos - buf;
3159 pos += ret;
3160 }
3161
3162 return pos - buf;
3163}
3164
3165
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003166#ifdef CONFIG_MESH
3167
3168static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3169 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
3170{
3171 char *pos, ifname[IFNAMSIZ + 1];
3172
3173 ifname[0] = '\0';
3174
3175 pos = os_strstr(cmd, "ifname=");
3176 if (pos) {
3177 pos += 7;
3178 os_strlcpy(ifname, pos, sizeof(ifname));
3179 }
3180
3181 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
3182 return -1;
3183
3184 os_strlcpy(reply, ifname, max_len);
3185 return os_strlen(ifname);
3186}
3187
3188
3189static int wpa_supplicant_ctrl_iface_mesh_group_add(
3190 struct wpa_supplicant *wpa_s, char *cmd)
3191{
3192 int id;
3193 struct wpa_ssid *ssid;
3194
3195 id = atoi(cmd);
3196 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
3197
3198 ssid = wpa_config_get_network(wpa_s->conf, id);
3199 if (ssid == NULL) {
3200 wpa_printf(MSG_DEBUG,
3201 "CTRL_IFACE: Could not find network id=%d", id);
3202 return -1;
3203 }
3204 if (ssid->mode != WPAS_MODE_MESH) {
3205 wpa_printf(MSG_DEBUG,
3206 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3207 return -1;
3208 }
3209 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
3210 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
3211 wpa_printf(MSG_ERROR,
3212 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3213 return -1;
3214 }
3215
3216 /*
3217 * TODO: If necessary write our own group_add function,
3218 * for now we can reuse select_network
3219 */
3220 wpa_supplicant_select_network(wpa_s, ssid);
3221
3222 return 0;
3223}
3224
3225
3226static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3227 struct wpa_supplicant *wpa_s, char *cmd)
3228{
3229 struct wpa_supplicant *orig;
3230 struct wpa_global *global;
3231 int found = 0;
3232
3233 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3234
3235 global = wpa_s->global;
3236 orig = wpa_s;
3237
3238 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3239 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3240 found = 1;
3241 break;
3242 }
3243 }
3244 if (!found) {
3245 wpa_printf(MSG_ERROR,
3246 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3247 cmd);
3248 return -1;
3249 }
3250 if (wpa_s->mesh_if_created && wpa_s == orig) {
3251 wpa_printf(MSG_ERROR,
3252 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3253 return -1;
3254 }
3255
3256 wpa_s->reassociate = 0;
3257 wpa_s->disconnected = 1;
3258 wpa_supplicant_cancel_sched_scan(wpa_s);
3259 wpa_supplicant_cancel_scan(wpa_s);
3260
3261 /*
3262 * TODO: If necessary write our own group_remove function,
3263 * for now we can reuse deauthenticate
3264 */
3265 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3266
3267 if (wpa_s->mesh_if_created)
3268 wpa_supplicant_remove_iface(global, wpa_s, 0);
3269
3270 return 0;
3271}
3272
Dmitry Shmidte4663042016-04-04 10:07:49 -07003273
3274static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3275 struct wpa_supplicant *wpa_s, char *cmd)
3276{
3277 u8 addr[ETH_ALEN];
3278
3279 if (hwaddr_aton(cmd, addr) < 0)
3280 return -1;
3281
3282 return wpas_mesh_peer_remove(wpa_s, addr);
3283}
3284
3285
3286static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3287 struct wpa_supplicant *wpa_s, char *cmd)
3288{
3289 u8 addr[ETH_ALEN];
3290 int duration;
3291 char *pos;
3292
3293 pos = os_strstr(cmd, " duration=");
3294 if (pos) {
3295 *pos = '\0';
3296 duration = atoi(pos + 10);
3297 } else {
3298 duration = -1;
3299 }
3300
3301 if (hwaddr_aton(cmd, addr))
3302 return -1;
3303
3304 return wpas_mesh_peer_add(wpa_s, addr, duration);
3305}
3306
Hai Shalom81f62d82019-07-22 12:10:00 -07003307
3308static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3309 struct wpa_supplicant *wpa_s, char *cmd)
3310{
3311 struct ether_header *eth;
3312 u8 addr[ETH_ALEN];
3313 u8 *buf;
3314 char *pos;
3315 size_t payload_len = 0, len;
3316 int ret = -1;
3317
3318 if (hwaddr_aton(cmd, addr))
3319 return -1;
3320
3321 pos = os_strstr(cmd, " payload=");
3322 if (pos) {
3323 pos = pos + 9;
3324 payload_len = os_strlen(pos);
3325 if (payload_len & 1)
3326 return -1;
3327
3328 payload_len /= 2;
3329 }
3330
3331 len = ETH_HLEN + payload_len;
3332 buf = os_malloc(len);
3333 if (!buf)
3334 return -1;
3335
3336 eth = (struct ether_header *) buf;
3337 os_memcpy(eth->ether_dhost, addr, ETH_ALEN);
3338 os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN);
3339 eth->ether_type = htons(ETH_P_802_3);
3340
3341 if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0)
3342 goto fail;
3343
3344 ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len);
3345fail:
3346 os_free(buf);
3347 return -ret;
3348}
3349
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003350#endif /* CONFIG_MESH */
3351
3352
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003353static int wpa_supplicant_ctrl_iface_select_network(
3354 struct wpa_supplicant *wpa_s, char *cmd)
3355{
3356 int id;
3357 struct wpa_ssid *ssid;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003358 char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003359
3360 /* cmd: "<network id>" or "any" */
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003361 if (os_strncmp(cmd, "any", 3) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003362 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3363 ssid = NULL;
3364 } else {
3365 id = atoi(cmd);
3366 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3367
3368 ssid = wpa_config_get_network(wpa_s->conf, id);
3369 if (ssid == NULL) {
3370 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3371 "network id=%d", id);
3372 return -1;
3373 }
3374 if (ssid->disabled == 2) {
3375 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3376 "SELECT_NETWORK with persistent P2P group");
3377 return -1;
3378 }
3379 }
3380
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003381 pos = os_strstr(cmd, " freq=");
3382 if (pos) {
3383 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3384 if (freqs) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003385 os_free(wpa_s->select_network_scan_freqs);
3386 wpa_s->select_network_scan_freqs = freqs;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003387 }
3388 }
3389
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003390 wpa_s->scan_min_time.sec = 0;
3391 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003392 wpa_supplicant_select_network(wpa_s, ssid);
3393
3394 return 0;
3395}
3396
3397
3398static int wpa_supplicant_ctrl_iface_enable_network(
3399 struct wpa_supplicant *wpa_s, char *cmd)
3400{
3401 int id;
3402 struct wpa_ssid *ssid;
3403
3404 /* cmd: "<network id>" or "all" */
3405 if (os_strcmp(cmd, "all") == 0) {
3406 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3407 ssid = NULL;
3408 } else {
3409 id = atoi(cmd);
3410 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3411
3412 ssid = wpa_config_get_network(wpa_s->conf, id);
3413 if (ssid == NULL) {
3414 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3415 "network id=%d", id);
3416 return -1;
3417 }
3418 if (ssid->disabled == 2) {
3419 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3420 "ENABLE_NETWORK with persistent P2P group");
3421 return -1;
3422 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003423
3424 if (os_strstr(cmd, " no-connect")) {
3425 ssid->disabled = 0;
3426 return 0;
3427 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003428 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003429 wpa_s->scan_min_time.sec = 0;
3430 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003431 wpa_supplicant_enable_network(wpa_s, ssid);
3432
3433 return 0;
3434}
3435
3436
3437static int wpa_supplicant_ctrl_iface_disable_network(
3438 struct wpa_supplicant *wpa_s, char *cmd)
3439{
3440 int id;
3441 struct wpa_ssid *ssid;
3442
3443 /* cmd: "<network id>" or "all" */
3444 if (os_strcmp(cmd, "all") == 0) {
3445 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3446 ssid = NULL;
3447 } else {
3448 id = atoi(cmd);
3449 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3450
3451 ssid = wpa_config_get_network(wpa_s->conf, id);
3452 if (ssid == NULL) {
3453 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3454 "network id=%d", id);
3455 return -1;
3456 }
3457 if (ssid->disabled == 2) {
3458 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3459 "DISABLE_NETWORK with persistent P2P "
3460 "group");
3461 return -1;
3462 }
3463 }
3464 wpa_supplicant_disable_network(wpa_s, ssid);
3465
3466 return 0;
3467}
3468
3469
3470static int wpa_supplicant_ctrl_iface_add_network(
3471 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3472{
3473 struct wpa_ssid *ssid;
3474 int ret;
3475
3476 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3477
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003478 ssid = wpa_supplicant_add_network(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003479 if (ssid == NULL)
3480 return -1;
3481
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003482 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003483 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003484 return -1;
3485 return ret;
3486}
3487
3488
3489static int wpa_supplicant_ctrl_iface_remove_network(
3490 struct wpa_supplicant *wpa_s, char *cmd)
3491{
3492 int id;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003493 int result;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003494
3495 /* cmd: "<network id>" or "all" */
3496 if (os_strcmp(cmd, "all") == 0) {
3497 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Hai Shalom899fcc72020-10-19 14:38:18 -07003498 return wpa_supplicant_remove_all_networks(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003499 }
3500
3501 id = atoi(cmd);
3502 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3503
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003504 result = wpa_supplicant_remove_network(wpa_s, id);
3505 if (result == -1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003506 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3507 "id=%d", id);
3508 return -1;
3509 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003510 if (result == -2) {
Deepthi Gowria831d782012-09-03 11:55:38 +03003511 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3512 "network id=%d", id);
3513 return -1;
3514 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003515 return 0;
3516}
3517
3518
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003519static int wpa_supplicant_ctrl_iface_update_network(
3520 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3521 char *name, char *value)
3522{
Dmitry Shmidte4663042016-04-04 10:07:49 -07003523 int ret;
3524
3525 ret = wpa_config_set(ssid, name, value, 0);
3526 if (ret < 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003527 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3528 "variable '%s'", name);
3529 return -1;
3530 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07003531 if (ret == 1)
3532 return 0; /* No change to the previously configured value */
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003533
Hai Shalom899fcc72020-10-19 14:38:18 -07003534#ifdef CONFIG_BGSCAN
3535 if (os_strcmp(name, "bgscan") == 0) {
3536 /*
3537 * Reset the bgscan parameters for the current network and
3538 * return. There's no need to flush caches for bgscan parameter
3539 * changes.
3540 */
3541 if (wpa_s->current_ssid == ssid &&
3542 wpa_s->wpa_state == WPA_COMPLETED)
3543 wpa_supplicant_reset_bgscan(wpa_s);
3544 return 0;
3545 }
3546#endif /* CONFIG_BGSCAN */
3547
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003548 if (os_strcmp(name, "bssid") != 0 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003549 os_strcmp(name, "bssid_hint") != 0 &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003550 os_strcmp(name, "priority") != 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003551 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3552
Dmitry Shmidte4663042016-04-04 10:07:49 -07003553 if (wpa_s->current_ssid == ssid ||
3554 wpa_s->current_ssid == NULL) {
3555 /*
3556 * Invalidate the EAP session cache if anything in the
3557 * current or previously used configuration changes.
3558 */
3559 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3560 }
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003561 }
3562
3563 if ((os_strcmp(name, "psk") == 0 &&
3564 value[0] == '"' && ssid->ssid_len) ||
3565 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3566 wpa_config_update_psk(ssid);
3567 else if (os_strcmp(name, "priority") == 0)
3568 wpa_config_update_prio_list(wpa_s->conf);
3569
3570 return 0;
3571}
3572
3573
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003574static int wpa_supplicant_ctrl_iface_set_network(
3575 struct wpa_supplicant *wpa_s, char *cmd)
3576{
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003577 int id, ret, prev_bssid_set, prev_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003578 struct wpa_ssid *ssid;
3579 char *name, *value;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003580 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003581
3582 /* cmd: "<network id> <variable name> <value>" */
3583 name = os_strchr(cmd, ' ');
3584 if (name == NULL)
3585 return -1;
3586 *name++ = '\0';
3587
3588 value = os_strchr(name, ' ');
3589 if (value == NULL)
3590 return -1;
3591 *value++ = '\0';
3592
3593 id = atoi(cmd);
3594 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3595 id, name);
3596 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3597 (u8 *) value, os_strlen(value));
3598
3599 ssid = wpa_config_get_network(wpa_s->conf, id);
3600 if (ssid == NULL) {
3601 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3602 "id=%d", id);
3603 return -1;
3604 }
3605
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003606 prev_bssid_set = ssid->bssid_set;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003607 prev_disabled = ssid->disabled;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003608 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3609 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3610 value);
3611 if (ret == 0 &&
3612 (ssid->bssid_set != prev_bssid_set ||
3613 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3614 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003615
3616 if (prev_disabled != ssid->disabled &&
3617 (prev_disabled == 2 || ssid->disabled == 2))
3618 wpas_notify_network_type_changed(wpa_s, ssid);
3619
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003620 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003621}
3622
3623
3624static int wpa_supplicant_ctrl_iface_get_network(
3625 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3626{
3627 int id;
3628 size_t res;
3629 struct wpa_ssid *ssid;
3630 char *name, *value;
3631
3632 /* cmd: "<network id> <variable name>" */
3633 name = os_strchr(cmd, ' ');
3634 if (name == NULL || buflen == 0)
3635 return -1;
3636 *name++ = '\0';
3637
3638 id = atoi(cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003639 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003640 id, name);
3641
3642 ssid = wpa_config_get_network(wpa_s->conf, id);
3643 if (ssid == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003644 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003645 "id=%d", id);
3646 return -1;
3647 }
3648
3649 value = wpa_config_get_no_key(ssid, name);
3650 if (value == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003651 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003652 "variable '%s'", name);
3653 return -1;
3654 }
3655
3656 res = os_strlcpy(buf, value, buflen);
3657 if (res >= buflen) {
3658 os_free(value);
3659 return -1;
3660 }
3661
3662 os_free(value);
3663
3664 return res;
3665}
3666
3667
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003668static int wpa_supplicant_ctrl_iface_dup_network(
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003669 struct wpa_supplicant *wpa_s, char *cmd,
3670 struct wpa_supplicant *dst_wpa_s)
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003671{
3672 struct wpa_ssid *ssid_s, *ssid_d;
3673 char *name, *id, *value;
3674 int id_s, id_d, ret;
3675
3676 /* cmd: "<src network id> <dst network id> <variable name>" */
3677 id = os_strchr(cmd, ' ');
3678 if (id == NULL)
3679 return -1;
3680 *id++ = '\0';
3681
3682 name = os_strchr(id, ' ');
3683 if (name == NULL)
3684 return -1;
3685 *name++ = '\0';
3686
3687 id_s = atoi(cmd);
3688 id_d = atoi(id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003689
3690 wpa_printf(MSG_DEBUG,
3691 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3692 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003693
3694 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3695 if (ssid_s == NULL) {
3696 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3697 "network id=%d", id_s);
3698 return -1;
3699 }
3700
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003701 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003702 if (ssid_d == NULL) {
3703 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003704 "network id=%d", id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003705 return -1;
3706 }
3707
3708 value = wpa_config_get(ssid_s, name);
3709 if (value == NULL) {
3710 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3711 "variable '%s'", name);
3712 return -1;
3713 }
3714
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003715 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003716 value);
3717
3718 os_free(value);
3719
3720 return ret;
3721}
3722
3723
Dmitry Shmidt04949592012-07-19 12:16:46 -07003724static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3725 char *buf, size_t buflen)
3726{
3727 char *pos, *end;
3728 struct wpa_cred *cred;
3729 int ret;
3730
3731 pos = buf;
3732 end = buf + buflen;
3733 ret = os_snprintf(pos, end - pos,
3734 "cred id / realm / username / domain / imsi\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003735 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003736 return pos - buf;
3737 pos += ret;
3738
3739 cred = wpa_s->conf->cred;
3740 while (cred) {
3741 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3742 cred->id, cred->realm ? cred->realm : "",
3743 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07003744 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003745 cred->imsi ? cred->imsi : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003746 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003747 return pos - buf;
3748 pos += ret;
3749
3750 cred = cred->next;
3751 }
3752
3753 return pos - buf;
3754}
3755
3756
3757static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3758 char *buf, size_t buflen)
3759{
3760 struct wpa_cred *cred;
3761 int ret;
3762
3763 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3764
3765 cred = wpa_config_add_cred(wpa_s->conf);
3766 if (cred == NULL)
3767 return -1;
3768
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003769 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3770
Dmitry Shmidt04949592012-07-19 12:16:46 -07003771 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003772 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003773 return -1;
3774 return ret;
3775}
3776
3777
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003778static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
3779 struct wpa_cred *cred)
3780{
3781 struct wpa_ssid *ssid;
3782 char str[20];
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003783 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003784
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003785 if (cred == NULL) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003786 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3787 return -1;
3788 }
3789
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003790 id = cred->id;
3791 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
3792 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3793 return -1;
3794 }
3795
3796 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
3797
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003798 /* Remove any network entry created based on the removed credential */
3799 ssid = wpa_s->conf->ssid;
3800 while (ssid) {
3801 if (ssid->parent_cred == cred) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003802 int res;
3803
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003804 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
3805 "used the removed credential", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003806 res = os_snprintf(str, sizeof(str), "%d", ssid->id);
3807 if (os_snprintf_error(sizeof(str), res))
3808 str[sizeof(str) - 1] = '\0';
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003809 ssid = ssid->next;
3810 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
3811 } else
3812 ssid = ssid->next;
3813 }
3814
3815 return 0;
3816}
3817
3818
Dmitry Shmidt04949592012-07-19 12:16:46 -07003819static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3820 char *cmd)
3821{
3822 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003823 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003824
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003825 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3826 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003827 if (os_strcmp(cmd, "all") == 0) {
3828 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3829 cred = wpa_s->conf->cred;
3830 while (cred) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003831 prev = cred;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003832 cred = cred->next;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003833 wpas_ctrl_remove_cred(wpa_s, prev);
3834 }
3835 return 0;
3836 }
3837
3838 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3839 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3840 cmd + 8);
3841 cred = wpa_s->conf->cred;
3842 while (cred) {
3843 prev = cred;
3844 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003845 if (prev->domain) {
3846 size_t i;
3847 for (i = 0; i < prev->num_domain; i++) {
3848 if (os_strcmp(prev->domain[i], cmd + 8)
3849 != 0)
3850 continue;
3851 wpas_ctrl_remove_cred(wpa_s, prev);
3852 break;
3853 }
3854 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003855 }
3856 return 0;
3857 }
3858
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003859 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3860 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3861 cmd + 16);
3862 cred = wpa_s->conf->cred;
3863 while (cred) {
3864 prev = cred;
3865 cred = cred->next;
3866 if (prev->provisioning_sp &&
3867 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3868 wpas_ctrl_remove_cred(wpa_s, prev);
3869 }
3870 return 0;
3871 }
3872
Dmitry Shmidt04949592012-07-19 12:16:46 -07003873 id = atoi(cmd);
3874 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3875
3876 cred = wpa_config_get_cred(wpa_s->conf, id);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003877 return wpas_ctrl_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003878}
3879
3880
3881static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3882 char *cmd)
3883{
3884 int id;
3885 struct wpa_cred *cred;
3886 char *name, *value;
3887
3888 /* cmd: "<cred id> <variable name> <value>" */
3889 name = os_strchr(cmd, ' ');
3890 if (name == NULL)
3891 return -1;
3892 *name++ = '\0';
3893
3894 value = os_strchr(name, ' ');
3895 if (value == NULL)
3896 return -1;
3897 *value++ = '\0';
3898
3899 id = atoi(cmd);
3900 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3901 id, name);
3902 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3903 (u8 *) value, os_strlen(value));
3904
3905 cred = wpa_config_get_cred(wpa_s->conf, id);
3906 if (cred == NULL) {
3907 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3908 id);
3909 return -1;
3910 }
3911
3912 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3913 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3914 "variable '%s'", name);
3915 return -1;
3916 }
3917
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003918 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3919
Dmitry Shmidt04949592012-07-19 12:16:46 -07003920 return 0;
3921}
3922
3923
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003924static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3925 char *cmd, char *buf,
3926 size_t buflen)
3927{
3928 int id;
3929 size_t res;
3930 struct wpa_cred *cred;
3931 char *name, *value;
3932
3933 /* cmd: "<cred id> <variable name>" */
3934 name = os_strchr(cmd, ' ');
3935 if (name == NULL)
3936 return -1;
3937 *name++ = '\0';
3938
3939 id = atoi(cmd);
3940 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3941 id, name);
3942
3943 cred = wpa_config_get_cred(wpa_s->conf, id);
3944 if (cred == NULL) {
3945 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3946 id);
3947 return -1;
3948 }
3949
3950 value = wpa_config_get_cred_no_key(cred, name);
3951 if (value == NULL) {
3952 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3953 name);
3954 return -1;
3955 }
3956
3957 res = os_strlcpy(buf, value, buflen);
3958 if (res >= buflen) {
3959 os_free(value);
3960 return -1;
3961 }
3962
3963 os_free(value);
3964
3965 return res;
3966}
3967
3968
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003969#ifndef CONFIG_NO_CONFIG_WRITE
3970static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3971{
3972 int ret;
3973
3974 if (!wpa_s->conf->update_config) {
3975 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3976 "to update configuration (update_config=0)");
3977 return -1;
3978 }
3979
3980 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3981 if (ret) {
3982 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3983 "update configuration");
3984 } else {
3985 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3986 " updated");
3987 }
3988
3989 return ret;
3990}
3991#endif /* CONFIG_NO_CONFIG_WRITE */
3992
3993
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003994struct cipher_info {
3995 unsigned int capa;
3996 const char *name;
3997 int group_only;
3998};
3999
4000static const struct cipher_info ciphers[] = {
4001 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
4002 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
4003 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
4004 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07004005#ifndef CONFIG_NO_TKIP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004006 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07004007#endif /* CONFIG_NO_TKIP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004008 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
Hai Shalomfdcde762020-04-02 11:19:20 -07004009#ifdef CONFIG_WEP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004010 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
4011 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004012#endif /* CONFIG_WEP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004013};
4014
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004015static const struct cipher_info ciphers_group_mgmt[] = {
4016 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
4017 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
4018 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
4019 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
4020};
4021
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004022
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004023static int ctrl_iface_get_capability_pairwise(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004024 struct wpa_driver_capa *capa,
4025 char *buf, size_t buflen)
4026{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004027 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004028 char *pos, *end;
4029 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004030 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004031
4032 pos = buf;
4033 end = pos + buflen;
4034
4035 if (res < 0) {
4036 if (strict)
4037 return 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07004038#ifdef CONFIG_NO_TKIP
4039 len = os_strlcpy(buf, "CCMP NONE", buflen);
4040#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004041 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004042#endif /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004043 if (len >= buflen)
4044 return -1;
4045 return len;
4046 }
4047
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004048 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4049 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
4050 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004051 pos == buf ? "" : " ",
4052 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004053 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004054 return pos - buf;
4055 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004056 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004057 }
4058
4059 return pos - buf;
4060}
4061
4062
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004063static int ctrl_iface_get_capability_group(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004064 struct wpa_driver_capa *capa,
4065 char *buf, size_t buflen)
4066{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004067 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004068 char *pos, *end;
4069 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004070 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004071
4072 pos = buf;
4073 end = pos + buflen;
4074
4075 if (res < 0) {
4076 if (strict)
4077 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07004078#ifdef CONFIG_WEP
Hai Shalomb755a2a2020-04-23 21:49:02 -07004079#ifdef CONFIG_NO_TKIP
4080 len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen);
4081#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004082 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004083#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004084#else /* CONFIG_WEP */
Hai Shalomb755a2a2020-04-23 21:49:02 -07004085#ifdef CONFIG_NO_TKIP
4086 len = os_strlcpy(buf, "CCMP", buflen);
4087#else /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004088 len = os_strlcpy(buf, "CCMP TKIP", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004089#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004090#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004091 if (len >= buflen)
4092 return -1;
4093 return len;
4094 }
4095
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004096 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4097 if (capa->enc & ciphers[i].capa) {
4098 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004099 pos == buf ? "" : " ",
4100 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004101 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004102 return pos - buf;
4103 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004104 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004105 }
4106
4107 return pos - buf;
4108}
4109
4110
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004111static int ctrl_iface_get_capability_group_mgmt(int res, bool strict,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004112 struct wpa_driver_capa *capa,
4113 char *buf, size_t buflen)
4114{
4115 int ret;
4116 char *pos, *end;
4117 unsigned int i;
4118
4119 pos = buf;
4120 end = pos + buflen;
4121
4122 if (res < 0)
4123 return 0;
4124
4125 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
4126 if (capa->enc & ciphers_group_mgmt[i].capa) {
4127 ret = os_snprintf(pos, end - pos, "%s%s",
4128 pos == buf ? "" : " ",
4129 ciphers_group_mgmt[i].name);
4130 if (os_snprintf_error(end - pos, ret))
4131 return pos - buf;
4132 pos += ret;
4133 }
4134 }
4135
4136 return pos - buf;
4137}
4138
4139
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004140static int iftype_str_to_index(const char *iftype_str)
4141{
4142 if (!iftype_str)
4143 return WPA_IF_MAX;
4144
4145 if (os_strcmp(iftype_str, "STATION") == 0)
4146 return WPA_IF_STATION;
4147
4148 if (os_strcmp(iftype_str, "AP_VLAN") == 0)
4149 return WPA_IF_AP_VLAN;
4150
4151 if (os_strcmp(iftype_str, "AP") == 0)
4152 return WPA_IF_AP_BSS;
4153
4154 if (os_strcmp(iftype_str, "P2P_GO") == 0)
4155 return WPA_IF_P2P_GO;
4156
4157 if (os_strcmp(iftype_str, "P2P_CLIENT") == 0)
4158 return WPA_IF_P2P_CLIENT;
4159
4160 if (os_strcmp(iftype_str, "P2P_DEVICE") == 0)
4161 return WPA_IF_P2P_DEVICE;
4162
4163 if (os_strcmp(iftype_str, "MESH") == 0)
4164 return WPA_IF_MESH;
4165
4166 if (os_strcmp(iftype_str, "IBSS") == 0)
4167 return WPA_IF_IBSS;
4168
4169 if (os_strcmp(iftype_str, "NAN") == 0)
4170 return WPA_IF_NAN;
4171
4172 return WPA_IF_MAX;
4173}
4174
4175
4176static int ctrl_iface_get_capability_key_mgmt(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004177 struct wpa_driver_capa *capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004178 const char *iftype_str,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004179 char *buf, size_t buflen)
4180{
4181 int ret;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004182 unsigned int key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004183 char *pos, *end;
4184 size_t len;
4185
4186 pos = buf;
4187 end = pos + buflen;
4188
4189 if (res < 0) {
4190 if (strict)
4191 return 0;
4192 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4193 "NONE", buflen);
4194 if (len >= buflen)
4195 return -1;
4196 return len;
4197 }
4198
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004199 if (iftype_str) {
4200 enum wpa_driver_if_type iftype;
4201
4202 iftype = iftype_str_to_index(iftype_str);
4203 if (iftype == WPA_IF_MAX)
4204 return -1;
4205 key_mgmt = capa->key_mgmt_iftype[iftype];
4206 } else {
4207 key_mgmt = capa->key_mgmt;
4208 }
4209
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004210 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004211 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004212 return pos - buf;
4213 pos += ret;
4214
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004215 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4216 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004217 ret = os_snprintf(pos, end - pos, " WPA-EAP");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004218 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004219 return pos - buf;
4220 pos += ret;
4221 }
4222
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004223 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
4224 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004225 ret = os_snprintf(pos, end - pos, " WPA-PSK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004226 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004227 return pos - buf;
4228 pos += ret;
4229 }
4230
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004231 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004232 ret = os_snprintf(pos, end - pos, " WPA-NONE");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004233 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004234 return pos - buf;
4235 pos += ret;
4236 }
4237
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304238 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WAPI_PSK) {
4239 ret = os_snprintf(pos, end - pos, " WAPI-PSK");
4240 if (os_snprintf_error(end - pos, ret))
4241 return pos - buf;
4242 pos += ret;
4243 }
4244
4245 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE) {
4246 ret = os_snprintf(pos, end - pos, " TPK-HANDSHAKE");
4247 if (os_snprintf_error(end - pos, ret))
4248 return pos - buf;
4249 pos += ret;
4250 }
4251
4252 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_CCKM) {
4253 ret = os_snprintf(pos, end - pos, " CCKM");
4254 if (os_snprintf_error(end - pos, ret))
4255 return pos - buf;
4256 pos += ret;
4257 }
4258
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004259#ifdef CONFIG_SUITEB
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004260 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004261 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
4262 if (os_snprintf_error(end - pos, ret))
4263 return pos - buf;
4264 pos += ret;
4265 }
4266#endif /* CONFIG_SUITEB */
4267#ifdef CONFIG_SUITEB192
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004268 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004269 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
4270 if (os_snprintf_error(end - pos, ret))
4271 return pos - buf;
4272 pos += ret;
4273 }
4274#endif /* CONFIG_SUITEB192 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004275#ifdef CONFIG_OWE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004276 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004277 ret = os_snprintf(pos, end - pos, " OWE");
4278 if (os_snprintf_error(end - pos, ret))
4279 return pos - buf;
4280 pos += ret;
4281 }
4282#endif /* CONFIG_OWE */
4283#ifdef CONFIG_DPP
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004284 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004285 ret = os_snprintf(pos, end - pos, " DPP");
4286 if (os_snprintf_error(end - pos, ret))
4287 return pos - buf;
4288 pos += ret;
4289 }
4290#endif /* CONFIG_DPP */
4291#ifdef CONFIG_FILS
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004292 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004293 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
4294 if (os_snprintf_error(end - pos, ret))
4295 return pos - buf;
4296 pos += ret;
4297 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004298 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004299 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
4300 if (os_snprintf_error(end - pos, ret))
4301 return pos - buf;
4302 pos += ret;
4303 }
4304#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004305 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004306 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
4307 if (os_snprintf_error(end - pos, ret))
4308 return pos - buf;
4309 pos += ret;
4310 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004311 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004312 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
4313 if (os_snprintf_error(end - pos, ret))
4314 return pos - buf;
4315 pos += ret;
4316 }
4317#endif /* CONFIG_IEEE80211R */
4318#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08004319#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004320 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004321 ret = os_snprintf(pos, end - pos, " FT-PSK");
4322 if (os_snprintf_error(end - pos, ret))
4323 return pos - buf;
4324 pos += ret;
4325 }
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304326 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) {
4327 ret = os_snprintf(pos, end - pos, " FT-EAP");
4328 if (os_snprintf_error(end - pos, ret))
4329 return pos - buf;
4330 pos += ret;
4331 }
4332#ifdef CONFIG_SAE
4333 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE) {
4334 ret = os_snprintf(pos, end - pos, " FT-SAE");
4335 if (os_snprintf_error(end - pos, ret))
4336 return pos - buf;
4337 pos += ret;
4338 }
4339#endif /* CONFIG_SAE */
4340#ifdef CONFIG_SHA384
4341 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384) {
4342 ret = os_snprintf(pos, end - pos, " FT-EAP-SHA384");
4343 if (os_snprintf_error(end - pos, ret))
4344 return pos - buf;
4345 pos += ret;
4346 }
4347#endif /* CONFIG_SHA384 */
Hai Shalom74f70d42019-02-11 14:42:39 -08004348#endif /* CONFIG_IEEE80211R */
4349#ifdef CONFIG_SAE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004350 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004351 ret = os_snprintf(pos, end - pos, " SAE");
4352 if (os_snprintf_error(end - pos, ret))
4353 return pos - buf;
4354 pos += ret;
4355 }
4356#endif /* CONFIG_SAE */
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304357#ifdef CONFIG_SHA256
4358 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256) {
4359 ret = os_snprintf(pos, end - pos, " WPA-EAP-SHA256");
4360 if (os_snprintf_error(end - pos, ret))
4361 return pos - buf;
4362 pos += ret;
4363 }
4364
4365 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256) {
4366 ret = os_snprintf(pos, end - pos, " WPA-PSK-SHA256");
4367 if (os_snprintf_error(end - pos, ret))
4368 return pos - buf;
4369 pos += ret;
4370 }
4371#endif /* CONFIG_SHA256 */
4372#ifdef CONFIG_HS20
4373 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OSEN) {
4374 ret = os_snprintf(pos, end - pos, " OSEN");
4375 if (os_snprintf_error(end - pos, ret))
4376 return pos - buf;
4377 pos += ret;
4378 }
4379#endif /* CONFIG_HS20 */
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004380
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004381 return pos - buf;
4382}
4383
4384
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004385static int ctrl_iface_get_capability_proto(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004386 struct wpa_driver_capa *capa,
4387 char *buf, size_t buflen)
4388{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004389 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004390 char *pos, *end;
4391 size_t len;
4392
4393 pos = buf;
4394 end = pos + buflen;
4395
4396 if (res < 0) {
4397 if (strict)
4398 return 0;
4399 len = os_strlcpy(buf, "RSN WPA", buflen);
4400 if (len >= buflen)
4401 return -1;
4402 return len;
4403 }
4404
4405 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4406 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004407 ret = os_snprintf(pos, end - pos, "%sRSN",
4408 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004409 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004410 return pos - buf;
4411 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004412 }
4413
4414 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4415 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004416 ret = os_snprintf(pos, end - pos, "%sWPA",
4417 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004418 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004419 return pos - buf;
4420 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004421 }
4422
4423 return pos - buf;
4424}
4425
4426
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004427static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004428 int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004429 struct wpa_driver_capa *capa,
4430 char *buf, size_t buflen)
4431{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004432 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004433 char *pos, *end;
4434 size_t len;
4435
4436 pos = buf;
4437 end = pos + buflen;
4438
4439 if (res < 0) {
4440 if (strict)
4441 return 0;
4442 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4443 if (len >= buflen)
4444 return -1;
4445 return len;
4446 }
4447
4448 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004449 ret = os_snprintf(pos, end - pos, "%sOPEN",
4450 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004451 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004452 return pos - buf;
4453 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004454 }
4455
4456 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4457 ret = os_snprintf(pos, end - pos, "%sSHARED",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004458 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004459 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004460 return pos - buf;
4461 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004462 }
4463
4464 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004465 ret = os_snprintf(pos, end - pos, "%sLEAP",
4466 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004467 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004468 return pos - buf;
4469 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004470 }
4471
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004472#ifdef CONFIG_SAE
4473 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4474 ret = os_snprintf(pos, end - pos, "%sSAE",
4475 pos == buf ? "" : " ");
4476 if (os_snprintf_error(end - pos, ret))
4477 return pos - buf;
4478 pos += ret;
4479 }
4480#endif /* CONFIG_SAE */
4481
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004482#ifdef CONFIG_FILS
4483 if (wpa_is_fils_supported(wpa_s)) {
4484 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4485 pos == buf ? "" : " ");
4486 if (os_snprintf_error(end - pos, ret))
4487 return pos - buf;
4488 pos += ret;
4489 }
4490
4491#ifdef CONFIG_FILS_SK_PFS
4492 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4493 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4494 pos == buf ? "" : " ");
4495 if (os_snprintf_error(end - pos, ret))
4496 return pos - buf;
4497 pos += ret;
4498 }
4499#endif /* CONFIG_FILS_SK_PFS */
4500#endif /* CONFIG_FILS */
4501
Hai Shalom60840252021-02-19 19:02:11 -08004502#ifdef CONFIG_PASN
4503 ret = os_snprintf(pos, end - pos, "%sPASN",
4504 pos == buf ? "" : " ");
4505 if (os_snprintf_error(end - pos, ret))
4506 return pos - buf;
4507 pos += ret;
4508
4509#endif /* CONFIG_PASN */
4510
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004511 return pos - buf;
4512}
4513
4514
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004515static int ctrl_iface_get_capability_modes(int res, bool strict,
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004516 struct wpa_driver_capa *capa,
4517 char *buf, size_t buflen)
4518{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004519 int ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004520 char *pos, *end;
4521 size_t len;
4522
4523 pos = buf;
4524 end = pos + buflen;
4525
4526 if (res < 0) {
4527 if (strict)
4528 return 0;
4529 len = os_strlcpy(buf, "IBSS AP", buflen);
4530 if (len >= buflen)
4531 return -1;
4532 return len;
4533 }
4534
4535 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004536 ret = os_snprintf(pos, end - pos, "%sIBSS",
4537 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004538 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004539 return pos - buf;
4540 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004541 }
4542
4543 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004544 ret = os_snprintf(pos, end - pos, "%sAP",
4545 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004546 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004547 return pos - buf;
4548 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004549 }
4550
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004551#ifdef CONFIG_MESH
4552 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4553 ret = os_snprintf(pos, end - pos, "%sMESH",
4554 pos == buf ? "" : " ");
4555 if (os_snprintf_error(end - pos, ret))
4556 return pos - buf;
4557 pos += ret;
4558 }
4559#endif /* CONFIG_MESH */
4560
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004561 return pos - buf;
4562}
4563
4564
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004565static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4566 char *buf, size_t buflen)
4567{
4568 struct hostapd_channel_data *chnl;
4569 int ret, i, j;
4570 char *pos, *end, *hmode;
4571
4572 pos = buf;
4573 end = pos + buflen;
4574
4575 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4576 switch (wpa_s->hw.modes[j].mode) {
4577 case HOSTAPD_MODE_IEEE80211B:
4578 hmode = "B";
4579 break;
4580 case HOSTAPD_MODE_IEEE80211G:
4581 hmode = "G";
4582 break;
4583 case HOSTAPD_MODE_IEEE80211A:
4584 hmode = "A";
4585 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004586 case HOSTAPD_MODE_IEEE80211AD:
4587 hmode = "AD";
4588 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004589 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004590 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004591 }
4592 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004593 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004594 return pos - buf;
4595 pos += ret;
4596 chnl = wpa_s->hw.modes[j].channels;
4597 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004598 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4599 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004600 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004601 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004602 return pos - buf;
4603 pos += ret;
4604 }
4605 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004606 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004607 return pos - buf;
4608 pos += ret;
4609 }
4610
4611 return pos - buf;
4612}
4613
4614
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004615static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4616 char *buf, size_t buflen)
4617{
4618 struct hostapd_channel_data *chnl;
4619 int ret, i, j;
4620 char *pos, *end, *hmode;
4621
4622 pos = buf;
4623 end = pos + buflen;
4624
4625 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4626 switch (wpa_s->hw.modes[j].mode) {
4627 case HOSTAPD_MODE_IEEE80211B:
4628 hmode = "B";
4629 break;
4630 case HOSTAPD_MODE_IEEE80211G:
4631 hmode = "G";
4632 break;
4633 case HOSTAPD_MODE_IEEE80211A:
4634 hmode = "A";
4635 break;
4636 case HOSTAPD_MODE_IEEE80211AD:
4637 hmode = "AD";
4638 break;
4639 default:
4640 continue;
4641 }
4642 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4643 hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004644 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004645 return pos - buf;
4646 pos += ret;
4647 chnl = wpa_s->hw.modes[j].channels;
4648 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4649 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4650 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004651 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004652 chnl[i].chan, chnl[i].freq,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004653 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4654 " (NO_IR)" : "",
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004655 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4656 " (DFS)" : "");
4657
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004658 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004659 return pos - buf;
4660 pos += ret;
4661 }
4662 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004663 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004664 return pos - buf;
4665 pos += ret;
4666 }
4667
4668 return pos - buf;
4669}
4670
4671
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004672static int wpa_supplicant_ctrl_iface_get_capability(
4673 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4674 size_t buflen)
4675{
4676 struct wpa_driver_capa capa;
4677 int res;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004678 char *next_param, *curr_param, *iftype = NULL;
4679 bool strict = false;
4680 char field[50];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004681 size_t len;
4682
4683 /* Determine whether or not strict checking was requested */
4684 len = os_strlcpy(field, _field, sizeof(field));
4685 if (len >= sizeof(field))
4686 return -1;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004687
4688 next_param = os_strchr(field, ' ');
4689 while (next_param) {
4690 *next_param++ = '\0';
4691 curr_param = next_param;
4692 next_param = os_strchr(next_param, ' ');
4693
4694 if (next_param)
4695 *next_param = '\0';
4696
4697 if (os_strcmp(curr_param, "strict") == 0)
4698 strict = true;
4699 else if (os_strncmp(curr_param, "iftype=", 7) == 0)
4700 iftype = curr_param + 7;
4701 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004702 return -1;
4703 }
4704
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004705 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'%s%s%s",
4706 field, iftype ? " iftype=" : "", iftype ? iftype : "",
4707 strict ? " strict" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004708
4709 if (os_strcmp(field, "eap") == 0) {
4710 return eap_get_names(buf, buflen);
4711 }
4712
4713 res = wpa_drv_get_capa(wpa_s, &capa);
4714
4715 if (os_strcmp(field, "pairwise") == 0)
4716 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4717 buf, buflen);
4718
4719 if (os_strcmp(field, "group") == 0)
4720 return ctrl_iface_get_capability_group(res, strict, &capa,
4721 buf, buflen);
4722
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004723 if (os_strcmp(field, "group_mgmt") == 0)
4724 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4725 buf, buflen);
4726
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004727 if (os_strcmp(field, "key_mgmt") == 0)
4728 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004729 iftype, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004730
4731 if (os_strcmp(field, "proto") == 0)
4732 return ctrl_iface_get_capability_proto(res, strict, &capa,
4733 buf, buflen);
4734
4735 if (os_strcmp(field, "auth_alg") == 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004736 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4737 &capa, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004738
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004739 if (os_strcmp(field, "modes") == 0)
4740 return ctrl_iface_get_capability_modes(res, strict, &capa,
4741 buf, buflen);
4742
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004743 if (os_strcmp(field, "channels") == 0)
4744 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4745
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004746 if (os_strcmp(field, "freq") == 0)
4747 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4748
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004749#ifdef CONFIG_TDLS
4750 if (os_strcmp(field, "tdls") == 0)
4751 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4752#endif /* CONFIG_TDLS */
4753
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004754#ifdef CONFIG_ERP
4755 if (os_strcmp(field, "erp") == 0) {
4756 res = os_snprintf(buf, buflen, "ERP");
4757 if (os_snprintf_error(buflen, res))
4758 return -1;
4759 return res;
4760 }
4761#endif /* CONFIG_EPR */
4762
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004763#ifdef CONFIG_FIPS
4764 if (os_strcmp(field, "fips") == 0) {
4765 res = os_snprintf(buf, buflen, "FIPS");
4766 if (os_snprintf_error(buflen, res))
4767 return -1;
4768 return res;
4769 }
4770#endif /* CONFIG_FIPS */
4771
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004772#ifdef CONFIG_ACS
4773 if (os_strcmp(field, "acs") == 0) {
4774 res = os_snprintf(buf, buflen, "ACS");
4775 if (os_snprintf_error(buflen, res))
4776 return -1;
4777 return res;
4778 }
4779#endif /* CONFIG_ACS */
4780
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004781#ifdef CONFIG_FILS
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004782 if (os_strcmp(field, "fils") == 0) {
4783#ifdef CONFIG_FILS_SK_PFS
4784 if (wpa_is_fils_supported(wpa_s) &&
4785 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4786 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4787 if (os_snprintf_error(buflen, res))
4788 return -1;
4789 return res;
4790 }
4791#endif /* CONFIG_FILS_SK_PFS */
4792
4793 if (wpa_is_fils_supported(wpa_s)) {
4794 res = os_snprintf(buf, buflen, "FILS");
4795 if (os_snprintf_error(buflen, res))
4796 return -1;
4797 return res;
4798 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004799 }
4800#endif /* CONFIG_FILS */
4801
Hai Shalom74f70d42019-02-11 14:42:39 -08004802 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
4803 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
4804 if (os_snprintf_error(buflen, res))
4805 return -1;
4806 return res;
4807 }
4808
Hai Shalom021b0b52019-04-10 11:17:58 -07004809#ifdef CONFIG_DPP
4810 if (os_strcmp(field, "dpp") == 0) {
4811#ifdef CONFIG_DPP2
4812 res = os_snprintf(buf, buflen, "DPP=2");
4813#else /* CONFIG_DPP2 */
4814 res = os_snprintf(buf, buflen, "DPP=1");
4815#endif /* CONFIG_DPP2 */
4816 if (os_snprintf_error(buflen, res))
4817 return -1;
4818 return res;
4819 }
4820#endif /* CONFIG_DPP */
4821
Hai Shalom899fcc72020-10-19 14:38:18 -07004822#ifdef CONFIG_SAE
4823 if (os_strcmp(field, "sae") == 0 &&
4824 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4825#ifdef CONFIG_SAE_PK
4826 res = os_snprintf(buf, buflen, "H2E PK");
4827#else /* CONFIG_SAE_PK */
4828 res = os_snprintf(buf, buflen, "H2E");
4829#endif /* CONFIG_SAE_PK */
4830 if (os_snprintf_error(buflen, res))
4831 return -1;
4832 return res;
4833 }
4834#endif /* CONFIG_SAE */
4835
Hai Shalom60840252021-02-19 19:02:11 -08004836#ifdef CONFIG_OCV
4837 if (os_strcmp(field, "ocv") == 0) {
4838 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) ||
4839 (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV))
4840 res = os_snprintf(buf, buflen, "supported");
4841 else
4842 res = os_snprintf(buf, buflen, "not supported");
4843 if (os_snprintf_error(buflen, res))
4844 return -1;
4845 return res;
4846 }
4847#endif /* CONFIG_OCV */
4848
4849 if (os_strcmp(field, "beacon_prot") == 0) {
4850 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_BEACON_PROTECTION) ||
4851 (wpa_s->drv_flags2 &
4852 WPA_DRIVER_FLAGS2_BEACON_PROTECTION_CLIENT))
4853 res = os_snprintf(buf, buflen, "supported");
4854 else
4855 res = os_snprintf(buf, buflen, "not supported");
4856 if (os_snprintf_error(buflen, res))
4857 return -1;
4858 return res;
4859 }
4860
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004861 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4862 field);
4863
4864 return -1;
4865}
4866
4867
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004868#ifdef CONFIG_INTERWORKING
4869static char * anqp_add_hex(char *pos, char *end, const char *title,
4870 struct wpabuf *data)
4871{
4872 char *start = pos;
4873 size_t i;
4874 int ret;
4875 const u8 *d;
4876
4877 if (data == NULL)
4878 return start;
4879
4880 ret = os_snprintf(pos, end - pos, "%s=", title);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004881 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004882 return start;
4883 pos += ret;
4884
4885 d = wpabuf_head_u8(data);
4886 for (i = 0; i < wpabuf_len(data); i++) {
4887 ret = os_snprintf(pos, end - pos, "%02x", *d++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004888 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004889 return start;
4890 pos += ret;
4891 }
4892
4893 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004894 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004895 return start;
4896 pos += ret;
4897
4898 return pos;
4899}
4900#endif /* CONFIG_INTERWORKING */
4901
4902
Dmitry Shmidt29333592017-01-09 12:27:11 -08004903#ifdef CONFIG_FILS
4904static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4905{
4906 char *start = pos;
4907 const u8 *ie, *ie_end;
4908 u16 info, realms;
4909 int ret;
4910
4911 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4912 if (!ie)
4913 return 0;
4914 ie_end = ie + 2 + ie[1];
4915 ie += 2;
4916 if (ie_end - ie < 2)
4917 return -1;
4918
4919 info = WPA_GET_LE16(ie);
4920 ie += 2;
4921 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4922 if (os_snprintf_error(end - pos, ret))
4923 return 0;
4924 pos += ret;
4925
4926 if (info & BIT(7)) {
4927 /* Cache Identifier Included */
4928 if (ie_end - ie < 2)
4929 return -1;
4930 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4931 ie[0], ie[1]);
4932 if (os_snprintf_error(end - pos, ret))
4933 return 0;
4934 pos += ret;
4935 ie += 2;
4936 }
4937
4938 if (info & BIT(8)) {
4939 /* HESSID Included */
4940 if (ie_end - ie < ETH_ALEN)
4941 return -1;
4942 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4943 MAC2STR(ie));
4944 if (os_snprintf_error(end - pos, ret))
4945 return 0;
4946 pos += ret;
4947 ie += ETH_ALEN;
4948 }
4949
4950 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4951 if (realms) {
4952 if (ie_end - ie < realms * 2)
4953 return -1;
4954 ret = os_snprintf(pos, end - pos, "fils_realms=");
4955 if (os_snprintf_error(end - pos, ret))
4956 return 0;
4957 pos += ret;
4958
4959 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
4960 if (ret <= 0)
4961 return 0;
4962 pos += ret;
4963 ie += realms * 2;
4964 ret = os_snprintf(pos, end - pos, "\n");
4965 if (os_snprintf_error(end - pos, ret))
4966 return 0;
4967 pos += ret;
4968 }
4969
4970 return pos - start;
4971}
4972#endif /* CONFIG_FILS */
4973
4974
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004975static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
4976 unsigned long mask, char *buf, size_t buflen)
4977{
4978 size_t i;
4979 int ret;
4980 char *pos, *end;
Hai Shalom899fcc72020-10-19 14:38:18 -07004981 const u8 *ie, *ie2, *osen_ie, *mesh, *owe, *rsnxe;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004982
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004983 pos = buf;
4984 end = buf + buflen;
4985
4986 if (mask & WPA_BSS_MASK_ID) {
4987 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004988 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004989 return 0;
4990 pos += ret;
4991 }
4992
4993 if (mask & WPA_BSS_MASK_BSSID) {
4994 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
4995 MAC2STR(bss->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004996 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004997 return 0;
4998 pos += ret;
4999 }
5000
5001 if (mask & WPA_BSS_MASK_FREQ) {
5002 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005003 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005004 return 0;
5005 pos += ret;
5006 }
5007
5008 if (mask & WPA_BSS_MASK_BEACON_INT) {
5009 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
5010 bss->beacon_int);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005011 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005012 return 0;
5013 pos += ret;
5014 }
5015
5016 if (mask & WPA_BSS_MASK_CAPABILITIES) {
5017 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
5018 bss->caps);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005019 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005020 return 0;
5021 pos += ret;
5022 }
5023
5024 if (mask & WPA_BSS_MASK_QUAL) {
5025 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005026 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005027 return 0;
5028 pos += ret;
5029 }
5030
5031 if (mask & WPA_BSS_MASK_NOISE) {
5032 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005033 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005034 return 0;
5035 pos += ret;
5036 }
5037
5038 if (mask & WPA_BSS_MASK_LEVEL) {
5039 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005040 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005041 return 0;
5042 pos += ret;
5043 }
5044
5045 if (mask & WPA_BSS_MASK_TSF) {
5046 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
5047 (unsigned long long) bss->tsf);
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 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005054 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005055
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005056 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005057 ret = os_snprintf(pos, end - pos, "age=%d\n",
5058 (int) (now.sec - bss->last_update.sec));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005059 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005060 return 0;
5061 pos += ret;
5062 }
5063
5064 if (mask & WPA_BSS_MASK_IE) {
5065 ret = os_snprintf(pos, end - pos, "ie=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005066 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005067 return 0;
5068 pos += ret;
5069
Hai Shalom60840252021-02-19 19:02:11 -08005070 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005071 for (i = 0; i < bss->ie_len; i++) {
5072 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005073 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005074 return 0;
5075 pos += ret;
5076 }
5077
5078 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005079 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005080 return 0;
5081 pos += ret;
5082 }
5083
5084 if (mask & WPA_BSS_MASK_FLAGS) {
5085 ret = os_snprintf(pos, end - pos, "flags=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005086 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005087 return 0;
5088 pos += ret;
5089
Dmitry Shmidt29333592017-01-09 12:27:11 -08005090 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
5091
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005092 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
5093 if (ie)
5094 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
5095 2 + ie[1]);
5096 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
5097 if (ie2)
Dmitry Shmidt29333592017-01-09 12:27:11 -08005098 pos = wpa_supplicant_ie_txt(pos, end,
5099 mesh ? "RSN" : "WPA2", ie2,
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005100 2 + ie2[1]);
Hai Shalom899fcc72020-10-19 14:38:18 -07005101 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
5102 if (rsnxe && rsnxe[1] >= 1) {
5103 if (rsnxe[2] & BIT(WLAN_RSNX_CAPAB_SAE_H2E)) {
5104 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
5105 if (os_snprintf_error(end - pos, ret))
5106 return -1;
5107 pos += ret;
5108 }
5109 if (rsnxe[2] & BIT(WLAN_RSNX_CAPAB_SAE_PK)) {
5110 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
5111 if (os_snprintf_error(end - pos, ret))
5112 return -1;
5113 pos += ret;
5114 }
5115 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005116 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
5117 if (osen_ie)
5118 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
5119 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005120 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
5121 if (owe) {
5122 ret = os_snprintf(
5123 pos, end - pos,
5124 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
5125 if (os_snprintf_error(end - pos, ret))
5126 return 0;
5127 pos += ret;
5128 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005129 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005130 if (!ie && !ie2 && !osen_ie &&
5131 (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005132 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005133 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005134 return 0;
5135 pos += ret;
5136 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005137
5138 if (mesh) {
5139 ret = os_snprintf(pos, end - pos, "[MESH]");
5140 if (os_snprintf_error(end - pos, ret))
5141 return 0;
5142 pos += ret;
5143 }
5144
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005145 if (bss_is_dmg(bss)) {
5146 const char *s;
5147 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005148 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005149 return 0;
5150 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005151 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
5152 case IEEE80211_CAP_DMG_IBSS:
5153 s = "[IBSS]";
5154 break;
5155 case IEEE80211_CAP_DMG_AP:
5156 s = "[ESS]";
5157 break;
5158 case IEEE80211_CAP_DMG_PBSS:
5159 s = "[PBSS]";
5160 break;
5161 default:
5162 s = "";
5163 break;
5164 }
5165 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005166 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005167 return 0;
5168 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005169 } else {
5170 if (bss->caps & IEEE80211_CAP_IBSS) {
5171 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005172 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005173 return 0;
5174 pos += ret;
5175 }
5176 if (bss->caps & IEEE80211_CAP_ESS) {
5177 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005178 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005179 return 0;
5180 pos += ret;
5181 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005182 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07005183 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
5184 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005185 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005186 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005187 return 0;
5188 pos += ret;
5189 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005190#ifdef CONFIG_HS20
5191 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
5192 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005193 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005194 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005195 pos += ret;
5196 }
5197#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005198#ifdef CONFIG_FILS
5199 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
5200 ret = os_snprintf(pos, end - pos, "[FILS]");
5201 if (os_snprintf_error(end - pos, ret))
5202 return 0;
5203 pos += ret;
5204 }
5205#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08005206#ifdef CONFIG_FST
5207 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
5208 ret = os_snprintf(pos, end - pos, "[FST]");
5209 if (os_snprintf_error(end - pos, ret))
5210 return 0;
5211 pos += ret;
5212 }
5213#endif /* CONFIG_FST */
5214 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
5215 ret = os_snprintf(pos, end - pos, "[UTF-8]");
5216 if (os_snprintf_error(end - pos, ret))
5217 return 0;
5218 pos += ret;
5219 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005220
5221 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005222 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005223 return 0;
5224 pos += ret;
5225 }
5226
5227 if (mask & WPA_BSS_MASK_SSID) {
5228 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
5229 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005230 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005231 return 0;
5232 pos += ret;
5233 }
5234
5235#ifdef CONFIG_WPS
5236 if (mask & WPA_BSS_MASK_WPS_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005237 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005238 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005239 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005240 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005241 if (ret > 0)
5242 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005243 }
5244#endif /* CONFIG_WPS */
5245
5246#ifdef CONFIG_P2P
5247 if (mask & WPA_BSS_MASK_P2P_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005248 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005249 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005250 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005251 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005252 if (ret > 0)
5253 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005254 }
5255#endif /* CONFIG_P2P */
5256
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005257#ifdef CONFIG_WIFI_DISPLAY
5258 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
5259 struct wpabuf *wfd;
Hai Shalom60840252021-02-19 19:02:11 -08005260
5261 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005262 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
5263 WFD_IE_VENDOR_TYPE);
5264 if (wfd) {
5265 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005266 if (os_snprintf_error(end - pos, ret)) {
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005267 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005268 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005269 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005270 pos += ret;
5271
5272 pos += wpa_snprintf_hex(pos, end - pos,
5273 wpabuf_head(wfd),
5274 wpabuf_len(wfd));
5275 wpabuf_free(wfd);
5276
5277 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005278 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005279 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005280 pos += ret;
5281 }
5282 }
5283#endif /* CONFIG_WIFI_DISPLAY */
5284
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005285#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005286 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
5287 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005288 struct wpa_bss_anqp_elem *elem;
5289
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005290 pos = anqp_add_hex(pos, end, "anqp_capability_list",
5291 anqp->capability_list);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005292 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005293 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005294 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005295 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005296 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005297 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005298 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005299 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005300 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005301 anqp->nai_realm);
5302 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005303 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005304 anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005305 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
5306 anqp->fils_realm_info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005307#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005308 pos = anqp_add_hex(pos, end, "hs20_capability_list",
5309 anqp->hs20_capability_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005310 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005311 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005312 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005313 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005314 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005315 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005316 pos = anqp_add_hex(pos, end, "hs20_operating_class",
5317 anqp->hs20_operating_class);
5318 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
5319 anqp->hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005320 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
5321 anqp->hs20_operator_icon_metadata);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005322 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
5323 anqp->hs20_osu_providers_nai_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005324#endif /* CONFIG_HS20 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005325
5326 dl_list_for_each(elem, &anqp->anqp_elems,
5327 struct wpa_bss_anqp_elem, list) {
5328 char title[20];
5329
5330 os_snprintf(title, sizeof(title), "anqp[%u]",
5331 elem->infoid);
5332 pos = anqp_add_hex(pos, end, title, elem->payload);
Hai Shalom60840252021-02-19 19:02:11 -08005333 if (elem->protected_response) {
5334 ret = os_snprintf(pos, end - pos,
5335 "protected-anqp-info[%u]=1\n",
5336 elem->infoid);
5337 if (os_snprintf_error(end - pos, ret))
5338 return 0;
5339 pos += ret;
5340 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005341 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005342 }
5343#endif /* CONFIG_INTERWORKING */
5344
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005345#ifdef CONFIG_MESH
5346 if (mask & WPA_BSS_MASK_MESH_SCAN) {
Hai Shalom60840252021-02-19 19:02:11 -08005347 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005348 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005349 if (ret >= end - pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005350 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005351 if (ret > 0)
5352 pos += ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005353 }
5354#endif /* CONFIG_MESH */
5355
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005356 if (mask & WPA_BSS_MASK_SNR) {
5357 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
5358 if (os_snprintf_error(end - pos, ret))
5359 return 0;
5360 pos += ret;
5361 }
5362
5363 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
5364 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
5365 bss->est_throughput);
5366 if (os_snprintf_error(end - pos, ret))
5367 return 0;
5368 pos += ret;
5369 }
5370
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005371#ifdef CONFIG_FST
5372 if (mask & WPA_BSS_MASK_FST) {
5373 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
5374 if (ret < 0 || ret >= end - pos)
5375 return 0;
5376 pos += ret;
5377 }
5378#endif /* CONFIG_FST */
5379
Dmitry Shmidt29333592017-01-09 12:27:11 -08005380 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
5381 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
5382 bss->last_update_idx);
5383 if (os_snprintf_error(end - pos, ret))
5384 return 0;
5385 pos += ret;
5386 }
5387
5388 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
5389 ret = os_snprintf(pos, end - pos, "beacon_ie=");
5390 if (os_snprintf_error(end - pos, ret))
5391 return 0;
5392 pos += ret;
5393
Hai Shalom60840252021-02-19 19:02:11 -08005394 ie = wpa_bss_ie_ptr(bss);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005395 ie += bss->ie_len;
5396 for (i = 0; i < bss->beacon_ie_len; i++) {
5397 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
5398 if (os_snprintf_error(end - pos, ret))
5399 return 0;
5400 pos += ret;
5401 }
5402
5403 ret = os_snprintf(pos, end - pos, "\n");
5404 if (os_snprintf_error(end - pos, ret))
5405 return 0;
5406 pos += ret;
5407 }
5408
5409#ifdef CONFIG_FILS
5410 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
5411 ret = print_fils_indication(bss, pos, end);
5412 if (ret < 0)
5413 return 0;
5414 pos += ret;
5415 }
5416#endif /* CONFIG_FILS */
5417
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005418 if (mask & WPA_BSS_MASK_DELIM) {
5419 ret = os_snprintf(pos, end - pos, "====\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005420 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005421 return 0;
5422 pos += ret;
5423 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07005424
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005425 return pos - buf;
5426}
5427
Dmitry Shmidt04949592012-07-19 12:16:46 -07005428
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005429static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
5430 const char *cmd, char *buf,
5431 size_t buflen)
5432{
5433 u8 bssid[ETH_ALEN];
5434 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005435 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005436 struct wpa_bss *bsslast = NULL;
5437 struct dl_list *next;
5438 int ret = 0;
5439 int len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005440 char *ctmp, *end = buf + buflen;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005441 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005442
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005443 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
5444 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
5445 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005446 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005447 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
5448 list_id);
5449 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005450 unsigned int id1, id2;
5451
5452 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
5453 wpa_printf(MSG_INFO, "Wrong BSS range "
5454 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005455 return 0;
5456 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005457
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005458 if (*(cmd + 6) == '-')
5459 id1 = 0;
5460 else
5461 id1 = atoi(cmd + 6);
5462 ctmp++;
5463 if (*ctmp >= '0' && *ctmp <= '9')
5464 id2 = atoi(ctmp);
5465 else
5466 id2 = (unsigned int) -1;
5467 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
5468 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005469 bsslast = dl_list_last(&wpa_s->bss_id,
5470 struct wpa_bss,
5471 list_id);
5472 else {
5473 bsslast = wpa_bss_get_id(wpa_s, id2);
5474 if (bsslast == NULL && bss && id2 > id1) {
5475 struct wpa_bss *tmp = bss;
5476 for (;;) {
5477 next = tmp->list_id.next;
5478 if (next == &wpa_s->bss_id)
5479 break;
5480 tmp = dl_list_entry(
5481 next, struct wpa_bss,
5482 list_id);
5483 if (tmp->id > id2)
5484 break;
5485 bsslast = tmp;
5486 }
5487 }
5488 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005489 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005490 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005491 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005492 else if (os_strncmp(cmd, "LAST", 4) == 0)
5493 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005494 else if (os_strncmp(cmd, "ID-", 3) == 0) {
5495 i = atoi(cmd + 3);
5496 bss = wpa_bss_get_id(wpa_s, i);
5497 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5498 i = atoi(cmd + 5);
5499 bss = wpa_bss_get_id(wpa_s, i);
5500 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005501 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005502 if (next == &wpa_s->bss_id)
5503 bss = NULL;
5504 else
5505 bss = dl_list_entry(next, struct wpa_bss,
5506 list_id);
5507 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005508 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5509 bss = wpa_s->current_bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005510#ifdef CONFIG_P2P
5511 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5512 if (hwaddr_aton(cmd + 13, bssid) == 0)
5513 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5514 else
5515 bss = NULL;
5516#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005517 } else if (hwaddr_aton(cmd, bssid) == 0)
5518 bss = wpa_bss_get_bssid(wpa_s, bssid);
5519 else {
5520 struct wpa_bss *tmp;
5521 i = atoi(cmd);
5522 bss = NULL;
5523 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5524 {
Hai Shalom021b0b52019-04-10 11:17:58 -07005525 if (i == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005526 bss = tmp;
5527 break;
5528 }
Hai Shalom021b0b52019-04-10 11:17:58 -07005529 i--;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005530 }
5531 }
5532
Dmitry Shmidt04949592012-07-19 12:16:46 -07005533 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5534 mask = strtoul(ctmp + 5, NULL, 0x10);
5535 if (mask == 0)
5536 mask = WPA_BSS_MASK_ALL;
5537 }
5538
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005539 if (bss == NULL)
5540 return 0;
5541
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005542 if (bsslast == NULL)
5543 bsslast = bss;
5544 do {
5545 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5546 ret += len;
5547 buf += len;
5548 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005549 if (bss == bsslast) {
5550 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5551 (bss == dl_list_last(&wpa_s->bss_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005552 struct wpa_bss, list_id))) {
5553 int res;
5554
5555 res = os_snprintf(buf - 5, end - buf + 5,
5556 "####\n");
5557 if (os_snprintf_error(end - buf + 5, res)) {
5558 wpa_printf(MSG_DEBUG,
5559 "Could not add end delim");
5560 }
5561 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005562 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005563 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005564 next = bss->list_id.next;
5565 if (next == &wpa_s->bss_id)
5566 break;
5567 bss = dl_list_entry(next, struct wpa_bss, list_id);
5568 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005569
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005570 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005571}
5572
5573
5574static int wpa_supplicant_ctrl_iface_ap_scan(
5575 struct wpa_supplicant *wpa_s, char *cmd)
5576{
5577 int ap_scan = atoi(cmd);
5578 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5579}
5580
5581
5582static int wpa_supplicant_ctrl_iface_scan_interval(
5583 struct wpa_supplicant *wpa_s, char *cmd)
5584{
5585 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005586 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005587}
5588
5589
5590static int wpa_supplicant_ctrl_iface_bss_expire_age(
5591 struct wpa_supplicant *wpa_s, char *cmd)
5592{
5593 int expire_age = atoi(cmd);
5594 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5595}
5596
5597
5598static int wpa_supplicant_ctrl_iface_bss_expire_count(
5599 struct wpa_supplicant *wpa_s, char *cmd)
5600{
5601 int expire_count = atoi(cmd);
5602 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5603}
5604
5605
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005606static void wpa_supplicant_ctrl_iface_bss_flush(
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005607 struct wpa_supplicant *wpa_s, char *cmd)
5608{
5609 int flush_age = atoi(cmd);
5610
5611 if (flush_age == 0)
5612 wpa_bss_flush(wpa_s);
5613 else
5614 wpa_bss_flush_by_age(wpa_s, flush_age);
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005615}
5616
5617
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005618#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005619static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5620{
5621 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5622 /* MLME-DELETEKEYS.request */
Hai Shalomfdcde762020-04-02 11:19:20 -07005623 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL,
5624 0, KEY_FLAG_GROUP);
5625 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL,
5626 0, KEY_FLAG_GROUP);
5627 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL,
5628 0, KEY_FLAG_GROUP);
5629 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL,
5630 0, KEY_FLAG_GROUP);
5631 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL,
5632 0, KEY_FLAG_GROUP);
5633 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL,
5634 0, KEY_FLAG_GROUP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005635
5636 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005637 0, KEY_FLAG_PAIRWISE);
5638 if (wpa_sm_ext_key_id(wpa_s->wpa))
5639 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 1, 0,
5640 NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005641 /* MLME-SETPROTECTION.request(None) */
5642 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5643 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5644 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5645 wpa_sm_drop_sa(wpa_s->wpa);
5646}
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005647#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005648
5649
5650static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5651 char *addr)
5652{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005653#ifdef CONFIG_NO_SCAN_PROCESSING
5654 return -1;
5655#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005656 u8 bssid[ETH_ALEN];
5657 struct wpa_bss *bss;
5658 struct wpa_ssid *ssid = wpa_s->current_ssid;
5659
5660 if (hwaddr_aton(addr, bssid)) {
5661 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5662 "address '%s'", addr);
5663 return -1;
5664 }
5665
5666 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5667
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005668 if (!ssid) {
5669 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5670 "configuration known for the target AP");
5671 return -1;
5672 }
5673
5674 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005675 if (!bss) {
5676 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
5677 "from BSS table");
5678 return -1;
5679 }
5680
5681 /*
5682 * TODO: Find best network configuration block from configuration to
5683 * allow roaming to other networks
5684 */
5685
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005686 wpa_s->reassociate = 1;
5687 wpa_supplicant_connect(wpa_s, bss, ssid);
5688
5689 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005690#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005691}
5692
5693
5694#ifdef CONFIG_P2P
5695static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
5696{
5697 unsigned int timeout = atoi(cmd);
5698 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005699 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005700 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005701 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005702 unsigned int search_delay;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005703 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005704 u8 seek_count = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005705 int freq = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005706
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005707 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5708 wpa_dbg(wpa_s, MSG_INFO,
5709 "Reject P2P_FIND since interface is disabled");
5710 return -1;
5711 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005712 if (os_strstr(cmd, "type=social"))
5713 type = P2P_FIND_ONLY_SOCIAL;
5714 else if (os_strstr(cmd, "type=progressive"))
5715 type = P2P_FIND_PROGRESSIVE;
5716
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005717 pos = os_strstr(cmd, "dev_id=");
5718 if (pos) {
5719 pos += 7;
5720 if (hwaddr_aton(pos, dev_id))
5721 return -1;
5722 _dev_id = dev_id;
5723 }
5724
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005725 pos = os_strstr(cmd, "dev_type=");
5726 if (pos) {
5727 pos += 9;
5728 if (wps_dev_type_str2bin(pos, dev_type) < 0)
5729 return -1;
5730 _dev_type = dev_type;
5731 }
5732
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005733 pos = os_strstr(cmd, "delay=");
5734 if (pos) {
5735 pos += 6;
5736 search_delay = atoi(pos);
5737 } else
5738 search_delay = wpas_p2p_search_delay(wpa_s);
5739
Dmitry Shmidt41712582015-06-29 11:02:15 -07005740 pos = os_strstr(cmd, "freq=");
5741 if (pos) {
5742 pos += 5;
5743 freq = atoi(pos);
5744 if (freq <= 0)
5745 return -1;
5746 }
5747
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005748 /* Must be searched for last, because it adds nul termination */
5749 pos = os_strstr(cmd, " seek=");
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005750 if (pos)
5751 pos += 6;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005752 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
5753 char *term;
5754
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005755 _seek[seek_count++] = pos;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005756 seek = _seek;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005757 term = os_strchr(pos, ' ');
5758 if (!term)
5759 break;
5760 *term = '\0';
5761 pos = os_strstr(term + 1, "seek=");
5762 if (pos)
5763 pos += 5;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005764 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005765 if (seek_count > P2P_MAX_QUERY_HASH) {
5766 seek[0] = NULL;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005767 seek_count = 1;
5768 }
5769
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005770 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005771 _dev_id, search_delay, seek_count, seek, freq);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005772}
5773
5774
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005775static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
5776{
5777 const char *last = NULL;
5778 const char *token;
5779 long int token_len;
5780 unsigned int i;
5781
5782 /* Expected predefined CPT names delimited by ':' */
5783 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
5784 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
5785 wpa_printf(MSG_ERROR,
5786 "P2PS: CPT name list is too long, expected up to %d names",
5787 P2PS_FEATURE_CAPAB_CPT_MAX);
5788 cpt[0] = 0;
5789 return -1;
5790 }
5791
5792 token_len = last - token;
5793
5794 if (token_len == 3 &&
5795 os_memcmp(token, "UDP", token_len) == 0) {
5796 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5797 } else if (token_len == 3 &&
5798 os_memcmp(token, "MAC", token_len) == 0) {
5799 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
5800 } else {
5801 wpa_printf(MSG_ERROR,
5802 "P2PS: Unsupported CPT name '%s'", token);
5803 cpt[0] = 0;
5804 return -1;
5805 }
5806
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005807 if (isblank((unsigned char) *last)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005808 i++;
5809 break;
5810 }
5811 }
5812 cpt[i] = 0;
5813 return 0;
5814}
5815
5816
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005817static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
5818{
5819 struct p2ps_provision *p2ps_prov;
5820 char *pos;
5821 size_t info_len = 0;
5822 char *info = NULL;
5823 u8 role = P2PS_SETUP_NONE;
5824 long long unsigned val;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005825 int i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005826
5827 pos = os_strstr(cmd, "info=");
5828 if (pos) {
5829 pos += 5;
5830 info_len = os_strlen(pos);
5831
5832 if (info_len) {
5833 info = os_malloc(info_len + 1);
5834 if (info) {
5835 info_len = utf8_unescape(pos, info_len,
5836 info, info_len + 1);
5837 } else
5838 info_len = 0;
5839 }
5840 }
5841
5842 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
5843 if (p2ps_prov == NULL) {
5844 os_free(info);
5845 return NULL;
5846 }
5847
5848 if (info) {
5849 os_memcpy(p2ps_prov->info, info, info_len);
5850 p2ps_prov->info[info_len] = '\0';
5851 os_free(info);
5852 }
5853
5854 pos = os_strstr(cmd, "status=");
5855 if (pos)
5856 p2ps_prov->status = atoi(pos + 7);
5857 else
5858 p2ps_prov->status = -1;
5859
5860 pos = os_strstr(cmd, "adv_id=");
5861 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
5862 goto invalid_args;
5863 p2ps_prov->adv_id = val;
5864
5865 pos = os_strstr(cmd, "method=");
5866 if (pos)
5867 p2ps_prov->method = strtol(pos + 7, NULL, 16);
5868 else
5869 p2ps_prov->method = 0;
5870
5871 pos = os_strstr(cmd, "session=");
5872 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
5873 goto invalid_args;
5874 p2ps_prov->session_id = val;
5875
5876 pos = os_strstr(cmd, "adv_mac=");
5877 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
5878 goto invalid_args;
5879
5880 pos = os_strstr(cmd, "session_mac=");
5881 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
5882 goto invalid_args;
5883
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005884 pos = os_strstr(cmd, "cpt=");
5885 if (pos) {
5886 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
5887 p2ps_prov->cpt_priority))
5888 goto invalid_args;
5889 } else {
5890 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5891 }
5892
5893 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
5894 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
5895
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005896 /* force conncap with tstCap (no sanity checks) */
5897 pos = os_strstr(cmd, "tstCap=");
5898 if (pos) {
5899 role = strtol(pos + 7, NULL, 16);
5900 } else {
5901 pos = os_strstr(cmd, "role=");
5902 if (pos) {
5903 role = strtol(pos + 5, NULL, 16);
5904 if (role != P2PS_SETUP_CLIENT &&
5905 role != P2PS_SETUP_GROUP_OWNER)
5906 role = P2PS_SETUP_NONE;
5907 }
5908 }
5909 p2ps_prov->role = role;
5910
5911 return p2ps_prov;
5912
5913invalid_args:
5914 os_free(p2ps_prov);
5915 return NULL;
5916}
5917
5918
5919static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
5920{
5921 u8 addr[ETH_ALEN];
5922 struct p2ps_provision *p2ps_prov;
5923 char *pos;
5924
5925 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5926
5927 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5928
5929 if (hwaddr_aton(cmd, addr))
5930 return -1;
5931
5932 pos = cmd + 17;
5933 if (*pos != ' ')
5934 return -1;
5935
5936 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5937 if (!p2ps_prov)
5938 return -1;
5939
5940 if (p2ps_prov->status < 0) {
5941 os_free(p2ps_prov);
5942 return -1;
5943 }
5944
5945 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5946 p2ps_prov);
5947}
5948
5949
5950static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
5951{
5952 u8 addr[ETH_ALEN];
5953 struct p2ps_provision *p2ps_prov;
5954 char *pos;
5955
5956 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5957 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5958 */
5959
5960 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5961 if (hwaddr_aton(cmd, addr))
5962 return -1;
5963
5964 pos = cmd + 17;
5965 if (*pos != ' ')
5966 return -1;
5967
5968 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5969 if (!p2ps_prov)
5970 return -1;
5971
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005972 p2ps_prov->pd_seeker = 1;
5973
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005974 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5975 p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005976}
5977
5978
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005979static int parse_freq(int chwidth, int freq2)
5980{
5981 if (freq2 < 0)
5982 return -1;
5983 if (freq2)
Hai Shalom81f62d82019-07-22 12:10:00 -07005984 return CHANWIDTH_80P80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005985
5986 switch (chwidth) {
5987 case 0:
5988 case 20:
5989 case 40:
Hai Shalom81f62d82019-07-22 12:10:00 -07005990 return CHANWIDTH_USE_HT;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005991 case 80:
Hai Shalom81f62d82019-07-22 12:10:00 -07005992 return CHANWIDTH_80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005993 case 160:
Hai Shalom81f62d82019-07-22 12:10:00 -07005994 return CHANWIDTH_160MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005995 default:
5996 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
5997 chwidth);
5998 return -1;
5999 }
6000}
6001
6002
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006003static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
6004 char *buf, size_t buflen)
6005{
6006 u8 addr[ETH_ALEN];
6007 char *pos, *pos2;
6008 char *pin = NULL;
6009 enum p2p_wps_method wps_method;
6010 int new_pin;
6011 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006012 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006013 int join;
6014 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006015 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006016 int go_intent = -1;
6017 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006018 int pd;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006019 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006020 int edmg;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006021 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
6022 size_t group_ssid_len = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08006023 int he;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006024
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08006025 if (!wpa_s->global->p2p_init_wpa_s)
6026 return -1;
6027 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
6028 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
6029 wpa_s->global->p2p_init_wpa_s->ifname);
6030 wpa_s = wpa_s->global->p2p_init_wpa_s;
6031 }
6032
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006033 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
Dmitry Shmidt04949592012-07-19 12:16:46 -07006034 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006035 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006036 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006037
6038 if (hwaddr_aton(cmd, addr))
6039 return -1;
6040
6041 pos = cmd + 17;
6042 if (*pos != ' ')
6043 return -1;
6044 pos++;
6045
6046 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006047 pos2 = os_strstr(pos, " persistent=");
6048 if (pos2) {
6049 struct wpa_ssid *ssid;
6050 persistent_id = atoi(pos2 + 12);
6051 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
6052 if (ssid == NULL || ssid->disabled != 2 ||
6053 ssid->mode != WPAS_MODE_P2P_GO) {
6054 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
6055 "SSID id=%d for persistent P2P group (GO)",
6056 persistent_id);
6057 return -1;
6058 }
6059 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006060 join = os_strstr(pos, " join") != NULL;
6061 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006062 automatic = os_strstr(pos, " auto") != NULL;
6063 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006064 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6065 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6066 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006067 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006068 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006069
6070 pos2 = os_strstr(pos, " go_intent=");
6071 if (pos2) {
6072 pos2 += 11;
6073 go_intent = atoi(pos2);
6074 if (go_intent < 0 || go_intent > 15)
6075 return -1;
6076 }
6077
6078 pos2 = os_strstr(pos, " freq=");
6079 if (pos2) {
6080 pos2 += 6;
6081 freq = atoi(pos2);
6082 if (freq <= 0)
6083 return -1;
6084 }
6085
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006086 pos2 = os_strstr(pos, " freq2=");
6087 if (pos2)
6088 freq2 = atoi(pos2 + 7);
6089
6090 pos2 = os_strstr(pos, " max_oper_chwidth=");
6091 if (pos2)
6092 chwidth = atoi(pos2 + 18);
6093
6094 max_oper_chwidth = parse_freq(chwidth, freq2);
6095 if (max_oper_chwidth < 0)
6096 return -1;
6097
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006098 pos2 = os_strstr(pos, " ssid=");
6099 if (pos2) {
6100 char *end;
6101
6102 pos2 += 6;
6103 end = os_strchr(pos2, ' ');
6104 if (!end)
6105 group_ssid_len = os_strlen(pos2) / 2;
6106 else
6107 group_ssid_len = (end - pos2) / 2;
6108 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
6109 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
6110 return -1;
6111 group_ssid = _group_ssid;
6112 }
6113
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006114 if (os_strncmp(pos, "pin", 3) == 0) {
6115 /* Request random PIN (to be displayed) and enable the PIN */
6116 wps_method = WPS_PIN_DISPLAY;
6117 } else if (os_strncmp(pos, "pbc", 3) == 0) {
6118 wps_method = WPS_PBC;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006119 } else if (os_strstr(pos, "p2ps") != NULL) {
6120 wps_method = WPS_P2PS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006121 } else {
6122 pin = pos;
6123 pos = os_strchr(pin, ' ');
6124 wps_method = WPS_PIN_KEYPAD;
6125 if (pos) {
6126 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006127 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006128 wps_method = WPS_PIN_DISPLAY;
6129 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006130 if (!wps_pin_str_valid(pin)) {
6131 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
6132 return 17;
6133 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006134 }
6135
6136 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006137 persistent_group, automatic, join,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006138 auth, go_intent, freq, freq2, persistent_id,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006139 pd, ht40, vht, max_oper_chwidth, he, edmg,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006140 group_ssid, group_ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006141 if (new_pin == -2) {
6142 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
6143 return 25;
6144 }
6145 if (new_pin == -3) {
6146 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
6147 return 25;
6148 }
6149 if (new_pin < 0)
6150 return -1;
6151 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
6152 ret = os_snprintf(buf, buflen, "%08d", new_pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006153 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006154 return -1;
6155 return ret;
6156 }
6157
6158 os_memcpy(buf, "OK\n", 3);
6159 return 3;
6160}
6161
6162
6163static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
6164{
6165 unsigned int timeout = atoi(cmd);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006166 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6167 wpa_dbg(wpa_s, MSG_INFO,
6168 "Reject P2P_LISTEN since interface is disabled");
6169 return -1;
6170 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006171 return wpas_p2p_listen(wpa_s, timeout);
6172}
6173
6174
6175static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
6176{
6177 u8 addr[ETH_ALEN];
6178 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006179 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006180
Dmitry Shmidt04949592012-07-19 12:16:46 -07006181 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006182
6183 if (hwaddr_aton(cmd, addr))
6184 return -1;
6185
6186 pos = cmd + 17;
6187 if (*pos != ' ')
6188 return -1;
6189 pos++;
6190
Dmitry Shmidt04949592012-07-19 12:16:46 -07006191 if (os_strstr(pos, " join") != NULL)
6192 use = WPAS_P2P_PD_FOR_JOIN;
6193 else if (os_strstr(pos, " auto") != NULL)
6194 use = WPAS_P2P_PD_AUTO;
6195
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006196 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006197}
6198
6199
6200static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
6201 size_t buflen)
6202{
6203 struct wpa_ssid *ssid = wpa_s->current_ssid;
6204
6205 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
6206 ssid->passphrase == NULL)
6207 return -1;
6208
6209 os_strlcpy(buf, ssid->passphrase, buflen);
6210 return os_strlen(buf);
6211}
6212
6213
6214static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
6215 char *buf, size_t buflen)
6216{
6217 u64 ref;
6218 int res;
6219 u8 dst_buf[ETH_ALEN], *dst;
6220 struct wpabuf *tlvs;
6221 char *pos;
6222 size_t len;
6223
6224 if (hwaddr_aton(cmd, dst_buf))
6225 return -1;
6226 dst = dst_buf;
6227 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
6228 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
6229 dst = NULL;
6230 pos = cmd + 17;
6231 if (*pos != ' ')
6232 return -1;
6233 pos++;
6234
6235 if (os_strncmp(pos, "upnp ", 5) == 0) {
6236 u8 version;
6237 pos += 5;
6238 if (hexstr2bin(pos, &version, 1) < 0)
6239 return -1;
6240 pos += 2;
6241 if (*pos != ' ')
6242 return -1;
6243 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006244 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006245#ifdef CONFIG_WIFI_DISPLAY
6246 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
6247 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
6248#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006249 } else if (os_strncmp(pos, "asp ", 4) == 0) {
6250 char *svc_str;
6251 char *svc_info = NULL;
6252 u32 id;
6253
6254 pos += 4;
6255 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
6256 return -1;
6257
6258 pos = os_strchr(pos, ' ');
6259 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
6260 return -1;
6261
6262 svc_str = pos + 1;
6263
6264 pos = os_strchr(svc_str, ' ');
6265
6266 if (pos)
6267 *pos++ = '\0';
6268
6269 /* All remaining data is the svc_info string */
6270 if (pos && pos[0] && pos[0] != ' ') {
6271 len = os_strlen(pos);
6272
6273 /* Unescape in place */
6274 len = utf8_unescape(pos, len, pos, len);
6275 if (len > 0xff)
6276 return -1;
6277
6278 svc_info = pos;
6279 }
6280
6281 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
6282 svc_str, svc_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006283 } else {
6284 len = os_strlen(pos);
6285 if (len & 1)
6286 return -1;
6287 len /= 2;
6288 tlvs = wpabuf_alloc(len);
6289 if (tlvs == NULL)
6290 return -1;
6291 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
6292 wpabuf_free(tlvs);
6293 return -1;
6294 }
6295
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006296 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006297 wpabuf_free(tlvs);
6298 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006299 if (ref == 0)
6300 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006301 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006302 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006303 return -1;
6304 return res;
6305}
6306
6307
6308static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
6309 char *cmd)
6310{
6311 long long unsigned val;
6312 u64 req;
6313 if (sscanf(cmd, "%llx", &val) != 1)
6314 return -1;
6315 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006316 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006317}
6318
6319
6320static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
6321{
6322 int freq;
6323 u8 dst[ETH_ALEN];
6324 u8 dialog_token;
6325 struct wpabuf *resp_tlvs;
6326 char *pos, *pos2;
6327 size_t len;
6328
6329 pos = os_strchr(cmd, ' ');
6330 if (pos == NULL)
6331 return -1;
6332 *pos++ = '\0';
6333 freq = atoi(cmd);
6334 if (freq == 0)
6335 return -1;
6336
6337 if (hwaddr_aton(pos, dst))
6338 return -1;
6339 pos += 17;
6340 if (*pos != ' ')
6341 return -1;
6342 pos++;
6343
6344 pos2 = os_strchr(pos, ' ');
6345 if (pos2 == NULL)
6346 return -1;
6347 *pos2++ = '\0';
6348 dialog_token = atoi(pos);
6349
6350 len = os_strlen(pos2);
6351 if (len & 1)
6352 return -1;
6353 len /= 2;
6354 resp_tlvs = wpabuf_alloc(len);
6355 if (resp_tlvs == NULL)
6356 return -1;
6357 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
6358 wpabuf_free(resp_tlvs);
6359 return -1;
6360 }
6361
6362 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
6363 wpabuf_free(resp_tlvs);
6364 return 0;
6365}
6366
6367
6368static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
6369 char *cmd)
6370{
Dmitry Shmidt04949592012-07-19 12:16:46 -07006371 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
6372 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006373 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
6374 return 0;
6375}
6376
6377
6378static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
6379 char *cmd)
6380{
6381 char *pos;
6382 size_t len;
6383 struct wpabuf *query, *resp;
6384
6385 pos = os_strchr(cmd, ' ');
6386 if (pos == NULL)
6387 return -1;
6388 *pos++ = '\0';
6389
6390 len = os_strlen(cmd);
6391 if (len & 1)
6392 return -1;
6393 len /= 2;
6394 query = wpabuf_alloc(len);
6395 if (query == NULL)
6396 return -1;
6397 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6398 wpabuf_free(query);
6399 return -1;
6400 }
6401
6402 len = os_strlen(pos);
6403 if (len & 1) {
6404 wpabuf_free(query);
6405 return -1;
6406 }
6407 len /= 2;
6408 resp = wpabuf_alloc(len);
6409 if (resp == NULL) {
6410 wpabuf_free(query);
6411 return -1;
6412 }
6413 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
6414 wpabuf_free(query);
6415 wpabuf_free(resp);
6416 return -1;
6417 }
6418
6419 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
6420 wpabuf_free(query);
6421 wpabuf_free(resp);
6422 return -1;
6423 }
6424 return 0;
6425}
6426
6427
6428static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6429{
6430 char *pos;
6431 u8 version;
6432
6433 pos = os_strchr(cmd, ' ');
6434 if (pos == NULL)
6435 return -1;
6436 *pos++ = '\0';
6437
6438 if (hexstr2bin(cmd, &version, 1) < 0)
6439 return -1;
6440
6441 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
6442}
6443
6444
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006445static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
6446 u8 replace, char *cmd)
6447{
6448 char *pos;
6449 char *adv_str;
6450 u32 auto_accept, adv_id, svc_state, config_methods;
6451 char *svc_info = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006452 char *cpt_prio_str;
6453 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006454
6455 pos = os_strchr(cmd, ' ');
6456 if (pos == NULL)
6457 return -1;
6458 *pos++ = '\0';
6459
6460 /* Auto-Accept value is mandatory, and must be one of the
6461 * single values (0, 1, 2, 4) */
6462 auto_accept = atoi(cmd);
6463 switch (auto_accept) {
6464 case P2PS_SETUP_NONE: /* No auto-accept */
6465 case P2PS_SETUP_NEW:
6466 case P2PS_SETUP_CLIENT:
6467 case P2PS_SETUP_GROUP_OWNER:
6468 break;
6469 default:
6470 return -1;
6471 }
6472
6473 /* Advertisement ID is mandatory */
6474 cmd = pos;
6475 pos = os_strchr(cmd, ' ');
6476 if (pos == NULL)
6477 return -1;
6478 *pos++ = '\0';
6479
6480 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6481 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
6482 return -1;
6483
6484 /* Only allow replacements if exist, and adds if not */
6485 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
6486 if (!replace)
6487 return -1;
6488 } else {
6489 if (replace)
6490 return -1;
6491 }
6492
6493 /* svc_state between 0 - 0xff is mandatory */
6494 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
6495 return -1;
6496
6497 pos = os_strchr(pos, ' ');
6498 if (pos == NULL)
6499 return -1;
6500
6501 /* config_methods is mandatory */
6502 pos++;
6503 if (sscanf(pos, "%x", &config_methods) != 1)
6504 return -1;
6505
6506 if (!(config_methods &
6507 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
6508 return -1;
6509
6510 pos = os_strchr(pos, ' ');
6511 if (pos == NULL)
6512 return -1;
6513
6514 pos++;
6515 adv_str = pos;
6516
6517 /* Advertisement string is mandatory */
6518 if (!pos[0] || pos[0] == ' ')
6519 return -1;
6520
6521 /* Terminate svc string */
6522 pos = os_strchr(pos, ' ');
6523 if (pos != NULL)
6524 *pos++ = '\0';
6525
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006526 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6527 if (cpt_prio_str) {
6528 pos = os_strchr(pos, ' ');
6529 if (pos != NULL)
6530 *pos++ = '\0';
6531
6532 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6533 return -1;
6534 } else {
6535 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6536 cpt_prio[1] = 0;
6537 }
6538
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006539 /* Service and Response Information are optional */
6540 if (pos && pos[0]) {
6541 size_t len;
6542
6543 /* Note the bare ' included, which cannot exist legally
6544 * in unescaped string. */
6545 svc_info = os_strstr(pos, "svc_info='");
6546
6547 if (svc_info) {
6548 svc_info += 9;
6549 len = os_strlen(svc_info);
6550 utf8_unescape(svc_info, len, svc_info, len);
6551 }
6552 }
6553
6554 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6555 (u8) svc_state, (u16) config_methods,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006556 svc_info, cpt_prio);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006557}
6558
6559
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006560static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6561{
6562 char *pos;
6563
6564 pos = os_strchr(cmd, ' ');
6565 if (pos == NULL)
6566 return -1;
6567 *pos++ = '\0';
6568
6569 if (os_strcmp(cmd, "bonjour") == 0)
6570 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6571 if (os_strcmp(cmd, "upnp") == 0)
6572 return p2p_ctrl_service_add_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006573 if (os_strcmp(cmd, "asp") == 0)
6574 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006575 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6576 return -1;
6577}
6578
6579
6580static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6581 char *cmd)
6582{
6583 size_t len;
6584 struct wpabuf *query;
6585 int ret;
6586
6587 len = os_strlen(cmd);
6588 if (len & 1)
6589 return -1;
6590 len /= 2;
6591 query = wpabuf_alloc(len);
6592 if (query == NULL)
6593 return -1;
6594 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6595 wpabuf_free(query);
6596 return -1;
6597 }
6598
6599 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6600 wpabuf_free(query);
6601 return ret;
6602}
6603
6604
6605static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6606{
6607 char *pos;
6608 u8 version;
6609
6610 pos = os_strchr(cmd, ' ');
6611 if (pos == NULL)
6612 return -1;
6613 *pos++ = '\0';
6614
6615 if (hexstr2bin(cmd, &version, 1) < 0)
6616 return -1;
6617
6618 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6619}
6620
6621
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006622static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6623{
6624 u32 adv_id;
6625
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07006626 if (os_strcmp(cmd, "all") == 0) {
6627 wpas_p2p_service_flush_asp(wpa_s);
6628 return 0;
6629 }
6630
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006631 if (sscanf(cmd, "%x", &adv_id) != 1)
6632 return -1;
6633
6634 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6635}
6636
6637
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006638static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6639{
6640 char *pos;
6641
6642 pos = os_strchr(cmd, ' ');
6643 if (pos == NULL)
6644 return -1;
6645 *pos++ = '\0';
6646
6647 if (os_strcmp(cmd, "bonjour") == 0)
6648 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6649 if (os_strcmp(cmd, "upnp") == 0)
6650 return p2p_ctrl_service_del_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006651 if (os_strcmp(cmd, "asp") == 0)
6652 return p2p_ctrl_service_del_asp(wpa_s, pos);
6653 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6654 return -1;
6655}
6656
6657
6658static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6659{
6660 char *pos;
6661
6662 pos = os_strchr(cmd, ' ');
6663 if (pos == NULL)
6664 return -1;
6665 *pos++ = '\0';
6666
6667 if (os_strcmp(cmd, "asp") == 0)
6668 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6669
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006670 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6671 return -1;
6672}
6673
6674
6675static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
6676{
6677 u8 addr[ETH_ALEN];
6678
6679 /* <addr> */
6680
6681 if (hwaddr_aton(cmd, addr))
6682 return -1;
6683
6684 return wpas_p2p_reject(wpa_s, addr);
6685}
6686
6687
6688static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
6689{
6690 char *pos;
6691 int id;
6692 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006693 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006694 int freq = 0, pref_freq = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08006695 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006696 int edmg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006697
6698 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006699 pos = os_strstr(cmd, " peer=");
6700 if (pos) {
6701 pos += 6;
6702 if (hwaddr_aton(pos, peer))
6703 return -1;
6704 _peer = peer;
6705 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006706 ssid = wpa_config_get_network(wpa_s->conf, id);
6707 if (ssid == NULL || ssid->disabled != 2) {
6708 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6709 "for persistent P2P group",
6710 id);
6711 return -1;
6712 }
6713
Jouni Malinen31be0a42012-08-31 21:20:51 +03006714 pos = os_strstr(cmd, " freq=");
6715 if (pos) {
6716 pos += 6;
6717 freq = atoi(pos);
6718 if (freq <= 0)
6719 return -1;
6720 }
6721
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006722 pos = os_strstr(cmd, " pref=");
6723 if (pos) {
6724 pos += 6;
6725 pref_freq = atoi(pos);
6726 if (pref_freq <= 0)
6727 return -1;
6728 }
6729
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006730 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6731 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6732 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006733 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006734 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Jouni Malinen31be0a42012-08-31 21:20:51 +03006735
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006736 pos = os_strstr(cmd, "freq2=");
6737 if (pos)
6738 freq2 = atoi(pos + 6);
6739
6740 pos = os_strstr(cmd, " max_oper_chwidth=");
6741 if (pos)
6742 chwidth = atoi(pos + 18);
6743
6744 max_oper_chwidth = parse_freq(chwidth, freq2);
6745 if (max_oper_chwidth < 0)
6746 return -1;
6747
6748 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006749 max_oper_chwidth, pref_freq, he, edmg);
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;
6757
6758 pos = os_strstr(cmd, " peer=");
6759 if (!pos)
6760 return -1;
6761
6762 *pos = '\0';
6763 pos += 6;
6764 if (hwaddr_aton(pos, peer)) {
6765 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
6766 return -1;
6767 }
6768
6769 pos = os_strstr(pos, " go_dev_addr=");
6770 if (pos) {
6771 pos += 13;
6772 if (hwaddr_aton(pos, go_dev_addr)) {
6773 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
6774 pos);
6775 return -1;
6776 }
6777 go_dev = go_dev_addr;
6778 }
6779
6780 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
6781}
6782
6783
6784static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
6785{
6786 if (os_strncmp(cmd, "persistent=", 11) == 0)
6787 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
6788 if (os_strncmp(cmd, "group=", 6) == 0)
6789 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
6790
6791 return -1;
6792}
6793
6794
6795static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006796 int id, int freq, int vht_center_freq2,
Hai Shalom74f70d42019-02-11 14:42:39 -08006797 int ht40, int vht, int vht_chwidth,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006798 int he, int edmg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006799{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006800 struct wpa_ssid *ssid;
6801
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006802 ssid = wpa_config_get_network(wpa_s->conf, id);
6803 if (ssid == NULL || ssid->disabled != 2) {
6804 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6805 "for persistent P2P group",
6806 id);
6807 return -1;
6808 }
6809
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006810 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
6811 vht_center_freq2, 0, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006812 vht_chwidth, he, edmg,
6813 NULL, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006814}
6815
6816
6817static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
6818{
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006819 int freq = 0, persistent = 0, group_id = -1;
6820 int vht = wpa_s->conf->p2p_go_vht;
6821 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006822 int he = wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006823 int edmg = wpa_s->conf->p2p_go_edmg;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006824 int max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006825 char *token, *context = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006826#ifdef CONFIG_ACS
6827 int acs = 0;
6828#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006829
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006830 while ((token = str_token(cmd, " ", &context))) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07006831 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006832 sscanf(token, "persistent=%d", &group_id) == 1 ||
6833 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006834 continue;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006835#ifdef CONFIG_ACS
6836 } else if (os_strcmp(token, "freq=acs") == 0) {
6837 acs = 1;
6838#endif /* CONFIG_ACS */
6839 } else if (sscanf(token, "freq=%d", &freq) == 1) {
6840 continue;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006841 } else if (os_strcmp(token, "ht40") == 0) {
6842 ht40 = 1;
6843 } else if (os_strcmp(token, "vht") == 0) {
6844 vht = 1;
6845 ht40 = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08006846 } else if (os_strcmp(token, "he") == 0) {
6847 he = 1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006848 } else if (os_strcmp(token, "edmg") == 0) {
6849 edmg = 1;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006850 } else if (os_strcmp(token, "persistent") == 0) {
6851 persistent = 1;
6852 } else {
6853 wpa_printf(MSG_DEBUG,
6854 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6855 token);
6856 return -1;
6857 }
6858 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006859
Roshan Pius3a1667e2018-07-03 15:17:14 -07006860#ifdef CONFIG_ACS
6861 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
6862 (acs || freq == 2 || freq == 5)) {
6863 if (freq == 2 && wpa_s->best_24_freq <= 0) {
6864 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
6865 wpa_s->p2p_go_do_acs = 1;
6866 freq = 0;
6867 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
6868 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
6869 wpa_s->p2p_go_do_acs = 1;
6870 freq = 0;
6871 } else {
6872 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
6873 wpa_s->p2p_go_do_acs = 1;
6874 }
Hai Shalom021b0b52019-04-10 11:17:58 -07006875 } else {
6876 wpa_s->p2p_go_do_acs = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006877 }
6878#endif /* CONFIG_ACS */
6879
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006880 max_oper_chwidth = parse_freq(chwidth, freq2);
6881 if (max_oper_chwidth < 0)
6882 return -1;
6883
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006884 if (group_id >= 0)
6885 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006886 freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006887 max_oper_chwidth, he,
6888 edmg);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006889
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006890 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006891 max_oper_chwidth, he, edmg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006892}
6893
6894
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006895static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
6896 char *buf, size_t buflen)
6897{
6898 u8 dev_addr[ETH_ALEN];
6899 struct wpa_ssid *ssid;
6900 int res;
6901 const u8 *iaddr;
6902
6903 ssid = wpa_s->current_ssid;
6904 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
6905 hwaddr_aton(cmd, dev_addr))
6906 return -1;
6907
6908 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
6909 if (!iaddr)
6910 return -1;
6911 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
6912 if (os_snprintf_error(buflen, res))
6913 return -1;
6914 return res;
6915}
6916
6917
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006918static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
6919 const u8 *p2p_dev_addr)
6920{
6921 struct wpa_supplicant *wpa_s;
6922
6923 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6924 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
6925 return 1;
6926 }
6927
6928 return 0;
6929}
6930
6931
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006932static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
6933 char *buf, size_t buflen)
6934{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006935 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006936 int next, res;
6937 const struct p2p_peer_info *info;
6938 char *pos, *end;
6939 char devtype[WPS_DEV_TYPE_BUFSIZE];
6940 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006941 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006942
6943 if (!wpa_s->global->p2p)
6944 return -1;
6945
6946 if (os_strcmp(cmd, "FIRST") == 0) {
6947 addr_ptr = NULL;
6948 next = 0;
6949 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
6950 if (hwaddr_aton(cmd + 5, addr) < 0)
6951 return -1;
6952 addr_ptr = addr;
6953 next = 1;
6954 } else {
6955 if (hwaddr_aton(cmd, addr) < 0)
6956 return -1;
6957 addr_ptr = addr;
6958 next = 0;
6959 }
6960
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006961 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
6962 if (info == NULL)
6963 return -1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006964 group_capab = info->group_capab;
6965
6966 if (group_capab &&
6967 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
6968 wpa_printf(MSG_DEBUG,
6969 "P2P: Could not find any BSS with p2p_dev_addr "
6970 MACSTR ", hence override group_capab from 0x%x to 0",
6971 MAC2STR(info->p2p_device_addr), group_capab);
6972 group_capab = 0;
6973 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006974
6975 pos = buf;
6976 end = buf + buflen;
6977
6978 res = os_snprintf(pos, end - pos, MACSTR "\n"
6979 "pri_dev_type=%s\n"
6980 "device_name=%s\n"
6981 "manufacturer=%s\n"
6982 "model_name=%s\n"
6983 "model_number=%s\n"
6984 "serial_number=%s\n"
6985 "config_methods=0x%x\n"
6986 "dev_capab=0x%x\n"
6987 "group_capab=0x%x\n"
6988 "level=%d\n",
6989 MAC2STR(info->p2p_device_addr),
6990 wps_dev_type_bin2str(info->pri_dev_type,
6991 devtype, sizeof(devtype)),
6992 info->device_name,
6993 info->manufacturer,
6994 info->model_name,
6995 info->model_number,
6996 info->serial_number,
6997 info->config_methods,
6998 info->dev_capab,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006999 group_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007000 info->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007001 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007002 return pos - buf;
7003 pos += res;
7004
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007005 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
7006 {
7007 const u8 *t;
7008 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
7009 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
7010 wps_dev_type_bin2str(t, devtype,
7011 sizeof(devtype)));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007012 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007013 return pos - buf;
7014 pos += res;
7015 }
7016
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007017 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007018 if (ssid) {
7019 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007020 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007021 return pos - buf;
7022 pos += res;
7023 }
7024
7025 res = p2p_get_peer_info_txt(info, pos, end - pos);
7026 if (res < 0)
7027 return pos - buf;
7028 pos += res;
7029
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007030 if (info->vendor_elems) {
7031 res = os_snprintf(pos, end - pos, "vendor_elems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007032 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007033 return pos - buf;
7034 pos += res;
7035
7036 pos += wpa_snprintf_hex(pos, end - pos,
7037 wpabuf_head(info->vendor_elems),
7038 wpabuf_len(info->vendor_elems));
7039
7040 res = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007041 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07007042 return pos - buf;
7043 pos += res;
7044 }
7045
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007046 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007047}
7048
7049
Dmitry Shmidt04949592012-07-19 12:16:46 -07007050static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
7051 const char *param)
7052{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007053 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007054
7055 if (wpa_s->global->p2p == NULL)
7056 return -1;
7057
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007058 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
7059 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007060
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007061 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
7062 struct wpa_freq_range *freq;
7063 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07007064 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007065 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007066 }
7067
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007068 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007069 return 0;
7070}
7071
7072
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007073static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
7074{
7075 char *param;
7076
7077 if (wpa_s->global->p2p == NULL)
7078 return -1;
7079
7080 param = os_strchr(cmd, ' ');
7081 if (param == NULL)
7082 return -1;
7083 *param++ = '\0';
7084
7085 if (os_strcmp(cmd, "discoverability") == 0) {
7086 p2p_set_client_discoverability(wpa_s->global->p2p,
7087 atoi(param));
7088 return 0;
7089 }
7090
7091 if (os_strcmp(cmd, "managed") == 0) {
7092 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
7093 return 0;
7094 }
7095
7096 if (os_strcmp(cmd, "listen_channel") == 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08007097 char *pos;
7098 u8 channel, op_class;
7099
7100 channel = atoi(param);
7101 pos = os_strchr(param, ' ');
7102 op_class = pos ? atoi(pos) : 81;
7103
7104 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
7105 channel, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007106 }
7107
7108 if (os_strcmp(cmd, "ssid_postfix") == 0) {
7109 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
7110 os_strlen(param));
7111 }
7112
7113 if (os_strcmp(cmd, "noa") == 0) {
7114 char *pos;
7115 int count, start, duration;
7116 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
7117 count = atoi(param);
7118 pos = os_strchr(param, ',');
7119 if (pos == NULL)
7120 return -1;
7121 pos++;
7122 start = atoi(pos);
7123 pos = os_strchr(pos, ',');
7124 if (pos == NULL)
7125 return -1;
7126 pos++;
7127 duration = atoi(pos);
7128 if (count < 0 || count > 255 || start < 0 || duration < 0)
7129 return -1;
7130 if (count == 0 && duration > 0)
7131 return -1;
7132 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
7133 "start=%d duration=%d", count, start, duration);
7134 return wpas_p2p_set_noa(wpa_s, count, start, duration);
7135 }
7136
7137 if (os_strcmp(cmd, "ps") == 0)
7138 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
7139
7140 if (os_strcmp(cmd, "oppps") == 0)
7141 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
7142
7143 if (os_strcmp(cmd, "ctwindow") == 0)
7144 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
7145
7146 if (os_strcmp(cmd, "disabled") == 0) {
7147 wpa_s->global->p2p_disabled = atoi(param);
7148 wpa_printf(MSG_DEBUG, "P2P functionality %s",
7149 wpa_s->global->p2p_disabled ?
7150 "disabled" : "enabled");
7151 if (wpa_s->global->p2p_disabled) {
7152 wpas_p2p_stop_find(wpa_s);
7153 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7154 p2p_flush(wpa_s->global->p2p);
7155 }
7156 return 0;
7157 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007158
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007159 if (os_strcmp(cmd, "conc_pref") == 0) {
7160 if (os_strcmp(param, "sta") == 0)
7161 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
7162 else if (os_strcmp(param, "p2p") == 0)
7163 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007164 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007165 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007166 return -1;
7167 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007168 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07007169 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007170 return 0;
7171 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007172
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007173 if (os_strcmp(cmd, "force_long_sd") == 0) {
7174 wpa_s->force_long_sd = atoi(param);
7175 return 0;
7176 }
7177
7178 if (os_strcmp(cmd, "peer_filter") == 0) {
7179 u8 addr[ETH_ALEN];
7180 if (hwaddr_aton(param, addr))
7181 return -1;
7182 p2p_set_peer_filter(wpa_s->global->p2p, addr);
7183 return 0;
7184 }
7185
7186 if (os_strcmp(cmd, "cross_connect") == 0)
7187 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
7188
7189 if (os_strcmp(cmd, "go_apsd") == 0) {
7190 if (os_strcmp(param, "disable") == 0)
7191 wpa_s->set_ap_uapsd = 0;
7192 else {
7193 wpa_s->set_ap_uapsd = 1;
7194 wpa_s->ap_uapsd = atoi(param);
7195 }
7196 return 0;
7197 }
7198
7199 if (os_strcmp(cmd, "client_apsd") == 0) {
7200 if (os_strcmp(param, "disable") == 0)
7201 wpa_s->set_sta_uapsd = 0;
7202 else {
7203 int be, bk, vi, vo;
7204 char *pos;
7205 /* format: BE,BK,VI,VO;max SP Length */
7206 be = atoi(param);
7207 pos = os_strchr(param, ',');
7208 if (pos == NULL)
7209 return -1;
7210 pos++;
7211 bk = atoi(pos);
7212 pos = os_strchr(pos, ',');
7213 if (pos == NULL)
7214 return -1;
7215 pos++;
7216 vi = atoi(pos);
7217 pos = os_strchr(pos, ',');
7218 if (pos == NULL)
7219 return -1;
7220 pos++;
7221 vo = atoi(pos);
7222 /* ignore max SP Length for now */
7223
7224 wpa_s->set_sta_uapsd = 1;
7225 wpa_s->sta_uapsd = 0;
7226 if (be)
7227 wpa_s->sta_uapsd |= BIT(0);
7228 if (bk)
7229 wpa_s->sta_uapsd |= BIT(1);
7230 if (vi)
7231 wpa_s->sta_uapsd |= BIT(2);
7232 if (vo)
7233 wpa_s->sta_uapsd |= BIT(3);
7234 }
7235 return 0;
7236 }
7237
Dmitry Shmidt04949592012-07-19 12:16:46 -07007238 if (os_strcmp(cmd, "disallow_freq") == 0)
7239 return p2p_ctrl_disallow_freq(wpa_s, param);
7240
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007241 if (os_strcmp(cmd, "disc_int") == 0) {
7242 int min_disc_int, max_disc_int, max_disc_tu;
7243 char *pos;
7244
7245 pos = param;
7246
7247 min_disc_int = atoi(pos);
7248 pos = os_strchr(pos, ' ');
7249 if (pos == NULL)
7250 return -1;
7251 *pos++ = '\0';
7252
7253 max_disc_int = atoi(pos);
7254 pos = os_strchr(pos, ' ');
7255 if (pos == NULL)
7256 return -1;
7257 *pos++ = '\0';
7258
7259 max_disc_tu = atoi(pos);
7260
7261 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
7262 max_disc_int, max_disc_tu);
7263 }
7264
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007265 if (os_strcmp(cmd, "per_sta_psk") == 0) {
7266 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
7267 return 0;
7268 }
7269
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007270#ifdef CONFIG_WPS_NFC
7271 if (os_strcmp(cmd, "nfc_tag") == 0)
7272 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
7273#endif /* CONFIG_WPS_NFC */
7274
7275 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
7276 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
7277 return 0;
7278 }
7279
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007280 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
7281 int op_class, chan;
7282
7283 op_class = atoi(param);
7284 param = os_strchr(param, ':');
7285 if (!param)
7286 return -1;
7287 param++;
7288 chan = atoi(param);
7289 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
7290 chan);
7291 return 0;
7292 }
7293
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007294 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
7295 cmd);
7296
7297 return -1;
7298}
7299
7300
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007301static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
7302{
7303 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7304 wpa_s->force_long_sd = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007305
7306#ifdef CONFIG_TESTING_OPTIONS
7307 os_free(wpa_s->get_pref_freq_list_override);
7308 wpa_s->get_pref_freq_list_override = NULL;
7309#endif /* CONFIG_TESTING_OPTIONS */
7310
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007311 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007312 wpa_s->parent->p2ps_method_config_any = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007313 if (wpa_s->global->p2p)
7314 p2p_flush(wpa_s->global->p2p);
7315}
7316
7317
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007318static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
7319{
7320 char *pos, *pos2;
7321 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
7322
7323 if (cmd[0]) {
7324 pos = os_strchr(cmd, ' ');
7325 if (pos == NULL)
7326 return -1;
7327 *pos++ = '\0';
7328 dur1 = atoi(cmd);
7329
7330 pos2 = os_strchr(pos, ' ');
7331 if (pos2)
7332 *pos2++ = '\0';
7333 int1 = atoi(pos);
7334 } else
7335 pos2 = NULL;
7336
7337 if (pos2) {
7338 pos = os_strchr(pos2, ' ');
7339 if (pos == NULL)
7340 return -1;
7341 *pos++ = '\0';
7342 dur2 = atoi(pos2);
7343 int2 = atoi(pos);
7344 }
7345
7346 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
7347}
7348
7349
7350static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
7351{
7352 char *pos;
7353 unsigned int period = 0, interval = 0;
7354
7355 if (cmd[0]) {
7356 pos = os_strchr(cmd, ' ');
7357 if (pos == NULL)
7358 return -1;
7359 *pos++ = '\0';
7360 period = atoi(cmd);
7361 interval = atoi(pos);
7362 }
7363
7364 return wpas_p2p_ext_listen(wpa_s, period, interval);
7365}
7366
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007367
7368static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
7369{
7370 const char *pos;
7371 u8 peer[ETH_ALEN];
7372 int iface_addr = 0;
7373
7374 pos = cmd;
7375 if (os_strncmp(pos, "iface=", 6) == 0) {
7376 iface_addr = 1;
7377 pos += 6;
7378 }
7379 if (hwaddr_aton(pos, peer))
7380 return -1;
7381
7382 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
7383 return 0;
7384}
7385
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007386
7387static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
7388{
7389 int freq = 0, period = 0, interval = 0, count = 0;
7390
7391 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
7392 {
7393 wpa_printf(MSG_DEBUG,
7394 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
7395 return -1;
7396 }
7397
7398 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
7399}
7400
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007401#endif /* CONFIG_P2P */
7402
7403
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007404static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
7405{
7406 struct wpa_freq_range_list ranges;
7407 int *freqs = NULL;
7408 struct hostapd_hw_modes *mode;
7409 u16 i;
7410
7411 if (wpa_s->hw.modes == NULL)
7412 return NULL;
7413
7414 os_memset(&ranges, 0, sizeof(ranges));
7415 if (freq_range_list_parse(&ranges, val) < 0)
7416 return NULL;
7417
7418 for (i = 0; i < wpa_s->hw.num_modes; i++) {
7419 int j;
7420
7421 mode = &wpa_s->hw.modes[i];
7422 for (j = 0; j < mode->num_channels; j++) {
7423 unsigned int freq;
7424
7425 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
7426 continue;
7427
7428 freq = mode->channels[j].freq;
7429 if (!freq_range_list_includes(&ranges, freq))
7430 continue;
7431
7432 int_array_add_unique(&freqs, freq);
7433 }
7434 }
7435
7436 os_free(ranges.range);
7437 return freqs;
7438}
7439
7440
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007441#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007442
7443static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
7444{
7445 int auto_sel = 0;
7446 int *freqs = NULL;
7447
7448 if (param) {
7449 char *pos;
7450
7451 auto_sel = os_strstr(param, "auto") != NULL;
7452
7453 pos = os_strstr(param, "freq=");
7454 if (pos) {
7455 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
7456 if (freqs == NULL)
7457 return -1;
7458 }
7459
7460 }
7461
7462 return interworking_select(wpa_s, auto_sel, freqs);
7463}
7464
7465
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007466static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
7467 int only_add)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007468{
7469 u8 bssid[ETH_ALEN];
7470 struct wpa_bss *bss;
7471
7472 if (hwaddr_aton(dst, bssid)) {
7473 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
7474 return -1;
7475 }
7476
Hai Shalomfdcde762020-04-02 11:19:20 -07007477 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007478 if (bss == NULL) {
7479 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
7480 MAC2STR(bssid));
7481 return -1;
7482 }
7483
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007484 if (bss->ssid_len == 0) {
7485 int found = 0;
7486
7487 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
7488 " does not have SSID information", MAC2STR(bssid));
7489
7490 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
7491 list) {
7492 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
7493 bss->ssid_len > 0) {
7494 found = 1;
7495 break;
7496 }
7497 }
7498
7499 if (!found)
7500 return -1;
7501 wpa_printf(MSG_DEBUG,
7502 "Found another matching BSS entry with SSID");
7503 }
7504
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007505 return interworking_connect(wpa_s, bss, only_add);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007506}
7507
7508
7509static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
7510{
7511 u8 dst_addr[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07007512 int used, freq = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007513 char *pos;
7514#define MAX_ANQP_INFO_ID 100
7515 u16 id[MAX_ANQP_INFO_ID];
7516 size_t num_id = 0;
Dmitry Shmidt15907092014-03-25 10:42:57 -07007517 u32 subtypes = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007518 u32 mbo_subtypes = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007519
7520 used = hwaddr_aton2(dst, dst_addr);
7521 if (used < 0)
7522 return -1;
7523 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007524 if (*pos == ' ')
7525 pos++;
Hai Shalom899fcc72020-10-19 14:38:18 -07007526
7527 if (os_strncmp(pos, "freq=", 5) == 0) {
7528 freq = atoi(pos + 5);
7529 pos = os_strchr(pos, ' ');
7530 if (!pos)
7531 return -1;
7532 pos++;
7533 }
7534
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007535 while (num_id < MAX_ANQP_INFO_ID) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07007536 if (os_strncmp(pos, "hs20:", 5) == 0) {
7537#ifdef CONFIG_HS20
7538 int num = atoi(pos + 5);
7539 if (num <= 0 || num > 31)
7540 return -1;
7541 subtypes |= BIT(num);
7542#else /* CONFIG_HS20 */
7543 return -1;
7544#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007545 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7546#ifdef CONFIG_MBO
7547 int num = atoi(pos + 4);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007548
7549 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007550 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007551 mbo_subtypes |= BIT(num);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007552#else /* CONFIG_MBO */
7553 return -1;
7554#endif /* CONFIG_MBO */
Dmitry Shmidt15907092014-03-25 10:42:57 -07007555 } else {
7556 id[num_id] = atoi(pos);
7557 if (id[num_id])
7558 num_id++;
7559 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007560 pos = os_strchr(pos + 1, ',');
7561 if (pos == NULL)
7562 break;
7563 pos++;
7564 }
7565
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007566 if (num_id == 0 && !subtypes && !mbo_subtypes)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007567 return -1;
7568
Hai Shalom899fcc72020-10-19 14:38:18 -07007569 return anqp_send_req(wpa_s, dst_addr, freq, id, num_id, subtypes,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007570 mbo_subtypes);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007571}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007572
7573
7574static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7575{
7576 u8 dst_addr[ETH_ALEN];
7577 struct wpabuf *advproto, *query = NULL;
7578 int used, ret = -1;
7579 char *pos, *end;
7580 size_t len;
7581
7582 used = hwaddr_aton2(cmd, dst_addr);
7583 if (used < 0)
7584 return -1;
7585
7586 pos = cmd + used;
7587 while (*pos == ' ')
7588 pos++;
7589
7590 /* Advertisement Protocol ID */
7591 end = os_strchr(pos, ' ');
7592 if (end)
7593 len = end - pos;
7594 else
7595 len = os_strlen(pos);
7596 if (len & 0x01)
7597 return -1;
7598 len /= 2;
7599 if (len == 0)
7600 return -1;
7601 advproto = wpabuf_alloc(len);
7602 if (advproto == NULL)
7603 return -1;
7604 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7605 goto fail;
7606
7607 if (end) {
7608 /* Optional Query Request */
7609 pos = end + 1;
7610 while (*pos == ' ')
7611 pos++;
7612
7613 len = os_strlen(pos);
7614 if (len) {
7615 if (len & 0x01)
7616 goto fail;
7617 len /= 2;
7618 if (len == 0)
7619 goto fail;
7620 query = wpabuf_alloc(len);
7621 if (query == NULL)
7622 goto fail;
7623 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7624 goto fail;
7625 }
7626 }
7627
7628 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7629
7630fail:
7631 wpabuf_free(advproto);
7632 wpabuf_free(query);
7633
7634 return ret;
7635}
7636
7637
7638static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7639 size_t buflen)
7640{
7641 u8 addr[ETH_ALEN];
7642 int dialog_token;
7643 int used;
7644 char *pos;
7645 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007646 struct wpabuf *resp;
7647 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007648
7649 used = hwaddr_aton2(cmd, addr);
7650 if (used < 0)
7651 return -1;
7652
7653 pos = cmd + used;
7654 while (*pos == ' ')
7655 pos++;
7656 dialog_token = atoi(pos);
7657
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007658 if (wpa_s->last_gas_resp &&
7659 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
7660 dialog_token == wpa_s->last_gas_dialog_token)
7661 resp = wpa_s->last_gas_resp;
7662 else if (wpa_s->prev_gas_resp &&
7663 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
7664 dialog_token == wpa_s->prev_gas_dialog_token)
7665 resp = wpa_s->prev_gas_resp;
7666 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007667 return -1;
7668
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007669 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007670 start = 0;
7671 requested_len = resp_len;
7672
7673 pos = os_strchr(pos, ' ');
7674 if (pos) {
7675 start = atoi(pos);
7676 if (start > resp_len)
7677 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7678 pos = os_strchr(pos, ',');
7679 if (pos == NULL)
7680 return -1;
7681 pos++;
7682 requested_len = atoi(pos);
7683 if (start + requested_len > resp_len)
7684 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7685 }
7686
7687 if (requested_len * 2 + 1 > buflen)
7688 return os_snprintf(buf, buflen, "FAIL-Too long response");
7689
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007690 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
7691 requested_len);
7692
7693 if (start + requested_len == resp_len) {
7694 /*
7695 * Free memory by dropping the response after it has been
7696 * fetched.
7697 */
7698 if (resp == wpa_s->prev_gas_resp) {
7699 wpabuf_free(wpa_s->prev_gas_resp);
7700 wpa_s->prev_gas_resp = NULL;
7701 } else {
7702 wpabuf_free(wpa_s->last_gas_resp);
7703 wpa_s->last_gas_resp = NULL;
7704 }
7705 }
7706
7707 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007708}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007709#endif /* CONFIG_INTERWORKING */
7710
7711
Dmitry Shmidt04949592012-07-19 12:16:46 -07007712#ifdef CONFIG_HS20
7713
7714static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
7715{
7716 u8 dst_addr[ETH_ALEN];
7717 int used;
7718 char *pos;
7719 u32 subtypes = 0;
7720
7721 used = hwaddr_aton2(dst, dst_addr);
7722 if (used < 0)
7723 return -1;
7724 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007725 if (*pos == ' ')
7726 pos++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007727 for (;;) {
7728 int num = atoi(pos);
7729 if (num <= 0 || num > 31)
7730 return -1;
7731 subtypes |= BIT(num);
7732 pos = os_strchr(pos + 1, ',');
7733 if (pos == NULL)
7734 break;
7735 pos++;
7736 }
7737
7738 if (subtypes == 0)
7739 return -1;
7740
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007741 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007742}
7743
7744
7745static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7746 const u8 *addr, const char *realm)
7747{
7748 u8 *buf;
7749 size_t rlen, len;
7750 int ret;
7751
7752 rlen = os_strlen(realm);
7753 len = 3 + rlen;
7754 buf = os_malloc(len);
7755 if (buf == NULL)
7756 return -1;
7757 buf[0] = 1; /* NAI Home Realm Count */
7758 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
7759 buf[2] = rlen;
7760 os_memcpy(buf + 3, realm, rlen);
7761
7762 ret = hs20_anqp_send_req(wpa_s, addr,
7763 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007764 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007765
7766 os_free(buf);
7767
7768 return ret;
7769}
7770
7771
7772static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7773 char *dst)
7774{
7775 struct wpa_cred *cred = wpa_s->conf->cred;
7776 u8 dst_addr[ETH_ALEN];
7777 int used;
7778 u8 *buf;
7779 size_t len;
7780 int ret;
7781
7782 used = hwaddr_aton2(dst, dst_addr);
7783 if (used < 0)
7784 return -1;
7785
7786 while (dst[used] == ' ')
7787 used++;
7788 if (os_strncmp(dst + used, "realm=", 6) == 0)
7789 return hs20_nai_home_realm_list(wpa_s, dst_addr,
7790 dst + used + 6);
7791
7792 len = os_strlen(dst + used);
7793
7794 if (len == 0 && cred && cred->realm)
7795 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
7796
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07007797 if (len & 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07007798 return -1;
7799 len /= 2;
7800 buf = os_malloc(len);
7801 if (buf == NULL)
7802 return -1;
7803 if (hexstr2bin(dst + used, buf, len) < 0) {
7804 os_free(buf);
7805 return -1;
7806 }
7807
7808 ret = hs20_anqp_send_req(wpa_s, dst_addr,
7809 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007810 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007811 os_free(buf);
7812
7813 return ret;
7814}
7815
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007816
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007817static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
7818 int buflen)
7819{
7820 u8 dst_addr[ETH_ALEN];
7821 int used;
7822 char *ctx = NULL, *icon, *poffset, *psize;
7823
7824 used = hwaddr_aton2(cmd, dst_addr);
7825 if (used < 0)
7826 return -1;
7827 cmd += used;
7828
7829 icon = str_token(cmd, " ", &ctx);
7830 poffset = str_token(cmd, " ", &ctx);
7831 psize = str_token(cmd, " ", &ctx);
7832 if (!icon || !poffset || !psize)
7833 return -1;
7834
7835 wpa_s->fetch_osu_icon_in_progress = 0;
7836 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
7837 reply, buflen);
7838}
7839
7840
7841static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
7842{
7843 u8 dst_addr[ETH_ALEN];
7844 int used;
7845 char *icon;
7846
7847 if (!cmd[0])
7848 return hs20_del_icon(wpa_s, NULL, NULL);
7849
7850 used = hwaddr_aton2(cmd, dst_addr);
7851 if (used < 0)
7852 return -1;
7853
7854 while (cmd[used] == ' ')
7855 used++;
7856 icon = cmd[used] ? &cmd[used] : NULL;
7857
7858 return hs20_del_icon(wpa_s, dst_addr, icon);
7859}
7860
7861
7862static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007863{
7864 u8 dst_addr[ETH_ALEN];
7865 int used;
7866 char *icon;
7867
7868 used = hwaddr_aton2(cmd, dst_addr);
7869 if (used < 0)
7870 return -1;
7871
7872 while (cmd[used] == ' ')
7873 used++;
7874 icon = &cmd[used];
7875
7876 wpa_s->fetch_osu_icon_in_progress = 0;
7877 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007878 (u8 *) icon, os_strlen(icon), inmem);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007879}
7880
Dmitry Shmidt04949592012-07-19 12:16:46 -07007881#endif /* CONFIG_HS20 */
7882
7883
Dmitry Shmidt04949592012-07-19 12:16:46 -07007884#ifdef CONFIG_AUTOSCAN
7885
7886static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
7887 char *cmd)
7888{
7889 enum wpa_states state = wpa_s->wpa_state;
7890 char *new_params = NULL;
7891
7892 if (os_strlen(cmd) > 0) {
7893 new_params = os_strdup(cmd);
7894 if (new_params == NULL)
7895 return -1;
7896 }
7897
7898 os_free(wpa_s->conf->autoscan);
7899 wpa_s->conf->autoscan = new_params;
7900
7901 if (wpa_s->conf->autoscan == NULL)
7902 autoscan_deinit(wpa_s);
7903 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
7904 autoscan_init(wpa_s, 1);
7905 else if (state == WPA_SCANNING)
7906 wpa_supplicant_reinit_autoscan(wpa_s);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007907 else
7908 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
7909 wpa_supplicant_state_txt(state));
Dmitry Shmidt04949592012-07-19 12:16:46 -07007910
7911 return 0;
7912}
7913
7914#endif /* CONFIG_AUTOSCAN */
7915
7916
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007917#ifdef CONFIG_WNM
7918
7919static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
7920{
7921 int enter;
7922 int intval = 0;
7923 char *pos;
7924 int ret;
7925 struct wpabuf *tfs_req = NULL;
7926
7927 if (os_strncmp(cmd, "enter", 5) == 0)
7928 enter = 1;
7929 else if (os_strncmp(cmd, "exit", 4) == 0)
7930 enter = 0;
7931 else
7932 return -1;
7933
7934 pos = os_strstr(cmd, " interval=");
7935 if (pos)
7936 intval = atoi(pos + 10);
7937
7938 pos = os_strstr(cmd, " tfs_req=");
7939 if (pos) {
7940 char *end;
7941 size_t len;
7942 pos += 9;
7943 end = os_strchr(pos, ' ');
7944 if (end)
7945 len = end - pos;
7946 else
7947 len = os_strlen(pos);
7948 if (len & 1)
7949 return -1;
7950 len /= 2;
7951 tfs_req = wpabuf_alloc(len);
7952 if (tfs_req == NULL)
7953 return -1;
7954 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
7955 wpabuf_free(tfs_req);
7956 return -1;
7957 }
7958 }
7959
7960 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
7961 WNM_SLEEP_MODE_EXIT, intval,
7962 tfs_req);
7963 wpabuf_free(tfs_req);
7964
7965 return ret;
7966}
7967
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007968
7969static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
7970{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007971 int query_reason, list = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007972 char *btm_candidates = NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007973
7974 query_reason = atoi(cmd);
7975
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007976 cmd = os_strchr(cmd, ' ');
7977 if (cmd) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007978 if (os_strncmp(cmd, " list", 5) == 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007979 list = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007980 else
7981 btm_candidates = cmd;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007982 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007983
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007984 wpa_printf(MSG_DEBUG,
7985 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7986 query_reason, list ? " candidate list" : "");
7987
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007988 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
7989 btm_candidates,
7990 list);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007991}
7992
Hai Shalom39ba6fc2019-01-22 12:40:38 -08007993
7994static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
7995 char *cmd)
7996{
7997 struct wpabuf *elems;
7998 int ret;
7999
8000 elems = wpabuf_parse_bin(cmd);
8001 if (!elems)
8002 return -1;
8003
8004 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
8005 wpabuf_free(elems);
8006 return ret;
8007}
8008
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08008009#endif /* CONFIG_WNM */
8010
8011
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008012static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
8013 size_t buflen)
8014{
8015 struct wpa_signal_info si;
8016 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008017 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008018
8019 ret = wpa_drv_signal_poll(wpa_s, &si);
8020 if (ret)
8021 return -1;
8022
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008023 pos = buf;
8024 end = buf + buflen;
8025
8026 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008027 "NOISE=%d\nFREQUENCY=%u\n",
8028 si.current_signal, si.current_txrate / 1000,
8029 si.current_noise, si.frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008030 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008031 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008032 pos += ret;
8033
8034 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
8035 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008036 channel_width_to_string(si.chanwidth));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008037 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008038 return -1;
8039 pos += ret;
8040 }
8041
Roshan Pius3a1667e2018-07-03 15:17:14 -07008042 if (si.center_frq1 > 0) {
8043 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
8044 si.center_frq1);
8045 if (os_snprintf_error(end - pos, ret))
8046 return -1;
8047 pos += ret;
8048 }
8049
8050 if (si.center_frq2 > 0) {
8051 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
8052 si.center_frq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008053 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008054 return -1;
8055 pos += ret;
8056 }
8057
8058 if (si.avg_signal) {
8059 ret = os_snprintf(pos, end - pos,
8060 "AVG_RSSI=%d\n", si.avg_signal);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008061 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008062 return -1;
8063 pos += ret;
8064 }
8065
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07008066 if (si.avg_beacon_signal) {
8067 ret = os_snprintf(pos, end - pos,
8068 "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
8069 if (os_snprintf_error(end - pos, ret))
8070 return -1;
8071 pos += ret;
8072 }
8073
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008074 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008075}
8076
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008077
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008078static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
8079 const char *cmd)
8080{
8081 const char *pos;
8082 int threshold = 0;
8083 int hysteresis = 0;
8084
8085 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
8086 wpa_printf(MSG_DEBUG,
8087 "Reject SIGNAL_MONITOR command - bgscan is active");
8088 return -1;
8089 }
8090 pos = os_strstr(cmd, "THRESHOLD=");
8091 if (pos)
8092 threshold = atoi(pos + 10);
8093 pos = os_strstr(cmd, "HYSTERESIS=");
8094 if (pos)
8095 hysteresis = atoi(pos + 11);
8096 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
8097}
8098
8099
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008100#ifdef CONFIG_TESTING_OPTIONS
8101int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
8102 enum wpa_driver_if_type if_type,
8103 unsigned int *num,
8104 unsigned int *freq_list)
8105{
8106 char *pos = wpa_s->get_pref_freq_list_override;
8107 char *end;
8108 unsigned int count = 0;
8109
8110 /* Override string format:
8111 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
8112
8113 while (pos) {
8114 if (atoi(pos) == (int) if_type)
8115 break;
8116 pos = os_strchr(pos, ' ');
8117 if (pos)
8118 pos++;
8119 }
8120 if (!pos)
8121 return -1;
8122 pos = os_strchr(pos, ':');
8123 if (!pos)
8124 return -1;
8125 pos++;
8126 end = os_strchr(pos, ' ');
8127 while (pos && (!end || pos < end) && count < *num) {
8128 freq_list[count++] = atoi(pos);
8129 pos = os_strchr(pos, ',');
8130 if (pos)
8131 pos++;
8132 }
8133
8134 *num = count;
8135 return 0;
8136}
8137#endif /* CONFIG_TESTING_OPTIONS */
8138
8139
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008140static int wpas_ctrl_iface_get_pref_freq_list(
8141 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
8142{
8143 unsigned int freq_list[100], num = 100, i;
8144 int ret;
8145 enum wpa_driver_if_type iface_type;
8146 char *pos, *end;
8147
8148 pos = buf;
8149 end = buf + buflen;
8150
8151 /* buf: "<interface_type>" */
8152 if (os_strcmp(cmd, "STATION") == 0)
8153 iface_type = WPA_IF_STATION;
8154 else if (os_strcmp(cmd, "AP") == 0)
8155 iface_type = WPA_IF_AP_BSS;
8156 else if (os_strcmp(cmd, "P2P_GO") == 0)
8157 iface_type = WPA_IF_P2P_GO;
8158 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
8159 iface_type = WPA_IF_P2P_CLIENT;
8160 else if (os_strcmp(cmd, "IBSS") == 0)
8161 iface_type = WPA_IF_IBSS;
8162 else if (os_strcmp(cmd, "TDLS") == 0)
8163 iface_type = WPA_IF_TDLS;
8164 else
8165 return -1;
8166
8167 wpa_printf(MSG_DEBUG,
8168 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
Hai Shalom5f92bc92019-04-18 11:54:11 -07008169 iface_type, cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008170
8171 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
8172 if (ret)
8173 return -1;
8174
8175 for (i = 0; i < num; i++) {
8176 ret = os_snprintf(pos, end - pos, "%s%u",
8177 i > 0 ? "," : "", freq_list[i]);
8178 if (os_snprintf_error(end - pos, ret))
8179 return -1;
8180 pos += ret;
8181 }
8182
8183 return pos - buf;
8184}
8185
8186
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008187static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
8188 char *buf, size_t buflen)
8189{
8190 int ret, i;
8191 char *pos, *end;
8192
8193 ret = os_snprintf(buf, buflen, "%016llX:\n",
8194 (long long unsigned) wpa_s->drv_flags);
8195 if (os_snprintf_error(buflen, ret))
8196 return -1;
8197
8198 pos = buf + ret;
8199 end = buf + buflen;
8200
8201 for (i = 0; i < 64; i++) {
8202 if (wpa_s->drv_flags & (1LLU << i)) {
8203 ret = os_snprintf(pos, end - pos, "%s\n",
8204 driver_flag_to_string(1LLU << i));
8205 if (os_snprintf_error(end - pos, ret))
8206 return -1;
8207 pos += ret;
8208 }
8209 }
8210
8211 return pos - buf;
8212}
8213
8214
Hai Shalomb755a2a2020-04-23 21:49:02 -07008215static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s,
8216 char *buf, size_t buflen)
8217{
8218 int ret, i;
8219 char *pos, *end;
8220
8221 ret = os_snprintf(buf, buflen, "%016llX:\n",
8222 (long long unsigned) wpa_s->drv_flags2);
8223 if (os_snprintf_error(buflen, ret))
8224 return -1;
8225
8226 pos = buf + ret;
8227 end = buf + buflen;
8228
8229 for (i = 0; i < 64; i++) {
8230 if (wpa_s->drv_flags2 & (1LLU << i)) {
8231 ret = os_snprintf(pos, end - pos, "%s\n",
8232 driver_flag2_to_string(1LLU << i));
8233 if (os_snprintf_error(end - pos, ret))
8234 return -1;
8235 pos += ret;
8236 }
8237 }
8238
8239 return pos - buf;
8240}
8241
8242
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008243static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
8244 size_t buflen)
8245{
8246 struct hostap_sta_driver_data sta;
8247 int ret;
8248
8249 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
8250 if (ret)
8251 return -1;
8252
8253 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008254 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008255 if (os_snprintf_error(buflen, ret))
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008256 return -1;
8257 return ret;
8258}
8259
8260
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008261#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008262static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8263 char *buf, size_t buflen)
8264{
8265 int ret;
8266
8267 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008268 if (ret == 0) {
8269 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
8270 struct p2p_data *p2p = wpa_s->global->p2p;
8271 if (p2p) {
8272 char country[3];
8273 country[0] = cmd[8];
8274 country[1] = cmd[9];
8275 country[2] = 0x04;
8276 p2p_set_country(p2p, country);
8277 }
8278 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008279 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008280 if (os_snprintf_error(buflen, ret))
8281 ret = -1;
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008282 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008283 return ret;
8284}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008285#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008286
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07008287
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008288static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8289 char *buf, size_t buflen)
8290{
8291 int ret;
Hai Shalom60840252021-02-19 19:02:11 -08008292 char *pos, *temp = NULL;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008293 u8 *data = NULL;
8294 unsigned int vendor_id, subcmd;
Hai Shalom60840252021-02-19 19:02:11 -08008295 enum nested_attr nested_attr_flag = NESTED_ATTR_UNSPECIFIED;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008296 struct wpabuf *reply;
8297 size_t data_len = 0;
8298
Hai Shalom60840252021-02-19 19:02:11 -08008299 /**
8300 * cmd: <vendor id> <subcommand id> [<hex formatted data>]
8301 * [nested=<0|1>]
8302 */
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008303 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008304 if (!isblank((unsigned char) *pos))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008305 return -EINVAL;
8306
8307 subcmd = strtoul(pos, &pos, 10);
8308
8309 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008310 if (!isblank((unsigned char) *pos++))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008311 return -EINVAL;
Hai Shalom60840252021-02-19 19:02:11 -08008312
8313 temp = os_strchr(pos, ' ');
8314 data_len = temp ? (size_t) (temp - pos) : os_strlen(pos);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008315 }
8316
8317 if (data_len) {
8318 data_len /= 2;
8319 data = os_malloc(data_len);
8320 if (!data)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008321 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008322
8323 if (hexstr2bin(pos, data, data_len)) {
8324 wpa_printf(MSG_DEBUG,
8325 "Vendor command: wrong parameter format");
8326 os_free(data);
8327 return -EINVAL;
8328 }
8329 }
8330
Hai Shalom60840252021-02-19 19:02:11 -08008331 pos = os_strstr(cmd, "nested=");
8332 if (pos)
8333 nested_attr_flag = atoi(pos + 7) ? NESTED_ATTR_USED :
8334 NESTED_ATTR_NOT_USED;
8335
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008336 reply = wpabuf_alloc((buflen - 1) / 2);
8337 if (!reply) {
8338 os_free(data);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008339 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008340 }
8341
8342 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
Hai Shalom60840252021-02-19 19:02:11 -08008343 nested_attr_flag, reply);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008344
8345 if (ret == 0)
8346 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
8347 wpabuf_len(reply));
8348
8349 wpabuf_free(reply);
8350 os_free(data);
8351
8352 return ret;
8353}
8354
8355
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008356static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
8357{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008358#ifdef CONFIG_P2P
8359 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
8360 wpa_s->global->p2p_init_wpa_s : wpa_s;
8361#endif /* CONFIG_P2P */
8362
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008363 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
8364
Dmitry Shmidt29333592017-01-09 12:27:11 -08008365 if (wpas_abort_ongoing_scan(wpa_s) == 0)
8366 wpa_s->ignore_post_flush_scan_res = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008367
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008368 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
8369 /*
8370 * Avoid possible auto connect re-connection on getting
8371 * disconnected due to state flush.
8372 */
8373 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
8374 }
8375
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008376#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008377 wpas_p2p_group_remove(p2p_wpa_s, "*");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008378 wpas_p2p_cancel(p2p_wpa_s);
8379 p2p_ctrl_flush(p2p_wpa_s);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008380 wpas_p2p_service_flush(p2p_wpa_s);
8381 p2p_wpa_s->global->p2p_disabled = 0;
8382 p2p_wpa_s->global->p2p_per_sta_psk = 0;
8383 p2p_wpa_s->conf->num_sec_device_types = 0;
8384 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
8385 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
8386 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008387 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08008388 p2p_wpa_s->global->pending_p2ps_group = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008389 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008390#endif /* CONFIG_P2P */
8391
8392#ifdef CONFIG_WPS_TESTING
8393 wps_version_number = 0x20;
8394 wps_testing_dummy_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08008395 wps_corrupt_pkhash = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008396 wps_force_auth_types_in_use = 0;
8397 wps_force_encr_types_in_use = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008398#endif /* CONFIG_WPS_TESTING */
8399#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008400 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008401 wpas_wps_cancel(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008402 wps_registrar_flush(wpa_s->wps->registrar);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008403#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07008404 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008405 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008406
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008407#ifdef CONFIG_DPP
8408 wpas_dpp_deinit(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07008409 wpa_s->dpp_init_max_tries = 0;
8410 wpa_s->dpp_init_retry_time = 0;
8411 wpa_s->dpp_resp_wait_time = 0;
8412 wpa_s->dpp_resp_max_tries = 0;
8413 wpa_s->dpp_resp_retry_time = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008414#ifdef CONFIG_DPP2
8415 wpas_dpp_chirp_stop(wpa_s);
8416 wpa_s->dpp_pfs_fallback = 0;
8417#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008418#ifdef CONFIG_TESTING_OPTIONS
8419 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
8420 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
8421 dpp_pkex_ephemeral_key_override_len = 0;
8422 dpp_protocol_key_override_len = 0;
8423 dpp_nonce_override_len = 0;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07008424#ifdef CONFIG_DPP2
8425 dpp_version_override = 2;
8426#else /* CONFIG_DPP2 */
8427 dpp_version_override = 1;
8428#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008429#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008430#endif /* CONFIG_DPP */
8431
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008432#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008433#ifdef CONFIG_TDLS_TESTING
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008434 tdls_testing = 0;
8435#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008436 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
8437 wpa_tdls_enable(wpa_s->wpa, 1);
8438#endif /* CONFIG_TDLS */
8439
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008440 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
8441 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07008442 wpa_s->last_michael_mic_error.sec = 0;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008443
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008444 wpa_s->no_keep_alive = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08008445 wpa_s->own_disconnect_req = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008446 wpa_s->own_reconnect_req = 0;
8447 wpa_s->deny_ptk0_rekey = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008448
8449 os_free(wpa_s->disallow_aps_bssid);
8450 wpa_s->disallow_aps_bssid = NULL;
8451 wpa_s->disallow_aps_bssid_count = 0;
8452 os_free(wpa_s->disallow_aps_ssid);
8453 wpa_s->disallow_aps_ssid = NULL;
8454 wpa_s->disallow_aps_ssid_count = 0;
8455
8456 wpa_s->set_sta_uapsd = 0;
8457 wpa_s->sta_uapsd = 0;
8458
Hai Shalom899fcc72020-10-19 14:38:18 -07008459 wpa_s->consecutive_conn_failures = 0;
8460
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008461 wpa_drv_radio_disable(wpa_s, 0);
Hai Shalom60840252021-02-19 19:02:11 -08008462 wpa_bssid_ignore_clear(wpa_s);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008463 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
8464 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08008465 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08008466 wpa_s->conf->auto_interworking = 0;
8467 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008468
Hai Shalom60840252021-02-19 19:02:11 -08008469 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008470 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
8471 rsn_preauth_deinit(wpa_s->wpa);
8472
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008473 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
8474 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
8475 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
Hai Shalome21d4e82020-04-29 16:34:06 -07008476 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008477
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008478 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008479 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008480
8481 wpa_s->next_ssid = NULL;
8482
8483#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008484#ifdef CONFIG_HS20
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008485 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008486 hs20_del_icon(wpa_s, NULL, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008487#endif /* CONFIG_HS20 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008488#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008489
8490 wpa_s->ext_mgmt_frame_handling = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008491 wpa_s->ext_eapol_frame_io = 0;
8492#ifdef CONFIG_TESTING_OPTIONS
8493 wpa_s->extra_roc_dur = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008494 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008495 wpa_s->p2p_go_csa_on_inv = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008496 wpa_s->ignore_auth_resp = 0;
8497 wpa_s->ignore_assoc_disallow = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008498 wpa_s->disable_sa_query = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008499 wpa_s->testing_resend_assoc = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008500 wpa_s->ignore_sae_h2e_only = 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07008501 wpa_s->ft_rsnxe_used = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008502 wpa_s->reject_btm_req_reason = 0;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008503 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008504 os_free(wpa_s->get_pref_freq_list_override);
8505 wpa_s->get_pref_freq_list_override = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008506 wpabuf_free(wpa_s->sae_commit_override);
8507 wpa_s->sae_commit_override = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008508 os_free(wpa_s->extra_sae_rejected_groups);
8509 wpa_s->extra_sae_rejected_groups = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008510 wpabuf_free(wpa_s->rsne_override_eapol);
8511 wpa_s->rsne_override_eapol = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008512 wpabuf_free(wpa_s->rsnxe_override_assoc);
8513 wpa_s->rsnxe_override_assoc = NULL;
8514 wpabuf_free(wpa_s->rsnxe_override_eapol);
8515 wpa_s->rsnxe_override_eapol = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008516 wpas_clear_driver_signal_override(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -07008517 wpa_s->oci_freq_override_eapol = 0;
8518 wpa_s->oci_freq_override_saquery_req = 0;
8519 wpa_s->oci_freq_override_saquery_resp = 0;
8520 wpa_s->oci_freq_override_eapol_g2 = 0;
8521 wpa_s->oci_freq_override_ft_assoc = 0;
8522 wpa_s->oci_freq_override_fils_assoc = 0;
8523 wpa_s->oci_freq_override_wnm_sleep = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008524#ifdef CONFIG_DPP
8525 os_free(wpa_s->dpp_config_obj_override);
8526 wpa_s->dpp_config_obj_override = NULL;
8527 os_free(wpa_s->dpp_discovery_override);
8528 wpa_s->dpp_discovery_override = NULL;
8529 os_free(wpa_s->dpp_groups_override);
8530 wpa_s->dpp_groups_override = NULL;
8531 dpp_test = DPP_TEST_DISABLED;
8532#endif /* CONFIG_DPP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008533#endif /* CONFIG_TESTING_OPTIONS */
8534
8535 wpa_s->disconnected = 0;
8536 os_free(wpa_s->next_scan_freqs);
8537 wpa_s->next_scan_freqs = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008538 os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN);
8539 wpa_s->next_scan_bssid_wildcard_ssid = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008540 os_free(wpa_s->select_network_scan_freqs);
8541 wpa_s->select_network_scan_freqs = NULL;
Hai Shalom899fcc72020-10-19 14:38:18 -07008542 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008543
8544 wpa_bss_flush(wpa_s);
8545 if (!dl_list_empty(&wpa_s->bss)) {
8546 wpa_printf(MSG_DEBUG,
8547 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8548 MACSTR " pending_bssid=" MACSTR,
8549 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
8550 MAC2STR(wpa_s->bssid),
8551 MAC2STR(wpa_s->pending_bssid));
8552 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008553
8554 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -08008555 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008556
8557#ifdef CONFIG_SME
8558 wpa_s->sme.last_unprot_disconnect.sec = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008559 wpa_s->sme.auth_alg = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008560#endif /* CONFIG_SME */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008561
8562 wpabuf_free(wpa_s->ric_ies);
8563 wpa_s->ric_ies = NULL;
Hai Shalom74f70d42019-02-11 14:42:39 -08008564
8565 wpa_supplicant_update_channel_list(wpa_s, NULL);
8566
8567 free_bss_tmp_disallowed(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -07008568
8569 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Hai Shalom60840252021-02-19 19:02:11 -08008570
8571#ifdef CONFIG_PASN
8572 wpas_pasn_auth_stop(wpa_s);
8573#endif /* CONFIG_PASN */
8574
8575 if (wpa_s->mac_addr_changed && wpa_s->conf->mac_addr == 0)
8576 wpas_restore_permanent_mac_addr(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008577}
8578
8579
8580static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
8581 char *buf, size_t buflen)
8582{
8583 struct wpa_radio_work *work;
8584 char *pos, *end;
8585 struct os_reltime now, diff;
8586
8587 pos = buf;
8588 end = buf + buflen;
8589
8590 os_get_reltime(&now);
8591
8592 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8593 {
8594 int ret;
8595
8596 os_reltime_sub(&now, &work->time, &diff);
8597 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
8598 work->type, work->wpa_s->ifname, work->freq,
8599 work->started, diff.sec, diff.usec);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008600 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008601 break;
8602 pos += ret;
8603 }
8604
8605 return pos - buf;
8606}
8607
8608
8609static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
8610{
8611 struct wpa_radio_work *work = eloop_ctx;
8612 struct wpa_external_work *ework = work->ctx;
8613
8614 wpa_dbg(work->wpa_s, MSG_DEBUG,
8615 "Timing out external radio work %u (%s)",
8616 ework->id, work->type);
8617 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008618 work->wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008619 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008620 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008621}
8622
8623
8624static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
8625{
8626 struct wpa_external_work *ework = work->ctx;
8627
8628 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008629 if (work->started)
8630 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8631 work, NULL);
8632
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008633 /*
8634 * work->type points to a buffer in ework, so need to replace
8635 * that here with a fixed string to avoid use of freed memory
8636 * in debug prints.
8637 */
8638 work->type = "freed-ext-work";
8639 work->ctx = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008640 os_free(ework);
8641 return;
8642 }
8643
8644 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
8645 ework->id, ework->type);
8646 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008647 work->wpa_s->ext_work_in_progress = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008648 if (!ework->timeout)
8649 ework->timeout = 10;
8650 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
8651 work, NULL);
8652}
8653
8654
8655static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
8656 char *buf, size_t buflen)
8657{
8658 struct wpa_external_work *ework;
8659 char *pos, *pos2;
8660 size_t type_len;
8661 int ret;
8662 unsigned int freq = 0;
8663
8664 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8665
8666 ework = os_zalloc(sizeof(*ework));
8667 if (ework == NULL)
8668 return -1;
8669
8670 pos = os_strchr(cmd, ' ');
8671 if (pos) {
8672 type_len = pos - cmd;
8673 pos++;
8674
8675 pos2 = os_strstr(pos, "freq=");
8676 if (pos2)
8677 freq = atoi(pos2 + 5);
8678
8679 pos2 = os_strstr(pos, "timeout=");
8680 if (pos2)
8681 ework->timeout = atoi(pos2 + 8);
8682 } else {
8683 type_len = os_strlen(cmd);
8684 }
8685 if (4 + type_len >= sizeof(ework->type))
8686 type_len = sizeof(ework->type) - 4 - 1;
8687 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
8688 os_memcpy(ework->type + 4, cmd, type_len);
8689 ework->type[4 + type_len] = '\0';
8690
8691 wpa_s->ext_work_id++;
8692 if (wpa_s->ext_work_id == 0)
8693 wpa_s->ext_work_id++;
8694 ework->id = wpa_s->ext_work_id;
8695
8696 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
8697 ework) < 0) {
8698 os_free(ework);
8699 return -1;
8700 }
8701
8702 ret = os_snprintf(buf, buflen, "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008703 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008704 return -1;
8705 return ret;
8706}
8707
8708
8709static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
8710{
8711 struct wpa_radio_work *work;
8712 unsigned int id = atoi(cmd);
8713
8714 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8715 {
8716 struct wpa_external_work *ework;
8717
8718 if (os_strncmp(work->type, "ext:", 4) != 0)
8719 continue;
8720 ework = work->ctx;
8721 if (id && ework->id != id)
8722 continue;
8723 wpa_dbg(wpa_s, MSG_DEBUG,
8724 "Completed external radio work %u (%s)",
8725 ework->id, ework->type);
8726 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008727 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008728 radio_work_done(work);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07008729 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008730 return 3; /* "OK\n" */
8731 }
8732
8733 return -1;
8734}
8735
8736
8737static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
8738 char *buf, size_t buflen)
8739{
8740 if (os_strcmp(cmd, "show") == 0)
8741 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
8742 if (os_strncmp(cmd, "add ", 4) == 0)
8743 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
8744 if (os_strncmp(cmd, "done ", 5) == 0)
8745 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
8746 return -1;
8747}
8748
8749
8750void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
8751{
8752 struct wpa_radio_work *work, *tmp;
8753
Dmitry Shmidt18463232014-01-24 12:29:41 -08008754 if (!wpa_s || !wpa_s->radio)
8755 return;
8756
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008757 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
8758 struct wpa_radio_work, list) {
8759 struct wpa_external_work *ework;
8760
8761 if (os_strncmp(work->type, "ext:", 4) != 0)
8762 continue;
8763 ework = work->ctx;
8764 wpa_dbg(wpa_s, MSG_DEBUG,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07008765 "Flushing%s external radio work %u (%s)",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008766 work->started ? " started" : "", ework->id,
8767 ework->type);
8768 if (work->started)
8769 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8770 work, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008771 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008772 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008773 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008774}
8775
8776
Dmitry Shmidt051af732013-10-22 13:52:46 -07008777static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
8778{
8779 struct wpa_supplicant *wpa_s = eloop_ctx;
8780 eapol_sm_notify_ctrl_response(wpa_s->eapol);
8781}
8782
8783
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008784static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
8785 unsigned int *scan_id_count, int scan_id[])
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008786{
8787 const char *pos = value;
8788
8789 while (pos) {
8790 if (*pos == ' ' || *pos == '\0')
8791 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008792 if (*scan_id_count == MAX_SCAN_ID)
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008793 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008794 scan_id[(*scan_id_count)++] = atoi(pos);
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008795 pos = os_strchr(pos, ',');
8796 if (pos)
8797 pos++;
8798 }
8799
8800 return 0;
8801}
8802
8803
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008804static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
8805 char *reply, int reply_size, int *reply_len)
8806{
8807 char *pos;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008808 unsigned int manual_scan_passive = 0;
8809 unsigned int manual_scan_use_id = 0;
8810 unsigned int manual_scan_only_new = 0;
8811 unsigned int scan_only = 0;
8812 unsigned int scan_id_count = 0;
8813 int scan_id[MAX_SCAN_ID];
8814 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
8815 struct wpa_scan_results *scan_res);
8816 int *manual_scan_freqs = NULL;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008817 struct wpa_ssid_value *ssid = NULL, *ns;
8818 unsigned int ssid_count = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008819
8820 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
8821 *reply_len = -1;
8822 return;
8823 }
8824
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008825 if (radio_work_pending(wpa_s, "scan")) {
8826 wpa_printf(MSG_DEBUG,
8827 "Pending scan scheduled - reject new request");
8828 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8829 return;
8830 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008831
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008832#ifdef CONFIG_INTERWORKING
8833 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
8834 wpa_printf(MSG_DEBUG,
8835 "Interworking select in progress - reject new scan");
8836 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8837 return;
8838 }
8839#endif /* CONFIG_INTERWORKING */
8840
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008841 if (params) {
8842 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008843 scan_only = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008844
8845 pos = os_strstr(params, "freq=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008846 if (pos) {
8847 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
8848 pos + 5);
8849 if (manual_scan_freqs == NULL) {
8850 *reply_len = -1;
8851 goto done;
8852 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008853 }
8854
8855 pos = os_strstr(params, "passive=");
8856 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008857 manual_scan_passive = !!atoi(pos + 8);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008858
8859 pos = os_strstr(params, "use_id=");
8860 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008861 manual_scan_use_id = atoi(pos + 7);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008862
8863 pos = os_strstr(params, "only_new=1");
8864 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008865 manual_scan_only_new = 1;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008866
8867 pos = os_strstr(params, "scan_id=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008868 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
8869 scan_id) < 0) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008870 *reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008871 goto done;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008872 }
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008873
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008874 pos = os_strstr(params, "bssid=");
8875 if (pos) {
8876 u8 bssid[ETH_ALEN];
8877
8878 pos += 6;
8879 if (hwaddr_aton(pos, bssid)) {
8880 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
8881 *reply_len = -1;
8882 goto done;
8883 }
8884 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
Hai Shalomfdcde762020-04-02 11:19:20 -07008885
8886 wpa_s->next_scan_bssid_wildcard_ssid =
8887 os_strstr(params, "wildcard_ssid=1") != NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008888 }
8889
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008890 pos = params;
8891 while (pos && *pos != '\0') {
8892 if (os_strncmp(pos, "ssid ", 5) == 0) {
8893 char *end;
8894
8895 pos += 5;
8896 end = pos;
8897 while (*end) {
8898 if (*end == '\0' || *end == ' ')
8899 break;
8900 end++;
8901 }
8902
8903 ns = os_realloc_array(
8904 ssid, ssid_count + 1,
8905 sizeof(struct wpa_ssid_value));
8906 if (ns == NULL) {
8907 *reply_len = -1;
8908 goto done;
8909 }
8910 ssid = ns;
8911
8912 if ((end - pos) & 0x01 ||
8913 end - pos > 2 * SSID_MAX_LEN ||
8914 hexstr2bin(pos, ssid[ssid_count].ssid,
8915 (end - pos) / 2) < 0) {
8916 wpa_printf(MSG_DEBUG,
8917 "Invalid SSID value '%s'",
8918 pos);
8919 *reply_len = -1;
8920 goto done;
8921 }
8922 ssid[ssid_count].ssid_len = (end - pos) / 2;
8923 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
8924 ssid[ssid_count].ssid,
8925 ssid[ssid_count].ssid_len);
8926 ssid_count++;
8927 pos = end;
8928 }
8929
8930 pos = os_strchr(pos, ' ');
8931 if (pos)
8932 pos++;
8933 }
8934 }
8935
8936 wpa_s->num_ssids_from_scan_req = ssid_count;
8937 os_free(wpa_s->ssids_from_scan_req);
8938 if (ssid_count) {
8939 wpa_s->ssids_from_scan_req = ssid;
8940 ssid = NULL;
8941 } else {
8942 wpa_s->ssids_from_scan_req = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008943 }
8944
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008945 if (scan_only)
8946 scan_res_handler = scan_only_handler;
8947 else if (wpa_s->scan_res_handler == scan_only_handler)
8948 scan_res_handler = NULL;
8949 else
8950 scan_res_handler = wpa_s->scan_res_handler;
8951
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008952 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
8953 ((wpa_s->wpa_state <= WPA_SCANNING) ||
8954 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008955 wpa_s->manual_scan_passive = manual_scan_passive;
8956 wpa_s->manual_scan_use_id = manual_scan_use_id;
8957 wpa_s->manual_scan_only_new = manual_scan_only_new;
8958 wpa_s->scan_id_count = scan_id_count;
8959 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8960 wpa_s->scan_res_handler = scan_res_handler;
8961 os_free(wpa_s->manual_scan_freqs);
8962 wpa_s->manual_scan_freqs = manual_scan_freqs;
8963 manual_scan_freqs = NULL;
8964
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008965 wpa_s->normal_scans = 0;
8966 wpa_s->scan_req = MANUAL_SCAN_REQ;
8967 wpa_s->after_wps = 0;
8968 wpa_s->known_wps_freq = 0;
8969 wpa_supplicant_req_scan(wpa_s, 0, 0);
8970 if (wpa_s->manual_scan_use_id) {
8971 wpa_s->manual_scan_id++;
8972 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8973 wpa_s->manual_scan_id);
8974 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8975 wpa_s->manual_scan_id);
8976 }
8977 } else if (wpa_s->sched_scanning) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008978 wpa_s->manual_scan_passive = manual_scan_passive;
8979 wpa_s->manual_scan_use_id = manual_scan_use_id;
8980 wpa_s->manual_scan_only_new = manual_scan_only_new;
8981 wpa_s->scan_id_count = scan_id_count;
8982 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8983 wpa_s->scan_res_handler = scan_res_handler;
8984 os_free(wpa_s->manual_scan_freqs);
8985 wpa_s->manual_scan_freqs = manual_scan_freqs;
8986 manual_scan_freqs = NULL;
8987
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008988 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
8989 wpa_supplicant_cancel_sched_scan(wpa_s);
8990 wpa_s->scan_req = MANUAL_SCAN_REQ;
8991 wpa_supplicant_req_scan(wpa_s, 0, 0);
8992 if (wpa_s->manual_scan_use_id) {
8993 wpa_s->manual_scan_id++;
8994 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8995 wpa_s->manual_scan_id);
8996 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8997 wpa_s->manual_scan_id);
8998 }
8999 } else {
9000 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
9001 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
9002 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009003
9004done:
9005 os_free(manual_scan_freqs);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07009006 os_free(ssid);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009007}
9008
9009
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009010#ifdef CONFIG_TESTING_OPTIONS
9011
9012static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
9013 unsigned int freq, const u8 *dst,
9014 const u8 *src, const u8 *bssid,
9015 const u8 *data, size_t data_len,
9016 enum offchannel_send_action_result
9017 result)
9018{
9019 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
9020 " src=" MACSTR " bssid=" MACSTR " result=%s",
9021 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
9022 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
9023 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
9024 "NO_ACK" : "FAILED"));
9025}
9026
9027
9028static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
9029{
9030 char *pos, *param;
9031 size_t len;
9032 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
9033 int res, used;
9034 int freq = 0, no_cck = 0, wait_time = 0;
9035
9036 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
9037 * <action=Action frame payload> */
9038
9039 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
9040
9041 pos = cmd;
9042 used = hwaddr_aton2(pos, da);
9043 if (used < 0)
9044 return -1;
9045 pos += used;
9046 while (*pos == ' ')
9047 pos++;
9048 used = hwaddr_aton2(pos, bssid);
9049 if (used < 0)
9050 return -1;
9051 pos += used;
9052
9053 param = os_strstr(pos, " freq=");
9054 if (param) {
9055 param += 6;
9056 freq = atoi(param);
9057 }
9058
9059 param = os_strstr(pos, " no_cck=");
9060 if (param) {
9061 param += 8;
9062 no_cck = atoi(param);
9063 }
9064
9065 param = os_strstr(pos, " wait_time=");
9066 if (param) {
9067 param += 11;
9068 wait_time = atoi(param);
9069 }
9070
9071 param = os_strstr(pos, " action=");
9072 if (param == NULL)
9073 return -1;
9074 param += 8;
9075
9076 len = os_strlen(param);
9077 if (len & 1)
9078 return -1;
9079 len /= 2;
9080
9081 buf = os_malloc(len);
9082 if (buf == NULL)
9083 return -1;
9084
9085 if (hexstr2bin(param, buf, len) < 0) {
9086 os_free(buf);
9087 return -1;
9088 }
9089
9090 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
9091 buf, len, wait_time,
9092 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
9093 os_free(buf);
9094 return res;
9095}
9096
9097
9098static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
9099{
9100 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
9101 offchannel_send_action_done(wpa_s);
9102}
9103
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009104
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009105static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
9106 char *cmd)
9107{
9108 char *pos, *param;
9109 size_t len;
9110 u8 *buf;
9111 int freq = 0, datarate = 0, ssi_signal = 0;
9112 union wpa_event_data event;
9113
9114 if (!wpa_s->ext_mgmt_frame_handling)
9115 return -1;
9116
9117 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
9118
9119 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
9120
9121 pos = cmd;
9122 param = os_strstr(pos, "freq=");
9123 if (param) {
9124 param += 5;
9125 freq = atoi(param);
9126 }
9127
9128 param = os_strstr(pos, " datarate=");
9129 if (param) {
9130 param += 10;
9131 datarate = atoi(param);
9132 }
9133
9134 param = os_strstr(pos, " ssi_signal=");
9135 if (param) {
9136 param += 12;
9137 ssi_signal = atoi(param);
9138 }
9139
9140 param = os_strstr(pos, " frame=");
9141 if (param == NULL)
9142 return -1;
9143 param += 7;
9144
9145 len = os_strlen(param);
9146 if (len & 1)
9147 return -1;
9148 len /= 2;
9149
9150 buf = os_malloc(len);
9151 if (buf == NULL)
9152 return -1;
9153
9154 if (hexstr2bin(param, buf, len) < 0) {
9155 os_free(buf);
9156 return -1;
9157 }
9158
9159 os_memset(&event, 0, sizeof(event));
9160 event.rx_mgmt.freq = freq;
9161 event.rx_mgmt.frame = buf;
9162 event.rx_mgmt.frame_len = len;
9163 event.rx_mgmt.ssi_signal = ssi_signal;
9164 event.rx_mgmt.datarate = datarate;
9165 wpa_s->ext_mgmt_frame_handling = 0;
9166 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
9167 wpa_s->ext_mgmt_frame_handling = 1;
9168
9169 os_free(buf);
9170
9171 return 0;
9172}
9173
9174
Paul Stewart092955c2017-02-06 09:13:09 -08009175static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
9176 char *param)
9177{
9178 struct wpa_scan_res *res;
9179 struct os_reltime now;
9180 char *pos, *end;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009181 int ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08009182
9183 if (!param)
9184 return -1;
9185
9186 if (os_strcmp(param, "START") == 0) {
9187 wpa_bss_update_start(wpa_s);
9188 return 0;
9189 }
9190
9191 if (os_strcmp(param, "END") == 0) {
9192 wpa_bss_update_end(wpa_s, NULL, 1);
9193 return 0;
9194 }
9195
9196 if (os_strncmp(param, "BSS ", 4) != 0)
9197 return -1;
9198 param += 3;
9199
9200 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
9201 if (!res)
9202 return -1;
9203
9204 pos = os_strstr(param, " flags=");
9205 if (pos)
9206 res->flags = strtol(pos + 7, NULL, 16);
9207
9208 pos = os_strstr(param, " bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009209 if (pos && hwaddr_aton(pos + 7, res->bssid))
9210 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009211
9212 pos = os_strstr(param, " freq=");
9213 if (pos)
9214 res->freq = atoi(pos + 6);
9215
9216 pos = os_strstr(param, " beacon_int=");
9217 if (pos)
9218 res->beacon_int = atoi(pos + 12);
9219
9220 pos = os_strstr(param, " caps=");
9221 if (pos)
9222 res->caps = strtol(pos + 6, NULL, 16);
9223
9224 pos = os_strstr(param, " qual=");
9225 if (pos)
9226 res->qual = atoi(pos + 6);
9227
9228 pos = os_strstr(param, " noise=");
9229 if (pos)
9230 res->noise = atoi(pos + 7);
9231
9232 pos = os_strstr(param, " level=");
9233 if (pos)
9234 res->level = atoi(pos + 7);
9235
9236 pos = os_strstr(param, " tsf=");
9237 if (pos)
9238 res->tsf = strtoll(pos + 5, NULL, 16);
9239
9240 pos = os_strstr(param, " age=");
9241 if (pos)
9242 res->age = atoi(pos + 5);
9243
9244 pos = os_strstr(param, " est_throughput=");
9245 if (pos)
9246 res->est_throughput = atoi(pos + 16);
9247
9248 pos = os_strstr(param, " snr=");
9249 if (pos)
9250 res->snr = atoi(pos + 5);
9251
9252 pos = os_strstr(param, " parent_tsf=");
9253 if (pos)
9254 res->parent_tsf = strtoll(pos + 7, NULL, 16);
9255
9256 pos = os_strstr(param, " tsf_bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009257 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
9258 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009259
9260 pos = os_strstr(param, " ie=");
9261 if (pos) {
9262 pos += 4;
9263 end = os_strchr(pos, ' ');
9264 if (!end)
9265 end = pos + os_strlen(pos);
9266 res->ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009267 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
9268 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009269 }
9270
9271 pos = os_strstr(param, " beacon_ie=");
9272 if (pos) {
9273 pos += 11;
9274 end = os_strchr(pos, ' ');
9275 if (!end)
9276 end = pos + os_strlen(pos);
9277 res->beacon_ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009278 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
9279 res->beacon_ie_len))
9280 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009281 }
9282
9283 os_get_reltime(&now);
9284 wpa_bss_update_scan_res(wpa_s, res, &now);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009285 ret = 0;
9286fail:
Paul Stewart092955c2017-02-06 09:13:09 -08009287 os_free(res);
9288
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009289 return ret;
Paul Stewart092955c2017-02-06 09:13:09 -08009290}
9291
9292
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009293static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
9294{
9295 char *pos, *param;
9296 union wpa_event_data event;
9297 enum wpa_event_type ev;
9298
9299 /* <event name> [parameters..] */
9300
9301 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
9302
9303 pos = cmd;
9304 param = os_strchr(pos, ' ');
9305 if (param)
9306 *param++ = '\0';
9307
9308 os_memset(&event, 0, sizeof(event));
9309
9310 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
9311 ev = EVENT_INTERFACE_ENABLED;
9312 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
9313 ev = EVENT_INTERFACE_DISABLED;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07009314 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
9315 ev = EVENT_AVOID_FREQUENCIES;
9316 if (param == NULL)
9317 param = "";
9318 if (freq_range_list_parse(&event.freq_range, param) < 0)
9319 return -1;
9320 wpa_supplicant_event(wpa_s, ev, &event);
9321 os_free(event.freq_range.range);
9322 return 0;
Paul Stewart092955c2017-02-06 09:13:09 -08009323 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
9324 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009325 } else {
9326 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
9327 cmd);
9328 return -1;
9329 }
9330
9331 wpa_supplicant_event(wpa_s, ev, &event);
9332
9333 return 0;
9334}
9335
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009336
9337static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
9338{
9339 char *pos;
9340 u8 src[ETH_ALEN], *buf;
9341 int used;
9342 size_t len;
9343
9344 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
9345
9346 pos = cmd;
9347 used = hwaddr_aton2(pos, src);
9348 if (used < 0)
9349 return -1;
9350 pos += used;
9351 while (*pos == ' ')
9352 pos++;
9353
9354 len = os_strlen(pos);
9355 if (len & 1)
9356 return -1;
9357 len /= 2;
9358
9359 buf = os_malloc(len);
9360 if (buf == NULL)
9361 return -1;
9362
9363 if (hexstr2bin(pos, buf, len) < 0) {
9364 os_free(buf);
9365 return -1;
9366 }
9367
9368 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
9369 os_free(buf);
9370
9371 return 0;
9372}
9373
9374
9375static u16 ipv4_hdr_checksum(const void *buf, size_t len)
9376{
9377 size_t i;
9378 u32 sum = 0;
9379 const u16 *pos = buf;
9380
9381 for (i = 0; i < len / 2; i++)
9382 sum += *pos++;
9383
9384 while (sum >> 16)
9385 sum = (sum & 0xffff) + (sum >> 16);
9386
9387 return sum ^ 0xffff;
9388}
9389
9390
9391#define HWSIM_PACKETLEN 1500
9392#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
9393
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07009394static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
9395 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009396{
9397 struct wpa_supplicant *wpa_s = ctx;
9398 const struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07009399 struct ip ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009400 const u8 *pos;
9401 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08009402 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009403
Hai Shalom74f70d42019-02-11 14:42:39 -08009404 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
9405 wpa_printf(MSG_DEBUG,
9406 "test data: RX - ignore unexpected length %d",
9407 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009408 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08009409 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009410
9411 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009412 os_memcpy(&ip, eth + 1, sizeof(ip));
9413 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009414
Hai Shalomfdcde762020-04-02 11:19:20 -07009415 if (ip.ip_hl != 5 || ip.ip_v != 4 || ntohs(ip.ip_len) > HWSIM_IP_LEN) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009416 wpa_printf(MSG_DEBUG,
Hai Shalom899fcc72020-10-19 14:38:18 -07009417 "test data: RX - ignore unexpected IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009418 return;
Hai Shalom39bc25d2019-02-06 16:32:13 -08009419 }
Hai Shalombf6e0ba2019-02-11 12:01:50 -08009420
Hai Shalomfdcde762020-04-02 11:19:20 -07009421 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009422 if (*pos != (u8) i) {
9423 wpa_printf(MSG_DEBUG,
9424 "test data: RX - ignore mismatching payload");
9425 return;
9426 }
9427 pos++;
9428 }
9429 extra[0] = '\0';
Hai Shalomfdcde762020-04-02 11:19:20 -07009430 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
9431 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
Hai Shalom74f70d42019-02-11 14:42:39 -08009432 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
9433 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009434}
9435
9436
9437static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
9438 char *cmd)
9439{
9440 int enabled = atoi(cmd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009441 char *pos;
9442 const char *ifname;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009443
9444 if (!enabled) {
9445 if (wpa_s->l2_test) {
9446 l2_packet_deinit(wpa_s->l2_test);
9447 wpa_s->l2_test = NULL;
9448 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
9449 }
9450 return 0;
9451 }
9452
9453 if (wpa_s->l2_test)
9454 return 0;
9455
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009456 pos = os_strstr(cmd, " ifname=");
9457 if (pos)
9458 ifname = pos + 8;
9459 else
9460 ifname = wpa_s->ifname;
9461
9462 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009463 ETHERTYPE_IP, wpas_data_test_rx,
9464 wpa_s, 1);
9465 if (wpa_s->l2_test == NULL)
9466 return -1;
9467
9468 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
9469
9470 return 0;
9471}
9472
9473
9474static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
9475{
9476 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom74f70d42019-02-11 14:42:39 -08009477 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009478 int used;
9479 long int val;
9480 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009481 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009482 struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07009483 struct ip *ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009484 u8 *dpos;
9485 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08009486 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009487
9488 if (wpa_s->l2_test == NULL)
9489 return -1;
9490
Hai Shalom74f70d42019-02-11 14:42:39 -08009491 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009492
9493 pos = cmd;
9494 used = hwaddr_aton2(pos, dst);
9495 if (used < 0)
9496 return -1;
9497 pos += used;
9498 while (*pos == ' ')
9499 pos++;
9500 used = hwaddr_aton2(pos, src);
9501 if (used < 0)
9502 return -1;
9503 pos += used;
9504
Hai Shalom74f70d42019-02-11 14:42:39 -08009505 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009506 if (val < 0 || val > 0xff)
9507 return -1;
9508 tos = val;
9509
Hai Shalom74f70d42019-02-11 14:42:39 -08009510 pos = os_strstr(pos2, " len=");
9511 if (pos) {
9512 i = atoi(pos + 5);
9513 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
9514 return -1;
9515 send_len = i;
9516 }
9517
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009518 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009519 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
9520 os_memcpy(eth->ether_shost, src, ETH_ALEN);
9521 eth->ether_type = htons(ETHERTYPE_IP);
Hai Shalomfdcde762020-04-02 11:19:20 -07009522 ip = (struct ip *) (eth + 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009523 os_memset(ip, 0, sizeof(*ip));
Hai Shalomfdcde762020-04-02 11:19:20 -07009524 ip->ip_hl = 5;
9525 ip->ip_v = 4;
9526 ip->ip_ttl = 64;
9527 ip->ip_tos = tos;
9528 ip->ip_len = htons(send_len);
9529 ip->ip_p = 1;
9530 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
9531 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
9532 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009533 dpos = (u8 *) (ip + 1);
Hai Shalom74f70d42019-02-11 14:42:39 -08009534 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009535 *dpos++ = i;
9536
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009537 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom74f70d42019-02-11 14:42:39 -08009538 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009539 return -1;
9540
9541 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
9542 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
9543
9544 return 0;
9545}
9546
9547
9548static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
9549 char *cmd)
9550{
9551 u8 *buf;
9552 struct ether_header *eth;
9553 struct l2_packet_data *l2 = NULL;
9554 size_t len;
9555 u16 ethertype;
9556 int res = -1;
9557
9558 len = os_strlen(cmd);
9559 if (len & 1 || len < ETH_HLEN * 2)
9560 return -1;
9561 len /= 2;
9562
9563 buf = os_malloc(len);
9564 if (buf == NULL)
9565 return -1;
9566
9567 if (hexstr2bin(cmd, buf, len) < 0)
9568 goto done;
9569
9570 eth = (struct ether_header *) buf;
9571 ethertype = ntohs(eth->ether_type);
9572
9573 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
9574 wpas_data_test_rx, wpa_s, 1);
9575 if (l2 == NULL)
9576 goto done;
9577
9578 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
9579 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
9580done:
9581 if (l2)
9582 l2_packet_deinit(l2);
9583 os_free(buf);
9584
9585 return res < 0 ? -1 : 0;
9586}
9587
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009588
9589static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
9590{
9591#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009592 char *pos;
9593
9594 wpa_trace_fail_after = atoi(cmd);
9595 pos = os_strchr(cmd, ':');
9596 if (pos) {
9597 pos++;
9598 os_strlcpy(wpa_trace_fail_func, pos,
9599 sizeof(wpa_trace_fail_func));
9600 } else {
9601 wpa_trace_fail_after = 0;
9602 }
9603 return 0;
9604#else /* WPA_TRACE_BFD */
9605 return -1;
9606#endif /* WPA_TRACE_BFD */
9607}
9608
9609
9610static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
9611 char *buf, size_t buflen)
9612{
9613#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009614 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
9615 wpa_trace_fail_func);
9616#else /* WPA_TRACE_BFD */
9617 return -1;
9618#endif /* WPA_TRACE_BFD */
9619}
9620
Jouni Malinenc4818362015-10-04 11:45:13 +03009621
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009622static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
9623{
9624#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009625 char *pos;
9626
9627 wpa_trace_test_fail_after = atoi(cmd);
9628 pos = os_strchr(cmd, ':');
9629 if (pos) {
9630 pos++;
9631 os_strlcpy(wpa_trace_test_fail_func, pos,
9632 sizeof(wpa_trace_test_fail_func));
9633 } else {
9634 wpa_trace_test_fail_after = 0;
9635 }
9636 return 0;
9637#else /* WPA_TRACE_BFD */
9638 return -1;
9639#endif /* WPA_TRACE_BFD */
9640}
9641
9642
9643static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
9644 char *buf, size_t buflen)
9645{
9646#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009647 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
9648 wpa_trace_test_fail_func);
9649#else /* WPA_TRACE_BFD */
9650 return -1;
9651#endif /* WPA_TRACE_BFD */
9652}
9653
9654
Jouni Malinenc4818362015-10-04 11:45:13 +03009655static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
9656{
9657 struct wpa_supplicant *wpa_s = eloop_ctx;
9658 int i, count = (intptr_t) timeout_ctx;
9659
9660 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
9661 count);
9662 for (i = 0; i < count; i++) {
9663 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
9664 i + 1, count);
9665 }
9666}
9667
9668
9669static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
9670{
9671 int count;
9672
9673 count = atoi(cmd);
9674 if (count <= 0)
9675 return -1;
9676
9677 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
9678 (void *) (intptr_t) count);
9679}
9680
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009681
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009682static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
9683 const char *cmd)
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009684{
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009685 struct wpabuf *buf;
9686 size_t len;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009687
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009688 len = os_strlen(cmd);
9689 if (len & 1)
9690 return -1;
9691 len /= 2;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009692
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009693 if (len == 0) {
9694 buf = NULL;
9695 } else {
9696 buf = wpabuf_alloc(len);
9697 if (buf == NULL)
9698 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009699
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009700 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
9701 wpabuf_free(buf);
9702 return -1;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009703 }
9704 }
9705
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009706 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
9707 return 0;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009708}
9709
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009710
9711static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
9712{
9713 u8 zero[WPA_TK_MAX_LEN];
9714
9715 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
9716 return -1;
9717
9718 wpa_printf(MSG_INFO, "TESTING: Reset PN");
9719 os_memset(zero, 0, sizeof(zero));
9720
9721 /* First, use a zero key to avoid any possible duplicate key avoidance
9722 * in the driver. */
9723 if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9724 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -07009725 zero, wpa_s->last_tk_len,
9726 KEY_FLAG_PAIRWISE_RX_TX) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009727 return -1;
9728
9729 /* Set the previously configured key to reset its TSC/RSC */
9730 return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9731 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -07009732 wpa_s->last_tk, wpa_s->last_tk_len,
9733 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009734}
9735
9736
9737static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
9738{
9739 const char *pos = cmd;
9740 int error, pairwise;
9741
9742 error = atoi(pos);
9743 pos = os_strchr(pos, ' ');
9744 if (!pos)
9745 return -1;
9746 pairwise = atoi(pos);
9747 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
9748 return 0;
9749}
9750
9751
9752static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
9753{
9754#ifdef CONFIG_SME
9755 struct wpa_driver_associate_params params;
9756 int ret;
9757
9758 os_memset(&params, 0, sizeof(params));
9759 params.bssid = wpa_s->bssid;
9760 params.ssid = wpa_s->sme.ssid;
9761 params.ssid_len = wpa_s->sme.ssid_len;
9762 params.freq.freq = wpa_s->sme.freq;
9763 if (wpa_s->last_assoc_req_wpa_ie) {
9764 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
9765 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
9766 }
9767 params.pairwise_suite = wpa_s->pairwise_cipher;
9768 params.group_suite = wpa_s->group_cipher;
9769 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
9770 params.key_mgmt_suite = wpa_s->key_mgmt;
9771 params.wpa_proto = wpa_s->wpa_proto;
9772 params.mgmt_frame_protection = wpa_s->sme.mfp;
9773 params.rrm_used = wpa_s->rrm.rrm_used;
9774 if (wpa_s->sme.prev_bssid_set)
9775 params.prev_bssid = wpa_s->sme.prev_bssid;
9776 wpa_printf(MSG_INFO, "TESTING: Resend association request");
9777 ret = wpa_drv_associate(wpa_s, &params);
9778 wpa_s->testing_resend_assoc = 1;
9779 return ret;
9780#else /* CONFIG_SME */
9781 return -1;
9782#endif /* CONFIG_SME */
9783}
9784
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009785#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009786
9787
9788static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
9789{
9790 char *pos = cmd;
9791 int frame;
9792 size_t len;
9793 struct wpabuf *buf;
9794 struct ieee802_11_elems elems;
9795
9796 frame = atoi(pos);
9797 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9798 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009799 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009800
9801 pos = os_strchr(pos, ' ');
9802 if (pos == NULL)
9803 return -1;
9804 pos++;
9805
9806 len = os_strlen(pos);
9807 if (len == 0)
9808 return 0;
9809 if (len & 1)
9810 return -1;
9811 len /= 2;
9812
9813 buf = wpabuf_alloc(len);
9814 if (buf == NULL)
9815 return -1;
9816
9817 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
9818 wpabuf_free(buf);
9819 return -1;
9820 }
9821
9822 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
9823 ParseFailed) {
9824 wpabuf_free(buf);
9825 return -1;
9826 }
9827
9828 if (wpa_s->vendor_elem[frame] == NULL) {
9829 wpa_s->vendor_elem[frame] = buf;
Hai Shalom60840252021-02-19 19:02:11 -08009830 goto update_ies;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009831 }
9832
9833 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
9834 wpabuf_free(buf);
9835 return -1;
9836 }
9837
9838 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
9839 wpabuf_free(buf);
Hai Shalom60840252021-02-19 19:02:11 -08009840
9841update_ies:
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009842 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009843
Hai Shalom60840252021-02-19 19:02:11 -08009844 if (frame == VENDOR_ELEM_PROBE_REQ ||
9845 frame == VENDOR_ELEM_PROBE_REQ_P2P)
9846 wpa_supplicant_set_default_scan_ies(wpa_s);
9847
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009848 return 0;
9849}
9850
9851
9852static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
9853 char *buf, size_t buflen)
9854{
9855 int frame = atoi(cmd);
9856
9857 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9858 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009859 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009860
9861 if (wpa_s->vendor_elem[frame] == NULL)
9862 return 0;
9863
9864 return wpa_snprintf_hex(buf, buflen,
9865 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
9866 wpabuf_len(wpa_s->vendor_elem[frame]));
9867}
9868
9869
9870static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
9871{
9872 char *pos = cmd;
9873 int frame;
9874 size_t len;
9875 u8 *buf;
9876 struct ieee802_11_elems elems;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009877 int res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009878
9879 frame = atoi(pos);
9880 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9881 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009882 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009883
9884 pos = os_strchr(pos, ' ');
9885 if (pos == NULL)
9886 return -1;
9887 pos++;
9888
9889 if (*pos == '*') {
9890 wpabuf_free(wpa_s->vendor_elem[frame]);
9891 wpa_s->vendor_elem[frame] = NULL;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009892 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009893 return 0;
9894 }
9895
9896 if (wpa_s->vendor_elem[frame] == NULL)
9897 return -1;
9898
9899 len = os_strlen(pos);
9900 if (len == 0)
9901 return 0;
9902 if (len & 1)
9903 return -1;
9904 len /= 2;
9905
9906 buf = os_malloc(len);
9907 if (buf == NULL)
9908 return -1;
9909
9910 if (hexstr2bin(pos, buf, len) < 0) {
9911 os_free(buf);
9912 return -1;
9913 }
9914
9915 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
9916 os_free(buf);
9917 return -1;
9918 }
9919
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009920 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009921 os_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009922 return res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009923}
9924
9925
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009926static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
9927{
9928 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009929 size_t len;
9930 const u8 *data;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009931
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009932 /*
9933 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9934 * BSSID[6]
9935 * BSSID Information[4]
9936 * Operating Class[1]
9937 * Channel Number[1]
9938 * PHY Type[1]
9939 * Optional Subelements[variable]
9940 */
9941#define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9942
9943 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009944 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009945 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009946 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009947
9948 data = wpabuf_head_u8(neighbor_rep);
9949 len = wpabuf_len(neighbor_rep);
9950
9951 while (len >= 2 + NR_IE_MIN_LEN) {
9952 const u8 *nr;
9953 char lci[256 * 2 + 1];
9954 char civic[256 * 2 + 1];
9955 u8 nr_len = data[1];
9956 const u8 *pos = data, *end;
9957
9958 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
9959 nr_len < NR_IE_MIN_LEN) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08009960 wpa_dbg(wpa_s, MSG_DEBUG,
9961 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9962 data[0], nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009963 goto out;
9964 }
9965
9966 if (2U + nr_len > len) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08009967 wpa_dbg(wpa_s, MSG_DEBUG,
9968 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9969 data[0], len, nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009970 goto out;
9971 }
9972 pos += 2;
9973 end = pos + nr_len;
9974
9975 nr = pos;
9976 pos += NR_IE_MIN_LEN;
9977
9978 lci[0] = '\0';
9979 civic[0] = '\0';
9980 while (end - pos > 2) {
9981 u8 s_id, s_len;
9982
9983 s_id = *pos++;
9984 s_len = *pos++;
9985 if (s_len > end - pos)
9986 goto out;
9987 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
9988 /* Measurement Token[1] */
9989 /* Measurement Report Mode[1] */
9990 /* Measurement Type[1] */
9991 /* Measurement Report[variable] */
9992 switch (pos[2]) {
9993 case MEASURE_TYPE_LCI:
9994 if (lci[0])
9995 break;
9996 wpa_snprintf_hex(lci, sizeof(lci),
9997 pos, s_len);
9998 break;
9999 case MEASURE_TYPE_LOCATION_CIVIC:
10000 if (civic[0])
10001 break;
10002 wpa_snprintf_hex(civic, sizeof(civic),
10003 pos, s_len);
10004 break;
10005 }
10006 }
10007
10008 pos += s_len;
10009 }
10010
10011 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
10012 "bssid=" MACSTR
10013 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
10014 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
10015 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
10016 nr[ETH_ALEN + 6],
10017 lci[0] ? " lci=" : "", lci,
10018 civic[0] ? " civic=" : "", civic);
10019
10020 data = end;
10021 len -= 2 + nr_len;
10022 }
10023
10024out:
10025 wpabuf_free(neighbor_rep);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010026}
10027
10028
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010029static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
10030 char *cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010031{
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010032 struct wpa_ssid_value ssid, *ssid_p = NULL;
10033 int ret, lci = 0, civic = 0;
10034 char *ssid_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010035
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010036 ssid_s = os_strstr(cmd, "ssid=");
10037 if (ssid_s) {
10038 if (ssid_parse(ssid_s + 5, &ssid)) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010039 wpa_msg(wpa_s, MSG_INFO,
10040 "CTRL: Send Neighbor Report: bad SSID");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010041 return -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010042 }
10043
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010044 ssid_p = &ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010045
10046 /*
10047 * Move cmd after the SSID text that may include "lci" or
10048 * "civic".
10049 */
10050 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
10051 if (cmd)
10052 cmd++;
10053
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010054 }
10055
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010056 if (cmd && os_strstr(cmd, "lci"))
10057 lci = 1;
10058
10059 if (cmd && os_strstr(cmd, "civic"))
10060 civic = 1;
10061
10062 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010063 wpas_ctrl_neighbor_rep_cb,
10064 wpa_s);
10065
10066 return ret;
10067}
10068
10069
10070static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
10071{
10072 eapol_sm_erp_flush(wpa_s->eapol);
10073 return 0;
10074}
10075
10076
10077static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
10078 char *cmd)
10079{
10080 char *token, *context = NULL;
10081 unsigned int enable = ~0, type = 0;
10082 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
10083 u8 *addr = NULL, *mask = NULL;
10084
10085 while ((token = str_token(cmd, " ", &context))) {
10086 if (os_strcasecmp(token, "scan") == 0) {
10087 type |= MAC_ADDR_RAND_SCAN;
10088 } else if (os_strcasecmp(token, "sched") == 0) {
10089 type |= MAC_ADDR_RAND_SCHED_SCAN;
10090 } else if (os_strcasecmp(token, "pno") == 0) {
10091 type |= MAC_ADDR_RAND_PNO;
10092 } else if (os_strcasecmp(token, "all") == 0) {
10093 type = wpa_s->mac_addr_rand_supported;
10094 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
10095 enable = atoi(token + 7);
10096 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
10097 addr = _addr;
10098 if (hwaddr_aton(token + 5, addr)) {
10099 wpa_printf(MSG_INFO,
10100 "CTRL: Invalid MAC address: %s",
10101 token);
10102 return -1;
10103 }
10104 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
10105 mask = _mask;
10106 if (hwaddr_aton(token + 5, mask)) {
10107 wpa_printf(MSG_INFO,
10108 "CTRL: Invalid MAC address mask: %s",
10109 token);
10110 return -1;
10111 }
10112 } else {
10113 wpa_printf(MSG_INFO,
10114 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
10115 token);
10116 return -1;
10117 }
10118 }
10119
10120 if (!type) {
10121 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
10122 return -1;
10123 }
10124
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010125 if (enable > 1) {
10126 wpa_printf(MSG_INFO,
10127 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
10128 return -1;
10129 }
10130
Hai Shalom81f62d82019-07-22 12:10:00 -070010131 if (!enable)
10132 return wpas_disable_mac_addr_randomization(wpa_s, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010133
Hai Shalom81f62d82019-07-22 12:10:00 -070010134 return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010135}
10136
10137
Dmitry Shmidte4663042016-04-04 10:07:49 -070010138static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
10139 char *buf, size_t buflen)
10140{
10141 size_t reply_len;
10142
10143 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
10144#ifdef CONFIG_AP
10145 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
10146 buflen - reply_len);
10147#endif /* CONFIG_AP */
10148 return reply_len;
10149}
10150
10151
10152static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
10153{
Hai Shalom60840252021-02-19 19:02:11 -080010154 ptksa_cache_flush(wpa_s->ptksa, NULL, WPA_CIPHER_NONE);
Dmitry Shmidte4663042016-04-04 10:07:49 -070010155 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
10156#ifdef CONFIG_AP
10157 wpas_ap_pmksa_cache_flush(wpa_s);
10158#endif /* CONFIG_AP */
10159}
10160
10161
Dmitry Shmidt29333592017-01-09 12:27:11 -080010162#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10163
10164static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
10165 const char *cmd, char *buf, size_t buflen)
10166{
10167 struct rsn_pmksa_cache_entry *entry;
10168 struct wpa_ssid *ssid;
10169 char *pos, *pos2, *end;
10170 int ret;
10171 struct os_reltime now;
10172
10173 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10174 if (!ssid)
10175 return -1;
10176
10177 pos = buf;
10178 end = buf + buflen;
10179
10180 os_get_reltime(&now);
10181
10182 /*
10183 * Entry format:
10184 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10185 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010186 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010187 */
10188
10189 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
10190 entry = entry->next) {
10191 if (entry->network_ctx != ssid)
10192 continue;
10193
10194 pos2 = pos;
10195 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
10196 MAC2STR(entry->aa));
10197 if (os_snprintf_error(end - pos2, ret))
10198 break;
10199 pos2 += ret;
10200
10201 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
10202 PMKID_LEN);
10203
10204 ret = os_snprintf(pos2, end - pos2, " ");
10205 if (os_snprintf_error(end - pos2, ret))
10206 break;
10207 pos2 += ret;
10208
10209 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
10210 entry->pmk_len);
10211
10212 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
10213 (int) (entry->reauth_time - now.sec),
10214 (int) (entry->expiration - now.sec),
10215 entry->akmp,
10216 entry->opportunistic);
10217 if (os_snprintf_error(end - pos2, ret))
10218 break;
10219 pos2 += ret;
10220
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010221 if (entry->fils_cache_id_set) {
10222 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
10223 entry->fils_cache_id[0],
10224 entry->fils_cache_id[1]);
10225 if (os_snprintf_error(end - pos2, ret))
10226 break;
10227 pos2 += ret;
10228 }
10229
Dmitry Shmidt29333592017-01-09 12:27:11 -080010230 ret = os_snprintf(pos2, end - pos2, "\n");
10231 if (os_snprintf_error(end - pos2, ret))
10232 break;
10233 pos2 += ret;
10234
10235 pos = pos2;
10236 }
10237
10238 return pos - buf;
10239}
10240
10241
10242static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
10243 char *cmd)
10244{
10245 struct rsn_pmksa_cache_entry *entry;
10246 struct wpa_ssid *ssid;
10247 char *pos, *pos2;
10248 int ret = -1;
10249 struct os_reltime now;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010250 int reauth_time = 0, expiration = 0, i;
Dmitry Shmidt29333592017-01-09 12:27:11 -080010251
10252 /*
10253 * Entry format:
10254 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10255 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010256 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010257 */
10258
10259 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10260 if (!ssid)
10261 return -1;
10262
10263 pos = os_strchr(cmd, ' ');
10264 if (!pos)
10265 return -1;
10266 pos++;
10267
10268 entry = os_zalloc(sizeof(*entry));
10269 if (!entry)
10270 return -1;
10271
10272 if (hwaddr_aton(pos, entry->aa))
10273 goto fail;
10274
10275 pos = os_strchr(pos, ' ');
10276 if (!pos)
10277 goto fail;
10278 pos++;
10279
10280 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
10281 goto fail;
10282
10283 pos = os_strchr(pos, ' ');
10284 if (!pos)
10285 goto fail;
10286 pos++;
10287
10288 pos2 = os_strchr(pos, ' ');
10289 if (!pos2)
10290 goto fail;
10291 entry->pmk_len = (pos2 - pos) / 2;
10292 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
10293 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
10294 goto fail;
10295
10296 pos = os_strchr(pos, ' ');
10297 if (!pos)
10298 goto fail;
10299 pos++;
10300
10301 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
10302 &entry->akmp, &entry->opportunistic) != 4)
10303 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010304 for (i = 0; i < 4; i++) {
10305 pos = os_strchr(pos, ' ');
10306 if (!pos) {
10307 if (i < 3)
10308 goto fail;
10309 break;
10310 }
10311 pos++;
10312 }
10313 if (pos) {
10314 if (hexstr2bin(pos, entry->fils_cache_id,
10315 FILS_CACHE_ID_LEN) < 0)
10316 goto fail;
10317 entry->fils_cache_id_set = 1;
10318 }
Dmitry Shmidt29333592017-01-09 12:27:11 -080010319 os_get_reltime(&now);
10320 entry->expiration = now.sec + expiration;
10321 entry->reauth_time = now.sec + reauth_time;
10322
10323 entry->network_ctx = ssid;
10324
10325 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
10326 entry = NULL;
10327 ret = 0;
10328fail:
10329 os_free(entry);
10330 return ret;
10331}
10332
Paul Stewart092955c2017-02-06 09:13:09 -080010333
10334#ifdef CONFIG_MESH
10335
10336static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
10337 const char *cmd, char *buf,
10338 size_t buflen)
10339{
10340 u8 spa[ETH_ALEN];
10341
10342 if (!wpa_s->ifmsh)
10343 return -1;
10344
10345 if (os_strcasecmp(cmd, "any") == 0)
10346 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
10347
10348 if (hwaddr_aton(cmd, spa))
10349 return -1;
10350
10351 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
10352}
10353
10354
10355static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
10356 char *cmd)
10357{
10358 /*
Hai Shalom60840252021-02-19 19:02:11 -080010359 * We do not check mesh interface existence because PMKSA should be
Paul Stewart092955c2017-02-06 09:13:09 -080010360 * stored before wpa_s->ifmsh creation to suppress commit message
10361 * creation.
10362 */
10363 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
10364}
10365
10366#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080010367#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10368
10369
Paul Stewart092955c2017-02-06 09:13:09 -080010370#ifdef CONFIG_FILS
10371static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
10372 const char *cmd)
10373{
10374 struct fils_hlp_req *req;
10375 const char *pos;
10376
10377 /* format: <dst> <packet starting from ethertype> */
10378
10379 req = os_zalloc(sizeof(*req));
10380 if (!req)
10381 return -1;
10382
10383 if (hwaddr_aton(cmd, req->dst))
10384 goto fail;
10385
10386 pos = os_strchr(cmd, ' ');
10387 if (!pos)
10388 goto fail;
10389 pos++;
10390 req->pkt = wpabuf_parse_bin(pos);
10391 if (!req->pkt)
10392 goto fail;
10393
10394 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
10395 return 0;
10396fail:
10397 wpabuf_free(req->pkt);
10398 os_free(req);
10399 return -1;
10400}
10401#endif /* CONFIG_FILS */
10402
10403
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010404static int wpas_ctrl_cmd_debug_level(const char *cmd)
10405{
10406 if (os_strcmp(cmd, "PING") == 0 ||
10407 os_strncmp(cmd, "BSS ", 4) == 0 ||
10408 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
10409 os_strncmp(cmd, "STATUS", 6) == 0 ||
10410 os_strncmp(cmd, "STA ", 4) == 0 ||
10411 os_strncmp(cmd, "STA-", 4) == 0)
10412 return MSG_EXCESSIVE;
10413 return MSG_DEBUG;
10414}
10415
10416
Hai Shalom899fcc72020-10-19 14:38:18 -070010417static int wpas_ctrl_iface_configure_mscs(struct wpa_supplicant *wpa_s,
10418 const char *cmd)
10419{
10420 size_t frame_classifier_len;
10421 const char *pos, *end;
10422 struct robust_av_data *robust_av = &wpa_s->robust_av;
10423 int val;
10424
10425 /*
10426 * format:
10427 * <add|remove|change> [up_bitmap=<hex byte>] [up_limit=<integer>]
10428 * [stream_timeout=<in TUs>] [frame_classifier=<hex bytes>]
10429 */
10430 os_memset(robust_av, 0, sizeof(struct robust_av_data));
10431 if (os_strncmp(cmd, "add ", 4) == 0) {
10432 robust_av->request_type = SCS_REQ_ADD;
10433 } else if (os_strcmp(cmd, "remove") == 0) {
10434 robust_av->request_type = SCS_REQ_REMOVE;
10435 robust_av->valid_config = false;
10436 return wpas_send_mscs_req(wpa_s);
10437 } else if (os_strncmp(cmd, "change ", 7) == 0) {
10438 robust_av->request_type = SCS_REQ_CHANGE;
10439 } else {
10440 return -1;
10441 }
10442
10443 pos = os_strstr(cmd, "up_bitmap=");
10444 if (!pos)
10445 return -1;
10446
10447 val = hex2byte(pos + 10);
10448 if (val < 0)
10449 return -1;
10450 robust_av->up_bitmap = val;
10451
10452 pos = os_strstr(cmd, "up_limit=");
10453 if (!pos)
10454 return -1;
10455
10456 robust_av->up_limit = atoi(pos + 9);
10457
10458 pos = os_strstr(cmd, "stream_timeout=");
10459 if (!pos)
10460 return -1;
10461
10462 robust_av->stream_timeout = atoi(pos + 15);
10463 if (robust_av->stream_timeout == 0)
10464 return -1;
10465
10466 pos = os_strstr(cmd, "frame_classifier=");
10467 if (!pos)
10468 return -1;
10469
10470 pos += 17;
10471 end = os_strchr(pos, ' ');
10472 if (!end)
10473 end = pos + os_strlen(pos);
10474
10475 frame_classifier_len = (end - pos) / 2;
10476 if (frame_classifier_len > sizeof(robust_av->frame_classifier) ||
10477 hexstr2bin(pos, robust_av->frame_classifier, frame_classifier_len))
10478 return -1;
10479
10480 robust_av->frame_classifier_len = frame_classifier_len;
10481 robust_av->valid_config = true;
10482
10483 return wpas_send_mscs_req(wpa_s);
10484}
10485
10486
Hai Shalom60840252021-02-19 19:02:11 -080010487#ifdef CONFIG_PASN
10488static int wpas_ctrl_iface_pasn_start(struct wpa_supplicant *wpa_s, char *cmd)
10489{
10490 char *token, *context = NULL;
10491 u8 bssid[ETH_ALEN];
10492 int akmp = -1, cipher = -1, got_bssid = 0;
10493 u16 group = 0xFFFF;
10494 int id = 0;
10495
10496 /*
10497 * Entry format: bssid=<BSSID> akmp=<AKMP> cipher=<CIPHER> group=<group>
10498 */
10499 while ((token = str_token(cmd, " ", &context))) {
10500 if (os_strncmp(token, "bssid=", 6) == 0) {
10501 if (hwaddr_aton(token + 6, bssid))
10502 return -1;
10503 got_bssid = 1;
10504 } else if (os_strcmp(token, "akmp=PASN") == 0) {
10505 akmp = WPA_KEY_MGMT_PASN;
10506#ifdef CONFIG_IEEE80211R
10507 } else if (os_strcmp(token, "akmp=FT-PSK") == 0) {
10508 akmp = WPA_KEY_MGMT_FT_PSK;
10509 } else if (os_strcmp(token, "akmp=FT-EAP-SHA384") == 0) {
10510 akmp = WPA_KEY_MGMT_FT_IEEE8021X_SHA384;
10511 } else if (os_strcmp(token, "akmp=FT-EAP") == 0) {
10512 akmp = WPA_KEY_MGMT_FT_IEEE8021X;
10513#endif /* CONFIG_IEEE80211R */
10514#ifdef CONFIG_SAE
10515 } else if (os_strcmp(token, "akmp=SAE") == 0) {
10516 akmp = WPA_KEY_MGMT_SAE;
10517#endif /* CONFIG_SAE */
10518#ifdef CONFIG_FILS
10519 } else if (os_strcmp(token, "akmp=FILS-SHA256") == 0) {
10520 akmp = WPA_KEY_MGMT_FILS_SHA256;
10521 } else if (os_strcmp(token, "akmp=FILS-SHA384") == 0) {
10522 akmp = WPA_KEY_MGMT_FILS_SHA384;
10523#endif /* CONFIG_FILS */
10524 } else if (os_strcmp(token, "cipher=CCMP-256") == 0) {
10525 cipher = WPA_CIPHER_CCMP_256;
10526 } else if (os_strcmp(token, "cipher=GCMP-256") == 0) {
10527 cipher = WPA_CIPHER_GCMP_256;
10528 } else if (os_strcmp(token, "cipher=CCMP") == 0) {
10529 cipher = WPA_CIPHER_CCMP;
10530 } else if (os_strcmp(token, "cipher=GCMP") == 0) {
10531 cipher = WPA_CIPHER_GCMP;
10532 } else if (os_strncmp(token, "group=", 6) == 0) {
10533 group = atoi(token + 6);
10534 } else if (os_strncmp(token, "nid=", 4) == 0) {
10535 id = atoi(token + 4);
10536 } else {
10537 wpa_printf(MSG_DEBUG,
10538 "CTRL: PASN Invalid parameter: '%s'",
10539 token);
10540 return -1;
10541 }
10542 }
10543
10544 if (!got_bssid || akmp == -1 || cipher == -1 || group == 0xFFFF) {
10545 wpa_printf(MSG_DEBUG,"CTRL: PASN missing parameter");
10546 return -1;
10547 }
10548
10549 return wpas_pasn_auth_start(wpa_s, bssid, akmp, cipher, group, id);
10550}
10551#endif /* CONFIG_PASN */
10552
10553
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010554char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
10555 char *buf, size_t *resp_len)
10556{
10557 char *reply;
10558 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010559 int reply_len;
10560
10561 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010562 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
10563 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
10564 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010565 if (wpa_debug_show_keys)
10566 wpa_dbg(wpa_s, MSG_DEBUG,
10567 "Control interface command '%s'", buf);
10568 else
10569 wpa_dbg(wpa_s, MSG_DEBUG,
10570 "Control interface command '%s [REMOVED]'",
10571 os_strncmp(buf, WPA_CTRL_RSP,
10572 os_strlen(WPA_CTRL_RSP)) == 0 ?
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010573 WPA_CTRL_RSP :
10574 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
10575 "SET_NETWORK" : "key-add"));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010576 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010577 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010578 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
10579 (const u8 *) buf, os_strlen(buf));
10580 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010581 int level = wpas_ctrl_cmd_debug_level(buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -070010582 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010583 }
10584
10585 reply = os_malloc(reply_size);
10586 if (reply == NULL) {
10587 *resp_len = 1;
10588 return NULL;
10589 }
10590
10591 os_memcpy(reply, "OK\n", 3);
10592 reply_len = 3;
10593
10594 if (os_strcmp(buf, "PING") == 0) {
10595 os_memcpy(reply, "PONG\n", 5);
10596 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010597 } else if (os_strcmp(buf, "IFNAME") == 0) {
10598 reply_len = os_strlen(wpa_s->ifname);
10599 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010600 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
10601 if (wpa_debug_reopen_file() < 0)
10602 reply_len = -1;
10603 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
10604 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
10605 } else if (os_strcmp(buf, "MIB") == 0) {
10606 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
10607 if (reply_len >= 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010608 reply_len += eapol_sm_get_mib(wpa_s->eapol,
10609 reply + reply_len,
10610 reply_size - reply_len);
Hai Shalom74f70d42019-02-11 14:42:39 -080010611#ifdef CONFIG_MACSEC
10612 reply_len += ieee802_1x_kay_get_mib(
10613 wpa_s->kay, reply + reply_len,
10614 reply_size - reply_len);
10615#endif /* CONFIG_MACSEC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010616 }
10617 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
10618 reply_len = wpa_supplicant_ctrl_iface_status(
10619 wpa_s, buf + 6, reply, reply_size);
10620 } else if (os_strcmp(buf, "PMKSA") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070010621 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070010622 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070010623 wpas_ctrl_iface_pmksa_flush(wpa_s);
Dmitry Shmidt29333592017-01-09 12:27:11 -080010624#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10625 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
10626 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
10627 reply, reply_size);
10628 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
10629 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
10630 reply_len = -1;
Paul Stewart092955c2017-02-06 09:13:09 -080010631#ifdef CONFIG_MESH
10632 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
10633 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
10634 reply, reply_size);
10635 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
10636 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
10637 reply_len = -1;
10638#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080010639#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010640 } else if (os_strncmp(buf, "SET ", 4) == 0) {
10641 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
10642 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010643 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
10644 reply_len = wpa_config_dump_values(wpa_s->conf,
10645 reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010646 } else if (os_strncmp(buf, "GET ", 4) == 0) {
10647 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
10648 reply, reply_size);
10649 } else if (os_strcmp(buf, "LOGON") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070010650 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010651 } else if (os_strcmp(buf, "LOGOFF") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070010652 eapol_sm_notify_logoff(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010653 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
10654 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
10655 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010656 else
10657 wpas_request_connection(wpa_s);
Dmitry Shmidt98660862014-03-11 17:26:21 -070010658 } else if (os_strcmp(buf, "REATTACH") == 0) {
10659 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
10660 !wpa_s->current_ssid)
10661 reply_len = -1;
10662 else {
10663 wpa_s->reattach = 1;
10664 wpas_request_connection(wpa_s);
10665 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010666 } else if (os_strcmp(buf, "RECONNECT") == 0) {
10667 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
10668 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010669 else if (wpa_s->disconnected)
10670 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010671#ifdef IEEE8021X_EAPOL
10672 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
10673 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
10674 reply_len = -1;
10675#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010676#ifdef CONFIG_IEEE80211R
10677 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
10678 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
10679 reply_len = -1;
10680#endif /* CONFIG_IEEE80211R */
10681#ifdef CONFIG_WPS
10682 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
10683 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
10684 if (res == -2) {
10685 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10686 reply_len = 17;
10687 } else if (res)
10688 reply_len = -1;
10689 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
10690 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
10691 if (res == -2) {
10692 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10693 reply_len = 17;
10694 } else if (res)
10695 reply_len = -1;
10696 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
10697 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
10698 reply,
10699 reply_size);
10700 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
10701 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
10702 wpa_s, buf + 14, reply, reply_size);
10703 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
10704 if (wpas_wps_cancel(wpa_s))
10705 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010706#ifdef CONFIG_WPS_NFC
10707 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
10708 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
10709 reply_len = -1;
10710 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
10711 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
10712 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -080010713 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
10714 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
10715 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010716 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
10717 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
10718 wpa_s, buf + 14, reply, reply_size);
10719 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
10720 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
10721 buf + 17))
10722 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010723 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
10724 reply_len = wpas_ctrl_nfc_get_handover_req(
10725 wpa_s, buf + 21, reply, reply_size);
10726 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
10727 reply_len = wpas_ctrl_nfc_get_handover_sel(
10728 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -080010729 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
10730 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
10731 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010732#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010733 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
10734 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
10735 reply_len = -1;
10736#ifdef CONFIG_AP
10737 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
10738 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
10739 wpa_s, buf + 11, reply, reply_size);
10740#endif /* CONFIG_AP */
10741#ifdef CONFIG_WPS_ER
10742 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
10743 if (wpas_wps_er_start(wpa_s, NULL))
10744 reply_len = -1;
10745 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
10746 if (wpas_wps_er_start(wpa_s, buf + 13))
10747 reply_len = -1;
10748 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010749 wpas_wps_er_stop(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010750 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
10751 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
10752 reply_len = -1;
10753 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
10754 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
10755 if (ret == -2) {
10756 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10757 reply_len = 17;
10758 } else if (ret == -3) {
10759 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
10760 reply_len = 18;
10761 } else if (ret == -4) {
10762 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
10763 reply_len = 20;
10764 } else if (ret)
10765 reply_len = -1;
10766 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
10767 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
10768 reply_len = -1;
10769 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
10770 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
10771 buf + 18))
10772 reply_len = -1;
10773 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
10774 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
10775 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010776#ifdef CONFIG_WPS_NFC
10777 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10778 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10779 wpa_s, buf + 24, reply, reply_size);
10780#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010781#endif /* CONFIG_WPS_ER */
10782#endif /* CONFIG_WPS */
10783#ifdef CONFIG_IBSS_RSN
10784 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
10785 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
10786 reply_len = -1;
10787#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010788#ifdef CONFIG_MESH
10789 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
10790 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10791 wpa_s, buf + 19, reply, reply_size);
10792 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
10793 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10794 wpa_s, "", reply, reply_size);
10795 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
10796 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
10797 reply_len = -1;
10798 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
10799 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
10800 buf + 18))
10801 reply_len = -1;
Dmitry Shmidte4663042016-04-04 10:07:49 -070010802 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
10803 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
10804 reply_len = -1;
10805 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
10806 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
10807 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070010808 } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) {
10809 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16))
10810 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010811#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010812#ifdef CONFIG_P2P
10813 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010814 if (p2p_ctrl_find(wpa_s, buf + 8))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010815 reply_len = -1;
10816 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
10817 if (p2p_ctrl_find(wpa_s, ""))
10818 reply_len = -1;
10819 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
10820 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010821 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
10822 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
10823 reply_len = -1;
10824 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10825 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
10826 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010827 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
10828 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
10829 reply_size);
10830 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
10831 if (p2p_ctrl_listen(wpa_s, buf + 11))
10832 reply_len = -1;
10833 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
10834 if (p2p_ctrl_listen(wpa_s, ""))
10835 reply_len = -1;
10836 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
10837 if (wpas_p2p_group_remove(wpa_s, buf + 17))
10838 reply_len = -1;
10839 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070010840 if (p2p_ctrl_group_add(wpa_s, ""))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010841 reply_len = -1;
10842 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
10843 if (p2p_ctrl_group_add(wpa_s, buf + 14))
10844 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010845 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
10846 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
10847 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010848 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
10849 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
10850 reply_len = -1;
10851 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
10852 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
10853 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
10854 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
10855 reply_size);
10856 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10857 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
10858 reply_len = -1;
10859 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
10860 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
10861 reply_len = -1;
10862 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
10863 wpas_p2p_sd_service_update(wpa_s);
10864 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10865 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
10866 reply_len = -1;
10867 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
10868 wpas_p2p_service_flush(wpa_s);
10869 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
10870 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
10871 reply_len = -1;
10872 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
10873 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
10874 reply_len = -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010875 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
10876 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
10877 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010878 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
10879 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
10880 reply_len = -1;
10881 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
10882 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
10883 reply_len = -1;
10884 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
10885 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
10886 reply_size);
10887 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
10888 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
10889 reply_len = -1;
10890 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -070010891 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010892 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
10893 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
10894 reply_len = -1;
10895 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
10896 if (wpas_p2p_cancel(wpa_s))
10897 reply_len = -1;
10898 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
10899 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
10900 reply_len = -1;
10901 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
10902 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
10903 reply_len = -1;
10904 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
10905 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
10906 reply_len = -1;
10907 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
10908 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
10909 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070010910 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
10911 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
10912 reply_len = -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010913 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
10914 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
10915 reply_len = -1;
10916 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
10917 if (wpas_p2p_lo_stop(wpa_s))
10918 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010919#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010920#ifdef CONFIG_WIFI_DISPLAY
10921 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
10922 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
10923 reply_len = -1;
10924 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
10925 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
10926 reply, reply_size);
10927#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010928#ifdef CONFIG_INTERWORKING
10929 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
10930 if (interworking_fetch_anqp(wpa_s) < 0)
10931 reply_len = -1;
10932 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
10933 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010934 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
10935 if (ctrl_interworking_select(wpa_s, NULL) < 0)
10936 reply_len = -1;
10937 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
10938 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010939 reply_len = -1;
10940 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010941 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010942 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010943 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10944 int id;
10945
10946 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
10947 if (id < 0)
10948 reply_len = -1;
10949 else {
10950 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
10951 if (os_snprintf_error(reply_size, reply_len))
10952 reply_len = -1;
10953 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010954 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
10955 if (get_anqp(wpa_s, buf + 9) < 0)
10956 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010957 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
10958 if (gas_request(wpa_s, buf + 12) < 0)
10959 reply_len = -1;
10960 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
10961 reply_len = gas_response_get(wpa_s, buf + 17, reply,
10962 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010963#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -070010964#ifdef CONFIG_HS20
10965 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
10966 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
10967 reply_len = -1;
10968 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10969 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
10970 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010971 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080010972 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
10973 reply_len = -1;
10974 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
10975 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
10976 reply_len = -1;
10977 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
10978 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
10979 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
10980 if (del_hs20_icon(wpa_s, buf + 14) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010981 reply_len = -1;
10982 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010983 if (hs20_fetch_osu(wpa_s, 0) < 0)
10984 reply_len = -1;
10985 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
10986 if (hs20_fetch_osu(wpa_s, 1) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010987 reply_len = -1;
10988 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
10989 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010990#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010991 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
10992 {
10993 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10994 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
10995 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -070010996 else {
10997 /*
10998 * Notify response from timeout to allow the control
10999 * interface response to be sent first.
11000 */
11001 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
11002 wpa_s, NULL);
11003 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011004 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
11005 if (wpa_supplicant_reload_configuration(wpa_s))
11006 reply_len = -1;
11007 } else if (os_strcmp(buf, "TERMINATE") == 0) {
11008 wpa_supplicant_terminate_proc(wpa_s->global);
11009 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
11010 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
11011 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080011012 } else if (os_strncmp(buf, "BSSID_IGNORE", 12) == 0) {
11013 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
11014 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidte19501d2011-03-16 14:32:18 -070011015 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -080011016 /* deprecated backwards compatibility alias for BSSID_IGNORE */
11017 reply_len = wpa_supplicant_ctrl_iface_bssid_ignore(
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011018 wpa_s, buf + 9, reply, reply_size);
11019 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
11020 reply_len = wpa_supplicant_ctrl_iface_log_level(
11021 wpa_s, buf + 9, reply, reply_size);
Vinit Deshpandeda134e92014-12-02 10:59:29 -080011022 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
11023 reply_len = wpa_supplicant_ctrl_iface_list_networks(
11024 wpa_s, buf + 14, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011025 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
11026 reply_len = wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -080011027 wpa_s, NULL, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011028 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070011029 wpas_request_disconnection(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011030 } else if (os_strcmp(buf, "SCAN") == 0) {
11031 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
11032 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
11033 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011034 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
11035 reply_len = wpa_supplicant_ctrl_iface_scan_results(
11036 wpa_s, reply, reply_size);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011037 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
11038 if (wpas_abort_ongoing_scan(wpa_s) < 0)
11039 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011040 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
11041 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
11042 reply_len = -1;
11043 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
11044 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
11045 reply_len = -1;
11046 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
11047 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
11048 reply_len = -1;
11049 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
11050 reply_len = wpa_supplicant_ctrl_iface_add_network(
11051 wpa_s, reply, reply_size);
11052 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
11053 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
11054 reply_len = -1;
11055 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
11056 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
11057 reply_len = -1;
11058 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
11059 reply_len = wpa_supplicant_ctrl_iface_get_network(
11060 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt684785c2014-05-12 13:34:29 -070011061 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011062 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
11063 wpa_s))
Dmitry Shmidt684785c2014-05-12 13:34:29 -070011064 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070011065 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
11066 reply_len = wpa_supplicant_ctrl_iface_list_creds(
11067 wpa_s, reply, reply_size);
11068 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
11069 reply_len = wpa_supplicant_ctrl_iface_add_cred(
11070 wpa_s, reply, reply_size);
11071 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
11072 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
11073 reply_len = -1;
11074 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
11075 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
11076 reply_len = -1;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -070011077 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
11078 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
11079 reply,
11080 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011081#ifndef CONFIG_NO_CONFIG_WRITE
11082 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
11083 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
11084 reply_len = -1;
11085#endif /* CONFIG_NO_CONFIG_WRITE */
11086 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
11087 reply_len = wpa_supplicant_ctrl_iface_get_capability(
11088 wpa_s, buf + 15, reply, reply_size);
11089 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
11090 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
11091 reply_len = -1;
11092 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
11093 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
11094 reply_len = -1;
11095 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
11096 reply_len = wpa_supplicant_global_iface_list(
11097 wpa_s->global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011098 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011099 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011100 wpa_s->global, buf + 10, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011101 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
11102 reply_len = wpa_supplicant_ctrl_iface_bss(
11103 wpa_s, buf + 4, reply, reply_size);
11104#ifdef CONFIG_AP
11105 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
11106 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
11107 } else if (os_strncmp(buf, "STA ", 4) == 0) {
11108 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
11109 reply_size);
11110 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
11111 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
11112 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070011113 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
11114 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
11115 reply_len = -1;
11116 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
11117 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
11118 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080011119 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
11120 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
11121 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080011122 } else if (os_strcmp(buf, "STOP_AP") == 0) {
11123 if (wpas_ap_stop_ap(wpa_s))
11124 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011125#endif /* CONFIG_AP */
11126 } else if (os_strcmp(buf, "SUSPEND") == 0) {
11127 wpas_notify_suspend(wpa_s->global);
11128 } else if (os_strcmp(buf, "RESUME") == 0) {
11129 wpas_notify_resume(wpa_s->global);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070011130#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011131 } else if (os_strcmp(buf, "DROP_SA") == 0) {
11132 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070011133#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011134 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
11135 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
11136 reply_len = -1;
11137 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011138 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011139 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
11140 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
11141 reply_len = -1;
11142 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
11143 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
11144 buf + 17))
11145 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -070011146 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011147 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011148#ifdef CONFIG_TDLS
11149 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
11150 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
11151 reply_len = -1;
11152 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
11153 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
11154 reply_len = -1;
11155 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
11156 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
11157 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011158 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
11159 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
11160 buf + 17))
11161 reply_len = -1;
11162 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
11163 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
11164 buf + 24))
11165 reply_len = -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -070011166 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
11167 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
11168 wpa_s, buf + 17, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011169#endif /* CONFIG_TDLS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011170 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
11171 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
11172 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
11173 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
11174 reply_len = -1;
11175 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
11176 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
11177 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011178 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
11179 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
11180 reply_size);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080011181 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
11182 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
11183 reply_len = -1;
Yuhao Zhengfcd6f212012-07-27 10:37:52 -070011184 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
11185 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
11186 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070011187#ifdef CONFIG_AUTOSCAN
11188 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
11189 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
11190 reply_len = -1;
11191#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070011192 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
11193 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
11194 reply_size);
Hai Shalomb755a2a2020-04-23 21:49:02 -070011195 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
11196 reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply,
11197 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080011198#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -070011199 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
11200 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
11201 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080011202#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011203 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
11204 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
11205 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011206 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080011207 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011208 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080011209#ifdef CONFIG_WNM
11210 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
11211 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
11212 reply_len = -1;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080011213 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
11214 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
Dmitry Shmidt44c95782013-05-17 09:51:35 -070011215 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -080011216 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
11217 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
11218 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080011219#endif /* CONFIG_WNM */
Dmitry Shmidt444d5672013-04-01 13:08:44 -070011220 } else if (os_strcmp(buf, "FLUSH") == 0) {
11221 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011222 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
11223 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
11224 reply_size);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070011225#ifdef CONFIG_TESTING_OPTIONS
11226 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
11227 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
11228 reply_len = -1;
11229 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
11230 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011231 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
11232 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
11233 reply_len = -1;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -070011234 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
11235 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
11236 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011237 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
11238 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
11239 reply_len = -1;
11240 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
11241 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
11242 reply_len = -1;
11243 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
11244 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
11245 reply_len = -1;
11246 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
11247 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
11248 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -080011249 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
11250 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
11251 reply_len = -1;
11252 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
11253 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011254 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
11255 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
11256 reply_len = -1;
11257 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
11258 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
Jouni Malinenc4818362015-10-04 11:45:13 +030011259 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
11260 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
11261 reply_len = -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080011262 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
11263 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
11264 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011265 } else if (os_strcmp(buf, "RESET_PN") == 0) {
11266 if (wpas_ctrl_reset_pn(wpa_s) < 0)
11267 reply_len = -1;
11268 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
11269 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
11270 reply_len = -1;
11271 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
11272 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
11273 reply_len = -1;
Hai Shalom74f70d42019-02-11 14:42:39 -080011274 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
11275 sme_event_unprot_disconnect(
11276 wpa_s, wpa_s->bssid, NULL,
11277 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070011278#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070011279 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
11280 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
11281 reply_len = -1;
11282 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
11283 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
11284 reply_size);
11285 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
11286 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
11287 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011288 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011289 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011290 reply_len = -1;
11291 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
11292 wpas_ctrl_iface_erp_flush(wpa_s);
11293 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
11294 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
11295 reply_len = -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011296 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
11297 reply_len = wpas_ctrl_iface_get_pref_freq_list(
11298 wpa_s, buf + 19, reply, reply_size);
Paul Stewart092955c2017-02-06 09:13:09 -080011299#ifdef CONFIG_FILS
11300 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
11301 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
11302 reply_len = -1;
11303 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
11304 wpas_flush_fils_hlp_req(wpa_s);
11305#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011306#ifdef CONFIG_DPP
11307 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
11308 int res;
11309
11310 res = wpas_dpp_qr_code(wpa_s, buf + 12);
11311 if (res < 0) {
11312 reply_len = -1;
11313 } else {
11314 reply_len = os_snprintf(reply, reply_size, "%d", res);
11315 if (os_snprintf_error(reply_size, reply_len))
11316 reply_len = -1;
11317 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080011318 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
11319 int res;
11320
11321 res = wpas_dpp_nfc_uri(wpa_s, buf + 12);
11322 if (res < 0) {
11323 reply_len = -1;
11324 } else {
11325 reply_len = os_snprintf(reply, reply_size, "%d", res);
11326 if (os_snprintf_error(reply_size, reply_len))
11327 reply_len = -1;
11328 }
Hai Shalomfdcde762020-04-02 11:19:20 -070011329 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
11330 int res;
11331
11332 res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20);
11333 if (res < 0) {
11334 reply_len = -1;
11335 } else {
11336 reply_len = os_snprintf(reply, reply_size, "%d", res);
11337 if (os_snprintf_error(reply_size, reply_len))
11338 reply_len = -1;
11339 }
11340 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
11341 int res;
11342
11343 res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20);
11344 if (res < 0) {
11345 reply_len = -1;
11346 } else {
11347 reply_len = os_snprintf(reply, reply_size, "%d", res);
11348 if (os_snprintf_error(reply_size, reply_len))
11349 reply_len = -1;
11350 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011351 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
11352 int res;
11353
Hai Shalom021b0b52019-04-10 11:17:58 -070011354 res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011355 if (res < 0) {
11356 reply_len = -1;
11357 } else {
11358 reply_len = os_snprintf(reply, reply_size, "%d", res);
11359 if (os_snprintf_error(reply_size, reply_len))
11360 reply_len = -1;
11361 }
11362 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070011363 if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011364 reply_len = -1;
11365 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
11366 const char *uri;
11367
Hai Shalom021b0b52019-04-10 11:17:58 -070011368 uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011369 if (!uri) {
11370 reply_len = -1;
11371 } else {
11372 reply_len = os_snprintf(reply, reply_size, "%s", uri);
11373 if (os_snprintf_error(reply_size, reply_len))
11374 reply_len = -1;
11375 }
11376 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070011377 reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19),
11378 reply, reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -070011379 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
11380 if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18),
11381 os_strchr(buf + 18, ' ')) < 0)
11382 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011383 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
11384 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
11385 reply_len = -1;
11386 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
11387 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
11388 reply_len = -1;
11389 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -070011390 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011391 wpas_dpp_listen_stop(wpa_s);
11392 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
11393 int res;
11394
Hai Shalom021b0b52019-04-10 11:17:58 -070011395 res = dpp_configurator_add(wpa_s->dpp, buf + 20);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011396 if (res < 0) {
11397 reply_len = -1;
11398 } else {
11399 reply_len = os_snprintf(reply, reply_size, "%d", res);
11400 if (os_snprintf_error(reply_size, reply_len))
11401 reply_len = -1;
11402 }
11403 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070011404 if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011405 reply_len = -1;
11406 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -080011407 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011408 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -070011409 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070011410 reply_len = dpp_configurator_get_key_id(wpa_s->dpp,
11411 atoi(buf + 25),
11412 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011413 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
11414 int res;
11415
11416 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
11417 if (res < 0) {
11418 reply_len = -1;
11419 } else {
11420 reply_len = os_snprintf(reply, reply_size, "%d", res);
11421 if (os_snprintf_error(reply_size, reply_len))
11422 reply_len = -1;
11423 }
11424 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
11425 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
11426 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070011427#ifdef CONFIG_DPP2
11428 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
11429 if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0)
11430 reply_len = -1;
11431 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
11432 if (wpas_dpp_controller_start(wpa_s, NULL) < 0)
11433 reply_len = -1;
11434 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
11435 dpp_controller_stop(wpa_s->dpp);
Hai Shalomfdcde762020-04-02 11:19:20 -070011436 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
11437 if (wpas_dpp_chirp(wpa_s, buf + 9) < 0)
11438 reply_len = -1;
11439 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
11440 wpas_dpp_chirp_stop(wpa_s);
Hai Shalom4fbc08f2020-05-18 12:37:00 -070011441 } else if (os_strncmp(buf, "DPP_RECONFIG ", 13) == 0) {
Hai Shalom899fcc72020-10-19 14:38:18 -070011442 if (wpas_dpp_reconfig(wpa_s, buf + 13) < 0)
11443 reply_len = -1;
11444 } else if (os_strncmp(buf, "DPP_CA_SET ", 11) == 0) {
11445 if (wpas_dpp_ca_set(wpa_s, buf + 10) < 0)
Hai Shalom4fbc08f2020-05-18 12:37:00 -070011446 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070011447#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011448#endif /* CONFIG_DPP */
Hai Shalom899fcc72020-10-19 14:38:18 -070011449 } else if (os_strncmp(buf, "MSCS ", 5) == 0) {
11450 if (wpas_ctrl_iface_configure_mscs(wpa_s, buf + 5))
11451 reply_len = -1;
Hai Shalom60840252021-02-19 19:02:11 -080011452#ifdef CONFIG_PASN
11453 } else if (os_strncmp(buf, "PASN_START ", 11) == 0) {
11454 if (wpas_ctrl_iface_pasn_start(wpa_s, buf + 11) < 0)
11455 reply_len = -1;
11456 } else if (os_strcmp(buf, "PASN_STOP") == 0) {
11457 wpas_pasn_auth_stop(wpa_s);
11458 } else if (os_strcmp(buf, "PTKSA_CACHE_LIST") == 0) {
11459 reply_len = ptksa_cache_list(wpa_s->ptksa, reply, reply_size);
11460#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011461 } else {
11462 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
11463 reply_len = 16;
11464 }
11465
11466 if (reply_len < 0) {
11467 os_memcpy(reply, "FAIL\n", 5);
11468 reply_len = 5;
11469 }
11470
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011471 *resp_len = reply_len;
11472 return reply;
11473}
11474
11475
11476static int wpa_supplicant_global_iface_add(struct wpa_global *global,
11477 char *cmd)
11478{
11479 struct wpa_interface iface;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011480 char *pos, *extra;
11481 struct wpa_supplicant *wpa_s;
11482 unsigned int create_iface = 0;
11483 u8 mac_addr[ETH_ALEN];
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011484 enum wpa_driver_if_type type = WPA_IF_STATION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011485
11486 /*
11487 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011488 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011489 */
11490 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
11491
11492 os_memset(&iface, 0, sizeof(iface));
11493
11494 do {
11495 iface.ifname = pos = cmd;
11496 pos = os_strchr(pos, '\t');
11497 if (pos)
11498 *pos++ = '\0';
11499 if (iface.ifname[0] == '\0')
11500 return -1;
11501 if (pos == NULL)
11502 break;
11503
11504 iface.confname = pos;
11505 pos = os_strchr(pos, '\t');
11506 if (pos)
11507 *pos++ = '\0';
11508 if (iface.confname[0] == '\0')
11509 iface.confname = NULL;
11510 if (pos == NULL)
11511 break;
11512
11513 iface.driver = pos;
11514 pos = os_strchr(pos, '\t');
11515 if (pos)
11516 *pos++ = '\0';
11517 if (iface.driver[0] == '\0')
11518 iface.driver = NULL;
11519 if (pos == NULL)
11520 break;
11521
11522 iface.ctrl_interface = pos;
11523 pos = os_strchr(pos, '\t');
11524 if (pos)
11525 *pos++ = '\0';
11526 if (iface.ctrl_interface[0] == '\0')
11527 iface.ctrl_interface = NULL;
11528 if (pos == NULL)
11529 break;
11530
11531 iface.driver_param = pos;
11532 pos = os_strchr(pos, '\t');
11533 if (pos)
11534 *pos++ = '\0';
11535 if (iface.driver_param[0] == '\0')
11536 iface.driver_param = NULL;
11537 if (pos == NULL)
11538 break;
11539
11540 iface.bridge_ifname = pos;
11541 pos = os_strchr(pos, '\t');
11542 if (pos)
11543 *pos++ = '\0';
11544 if (iface.bridge_ifname[0] == '\0')
11545 iface.bridge_ifname = NULL;
11546 if (pos == NULL)
11547 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011548
11549 extra = pos;
11550 pos = os_strchr(pos, '\t');
11551 if (pos)
11552 *pos++ = '\0';
Dmitry Shmidt83474442015-04-15 13:47:09 -070011553 if (!extra[0])
11554 break;
11555
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011556 if (os_strcmp(extra, "create") == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011557 create_iface = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011558 if (!pos)
11559 break;
11560
11561 if (os_strcmp(pos, "sta") == 0) {
11562 type = WPA_IF_STATION;
11563 } else if (os_strcmp(pos, "ap") == 0) {
11564 type = WPA_IF_AP_BSS;
11565 } else {
11566 wpa_printf(MSG_DEBUG,
11567 "INTERFACE_ADD unsupported interface type: '%s'",
11568 pos);
11569 return -1;
11570 }
11571 } else {
Dmitry Shmidt83474442015-04-15 13:47:09 -070011572 wpa_printf(MSG_DEBUG,
11573 "INTERFACE_ADD unsupported extra parameter: '%s'",
11574 extra);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011575 return -1;
Dmitry Shmidt83474442015-04-15 13:47:09 -070011576 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011577 } while (0);
11578
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011579 if (create_iface) {
11580 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
11581 iface.ifname);
11582 if (!global->ifaces)
11583 return -1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011584 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011585 NULL, NULL, NULL, mac_addr, NULL) < 0) {
11586 wpa_printf(MSG_ERROR,
11587 "CTRL_IFACE interface creation failed");
11588 return -1;
11589 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011590
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011591 wpa_printf(MSG_DEBUG,
11592 "CTRL_IFACE interface '%s' created with MAC addr: "
11593 MACSTR, iface.ifname, MAC2STR(mac_addr));
11594 }
11595
11596 if (wpa_supplicant_get_iface(global, iface.ifname))
11597 goto fail;
11598
11599 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
11600 if (!wpa_s)
11601 goto fail;
11602 wpa_s->added_vif = create_iface;
11603 return 0;
11604
11605fail:
11606 if (create_iface)
11607 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
11608 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011609}
11610
11611
11612static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
11613 char *cmd)
11614{
11615 struct wpa_supplicant *wpa_s;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011616 int ret;
11617 unsigned int delete_iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011618
11619 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
11620
11621 wpa_s = wpa_supplicant_get_iface(global, cmd);
11622 if (wpa_s == NULL)
11623 return -1;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011624 delete_iface = wpa_s->added_vif;
11625 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
11626 if (!ret && delete_iface) {
11627 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
11628 cmd);
11629 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
11630 }
11631 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011632}
11633
11634
11635static void wpa_free_iface_info(struct wpa_interface_info *iface)
11636{
11637 struct wpa_interface_info *prev;
11638
11639 while (iface) {
11640 prev = iface;
11641 iface = iface->next;
11642
11643 os_free(prev->ifname);
11644 os_free(prev->desc);
11645 os_free(prev);
11646 }
11647}
11648
11649
11650static int wpa_supplicant_global_iface_list(struct wpa_global *global,
11651 char *buf, int len)
11652{
11653 int i, res;
11654 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
11655 char *pos, *end;
11656
11657 for (i = 0; wpa_drivers[i]; i++) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070011658 const struct wpa_driver_ops *drv = wpa_drivers[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011659 if (drv->get_interfaces == NULL)
11660 continue;
11661 tmp = drv->get_interfaces(global->drv_priv[i]);
11662 if (tmp == NULL)
11663 continue;
11664
11665 if (last == NULL)
11666 iface = last = tmp;
11667 else
11668 last->next = tmp;
11669 while (last->next)
11670 last = last->next;
11671 }
11672
11673 pos = buf;
11674 end = buf + len;
11675 for (tmp = iface; tmp; tmp = tmp->next) {
11676 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
11677 tmp->drv_name, tmp->ifname,
11678 tmp->desc ? tmp->desc : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011679 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011680 *pos = '\0';
11681 break;
11682 }
11683 pos += res;
11684 }
11685
11686 wpa_free_iface_info(iface);
11687
11688 return pos - buf;
11689}
11690
11691
11692static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011693 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011694 char *buf, int len)
11695{
11696 int res;
11697 char *pos, *end;
11698 struct wpa_supplicant *wpa_s;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011699 int show_ctrl = 0;
11700
11701 if (input)
11702 show_ctrl = !!os_strstr(input, "ctrl");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011703
11704 wpa_s = global->ifaces;
11705 pos = buf;
11706 end = buf + len;
11707
11708 while (wpa_s) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011709 if (show_ctrl)
11710 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
11711 wpa_s->ifname,
11712 wpa_s->conf->ctrl_interface ?
11713 wpa_s->conf->ctrl_interface : "N/A");
11714 else
11715 res = os_snprintf(pos, end - pos, "%s\n",
11716 wpa_s->ifname);
11717
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011718 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011719 *pos = '\0';
11720 break;
11721 }
11722 pos += res;
11723 wpa_s = wpa_s->next;
11724 }
11725 return pos - buf;
11726}
11727
11728
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011729static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
11730 const char *ifname,
11731 char *cmd, size_t *resp_len)
11732{
11733 struct wpa_supplicant *wpa_s;
11734
11735 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11736 if (os_strcmp(ifname, wpa_s->ifname) == 0)
11737 break;
11738 }
11739
11740 if (wpa_s == NULL) {
11741 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
11742 if (resp)
11743 *resp_len = os_strlen(resp);
11744 else
11745 *resp_len = 1;
11746 return resp;
11747 }
11748
11749 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
11750}
11751
11752
11753static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
11754 char *buf, size_t *resp_len)
11755{
11756#ifdef CONFIG_P2P
11757 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011758 "LIST_NETWORKS",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011759 "P2P_FIND",
11760 "P2P_STOP_FIND",
11761 "P2P_LISTEN",
11762 "P2P_GROUP_ADD",
11763 "P2P_GET_PASSPHRASE",
11764 "P2P_SERVICE_UPDATE",
11765 "P2P_SERVICE_FLUSH",
11766 "P2P_FLUSH",
11767 "P2P_CANCEL",
11768 "P2P_PRESENCE_REQ",
11769 "P2P_EXT_LISTEN",
Paul Stewart092955c2017-02-06 09:13:09 -080011770#ifdef CONFIG_AP
11771 "STA-FIRST",
11772#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011773 NULL
11774 };
11775 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080011776#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011777 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080011778#endif /* ANDROID */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011779 "GET_CAPABILITY ",
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011780 "GET_NETWORK ",
11781 "REMOVE_NETWORK ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011782 "P2P_FIND ",
11783 "P2P_CONNECT ",
11784 "P2P_LISTEN ",
11785 "P2P_GROUP_REMOVE ",
11786 "P2P_GROUP_ADD ",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011787 "P2P_GROUP_MEMBER ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011788 "P2P_PROV_DISC ",
11789 "P2P_SERV_DISC_REQ ",
11790 "P2P_SERV_DISC_CANCEL_REQ ",
11791 "P2P_SERV_DISC_RESP ",
11792 "P2P_SERV_DISC_EXTERNAL ",
11793 "P2P_SERVICE_ADD ",
11794 "P2P_SERVICE_DEL ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011795 "P2P_SERVICE_REP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011796 "P2P_REJECT ",
11797 "P2P_INVITE ",
11798 "P2P_PEER ",
11799 "P2P_SET ",
11800 "P2P_UNAUTHORIZE ",
11801 "P2P_PRESENCE_REQ ",
11802 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070011803 "P2P_REMOVE_CLIENT ",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080011804 "WPS_NFC_TOKEN ",
11805 "WPS_NFC_TAG_READ ",
Dmitry Shmidt413dde72014-04-11 10:23:22 -070011806 "NFC_GET_HANDOVER_SEL ",
11807 "NFC_GET_HANDOVER_REQ ",
11808 "NFC_REPORT_HANDOVER ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011809 "P2P_ASP_PROVISION ",
11810 "P2P_ASP_PROVISION_RESP ",
Paul Stewart092955c2017-02-06 09:13:09 -080011811#ifdef CONFIG_AP
11812 "STA ",
11813 "STA-NEXT ",
11814#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011815 NULL
11816 };
11817 int found = 0;
11818 int i;
11819
11820 if (global->p2p_init_wpa_s == NULL)
11821 return NULL;
11822
11823 for (i = 0; !found && cmd[i]; i++) {
11824 if (os_strcmp(buf, cmd[i]) == 0)
11825 found = 1;
11826 }
11827
11828 for (i = 0; !found && prefix[i]; i++) {
11829 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
11830 found = 1;
11831 }
11832
11833 if (found)
11834 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11835 buf, resp_len);
11836#endif /* CONFIG_P2P */
11837 return NULL;
11838}
11839
11840
11841static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
11842 char *buf, size_t *resp_len)
11843{
11844#ifdef CONFIG_WIFI_DISPLAY
11845 if (global->p2p_init_wpa_s == NULL)
11846 return NULL;
11847 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
11848 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
11849 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11850 buf, resp_len);
11851#endif /* CONFIG_WIFI_DISPLAY */
11852 return NULL;
11853}
11854
11855
11856static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
11857 char *buf, size_t *resp_len)
11858{
11859 char *ret;
11860
11861 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
11862 if (ret)
11863 return ret;
11864
11865 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
11866 if (ret)
11867 return ret;
11868
11869 return NULL;
11870}
11871
11872
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011873static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
11874{
11875 char *value;
11876
11877 value = os_strchr(cmd, ' ');
11878 if (value == NULL)
11879 return -1;
11880 *value++ = '\0';
11881
11882 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
11883
11884#ifdef CONFIG_WIFI_DISPLAY
11885 if (os_strcasecmp(cmd, "wifi_display") == 0) {
11886 wifi_display_enable(global, !!atoi(value));
11887 return 0;
11888 }
11889#endif /* CONFIG_WIFI_DISPLAY */
11890
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011891 /* Restore cmd to its original value to allow redirection */
11892 value[-1] = ' ';
11893
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011894 return -1;
11895}
11896
11897
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011898static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
11899 char *cmd)
11900{
11901 struct wpa_supplicant *wpa_s[2]; /* src, dst */
11902 char *p;
11903 unsigned int i;
11904
11905 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11906 * <variable name> */
11907
11908 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
11909 p = os_strchr(cmd, ' ');
11910 if (p == NULL)
11911 return -1;
11912 *p = '\0';
11913
11914 wpa_s[i] = global->ifaces;
11915 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
11916 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
11917 break;
11918 }
11919
11920 if (!wpa_s[i]) {
11921 wpa_printf(MSG_DEBUG,
11922 "CTRL_IFACE: Could not find iface=%s", cmd);
11923 return -1;
11924 }
11925
11926 cmd = p + 1;
11927 }
11928
11929 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
11930}
11931
11932
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011933#ifndef CONFIG_NO_CONFIG_WRITE
11934static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
11935{
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011936 int ret = 0, saved = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011937 struct wpa_supplicant *wpa_s;
11938
11939 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11940 if (!wpa_s->conf->update_config) {
11941 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11942 continue;
11943 }
11944
11945 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
11946 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11947 ret = 1;
11948 } else {
11949 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011950 saved++;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011951 }
11952 }
11953
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011954 if (!saved && !ret) {
11955 wpa_dbg(wpa_s, MSG_DEBUG,
11956 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11957 ret = 1;
11958 }
11959
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011960 return ret;
11961}
11962#endif /* CONFIG_NO_CONFIG_WRITE */
11963
11964
11965static int wpas_global_ctrl_iface_status(struct wpa_global *global,
11966 char *buf, size_t buflen)
11967{
11968 char *pos, *end;
11969 int ret;
11970 struct wpa_supplicant *wpa_s;
11971
11972 pos = buf;
11973 end = buf + buflen;
11974
11975#ifdef CONFIG_P2P
11976 if (global->p2p && !global->p2p_disabled) {
11977 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
11978 "\n"
11979 "p2p_state=%s\n",
11980 MAC2STR(global->p2p_dev_addr),
11981 p2p_get_state_txt(global->p2p));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011982 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011983 return pos - buf;
11984 pos += ret;
11985 } else if (global->p2p) {
11986 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011987 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011988 return pos - buf;
11989 pos += ret;
11990 }
11991#endif /* CONFIG_P2P */
11992
11993#ifdef CONFIG_WIFI_DISPLAY
11994 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
11995 !!global->wifi_display);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011996 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011997 return pos - buf;
11998 pos += ret;
11999#endif /* CONFIG_WIFI_DISPLAY */
12000
12001 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
12002 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
12003 "address=" MACSTR "\n",
12004 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012005 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012006 return pos - buf;
12007 pos += ret;
12008 }
12009
12010 return pos - buf;
12011}
12012
12013
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012014#ifdef CONFIG_FST
12015
12016static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
12017 char *cmd, char *buf,
12018 size_t reply_size)
12019{
12020 char ifname[IFNAMSIZ + 1];
12021 struct fst_iface_cfg cfg;
12022 struct wpa_supplicant *wpa_s;
12023 struct fst_wpa_obj iface_obj;
12024
12025 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
12026 wpa_s = wpa_supplicant_get_iface(global, ifname);
12027 if (wpa_s) {
12028 if (wpa_s->fst) {
12029 wpa_printf(MSG_INFO, "FST: Already attached");
12030 return -1;
12031 }
12032 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
12033 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
12034 &iface_obj, &cfg);
12035 if (wpa_s->fst)
12036 return os_snprintf(buf, reply_size, "OK\n");
12037 }
12038 }
12039
12040 return -1;
12041}
12042
12043
12044static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
12045 char *cmd, char *buf,
12046 size_t reply_size)
12047{
12048 char ifname[IFNAMSIZ + 1];
12049 struct wpa_supplicant *wpa_s;
12050
12051 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
12052 wpa_s = wpa_supplicant_get_iface(global, ifname);
12053 if (wpa_s) {
12054 if (!fst_iface_detach(ifname)) {
12055 wpa_s->fst = NULL;
12056 return os_snprintf(buf, reply_size, "OK\n");
12057 }
12058 }
12059 }
12060
12061 return -1;
12062}
12063
12064#endif /* CONFIG_FST */
12065
12066
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012067char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
12068 char *buf, size_t *resp_len)
12069{
12070 char *reply;
12071 const int reply_size = 2048;
12072 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012073 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012074
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070012075 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
12076 char *pos = os_strchr(buf + 7, ' ');
12077 if (pos) {
12078 *pos++ = '\0';
12079 return wpas_global_ctrl_iface_ifname(global,
12080 buf + 7, pos,
12081 resp_len);
12082 }
12083 }
12084
12085 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
12086 if (reply)
12087 return reply;
12088
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080012089 if (os_strcmp(buf, "PING") == 0)
12090 level = MSG_EXCESSIVE;
12091 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012092 (const u8 *) buf, os_strlen(buf));
12093
12094 reply = os_malloc(reply_size);
12095 if (reply == NULL) {
12096 *resp_len = 1;
12097 return NULL;
12098 }
12099
12100 os_memcpy(reply, "OK\n", 3);
12101 reply_len = 3;
12102
12103 if (os_strcmp(buf, "PING") == 0) {
12104 os_memcpy(reply, "PONG\n", 5);
12105 reply_len = 5;
12106 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
12107 if (wpa_supplicant_global_iface_add(global, buf + 14))
12108 reply_len = -1;
12109 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
12110 if (wpa_supplicant_global_iface_remove(global, buf + 17))
12111 reply_len = -1;
12112 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
12113 reply_len = wpa_supplicant_global_iface_list(
12114 global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080012115 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012116 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080012117 global, buf + 10, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012118#ifdef CONFIG_FST
12119 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
12120 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
12121 reply,
12122 reply_size);
12123 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
12124 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
12125 reply,
12126 reply_size);
12127 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
12128 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
12129#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012130 } else if (os_strcmp(buf, "TERMINATE") == 0) {
12131 wpa_supplicant_terminate_proc(global);
12132 } else if (os_strcmp(buf, "SUSPEND") == 0) {
12133 wpas_notify_suspend(global);
12134 } else if (os_strcmp(buf, "RESUME") == 0) {
12135 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012136 } else if (os_strncmp(buf, "SET ", 4) == 0) {
Dmitry Shmidt61593f02014-04-21 16:27:35 -070012137 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
12138#ifdef CONFIG_P2P
12139 if (global->p2p_init_wpa_s) {
12140 os_free(reply);
12141 /* Check if P2P redirection would work for this
12142 * command. */
12143 return wpa_supplicant_ctrl_iface_process(
12144 global->p2p_init_wpa_s,
12145 buf, resp_len);
12146 }
12147#endif /* CONFIG_P2P */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012148 reply_len = -1;
Dmitry Shmidt61593f02014-04-21 16:27:35 -070012149 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080012150 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
12151 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
12152 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070012153#ifndef CONFIG_NO_CONFIG_WRITE
12154 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
12155 if (wpas_global_ctrl_iface_save_config(global))
12156 reply_len = -1;
12157#endif /* CONFIG_NO_CONFIG_WRITE */
12158 } else if (os_strcmp(buf, "STATUS") == 0) {
12159 reply_len = wpas_global_ctrl_iface_status(global, reply,
12160 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080012161#ifdef CONFIG_MODULE_TESTS
12162 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080012163 if (wpas_module_tests() < 0)
12164 reply_len = -1;
12165#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012166 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
12167 if (wpa_debug_reopen_file() < 0)
12168 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012169 } else {
12170 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
12171 reply_len = 16;
12172 }
12173
12174 if (reply_len < 0) {
12175 os_memcpy(reply, "FAIL\n", 5);
12176 reply_len = 5;
12177 }
12178
12179 *resp_len = reply_len;
12180 return reply;
12181}