blob: f5c65870ec373b0e1fe5ce4e85aeb8f6d21ec00c [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 */
Dmitry Shmidtff787d52015-01-12 13:01:47 -080025#include "crypto/tls.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080026#include "ap/hostapd.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070027#include "eap_peer/eap.h"
28#include "eapol_supp/eapol_supp_sm.h"
29#include "rsn_supp/wpa.h"
30#include "rsn_supp/preauth.h"
31#include "rsn_supp/pmksa_cache.h"
32#include "l2_packet/l2_packet.h"
33#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080034#include "fst/fst.h"
35#include "fst/fst_ctrl_iface.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036#include "config.h"
37#include "wpa_supplicant_i.h"
38#include "driver_i.h"
39#include "wps_supplicant.h"
40#include "ibss_rsn.h"
41#include "ap.h"
42#include "p2p_supplicant.h"
43#include "p2p/p2p.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070044#include "hs20_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070045#include "wifi_display.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070046#include "notify.h"
47#include "bss.h"
48#include "scan.h"
49#include "ctrl_iface.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080050#include "interworking.h"
Dmitry Shmidte19501d2011-03-16 14:32:18 -070051#include "blacklist.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070052#include "autoscan.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080053#include "wnm_sta.h"
Dmitry Shmidt818ea482014-03-10 13:15:21 -070054#include "offchannel.h"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070055#include "drivers/driver.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080056#include "mesh.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070057#include "dpp_supplicant.h"
Hai Shalom74f70d42019-02-11 14:42:39 -080058#include "sme.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070059
Hai Shalomc3565922019-10-28 11:58:20 -070060#ifdef __NetBSD__
61#include <net/if_ether.h>
62#elif !defined(__CYGWIN__) && !defined(CONFIG_NATIVE_WINDOWS)
63#include <net/ethernet.h>
64#endif
65
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070066static int wpa_supplicant_global_iface_list(struct wpa_global *global,
67 char *buf, int len);
68static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080069 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070070 char *buf, int len);
Dmitry Shmidtd11f0192014-03-24 12:09:47 -070071static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
72 char *val);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070073
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070074
Dmitry Shmidt04949592012-07-19 12:16:46 -070075static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
76{
77 char *pos;
78 u8 addr[ETH_ALEN], *filter = NULL, *n;
79 size_t count = 0;
80
81 pos = val;
82 while (pos) {
83 if (*pos == '\0')
84 break;
85 if (hwaddr_aton(pos, addr)) {
86 os_free(filter);
87 return -1;
88 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070089 n = os_realloc_array(filter, count + 1, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -070090 if (n == NULL) {
91 os_free(filter);
92 return -1;
93 }
94 filter = n;
95 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
96 count++;
97
98 pos = os_strchr(pos, ' ');
99 if (pos)
100 pos++;
101 }
102
103 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
104 os_free(wpa_s->bssid_filter);
105 wpa_s->bssid_filter = filter;
106 wpa_s->bssid_filter_count = count;
107
108 return 0;
109}
110
111
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800112static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
113{
114 char *pos;
115 u8 addr[ETH_ALEN], *bssid = NULL, *n;
116 struct wpa_ssid_value *ssid = NULL, *ns;
117 size_t count = 0, ssid_count = 0;
118 struct wpa_ssid *c;
119
120 /*
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800121 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800122 * SSID_SPEC ::= ssid <SSID_HEX>
123 * BSSID_SPEC ::= bssid <BSSID_HEX>
124 */
125
126 pos = val;
127 while (pos) {
128 if (*pos == '\0')
129 break;
130 if (os_strncmp(pos, "bssid ", 6) == 0) {
131 int res;
132 pos += 6;
133 res = hwaddr_aton2(pos, addr);
134 if (res < 0) {
135 os_free(ssid);
136 os_free(bssid);
137 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
138 "BSSID value '%s'", pos);
139 return -1;
140 }
141 pos += res;
142 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
143 if (n == NULL) {
144 os_free(ssid);
145 os_free(bssid);
146 return -1;
147 }
148 bssid = n;
149 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
150 count++;
151 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
152 char *end;
153 pos += 5;
154
155 end = pos;
156 while (*end) {
157 if (*end == '\0' || *end == ' ')
158 break;
159 end++;
160 }
161
162 ns = os_realloc_array(ssid, ssid_count + 1,
163 sizeof(struct wpa_ssid_value));
164 if (ns == NULL) {
165 os_free(ssid);
166 os_free(bssid);
167 return -1;
168 }
169 ssid = ns;
170
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700171 if ((end - pos) & 0x01 ||
172 end - pos > 2 * SSID_MAX_LEN ||
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800173 hexstr2bin(pos, ssid[ssid_count].ssid,
174 (end - pos) / 2) < 0) {
175 os_free(ssid);
176 os_free(bssid);
177 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
178 "SSID value '%s'", pos);
179 return -1;
180 }
181 ssid[ssid_count].ssid_len = (end - pos) / 2;
182 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
183 ssid[ssid_count].ssid,
184 ssid[ssid_count].ssid_len);
185 ssid_count++;
186 pos = end;
187 } else {
188 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
189 "'%s'", pos);
190 os_free(ssid);
191 os_free(bssid);
192 return -1;
193 }
194
195 pos = os_strchr(pos, ' ');
196 if (pos)
197 pos++;
198 }
199
200 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
201 os_free(wpa_s->disallow_aps_bssid);
202 wpa_s->disallow_aps_bssid = bssid;
203 wpa_s->disallow_aps_bssid_count = count;
204
205 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
206 os_free(wpa_s->disallow_aps_ssid);
207 wpa_s->disallow_aps_ssid = ssid;
208 wpa_s->disallow_aps_ssid_count = ssid_count;
209
210 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
211 return 0;
212
213 c = wpa_s->current_ssid;
214 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
215 return 0;
216
217 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
218 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
219 return 0;
220
221 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
222 "because current AP was marked disallowed");
223
224#ifdef CONFIG_SME
225 wpa_s->sme.prev_bssid_set = 0;
226#endif /* CONFIG_SME */
227 wpa_s->reassociate = 1;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800228 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800229 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
230 wpa_supplicant_req_scan(wpa_s, 0, 0);
231
232 return 0;
233}
234
235
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700236#ifndef CONFIG_NO_CONFIG_BLOBS
237static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
238{
239 char *name = pos;
240 struct wpa_config_blob *blob;
241 size_t len;
242
243 pos = os_strchr(pos, ' ');
244 if (pos == NULL)
245 return -1;
246 *pos++ = '\0';
247 len = os_strlen(pos);
248 if (len & 1)
249 return -1;
250
251 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
252 blob = os_zalloc(sizeof(*blob));
253 if (blob == NULL)
254 return -1;
255 blob->name = os_strdup(name);
256 blob->data = os_malloc(len / 2);
257 if (blob->name == NULL || blob->data == NULL) {
258 wpa_config_free_blob(blob);
259 return -1;
260 }
261
262 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
263 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
264 wpa_config_free_blob(blob);
265 return -1;
266 }
267 blob->len = len / 2;
268
269 wpa_config_set_blob(wpa_s->conf, blob);
270
271 return 0;
272}
273#endif /* CONFIG_NO_CONFIG_BLOBS */
274
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700275
276static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
277{
278 char *params;
279 char *pos;
280 int *freqs = NULL;
281 int ret;
282
283 if (atoi(cmd)) {
284 params = os_strchr(cmd, ' ');
285 os_free(wpa_s->manual_sched_scan_freqs);
286 if (params) {
287 params++;
288 pos = os_strstr(params, "freq=");
289 if (pos)
290 freqs = freq_range_to_channel_list(wpa_s,
291 pos + 5);
292 }
293 wpa_s->manual_sched_scan_freqs = freqs;
294 ret = wpas_start_pno(wpa_s);
295 } else {
296 ret = wpas_stop_pno(wpa_s);
297 }
298 return ret;
299}
300
301
Ravi Joshie6ccb162015-07-16 17:45:41 -0700302static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band)
303{
304 union wpa_event_data event;
305
306 if (os_strcmp(band, "AUTO") == 0)
307 wpa_s->setband = WPA_SETBAND_AUTO;
308 else if (os_strcmp(band, "5G") == 0)
309 wpa_s->setband = WPA_SETBAND_5G;
310 else if (os_strcmp(band, "2G") == 0)
311 wpa_s->setband = WPA_SETBAND_2G;
312 else
313 return -1;
314
315 if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) {
316 os_memset(&event, 0, sizeof(event));
317 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
318 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
319 wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
320 }
321
322 return 0;
323}
324
325
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700326static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s,
327 const char *cmd)
328{
329 struct wpabuf *lci;
330
331 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
332 wpabuf_free(wpa_s->lci);
333 wpa_s->lci = NULL;
334 return 0;
335 }
336
337 lci = wpabuf_parse_bin(cmd);
338 if (!lci)
339 return -1;
340
341 if (os_get_reltime(&wpa_s->lci_time)) {
342 wpabuf_free(lci);
343 return -1;
344 }
345
346 wpabuf_free(wpa_s->lci);
347 wpa_s->lci = lci;
348
349 return 0;
350}
351
352
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800353static int
354wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd)
355{
356 int relative_rssi;
357
358 if (os_strcmp(cmd, "disable") == 0) {
359 wpa_s->srp.relative_rssi_set = 0;
360 return 0;
361 }
362
363 relative_rssi = atoi(cmd);
364 if (relative_rssi < 0 || relative_rssi > 100)
365 return -1;
366 wpa_s->srp.relative_rssi = relative_rssi;
367 wpa_s->srp.relative_rssi_set = 1;
368 return 0;
369}
370
371
372static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s,
373 const char *cmd)
374{
375 char *pos;
376 int adjust_rssi;
377
378 /* <band>:adjust_value */
379 pos = os_strchr(cmd, ':');
380 if (!pos)
381 return -1;
382 pos++;
383 adjust_rssi = atoi(pos);
384 if (adjust_rssi < -100 || adjust_rssi > 100)
385 return -1;
386
387 if (os_strncmp(cmd, "2G", 2) == 0)
388 wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G;
389 else if (os_strncmp(cmd, "5G", 2) == 0)
390 wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G;
391 else
392 return -1;
393
394 wpa_s->srp.relative_adjust_rssi = adjust_rssi;
395
396 return 0;
397}
398
399
400static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s,
401 const char *cmd)
402{
403 struct wpabuf *ric_ies;
404
405 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
406 wpabuf_free(wpa_s->ric_ies);
407 wpa_s->ric_ies = NULL;
408 return 0;
409 }
410
411 ric_ies = wpabuf_parse_bin(cmd);
412 if (!ric_ies)
413 return -1;
414
415 wpabuf_free(wpa_s->ric_ies);
416 wpa_s->ric_ies = ric_ies;
417
418 return 0;
419}
420
421
Hai Shalomfdcde762020-04-02 11:19:20 -0700422#ifdef CONFIG_TESTING_OPTIONS
423static int wpas_ctrl_iface_set_dso(struct wpa_supplicant *wpa_s,
424 const char *val)
425{
426 u8 bssid[ETH_ALEN];
427 const char *pos = val;
428 struct driver_signal_override *dso = NULL, *tmp, parsed;
429
430 if (hwaddr_aton(pos, bssid))
431 return -1;
432 pos = os_strchr(pos, ' ');
433
434 dl_list_for_each(tmp, &wpa_s->drv_signal_override,
435 struct driver_signal_override, list) {
436 if (os_memcmp(bssid, tmp->bssid, ETH_ALEN) == 0) {
437 dso = tmp;
438 break;
439 }
440 }
441
442 if (!pos) {
443 /* Remove existing entry */
444 if (dso) {
445 dl_list_del(&dso->list);
446 os_free(dso);
447 }
448 return 0;
449 }
450 pos++;
451
452 /* Update an existing entry or add a new one */
453 os_memset(&parsed, 0, sizeof(parsed));
454 if (sscanf(pos, "%d %d %d %d %d",
455 &parsed.si_current_signal,
456 &parsed.si_avg_signal,
457 &parsed.si_avg_beacon_signal,
458 &parsed.si_current_noise,
459 &parsed.scan_level) != 5)
460 return -1;
461
462 if (!dso) {
463 dso = os_zalloc(sizeof(*dso));
464 if (!dso)
465 return -1;
466 os_memcpy(dso->bssid, bssid, ETH_ALEN);
467 dl_list_add(&wpa_s->drv_signal_override, &dso->list);
468 }
469 dso->si_current_signal = parsed.si_current_signal;
470 dso->si_avg_signal = parsed.si_avg_signal;
471 dso->si_avg_beacon_signal = parsed.si_avg_beacon_signal;
472 dso->si_current_noise = parsed.si_current_noise;
473 dso->scan_level = parsed.scan_level;
474
475 return 0;
476}
477#endif /* CONFIG_TESTING_OPTIONS */
478
479
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700480static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
481 char *cmd)
482{
483 char *value;
484 int ret = 0;
485
486 value = os_strchr(cmd, ' ');
487 if (value == NULL)
488 return -1;
489 *value++ = '\0';
490
491 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
492 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
493 eapol_sm_configure(wpa_s->eapol,
494 atoi(value), -1, -1, -1);
495 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
496 eapol_sm_configure(wpa_s->eapol,
497 -1, atoi(value), -1, -1);
498 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
499 eapol_sm_configure(wpa_s->eapol,
500 -1, -1, atoi(value), -1);
501 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
502 eapol_sm_configure(wpa_s->eapol,
503 -1, -1, -1, atoi(value));
504 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
505 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
Paul Stewart092955c2017-02-06 09:13:09 -0800506 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700507 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800508 } else {
509 value[-1] = '=';
510 wpa_config_process_global(wpa_s->conf, cmd, -1);
511 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700512 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
513 0) {
514 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
Paul Stewart092955c2017-02-06 09:13:09 -0800515 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700516 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800517 } else {
518 value[-1] = '=';
519 wpa_config_process_global(wpa_s->conf, cmd, -1);
520 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
Paul Stewart092955c2017-02-06 09:13:09 -0800522 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
523 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700524 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800525 } else {
526 value[-1] = '=';
527 wpa_config_process_global(wpa_s->conf, cmd, -1);
528 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
530 wpa_s->wps_fragment_size = atoi(value);
531#ifdef CONFIG_WPS_TESTING
532 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
533 long int val;
534 val = strtol(value, NULL, 0);
535 if (val < 0 || val > 0xff) {
536 ret = -1;
537 wpa_printf(MSG_DEBUG, "WPS: Invalid "
538 "wps_version_number %ld", val);
539 } else {
540 wps_version_number = val;
541 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
542 "version %u.%u",
543 (wps_version_number & 0xf0) >> 4,
544 wps_version_number & 0x0f);
545 }
546 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
547 wps_testing_dummy_cred = atoi(value);
548 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
549 wps_testing_dummy_cred);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800550 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
551 wps_corrupt_pkhash = atoi(value);
552 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
553 wps_corrupt_pkhash);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800554 } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
555 if (value[0] == '\0') {
556 wps_force_auth_types_in_use = 0;
557 } else {
558 wps_force_auth_types = strtol(value, NULL, 0);
559 wps_force_auth_types_in_use = 1;
560 }
561 } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
562 if (value[0] == '\0') {
563 wps_force_encr_types_in_use = 0;
564 } else {
565 wps_force_encr_types = strtol(value, NULL, 0);
566 wps_force_encr_types_in_use = 1;
567 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700568#endif /* CONFIG_WPS_TESTING */
569 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
570 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
571 ret = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800572#ifdef CONFIG_TDLS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700573#ifdef CONFIG_TDLS_TESTING
574 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700575 tdls_testing = strtol(value, NULL, 0);
576 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
577#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700578 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
579 int disabled = atoi(value);
580 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
581 if (disabled) {
582 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
583 ret = -1;
584 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
585 ret = -1;
586 wpa_tdls_enable(wpa_s->wpa, !disabled);
587#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800588 } else if (os_strcasecmp(cmd, "pno") == 0) {
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700589 ret = wpas_ctrl_pno(wpa_s, value);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700590 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
591 int disabled = atoi(value);
592 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
593 ret = -1;
594 else if (disabled)
595 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
596 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
597 if (os_strcmp(value, "disable") == 0)
598 wpa_s->set_sta_uapsd = 0;
599 else {
600 int be, bk, vi, vo;
601 char *pos;
602 /* format: BE,BK,VI,VO;max SP Length */
603 be = atoi(value);
604 pos = os_strchr(value, ',');
605 if (pos == NULL)
606 return -1;
607 pos++;
608 bk = atoi(pos);
609 pos = os_strchr(pos, ',');
610 if (pos == NULL)
611 return -1;
612 pos++;
613 vi = atoi(pos);
614 pos = os_strchr(pos, ',');
615 if (pos == NULL)
616 return -1;
617 pos++;
618 vo = atoi(pos);
619 /* ignore max SP Length for now */
620
621 wpa_s->set_sta_uapsd = 1;
622 wpa_s->sta_uapsd = 0;
623 if (be)
624 wpa_s->sta_uapsd |= BIT(0);
625 if (bk)
626 wpa_s->sta_uapsd |= BIT(1);
627 if (vi)
628 wpa_s->sta_uapsd |= BIT(2);
629 if (vo)
630 wpa_s->sta_uapsd |= BIT(3);
631 }
Jouni Malinen21d6bc82012-04-10 16:17:59 -0700632 } else if (os_strcasecmp(cmd, "ps") == 0) {
633 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700634#ifdef CONFIG_WIFI_DISPLAY
635 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800636 int enabled = !!atoi(value);
637 if (enabled && !wpa_s->global->p2p)
638 ret = -1;
639 else
640 wifi_display_enable(wpa_s->global, enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700641#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700642 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
643 ret = set_bssid_filter(wpa_s, value);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800644 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
645 ret = set_disallow_aps(wpa_s, value);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800646 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
647 wpa_s->no_keep_alive = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700648#ifdef CONFIG_DPP
649 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
650 os_free(wpa_s->dpp_configurator_params);
651 wpa_s->dpp_configurator_params = os_strdup(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700652 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
653 wpa_s->dpp_init_max_tries = atoi(value);
654 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
655 wpa_s->dpp_init_retry_time = atoi(value);
656 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
657 wpa_s->dpp_resp_wait_time = atoi(value);
658 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
659 wpa_s->dpp_resp_max_tries = atoi(value);
660 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
661 wpa_s->dpp_resp_retry_time = atoi(value);
662#ifdef CONFIG_TESTING_OPTIONS
663 } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
664 if (hwaddr_aton(value, dpp_pkex_own_mac_override))
665 ret = -1;
666 } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
667 if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
668 ret = -1;
669 } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
670 size_t hex_len = os_strlen(value);
671
672 if (hex_len >
673 2 * sizeof(dpp_pkex_ephemeral_key_override))
674 ret = -1;
675 else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
676 hex_len / 2))
677 ret = -1;
678 else
679 dpp_pkex_ephemeral_key_override_len = hex_len / 2;
680 } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) {
681 size_t hex_len = os_strlen(value);
682
683 if (hex_len > 2 * sizeof(dpp_protocol_key_override))
684 ret = -1;
685 else if (hexstr2bin(value, dpp_protocol_key_override,
686 hex_len / 2))
687 ret = -1;
688 else
689 dpp_protocol_key_override_len = hex_len / 2;
690 } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) {
691 size_t hex_len = os_strlen(value);
692
693 if (hex_len > 2 * sizeof(dpp_nonce_override))
694 ret = -1;
695 else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2))
696 ret = -1;
697 else
698 dpp_nonce_override_len = hex_len / 2;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700699 } else if (os_strcasecmp(cmd, "dpp_version_override") == 0) {
700 dpp_version_override = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700701#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700702#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700703#ifdef CONFIG_TESTING_OPTIONS
704 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
705 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800706 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
707 wpa_s->ext_eapol_frame_io = !!atoi(value);
708#ifdef CONFIG_AP
709 if (wpa_s->ap_iface) {
710 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
711 wpa_s->ext_eapol_frame_io;
712 }
713#endif /* CONFIG_AP */
714 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
715 wpa_s->extra_roc_dur = atoi(value);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800716 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
717 wpa_s->test_failure = atoi(value);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800718 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
719 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700720 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
721 wpa_s->ignore_auth_resp = !!atoi(value);
722 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
723 wpa_s->ignore_assoc_disallow = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700724 wpa_drv_ignore_assoc_disallow(wpa_s,
725 wpa_s->ignore_assoc_disallow);
Hai Shalomfdcde762020-04-02 11:19:20 -0700726 } else if (os_strcasecmp(cmd, "disable_sa_query") == 0) {
727 wpa_s->disable_sa_query = !!atoi(value);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800728 } else if (os_strcasecmp(cmd, "ignore_sae_h2e_only") == 0) {
729 wpa_s->ignore_sae_h2e_only = !!atoi(value);
730 } else if (os_strcasecmp(cmd, "extra_sae_rejected_groups") == 0) {
731 char *pos;
732
733 os_free(wpa_s->extra_sae_rejected_groups);
734 wpa_s->extra_sae_rejected_groups = NULL;
735 pos = value;
736 while (pos && pos[0]) {
737 int group;
738
739 group = atoi(pos);
740 wpa_printf(MSG_DEBUG,
741 "TESTING: Extra rejection of SAE group %d",
742 group);
743 if (group)
744 int_array_add_unique(
745 &wpa_s->extra_sae_rejected_groups,
746 group);
747 pos = os_strchr(pos, ' ');
748 if (!pos)
749 break;
750 pos++;
751 }
Hai Shalomb755a2a2020-04-23 21:49:02 -0700752 } else if (os_strcasecmp(cmd, "ft_rsnxe_used") == 0) {
753 wpa_s->ft_rsnxe_used = atoi(value);
Hai Shalom899fcc72020-10-19 14:38:18 -0700754 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol") == 0) {
755 wpa_s->oci_freq_override_eapol = atoi(value);
756 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_req") == 0) {
757 wpa_s->oci_freq_override_saquery_req = atoi(value);
758 } else if (os_strcasecmp(cmd, "oci_freq_override_saquery_resp") == 0) {
759 wpa_s->oci_freq_override_saquery_resp = atoi(value);
760 } else if (os_strcasecmp(cmd, "oci_freq_override_eapol_g2") == 0) {
761 wpa_s->oci_freq_override_eapol_g2 = atoi(value);
762 /* Populate value to wpa_sm if already associated. */
763 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_EAPOL_G2,
764 wpa_s->oci_freq_override_eapol_g2);
765 } else if (os_strcasecmp(cmd, "oci_freq_override_ft_assoc") == 0) {
766 wpa_s->oci_freq_override_ft_assoc = atoi(value);
767 /* Populate value to wpa_sm if already associated. */
768 wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCI_FREQ_FT_ASSOC,
769 wpa_s->oci_freq_override_ft_assoc);
770 } else if (os_strcasecmp(cmd, "oci_freq_override_fils_assoc") == 0) {
771 wpa_s->oci_freq_override_fils_assoc = atoi(value);
772 } else if (os_strcasecmp(cmd, "oci_freq_override_wnm_sleep") == 0) {
773 wpa_s->oci_freq_override_wnm_sleep = atoi(value);
Hai Shalomfdcde762020-04-02 11:19:20 -0700774 } else if (os_strcasecmp(cmd, "rsne_override_eapol") == 0) {
775 wpabuf_free(wpa_s->rsne_override_eapol);
776 if (os_strcmp(value, "NULL") == 0)
777 wpa_s->rsne_override_eapol = NULL;
778 else
779 wpa_s->rsne_override_eapol = wpabuf_parse_bin(value);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800780 } else if (os_strcasecmp(cmd, "rsnxe_override_assoc") == 0) {
781 wpabuf_free(wpa_s->rsnxe_override_assoc);
782 if (os_strcmp(value, "NULL") == 0)
783 wpa_s->rsnxe_override_assoc = NULL;
784 else
785 wpa_s->rsnxe_override_assoc = wpabuf_parse_bin(value);
786 } else if (os_strcasecmp(cmd, "rsnxe_override_eapol") == 0) {
787 wpabuf_free(wpa_s->rsnxe_override_eapol);
788 if (os_strcmp(value, "NULL") == 0)
789 wpa_s->rsnxe_override_eapol = NULL;
790 else
791 wpa_s->rsnxe_override_eapol = wpabuf_parse_bin(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700792 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
793 wpa_s->reject_btm_req_reason = atoi(value);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800794 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
795 os_free(wpa_s->get_pref_freq_list_override);
796 if (!value[0])
797 wpa_s->get_pref_freq_list_override = NULL;
798 else
799 wpa_s->get_pref_freq_list_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700800 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
801 wpabuf_free(wpa_s->sae_commit_override);
802 if (value[0] == '\0')
803 wpa_s->sae_commit_override = NULL;
804 else
805 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
Hai Shalomfdcde762020-04-02 11:19:20 -0700806 } else if (os_strcasecmp(cmd, "driver_signal_override") == 0) {
807 ret = wpas_ctrl_iface_set_dso(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700808#ifdef CONFIG_DPP
809 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
810 os_free(wpa_s->dpp_config_obj_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700811 if (value[0] == '\0')
812 wpa_s->dpp_config_obj_override = NULL;
813 else
814 wpa_s->dpp_config_obj_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700815 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
816 os_free(wpa_s->dpp_discovery_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700817 if (value[0] == '\0')
818 wpa_s->dpp_discovery_override = NULL;
819 else
820 wpa_s->dpp_discovery_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700821 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
822 os_free(wpa_s->dpp_groups_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700823 if (value[0] == '\0')
824 wpa_s->dpp_groups_override = NULL;
825 else
826 wpa_s->dpp_groups_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700827 } else if (os_strcasecmp(cmd,
828 "dpp_ignore_netaccesskey_mismatch") == 0) {
829 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700830 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
831 dpp_test = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700832#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700833#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700834#ifdef CONFIG_FILS
835 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
836 wpa_s->disable_fils = !!atoi(value);
837 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
838 wpa_supplicant_set_default_scan_ies(wpa_s);
839#endif /* CONFIG_FILS */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700840#ifndef CONFIG_NO_CONFIG_BLOBS
841 } else if (os_strcmp(cmd, "blob") == 0) {
842 ret = wpas_ctrl_set_blob(wpa_s, value);
843#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800844 } else if (os_strcasecmp(cmd, "setband") == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700845 ret = wpas_ctrl_set_band(wpa_s, value);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800846#ifdef CONFIG_MBO
847 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
848 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
Paul Stewart092955c2017-02-06 09:13:09 -0800849 if (ret == 0) {
850 value[-1] = '=';
851 wpa_config_process_global(wpa_s->conf, cmd, -1);
852 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800853 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
854 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700855 } else if (os_strcasecmp(cmd, "oce") == 0) {
856 wpa_s->conf->oce = atoi(value);
857 if (wpa_s->conf->oce) {
858 if ((wpa_s->conf->oce & OCE_STA) &&
859 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
860 wpa_s->enable_oce = OCE_STA;
861
862 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
863 (wpa_s->drv_flags &
864 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
865 /* TODO: Need to add STA-CFON support */
866 wpa_printf(MSG_ERROR,
867 "OCE STA-CFON feature is not yet supported");
868 return -1;
869 }
870 } else {
871 wpa_s->enable_oce = 0;
872 }
873 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800874#endif /* CONFIG_MBO */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700875 } else if (os_strcasecmp(cmd, "lci") == 0) {
876 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800877 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
878 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800879 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
880 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
881 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
882 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
883 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
884 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700885 } else if (os_strcasecmp(cmd, "roaming") == 0) {
886 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800887#ifdef CONFIG_WNM
888 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
889 struct wpabuf *elems;
890
891 elems = wpabuf_parse_bin(value);
892 if (!elems)
893 return -1;
894 wnm_set_coloc_intf_elems(wpa_s, elems);
895#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700896 } else {
897 value[-1] = '=';
898 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
899 if (ret == 0)
900 wpa_supplicant_update_config(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -0700901 else if (ret == 1)
902 ret = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700903 }
904
905 return ret;
906}
907
908
909static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
910 char *cmd, char *buf, size_t buflen)
911{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700912 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913
914 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
915
916 if (os_strcmp(cmd, "version") == 0) {
917 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700918 } else if (os_strcasecmp(cmd, "max_command_len") == 0) {
919 res = os_snprintf(buf, buflen, "%u", CTRL_IFACE_MAX_LEN);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700920 } else if (os_strcasecmp(cmd, "country") == 0) {
921 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
922 res = os_snprintf(buf, buflen, "%c%c",
923 wpa_s->conf->country[0],
924 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700925#ifdef CONFIG_WIFI_DISPLAY
926 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800927 int enabled;
928 if (wpa_s->global->p2p == NULL ||
929 wpa_s->global->p2p_disabled)
930 enabled = 0;
931 else
932 enabled = wpa_s->global->wifi_display;
933 res = os_snprintf(buf, buflen, "%d", enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700934#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700935#ifdef CONFIG_TESTING_GET_GTK
936 } else if (os_strcmp(cmd, "gtk") == 0) {
937 if (wpa_s->last_gtk_len == 0)
938 return -1;
939 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
940 wpa_s->last_gtk_len);
941 return res;
942#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800943 } else if (os_strcmp(cmd, "tls_library") == 0) {
944 res = tls_get_library_version(buf, buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700945#ifdef CONFIG_TESTING_OPTIONS
946 } else if (os_strcmp(cmd, "anonce") == 0) {
947 return wpa_snprintf_hex(buf, buflen,
948 wpa_sm_get_anonce(wpa_s->wpa),
949 WPA_NONCE_LEN);
Hai Shalomfdcde762020-04-02 11:19:20 -0700950 } else if (os_strcasecmp(cmd, "last_tk_key_idx") == 0) {
951 res = os_snprintf(buf, buflen, "%d", wpa_s->last_tk_key_idx);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700952#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800953 } else {
954 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700955 }
956
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800957 if (os_snprintf_error(buflen, res))
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700958 return -1;
959 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700960}
961
962
963#ifdef IEEE8021X_EAPOL
964static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
965 char *addr)
966{
967 u8 bssid[ETH_ALEN];
968 struct wpa_ssid *ssid = wpa_s->current_ssid;
969
970 if (hwaddr_aton(addr, bssid)) {
971 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
972 "'%s'", addr);
973 return -1;
974 }
975
976 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
977 rsn_preauth_deinit(wpa_s->wpa);
978 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
979 return -1;
980
981 return 0;
982}
983#endif /* IEEE8021X_EAPOL */
984
985
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986#ifdef CONFIG_TDLS
987
988static int wpa_supplicant_ctrl_iface_tdls_discover(
989 struct wpa_supplicant *wpa_s, char *addr)
990{
991 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800992 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700993
994 if (hwaddr_aton(addr, peer)) {
995 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
996 "address '%s'", addr);
997 return -1;
998 }
999
1000 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
1001 MAC2STR(peer));
1002
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001003 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1004 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
1005 else
1006 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
1007
1008 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001009}
1010
1011
1012static int wpa_supplicant_ctrl_iface_tdls_setup(
1013 struct wpa_supplicant *wpa_s, char *addr)
1014{
1015 u8 peer[ETH_ALEN];
1016 int ret;
1017
1018 if (hwaddr_aton(addr, peer)) {
1019 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
1020 "address '%s'", addr);
1021 return -1;
1022 }
1023
1024 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
1025 MAC2STR(peer));
1026
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001027 if ((wpa_s->conf->tdls_external_control) &&
1028 wpa_tdls_is_external_setup(wpa_s->wpa))
1029 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
1030
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001031 wpa_tdls_remove(wpa_s->wpa, peer);
1032
1033 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1034 ret = wpa_tdls_start(wpa_s->wpa, peer);
1035 else
1036 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001037
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001038 return ret;
1039}
1040
1041
1042static int wpa_supplicant_ctrl_iface_tdls_teardown(
1043 struct wpa_supplicant *wpa_s, char *addr)
1044{
1045 u8 peer[ETH_ALEN];
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001046 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001048 if (os_strcmp(addr, "*") == 0) {
1049 /* remove everyone */
1050 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
1051 wpa_tdls_teardown_peers(wpa_s->wpa);
1052 return 0;
1053 }
1054
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055 if (hwaddr_aton(addr, peer)) {
1056 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
1057 "address '%s'", addr);
1058 return -1;
1059 }
1060
1061 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
1062 MAC2STR(peer));
1063
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001064 if ((wpa_s->conf->tdls_external_control) &&
1065 wpa_tdls_is_external_setup(wpa_s->wpa))
1066 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1067
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001068 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1069 ret = wpa_tdls_teardown_link(
1070 wpa_s->wpa, peer,
1071 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
1072 else
1073 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1074
1075 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076}
1077
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001078
1079static int ctrl_iface_get_capability_tdls(
1080 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1081{
1082 int ret;
1083
1084 ret = os_snprintf(buf, buflen, "%s\n",
1085 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
1086 (wpa_s->drv_flags &
1087 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
1088 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001089 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001090 return -1;
1091 return ret;
1092}
1093
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001094
1095static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
1096 struct wpa_supplicant *wpa_s, char *cmd)
1097{
1098 u8 peer[ETH_ALEN];
1099 struct hostapd_freq_params freq_params;
1100 u8 oper_class;
1101 char *pos, *end;
1102
1103 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1104 wpa_printf(MSG_INFO,
1105 "tdls_chanswitch: Only supported with external setup");
1106 return -1;
1107 }
1108
1109 os_memset(&freq_params, 0, sizeof(freq_params));
1110
1111 pos = os_strchr(cmd, ' ');
1112 if (pos == NULL)
1113 return -1;
1114 *pos++ = '\0';
1115
1116 oper_class = strtol(pos, &end, 10);
1117 if (pos == end) {
1118 wpa_printf(MSG_INFO,
1119 "tdls_chanswitch: Invalid op class provided");
1120 return -1;
1121 }
1122
1123 pos = end;
1124 freq_params.freq = atoi(pos);
1125 if (freq_params.freq == 0) {
1126 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
1127 return -1;
1128 }
1129
1130#define SET_FREQ_SETTING(str) \
1131 do { \
1132 const char *pos2 = os_strstr(pos, " " #str "="); \
1133 if (pos2) { \
1134 pos2 += sizeof(" " #str "=") - 1; \
1135 freq_params.str = atoi(pos2); \
1136 } \
1137 } while (0)
1138
1139 SET_FREQ_SETTING(center_freq1);
1140 SET_FREQ_SETTING(center_freq2);
1141 SET_FREQ_SETTING(bandwidth);
1142 SET_FREQ_SETTING(sec_channel_offset);
1143#undef SET_FREQ_SETTING
1144
1145 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1146 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1147
1148 if (hwaddr_aton(cmd, peer)) {
1149 wpa_printf(MSG_DEBUG,
1150 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1151 cmd);
1152 return -1;
1153 }
1154
1155 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1156 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1157 MAC2STR(peer), oper_class, freq_params.freq,
1158 freq_params.center_freq1, freq_params.center_freq2,
1159 freq_params.bandwidth, freq_params.sec_channel_offset,
1160 freq_params.ht_enabled ? " HT" : "",
1161 freq_params.vht_enabled ? " VHT" : "");
1162
1163 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1164 &freq_params);
1165}
1166
1167
1168static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1169 struct wpa_supplicant *wpa_s, char *cmd)
1170{
1171 u8 peer[ETH_ALEN];
1172
1173 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1174 wpa_printf(MSG_INFO,
1175 "tdls_chanswitch: Only supported with external setup");
1176 return -1;
1177 }
1178
1179 if (hwaddr_aton(cmd, peer)) {
1180 wpa_printf(MSG_DEBUG,
1181 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1182 cmd);
1183 return -1;
1184 }
1185
1186 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1187 MAC2STR(peer));
1188
1189 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1190}
1191
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07001192
1193static int wpa_supplicant_ctrl_iface_tdls_link_status(
1194 struct wpa_supplicant *wpa_s, const char *addr,
1195 char *buf, size_t buflen)
1196{
1197 u8 peer[ETH_ALEN];
1198 const char *tdls_status;
1199 int ret;
1200
1201 if (hwaddr_aton(addr, peer)) {
1202 wpa_printf(MSG_DEBUG,
1203 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1204 addr);
1205 return -1;
1206 }
1207 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1208 MAC2STR(peer));
1209
1210 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1211 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1212 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1213 if (os_snprintf_error(buflen, ret))
1214 return -1;
1215
1216 return ret;
1217}
1218
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001219#endif /* CONFIG_TDLS */
1220
1221
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001222static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1223{
1224 char *token, *context = NULL;
1225 struct wmm_ac_ts_setup_params params = {
1226 .tsid = 0xff,
1227 .direction = 0xff,
1228 };
1229
1230 while ((token = str_token(cmd, " ", &context))) {
1231 if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
1232 sscanf(token, "up=%i", &params.user_priority) == 1 ||
1233 sscanf(token, "nominal_msdu_size=%i",
1234 &params.nominal_msdu_size) == 1 ||
1235 sscanf(token, "mean_data_rate=%i",
1236 &params.mean_data_rate) == 1 ||
1237 sscanf(token, "min_phy_rate=%i",
1238 &params.minimum_phy_rate) == 1 ||
1239 sscanf(token, "sba=%i",
1240 &params.surplus_bandwidth_allowance) == 1)
1241 continue;
1242
1243 if (os_strcasecmp(token, "downlink") == 0) {
1244 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1245 } else if (os_strcasecmp(token, "uplink") == 0) {
1246 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1247 } else if (os_strcasecmp(token, "bidi") == 0) {
1248 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1249 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1250 params.fixed_nominal_msdu = 1;
1251 } else {
1252 wpa_printf(MSG_DEBUG,
1253 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1254 token);
1255 return -1;
1256 }
1257
1258 }
1259
1260 return wpas_wmm_ac_addts(wpa_s, &params);
1261}
1262
1263
1264static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1265{
1266 u8 tsid = atoi(cmd);
1267
1268 return wpas_wmm_ac_delts(wpa_s, tsid);
1269}
1270
1271
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001272#ifdef CONFIG_IEEE80211R
1273static int wpa_supplicant_ctrl_iface_ft_ds(
1274 struct wpa_supplicant *wpa_s, char *addr)
1275{
1276 u8 target_ap[ETH_ALEN];
1277 struct wpa_bss *bss;
1278 const u8 *mdie;
1279
1280 if (hwaddr_aton(addr, target_ap)) {
1281 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1282 "address '%s'", addr);
1283 return -1;
1284 }
1285
1286 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1287
1288 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1289 if (bss)
1290 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1291 else
1292 mdie = NULL;
1293
1294 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
1295}
1296#endif /* CONFIG_IEEE80211R */
1297
1298
1299#ifdef CONFIG_WPS
1300static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1301 char *cmd)
1302{
1303 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001304#ifdef CONFIG_P2P
1305 u8 p2p_dev_addr[ETH_ALEN];
1306#endif /* CONFIG_P2P */
1307#ifdef CONFIG_AP
1308 u8 *_p2p_dev_addr = NULL;
1309#endif /* CONFIG_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001310 char *pos;
1311 int multi_ap = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001312
Hai Shalom021b0b52019-04-10 11:17:58 -07001313 if (!cmd || os_strcmp(cmd, "any") == 0 ||
1314 os_strncmp(cmd, "any ", 4) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315 _bssid = NULL;
1316#ifdef CONFIG_P2P
1317 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1318 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1319 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1320 "P2P Device Address '%s'",
1321 cmd + 13);
1322 return -1;
1323 }
1324 _p2p_dev_addr = p2p_dev_addr;
1325#endif /* CONFIG_P2P */
Hai Shalom021b0b52019-04-10 11:17:58 -07001326 } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) {
1327 _bssid = NULL;
1328 multi_ap = atoi(cmd + 9);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001329 } else if (hwaddr_aton(cmd, bssid)) {
1330 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1331 cmd);
1332 return -1;
1333 }
1334
Hai Shalom021b0b52019-04-10 11:17:58 -07001335 if (cmd) {
1336 pos = os_strstr(cmd, " multi_ap=");
1337 if (pos) {
1338 pos += 10;
1339 multi_ap = atoi(pos);
1340 }
1341 }
1342
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001343#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001344 if (wpa_s->ap_iface)
1345 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1346#endif /* CONFIG_AP */
1347
Hai Shalom021b0b52019-04-10 11:17:58 -07001348 return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001349}
1350
1351
1352static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1353 char *cmd, char *buf,
1354 size_t buflen)
1355{
1356 u8 bssid[ETH_ALEN], *_bssid = bssid;
1357 char *pin;
1358 int ret;
1359
1360 pin = os_strchr(cmd, ' ');
1361 if (pin)
1362 *pin++ = '\0';
1363
1364 if (os_strcmp(cmd, "any") == 0)
1365 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001366 else if (os_strcmp(cmd, "get") == 0) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001367 if (wps_generate_pin((unsigned int *) &ret) < 0)
1368 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001369 goto done;
1370 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001371 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1372 cmd);
1373 return -1;
1374 }
1375
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001376#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001377 if (wpa_s->ap_iface) {
1378 int timeout = 0;
1379 char *pos;
1380
1381 if (pin) {
1382 pos = os_strchr(pin, ' ');
1383 if (pos) {
1384 *pos++ = '\0';
1385 timeout = atoi(pos);
1386 }
1387 }
1388
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001389 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001390 buf, buflen, timeout);
1391 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001392#endif /* CONFIG_AP */
1393
1394 if (pin) {
1395 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1396 DEV_PW_DEFAULT);
1397 if (ret < 0)
1398 return -1;
1399 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001400 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001401 return -1;
1402 return ret;
1403 }
1404
1405 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1406 if (ret < 0)
1407 return -1;
1408
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001409done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001410 /* Return the generated PIN */
1411 ret = os_snprintf(buf, buflen, "%08d", ret);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001412 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001413 return -1;
1414 return ret;
1415}
1416
1417
1418static int wpa_supplicant_ctrl_iface_wps_check_pin(
1419 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1420{
1421 char pin[9];
1422 size_t len;
1423 char *pos;
1424 int ret;
1425
1426 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1427 (u8 *) cmd, os_strlen(cmd));
1428 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1429 if (*pos < '0' || *pos > '9')
1430 continue;
1431 pin[len++] = *pos;
1432 if (len == 9) {
1433 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1434 return -1;
1435 }
1436 }
1437 if (len != 4 && len != 8) {
1438 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1439 return -1;
1440 }
1441 pin[len] = '\0';
1442
1443 if (len == 8) {
1444 unsigned int pin_val;
1445 pin_val = atoi(pin);
1446 if (!wps_pin_valid(pin_val)) {
1447 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1448 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001449 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001450 return -1;
1451 return ret;
1452 }
1453 }
1454
1455 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001456 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001457 return -1;
1458
1459 return ret;
1460}
1461
1462
Dmitry Shmidt04949592012-07-19 12:16:46 -07001463#ifdef CONFIG_WPS_NFC
1464
1465static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1466 char *cmd)
1467{
1468 u8 bssid[ETH_ALEN], *_bssid = bssid;
1469
1470 if (cmd == NULL || cmd[0] == '\0')
1471 _bssid = NULL;
1472 else if (hwaddr_aton(cmd, bssid))
1473 return -1;
1474
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001475 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1476 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001477}
1478
1479
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001480static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1481 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1482{
1483 int ndef;
1484 struct wpabuf *buf;
1485 int res;
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001486 char *pos;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001487
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001488 pos = os_strchr(cmd, ' ');
1489 if (pos)
1490 *pos++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001491 if (os_strcmp(cmd, "WPS") == 0)
1492 ndef = 0;
1493 else if (os_strcmp(cmd, "NDEF") == 0)
1494 ndef = 1;
1495 else
1496 return -1;
1497
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001498 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001499 if (buf == NULL)
1500 return -1;
1501
1502 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1503 wpabuf_len(buf));
1504 reply[res++] = '\n';
1505 reply[res] = '\0';
1506
1507 wpabuf_free(buf);
1508
1509 return res;
1510}
1511
1512
Dmitry Shmidt04949592012-07-19 12:16:46 -07001513static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1514 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1515{
1516 int ndef;
1517 struct wpabuf *buf;
1518 int res;
1519
1520 if (os_strcmp(cmd, "WPS") == 0)
1521 ndef = 0;
1522 else if (os_strcmp(cmd, "NDEF") == 0)
1523 ndef = 1;
1524 else
1525 return -1;
1526
1527 buf = wpas_wps_nfc_token(wpa_s, ndef);
1528 if (buf == NULL)
1529 return -1;
1530
1531 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1532 wpabuf_len(buf));
1533 reply[res++] = '\n';
1534 reply[res] = '\0';
1535
1536 wpabuf_free(buf);
1537
1538 return res;
1539}
1540
1541
1542static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1543 struct wpa_supplicant *wpa_s, char *pos)
1544{
1545 size_t len;
1546 struct wpabuf *buf;
1547 int ret;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001548 char *freq;
1549 int forced_freq = 0;
1550
1551 freq = strstr(pos, " freq=");
1552 if (freq) {
1553 *freq = '\0';
1554 freq += 6;
1555 forced_freq = atoi(freq);
1556 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001557
1558 len = os_strlen(pos);
1559 if (len & 0x01)
1560 return -1;
1561 len /= 2;
1562
1563 buf = wpabuf_alloc(len);
1564 if (buf == NULL)
1565 return -1;
1566 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1567 wpabuf_free(buf);
1568 return -1;
1569 }
1570
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001571 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001572 wpabuf_free(buf);
1573
1574 return ret;
1575}
1576
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001577
1578static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001579 char *reply, size_t max_len,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001580 int ndef)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001581{
1582 struct wpabuf *buf;
1583 int res;
1584
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001585 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001586 if (buf == NULL)
1587 return -1;
1588
1589 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1590 wpabuf_len(buf));
1591 reply[res++] = '\n';
1592 reply[res] = '\0';
1593
1594 wpabuf_free(buf);
1595
1596 return res;
1597}
1598
1599
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001600#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001601static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1602 char *reply, size_t max_len,
1603 int ndef)
1604{
1605 struct wpabuf *buf;
1606 int res;
1607
1608 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1609 if (buf == NULL) {
1610 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1611 return -1;
1612 }
1613
1614 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1615 wpabuf_len(buf));
1616 reply[res++] = '\n';
1617 reply[res] = '\0';
1618
1619 wpabuf_free(buf);
1620
1621 return res;
1622}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001623#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001624
1625
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001626static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1627 char *cmd, char *reply,
1628 size_t max_len)
1629{
1630 char *pos;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001631 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001632
1633 pos = os_strchr(cmd, ' ');
1634 if (pos == NULL)
1635 return -1;
1636 *pos++ = '\0';
1637
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001638 if (os_strcmp(cmd, "WPS") == 0)
1639 ndef = 0;
1640 else if (os_strcmp(cmd, "NDEF") == 0)
1641 ndef = 1;
1642 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001643 return -1;
1644
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001645 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001646 if (!ndef)
1647 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001648 return wpas_ctrl_nfc_get_handover_req_wps(
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001649 wpa_s, reply, max_len, ndef);
1650 }
1651
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001652#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001653 if (os_strcmp(pos, "P2P-CR") == 0) {
1654 return wpas_ctrl_nfc_get_handover_req_p2p(
1655 wpa_s, reply, max_len, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001656 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001657#endif /* CONFIG_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001658
1659 return -1;
1660}
1661
1662
1663static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001664 char *reply, size_t max_len,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001665 int ndef, int cr, char *uuid)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001666{
1667 struct wpabuf *buf;
1668 int res;
1669
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001670 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001671 if (buf == NULL)
1672 return -1;
1673
1674 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1675 wpabuf_len(buf));
1676 reply[res++] = '\n';
1677 reply[res] = '\0';
1678
1679 wpabuf_free(buf);
1680
1681 return res;
1682}
1683
1684
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001685#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001686static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1687 char *reply, size_t max_len,
1688 int ndef, int tag)
1689{
1690 struct wpabuf *buf;
1691 int res;
1692
1693 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1694 if (buf == NULL)
1695 return -1;
1696
1697 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1698 wpabuf_len(buf));
1699 reply[res++] = '\n';
1700 reply[res] = '\0';
1701
1702 wpabuf_free(buf);
1703
1704 return res;
1705}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001706#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001707
1708
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001709static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1710 char *cmd, char *reply,
1711 size_t max_len)
1712{
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001713 char *pos, *pos2;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001714 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001715
1716 pos = os_strchr(cmd, ' ');
1717 if (pos == NULL)
1718 return -1;
1719 *pos++ = '\0';
1720
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001721 if (os_strcmp(cmd, "WPS") == 0)
1722 ndef = 0;
1723 else if (os_strcmp(cmd, "NDEF") == 0)
1724 ndef = 1;
1725 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001726 return -1;
1727
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001728 pos2 = os_strchr(pos, ' ');
1729 if (pos2)
1730 *pos2++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001731 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001732 if (!ndef)
1733 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001734 return wpas_ctrl_nfc_get_handover_sel_wps(
1735 wpa_s, reply, max_len, ndef,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001736 os_strcmp(pos, "WPS-CR") == 0, pos2);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001737 }
1738
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001739#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001740 if (os_strcmp(pos, "P2P-CR") == 0) {
1741 return wpas_ctrl_nfc_get_handover_sel_p2p(
1742 wpa_s, reply, max_len, ndef, 0);
1743 }
1744
1745 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1746 return wpas_ctrl_nfc_get_handover_sel_p2p(
1747 wpa_s, reply, max_len, ndef, 1);
1748 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001749#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001750
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001751 return -1;
1752}
1753
1754
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001755static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1756 char *cmd)
1757{
1758 size_t len;
1759 struct wpabuf *req, *sel;
1760 int ret;
1761 char *pos, *role, *type, *pos2;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001762#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001763 char *freq;
1764 int forced_freq = 0;
1765
1766 freq = strstr(cmd, " freq=");
1767 if (freq) {
1768 *freq = '\0';
1769 freq += 6;
1770 forced_freq = atoi(freq);
1771 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001772#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001773
1774 role = cmd;
1775 pos = os_strchr(role, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001776 if (pos == NULL) {
1777 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001778 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001779 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001780 *pos++ = '\0';
1781
1782 type = pos;
1783 pos = os_strchr(type, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001784 if (pos == NULL) {
1785 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001786 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001787 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001788 *pos++ = '\0';
1789
1790 pos2 = os_strchr(pos, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001791 if (pos2 == NULL) {
1792 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001793 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001794 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001795 *pos2++ = '\0';
1796
1797 len = os_strlen(pos);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001798 if (len & 0x01) {
1799 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001800 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001801 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001802 len /= 2;
1803
1804 req = wpabuf_alloc(len);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001805 if (req == NULL) {
1806 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001807 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001808 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001809 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001810 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001811 wpabuf_free(req);
1812 return -1;
1813 }
1814
1815 len = os_strlen(pos2);
1816 if (len & 0x01) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001817 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001818 wpabuf_free(req);
1819 return -1;
1820 }
1821 len /= 2;
1822
1823 sel = wpabuf_alloc(len);
1824 if (sel == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001825 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001826 wpabuf_free(req);
1827 return -1;
1828 }
1829 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001830 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001831 wpabuf_free(req);
1832 wpabuf_free(sel);
1833 return -1;
1834 }
1835
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001836 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1837 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1838
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001839 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1840 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001841#ifdef CONFIG_AP
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001842 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1843 {
1844 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1845 if (ret < 0)
1846 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001847#endif /* CONFIG_AP */
1848#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001849 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1850 {
1851 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1852 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1853 {
1854 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1855 forced_freq);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001856#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001857 } else {
1858 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1859 "reported: role=%s type=%s", role, type);
1860 ret = -1;
1861 }
1862 wpabuf_free(req);
1863 wpabuf_free(sel);
1864
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001865 if (ret)
1866 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1867
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001868 return ret;
1869}
1870
Dmitry Shmidt04949592012-07-19 12:16:46 -07001871#endif /* CONFIG_WPS_NFC */
1872
1873
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001874static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1875 char *cmd)
1876{
1877 u8 bssid[ETH_ALEN];
1878 char *pin;
1879 char *new_ssid;
1880 char *new_auth;
1881 char *new_encr;
1882 char *new_key;
1883 struct wps_new_ap_settings ap;
1884
1885 pin = os_strchr(cmd, ' ');
1886 if (pin == NULL)
1887 return -1;
1888 *pin++ = '\0';
1889
1890 if (hwaddr_aton(cmd, bssid)) {
1891 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1892 cmd);
1893 return -1;
1894 }
1895
1896 new_ssid = os_strchr(pin, ' ');
1897 if (new_ssid == NULL)
1898 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1899 *new_ssid++ = '\0';
1900
1901 new_auth = os_strchr(new_ssid, ' ');
1902 if (new_auth == NULL)
1903 return -1;
1904 *new_auth++ = '\0';
1905
1906 new_encr = os_strchr(new_auth, ' ');
1907 if (new_encr == NULL)
1908 return -1;
1909 *new_encr++ = '\0';
1910
1911 new_key = os_strchr(new_encr, ' ');
1912 if (new_key == NULL)
1913 return -1;
1914 *new_key++ = '\0';
1915
1916 os_memset(&ap, 0, sizeof(ap));
1917 ap.ssid_hex = new_ssid;
1918 ap.auth = new_auth;
1919 ap.encr = new_encr;
1920 ap.key_hex = new_key;
1921 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1922}
1923
1924
1925#ifdef CONFIG_AP
1926static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1927 char *cmd, char *buf,
1928 size_t buflen)
1929{
1930 int timeout = 300;
1931 char *pos;
1932 const char *pin_txt;
1933
1934 if (!wpa_s->ap_iface)
1935 return -1;
1936
1937 pos = os_strchr(cmd, ' ');
1938 if (pos)
1939 *pos++ = '\0';
1940
1941 if (os_strcmp(cmd, "disable") == 0) {
1942 wpas_wps_ap_pin_disable(wpa_s);
1943 return os_snprintf(buf, buflen, "OK\n");
1944 }
1945
1946 if (os_strcmp(cmd, "random") == 0) {
1947 if (pos)
1948 timeout = atoi(pos);
1949 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1950 if (pin_txt == NULL)
1951 return -1;
1952 return os_snprintf(buf, buflen, "%s", pin_txt);
1953 }
1954
1955 if (os_strcmp(cmd, "get") == 0) {
1956 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1957 if (pin_txt == NULL)
1958 return -1;
1959 return os_snprintf(buf, buflen, "%s", pin_txt);
1960 }
1961
1962 if (os_strcmp(cmd, "set") == 0) {
1963 char *pin;
1964 if (pos == NULL)
1965 return -1;
1966 pin = pos;
1967 pos = os_strchr(pos, ' ');
1968 if (pos) {
1969 *pos++ = '\0';
1970 timeout = atoi(pos);
1971 }
1972 if (os_strlen(pin) > buflen)
1973 return -1;
1974 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1975 return -1;
1976 return os_snprintf(buf, buflen, "%s", pin);
1977 }
1978
1979 return -1;
1980}
1981#endif /* CONFIG_AP */
1982
1983
1984#ifdef CONFIG_WPS_ER
1985static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1986 char *cmd)
1987{
1988 char *uuid = cmd, *pin, *pos;
1989 u8 addr_buf[ETH_ALEN], *addr = NULL;
1990 pin = os_strchr(uuid, ' ');
1991 if (pin == NULL)
1992 return -1;
1993 *pin++ = '\0';
1994 pos = os_strchr(pin, ' ');
1995 if (pos) {
1996 *pos++ = '\0';
1997 if (hwaddr_aton(pos, addr_buf) == 0)
1998 addr = addr_buf;
1999 }
2000 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
2001}
2002
2003
2004static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
2005 char *cmd)
2006{
2007 char *uuid = cmd, *pin;
2008 pin = os_strchr(uuid, ' ');
2009 if (pin == NULL)
2010 return -1;
2011 *pin++ = '\0';
2012 return wpas_wps_er_learn(wpa_s, uuid, pin);
2013}
2014
2015
2016static int wpa_supplicant_ctrl_iface_wps_er_set_config(
2017 struct wpa_supplicant *wpa_s, char *cmd)
2018{
2019 char *uuid = cmd, *id;
2020 id = os_strchr(uuid, ' ');
2021 if (id == NULL)
2022 return -1;
2023 *id++ = '\0';
2024 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
2025}
2026
2027
2028static int wpa_supplicant_ctrl_iface_wps_er_config(
2029 struct wpa_supplicant *wpa_s, char *cmd)
2030{
2031 char *pin;
2032 char *new_ssid;
2033 char *new_auth;
2034 char *new_encr;
2035 char *new_key;
2036 struct wps_new_ap_settings ap;
2037
2038 pin = os_strchr(cmd, ' ');
2039 if (pin == NULL)
2040 return -1;
2041 *pin++ = '\0';
2042
2043 new_ssid = os_strchr(pin, ' ');
2044 if (new_ssid == NULL)
2045 return -1;
2046 *new_ssid++ = '\0';
2047
2048 new_auth = os_strchr(new_ssid, ' ');
2049 if (new_auth == NULL)
2050 return -1;
2051 *new_auth++ = '\0';
2052
2053 new_encr = os_strchr(new_auth, ' ');
2054 if (new_encr == NULL)
2055 return -1;
2056 *new_encr++ = '\0';
2057
2058 new_key = os_strchr(new_encr, ' ');
2059 if (new_key == NULL)
2060 return -1;
2061 *new_key++ = '\0';
2062
2063 os_memset(&ap, 0, sizeof(ap));
2064 ap.ssid_hex = new_ssid;
2065 ap.auth = new_auth;
2066 ap.encr = new_encr;
2067 ap.key_hex = new_key;
2068 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
2069}
Dmitry Shmidt04949592012-07-19 12:16:46 -07002070
2071
2072#ifdef CONFIG_WPS_NFC
2073static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
2074 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2075{
2076 int ndef;
2077 struct wpabuf *buf;
2078 int res;
2079 char *uuid;
2080
2081 uuid = os_strchr(cmd, ' ');
2082 if (uuid == NULL)
2083 return -1;
2084 *uuid++ = '\0';
2085
2086 if (os_strcmp(cmd, "WPS") == 0)
2087 ndef = 0;
2088 else if (os_strcmp(cmd, "NDEF") == 0)
2089 ndef = 1;
2090 else
2091 return -1;
2092
2093 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
2094 if (buf == NULL)
2095 return -1;
2096
2097 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
2098 wpabuf_len(buf));
2099 reply[res++] = '\n';
2100 reply[res] = '\0';
2101
2102 wpabuf_free(buf);
2103
2104 return res;
2105}
2106#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002107#endif /* CONFIG_WPS_ER */
2108
2109#endif /* CONFIG_WPS */
2110
2111
2112#ifdef CONFIG_IBSS_RSN
2113static int wpa_supplicant_ctrl_iface_ibss_rsn(
2114 struct wpa_supplicant *wpa_s, char *addr)
2115{
2116 u8 peer[ETH_ALEN];
2117
2118 if (hwaddr_aton(addr, peer)) {
2119 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
2120 "address '%s'", addr);
2121 return -1;
2122 }
2123
2124 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
2125 MAC2STR(peer));
2126
2127 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
2128}
2129#endif /* CONFIG_IBSS_RSN */
2130
2131
2132static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
2133 char *rsp)
2134{
2135#ifdef IEEE8021X_EAPOL
2136 char *pos, *id_pos;
2137 int id;
2138 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002139
2140 pos = os_strchr(rsp, '-');
2141 if (pos == NULL)
2142 return -1;
2143 *pos++ = '\0';
2144 id_pos = pos;
2145 pos = os_strchr(pos, ':');
2146 if (pos == NULL)
2147 return -1;
2148 *pos++ = '\0';
2149 id = atoi(id_pos);
2150 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
2151 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2152 (u8 *) pos, os_strlen(pos));
2153
2154 ssid = wpa_config_get_network(wpa_s->conf, id);
2155 if (ssid == NULL) {
2156 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2157 "to update", id);
2158 return -1;
2159 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002160
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002161 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2162 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002163#else /* IEEE8021X_EAPOL */
2164 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2165 return -1;
2166#endif /* IEEE8021X_EAPOL */
2167}
2168
2169
2170static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2171 const char *params,
2172 char *buf, size_t buflen)
2173{
2174 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002175 int res, verbose, wps, ret;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002176#ifdef CONFIG_HS20
2177 const u8 *hs20;
2178#endif /* CONFIG_HS20 */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002179 const u8 *sess_id;
2180 size_t sess_id_len;
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002181
Dmitry Shmidt56052862013-10-04 10:23:25 -07002182 if (os_strcmp(params, "-DRIVER") == 0)
2183 return wpa_drv_status(wpa_s, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002184 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002185 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002186 pos = buf;
2187 end = buf + buflen;
2188 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2189 struct wpa_ssid *ssid = wpa_s->current_ssid;
2190 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2191 MAC2STR(wpa_s->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002192 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002193 return pos - buf;
2194 pos += ret;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002195 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2196 wpa_s->assoc_freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002197 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002198 return pos - buf;
2199 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002200 if (ssid) {
2201 u8 *_ssid = ssid->ssid;
2202 size_t ssid_len = ssid->ssid_len;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002203 u8 ssid_buf[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002204 if (ssid_len == 0) {
2205 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2206 if (_res < 0)
2207 ssid_len = 0;
2208 else
2209 ssid_len = _res;
2210 _ssid = ssid_buf;
2211 }
2212 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2213 wpa_ssid_txt(_ssid, ssid_len),
2214 ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002215 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002216 return pos - buf;
2217 pos += ret;
2218
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002219 if (wps && ssid->passphrase &&
2220 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2221 (ssid->mode == WPAS_MODE_AP ||
2222 ssid->mode == WPAS_MODE_P2P_GO)) {
2223 ret = os_snprintf(pos, end - pos,
2224 "passphrase=%s\n",
2225 ssid->passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002226 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002227 return pos - buf;
2228 pos += ret;
2229 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002230 if (ssid->id_str) {
2231 ret = os_snprintf(pos, end - pos,
2232 "id_str=%s\n",
2233 ssid->id_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002234 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002235 return pos - buf;
2236 pos += ret;
2237 }
2238
2239 switch (ssid->mode) {
2240 case WPAS_MODE_INFRA:
2241 ret = os_snprintf(pos, end - pos,
2242 "mode=station\n");
2243 break;
2244 case WPAS_MODE_IBSS:
2245 ret = os_snprintf(pos, end - pos,
2246 "mode=IBSS\n");
2247 break;
2248 case WPAS_MODE_AP:
2249 ret = os_snprintf(pos, end - pos,
2250 "mode=AP\n");
2251 break;
2252 case WPAS_MODE_P2P_GO:
2253 ret = os_snprintf(pos, end - pos,
2254 "mode=P2P GO\n");
2255 break;
2256 case WPAS_MODE_P2P_GROUP_FORMATION:
2257 ret = os_snprintf(pos, end - pos,
2258 "mode=P2P GO - group "
2259 "formation\n");
2260 break;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002261 case WPAS_MODE_MESH:
2262 ret = os_snprintf(pos, end - pos,
2263 "mode=mesh\n");
2264 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002265 default:
2266 ret = 0;
2267 break;
2268 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002269 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002270 return pos - buf;
2271 pos += ret;
2272 }
2273
Hai Shalom021b0b52019-04-10 11:17:58 -07002274 if (wpa_s->connection_set &&
2275 (wpa_s->connection_ht || wpa_s->connection_vht ||
2276 wpa_s->connection_he)) {
2277 ret = os_snprintf(pos, end - pos,
2278 "wifi_generation=%u\n",
2279 wpa_s->connection_he ? 6 :
2280 (wpa_s->connection_vht ? 5 : 4));
2281 if (os_snprintf_error(end - pos, ret))
2282 return pos - buf;
2283 pos += ret;
2284 }
2285
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002286#ifdef CONFIG_AP
2287 if (wpa_s->ap_iface) {
2288 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2289 end - pos,
2290 verbose);
2291 } else
2292#endif /* CONFIG_AP */
2293 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2294 }
Paul Stewart092955c2017-02-06 09:13:09 -08002295#ifdef CONFIG_SME
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002296#ifdef CONFIG_SAE
2297 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002298#ifdef CONFIG_AP
2299 !wpa_s->ap_iface &&
2300#endif /* CONFIG_AP */
2301 wpa_s->sme.sae.state == SAE_ACCEPTED) {
Hai Shalom899fcc72020-10-19 14:38:18 -07002302 ret = os_snprintf(pos, end - pos, "sae_group=%d\n"
2303 "sae_h2e=%d\n"
2304 "sae_pk=%d\n",
2305 wpa_s->sme.sae.group,
2306 wpa_s->sme.sae.h2e,
2307 wpa_s->sme.sae.pk);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002308 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002309 return pos - buf;
2310 pos += ret;
2311 }
2312#endif /* CONFIG_SAE */
Paul Stewart092955c2017-02-06 09:13:09 -08002313#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002314 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2315 wpa_supplicant_state_txt(wpa_s->wpa_state));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002316 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002317 return pos - buf;
2318 pos += ret;
2319
2320 if (wpa_s->l2 &&
2321 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2322 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002323 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002324 return pos - buf;
2325 pos += ret;
2326 }
2327
2328#ifdef CONFIG_P2P
2329 if (wpa_s->global->p2p) {
2330 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2331 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002332 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002333 return pos - buf;
2334 pos += ret;
2335 }
2336#endif /* CONFIG_P2P */
2337
2338 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2339 MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002340 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002341 return pos - buf;
2342 pos += ret;
2343
Dmitry Shmidt04949592012-07-19 12:16:46 -07002344#ifdef CONFIG_HS20
2345 if (wpa_s->current_bss &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002346 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2347 HS20_IE_VENDOR_TYPE)) &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002348 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2349 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002350 int release = 1;
2351 if (hs20[1] >= 5) {
2352 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2353 release = rel_num + 1;
2354 }
2355 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002356 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002357 return pos - buf;
2358 pos += ret;
2359 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002360
2361 if (wpa_s->current_ssid) {
2362 struct wpa_cred *cred;
2363 char *type;
2364
2365 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002366 size_t i;
2367
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002368 if (wpa_s->current_ssid->parent_cred != cred)
2369 continue;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002370
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002371 if (cred->provisioning_sp) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002372 ret = os_snprintf(pos, end - pos,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002373 "provisioning_sp=%s\n",
2374 cred->provisioning_sp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002375 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt051af732013-10-22 13:52:46 -07002376 return pos - buf;
2377 pos += ret;
2378 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002379
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002380 if (!cred->domain)
2381 goto no_domain;
2382
2383 i = 0;
2384 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2385 struct wpabuf *names =
2386 wpa_s->current_bss->anqp->domain_name;
2387 for (i = 0; names && i < cred->num_domain; i++)
2388 {
2389 if (domain_name_list_contains(
2390 names, cred->domain[i], 1))
2391 break;
2392 }
2393 if (i == cred->num_domain)
2394 i = 0; /* show first entry by default */
2395 }
2396 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2397 cred->domain[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002398 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002399 return pos - buf;
2400 pos += ret;
2401
2402 no_domain:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002403 if (wpa_s->current_bss == NULL ||
2404 wpa_s->current_bss->anqp == NULL)
2405 res = -1;
2406 else
2407 res = interworking_home_sp_cred(
2408 wpa_s, cred,
2409 wpa_s->current_bss->anqp->domain_name);
2410 if (res > 0)
2411 type = "home";
2412 else if (res == 0)
2413 type = "roaming";
2414 else
2415 type = "unknown";
2416
2417 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002418 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002419 return pos - buf;
2420 pos += ret;
2421
2422 break;
2423 }
2424 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002425#endif /* CONFIG_HS20 */
2426
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002427 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2428 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2429 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2430 verbose);
2431 if (res >= 0)
2432 pos += res;
2433 }
2434
Dmitry Shmidt29333592017-01-09 12:27:11 -08002435#ifdef CONFIG_MACSEC
2436 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2437 if (res > 0)
2438 pos += res;
2439#endif /* CONFIG_MACSEC */
2440
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002441 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2442 if (sess_id) {
2443 char *start = pos;
2444
2445 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2446 if (os_snprintf_error(end - pos, ret))
2447 return start - buf;
2448 pos += ret;
2449 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2450 if (ret <= 0)
2451 return start - buf;
2452 pos += ret;
2453 ret = os_snprintf(pos, end - pos, "\n");
2454 if (os_snprintf_error(end - pos, ret))
2455 return start - buf;
2456 pos += ret;
2457 }
2458
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002459 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2460 if (res >= 0)
2461 pos += res;
2462
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002463#ifdef CONFIG_WPS
2464 {
2465 char uuid_str[100];
2466 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2467 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002468 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002469 return pos - buf;
2470 pos += ret;
2471 }
2472#endif /* CONFIG_WPS */
2473
Roshan Pius3a1667e2018-07-03 15:17:14 -07002474 if (wpa_s->ieee80211ac) {
2475 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2476 if (os_snprintf_error(end - pos, ret))
2477 return pos - buf;
2478 pos += ret;
2479 }
2480
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002481#ifdef ANDROID
vandwalleffc70182014-09-11 11:40:14 -07002482 /*
2483 * Allow using the STATUS command with default behavior, say for debug,
2484 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2485 * events with STATUS-NO_EVENTS.
2486 */
2487 if (os_strcmp(params, "-NO_EVENTS")) {
2488 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2489 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2490 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2491 wpa_s->wpa_state,
2492 MAC2STR(wpa_s->bssid),
2493 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2494 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2495 wpa_s->current_ssid->ssid_len) : "");
2496 if (wpa_s->wpa_state == WPA_COMPLETED) {
2497 struct wpa_ssid *ssid = wpa_s->current_ssid;
2498 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2499 "- connection to " MACSTR
2500 " completed %s [id=%d id_str=%s]",
2501 MAC2STR(wpa_s->bssid), "(auth)",
2502 ssid ? ssid->id : -1,
2503 ssid && ssid->id_str ? ssid->id_str : "");
2504 }
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08002505 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002506#endif /* ANDROID */
2507
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002508 return pos - buf;
2509}
2510
2511
2512static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2513 char *cmd)
2514{
2515 char *pos;
2516 int id;
2517 struct wpa_ssid *ssid;
2518 u8 bssid[ETH_ALEN];
2519
2520 /* cmd: "<network id> <BSSID>" */
2521 pos = os_strchr(cmd, ' ');
2522 if (pos == NULL)
2523 return -1;
2524 *pos++ = '\0';
2525 id = atoi(cmd);
2526 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2527 if (hwaddr_aton(pos, bssid)) {
2528 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2529 return -1;
2530 }
2531
2532 ssid = wpa_config_get_network(wpa_s->conf, id);
2533 if (ssid == NULL) {
2534 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2535 "to update", id);
2536 return -1;
2537 }
2538
2539 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2540 ssid->bssid_set = !is_zero_ether_addr(bssid);
2541
2542 return 0;
2543}
2544
2545
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002546static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002547 char *cmd, char *buf,
2548 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002549{
2550 u8 bssid[ETH_ALEN];
2551 struct wpa_blacklist *e;
2552 char *pos, *end;
2553 int ret;
2554
2555 /* cmd: "BLACKLIST [<BSSID>]" */
2556 if (*cmd == '\0') {
2557 pos = buf;
2558 end = buf + buflen;
2559 e = wpa_s->blacklist;
2560 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002561 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2562 MAC2STR(e->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002563 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002564 return pos - buf;
2565 pos += ret;
2566 e = e->next;
2567 }
2568 return pos - buf;
2569 }
2570
2571 cmd++;
2572 if (os_strncmp(cmd, "clear", 5) == 0) {
2573 wpa_blacklist_clear(wpa_s);
2574 os_memcpy(buf, "OK\n", 3);
2575 return 3;
2576 }
2577
2578 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
2579 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002580 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002581 return -1;
2582 }
2583
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002584 /*
2585 * Add the BSSID twice, so its count will be 2, causing it to be
2586 * skipped when processing scan results.
2587 */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002588 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002589 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002590 return -1;
2591 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002592 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002593 return -1;
2594 os_memcpy(buf, "OK\n", 3);
2595 return 3;
2596}
2597
2598
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002599static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2600 char *cmd, char *buf,
2601 size_t buflen)
2602{
2603 char *pos, *end, *stamp;
2604 int ret;
2605
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002606 /* cmd: "LOG_LEVEL [<level>]" */
2607 if (*cmd == '\0') {
2608 pos = buf;
2609 end = buf + buflen;
2610 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2611 "Timestamp: %d\n",
2612 debug_level_str(wpa_debug_level),
2613 wpa_debug_timestamp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002614 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002615 ret = 0;
2616
2617 return ret;
2618 }
2619
2620 while (*cmd == ' ')
2621 cmd++;
2622
2623 stamp = os_strchr(cmd, ' ');
2624 if (stamp) {
2625 *stamp++ = '\0';
2626 while (*stamp == ' ') {
2627 stamp++;
2628 }
2629 }
2630
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002631 if (os_strlen(cmd)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002632 int level = str_to_debug_level(cmd);
2633 if (level < 0)
2634 return -1;
2635 wpa_debug_level = level;
2636 }
2637
2638 if (stamp && os_strlen(stamp))
2639 wpa_debug_timestamp = atoi(stamp);
2640
2641 os_memcpy(buf, "OK\n", 3);
2642 return 3;
2643}
2644
2645
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002646static int wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002647 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002648{
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002649 char *pos, *end, *prev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002650 struct wpa_ssid *ssid;
2651 int ret;
2652
2653 pos = buf;
2654 end = buf + buflen;
2655 ret = os_snprintf(pos, end - pos,
2656 "network id / ssid / bssid / flags\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002657 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002658 return pos - buf;
2659 pos += ret;
2660
2661 ssid = wpa_s->conf->ssid;
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002662
2663 /* skip over ssids until we find next one */
2664 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2665 int last_id = atoi(cmd + 8);
2666 if (last_id != -1) {
2667 while (ssid != NULL && ssid->id <= last_id) {
2668 ssid = ssid->next;
2669 }
2670 }
2671 }
2672
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002673 while (ssid) {
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002674 prev = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002675 ret = os_snprintf(pos, end - pos, "%d\t%s",
2676 ssid->id,
2677 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002678 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002679 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002680 pos += ret;
2681 if (ssid->bssid_set) {
2682 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2683 MAC2STR(ssid->bssid));
2684 } else {
2685 ret = os_snprintf(pos, end - pos, "\tany");
2686 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002687 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002688 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002689 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002690 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002691 ssid == wpa_s->current_ssid ?
2692 "[CURRENT]" : "",
2693 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002694 ssid->disabled_until.sec ?
2695 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002696 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
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;
2701 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002702 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002703 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002704 pos += ret;
2705
2706 ssid = ssid->next;
2707 }
2708
2709 return pos - buf;
2710}
2711
2712
2713static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2714{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002715 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002716 ret = os_snprintf(pos, end - pos, "-");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002717 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002718 return pos;
2719 pos += ret;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002720 ret = wpa_write_ciphers(pos, end, cipher, "+");
2721 if (ret < 0)
2722 return pos;
2723 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002724 return pos;
2725}
2726
2727
2728static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2729 const u8 *ie, size_t ie_len)
2730{
2731 struct wpa_ie_data data;
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002732 char *start;
2733 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002734
2735 ret = os_snprintf(pos, end - pos, "[%s-", proto);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002736 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002737 return pos;
2738 pos += ret;
2739
2740 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2741 ret = os_snprintf(pos, end - pos, "?]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002742 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002743 return pos;
2744 pos += ret;
2745 return pos;
2746 }
2747
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002748 start = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002749 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002750 ret = os_snprintf(pos, end - pos, "%sEAP",
2751 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002752 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002753 return pos;
2754 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002755 }
2756 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002757 ret = os_snprintf(pos, end - pos, "%sPSK",
2758 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002759 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002760 return pos;
2761 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002762 }
2763 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002764 ret = os_snprintf(pos, end - pos, "%sNone",
2765 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002766 if (os_snprintf_error(end - pos, ret))
2767 return pos;
2768 pos += ret;
2769 }
2770 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2771 ret = os_snprintf(pos, end - pos, "%sSAE",
2772 pos == start ? "" : "+");
2773 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002774 return pos;
2775 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002776 }
2777#ifdef CONFIG_IEEE80211R
2778 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2779 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002780 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002781 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002782 return pos;
2783 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002784 }
2785 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2786 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002787 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002788 if (os_snprintf_error(end - pos, ret))
2789 return pos;
2790 pos += ret;
2791 }
2792 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2793 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2794 pos == start ? "" : "+");
2795 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002796 return pos;
2797 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002798 }
2799#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002800 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2801 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002802 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002803 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002804 return pos;
2805 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002806 }
2807 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2808 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002809 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002810 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002811 return pos;
2812 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002813 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002814
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002815#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002816 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2817 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2818 pos == start ? "" : "+");
2819 if (os_snprintf_error(end - pos, ret))
2820 return pos;
2821 pos += ret;
2822 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002823#endif /* CONFIG_SUITEB */
2824
2825#ifdef CONFIG_SUITEB192
2826 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2827 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2828 pos == start ? "" : "+");
2829 if (os_snprintf_error(end - pos, ret))
2830 return pos;
2831 pos += ret;
2832 }
2833#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002834
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002835#ifdef CONFIG_FILS
2836 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2837 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2838 pos == start ? "" : "+");
2839 if (os_snprintf_error(end - pos, ret))
2840 return pos;
2841 pos += ret;
2842 }
2843 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2844 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2845 pos == start ? "" : "+");
2846 if (os_snprintf_error(end - pos, ret))
2847 return pos;
2848 pos += ret;
2849 }
2850#ifdef CONFIG_IEEE80211R
2851 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2852 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2853 pos == start ? "" : "+");
2854 if (os_snprintf_error(end - pos, ret))
2855 return pos;
2856 pos += ret;
2857 }
2858 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2859 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2860 pos == start ? "" : "+");
2861 if (os_snprintf_error(end - pos, ret))
2862 return pos;
2863 pos += ret;
2864 }
2865#endif /* CONFIG_IEEE80211R */
2866#endif /* CONFIG_FILS */
2867
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002868#ifdef CONFIG_OWE
2869 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2870 ret = os_snprintf(pos, end - pos, "%sOWE",
2871 pos == start ? "" : "+");
2872 if (os_snprintf_error(end - pos, ret))
2873 return pos;
2874 pos += ret;
2875 }
2876#endif /* CONFIG_OWE */
2877
2878#ifdef CONFIG_DPP
2879 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
2880 ret = os_snprintf(pos, end - pos, "%sDPP",
2881 pos == start ? "" : "+");
2882 if (os_snprintf_error(end - pos, ret))
2883 return pos;
2884 pos += ret;
2885 }
2886#endif /* CONFIG_DPP */
2887
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002888 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2889 ret = os_snprintf(pos, end - pos, "%sOSEN",
2890 pos == start ? "" : "+");
2891 if (os_snprintf_error(end - pos, ret))
2892 return pos;
2893 pos += ret;
2894 }
2895
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002896 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2897
2898 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2899 ret = os_snprintf(pos, end - pos, "-preauth");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002900 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002901 return pos;
2902 pos += ret;
2903 }
2904
2905 ret = os_snprintf(pos, end - pos, "]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002906 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002907 return pos;
2908 pos += ret;
2909
2910 return pos;
2911}
2912
2913
2914#ifdef CONFIG_WPS
2915static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2916 char *pos, char *end,
2917 struct wpabuf *wps_ie)
2918{
2919 int ret;
2920 const char *txt;
2921
2922 if (wps_ie == NULL)
2923 return pos;
2924 if (wps_is_selected_pbc_registrar(wps_ie))
2925 txt = "[WPS-PBC]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002926 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2927 txt = "[WPS-AUTH]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002928 else if (wps_is_selected_pin_registrar(wps_ie))
2929 txt = "[WPS-PIN]";
2930 else
2931 txt = "[WPS]";
2932
2933 ret = os_snprintf(pos, end - pos, "%s", txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002934 if (!os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002935 pos += ret;
2936 wpabuf_free(wps_ie);
2937 return pos;
2938}
2939#endif /* CONFIG_WPS */
2940
2941
2942static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2943 char *pos, char *end,
2944 const struct wpa_bss *bss)
2945{
2946#ifdef CONFIG_WPS
2947 struct wpabuf *wps_ie;
2948 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2949 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2950#else /* CONFIG_WPS */
2951 return pos;
2952#endif /* CONFIG_WPS */
2953}
2954
2955
2956/* Format one result on one text line into a buffer. */
2957static int wpa_supplicant_ctrl_iface_scan_result(
2958 struct wpa_supplicant *wpa_s,
2959 const struct wpa_bss *bss, char *buf, size_t buflen)
2960{
2961 char *pos, *end;
2962 int ret;
Hai Shalom899fcc72020-10-19 14:38:18 -07002963 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe, *rsnxe;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002964
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002965 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002966 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07002967 if (!p2p)
2968 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002969 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2970 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2971 0)
2972 return 0; /* Do not show P2P listen discovery results here */
2973
2974 pos = buf;
2975 end = buf + buflen;
2976
2977 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2978 MAC2STR(bss->bssid), bss->freq, bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002979 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002980 return -1;
2981 pos += ret;
2982 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2983 if (ie)
2984 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2985 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002986 if (ie2) {
2987 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2988 ie2, 2 + ie2[1]);
2989 }
Hai Shalom899fcc72020-10-19 14:38:18 -07002990 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
2991 if (rsnxe && rsnxe[1] >= 1) {
2992 if (rsnxe[2] & BIT(WLAN_RSNX_CAPAB_SAE_H2E)) {
2993 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
2994 if (os_snprintf_error(end - pos, ret))
2995 return -1;
2996 pos += ret;
2997 }
2998 if (rsnxe[2] & BIT(WLAN_RSNX_CAPAB_SAE_PK)) {
2999 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
3000 if (os_snprintf_error(end - pos, ret))
3001 return -1;
3002 pos += ret;
3003 }
3004 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003005 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
3006 if (osen_ie)
3007 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
3008 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003009 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
3010 if (owe) {
3011 ret = os_snprintf(pos, end - pos,
3012 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
3013 if (os_snprintf_error(end - pos, ret))
3014 return -1;
3015 pos += ret;
3016 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003017 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07003018 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003019 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003020 if (os_snprintf_error(end - pos, ret))
3021 return -1;
3022 pos += ret;
3023 }
3024 if (mesh) {
3025 ret = os_snprintf(pos, end - pos, "[MESH]");
3026 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003027 return -1;
3028 pos += ret;
3029 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003030 if (bss_is_dmg(bss)) {
3031 const char *s;
Hai Shalomc3565922019-10-28 11:58:20 -07003032
3033 if (get_ie_ext((const u8 *) (bss + 1), bss->ie_len,
3034 WLAN_EID_EXT_EDMG_OPERATION)) {
3035 ret = os_snprintf(pos, end - pos, "[EDMG]");
3036 if (os_snprintf_error(end - pos, ret))
3037 return -1;
3038 pos += ret;
3039 }
3040
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003041 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003042 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003043 return -1;
3044 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003045 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3046 case IEEE80211_CAP_DMG_IBSS:
3047 s = "[IBSS]";
3048 break;
3049 case IEEE80211_CAP_DMG_AP:
3050 s = "[ESS]";
3051 break;
3052 case IEEE80211_CAP_DMG_PBSS:
3053 s = "[PBSS]";
3054 break;
3055 default:
3056 s = "";
3057 break;
3058 }
3059 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003060 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003061 return -1;
3062 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003063 } else {
3064 if (bss->caps & IEEE80211_CAP_IBSS) {
3065 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003066 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003067 return -1;
3068 pos += ret;
3069 }
3070 if (bss->caps & IEEE80211_CAP_ESS) {
3071 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003072 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003073 return -1;
3074 pos += ret;
3075 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003076 }
3077 if (p2p) {
3078 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003079 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003080 return -1;
3081 pos += ret;
3082 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003083#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003084 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003085 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003086 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003087 return -1;
3088 pos += ret;
3089 }
3090#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003091#ifdef CONFIG_FILS
3092 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
3093 ret = os_snprintf(pos, end - pos, "[FILS]");
3094 if (os_snprintf_error(end - pos, ret))
3095 return -1;
3096 pos += ret;
3097 }
3098#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003099#ifdef CONFIG_FST
3100 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
3101 ret = os_snprintf(pos, end - pos, "[FST]");
3102 if (os_snprintf_error(end - pos, ret))
3103 return -1;
3104 pos += ret;
3105 }
3106#endif /* CONFIG_FST */
Hai Shalom74f70d42019-02-11 14:42:39 -08003107 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
3108 ret = os_snprintf(pos, end - pos, "[UTF-8]");
3109 if (os_snprintf_error(end - pos, ret))
3110 return -1;
3111 pos += ret;
3112 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003113
3114 ret = os_snprintf(pos, end - pos, "\t%s",
3115 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003116 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003117 return -1;
3118 pos += ret;
3119
3120 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003121 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003122 return -1;
3123 pos += ret;
3124
3125 return pos - buf;
3126}
3127
3128
3129static int wpa_supplicant_ctrl_iface_scan_results(
3130 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3131{
3132 char *pos, *end;
3133 struct wpa_bss *bss;
3134 int ret;
3135
3136 pos = buf;
3137 end = buf + buflen;
3138 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
3139 "flags / ssid\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003140 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003141 return pos - buf;
3142 pos += ret;
3143
3144 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3145 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
3146 end - pos);
3147 if (ret < 0 || ret >= end - pos)
3148 return pos - buf;
3149 pos += ret;
3150 }
3151
3152 return pos - buf;
3153}
3154
3155
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003156#ifdef CONFIG_MESH
3157
3158static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3159 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
3160{
3161 char *pos, ifname[IFNAMSIZ + 1];
3162
3163 ifname[0] = '\0';
3164
3165 pos = os_strstr(cmd, "ifname=");
3166 if (pos) {
3167 pos += 7;
3168 os_strlcpy(ifname, pos, sizeof(ifname));
3169 }
3170
3171 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
3172 return -1;
3173
3174 os_strlcpy(reply, ifname, max_len);
3175 return os_strlen(ifname);
3176}
3177
3178
3179static int wpa_supplicant_ctrl_iface_mesh_group_add(
3180 struct wpa_supplicant *wpa_s, char *cmd)
3181{
3182 int id;
3183 struct wpa_ssid *ssid;
3184
3185 id = atoi(cmd);
3186 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
3187
3188 ssid = wpa_config_get_network(wpa_s->conf, id);
3189 if (ssid == NULL) {
3190 wpa_printf(MSG_DEBUG,
3191 "CTRL_IFACE: Could not find network id=%d", id);
3192 return -1;
3193 }
3194 if (ssid->mode != WPAS_MODE_MESH) {
3195 wpa_printf(MSG_DEBUG,
3196 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3197 return -1;
3198 }
3199 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
3200 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
3201 wpa_printf(MSG_ERROR,
3202 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3203 return -1;
3204 }
3205
3206 /*
3207 * TODO: If necessary write our own group_add function,
3208 * for now we can reuse select_network
3209 */
3210 wpa_supplicant_select_network(wpa_s, ssid);
3211
3212 return 0;
3213}
3214
3215
3216static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3217 struct wpa_supplicant *wpa_s, char *cmd)
3218{
3219 struct wpa_supplicant *orig;
3220 struct wpa_global *global;
3221 int found = 0;
3222
3223 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3224
3225 global = wpa_s->global;
3226 orig = wpa_s;
3227
3228 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3229 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3230 found = 1;
3231 break;
3232 }
3233 }
3234 if (!found) {
3235 wpa_printf(MSG_ERROR,
3236 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3237 cmd);
3238 return -1;
3239 }
3240 if (wpa_s->mesh_if_created && wpa_s == orig) {
3241 wpa_printf(MSG_ERROR,
3242 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3243 return -1;
3244 }
3245
3246 wpa_s->reassociate = 0;
3247 wpa_s->disconnected = 1;
3248 wpa_supplicant_cancel_sched_scan(wpa_s);
3249 wpa_supplicant_cancel_scan(wpa_s);
3250
3251 /*
3252 * TODO: If necessary write our own group_remove function,
3253 * for now we can reuse deauthenticate
3254 */
3255 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3256
3257 if (wpa_s->mesh_if_created)
3258 wpa_supplicant_remove_iface(global, wpa_s, 0);
3259
3260 return 0;
3261}
3262
Dmitry Shmidte4663042016-04-04 10:07:49 -07003263
3264static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3265 struct wpa_supplicant *wpa_s, char *cmd)
3266{
3267 u8 addr[ETH_ALEN];
3268
3269 if (hwaddr_aton(cmd, addr) < 0)
3270 return -1;
3271
3272 return wpas_mesh_peer_remove(wpa_s, addr);
3273}
3274
3275
3276static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3277 struct wpa_supplicant *wpa_s, char *cmd)
3278{
3279 u8 addr[ETH_ALEN];
3280 int duration;
3281 char *pos;
3282
3283 pos = os_strstr(cmd, " duration=");
3284 if (pos) {
3285 *pos = '\0';
3286 duration = atoi(pos + 10);
3287 } else {
3288 duration = -1;
3289 }
3290
3291 if (hwaddr_aton(cmd, addr))
3292 return -1;
3293
3294 return wpas_mesh_peer_add(wpa_s, addr, duration);
3295}
3296
Hai Shalom81f62d82019-07-22 12:10:00 -07003297
3298static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3299 struct wpa_supplicant *wpa_s, char *cmd)
3300{
3301 struct ether_header *eth;
3302 u8 addr[ETH_ALEN];
3303 u8 *buf;
3304 char *pos;
3305 size_t payload_len = 0, len;
3306 int ret = -1;
3307
3308 if (hwaddr_aton(cmd, addr))
3309 return -1;
3310
3311 pos = os_strstr(cmd, " payload=");
3312 if (pos) {
3313 pos = pos + 9;
3314 payload_len = os_strlen(pos);
3315 if (payload_len & 1)
3316 return -1;
3317
3318 payload_len /= 2;
3319 }
3320
3321 len = ETH_HLEN + payload_len;
3322 buf = os_malloc(len);
3323 if (!buf)
3324 return -1;
3325
3326 eth = (struct ether_header *) buf;
3327 os_memcpy(eth->ether_dhost, addr, ETH_ALEN);
3328 os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN);
3329 eth->ether_type = htons(ETH_P_802_3);
3330
3331 if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0)
3332 goto fail;
3333
3334 ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len);
3335fail:
3336 os_free(buf);
3337 return -ret;
3338}
3339
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003340#endif /* CONFIG_MESH */
3341
3342
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003343static int wpa_supplicant_ctrl_iface_select_network(
3344 struct wpa_supplicant *wpa_s, char *cmd)
3345{
3346 int id;
3347 struct wpa_ssid *ssid;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003348 char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003349
3350 /* cmd: "<network id>" or "any" */
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003351 if (os_strncmp(cmd, "any", 3) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003352 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3353 ssid = NULL;
3354 } else {
3355 id = atoi(cmd);
3356 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3357
3358 ssid = wpa_config_get_network(wpa_s->conf, id);
3359 if (ssid == NULL) {
3360 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3361 "network id=%d", id);
3362 return -1;
3363 }
3364 if (ssid->disabled == 2) {
3365 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3366 "SELECT_NETWORK with persistent P2P group");
3367 return -1;
3368 }
3369 }
3370
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003371 pos = os_strstr(cmd, " freq=");
3372 if (pos) {
3373 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3374 if (freqs) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003375 os_free(wpa_s->select_network_scan_freqs);
3376 wpa_s->select_network_scan_freqs = freqs;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003377 }
3378 }
3379
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003380 wpa_s->scan_min_time.sec = 0;
3381 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003382 wpa_supplicant_select_network(wpa_s, ssid);
3383
3384 return 0;
3385}
3386
3387
3388static int wpa_supplicant_ctrl_iface_enable_network(
3389 struct wpa_supplicant *wpa_s, char *cmd)
3390{
3391 int id;
3392 struct wpa_ssid *ssid;
3393
3394 /* cmd: "<network id>" or "all" */
3395 if (os_strcmp(cmd, "all") == 0) {
3396 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3397 ssid = NULL;
3398 } else {
3399 id = atoi(cmd);
3400 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3401
3402 ssid = wpa_config_get_network(wpa_s->conf, id);
3403 if (ssid == NULL) {
3404 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3405 "network id=%d", id);
3406 return -1;
3407 }
3408 if (ssid->disabled == 2) {
3409 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3410 "ENABLE_NETWORK with persistent P2P group");
3411 return -1;
3412 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003413
3414 if (os_strstr(cmd, " no-connect")) {
3415 ssid->disabled = 0;
3416 return 0;
3417 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003418 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003419 wpa_s->scan_min_time.sec = 0;
3420 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003421 wpa_supplicant_enable_network(wpa_s, ssid);
3422
3423 return 0;
3424}
3425
3426
3427static int wpa_supplicant_ctrl_iface_disable_network(
3428 struct wpa_supplicant *wpa_s, char *cmd)
3429{
3430 int id;
3431 struct wpa_ssid *ssid;
3432
3433 /* cmd: "<network id>" or "all" */
3434 if (os_strcmp(cmd, "all") == 0) {
3435 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3436 ssid = NULL;
3437 } else {
3438 id = atoi(cmd);
3439 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3440
3441 ssid = wpa_config_get_network(wpa_s->conf, id);
3442 if (ssid == NULL) {
3443 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3444 "network id=%d", id);
3445 return -1;
3446 }
3447 if (ssid->disabled == 2) {
3448 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3449 "DISABLE_NETWORK with persistent P2P "
3450 "group");
3451 return -1;
3452 }
3453 }
3454 wpa_supplicant_disable_network(wpa_s, ssid);
3455
3456 return 0;
3457}
3458
3459
3460static int wpa_supplicant_ctrl_iface_add_network(
3461 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3462{
3463 struct wpa_ssid *ssid;
3464 int ret;
3465
3466 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3467
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003468 ssid = wpa_supplicant_add_network(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003469 if (ssid == NULL)
3470 return -1;
3471
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003472 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003473 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003474 return -1;
3475 return ret;
3476}
3477
3478
3479static int wpa_supplicant_ctrl_iface_remove_network(
3480 struct wpa_supplicant *wpa_s, char *cmd)
3481{
3482 int id;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003483 int result;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003484
3485 /* cmd: "<network id>" or "all" */
3486 if (os_strcmp(cmd, "all") == 0) {
3487 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Hai Shalom899fcc72020-10-19 14:38:18 -07003488 return wpa_supplicant_remove_all_networks(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003489 }
3490
3491 id = atoi(cmd);
3492 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3493
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003494 result = wpa_supplicant_remove_network(wpa_s, id);
3495 if (result == -1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003496 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3497 "id=%d", id);
3498 return -1;
3499 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003500 if (result == -2) {
Deepthi Gowria831d782012-09-03 11:55:38 +03003501 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3502 "network id=%d", id);
3503 return -1;
3504 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003505 return 0;
3506}
3507
3508
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003509static int wpa_supplicant_ctrl_iface_update_network(
3510 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3511 char *name, char *value)
3512{
Dmitry Shmidte4663042016-04-04 10:07:49 -07003513 int ret;
3514
3515 ret = wpa_config_set(ssid, name, value, 0);
3516 if (ret < 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003517 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3518 "variable '%s'", name);
3519 return -1;
3520 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07003521 if (ret == 1)
3522 return 0; /* No change to the previously configured value */
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003523
Hai Shalom899fcc72020-10-19 14:38:18 -07003524#ifdef CONFIG_BGSCAN
3525 if (os_strcmp(name, "bgscan") == 0) {
3526 /*
3527 * Reset the bgscan parameters for the current network and
3528 * return. There's no need to flush caches for bgscan parameter
3529 * changes.
3530 */
3531 if (wpa_s->current_ssid == ssid &&
3532 wpa_s->wpa_state == WPA_COMPLETED)
3533 wpa_supplicant_reset_bgscan(wpa_s);
3534 return 0;
3535 }
3536#endif /* CONFIG_BGSCAN */
3537
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003538 if (os_strcmp(name, "bssid") != 0 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003539 os_strcmp(name, "bssid_hint") != 0 &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003540 os_strcmp(name, "priority") != 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003541 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3542
Dmitry Shmidte4663042016-04-04 10:07:49 -07003543 if (wpa_s->current_ssid == ssid ||
3544 wpa_s->current_ssid == NULL) {
3545 /*
3546 * Invalidate the EAP session cache if anything in the
3547 * current or previously used configuration changes.
3548 */
3549 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3550 }
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003551 }
3552
3553 if ((os_strcmp(name, "psk") == 0 &&
3554 value[0] == '"' && ssid->ssid_len) ||
3555 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3556 wpa_config_update_psk(ssid);
3557 else if (os_strcmp(name, "priority") == 0)
3558 wpa_config_update_prio_list(wpa_s->conf);
3559
3560 return 0;
3561}
3562
3563
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003564static int wpa_supplicant_ctrl_iface_set_network(
3565 struct wpa_supplicant *wpa_s, char *cmd)
3566{
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003567 int id, ret, prev_bssid_set, prev_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003568 struct wpa_ssid *ssid;
3569 char *name, *value;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003570 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003571
3572 /* cmd: "<network id> <variable name> <value>" */
3573 name = os_strchr(cmd, ' ');
3574 if (name == NULL)
3575 return -1;
3576 *name++ = '\0';
3577
3578 value = os_strchr(name, ' ');
3579 if (value == NULL)
3580 return -1;
3581 *value++ = '\0';
3582
3583 id = atoi(cmd);
3584 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3585 id, name);
3586 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3587 (u8 *) value, os_strlen(value));
3588
3589 ssid = wpa_config_get_network(wpa_s->conf, id);
3590 if (ssid == NULL) {
3591 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3592 "id=%d", id);
3593 return -1;
3594 }
3595
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003596 prev_bssid_set = ssid->bssid_set;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003597 prev_disabled = ssid->disabled;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003598 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3599 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3600 value);
3601 if (ret == 0 &&
3602 (ssid->bssid_set != prev_bssid_set ||
3603 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3604 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003605
3606 if (prev_disabled != ssid->disabled &&
3607 (prev_disabled == 2 || ssid->disabled == 2))
3608 wpas_notify_network_type_changed(wpa_s, ssid);
3609
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003610 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003611}
3612
3613
3614static int wpa_supplicant_ctrl_iface_get_network(
3615 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3616{
3617 int id;
3618 size_t res;
3619 struct wpa_ssid *ssid;
3620 char *name, *value;
3621
3622 /* cmd: "<network id> <variable name>" */
3623 name = os_strchr(cmd, ' ');
3624 if (name == NULL || buflen == 0)
3625 return -1;
3626 *name++ = '\0';
3627
3628 id = atoi(cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003629 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003630 id, name);
3631
3632 ssid = wpa_config_get_network(wpa_s->conf, id);
3633 if (ssid == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003634 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003635 "id=%d", id);
3636 return -1;
3637 }
3638
3639 value = wpa_config_get_no_key(ssid, name);
3640 if (value == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003641 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003642 "variable '%s'", name);
3643 return -1;
3644 }
3645
3646 res = os_strlcpy(buf, value, buflen);
3647 if (res >= buflen) {
3648 os_free(value);
3649 return -1;
3650 }
3651
3652 os_free(value);
3653
3654 return res;
3655}
3656
3657
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003658static int wpa_supplicant_ctrl_iface_dup_network(
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003659 struct wpa_supplicant *wpa_s, char *cmd,
3660 struct wpa_supplicant *dst_wpa_s)
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003661{
3662 struct wpa_ssid *ssid_s, *ssid_d;
3663 char *name, *id, *value;
3664 int id_s, id_d, ret;
3665
3666 /* cmd: "<src network id> <dst network id> <variable name>" */
3667 id = os_strchr(cmd, ' ');
3668 if (id == NULL)
3669 return -1;
3670 *id++ = '\0';
3671
3672 name = os_strchr(id, ' ');
3673 if (name == NULL)
3674 return -1;
3675 *name++ = '\0';
3676
3677 id_s = atoi(cmd);
3678 id_d = atoi(id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003679
3680 wpa_printf(MSG_DEBUG,
3681 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3682 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003683
3684 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3685 if (ssid_s == NULL) {
3686 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3687 "network id=%d", id_s);
3688 return -1;
3689 }
3690
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003691 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003692 if (ssid_d == NULL) {
3693 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003694 "network id=%d", id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003695 return -1;
3696 }
3697
3698 value = wpa_config_get(ssid_s, name);
3699 if (value == NULL) {
3700 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3701 "variable '%s'", name);
3702 return -1;
3703 }
3704
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003705 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003706 value);
3707
3708 os_free(value);
3709
3710 return ret;
3711}
3712
3713
Dmitry Shmidt04949592012-07-19 12:16:46 -07003714static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3715 char *buf, size_t buflen)
3716{
3717 char *pos, *end;
3718 struct wpa_cred *cred;
3719 int ret;
3720
3721 pos = buf;
3722 end = buf + buflen;
3723 ret = os_snprintf(pos, end - pos,
3724 "cred id / realm / username / domain / imsi\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003725 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003726 return pos - buf;
3727 pos += ret;
3728
3729 cred = wpa_s->conf->cred;
3730 while (cred) {
3731 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3732 cred->id, cred->realm ? cred->realm : "",
3733 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07003734 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003735 cred->imsi ? cred->imsi : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003736 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003737 return pos - buf;
3738 pos += ret;
3739
3740 cred = cred->next;
3741 }
3742
3743 return pos - buf;
3744}
3745
3746
3747static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3748 char *buf, size_t buflen)
3749{
3750 struct wpa_cred *cred;
3751 int ret;
3752
3753 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3754
3755 cred = wpa_config_add_cred(wpa_s->conf);
3756 if (cred == NULL)
3757 return -1;
3758
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003759 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3760
Dmitry Shmidt04949592012-07-19 12:16:46 -07003761 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003762 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003763 return -1;
3764 return ret;
3765}
3766
3767
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003768static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
3769 struct wpa_cred *cred)
3770{
3771 struct wpa_ssid *ssid;
3772 char str[20];
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003773 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003774
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003775 if (cred == NULL) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003776 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3777 return -1;
3778 }
3779
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003780 id = cred->id;
3781 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
3782 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3783 return -1;
3784 }
3785
3786 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
3787
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003788 /* Remove any network entry created based on the removed credential */
3789 ssid = wpa_s->conf->ssid;
3790 while (ssid) {
3791 if (ssid->parent_cred == cred) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003792 int res;
3793
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003794 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
3795 "used the removed credential", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003796 res = os_snprintf(str, sizeof(str), "%d", ssid->id);
3797 if (os_snprintf_error(sizeof(str), res))
3798 str[sizeof(str) - 1] = '\0';
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003799 ssid = ssid->next;
3800 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
3801 } else
3802 ssid = ssid->next;
3803 }
3804
3805 return 0;
3806}
3807
3808
Dmitry Shmidt04949592012-07-19 12:16:46 -07003809static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3810 char *cmd)
3811{
3812 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003813 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003814
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003815 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3816 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003817 if (os_strcmp(cmd, "all") == 0) {
3818 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3819 cred = wpa_s->conf->cred;
3820 while (cred) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003821 prev = cred;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003822 cred = cred->next;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003823 wpas_ctrl_remove_cred(wpa_s, prev);
3824 }
3825 return 0;
3826 }
3827
3828 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3829 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3830 cmd + 8);
3831 cred = wpa_s->conf->cred;
3832 while (cred) {
3833 prev = cred;
3834 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003835 if (prev->domain) {
3836 size_t i;
3837 for (i = 0; i < prev->num_domain; i++) {
3838 if (os_strcmp(prev->domain[i], cmd + 8)
3839 != 0)
3840 continue;
3841 wpas_ctrl_remove_cred(wpa_s, prev);
3842 break;
3843 }
3844 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003845 }
3846 return 0;
3847 }
3848
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003849 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3850 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3851 cmd + 16);
3852 cred = wpa_s->conf->cred;
3853 while (cred) {
3854 prev = cred;
3855 cred = cred->next;
3856 if (prev->provisioning_sp &&
3857 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3858 wpas_ctrl_remove_cred(wpa_s, prev);
3859 }
3860 return 0;
3861 }
3862
Dmitry Shmidt04949592012-07-19 12:16:46 -07003863 id = atoi(cmd);
3864 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3865
3866 cred = wpa_config_get_cred(wpa_s->conf, id);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003867 return wpas_ctrl_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003868}
3869
3870
3871static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3872 char *cmd)
3873{
3874 int id;
3875 struct wpa_cred *cred;
3876 char *name, *value;
3877
3878 /* cmd: "<cred id> <variable name> <value>" */
3879 name = os_strchr(cmd, ' ');
3880 if (name == NULL)
3881 return -1;
3882 *name++ = '\0';
3883
3884 value = os_strchr(name, ' ');
3885 if (value == NULL)
3886 return -1;
3887 *value++ = '\0';
3888
3889 id = atoi(cmd);
3890 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3891 id, name);
3892 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3893 (u8 *) value, os_strlen(value));
3894
3895 cred = wpa_config_get_cred(wpa_s->conf, id);
3896 if (cred == NULL) {
3897 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3898 id);
3899 return -1;
3900 }
3901
3902 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3903 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3904 "variable '%s'", name);
3905 return -1;
3906 }
3907
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003908 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3909
Dmitry Shmidt04949592012-07-19 12:16:46 -07003910 return 0;
3911}
3912
3913
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003914static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3915 char *cmd, char *buf,
3916 size_t buflen)
3917{
3918 int id;
3919 size_t res;
3920 struct wpa_cred *cred;
3921 char *name, *value;
3922
3923 /* cmd: "<cred id> <variable name>" */
3924 name = os_strchr(cmd, ' ');
3925 if (name == NULL)
3926 return -1;
3927 *name++ = '\0';
3928
3929 id = atoi(cmd);
3930 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3931 id, name);
3932
3933 cred = wpa_config_get_cred(wpa_s->conf, id);
3934 if (cred == NULL) {
3935 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3936 id);
3937 return -1;
3938 }
3939
3940 value = wpa_config_get_cred_no_key(cred, name);
3941 if (value == NULL) {
3942 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3943 name);
3944 return -1;
3945 }
3946
3947 res = os_strlcpy(buf, value, buflen);
3948 if (res >= buflen) {
3949 os_free(value);
3950 return -1;
3951 }
3952
3953 os_free(value);
3954
3955 return res;
3956}
3957
3958
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003959#ifndef CONFIG_NO_CONFIG_WRITE
3960static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3961{
3962 int ret;
3963
3964 if (!wpa_s->conf->update_config) {
3965 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3966 "to update configuration (update_config=0)");
3967 return -1;
3968 }
3969
3970 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3971 if (ret) {
3972 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3973 "update configuration");
3974 } else {
3975 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3976 " updated");
3977 }
3978
3979 return ret;
3980}
3981#endif /* CONFIG_NO_CONFIG_WRITE */
3982
3983
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003984struct cipher_info {
3985 unsigned int capa;
3986 const char *name;
3987 int group_only;
3988};
3989
3990static const struct cipher_info ciphers[] = {
3991 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3992 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3993 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3994 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07003995#ifndef CONFIG_NO_TKIP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003996 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07003997#endif /* CONFIG_NO_TKIP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003998 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
Hai Shalomfdcde762020-04-02 11:19:20 -07003999#ifdef CONFIG_WEP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004000 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
4001 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
Hai Shalomfdcde762020-04-02 11:19:20 -07004002#endif /* CONFIG_WEP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004003};
4004
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004005static const struct cipher_info ciphers_group_mgmt[] = {
4006 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
4007 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
4008 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
4009 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
4010};
4011
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004012
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004013static int ctrl_iface_get_capability_pairwise(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004014 struct wpa_driver_capa *capa,
4015 char *buf, size_t buflen)
4016{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004017 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004018 char *pos, *end;
4019 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004020 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004021
4022 pos = buf;
4023 end = pos + buflen;
4024
4025 if (res < 0) {
4026 if (strict)
4027 return 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07004028#ifdef CONFIG_NO_TKIP
4029 len = os_strlcpy(buf, "CCMP NONE", buflen);
4030#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004031 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004032#endif /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004033 if (len >= buflen)
4034 return -1;
4035 return len;
4036 }
4037
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004038 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4039 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
4040 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004041 pos == buf ? "" : " ",
4042 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004043 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004044 return pos - buf;
4045 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004046 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004047 }
4048
4049 return pos - buf;
4050}
4051
4052
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004053static int ctrl_iface_get_capability_group(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004054 struct wpa_driver_capa *capa,
4055 char *buf, size_t buflen)
4056{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004057 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004058 char *pos, *end;
4059 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004060 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004061
4062 pos = buf;
4063 end = pos + buflen;
4064
4065 if (res < 0) {
4066 if (strict)
4067 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07004068#ifdef CONFIG_WEP
Hai Shalomb755a2a2020-04-23 21:49:02 -07004069#ifdef CONFIG_NO_TKIP
4070 len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen);
4071#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004072 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004073#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004074#else /* CONFIG_WEP */
Hai Shalomb755a2a2020-04-23 21:49:02 -07004075#ifdef CONFIG_NO_TKIP
4076 len = os_strlcpy(buf, "CCMP", buflen);
4077#else /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004078 len = os_strlcpy(buf, "CCMP TKIP", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004079#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004080#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004081 if (len >= buflen)
4082 return -1;
4083 return len;
4084 }
4085
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004086 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4087 if (capa->enc & ciphers[i].capa) {
4088 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004089 pos == buf ? "" : " ",
4090 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004091 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004092 return pos - buf;
4093 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004094 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004095 }
4096
4097 return pos - buf;
4098}
4099
4100
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004101static int ctrl_iface_get_capability_group_mgmt(int res, bool strict,
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004102 struct wpa_driver_capa *capa,
4103 char *buf, size_t buflen)
4104{
4105 int ret;
4106 char *pos, *end;
4107 unsigned int i;
4108
4109 pos = buf;
4110 end = pos + buflen;
4111
4112 if (res < 0)
4113 return 0;
4114
4115 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
4116 if (capa->enc & ciphers_group_mgmt[i].capa) {
4117 ret = os_snprintf(pos, end - pos, "%s%s",
4118 pos == buf ? "" : " ",
4119 ciphers_group_mgmt[i].name);
4120 if (os_snprintf_error(end - pos, ret))
4121 return pos - buf;
4122 pos += ret;
4123 }
4124 }
4125
4126 return pos - buf;
4127}
4128
4129
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004130static int iftype_str_to_index(const char *iftype_str)
4131{
4132 if (!iftype_str)
4133 return WPA_IF_MAX;
4134
4135 if (os_strcmp(iftype_str, "STATION") == 0)
4136 return WPA_IF_STATION;
4137
4138 if (os_strcmp(iftype_str, "AP_VLAN") == 0)
4139 return WPA_IF_AP_VLAN;
4140
4141 if (os_strcmp(iftype_str, "AP") == 0)
4142 return WPA_IF_AP_BSS;
4143
4144 if (os_strcmp(iftype_str, "P2P_GO") == 0)
4145 return WPA_IF_P2P_GO;
4146
4147 if (os_strcmp(iftype_str, "P2P_CLIENT") == 0)
4148 return WPA_IF_P2P_CLIENT;
4149
4150 if (os_strcmp(iftype_str, "P2P_DEVICE") == 0)
4151 return WPA_IF_P2P_DEVICE;
4152
4153 if (os_strcmp(iftype_str, "MESH") == 0)
4154 return WPA_IF_MESH;
4155
4156 if (os_strcmp(iftype_str, "IBSS") == 0)
4157 return WPA_IF_IBSS;
4158
4159 if (os_strcmp(iftype_str, "NAN") == 0)
4160 return WPA_IF_NAN;
4161
4162 return WPA_IF_MAX;
4163}
4164
4165
4166static int ctrl_iface_get_capability_key_mgmt(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004167 struct wpa_driver_capa *capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004168 const char *iftype_str,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004169 char *buf, size_t buflen)
4170{
4171 int ret;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004172 unsigned int key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004173 char *pos, *end;
4174 size_t len;
4175
4176 pos = buf;
4177 end = pos + buflen;
4178
4179 if (res < 0) {
4180 if (strict)
4181 return 0;
4182 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4183 "NONE", buflen);
4184 if (len >= buflen)
4185 return -1;
4186 return len;
4187 }
4188
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004189 if (iftype_str) {
4190 enum wpa_driver_if_type iftype;
4191
4192 iftype = iftype_str_to_index(iftype_str);
4193 if (iftype == WPA_IF_MAX)
4194 return -1;
4195 key_mgmt = capa->key_mgmt_iftype[iftype];
4196 } else {
4197 key_mgmt = capa->key_mgmt;
4198 }
4199
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004200 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004201 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004202 return pos - buf;
4203 pos += ret;
4204
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004205 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4206 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004207 ret = os_snprintf(pos, end - pos, " WPA-EAP");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004208 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004209 return pos - buf;
4210 pos += ret;
4211 }
4212
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004213 if (key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
4214 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004215 ret = os_snprintf(pos, end - pos, " WPA-PSK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004216 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004217 return pos - buf;
4218 pos += ret;
4219 }
4220
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004221 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004222 ret = os_snprintf(pos, end - pos, " WPA-NONE");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004223 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004224 return pos - buf;
4225 pos += ret;
4226 }
4227
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304228 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WAPI_PSK) {
4229 ret = os_snprintf(pos, end - pos, " WAPI-PSK");
4230 if (os_snprintf_error(end - pos, ret))
4231 return pos - buf;
4232 pos += ret;
4233 }
4234
4235 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_TPK_HANDSHAKE) {
4236 ret = os_snprintf(pos, end - pos, " TPK-HANDSHAKE");
4237 if (os_snprintf_error(end - pos, ret))
4238 return pos - buf;
4239 pos += ret;
4240 }
4241
4242 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_CCKM) {
4243 ret = os_snprintf(pos, end - pos, " CCKM");
4244 if (os_snprintf_error(end - pos, ret))
4245 return pos - buf;
4246 pos += ret;
4247 }
4248
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004249#ifdef CONFIG_SUITEB
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004250 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004251 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
4252 if (os_snprintf_error(end - pos, ret))
4253 return pos - buf;
4254 pos += ret;
4255 }
4256#endif /* CONFIG_SUITEB */
4257#ifdef CONFIG_SUITEB192
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004258 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004259 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
4260 if (os_snprintf_error(end - pos, ret))
4261 return pos - buf;
4262 pos += ret;
4263 }
4264#endif /* CONFIG_SUITEB192 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004265#ifdef CONFIG_OWE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004266 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004267 ret = os_snprintf(pos, end - pos, " OWE");
4268 if (os_snprintf_error(end - pos, ret))
4269 return pos - buf;
4270 pos += ret;
4271 }
4272#endif /* CONFIG_OWE */
4273#ifdef CONFIG_DPP
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004274 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004275 ret = os_snprintf(pos, end - pos, " DPP");
4276 if (os_snprintf_error(end - pos, ret))
4277 return pos - buf;
4278 pos += ret;
4279 }
4280#endif /* CONFIG_DPP */
4281#ifdef CONFIG_FILS
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004282 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004283 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
4284 if (os_snprintf_error(end - pos, ret))
4285 return pos - buf;
4286 pos += ret;
4287 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004288 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004289 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
4290 if (os_snprintf_error(end - pos, ret))
4291 return pos - buf;
4292 pos += ret;
4293 }
4294#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004295 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004296 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
4297 if (os_snprintf_error(end - pos, ret))
4298 return pos - buf;
4299 pos += ret;
4300 }
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004301 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004302 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
4303 if (os_snprintf_error(end - pos, ret))
4304 return pos - buf;
4305 pos += ret;
4306 }
4307#endif /* CONFIG_IEEE80211R */
4308#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08004309#ifdef CONFIG_IEEE80211R
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004310 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004311 ret = os_snprintf(pos, end - pos, " FT-PSK");
4312 if (os_snprintf_error(end - pos, ret))
4313 return pos - buf;
4314 pos += ret;
4315 }
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304316 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT) {
4317 ret = os_snprintf(pos, end - pos, " FT-EAP");
4318 if (os_snprintf_error(end - pos, ret))
4319 return pos - buf;
4320 pos += ret;
4321 }
4322#ifdef CONFIG_SAE
4323 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_SAE) {
4324 ret = os_snprintf(pos, end - pos, " FT-SAE");
4325 if (os_snprintf_error(end - pos, ret))
4326 return pos - buf;
4327 pos += ret;
4328 }
4329#endif /* CONFIG_SAE */
4330#ifdef CONFIG_SHA384
4331 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_802_1X_SHA384) {
4332 ret = os_snprintf(pos, end - pos, " FT-EAP-SHA384");
4333 if (os_snprintf_error(end - pos, ret))
4334 return pos - buf;
4335 pos += ret;
4336 }
4337#endif /* CONFIG_SHA384 */
Hai Shalom74f70d42019-02-11 14:42:39 -08004338#endif /* CONFIG_IEEE80211R */
4339#ifdef CONFIG_SAE
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004340 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
Hai Shalom74f70d42019-02-11 14:42:39 -08004341 ret = os_snprintf(pos, end - pos, " SAE");
4342 if (os_snprintf_error(end - pos, ret))
4343 return pos - buf;
4344 pos += ret;
4345 }
4346#endif /* CONFIG_SAE */
Tanmay Garga7fd80d2020-05-18 15:52:44 +05304347#ifdef CONFIG_SHA256
4348 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_802_1X_SHA256) {
4349 ret = os_snprintf(pos, end - pos, " WPA-EAP-SHA256");
4350 if (os_snprintf_error(end - pos, ret))
4351 return pos - buf;
4352 pos += ret;
4353 }
4354
4355 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_PSK_SHA256) {
4356 ret = os_snprintf(pos, end - pos, " WPA-PSK-SHA256");
4357 if (os_snprintf_error(end - pos, ret))
4358 return pos - buf;
4359 pos += ret;
4360 }
4361#endif /* CONFIG_SHA256 */
4362#ifdef CONFIG_HS20
4363 if (key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OSEN) {
4364 ret = os_snprintf(pos, end - pos, " OSEN");
4365 if (os_snprintf_error(end - pos, ret))
4366 return pos - buf;
4367 pos += ret;
4368 }
4369#endif /* CONFIG_HS20 */
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004370
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004371 return pos - buf;
4372}
4373
4374
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004375static int ctrl_iface_get_capability_proto(int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004376 struct wpa_driver_capa *capa,
4377 char *buf, size_t buflen)
4378{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004379 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004380 char *pos, *end;
4381 size_t len;
4382
4383 pos = buf;
4384 end = pos + buflen;
4385
4386 if (res < 0) {
4387 if (strict)
4388 return 0;
4389 len = os_strlcpy(buf, "RSN WPA", buflen);
4390 if (len >= buflen)
4391 return -1;
4392 return len;
4393 }
4394
4395 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4396 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004397 ret = os_snprintf(pos, end - pos, "%sRSN",
4398 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004399 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004400 return pos - buf;
4401 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004402 }
4403
4404 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4405 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004406 ret = os_snprintf(pos, end - pos, "%sWPA",
4407 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004408 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004409 return pos - buf;
4410 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004411 }
4412
4413 return pos - buf;
4414}
4415
4416
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004417static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004418 int res, bool strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004419 struct wpa_driver_capa *capa,
4420 char *buf, size_t buflen)
4421{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004422 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004423 char *pos, *end;
4424 size_t len;
4425
4426 pos = buf;
4427 end = pos + buflen;
4428
4429 if (res < 0) {
4430 if (strict)
4431 return 0;
4432 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4433 if (len >= buflen)
4434 return -1;
4435 return len;
4436 }
4437
4438 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004439 ret = os_snprintf(pos, end - pos, "%sOPEN",
4440 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004441 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004442 return pos - buf;
4443 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004444 }
4445
4446 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4447 ret = os_snprintf(pos, end - pos, "%sSHARED",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004448 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004449 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004450 return pos - buf;
4451 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004452 }
4453
4454 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004455 ret = os_snprintf(pos, end - pos, "%sLEAP",
4456 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004457 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004458 return pos - buf;
4459 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004460 }
4461
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004462#ifdef CONFIG_SAE
4463 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4464 ret = os_snprintf(pos, end - pos, "%sSAE",
4465 pos == buf ? "" : " ");
4466 if (os_snprintf_error(end - pos, ret))
4467 return pos - buf;
4468 pos += ret;
4469 }
4470#endif /* CONFIG_SAE */
4471
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004472#ifdef CONFIG_FILS
4473 if (wpa_is_fils_supported(wpa_s)) {
4474 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4475 pos == buf ? "" : " ");
4476 if (os_snprintf_error(end - pos, ret))
4477 return pos - buf;
4478 pos += ret;
4479 }
4480
4481#ifdef CONFIG_FILS_SK_PFS
4482 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4483 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4484 pos == buf ? "" : " ");
4485 if (os_snprintf_error(end - pos, ret))
4486 return pos - buf;
4487 pos += ret;
4488 }
4489#endif /* CONFIG_FILS_SK_PFS */
4490#endif /* CONFIG_FILS */
4491
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004492 return pos - buf;
4493}
4494
4495
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004496static int ctrl_iface_get_capability_modes(int res, bool strict,
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004497 struct wpa_driver_capa *capa,
4498 char *buf, size_t buflen)
4499{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004500 int ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004501 char *pos, *end;
4502 size_t len;
4503
4504 pos = buf;
4505 end = pos + buflen;
4506
4507 if (res < 0) {
4508 if (strict)
4509 return 0;
4510 len = os_strlcpy(buf, "IBSS AP", buflen);
4511 if (len >= buflen)
4512 return -1;
4513 return len;
4514 }
4515
4516 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004517 ret = os_snprintf(pos, end - pos, "%sIBSS",
4518 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004519 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004520 return pos - buf;
4521 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004522 }
4523
4524 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004525 ret = os_snprintf(pos, end - pos, "%sAP",
4526 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004527 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004528 return pos - buf;
4529 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004530 }
4531
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004532#ifdef CONFIG_MESH
4533 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4534 ret = os_snprintf(pos, end - pos, "%sMESH",
4535 pos == buf ? "" : " ");
4536 if (os_snprintf_error(end - pos, ret))
4537 return pos - buf;
4538 pos += ret;
4539 }
4540#endif /* CONFIG_MESH */
4541
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004542 return pos - buf;
4543}
4544
4545
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004546static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4547 char *buf, size_t buflen)
4548{
4549 struct hostapd_channel_data *chnl;
4550 int ret, i, j;
4551 char *pos, *end, *hmode;
4552
4553 pos = buf;
4554 end = pos + buflen;
4555
4556 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4557 switch (wpa_s->hw.modes[j].mode) {
4558 case HOSTAPD_MODE_IEEE80211B:
4559 hmode = "B";
4560 break;
4561 case HOSTAPD_MODE_IEEE80211G:
4562 hmode = "G";
4563 break;
4564 case HOSTAPD_MODE_IEEE80211A:
4565 hmode = "A";
4566 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004567 case HOSTAPD_MODE_IEEE80211AD:
4568 hmode = "AD";
4569 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004570 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004571 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004572 }
4573 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004574 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004575 return pos - buf;
4576 pos += ret;
4577 chnl = wpa_s->hw.modes[j].channels;
4578 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004579 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4580 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004581 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004582 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004583 return pos - buf;
4584 pos += ret;
4585 }
4586 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004587 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004588 return pos - buf;
4589 pos += ret;
4590 }
4591
4592 return pos - buf;
4593}
4594
4595
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004596static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4597 char *buf, size_t buflen)
4598{
4599 struct hostapd_channel_data *chnl;
4600 int ret, i, j;
4601 char *pos, *end, *hmode;
4602
4603 pos = buf;
4604 end = pos + buflen;
4605
4606 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4607 switch (wpa_s->hw.modes[j].mode) {
4608 case HOSTAPD_MODE_IEEE80211B:
4609 hmode = "B";
4610 break;
4611 case HOSTAPD_MODE_IEEE80211G:
4612 hmode = "G";
4613 break;
4614 case HOSTAPD_MODE_IEEE80211A:
4615 hmode = "A";
4616 break;
4617 case HOSTAPD_MODE_IEEE80211AD:
4618 hmode = "AD";
4619 break;
4620 default:
4621 continue;
4622 }
4623 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4624 hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004625 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004626 return pos - buf;
4627 pos += ret;
4628 chnl = wpa_s->hw.modes[j].channels;
4629 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4630 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4631 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004632 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004633 chnl[i].chan, chnl[i].freq,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004634 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4635 " (NO_IR)" : "",
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004636 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4637 " (DFS)" : "");
4638
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004639 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004640 return pos - buf;
4641 pos += ret;
4642 }
4643 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004644 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004645 return pos - buf;
4646 pos += ret;
4647 }
4648
4649 return pos - buf;
4650}
4651
4652
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004653static int wpa_supplicant_ctrl_iface_get_capability(
4654 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4655 size_t buflen)
4656{
4657 struct wpa_driver_capa capa;
4658 int res;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004659 char *next_param, *curr_param, *iftype = NULL;
4660 bool strict = false;
4661 char field[50];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004662 size_t len;
4663
4664 /* Determine whether or not strict checking was requested */
4665 len = os_strlcpy(field, _field, sizeof(field));
4666 if (len >= sizeof(field))
4667 return -1;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004668
4669 next_param = os_strchr(field, ' ');
4670 while (next_param) {
4671 *next_param++ = '\0';
4672 curr_param = next_param;
4673 next_param = os_strchr(next_param, ' ');
4674
4675 if (next_param)
4676 *next_param = '\0';
4677
4678 if (os_strcmp(curr_param, "strict") == 0)
4679 strict = true;
4680 else if (os_strncmp(curr_param, "iftype=", 7) == 0)
4681 iftype = curr_param + 7;
4682 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004683 return -1;
4684 }
4685
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004686 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'%s%s%s",
4687 field, iftype ? " iftype=" : "", iftype ? iftype : "",
4688 strict ? " strict" : "");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004689
4690 if (os_strcmp(field, "eap") == 0) {
4691 return eap_get_names(buf, buflen);
4692 }
4693
4694 res = wpa_drv_get_capa(wpa_s, &capa);
4695
4696 if (os_strcmp(field, "pairwise") == 0)
4697 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4698 buf, buflen);
4699
4700 if (os_strcmp(field, "group") == 0)
4701 return ctrl_iface_get_capability_group(res, strict, &capa,
4702 buf, buflen);
4703
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004704 if (os_strcmp(field, "group_mgmt") == 0)
4705 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4706 buf, buflen);
4707
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004708 if (os_strcmp(field, "key_mgmt") == 0)
4709 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004710 iftype, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004711
4712 if (os_strcmp(field, "proto") == 0)
4713 return ctrl_iface_get_capability_proto(res, strict, &capa,
4714 buf, buflen);
4715
4716 if (os_strcmp(field, "auth_alg") == 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004717 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4718 &capa, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004719
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004720 if (os_strcmp(field, "modes") == 0)
4721 return ctrl_iface_get_capability_modes(res, strict, &capa,
4722 buf, buflen);
4723
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004724 if (os_strcmp(field, "channels") == 0)
4725 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4726
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004727 if (os_strcmp(field, "freq") == 0)
4728 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4729
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004730#ifdef CONFIG_TDLS
4731 if (os_strcmp(field, "tdls") == 0)
4732 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4733#endif /* CONFIG_TDLS */
4734
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004735#ifdef CONFIG_ERP
4736 if (os_strcmp(field, "erp") == 0) {
4737 res = os_snprintf(buf, buflen, "ERP");
4738 if (os_snprintf_error(buflen, res))
4739 return -1;
4740 return res;
4741 }
4742#endif /* CONFIG_EPR */
4743
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004744#ifdef CONFIG_FIPS
4745 if (os_strcmp(field, "fips") == 0) {
4746 res = os_snprintf(buf, buflen, "FIPS");
4747 if (os_snprintf_error(buflen, res))
4748 return -1;
4749 return res;
4750 }
4751#endif /* CONFIG_FIPS */
4752
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004753#ifdef CONFIG_ACS
4754 if (os_strcmp(field, "acs") == 0) {
4755 res = os_snprintf(buf, buflen, "ACS");
4756 if (os_snprintf_error(buflen, res))
4757 return -1;
4758 return res;
4759 }
4760#endif /* CONFIG_ACS */
4761
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004762#ifdef CONFIG_FILS
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004763 if (os_strcmp(field, "fils") == 0) {
4764#ifdef CONFIG_FILS_SK_PFS
4765 if (wpa_is_fils_supported(wpa_s) &&
4766 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4767 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4768 if (os_snprintf_error(buflen, res))
4769 return -1;
4770 return res;
4771 }
4772#endif /* CONFIG_FILS_SK_PFS */
4773
4774 if (wpa_is_fils_supported(wpa_s)) {
4775 res = os_snprintf(buf, buflen, "FILS");
4776 if (os_snprintf_error(buflen, res))
4777 return -1;
4778 return res;
4779 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004780 }
4781#endif /* CONFIG_FILS */
4782
Hai Shalom74f70d42019-02-11 14:42:39 -08004783 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
4784 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
4785 if (os_snprintf_error(buflen, res))
4786 return -1;
4787 return res;
4788 }
4789
Hai Shalom021b0b52019-04-10 11:17:58 -07004790#ifdef CONFIG_DPP
4791 if (os_strcmp(field, "dpp") == 0) {
4792#ifdef CONFIG_DPP2
4793 res = os_snprintf(buf, buflen, "DPP=2");
4794#else /* CONFIG_DPP2 */
4795 res = os_snprintf(buf, buflen, "DPP=1");
4796#endif /* CONFIG_DPP2 */
4797 if (os_snprintf_error(buflen, res))
4798 return -1;
4799 return res;
4800 }
4801#endif /* CONFIG_DPP */
4802
Hai Shalom899fcc72020-10-19 14:38:18 -07004803#ifdef CONFIG_SAE
4804 if (os_strcmp(field, "sae") == 0 &&
4805 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) {
4806#ifdef CONFIG_SAE_PK
4807 res = os_snprintf(buf, buflen, "H2E PK");
4808#else /* CONFIG_SAE_PK */
4809 res = os_snprintf(buf, buflen, "H2E");
4810#endif /* CONFIG_SAE_PK */
4811 if (os_snprintf_error(buflen, res))
4812 return -1;
4813 return res;
4814 }
4815#endif /* CONFIG_SAE */
4816
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004817 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4818 field);
4819
4820 return -1;
4821}
4822
4823
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004824#ifdef CONFIG_INTERWORKING
4825static char * anqp_add_hex(char *pos, char *end, const char *title,
4826 struct wpabuf *data)
4827{
4828 char *start = pos;
4829 size_t i;
4830 int ret;
4831 const u8 *d;
4832
4833 if (data == NULL)
4834 return start;
4835
4836 ret = os_snprintf(pos, end - pos, "%s=", title);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004837 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004838 return start;
4839 pos += ret;
4840
4841 d = wpabuf_head_u8(data);
4842 for (i = 0; i < wpabuf_len(data); i++) {
4843 ret = os_snprintf(pos, end - pos, "%02x", *d++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004844 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004845 return start;
4846 pos += ret;
4847 }
4848
4849 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004850 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004851 return start;
4852 pos += ret;
4853
4854 return pos;
4855}
4856#endif /* CONFIG_INTERWORKING */
4857
4858
Dmitry Shmidt29333592017-01-09 12:27:11 -08004859#ifdef CONFIG_FILS
4860static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4861{
4862 char *start = pos;
4863 const u8 *ie, *ie_end;
4864 u16 info, realms;
4865 int ret;
4866
4867 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4868 if (!ie)
4869 return 0;
4870 ie_end = ie + 2 + ie[1];
4871 ie += 2;
4872 if (ie_end - ie < 2)
4873 return -1;
4874
4875 info = WPA_GET_LE16(ie);
4876 ie += 2;
4877 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4878 if (os_snprintf_error(end - pos, ret))
4879 return 0;
4880 pos += ret;
4881
4882 if (info & BIT(7)) {
4883 /* Cache Identifier Included */
4884 if (ie_end - ie < 2)
4885 return -1;
4886 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4887 ie[0], ie[1]);
4888 if (os_snprintf_error(end - pos, ret))
4889 return 0;
4890 pos += ret;
4891 ie += 2;
4892 }
4893
4894 if (info & BIT(8)) {
4895 /* HESSID Included */
4896 if (ie_end - ie < ETH_ALEN)
4897 return -1;
4898 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4899 MAC2STR(ie));
4900 if (os_snprintf_error(end - pos, ret))
4901 return 0;
4902 pos += ret;
4903 ie += ETH_ALEN;
4904 }
4905
4906 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4907 if (realms) {
4908 if (ie_end - ie < realms * 2)
4909 return -1;
4910 ret = os_snprintf(pos, end - pos, "fils_realms=");
4911 if (os_snprintf_error(end - pos, ret))
4912 return 0;
4913 pos += ret;
4914
4915 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
4916 if (ret <= 0)
4917 return 0;
4918 pos += ret;
4919 ie += realms * 2;
4920 ret = os_snprintf(pos, end - pos, "\n");
4921 if (os_snprintf_error(end - pos, ret))
4922 return 0;
4923 pos += ret;
4924 }
4925
4926 return pos - start;
4927}
4928#endif /* CONFIG_FILS */
4929
4930
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004931static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
4932 unsigned long mask, char *buf, size_t buflen)
4933{
4934 size_t i;
4935 int ret;
4936 char *pos, *end;
Hai Shalom899fcc72020-10-19 14:38:18 -07004937 const u8 *ie, *ie2, *osen_ie, *mesh, *owe, *rsnxe;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004938
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004939 pos = buf;
4940 end = buf + buflen;
4941
4942 if (mask & WPA_BSS_MASK_ID) {
4943 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004944 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004945 return 0;
4946 pos += ret;
4947 }
4948
4949 if (mask & WPA_BSS_MASK_BSSID) {
4950 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
4951 MAC2STR(bss->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004952 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004953 return 0;
4954 pos += ret;
4955 }
4956
4957 if (mask & WPA_BSS_MASK_FREQ) {
4958 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004959 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004960 return 0;
4961 pos += ret;
4962 }
4963
4964 if (mask & WPA_BSS_MASK_BEACON_INT) {
4965 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
4966 bss->beacon_int);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004967 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004968 return 0;
4969 pos += ret;
4970 }
4971
4972 if (mask & WPA_BSS_MASK_CAPABILITIES) {
4973 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
4974 bss->caps);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004975 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004976 return 0;
4977 pos += ret;
4978 }
4979
4980 if (mask & WPA_BSS_MASK_QUAL) {
4981 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004982 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004983 return 0;
4984 pos += ret;
4985 }
4986
4987 if (mask & WPA_BSS_MASK_NOISE) {
4988 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004989 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004990 return 0;
4991 pos += ret;
4992 }
4993
4994 if (mask & WPA_BSS_MASK_LEVEL) {
4995 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
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_TSF) {
5002 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
5003 (unsigned long long) bss->tsf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005004 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005005 return 0;
5006 pos += ret;
5007 }
5008
5009 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005010 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005011
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005012 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005013 ret = os_snprintf(pos, end - pos, "age=%d\n",
5014 (int) (now.sec - bss->last_update.sec));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005015 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005016 return 0;
5017 pos += ret;
5018 }
5019
5020 if (mask & WPA_BSS_MASK_IE) {
5021 ret = os_snprintf(pos, end - pos, "ie=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005022 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005023 return 0;
5024 pos += ret;
5025
5026 ie = (const u8 *) (bss + 1);
5027 for (i = 0; i < bss->ie_len; i++) {
5028 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005029 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005030 return 0;
5031 pos += ret;
5032 }
5033
5034 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005035 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005036 return 0;
5037 pos += ret;
5038 }
5039
5040 if (mask & WPA_BSS_MASK_FLAGS) {
5041 ret = os_snprintf(pos, end - pos, "flags=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005042 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005043 return 0;
5044 pos += ret;
5045
Dmitry Shmidt29333592017-01-09 12:27:11 -08005046 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
5047
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005048 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
5049 if (ie)
5050 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
5051 2 + ie[1]);
5052 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
5053 if (ie2)
Dmitry Shmidt29333592017-01-09 12:27:11 -08005054 pos = wpa_supplicant_ie_txt(pos, end,
5055 mesh ? "RSN" : "WPA2", ie2,
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005056 2 + ie2[1]);
Hai Shalom899fcc72020-10-19 14:38:18 -07005057 rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX);
5058 if (rsnxe && rsnxe[1] >= 1) {
5059 if (rsnxe[2] & BIT(WLAN_RSNX_CAPAB_SAE_H2E)) {
5060 ret = os_snprintf(pos, end - pos, "[SAE-H2E]");
5061 if (os_snprintf_error(end - pos, ret))
5062 return -1;
5063 pos += ret;
5064 }
5065 if (rsnxe[2] & BIT(WLAN_RSNX_CAPAB_SAE_PK)) {
5066 ret = os_snprintf(pos, end - pos, "[SAE-PK]");
5067 if (os_snprintf_error(end - pos, ret))
5068 return -1;
5069 pos += ret;
5070 }
5071 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005072 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
5073 if (osen_ie)
5074 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
5075 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07005076 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
5077 if (owe) {
5078 ret = os_snprintf(
5079 pos, end - pos,
5080 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
5081 if (os_snprintf_error(end - pos, ret))
5082 return 0;
5083 pos += ret;
5084 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005085 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07005086 if (!ie && !ie2 && !osen_ie &&
5087 (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005088 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005089 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005090 return 0;
5091 pos += ret;
5092 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005093
5094 if (mesh) {
5095 ret = os_snprintf(pos, end - pos, "[MESH]");
5096 if (os_snprintf_error(end - pos, ret))
5097 return 0;
5098 pos += ret;
5099 }
5100
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005101 if (bss_is_dmg(bss)) {
5102 const char *s;
5103 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005104 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005105 return 0;
5106 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005107 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
5108 case IEEE80211_CAP_DMG_IBSS:
5109 s = "[IBSS]";
5110 break;
5111 case IEEE80211_CAP_DMG_AP:
5112 s = "[ESS]";
5113 break;
5114 case IEEE80211_CAP_DMG_PBSS:
5115 s = "[PBSS]";
5116 break;
5117 default:
5118 s = "";
5119 break;
5120 }
5121 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005122 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005123 return 0;
5124 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005125 } else {
5126 if (bss->caps & IEEE80211_CAP_IBSS) {
5127 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005128 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005129 return 0;
5130 pos += ret;
5131 }
5132 if (bss->caps & IEEE80211_CAP_ESS) {
5133 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005134 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07005135 return 0;
5136 pos += ret;
5137 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005138 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07005139 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
5140 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005141 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005142 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005143 return 0;
5144 pos += ret;
5145 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005146#ifdef CONFIG_HS20
5147 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
5148 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005149 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005150 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005151 pos += ret;
5152 }
5153#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08005154#ifdef CONFIG_FILS
5155 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
5156 ret = os_snprintf(pos, end - pos, "[FILS]");
5157 if (os_snprintf_error(end - pos, ret))
5158 return 0;
5159 pos += ret;
5160 }
5161#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08005162#ifdef CONFIG_FST
5163 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
5164 ret = os_snprintf(pos, end - pos, "[FST]");
5165 if (os_snprintf_error(end - pos, ret))
5166 return 0;
5167 pos += ret;
5168 }
5169#endif /* CONFIG_FST */
5170 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
5171 ret = os_snprintf(pos, end - pos, "[UTF-8]");
5172 if (os_snprintf_error(end - pos, ret))
5173 return 0;
5174 pos += ret;
5175 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005176
5177 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005178 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005179 return 0;
5180 pos += ret;
5181 }
5182
5183 if (mask & WPA_BSS_MASK_SSID) {
5184 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
5185 wpa_ssid_txt(bss->ssid, bss->ssid_len));
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 }
5190
5191#ifdef CONFIG_WPS
5192 if (mask & WPA_BSS_MASK_WPS_SCAN) {
5193 ie = (const u8 *) (bss + 1);
5194 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005195 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005196 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005197 if (ret > 0)
5198 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005199 }
5200#endif /* CONFIG_WPS */
5201
5202#ifdef CONFIG_P2P
5203 if (mask & WPA_BSS_MASK_P2P_SCAN) {
5204 ie = (const u8 *) (bss + 1);
5205 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005206 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005207 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005208 if (ret > 0)
5209 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005210 }
5211#endif /* CONFIG_P2P */
5212
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005213#ifdef CONFIG_WIFI_DISPLAY
5214 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
5215 struct wpabuf *wfd;
5216 ie = (const u8 *) (bss + 1);
5217 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
5218 WFD_IE_VENDOR_TYPE);
5219 if (wfd) {
5220 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005221 if (os_snprintf_error(end - pos, ret)) {
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005222 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005223 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005224 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005225 pos += ret;
5226
5227 pos += wpa_snprintf_hex(pos, end - pos,
5228 wpabuf_head(wfd),
5229 wpabuf_len(wfd));
5230 wpabuf_free(wfd);
5231
5232 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005233 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005234 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005235 pos += ret;
5236 }
5237 }
5238#endif /* CONFIG_WIFI_DISPLAY */
5239
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005240#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005241 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
5242 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005243 struct wpa_bss_anqp_elem *elem;
5244
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005245 pos = anqp_add_hex(pos, end, "anqp_capability_list",
5246 anqp->capability_list);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005247 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005248 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005249 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005250 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005251 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005252 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005253 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005254 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005255 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005256 anqp->nai_realm);
5257 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005258 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005259 anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005260 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
5261 anqp->fils_realm_info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005262#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005263 pos = anqp_add_hex(pos, end, "hs20_capability_list",
5264 anqp->hs20_capability_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005265 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005266 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005267 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005268 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005269 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005270 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005271 pos = anqp_add_hex(pos, end, "hs20_operating_class",
5272 anqp->hs20_operating_class);
5273 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
5274 anqp->hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005275 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
5276 anqp->hs20_operator_icon_metadata);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005277 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
5278 anqp->hs20_osu_providers_nai_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005279#endif /* CONFIG_HS20 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005280
5281 dl_list_for_each(elem, &anqp->anqp_elems,
5282 struct wpa_bss_anqp_elem, list) {
5283 char title[20];
5284
5285 os_snprintf(title, sizeof(title), "anqp[%u]",
5286 elem->infoid);
5287 pos = anqp_add_hex(pos, end, title, elem->payload);
5288 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005289 }
5290#endif /* CONFIG_INTERWORKING */
5291
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005292#ifdef CONFIG_MESH
5293 if (mask & WPA_BSS_MASK_MESH_SCAN) {
5294 ie = (const u8 *) (bss + 1);
5295 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005296 if (ret >= end - pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005297 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005298 if (ret > 0)
5299 pos += ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005300 }
5301#endif /* CONFIG_MESH */
5302
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005303 if (mask & WPA_BSS_MASK_SNR) {
5304 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
5305 if (os_snprintf_error(end - pos, ret))
5306 return 0;
5307 pos += ret;
5308 }
5309
5310 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
5311 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
5312 bss->est_throughput);
5313 if (os_snprintf_error(end - pos, ret))
5314 return 0;
5315 pos += ret;
5316 }
5317
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005318#ifdef CONFIG_FST
5319 if (mask & WPA_BSS_MASK_FST) {
5320 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
5321 if (ret < 0 || ret >= end - pos)
5322 return 0;
5323 pos += ret;
5324 }
5325#endif /* CONFIG_FST */
5326
Dmitry Shmidt29333592017-01-09 12:27:11 -08005327 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
5328 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
5329 bss->last_update_idx);
5330 if (os_snprintf_error(end - pos, ret))
5331 return 0;
5332 pos += ret;
5333 }
5334
5335 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
5336 ret = os_snprintf(pos, end - pos, "beacon_ie=");
5337 if (os_snprintf_error(end - pos, ret))
5338 return 0;
5339 pos += ret;
5340
5341 ie = (const u8 *) (bss + 1);
5342 ie += bss->ie_len;
5343 for (i = 0; i < bss->beacon_ie_len; i++) {
5344 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
5345 if (os_snprintf_error(end - pos, ret))
5346 return 0;
5347 pos += ret;
5348 }
5349
5350 ret = os_snprintf(pos, end - pos, "\n");
5351 if (os_snprintf_error(end - pos, ret))
5352 return 0;
5353 pos += ret;
5354 }
5355
5356#ifdef CONFIG_FILS
5357 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
5358 ret = print_fils_indication(bss, pos, end);
5359 if (ret < 0)
5360 return 0;
5361 pos += ret;
5362 }
5363#endif /* CONFIG_FILS */
5364
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005365 if (mask & WPA_BSS_MASK_DELIM) {
5366 ret = os_snprintf(pos, end - pos, "====\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005367 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005368 return 0;
5369 pos += ret;
5370 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07005371
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005372 return pos - buf;
5373}
5374
Dmitry Shmidt04949592012-07-19 12:16:46 -07005375
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005376static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
5377 const char *cmd, char *buf,
5378 size_t buflen)
5379{
5380 u8 bssid[ETH_ALEN];
5381 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005382 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005383 struct wpa_bss *bsslast = NULL;
5384 struct dl_list *next;
5385 int ret = 0;
5386 int len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005387 char *ctmp, *end = buf + buflen;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005388 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005389
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005390 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
5391 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
5392 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005393 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005394 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
5395 list_id);
5396 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005397 unsigned int id1, id2;
5398
5399 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
5400 wpa_printf(MSG_INFO, "Wrong BSS range "
5401 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005402 return 0;
5403 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005404
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005405 if (*(cmd + 6) == '-')
5406 id1 = 0;
5407 else
5408 id1 = atoi(cmd + 6);
5409 ctmp++;
5410 if (*ctmp >= '0' && *ctmp <= '9')
5411 id2 = atoi(ctmp);
5412 else
5413 id2 = (unsigned int) -1;
5414 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
5415 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005416 bsslast = dl_list_last(&wpa_s->bss_id,
5417 struct wpa_bss,
5418 list_id);
5419 else {
5420 bsslast = wpa_bss_get_id(wpa_s, id2);
5421 if (bsslast == NULL && bss && id2 > id1) {
5422 struct wpa_bss *tmp = bss;
5423 for (;;) {
5424 next = tmp->list_id.next;
5425 if (next == &wpa_s->bss_id)
5426 break;
5427 tmp = dl_list_entry(
5428 next, struct wpa_bss,
5429 list_id);
5430 if (tmp->id > id2)
5431 break;
5432 bsslast = tmp;
5433 }
5434 }
5435 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005436 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005437 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005438 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005439 else if (os_strncmp(cmd, "LAST", 4) == 0)
5440 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005441 else if (os_strncmp(cmd, "ID-", 3) == 0) {
5442 i = atoi(cmd + 3);
5443 bss = wpa_bss_get_id(wpa_s, i);
5444 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5445 i = atoi(cmd + 5);
5446 bss = wpa_bss_get_id(wpa_s, i);
5447 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005448 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005449 if (next == &wpa_s->bss_id)
5450 bss = NULL;
5451 else
5452 bss = dl_list_entry(next, struct wpa_bss,
5453 list_id);
5454 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005455 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5456 bss = wpa_s->current_bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005457#ifdef CONFIG_P2P
5458 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5459 if (hwaddr_aton(cmd + 13, bssid) == 0)
5460 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5461 else
5462 bss = NULL;
5463#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005464 } else if (hwaddr_aton(cmd, bssid) == 0)
5465 bss = wpa_bss_get_bssid(wpa_s, bssid);
5466 else {
5467 struct wpa_bss *tmp;
5468 i = atoi(cmd);
5469 bss = NULL;
5470 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5471 {
Hai Shalom021b0b52019-04-10 11:17:58 -07005472 if (i == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005473 bss = tmp;
5474 break;
5475 }
Hai Shalom021b0b52019-04-10 11:17:58 -07005476 i--;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005477 }
5478 }
5479
Dmitry Shmidt04949592012-07-19 12:16:46 -07005480 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5481 mask = strtoul(ctmp + 5, NULL, 0x10);
5482 if (mask == 0)
5483 mask = WPA_BSS_MASK_ALL;
5484 }
5485
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005486 if (bss == NULL)
5487 return 0;
5488
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005489 if (bsslast == NULL)
5490 bsslast = bss;
5491 do {
5492 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5493 ret += len;
5494 buf += len;
5495 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005496 if (bss == bsslast) {
5497 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5498 (bss == dl_list_last(&wpa_s->bss_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005499 struct wpa_bss, list_id))) {
5500 int res;
5501
5502 res = os_snprintf(buf - 5, end - buf + 5,
5503 "####\n");
5504 if (os_snprintf_error(end - buf + 5, res)) {
5505 wpa_printf(MSG_DEBUG,
5506 "Could not add end delim");
5507 }
5508 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005509 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005510 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005511 next = bss->list_id.next;
5512 if (next == &wpa_s->bss_id)
5513 break;
5514 bss = dl_list_entry(next, struct wpa_bss, list_id);
5515 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005516
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005517 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005518}
5519
5520
5521static int wpa_supplicant_ctrl_iface_ap_scan(
5522 struct wpa_supplicant *wpa_s, char *cmd)
5523{
5524 int ap_scan = atoi(cmd);
5525 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5526}
5527
5528
5529static int wpa_supplicant_ctrl_iface_scan_interval(
5530 struct wpa_supplicant *wpa_s, char *cmd)
5531{
5532 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005533 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005534}
5535
5536
5537static int wpa_supplicant_ctrl_iface_bss_expire_age(
5538 struct wpa_supplicant *wpa_s, char *cmd)
5539{
5540 int expire_age = atoi(cmd);
5541 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5542}
5543
5544
5545static int wpa_supplicant_ctrl_iface_bss_expire_count(
5546 struct wpa_supplicant *wpa_s, char *cmd)
5547{
5548 int expire_count = atoi(cmd);
5549 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5550}
5551
5552
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005553static void wpa_supplicant_ctrl_iface_bss_flush(
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005554 struct wpa_supplicant *wpa_s, char *cmd)
5555{
5556 int flush_age = atoi(cmd);
5557
5558 if (flush_age == 0)
5559 wpa_bss_flush(wpa_s);
5560 else
5561 wpa_bss_flush_by_age(wpa_s, flush_age);
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005562}
5563
5564
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005565#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005566static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5567{
5568 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5569 /* MLME-DELETEKEYS.request */
Hai Shalomfdcde762020-04-02 11:19:20 -07005570 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL,
5571 0, KEY_FLAG_GROUP);
5572 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL,
5573 0, KEY_FLAG_GROUP);
5574 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL,
5575 0, KEY_FLAG_GROUP);
5576 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL,
5577 0, KEY_FLAG_GROUP);
5578 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL,
5579 0, KEY_FLAG_GROUP);
5580 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL,
5581 0, KEY_FLAG_GROUP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005582
5583 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005584 0, KEY_FLAG_PAIRWISE);
5585 if (wpa_sm_ext_key_id(wpa_s->wpa))
5586 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 1, 0,
5587 NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005588 /* MLME-SETPROTECTION.request(None) */
5589 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5590 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5591 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5592 wpa_sm_drop_sa(wpa_s->wpa);
5593}
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005594#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005595
5596
5597static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5598 char *addr)
5599{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005600#ifdef CONFIG_NO_SCAN_PROCESSING
5601 return -1;
5602#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005603 u8 bssid[ETH_ALEN];
5604 struct wpa_bss *bss;
5605 struct wpa_ssid *ssid = wpa_s->current_ssid;
5606
5607 if (hwaddr_aton(addr, bssid)) {
5608 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5609 "address '%s'", addr);
5610 return -1;
5611 }
5612
5613 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5614
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005615 if (!ssid) {
5616 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5617 "configuration known for the target AP");
5618 return -1;
5619 }
5620
5621 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005622 if (!bss) {
5623 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
5624 "from BSS table");
5625 return -1;
5626 }
5627
5628 /*
5629 * TODO: Find best network configuration block from configuration to
5630 * allow roaming to other networks
5631 */
5632
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005633 wpa_s->reassociate = 1;
5634 wpa_supplicant_connect(wpa_s, bss, ssid);
5635
5636 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005637#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005638}
5639
5640
5641#ifdef CONFIG_P2P
5642static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
5643{
5644 unsigned int timeout = atoi(cmd);
5645 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005646 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005647 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005648 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005649 unsigned int search_delay;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005650 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005651 u8 seek_count = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005652 int freq = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005653
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005654 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5655 wpa_dbg(wpa_s, MSG_INFO,
5656 "Reject P2P_FIND since interface is disabled");
5657 return -1;
5658 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005659 if (os_strstr(cmd, "type=social"))
5660 type = P2P_FIND_ONLY_SOCIAL;
5661 else if (os_strstr(cmd, "type=progressive"))
5662 type = P2P_FIND_PROGRESSIVE;
5663
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005664 pos = os_strstr(cmd, "dev_id=");
5665 if (pos) {
5666 pos += 7;
5667 if (hwaddr_aton(pos, dev_id))
5668 return -1;
5669 _dev_id = dev_id;
5670 }
5671
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005672 pos = os_strstr(cmd, "dev_type=");
5673 if (pos) {
5674 pos += 9;
5675 if (wps_dev_type_str2bin(pos, dev_type) < 0)
5676 return -1;
5677 _dev_type = dev_type;
5678 }
5679
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005680 pos = os_strstr(cmd, "delay=");
5681 if (pos) {
5682 pos += 6;
5683 search_delay = atoi(pos);
5684 } else
5685 search_delay = wpas_p2p_search_delay(wpa_s);
5686
Dmitry Shmidt41712582015-06-29 11:02:15 -07005687 pos = os_strstr(cmd, "freq=");
5688 if (pos) {
5689 pos += 5;
5690 freq = atoi(pos);
5691 if (freq <= 0)
5692 return -1;
5693 }
5694
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005695 /* Must be searched for last, because it adds nul termination */
5696 pos = os_strstr(cmd, " seek=");
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005697 if (pos)
5698 pos += 6;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005699 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
5700 char *term;
5701
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005702 _seek[seek_count++] = pos;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005703 seek = _seek;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005704 term = os_strchr(pos, ' ');
5705 if (!term)
5706 break;
5707 *term = '\0';
5708 pos = os_strstr(term + 1, "seek=");
5709 if (pos)
5710 pos += 5;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005711 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005712 if (seek_count > P2P_MAX_QUERY_HASH) {
5713 seek[0] = NULL;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005714 seek_count = 1;
5715 }
5716
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005717 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005718 _dev_id, search_delay, seek_count, seek, freq);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005719}
5720
5721
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005722static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
5723{
5724 const char *last = NULL;
5725 const char *token;
5726 long int token_len;
5727 unsigned int i;
5728
5729 /* Expected predefined CPT names delimited by ':' */
5730 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
5731 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
5732 wpa_printf(MSG_ERROR,
5733 "P2PS: CPT name list is too long, expected up to %d names",
5734 P2PS_FEATURE_CAPAB_CPT_MAX);
5735 cpt[0] = 0;
5736 return -1;
5737 }
5738
5739 token_len = last - token;
5740
5741 if (token_len == 3 &&
5742 os_memcmp(token, "UDP", token_len) == 0) {
5743 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5744 } else if (token_len == 3 &&
5745 os_memcmp(token, "MAC", token_len) == 0) {
5746 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
5747 } else {
5748 wpa_printf(MSG_ERROR,
5749 "P2PS: Unsupported CPT name '%s'", token);
5750 cpt[0] = 0;
5751 return -1;
5752 }
5753
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005754 if (isblank((unsigned char) *last)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005755 i++;
5756 break;
5757 }
5758 }
5759 cpt[i] = 0;
5760 return 0;
5761}
5762
5763
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005764static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
5765{
5766 struct p2ps_provision *p2ps_prov;
5767 char *pos;
5768 size_t info_len = 0;
5769 char *info = NULL;
5770 u8 role = P2PS_SETUP_NONE;
5771 long long unsigned val;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005772 int i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005773
5774 pos = os_strstr(cmd, "info=");
5775 if (pos) {
5776 pos += 5;
5777 info_len = os_strlen(pos);
5778
5779 if (info_len) {
5780 info = os_malloc(info_len + 1);
5781 if (info) {
5782 info_len = utf8_unescape(pos, info_len,
5783 info, info_len + 1);
5784 } else
5785 info_len = 0;
5786 }
5787 }
5788
5789 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
5790 if (p2ps_prov == NULL) {
5791 os_free(info);
5792 return NULL;
5793 }
5794
5795 if (info) {
5796 os_memcpy(p2ps_prov->info, info, info_len);
5797 p2ps_prov->info[info_len] = '\0';
5798 os_free(info);
5799 }
5800
5801 pos = os_strstr(cmd, "status=");
5802 if (pos)
5803 p2ps_prov->status = atoi(pos + 7);
5804 else
5805 p2ps_prov->status = -1;
5806
5807 pos = os_strstr(cmd, "adv_id=");
5808 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
5809 goto invalid_args;
5810 p2ps_prov->adv_id = val;
5811
5812 pos = os_strstr(cmd, "method=");
5813 if (pos)
5814 p2ps_prov->method = strtol(pos + 7, NULL, 16);
5815 else
5816 p2ps_prov->method = 0;
5817
5818 pos = os_strstr(cmd, "session=");
5819 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
5820 goto invalid_args;
5821 p2ps_prov->session_id = val;
5822
5823 pos = os_strstr(cmd, "adv_mac=");
5824 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
5825 goto invalid_args;
5826
5827 pos = os_strstr(cmd, "session_mac=");
5828 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
5829 goto invalid_args;
5830
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005831 pos = os_strstr(cmd, "cpt=");
5832 if (pos) {
5833 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
5834 p2ps_prov->cpt_priority))
5835 goto invalid_args;
5836 } else {
5837 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5838 }
5839
5840 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
5841 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
5842
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005843 /* force conncap with tstCap (no sanity checks) */
5844 pos = os_strstr(cmd, "tstCap=");
5845 if (pos) {
5846 role = strtol(pos + 7, NULL, 16);
5847 } else {
5848 pos = os_strstr(cmd, "role=");
5849 if (pos) {
5850 role = strtol(pos + 5, NULL, 16);
5851 if (role != P2PS_SETUP_CLIENT &&
5852 role != P2PS_SETUP_GROUP_OWNER)
5853 role = P2PS_SETUP_NONE;
5854 }
5855 }
5856 p2ps_prov->role = role;
5857
5858 return p2ps_prov;
5859
5860invalid_args:
5861 os_free(p2ps_prov);
5862 return NULL;
5863}
5864
5865
5866static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
5867{
5868 u8 addr[ETH_ALEN];
5869 struct p2ps_provision *p2ps_prov;
5870 char *pos;
5871
5872 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5873
5874 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5875
5876 if (hwaddr_aton(cmd, addr))
5877 return -1;
5878
5879 pos = cmd + 17;
5880 if (*pos != ' ')
5881 return -1;
5882
5883 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5884 if (!p2ps_prov)
5885 return -1;
5886
5887 if (p2ps_prov->status < 0) {
5888 os_free(p2ps_prov);
5889 return -1;
5890 }
5891
5892 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5893 p2ps_prov);
5894}
5895
5896
5897static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
5898{
5899 u8 addr[ETH_ALEN];
5900 struct p2ps_provision *p2ps_prov;
5901 char *pos;
5902
5903 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5904 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5905 */
5906
5907 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5908 if (hwaddr_aton(cmd, addr))
5909 return -1;
5910
5911 pos = cmd + 17;
5912 if (*pos != ' ')
5913 return -1;
5914
5915 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5916 if (!p2ps_prov)
5917 return -1;
5918
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005919 p2ps_prov->pd_seeker = 1;
5920
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005921 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5922 p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005923}
5924
5925
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005926static int parse_freq(int chwidth, int freq2)
5927{
5928 if (freq2 < 0)
5929 return -1;
5930 if (freq2)
Hai Shalom81f62d82019-07-22 12:10:00 -07005931 return CHANWIDTH_80P80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005932
5933 switch (chwidth) {
5934 case 0:
5935 case 20:
5936 case 40:
Hai Shalom81f62d82019-07-22 12:10:00 -07005937 return CHANWIDTH_USE_HT;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005938 case 80:
Hai Shalom81f62d82019-07-22 12:10:00 -07005939 return CHANWIDTH_80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005940 case 160:
Hai Shalom81f62d82019-07-22 12:10:00 -07005941 return CHANWIDTH_160MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005942 default:
5943 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
5944 chwidth);
5945 return -1;
5946 }
5947}
5948
5949
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005950static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
5951 char *buf, size_t buflen)
5952{
5953 u8 addr[ETH_ALEN];
5954 char *pos, *pos2;
5955 char *pin = NULL;
5956 enum p2p_wps_method wps_method;
5957 int new_pin;
5958 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005959 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005960 int join;
5961 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005962 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005963 int go_intent = -1;
5964 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005965 int pd;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005966 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005967 int edmg;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005968 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
5969 size_t group_ssid_len = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08005970 int he;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005971
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005972 if (!wpa_s->global->p2p_init_wpa_s)
5973 return -1;
5974 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
5975 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
5976 wpa_s->global->p2p_init_wpa_s->ifname);
5977 wpa_s = wpa_s->global->p2p_init_wpa_s;
5978 }
5979
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005980 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
Dmitry Shmidt04949592012-07-19 12:16:46 -07005981 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005982 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005983 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005984
5985 if (hwaddr_aton(cmd, addr))
5986 return -1;
5987
5988 pos = cmd + 17;
5989 if (*pos != ' ')
5990 return -1;
5991 pos++;
5992
5993 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005994 pos2 = os_strstr(pos, " persistent=");
5995 if (pos2) {
5996 struct wpa_ssid *ssid;
5997 persistent_id = atoi(pos2 + 12);
5998 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
5999 if (ssid == NULL || ssid->disabled != 2 ||
6000 ssid->mode != WPAS_MODE_P2P_GO) {
6001 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
6002 "SSID id=%d for persistent P2P group (GO)",
6003 persistent_id);
6004 return -1;
6005 }
6006 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006007 join = os_strstr(pos, " join") != NULL;
6008 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006009 automatic = os_strstr(pos, " auto") != NULL;
6010 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006011 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6012 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6013 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006014 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006015 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006016
6017 pos2 = os_strstr(pos, " go_intent=");
6018 if (pos2) {
6019 pos2 += 11;
6020 go_intent = atoi(pos2);
6021 if (go_intent < 0 || go_intent > 15)
6022 return -1;
6023 }
6024
6025 pos2 = os_strstr(pos, " freq=");
6026 if (pos2) {
6027 pos2 += 6;
6028 freq = atoi(pos2);
6029 if (freq <= 0)
6030 return -1;
6031 }
6032
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006033 pos2 = os_strstr(pos, " freq2=");
6034 if (pos2)
6035 freq2 = atoi(pos2 + 7);
6036
6037 pos2 = os_strstr(pos, " max_oper_chwidth=");
6038 if (pos2)
6039 chwidth = atoi(pos2 + 18);
6040
6041 max_oper_chwidth = parse_freq(chwidth, freq2);
6042 if (max_oper_chwidth < 0)
6043 return -1;
6044
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006045 pos2 = os_strstr(pos, " ssid=");
6046 if (pos2) {
6047 char *end;
6048
6049 pos2 += 6;
6050 end = os_strchr(pos2, ' ');
6051 if (!end)
6052 group_ssid_len = os_strlen(pos2) / 2;
6053 else
6054 group_ssid_len = (end - pos2) / 2;
6055 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
6056 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
6057 return -1;
6058 group_ssid = _group_ssid;
6059 }
6060
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006061 if (os_strncmp(pos, "pin", 3) == 0) {
6062 /* Request random PIN (to be displayed) and enable the PIN */
6063 wps_method = WPS_PIN_DISPLAY;
6064 } else if (os_strncmp(pos, "pbc", 3) == 0) {
6065 wps_method = WPS_PBC;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006066 } else if (os_strstr(pos, "p2ps") != NULL) {
6067 wps_method = WPS_P2PS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006068 } else {
6069 pin = pos;
6070 pos = os_strchr(pin, ' ');
6071 wps_method = WPS_PIN_KEYPAD;
6072 if (pos) {
6073 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006074 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006075 wps_method = WPS_PIN_DISPLAY;
6076 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006077 if (!wps_pin_str_valid(pin)) {
6078 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
6079 return 17;
6080 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006081 }
6082
6083 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07006084 persistent_group, automatic, join,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006085 auth, go_intent, freq, freq2, persistent_id,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006086 pd, ht40, vht, max_oper_chwidth, he, edmg,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08006087 group_ssid, group_ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006088 if (new_pin == -2) {
6089 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
6090 return 25;
6091 }
6092 if (new_pin == -3) {
6093 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
6094 return 25;
6095 }
6096 if (new_pin < 0)
6097 return -1;
6098 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
6099 ret = os_snprintf(buf, buflen, "%08d", new_pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006100 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006101 return -1;
6102 return ret;
6103 }
6104
6105 os_memcpy(buf, "OK\n", 3);
6106 return 3;
6107}
6108
6109
6110static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
6111{
6112 unsigned int timeout = atoi(cmd);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07006113 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6114 wpa_dbg(wpa_s, MSG_INFO,
6115 "Reject P2P_LISTEN since interface is disabled");
6116 return -1;
6117 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006118 return wpas_p2p_listen(wpa_s, timeout);
6119}
6120
6121
6122static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
6123{
6124 u8 addr[ETH_ALEN];
6125 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006126 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006127
Dmitry Shmidt04949592012-07-19 12:16:46 -07006128 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006129
6130 if (hwaddr_aton(cmd, addr))
6131 return -1;
6132
6133 pos = cmd + 17;
6134 if (*pos != ' ')
6135 return -1;
6136 pos++;
6137
Dmitry Shmidt04949592012-07-19 12:16:46 -07006138 if (os_strstr(pos, " join") != NULL)
6139 use = WPAS_P2P_PD_FOR_JOIN;
6140 else if (os_strstr(pos, " auto") != NULL)
6141 use = WPAS_P2P_PD_AUTO;
6142
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006143 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006144}
6145
6146
6147static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
6148 size_t buflen)
6149{
6150 struct wpa_ssid *ssid = wpa_s->current_ssid;
6151
6152 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
6153 ssid->passphrase == NULL)
6154 return -1;
6155
6156 os_strlcpy(buf, ssid->passphrase, buflen);
6157 return os_strlen(buf);
6158}
6159
6160
6161static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
6162 char *buf, size_t buflen)
6163{
6164 u64 ref;
6165 int res;
6166 u8 dst_buf[ETH_ALEN], *dst;
6167 struct wpabuf *tlvs;
6168 char *pos;
6169 size_t len;
6170
6171 if (hwaddr_aton(cmd, dst_buf))
6172 return -1;
6173 dst = dst_buf;
6174 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
6175 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
6176 dst = NULL;
6177 pos = cmd + 17;
6178 if (*pos != ' ')
6179 return -1;
6180 pos++;
6181
6182 if (os_strncmp(pos, "upnp ", 5) == 0) {
6183 u8 version;
6184 pos += 5;
6185 if (hexstr2bin(pos, &version, 1) < 0)
6186 return -1;
6187 pos += 2;
6188 if (*pos != ' ')
6189 return -1;
6190 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006191 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006192#ifdef CONFIG_WIFI_DISPLAY
6193 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
6194 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
6195#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006196 } else if (os_strncmp(pos, "asp ", 4) == 0) {
6197 char *svc_str;
6198 char *svc_info = NULL;
6199 u32 id;
6200
6201 pos += 4;
6202 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
6203 return -1;
6204
6205 pos = os_strchr(pos, ' ');
6206 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
6207 return -1;
6208
6209 svc_str = pos + 1;
6210
6211 pos = os_strchr(svc_str, ' ');
6212
6213 if (pos)
6214 *pos++ = '\0';
6215
6216 /* All remaining data is the svc_info string */
6217 if (pos && pos[0] && pos[0] != ' ') {
6218 len = os_strlen(pos);
6219
6220 /* Unescape in place */
6221 len = utf8_unescape(pos, len, pos, len);
6222 if (len > 0xff)
6223 return -1;
6224
6225 svc_info = pos;
6226 }
6227
6228 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
6229 svc_str, svc_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006230 } else {
6231 len = os_strlen(pos);
6232 if (len & 1)
6233 return -1;
6234 len /= 2;
6235 tlvs = wpabuf_alloc(len);
6236 if (tlvs == NULL)
6237 return -1;
6238 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
6239 wpabuf_free(tlvs);
6240 return -1;
6241 }
6242
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006243 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006244 wpabuf_free(tlvs);
6245 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006246 if (ref == 0)
6247 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006248 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006249 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006250 return -1;
6251 return res;
6252}
6253
6254
6255static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
6256 char *cmd)
6257{
6258 long long unsigned val;
6259 u64 req;
6260 if (sscanf(cmd, "%llx", &val) != 1)
6261 return -1;
6262 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006263 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006264}
6265
6266
6267static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
6268{
6269 int freq;
6270 u8 dst[ETH_ALEN];
6271 u8 dialog_token;
6272 struct wpabuf *resp_tlvs;
6273 char *pos, *pos2;
6274 size_t len;
6275
6276 pos = os_strchr(cmd, ' ');
6277 if (pos == NULL)
6278 return -1;
6279 *pos++ = '\0';
6280 freq = atoi(cmd);
6281 if (freq == 0)
6282 return -1;
6283
6284 if (hwaddr_aton(pos, dst))
6285 return -1;
6286 pos += 17;
6287 if (*pos != ' ')
6288 return -1;
6289 pos++;
6290
6291 pos2 = os_strchr(pos, ' ');
6292 if (pos2 == NULL)
6293 return -1;
6294 *pos2++ = '\0';
6295 dialog_token = atoi(pos);
6296
6297 len = os_strlen(pos2);
6298 if (len & 1)
6299 return -1;
6300 len /= 2;
6301 resp_tlvs = wpabuf_alloc(len);
6302 if (resp_tlvs == NULL)
6303 return -1;
6304 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
6305 wpabuf_free(resp_tlvs);
6306 return -1;
6307 }
6308
6309 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
6310 wpabuf_free(resp_tlvs);
6311 return 0;
6312}
6313
6314
6315static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
6316 char *cmd)
6317{
Dmitry Shmidt04949592012-07-19 12:16:46 -07006318 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
6319 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006320 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
6321 return 0;
6322}
6323
6324
6325static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
6326 char *cmd)
6327{
6328 char *pos;
6329 size_t len;
6330 struct wpabuf *query, *resp;
6331
6332 pos = os_strchr(cmd, ' ');
6333 if (pos == NULL)
6334 return -1;
6335 *pos++ = '\0';
6336
6337 len = os_strlen(cmd);
6338 if (len & 1)
6339 return -1;
6340 len /= 2;
6341 query = wpabuf_alloc(len);
6342 if (query == NULL)
6343 return -1;
6344 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6345 wpabuf_free(query);
6346 return -1;
6347 }
6348
6349 len = os_strlen(pos);
6350 if (len & 1) {
6351 wpabuf_free(query);
6352 return -1;
6353 }
6354 len /= 2;
6355 resp = wpabuf_alloc(len);
6356 if (resp == NULL) {
6357 wpabuf_free(query);
6358 return -1;
6359 }
6360 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
6361 wpabuf_free(query);
6362 wpabuf_free(resp);
6363 return -1;
6364 }
6365
6366 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
6367 wpabuf_free(query);
6368 wpabuf_free(resp);
6369 return -1;
6370 }
6371 return 0;
6372}
6373
6374
6375static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6376{
6377 char *pos;
6378 u8 version;
6379
6380 pos = os_strchr(cmd, ' ');
6381 if (pos == NULL)
6382 return -1;
6383 *pos++ = '\0';
6384
6385 if (hexstr2bin(cmd, &version, 1) < 0)
6386 return -1;
6387
6388 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
6389}
6390
6391
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006392static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
6393 u8 replace, char *cmd)
6394{
6395 char *pos;
6396 char *adv_str;
6397 u32 auto_accept, adv_id, svc_state, config_methods;
6398 char *svc_info = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006399 char *cpt_prio_str;
6400 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006401
6402 pos = os_strchr(cmd, ' ');
6403 if (pos == NULL)
6404 return -1;
6405 *pos++ = '\0';
6406
6407 /* Auto-Accept value is mandatory, and must be one of the
6408 * single values (0, 1, 2, 4) */
6409 auto_accept = atoi(cmd);
6410 switch (auto_accept) {
6411 case P2PS_SETUP_NONE: /* No auto-accept */
6412 case P2PS_SETUP_NEW:
6413 case P2PS_SETUP_CLIENT:
6414 case P2PS_SETUP_GROUP_OWNER:
6415 break;
6416 default:
6417 return -1;
6418 }
6419
6420 /* Advertisement ID is mandatory */
6421 cmd = pos;
6422 pos = os_strchr(cmd, ' ');
6423 if (pos == NULL)
6424 return -1;
6425 *pos++ = '\0';
6426
6427 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6428 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
6429 return -1;
6430
6431 /* Only allow replacements if exist, and adds if not */
6432 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
6433 if (!replace)
6434 return -1;
6435 } else {
6436 if (replace)
6437 return -1;
6438 }
6439
6440 /* svc_state between 0 - 0xff is mandatory */
6441 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
6442 return -1;
6443
6444 pos = os_strchr(pos, ' ');
6445 if (pos == NULL)
6446 return -1;
6447
6448 /* config_methods is mandatory */
6449 pos++;
6450 if (sscanf(pos, "%x", &config_methods) != 1)
6451 return -1;
6452
6453 if (!(config_methods &
6454 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
6455 return -1;
6456
6457 pos = os_strchr(pos, ' ');
6458 if (pos == NULL)
6459 return -1;
6460
6461 pos++;
6462 adv_str = pos;
6463
6464 /* Advertisement string is mandatory */
6465 if (!pos[0] || pos[0] == ' ')
6466 return -1;
6467
6468 /* Terminate svc string */
6469 pos = os_strchr(pos, ' ');
6470 if (pos != NULL)
6471 *pos++ = '\0';
6472
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006473 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6474 if (cpt_prio_str) {
6475 pos = os_strchr(pos, ' ');
6476 if (pos != NULL)
6477 *pos++ = '\0';
6478
6479 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6480 return -1;
6481 } else {
6482 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6483 cpt_prio[1] = 0;
6484 }
6485
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006486 /* Service and Response Information are optional */
6487 if (pos && pos[0]) {
6488 size_t len;
6489
6490 /* Note the bare ' included, which cannot exist legally
6491 * in unescaped string. */
6492 svc_info = os_strstr(pos, "svc_info='");
6493
6494 if (svc_info) {
6495 svc_info += 9;
6496 len = os_strlen(svc_info);
6497 utf8_unescape(svc_info, len, svc_info, len);
6498 }
6499 }
6500
6501 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6502 (u8) svc_state, (u16) config_methods,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006503 svc_info, cpt_prio);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006504}
6505
6506
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006507static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6508{
6509 char *pos;
6510
6511 pos = os_strchr(cmd, ' ');
6512 if (pos == NULL)
6513 return -1;
6514 *pos++ = '\0';
6515
6516 if (os_strcmp(cmd, "bonjour") == 0)
6517 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6518 if (os_strcmp(cmd, "upnp") == 0)
6519 return p2p_ctrl_service_add_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006520 if (os_strcmp(cmd, "asp") == 0)
6521 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006522 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6523 return -1;
6524}
6525
6526
6527static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6528 char *cmd)
6529{
6530 size_t len;
6531 struct wpabuf *query;
6532 int ret;
6533
6534 len = os_strlen(cmd);
6535 if (len & 1)
6536 return -1;
6537 len /= 2;
6538 query = wpabuf_alloc(len);
6539 if (query == NULL)
6540 return -1;
6541 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6542 wpabuf_free(query);
6543 return -1;
6544 }
6545
6546 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6547 wpabuf_free(query);
6548 return ret;
6549}
6550
6551
6552static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6553{
6554 char *pos;
6555 u8 version;
6556
6557 pos = os_strchr(cmd, ' ');
6558 if (pos == NULL)
6559 return -1;
6560 *pos++ = '\0';
6561
6562 if (hexstr2bin(cmd, &version, 1) < 0)
6563 return -1;
6564
6565 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6566}
6567
6568
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006569static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6570{
6571 u32 adv_id;
6572
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07006573 if (os_strcmp(cmd, "all") == 0) {
6574 wpas_p2p_service_flush_asp(wpa_s);
6575 return 0;
6576 }
6577
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006578 if (sscanf(cmd, "%x", &adv_id) != 1)
6579 return -1;
6580
6581 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6582}
6583
6584
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006585static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6586{
6587 char *pos;
6588
6589 pos = os_strchr(cmd, ' ');
6590 if (pos == NULL)
6591 return -1;
6592 *pos++ = '\0';
6593
6594 if (os_strcmp(cmd, "bonjour") == 0)
6595 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6596 if (os_strcmp(cmd, "upnp") == 0)
6597 return p2p_ctrl_service_del_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006598 if (os_strcmp(cmd, "asp") == 0)
6599 return p2p_ctrl_service_del_asp(wpa_s, pos);
6600 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6601 return -1;
6602}
6603
6604
6605static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6606{
6607 char *pos;
6608
6609 pos = os_strchr(cmd, ' ');
6610 if (pos == NULL)
6611 return -1;
6612 *pos++ = '\0';
6613
6614 if (os_strcmp(cmd, "asp") == 0)
6615 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6616
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006617 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6618 return -1;
6619}
6620
6621
6622static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
6623{
6624 u8 addr[ETH_ALEN];
6625
6626 /* <addr> */
6627
6628 if (hwaddr_aton(cmd, addr))
6629 return -1;
6630
6631 return wpas_p2p_reject(wpa_s, addr);
6632}
6633
6634
6635static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
6636{
6637 char *pos;
6638 int id;
6639 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006640 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006641 int freq = 0, pref_freq = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08006642 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006643 int edmg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006644
6645 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006646 pos = os_strstr(cmd, " peer=");
6647 if (pos) {
6648 pos += 6;
6649 if (hwaddr_aton(pos, peer))
6650 return -1;
6651 _peer = peer;
6652 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006653 ssid = wpa_config_get_network(wpa_s->conf, id);
6654 if (ssid == NULL || ssid->disabled != 2) {
6655 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6656 "for persistent P2P group",
6657 id);
6658 return -1;
6659 }
6660
Jouni Malinen31be0a42012-08-31 21:20:51 +03006661 pos = os_strstr(cmd, " freq=");
6662 if (pos) {
6663 pos += 6;
6664 freq = atoi(pos);
6665 if (freq <= 0)
6666 return -1;
6667 }
6668
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006669 pos = os_strstr(cmd, " pref=");
6670 if (pos) {
6671 pos += 6;
6672 pref_freq = atoi(pos);
6673 if (pref_freq <= 0)
6674 return -1;
6675 }
6676
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006677 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6678 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6679 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006680 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006681 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Jouni Malinen31be0a42012-08-31 21:20:51 +03006682
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006683 pos = os_strstr(cmd, "freq2=");
6684 if (pos)
6685 freq2 = atoi(pos + 6);
6686
6687 pos = os_strstr(cmd, " max_oper_chwidth=");
6688 if (pos)
6689 chwidth = atoi(pos + 18);
6690
6691 max_oper_chwidth = parse_freq(chwidth, freq2);
6692 if (max_oper_chwidth < 0)
6693 return -1;
6694
6695 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006696 max_oper_chwidth, pref_freq, he, edmg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006697}
6698
6699
6700static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
6701{
6702 char *pos;
6703 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
6704
6705 pos = os_strstr(cmd, " peer=");
6706 if (!pos)
6707 return -1;
6708
6709 *pos = '\0';
6710 pos += 6;
6711 if (hwaddr_aton(pos, peer)) {
6712 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
6713 return -1;
6714 }
6715
6716 pos = os_strstr(pos, " go_dev_addr=");
6717 if (pos) {
6718 pos += 13;
6719 if (hwaddr_aton(pos, go_dev_addr)) {
6720 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
6721 pos);
6722 return -1;
6723 }
6724 go_dev = go_dev_addr;
6725 }
6726
6727 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
6728}
6729
6730
6731static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
6732{
6733 if (os_strncmp(cmd, "persistent=", 11) == 0)
6734 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
6735 if (os_strncmp(cmd, "group=", 6) == 0)
6736 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
6737
6738 return -1;
6739}
6740
6741
6742static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006743 int id, int freq, int vht_center_freq2,
Hai Shalom74f70d42019-02-11 14:42:39 -08006744 int ht40, int vht, int vht_chwidth,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006745 int he, int edmg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006746{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006747 struct wpa_ssid *ssid;
6748
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006749 ssid = wpa_config_get_network(wpa_s->conf, id);
6750 if (ssid == NULL || ssid->disabled != 2) {
6751 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6752 "for persistent P2P group",
6753 id);
6754 return -1;
6755 }
6756
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006757 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
6758 vht_center_freq2, 0, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006759 vht_chwidth, he, edmg,
6760 NULL, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006761}
6762
6763
6764static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
6765{
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006766 int freq = 0, persistent = 0, group_id = -1;
6767 int vht = wpa_s->conf->p2p_go_vht;
6768 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006769 int he = wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006770 int edmg = wpa_s->conf->p2p_go_edmg;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006771 int max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006772 char *token, *context = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006773#ifdef CONFIG_ACS
6774 int acs = 0;
6775#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006776
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006777 while ((token = str_token(cmd, " ", &context))) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07006778 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006779 sscanf(token, "persistent=%d", &group_id) == 1 ||
6780 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006781 continue;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006782#ifdef CONFIG_ACS
6783 } else if (os_strcmp(token, "freq=acs") == 0) {
6784 acs = 1;
6785#endif /* CONFIG_ACS */
6786 } else if (sscanf(token, "freq=%d", &freq) == 1) {
6787 continue;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006788 } else if (os_strcmp(token, "ht40") == 0) {
6789 ht40 = 1;
6790 } else if (os_strcmp(token, "vht") == 0) {
6791 vht = 1;
6792 ht40 = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08006793 } else if (os_strcmp(token, "he") == 0) {
6794 he = 1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006795 } else if (os_strcmp(token, "edmg") == 0) {
6796 edmg = 1;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006797 } else if (os_strcmp(token, "persistent") == 0) {
6798 persistent = 1;
6799 } else {
6800 wpa_printf(MSG_DEBUG,
6801 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6802 token);
6803 return -1;
6804 }
6805 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006806
Roshan Pius3a1667e2018-07-03 15:17:14 -07006807#ifdef CONFIG_ACS
6808 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
6809 (acs || freq == 2 || freq == 5)) {
6810 if (freq == 2 && wpa_s->best_24_freq <= 0) {
6811 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
6812 wpa_s->p2p_go_do_acs = 1;
6813 freq = 0;
6814 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
6815 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
6816 wpa_s->p2p_go_do_acs = 1;
6817 freq = 0;
6818 } else {
6819 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
6820 wpa_s->p2p_go_do_acs = 1;
6821 }
Hai Shalom021b0b52019-04-10 11:17:58 -07006822 } else {
6823 wpa_s->p2p_go_do_acs = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006824 }
6825#endif /* CONFIG_ACS */
6826
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006827 max_oper_chwidth = parse_freq(chwidth, freq2);
6828 if (max_oper_chwidth < 0)
6829 return -1;
6830
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006831 if (group_id >= 0)
6832 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006833 freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006834 max_oper_chwidth, he,
6835 edmg);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006836
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006837 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006838 max_oper_chwidth, he, edmg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006839}
6840
6841
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006842static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
6843 char *buf, size_t buflen)
6844{
6845 u8 dev_addr[ETH_ALEN];
6846 struct wpa_ssid *ssid;
6847 int res;
6848 const u8 *iaddr;
6849
6850 ssid = wpa_s->current_ssid;
6851 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
6852 hwaddr_aton(cmd, dev_addr))
6853 return -1;
6854
6855 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
6856 if (!iaddr)
6857 return -1;
6858 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
6859 if (os_snprintf_error(buflen, res))
6860 return -1;
6861 return res;
6862}
6863
6864
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006865static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
6866 const u8 *p2p_dev_addr)
6867{
6868 struct wpa_supplicant *wpa_s;
6869
6870 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6871 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
6872 return 1;
6873 }
6874
6875 return 0;
6876}
6877
6878
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006879static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
6880 char *buf, size_t buflen)
6881{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006882 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006883 int next, res;
6884 const struct p2p_peer_info *info;
6885 char *pos, *end;
6886 char devtype[WPS_DEV_TYPE_BUFSIZE];
6887 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006888 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006889
6890 if (!wpa_s->global->p2p)
6891 return -1;
6892
6893 if (os_strcmp(cmd, "FIRST") == 0) {
6894 addr_ptr = NULL;
6895 next = 0;
6896 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
6897 if (hwaddr_aton(cmd + 5, addr) < 0)
6898 return -1;
6899 addr_ptr = addr;
6900 next = 1;
6901 } else {
6902 if (hwaddr_aton(cmd, addr) < 0)
6903 return -1;
6904 addr_ptr = addr;
6905 next = 0;
6906 }
6907
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006908 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
6909 if (info == NULL)
6910 return -1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006911 group_capab = info->group_capab;
6912
6913 if (group_capab &&
6914 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
6915 wpa_printf(MSG_DEBUG,
6916 "P2P: Could not find any BSS with p2p_dev_addr "
6917 MACSTR ", hence override group_capab from 0x%x to 0",
6918 MAC2STR(info->p2p_device_addr), group_capab);
6919 group_capab = 0;
6920 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006921
6922 pos = buf;
6923 end = buf + buflen;
6924
6925 res = os_snprintf(pos, end - pos, MACSTR "\n"
6926 "pri_dev_type=%s\n"
6927 "device_name=%s\n"
6928 "manufacturer=%s\n"
6929 "model_name=%s\n"
6930 "model_number=%s\n"
6931 "serial_number=%s\n"
6932 "config_methods=0x%x\n"
6933 "dev_capab=0x%x\n"
6934 "group_capab=0x%x\n"
6935 "level=%d\n",
6936 MAC2STR(info->p2p_device_addr),
6937 wps_dev_type_bin2str(info->pri_dev_type,
6938 devtype, sizeof(devtype)),
6939 info->device_name,
6940 info->manufacturer,
6941 info->model_name,
6942 info->model_number,
6943 info->serial_number,
6944 info->config_methods,
6945 info->dev_capab,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006946 group_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006947 info->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006948 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006949 return pos - buf;
6950 pos += res;
6951
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006952 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
6953 {
6954 const u8 *t;
6955 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
6956 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
6957 wps_dev_type_bin2str(t, devtype,
6958 sizeof(devtype)));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006959 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006960 return pos - buf;
6961 pos += res;
6962 }
6963
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006964 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006965 if (ssid) {
6966 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006967 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006968 return pos - buf;
6969 pos += res;
6970 }
6971
6972 res = p2p_get_peer_info_txt(info, pos, end - pos);
6973 if (res < 0)
6974 return pos - buf;
6975 pos += res;
6976
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006977 if (info->vendor_elems) {
6978 res = os_snprintf(pos, end - pos, "vendor_elems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006979 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006980 return pos - buf;
6981 pos += res;
6982
6983 pos += wpa_snprintf_hex(pos, end - pos,
6984 wpabuf_head(info->vendor_elems),
6985 wpabuf_len(info->vendor_elems));
6986
6987 res = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006988 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006989 return pos - buf;
6990 pos += res;
6991 }
6992
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006993 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006994}
6995
6996
Dmitry Shmidt04949592012-07-19 12:16:46 -07006997static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
6998 const char *param)
6999{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007000 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007001
7002 if (wpa_s->global->p2p == NULL)
7003 return -1;
7004
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007005 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
7006 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007007
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007008 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
7009 struct wpa_freq_range *freq;
7010 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07007011 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07007012 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007013 }
7014
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007015 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007016 return 0;
7017}
7018
7019
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007020static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
7021{
7022 char *param;
7023
7024 if (wpa_s->global->p2p == NULL)
7025 return -1;
7026
7027 param = os_strchr(cmd, ' ');
7028 if (param == NULL)
7029 return -1;
7030 *param++ = '\0';
7031
7032 if (os_strcmp(cmd, "discoverability") == 0) {
7033 p2p_set_client_discoverability(wpa_s->global->p2p,
7034 atoi(param));
7035 return 0;
7036 }
7037
7038 if (os_strcmp(cmd, "managed") == 0) {
7039 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
7040 return 0;
7041 }
7042
7043 if (os_strcmp(cmd, "listen_channel") == 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08007044 char *pos;
7045 u8 channel, op_class;
7046
7047 channel = atoi(param);
7048 pos = os_strchr(param, ' ');
7049 op_class = pos ? atoi(pos) : 81;
7050
7051 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
7052 channel, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007053 }
7054
7055 if (os_strcmp(cmd, "ssid_postfix") == 0) {
7056 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
7057 os_strlen(param));
7058 }
7059
7060 if (os_strcmp(cmd, "noa") == 0) {
7061 char *pos;
7062 int count, start, duration;
7063 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
7064 count = atoi(param);
7065 pos = os_strchr(param, ',');
7066 if (pos == NULL)
7067 return -1;
7068 pos++;
7069 start = atoi(pos);
7070 pos = os_strchr(pos, ',');
7071 if (pos == NULL)
7072 return -1;
7073 pos++;
7074 duration = atoi(pos);
7075 if (count < 0 || count > 255 || start < 0 || duration < 0)
7076 return -1;
7077 if (count == 0 && duration > 0)
7078 return -1;
7079 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
7080 "start=%d duration=%d", count, start, duration);
7081 return wpas_p2p_set_noa(wpa_s, count, start, duration);
7082 }
7083
7084 if (os_strcmp(cmd, "ps") == 0)
7085 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
7086
7087 if (os_strcmp(cmd, "oppps") == 0)
7088 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
7089
7090 if (os_strcmp(cmd, "ctwindow") == 0)
7091 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
7092
7093 if (os_strcmp(cmd, "disabled") == 0) {
7094 wpa_s->global->p2p_disabled = atoi(param);
7095 wpa_printf(MSG_DEBUG, "P2P functionality %s",
7096 wpa_s->global->p2p_disabled ?
7097 "disabled" : "enabled");
7098 if (wpa_s->global->p2p_disabled) {
7099 wpas_p2p_stop_find(wpa_s);
7100 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7101 p2p_flush(wpa_s->global->p2p);
7102 }
7103 return 0;
7104 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007105
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007106 if (os_strcmp(cmd, "conc_pref") == 0) {
7107 if (os_strcmp(param, "sta") == 0)
7108 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
7109 else if (os_strcmp(param, "p2p") == 0)
7110 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007111 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007112 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007113 return -1;
7114 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07007115 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07007116 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07007117 return 0;
7118 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07007119
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007120 if (os_strcmp(cmd, "force_long_sd") == 0) {
7121 wpa_s->force_long_sd = atoi(param);
7122 return 0;
7123 }
7124
7125 if (os_strcmp(cmd, "peer_filter") == 0) {
7126 u8 addr[ETH_ALEN];
7127 if (hwaddr_aton(param, addr))
7128 return -1;
7129 p2p_set_peer_filter(wpa_s->global->p2p, addr);
7130 return 0;
7131 }
7132
7133 if (os_strcmp(cmd, "cross_connect") == 0)
7134 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
7135
7136 if (os_strcmp(cmd, "go_apsd") == 0) {
7137 if (os_strcmp(param, "disable") == 0)
7138 wpa_s->set_ap_uapsd = 0;
7139 else {
7140 wpa_s->set_ap_uapsd = 1;
7141 wpa_s->ap_uapsd = atoi(param);
7142 }
7143 return 0;
7144 }
7145
7146 if (os_strcmp(cmd, "client_apsd") == 0) {
7147 if (os_strcmp(param, "disable") == 0)
7148 wpa_s->set_sta_uapsd = 0;
7149 else {
7150 int be, bk, vi, vo;
7151 char *pos;
7152 /* format: BE,BK,VI,VO;max SP Length */
7153 be = atoi(param);
7154 pos = os_strchr(param, ',');
7155 if (pos == NULL)
7156 return -1;
7157 pos++;
7158 bk = atoi(pos);
7159 pos = os_strchr(pos, ',');
7160 if (pos == NULL)
7161 return -1;
7162 pos++;
7163 vi = atoi(pos);
7164 pos = os_strchr(pos, ',');
7165 if (pos == NULL)
7166 return -1;
7167 pos++;
7168 vo = atoi(pos);
7169 /* ignore max SP Length for now */
7170
7171 wpa_s->set_sta_uapsd = 1;
7172 wpa_s->sta_uapsd = 0;
7173 if (be)
7174 wpa_s->sta_uapsd |= BIT(0);
7175 if (bk)
7176 wpa_s->sta_uapsd |= BIT(1);
7177 if (vi)
7178 wpa_s->sta_uapsd |= BIT(2);
7179 if (vo)
7180 wpa_s->sta_uapsd |= BIT(3);
7181 }
7182 return 0;
7183 }
7184
Dmitry Shmidt04949592012-07-19 12:16:46 -07007185 if (os_strcmp(cmd, "disallow_freq") == 0)
7186 return p2p_ctrl_disallow_freq(wpa_s, param);
7187
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08007188 if (os_strcmp(cmd, "disc_int") == 0) {
7189 int min_disc_int, max_disc_int, max_disc_tu;
7190 char *pos;
7191
7192 pos = param;
7193
7194 min_disc_int = atoi(pos);
7195 pos = os_strchr(pos, ' ');
7196 if (pos == NULL)
7197 return -1;
7198 *pos++ = '\0';
7199
7200 max_disc_int = atoi(pos);
7201 pos = os_strchr(pos, ' ');
7202 if (pos == NULL)
7203 return -1;
7204 *pos++ = '\0';
7205
7206 max_disc_tu = atoi(pos);
7207
7208 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
7209 max_disc_int, max_disc_tu);
7210 }
7211
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007212 if (os_strcmp(cmd, "per_sta_psk") == 0) {
7213 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
7214 return 0;
7215 }
7216
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007217#ifdef CONFIG_WPS_NFC
7218 if (os_strcmp(cmd, "nfc_tag") == 0)
7219 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
7220#endif /* CONFIG_WPS_NFC */
7221
7222 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
7223 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
7224 return 0;
7225 }
7226
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007227 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
7228 int op_class, chan;
7229
7230 op_class = atoi(param);
7231 param = os_strchr(param, ':');
7232 if (!param)
7233 return -1;
7234 param++;
7235 chan = atoi(param);
7236 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
7237 chan);
7238 return 0;
7239 }
7240
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007241 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
7242 cmd);
7243
7244 return -1;
7245}
7246
7247
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007248static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
7249{
7250 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7251 wpa_s->force_long_sd = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007252
7253#ifdef CONFIG_TESTING_OPTIONS
7254 os_free(wpa_s->get_pref_freq_list_override);
7255 wpa_s->get_pref_freq_list_override = NULL;
7256#endif /* CONFIG_TESTING_OPTIONS */
7257
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007258 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007259 wpa_s->parent->p2ps_method_config_any = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007260 if (wpa_s->global->p2p)
7261 p2p_flush(wpa_s->global->p2p);
7262}
7263
7264
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007265static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
7266{
7267 char *pos, *pos2;
7268 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
7269
7270 if (cmd[0]) {
7271 pos = os_strchr(cmd, ' ');
7272 if (pos == NULL)
7273 return -1;
7274 *pos++ = '\0';
7275 dur1 = atoi(cmd);
7276
7277 pos2 = os_strchr(pos, ' ');
7278 if (pos2)
7279 *pos2++ = '\0';
7280 int1 = atoi(pos);
7281 } else
7282 pos2 = NULL;
7283
7284 if (pos2) {
7285 pos = os_strchr(pos2, ' ');
7286 if (pos == NULL)
7287 return -1;
7288 *pos++ = '\0';
7289 dur2 = atoi(pos2);
7290 int2 = atoi(pos);
7291 }
7292
7293 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
7294}
7295
7296
7297static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
7298{
7299 char *pos;
7300 unsigned int period = 0, interval = 0;
7301
7302 if (cmd[0]) {
7303 pos = os_strchr(cmd, ' ');
7304 if (pos == NULL)
7305 return -1;
7306 *pos++ = '\0';
7307 period = atoi(cmd);
7308 interval = atoi(pos);
7309 }
7310
7311 return wpas_p2p_ext_listen(wpa_s, period, interval);
7312}
7313
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007314
7315static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
7316{
7317 const char *pos;
7318 u8 peer[ETH_ALEN];
7319 int iface_addr = 0;
7320
7321 pos = cmd;
7322 if (os_strncmp(pos, "iface=", 6) == 0) {
7323 iface_addr = 1;
7324 pos += 6;
7325 }
7326 if (hwaddr_aton(pos, peer))
7327 return -1;
7328
7329 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
7330 return 0;
7331}
7332
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007333
7334static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
7335{
7336 int freq = 0, period = 0, interval = 0, count = 0;
7337
7338 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
7339 {
7340 wpa_printf(MSG_DEBUG,
7341 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
7342 return -1;
7343 }
7344
7345 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
7346}
7347
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007348#endif /* CONFIG_P2P */
7349
7350
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007351static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
7352{
7353 struct wpa_freq_range_list ranges;
7354 int *freqs = NULL;
7355 struct hostapd_hw_modes *mode;
7356 u16 i;
7357
7358 if (wpa_s->hw.modes == NULL)
7359 return NULL;
7360
7361 os_memset(&ranges, 0, sizeof(ranges));
7362 if (freq_range_list_parse(&ranges, val) < 0)
7363 return NULL;
7364
7365 for (i = 0; i < wpa_s->hw.num_modes; i++) {
7366 int j;
7367
7368 mode = &wpa_s->hw.modes[i];
7369 for (j = 0; j < mode->num_channels; j++) {
7370 unsigned int freq;
7371
7372 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
7373 continue;
7374
7375 freq = mode->channels[j].freq;
7376 if (!freq_range_list_includes(&ranges, freq))
7377 continue;
7378
7379 int_array_add_unique(&freqs, freq);
7380 }
7381 }
7382
7383 os_free(ranges.range);
7384 return freqs;
7385}
7386
7387
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007388#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007389
7390static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
7391{
7392 int auto_sel = 0;
7393 int *freqs = NULL;
7394
7395 if (param) {
7396 char *pos;
7397
7398 auto_sel = os_strstr(param, "auto") != NULL;
7399
7400 pos = os_strstr(param, "freq=");
7401 if (pos) {
7402 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
7403 if (freqs == NULL)
7404 return -1;
7405 }
7406
7407 }
7408
7409 return interworking_select(wpa_s, auto_sel, freqs);
7410}
7411
7412
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007413static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
7414 int only_add)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007415{
7416 u8 bssid[ETH_ALEN];
7417 struct wpa_bss *bss;
7418
7419 if (hwaddr_aton(dst, bssid)) {
7420 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
7421 return -1;
7422 }
7423
Hai Shalomfdcde762020-04-02 11:19:20 -07007424 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007425 if (bss == NULL) {
7426 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
7427 MAC2STR(bssid));
7428 return -1;
7429 }
7430
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007431 if (bss->ssid_len == 0) {
7432 int found = 0;
7433
7434 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
7435 " does not have SSID information", MAC2STR(bssid));
7436
7437 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
7438 list) {
7439 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
7440 bss->ssid_len > 0) {
7441 found = 1;
7442 break;
7443 }
7444 }
7445
7446 if (!found)
7447 return -1;
7448 wpa_printf(MSG_DEBUG,
7449 "Found another matching BSS entry with SSID");
7450 }
7451
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007452 return interworking_connect(wpa_s, bss, only_add);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007453}
7454
7455
7456static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
7457{
7458 u8 dst_addr[ETH_ALEN];
Hai Shalom899fcc72020-10-19 14:38:18 -07007459 int used, freq = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007460 char *pos;
7461#define MAX_ANQP_INFO_ID 100
7462 u16 id[MAX_ANQP_INFO_ID];
7463 size_t num_id = 0;
Dmitry Shmidt15907092014-03-25 10:42:57 -07007464 u32 subtypes = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007465 u32 mbo_subtypes = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007466
7467 used = hwaddr_aton2(dst, dst_addr);
7468 if (used < 0)
7469 return -1;
7470 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007471 if (*pos == ' ')
7472 pos++;
Hai Shalom899fcc72020-10-19 14:38:18 -07007473
7474 if (os_strncmp(pos, "freq=", 5) == 0) {
7475 freq = atoi(pos + 5);
7476 pos = os_strchr(pos, ' ');
7477 if (!pos)
7478 return -1;
7479 pos++;
7480 }
7481
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007482 while (num_id < MAX_ANQP_INFO_ID) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07007483 if (os_strncmp(pos, "hs20:", 5) == 0) {
7484#ifdef CONFIG_HS20
7485 int num = atoi(pos + 5);
7486 if (num <= 0 || num > 31)
7487 return -1;
7488 subtypes |= BIT(num);
7489#else /* CONFIG_HS20 */
7490 return -1;
7491#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007492 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7493#ifdef CONFIG_MBO
7494 int num = atoi(pos + 4);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007495
7496 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007497 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007498 mbo_subtypes |= BIT(num);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007499#else /* CONFIG_MBO */
7500 return -1;
7501#endif /* CONFIG_MBO */
Dmitry Shmidt15907092014-03-25 10:42:57 -07007502 } else {
7503 id[num_id] = atoi(pos);
7504 if (id[num_id])
7505 num_id++;
7506 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007507 pos = os_strchr(pos + 1, ',');
7508 if (pos == NULL)
7509 break;
7510 pos++;
7511 }
7512
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007513 if (num_id == 0 && !subtypes && !mbo_subtypes)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007514 return -1;
7515
Hai Shalom899fcc72020-10-19 14:38:18 -07007516 return anqp_send_req(wpa_s, dst_addr, freq, id, num_id, subtypes,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007517 mbo_subtypes);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007518}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007519
7520
7521static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7522{
7523 u8 dst_addr[ETH_ALEN];
7524 struct wpabuf *advproto, *query = NULL;
7525 int used, ret = -1;
7526 char *pos, *end;
7527 size_t len;
7528
7529 used = hwaddr_aton2(cmd, dst_addr);
7530 if (used < 0)
7531 return -1;
7532
7533 pos = cmd + used;
7534 while (*pos == ' ')
7535 pos++;
7536
7537 /* Advertisement Protocol ID */
7538 end = os_strchr(pos, ' ');
7539 if (end)
7540 len = end - pos;
7541 else
7542 len = os_strlen(pos);
7543 if (len & 0x01)
7544 return -1;
7545 len /= 2;
7546 if (len == 0)
7547 return -1;
7548 advproto = wpabuf_alloc(len);
7549 if (advproto == NULL)
7550 return -1;
7551 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7552 goto fail;
7553
7554 if (end) {
7555 /* Optional Query Request */
7556 pos = end + 1;
7557 while (*pos == ' ')
7558 pos++;
7559
7560 len = os_strlen(pos);
7561 if (len) {
7562 if (len & 0x01)
7563 goto fail;
7564 len /= 2;
7565 if (len == 0)
7566 goto fail;
7567 query = wpabuf_alloc(len);
7568 if (query == NULL)
7569 goto fail;
7570 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7571 goto fail;
7572 }
7573 }
7574
7575 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7576
7577fail:
7578 wpabuf_free(advproto);
7579 wpabuf_free(query);
7580
7581 return ret;
7582}
7583
7584
7585static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7586 size_t buflen)
7587{
7588 u8 addr[ETH_ALEN];
7589 int dialog_token;
7590 int used;
7591 char *pos;
7592 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007593 struct wpabuf *resp;
7594 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007595
7596 used = hwaddr_aton2(cmd, addr);
7597 if (used < 0)
7598 return -1;
7599
7600 pos = cmd + used;
7601 while (*pos == ' ')
7602 pos++;
7603 dialog_token = atoi(pos);
7604
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007605 if (wpa_s->last_gas_resp &&
7606 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
7607 dialog_token == wpa_s->last_gas_dialog_token)
7608 resp = wpa_s->last_gas_resp;
7609 else if (wpa_s->prev_gas_resp &&
7610 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
7611 dialog_token == wpa_s->prev_gas_dialog_token)
7612 resp = wpa_s->prev_gas_resp;
7613 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007614 return -1;
7615
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007616 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007617 start = 0;
7618 requested_len = resp_len;
7619
7620 pos = os_strchr(pos, ' ');
7621 if (pos) {
7622 start = atoi(pos);
7623 if (start > resp_len)
7624 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7625 pos = os_strchr(pos, ',');
7626 if (pos == NULL)
7627 return -1;
7628 pos++;
7629 requested_len = atoi(pos);
7630 if (start + requested_len > resp_len)
7631 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7632 }
7633
7634 if (requested_len * 2 + 1 > buflen)
7635 return os_snprintf(buf, buflen, "FAIL-Too long response");
7636
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007637 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
7638 requested_len);
7639
7640 if (start + requested_len == resp_len) {
7641 /*
7642 * Free memory by dropping the response after it has been
7643 * fetched.
7644 */
7645 if (resp == wpa_s->prev_gas_resp) {
7646 wpabuf_free(wpa_s->prev_gas_resp);
7647 wpa_s->prev_gas_resp = NULL;
7648 } else {
7649 wpabuf_free(wpa_s->last_gas_resp);
7650 wpa_s->last_gas_resp = NULL;
7651 }
7652 }
7653
7654 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007655}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007656#endif /* CONFIG_INTERWORKING */
7657
7658
Dmitry Shmidt04949592012-07-19 12:16:46 -07007659#ifdef CONFIG_HS20
7660
7661static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
7662{
7663 u8 dst_addr[ETH_ALEN];
7664 int used;
7665 char *pos;
7666 u32 subtypes = 0;
7667
7668 used = hwaddr_aton2(dst, dst_addr);
7669 if (used < 0)
7670 return -1;
7671 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007672 if (*pos == ' ')
7673 pos++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007674 for (;;) {
7675 int num = atoi(pos);
7676 if (num <= 0 || num > 31)
7677 return -1;
7678 subtypes |= BIT(num);
7679 pos = os_strchr(pos + 1, ',');
7680 if (pos == NULL)
7681 break;
7682 pos++;
7683 }
7684
7685 if (subtypes == 0)
7686 return -1;
7687
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007688 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007689}
7690
7691
7692static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7693 const u8 *addr, const char *realm)
7694{
7695 u8 *buf;
7696 size_t rlen, len;
7697 int ret;
7698
7699 rlen = os_strlen(realm);
7700 len = 3 + rlen;
7701 buf = os_malloc(len);
7702 if (buf == NULL)
7703 return -1;
7704 buf[0] = 1; /* NAI Home Realm Count */
7705 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
7706 buf[2] = rlen;
7707 os_memcpy(buf + 3, realm, rlen);
7708
7709 ret = hs20_anqp_send_req(wpa_s, addr,
7710 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007711 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007712
7713 os_free(buf);
7714
7715 return ret;
7716}
7717
7718
7719static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7720 char *dst)
7721{
7722 struct wpa_cred *cred = wpa_s->conf->cred;
7723 u8 dst_addr[ETH_ALEN];
7724 int used;
7725 u8 *buf;
7726 size_t len;
7727 int ret;
7728
7729 used = hwaddr_aton2(dst, dst_addr);
7730 if (used < 0)
7731 return -1;
7732
7733 while (dst[used] == ' ')
7734 used++;
7735 if (os_strncmp(dst + used, "realm=", 6) == 0)
7736 return hs20_nai_home_realm_list(wpa_s, dst_addr,
7737 dst + used + 6);
7738
7739 len = os_strlen(dst + used);
7740
7741 if (len == 0 && cred && cred->realm)
7742 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
7743
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07007744 if (len & 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07007745 return -1;
7746 len /= 2;
7747 buf = os_malloc(len);
7748 if (buf == NULL)
7749 return -1;
7750 if (hexstr2bin(dst + used, buf, len) < 0) {
7751 os_free(buf);
7752 return -1;
7753 }
7754
7755 ret = hs20_anqp_send_req(wpa_s, dst_addr,
7756 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007757 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007758 os_free(buf);
7759
7760 return ret;
7761}
7762
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007763
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007764static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
7765 int buflen)
7766{
7767 u8 dst_addr[ETH_ALEN];
7768 int used;
7769 char *ctx = NULL, *icon, *poffset, *psize;
7770
7771 used = hwaddr_aton2(cmd, dst_addr);
7772 if (used < 0)
7773 return -1;
7774 cmd += used;
7775
7776 icon = str_token(cmd, " ", &ctx);
7777 poffset = str_token(cmd, " ", &ctx);
7778 psize = str_token(cmd, " ", &ctx);
7779 if (!icon || !poffset || !psize)
7780 return -1;
7781
7782 wpa_s->fetch_osu_icon_in_progress = 0;
7783 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
7784 reply, buflen);
7785}
7786
7787
7788static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
7789{
7790 u8 dst_addr[ETH_ALEN];
7791 int used;
7792 char *icon;
7793
7794 if (!cmd[0])
7795 return hs20_del_icon(wpa_s, NULL, NULL);
7796
7797 used = hwaddr_aton2(cmd, dst_addr);
7798 if (used < 0)
7799 return -1;
7800
7801 while (cmd[used] == ' ')
7802 used++;
7803 icon = cmd[used] ? &cmd[used] : NULL;
7804
7805 return hs20_del_icon(wpa_s, dst_addr, icon);
7806}
7807
7808
7809static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007810{
7811 u8 dst_addr[ETH_ALEN];
7812 int used;
7813 char *icon;
7814
7815 used = hwaddr_aton2(cmd, dst_addr);
7816 if (used < 0)
7817 return -1;
7818
7819 while (cmd[used] == ' ')
7820 used++;
7821 icon = &cmd[used];
7822
7823 wpa_s->fetch_osu_icon_in_progress = 0;
7824 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007825 (u8 *) icon, os_strlen(icon), inmem);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007826}
7827
Dmitry Shmidt04949592012-07-19 12:16:46 -07007828#endif /* CONFIG_HS20 */
7829
7830
Dmitry Shmidt04949592012-07-19 12:16:46 -07007831#ifdef CONFIG_AUTOSCAN
7832
7833static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
7834 char *cmd)
7835{
7836 enum wpa_states state = wpa_s->wpa_state;
7837 char *new_params = NULL;
7838
7839 if (os_strlen(cmd) > 0) {
7840 new_params = os_strdup(cmd);
7841 if (new_params == NULL)
7842 return -1;
7843 }
7844
7845 os_free(wpa_s->conf->autoscan);
7846 wpa_s->conf->autoscan = new_params;
7847
7848 if (wpa_s->conf->autoscan == NULL)
7849 autoscan_deinit(wpa_s);
7850 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
7851 autoscan_init(wpa_s, 1);
7852 else if (state == WPA_SCANNING)
7853 wpa_supplicant_reinit_autoscan(wpa_s);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007854 else
7855 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
7856 wpa_supplicant_state_txt(state));
Dmitry Shmidt04949592012-07-19 12:16:46 -07007857
7858 return 0;
7859}
7860
7861#endif /* CONFIG_AUTOSCAN */
7862
7863
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007864#ifdef CONFIG_WNM
7865
7866static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
7867{
7868 int enter;
7869 int intval = 0;
7870 char *pos;
7871 int ret;
7872 struct wpabuf *tfs_req = NULL;
7873
7874 if (os_strncmp(cmd, "enter", 5) == 0)
7875 enter = 1;
7876 else if (os_strncmp(cmd, "exit", 4) == 0)
7877 enter = 0;
7878 else
7879 return -1;
7880
7881 pos = os_strstr(cmd, " interval=");
7882 if (pos)
7883 intval = atoi(pos + 10);
7884
7885 pos = os_strstr(cmd, " tfs_req=");
7886 if (pos) {
7887 char *end;
7888 size_t len;
7889 pos += 9;
7890 end = os_strchr(pos, ' ');
7891 if (end)
7892 len = end - pos;
7893 else
7894 len = os_strlen(pos);
7895 if (len & 1)
7896 return -1;
7897 len /= 2;
7898 tfs_req = wpabuf_alloc(len);
7899 if (tfs_req == NULL)
7900 return -1;
7901 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
7902 wpabuf_free(tfs_req);
7903 return -1;
7904 }
7905 }
7906
7907 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
7908 WNM_SLEEP_MODE_EXIT, intval,
7909 tfs_req);
7910 wpabuf_free(tfs_req);
7911
7912 return ret;
7913}
7914
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007915
7916static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
7917{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007918 int query_reason, list = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007919 char *btm_candidates = NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007920
7921 query_reason = atoi(cmd);
7922
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007923 cmd = os_strchr(cmd, ' ');
7924 if (cmd) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007925 if (os_strncmp(cmd, " list", 5) == 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007926 list = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007927 else
7928 btm_candidates = cmd;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007929 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007930
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007931 wpa_printf(MSG_DEBUG,
7932 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7933 query_reason, list ? " candidate list" : "");
7934
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007935 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
7936 btm_candidates,
7937 list);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007938}
7939
Hai Shalom39ba6fc2019-01-22 12:40:38 -08007940
7941static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
7942 char *cmd)
7943{
7944 struct wpabuf *elems;
7945 int ret;
7946
7947 elems = wpabuf_parse_bin(cmd);
7948 if (!elems)
7949 return -1;
7950
7951 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
7952 wpabuf_free(elems);
7953 return ret;
7954}
7955
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007956#endif /* CONFIG_WNM */
7957
7958
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007959static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
7960 size_t buflen)
7961{
7962 struct wpa_signal_info si;
7963 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007964 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007965
7966 ret = wpa_drv_signal_poll(wpa_s, &si);
7967 if (ret)
7968 return -1;
7969
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007970 pos = buf;
7971 end = buf + buflen;
7972
7973 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007974 "NOISE=%d\nFREQUENCY=%u\n",
7975 si.current_signal, si.current_txrate / 1000,
7976 si.current_noise, si.frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007977 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007978 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007979 pos += ret;
7980
7981 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
7982 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007983 channel_width_to_string(si.chanwidth));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007984 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007985 return -1;
7986 pos += ret;
7987 }
7988
Roshan Pius3a1667e2018-07-03 15:17:14 -07007989 if (si.center_frq1 > 0) {
7990 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
7991 si.center_frq1);
7992 if (os_snprintf_error(end - pos, ret))
7993 return -1;
7994 pos += ret;
7995 }
7996
7997 if (si.center_frq2 > 0) {
7998 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
7999 si.center_frq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008000 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008001 return -1;
8002 pos += ret;
8003 }
8004
8005 if (si.avg_signal) {
8006 ret = os_snprintf(pos, end - pos,
8007 "AVG_RSSI=%d\n", si.avg_signal);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008008 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008009 return -1;
8010 pos += ret;
8011 }
8012
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07008013 if (si.avg_beacon_signal) {
8014 ret = os_snprintf(pos, end - pos,
8015 "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
8016 if (os_snprintf_error(end - pos, ret))
8017 return -1;
8018 pos += ret;
8019 }
8020
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008021 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008022}
8023
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008024
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008025static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
8026 const char *cmd)
8027{
8028 const char *pos;
8029 int threshold = 0;
8030 int hysteresis = 0;
8031
8032 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
8033 wpa_printf(MSG_DEBUG,
8034 "Reject SIGNAL_MONITOR command - bgscan is active");
8035 return -1;
8036 }
8037 pos = os_strstr(cmd, "THRESHOLD=");
8038 if (pos)
8039 threshold = atoi(pos + 10);
8040 pos = os_strstr(cmd, "HYSTERESIS=");
8041 if (pos)
8042 hysteresis = atoi(pos + 11);
8043 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
8044}
8045
8046
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008047#ifdef CONFIG_TESTING_OPTIONS
8048int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
8049 enum wpa_driver_if_type if_type,
8050 unsigned int *num,
8051 unsigned int *freq_list)
8052{
8053 char *pos = wpa_s->get_pref_freq_list_override;
8054 char *end;
8055 unsigned int count = 0;
8056
8057 /* Override string format:
8058 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
8059
8060 while (pos) {
8061 if (atoi(pos) == (int) if_type)
8062 break;
8063 pos = os_strchr(pos, ' ');
8064 if (pos)
8065 pos++;
8066 }
8067 if (!pos)
8068 return -1;
8069 pos = os_strchr(pos, ':');
8070 if (!pos)
8071 return -1;
8072 pos++;
8073 end = os_strchr(pos, ' ');
8074 while (pos && (!end || pos < end) && count < *num) {
8075 freq_list[count++] = atoi(pos);
8076 pos = os_strchr(pos, ',');
8077 if (pos)
8078 pos++;
8079 }
8080
8081 *num = count;
8082 return 0;
8083}
8084#endif /* CONFIG_TESTING_OPTIONS */
8085
8086
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008087static int wpas_ctrl_iface_get_pref_freq_list(
8088 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
8089{
8090 unsigned int freq_list[100], num = 100, i;
8091 int ret;
8092 enum wpa_driver_if_type iface_type;
8093 char *pos, *end;
8094
8095 pos = buf;
8096 end = buf + buflen;
8097
8098 /* buf: "<interface_type>" */
8099 if (os_strcmp(cmd, "STATION") == 0)
8100 iface_type = WPA_IF_STATION;
8101 else if (os_strcmp(cmd, "AP") == 0)
8102 iface_type = WPA_IF_AP_BSS;
8103 else if (os_strcmp(cmd, "P2P_GO") == 0)
8104 iface_type = WPA_IF_P2P_GO;
8105 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
8106 iface_type = WPA_IF_P2P_CLIENT;
8107 else if (os_strcmp(cmd, "IBSS") == 0)
8108 iface_type = WPA_IF_IBSS;
8109 else if (os_strcmp(cmd, "TDLS") == 0)
8110 iface_type = WPA_IF_TDLS;
8111 else
8112 return -1;
8113
8114 wpa_printf(MSG_DEBUG,
8115 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
Hai Shalom5f92bc92019-04-18 11:54:11 -07008116 iface_type, cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008117
8118 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
8119 if (ret)
8120 return -1;
8121
8122 for (i = 0; i < num; i++) {
8123 ret = os_snprintf(pos, end - pos, "%s%u",
8124 i > 0 ? "," : "", freq_list[i]);
8125 if (os_snprintf_error(end - pos, ret))
8126 return -1;
8127 pos += ret;
8128 }
8129
8130 return pos - buf;
8131}
8132
8133
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008134static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
8135 char *buf, size_t buflen)
8136{
8137 int ret, i;
8138 char *pos, *end;
8139
8140 ret = os_snprintf(buf, buflen, "%016llX:\n",
8141 (long long unsigned) wpa_s->drv_flags);
8142 if (os_snprintf_error(buflen, ret))
8143 return -1;
8144
8145 pos = buf + ret;
8146 end = buf + buflen;
8147
8148 for (i = 0; i < 64; i++) {
8149 if (wpa_s->drv_flags & (1LLU << i)) {
8150 ret = os_snprintf(pos, end - pos, "%s\n",
8151 driver_flag_to_string(1LLU << i));
8152 if (os_snprintf_error(end - pos, ret))
8153 return -1;
8154 pos += ret;
8155 }
8156 }
8157
8158 return pos - buf;
8159}
8160
8161
Hai Shalomb755a2a2020-04-23 21:49:02 -07008162static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s,
8163 char *buf, size_t buflen)
8164{
8165 int ret, i;
8166 char *pos, *end;
8167
8168 ret = os_snprintf(buf, buflen, "%016llX:\n",
8169 (long long unsigned) wpa_s->drv_flags2);
8170 if (os_snprintf_error(buflen, ret))
8171 return -1;
8172
8173 pos = buf + ret;
8174 end = buf + buflen;
8175
8176 for (i = 0; i < 64; i++) {
8177 if (wpa_s->drv_flags2 & (1LLU << i)) {
8178 ret = os_snprintf(pos, end - pos, "%s\n",
8179 driver_flag2_to_string(1LLU << i));
8180 if (os_snprintf_error(end - pos, ret))
8181 return -1;
8182 pos += ret;
8183 }
8184 }
8185
8186 return pos - buf;
8187}
8188
8189
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008190static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
8191 size_t buflen)
8192{
8193 struct hostap_sta_driver_data sta;
8194 int ret;
8195
8196 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
8197 if (ret)
8198 return -1;
8199
8200 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008201 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008202 if (os_snprintf_error(buflen, ret))
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008203 return -1;
8204 return ret;
8205}
8206
8207
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008208#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008209static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8210 char *buf, size_t buflen)
8211{
8212 int ret;
8213
8214 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008215 if (ret == 0) {
8216 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
8217 struct p2p_data *p2p = wpa_s->global->p2p;
8218 if (p2p) {
8219 char country[3];
8220 country[0] = cmd[8];
8221 country[1] = cmd[9];
8222 country[2] = 0x04;
8223 p2p_set_country(p2p, country);
8224 }
8225 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008226 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008227 if (os_snprintf_error(buflen, ret))
8228 ret = -1;
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008229 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008230 return ret;
8231}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008232#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008233
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07008234
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008235static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8236 char *buf, size_t buflen)
8237{
8238 int ret;
8239 char *pos;
8240 u8 *data = NULL;
8241 unsigned int vendor_id, subcmd;
8242 struct wpabuf *reply;
8243 size_t data_len = 0;
8244
8245 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
8246 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008247 if (!isblank((unsigned char) *pos))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008248 return -EINVAL;
8249
8250 subcmd = strtoul(pos, &pos, 10);
8251
8252 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008253 if (!isblank((unsigned char) *pos++))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008254 return -EINVAL;
8255 data_len = os_strlen(pos);
8256 }
8257
8258 if (data_len) {
8259 data_len /= 2;
8260 data = os_malloc(data_len);
8261 if (!data)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008262 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008263
8264 if (hexstr2bin(pos, data, data_len)) {
8265 wpa_printf(MSG_DEBUG,
8266 "Vendor command: wrong parameter format");
8267 os_free(data);
8268 return -EINVAL;
8269 }
8270 }
8271
8272 reply = wpabuf_alloc((buflen - 1) / 2);
8273 if (!reply) {
8274 os_free(data);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008275 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008276 }
8277
8278 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
8279 reply);
8280
8281 if (ret == 0)
8282 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
8283 wpabuf_len(reply));
8284
8285 wpabuf_free(reply);
8286 os_free(data);
8287
8288 return ret;
8289}
8290
8291
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008292static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
8293{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008294#ifdef CONFIG_P2P
8295 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
8296 wpa_s->global->p2p_init_wpa_s : wpa_s;
8297#endif /* CONFIG_P2P */
8298
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008299 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
8300
Dmitry Shmidt29333592017-01-09 12:27:11 -08008301 if (wpas_abort_ongoing_scan(wpa_s) == 0)
8302 wpa_s->ignore_post_flush_scan_res = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008303
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008304 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
8305 /*
8306 * Avoid possible auto connect re-connection on getting
8307 * disconnected due to state flush.
8308 */
8309 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
8310 }
8311
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008312#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008313 wpas_p2p_group_remove(p2p_wpa_s, "*");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008314 wpas_p2p_cancel(p2p_wpa_s);
8315 p2p_ctrl_flush(p2p_wpa_s);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008316 wpas_p2p_service_flush(p2p_wpa_s);
8317 p2p_wpa_s->global->p2p_disabled = 0;
8318 p2p_wpa_s->global->p2p_per_sta_psk = 0;
8319 p2p_wpa_s->conf->num_sec_device_types = 0;
8320 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
8321 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
8322 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008323 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08008324 p2p_wpa_s->global->pending_p2ps_group = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008325 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008326#endif /* CONFIG_P2P */
8327
8328#ifdef CONFIG_WPS_TESTING
8329 wps_version_number = 0x20;
8330 wps_testing_dummy_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08008331 wps_corrupt_pkhash = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008332 wps_force_auth_types_in_use = 0;
8333 wps_force_encr_types_in_use = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008334#endif /* CONFIG_WPS_TESTING */
8335#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008336 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008337 wpas_wps_cancel(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008338 wps_registrar_flush(wpa_s->wps->registrar);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008339#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07008340 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008341 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008342
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008343#ifdef CONFIG_DPP
8344 wpas_dpp_deinit(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07008345 wpa_s->dpp_init_max_tries = 0;
8346 wpa_s->dpp_init_retry_time = 0;
8347 wpa_s->dpp_resp_wait_time = 0;
8348 wpa_s->dpp_resp_max_tries = 0;
8349 wpa_s->dpp_resp_retry_time = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008350#ifdef CONFIG_DPP2
8351 wpas_dpp_chirp_stop(wpa_s);
8352 wpa_s->dpp_pfs_fallback = 0;
8353#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008354#ifdef CONFIG_TESTING_OPTIONS
8355 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
8356 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
8357 dpp_pkex_ephemeral_key_override_len = 0;
8358 dpp_protocol_key_override_len = 0;
8359 dpp_nonce_override_len = 0;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07008360#ifdef CONFIG_DPP2
8361 dpp_version_override = 2;
8362#else /* CONFIG_DPP2 */
8363 dpp_version_override = 1;
8364#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008365#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008366#endif /* CONFIG_DPP */
8367
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008368#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008369#ifdef CONFIG_TDLS_TESTING
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008370 tdls_testing = 0;
8371#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008372 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
8373 wpa_tdls_enable(wpa_s->wpa, 1);
8374#endif /* CONFIG_TDLS */
8375
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008376 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
8377 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07008378 wpa_s->last_michael_mic_error.sec = 0;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008379
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008380 wpa_s->no_keep_alive = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08008381 wpa_s->own_disconnect_req = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008382 wpa_s->own_reconnect_req = 0;
8383 wpa_s->deny_ptk0_rekey = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008384
8385 os_free(wpa_s->disallow_aps_bssid);
8386 wpa_s->disallow_aps_bssid = NULL;
8387 wpa_s->disallow_aps_bssid_count = 0;
8388 os_free(wpa_s->disallow_aps_ssid);
8389 wpa_s->disallow_aps_ssid = NULL;
8390 wpa_s->disallow_aps_ssid_count = 0;
8391
8392 wpa_s->set_sta_uapsd = 0;
8393 wpa_s->sta_uapsd = 0;
8394
Hai Shalom899fcc72020-10-19 14:38:18 -07008395 wpa_s->consecutive_conn_failures = 0;
8396
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008397 wpa_drv_radio_disable(wpa_s, 0);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008398 wpa_blacklist_clear(wpa_s);
8399 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
8400 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08008401 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08008402 wpa_s->conf->auto_interworking = 0;
8403 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008404
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008405 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
8406 rsn_preauth_deinit(wpa_s->wpa);
8407
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008408 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
8409 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
8410 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
Hai Shalome21d4e82020-04-29 16:34:06 -07008411 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008412
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008413 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008414 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008415
8416 wpa_s->next_ssid = NULL;
8417
8418#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008419#ifdef CONFIG_HS20
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008420 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008421 hs20_del_icon(wpa_s, NULL, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008422#endif /* CONFIG_HS20 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008423#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008424
8425 wpa_s->ext_mgmt_frame_handling = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008426 wpa_s->ext_eapol_frame_io = 0;
8427#ifdef CONFIG_TESTING_OPTIONS
8428 wpa_s->extra_roc_dur = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008429 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008430 wpa_s->p2p_go_csa_on_inv = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008431 wpa_s->ignore_auth_resp = 0;
8432 wpa_s->ignore_assoc_disallow = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008433 wpa_s->disable_sa_query = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008434 wpa_s->testing_resend_assoc = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008435 wpa_s->ignore_sae_h2e_only = 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07008436 wpa_s->ft_rsnxe_used = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008437 wpa_s->reject_btm_req_reason = 0;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008438 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008439 os_free(wpa_s->get_pref_freq_list_override);
8440 wpa_s->get_pref_freq_list_override = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008441 wpabuf_free(wpa_s->sae_commit_override);
8442 wpa_s->sae_commit_override = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008443 os_free(wpa_s->extra_sae_rejected_groups);
8444 wpa_s->extra_sae_rejected_groups = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008445 wpabuf_free(wpa_s->rsne_override_eapol);
8446 wpa_s->rsne_override_eapol = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008447 wpabuf_free(wpa_s->rsnxe_override_assoc);
8448 wpa_s->rsnxe_override_assoc = NULL;
8449 wpabuf_free(wpa_s->rsnxe_override_eapol);
8450 wpa_s->rsnxe_override_eapol = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008451 wpas_clear_driver_signal_override(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -07008452 wpa_s->oci_freq_override_eapol = 0;
8453 wpa_s->oci_freq_override_saquery_req = 0;
8454 wpa_s->oci_freq_override_saquery_resp = 0;
8455 wpa_s->oci_freq_override_eapol_g2 = 0;
8456 wpa_s->oci_freq_override_ft_assoc = 0;
8457 wpa_s->oci_freq_override_fils_assoc = 0;
8458 wpa_s->oci_freq_override_wnm_sleep = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008459#ifdef CONFIG_DPP
8460 os_free(wpa_s->dpp_config_obj_override);
8461 wpa_s->dpp_config_obj_override = NULL;
8462 os_free(wpa_s->dpp_discovery_override);
8463 wpa_s->dpp_discovery_override = NULL;
8464 os_free(wpa_s->dpp_groups_override);
8465 wpa_s->dpp_groups_override = NULL;
8466 dpp_test = DPP_TEST_DISABLED;
8467#endif /* CONFIG_DPP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008468#endif /* CONFIG_TESTING_OPTIONS */
8469
8470 wpa_s->disconnected = 0;
8471 os_free(wpa_s->next_scan_freqs);
8472 wpa_s->next_scan_freqs = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008473 os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN);
8474 wpa_s->next_scan_bssid_wildcard_ssid = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008475 os_free(wpa_s->select_network_scan_freqs);
8476 wpa_s->select_network_scan_freqs = NULL;
Hai Shalom899fcc72020-10-19 14:38:18 -07008477 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008478
8479 wpa_bss_flush(wpa_s);
8480 if (!dl_list_empty(&wpa_s->bss)) {
8481 wpa_printf(MSG_DEBUG,
8482 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8483 MACSTR " pending_bssid=" MACSTR,
8484 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
8485 MAC2STR(wpa_s->bssid),
8486 MAC2STR(wpa_s->pending_bssid));
8487 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008488
8489 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -08008490 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008491
8492#ifdef CONFIG_SME
8493 wpa_s->sme.last_unprot_disconnect.sec = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008494 wpa_s->sme.auth_alg = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008495#endif /* CONFIG_SME */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008496
8497 wpabuf_free(wpa_s->ric_ies);
8498 wpa_s->ric_ies = NULL;
Hai Shalom74f70d42019-02-11 14:42:39 -08008499
8500 wpa_supplicant_update_channel_list(wpa_s, NULL);
8501
8502 free_bss_tmp_disallowed(wpa_s);
Hai Shalom899fcc72020-10-19 14:38:18 -07008503
8504 os_memset(&wpa_s->robust_av, 0, sizeof(struct robust_av_data));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008505}
8506
8507
8508static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
8509 char *buf, size_t buflen)
8510{
8511 struct wpa_radio_work *work;
8512 char *pos, *end;
8513 struct os_reltime now, diff;
8514
8515 pos = buf;
8516 end = buf + buflen;
8517
8518 os_get_reltime(&now);
8519
8520 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8521 {
8522 int ret;
8523
8524 os_reltime_sub(&now, &work->time, &diff);
8525 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
8526 work->type, work->wpa_s->ifname, work->freq,
8527 work->started, diff.sec, diff.usec);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008528 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008529 break;
8530 pos += ret;
8531 }
8532
8533 return pos - buf;
8534}
8535
8536
8537static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
8538{
8539 struct wpa_radio_work *work = eloop_ctx;
8540 struct wpa_external_work *ework = work->ctx;
8541
8542 wpa_dbg(work->wpa_s, MSG_DEBUG,
8543 "Timing out external radio work %u (%s)",
8544 ework->id, work->type);
8545 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008546 work->wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008547 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008548 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008549}
8550
8551
8552static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
8553{
8554 struct wpa_external_work *ework = work->ctx;
8555
8556 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008557 if (work->started)
8558 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8559 work, NULL);
8560
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008561 /*
8562 * work->type points to a buffer in ework, so need to replace
8563 * that here with a fixed string to avoid use of freed memory
8564 * in debug prints.
8565 */
8566 work->type = "freed-ext-work";
8567 work->ctx = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008568 os_free(ework);
8569 return;
8570 }
8571
8572 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
8573 ework->id, ework->type);
8574 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008575 work->wpa_s->ext_work_in_progress = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008576 if (!ework->timeout)
8577 ework->timeout = 10;
8578 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
8579 work, NULL);
8580}
8581
8582
8583static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
8584 char *buf, size_t buflen)
8585{
8586 struct wpa_external_work *ework;
8587 char *pos, *pos2;
8588 size_t type_len;
8589 int ret;
8590 unsigned int freq = 0;
8591
8592 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8593
8594 ework = os_zalloc(sizeof(*ework));
8595 if (ework == NULL)
8596 return -1;
8597
8598 pos = os_strchr(cmd, ' ');
8599 if (pos) {
8600 type_len = pos - cmd;
8601 pos++;
8602
8603 pos2 = os_strstr(pos, "freq=");
8604 if (pos2)
8605 freq = atoi(pos2 + 5);
8606
8607 pos2 = os_strstr(pos, "timeout=");
8608 if (pos2)
8609 ework->timeout = atoi(pos2 + 8);
8610 } else {
8611 type_len = os_strlen(cmd);
8612 }
8613 if (4 + type_len >= sizeof(ework->type))
8614 type_len = sizeof(ework->type) - 4 - 1;
8615 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
8616 os_memcpy(ework->type + 4, cmd, type_len);
8617 ework->type[4 + type_len] = '\0';
8618
8619 wpa_s->ext_work_id++;
8620 if (wpa_s->ext_work_id == 0)
8621 wpa_s->ext_work_id++;
8622 ework->id = wpa_s->ext_work_id;
8623
8624 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
8625 ework) < 0) {
8626 os_free(ework);
8627 return -1;
8628 }
8629
8630 ret = os_snprintf(buf, buflen, "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008631 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008632 return -1;
8633 return ret;
8634}
8635
8636
8637static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
8638{
8639 struct wpa_radio_work *work;
8640 unsigned int id = atoi(cmd);
8641
8642 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8643 {
8644 struct wpa_external_work *ework;
8645
8646 if (os_strncmp(work->type, "ext:", 4) != 0)
8647 continue;
8648 ework = work->ctx;
8649 if (id && ework->id != id)
8650 continue;
8651 wpa_dbg(wpa_s, MSG_DEBUG,
8652 "Completed external radio work %u (%s)",
8653 ework->id, ework->type);
8654 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008655 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008656 radio_work_done(work);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07008657 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008658 return 3; /* "OK\n" */
8659 }
8660
8661 return -1;
8662}
8663
8664
8665static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
8666 char *buf, size_t buflen)
8667{
8668 if (os_strcmp(cmd, "show") == 0)
8669 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
8670 if (os_strncmp(cmd, "add ", 4) == 0)
8671 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
8672 if (os_strncmp(cmd, "done ", 5) == 0)
8673 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
8674 return -1;
8675}
8676
8677
8678void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
8679{
8680 struct wpa_radio_work *work, *tmp;
8681
Dmitry Shmidt18463232014-01-24 12:29:41 -08008682 if (!wpa_s || !wpa_s->radio)
8683 return;
8684
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008685 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
8686 struct wpa_radio_work, list) {
8687 struct wpa_external_work *ework;
8688
8689 if (os_strncmp(work->type, "ext:", 4) != 0)
8690 continue;
8691 ework = work->ctx;
8692 wpa_dbg(wpa_s, MSG_DEBUG,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07008693 "Flushing%s external radio work %u (%s)",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008694 work->started ? " started" : "", ework->id,
8695 ework->type);
8696 if (work->started)
8697 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8698 work, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008699 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008700 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008701 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008702}
8703
8704
Dmitry Shmidt051af732013-10-22 13:52:46 -07008705static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
8706{
8707 struct wpa_supplicant *wpa_s = eloop_ctx;
8708 eapol_sm_notify_ctrl_response(wpa_s->eapol);
8709}
8710
8711
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008712static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
8713 unsigned int *scan_id_count, int scan_id[])
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008714{
8715 const char *pos = value;
8716
8717 while (pos) {
8718 if (*pos == ' ' || *pos == '\0')
8719 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008720 if (*scan_id_count == MAX_SCAN_ID)
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008721 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008722 scan_id[(*scan_id_count)++] = atoi(pos);
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008723 pos = os_strchr(pos, ',');
8724 if (pos)
8725 pos++;
8726 }
8727
8728 return 0;
8729}
8730
8731
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008732static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
8733 char *reply, int reply_size, int *reply_len)
8734{
8735 char *pos;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008736 unsigned int manual_scan_passive = 0;
8737 unsigned int manual_scan_use_id = 0;
8738 unsigned int manual_scan_only_new = 0;
8739 unsigned int scan_only = 0;
8740 unsigned int scan_id_count = 0;
8741 int scan_id[MAX_SCAN_ID];
8742 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
8743 struct wpa_scan_results *scan_res);
8744 int *manual_scan_freqs = NULL;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008745 struct wpa_ssid_value *ssid = NULL, *ns;
8746 unsigned int ssid_count = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008747
8748 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
8749 *reply_len = -1;
8750 return;
8751 }
8752
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008753 if (radio_work_pending(wpa_s, "scan")) {
8754 wpa_printf(MSG_DEBUG,
8755 "Pending scan scheduled - reject new request");
8756 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8757 return;
8758 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008759
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008760#ifdef CONFIG_INTERWORKING
8761 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
8762 wpa_printf(MSG_DEBUG,
8763 "Interworking select in progress - reject new scan");
8764 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8765 return;
8766 }
8767#endif /* CONFIG_INTERWORKING */
8768
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008769 if (params) {
8770 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008771 scan_only = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008772
8773 pos = os_strstr(params, "freq=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008774 if (pos) {
8775 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
8776 pos + 5);
8777 if (manual_scan_freqs == NULL) {
8778 *reply_len = -1;
8779 goto done;
8780 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008781 }
8782
8783 pos = os_strstr(params, "passive=");
8784 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008785 manual_scan_passive = !!atoi(pos + 8);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008786
8787 pos = os_strstr(params, "use_id=");
8788 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008789 manual_scan_use_id = atoi(pos + 7);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008790
8791 pos = os_strstr(params, "only_new=1");
8792 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008793 manual_scan_only_new = 1;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008794
8795 pos = os_strstr(params, "scan_id=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008796 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
8797 scan_id) < 0) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008798 *reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008799 goto done;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008800 }
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008801
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008802 pos = os_strstr(params, "bssid=");
8803 if (pos) {
8804 u8 bssid[ETH_ALEN];
8805
8806 pos += 6;
8807 if (hwaddr_aton(pos, bssid)) {
8808 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
8809 *reply_len = -1;
8810 goto done;
8811 }
8812 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
Hai Shalomfdcde762020-04-02 11:19:20 -07008813
8814 wpa_s->next_scan_bssid_wildcard_ssid =
8815 os_strstr(params, "wildcard_ssid=1") != NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008816 }
8817
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008818 pos = params;
8819 while (pos && *pos != '\0') {
8820 if (os_strncmp(pos, "ssid ", 5) == 0) {
8821 char *end;
8822
8823 pos += 5;
8824 end = pos;
8825 while (*end) {
8826 if (*end == '\0' || *end == ' ')
8827 break;
8828 end++;
8829 }
8830
8831 ns = os_realloc_array(
8832 ssid, ssid_count + 1,
8833 sizeof(struct wpa_ssid_value));
8834 if (ns == NULL) {
8835 *reply_len = -1;
8836 goto done;
8837 }
8838 ssid = ns;
8839
8840 if ((end - pos) & 0x01 ||
8841 end - pos > 2 * SSID_MAX_LEN ||
8842 hexstr2bin(pos, ssid[ssid_count].ssid,
8843 (end - pos) / 2) < 0) {
8844 wpa_printf(MSG_DEBUG,
8845 "Invalid SSID value '%s'",
8846 pos);
8847 *reply_len = -1;
8848 goto done;
8849 }
8850 ssid[ssid_count].ssid_len = (end - pos) / 2;
8851 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
8852 ssid[ssid_count].ssid,
8853 ssid[ssid_count].ssid_len);
8854 ssid_count++;
8855 pos = end;
8856 }
8857
8858 pos = os_strchr(pos, ' ');
8859 if (pos)
8860 pos++;
8861 }
8862 }
8863
8864 wpa_s->num_ssids_from_scan_req = ssid_count;
8865 os_free(wpa_s->ssids_from_scan_req);
8866 if (ssid_count) {
8867 wpa_s->ssids_from_scan_req = ssid;
8868 ssid = NULL;
8869 } else {
8870 wpa_s->ssids_from_scan_req = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008871 }
8872
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008873 if (scan_only)
8874 scan_res_handler = scan_only_handler;
8875 else if (wpa_s->scan_res_handler == scan_only_handler)
8876 scan_res_handler = NULL;
8877 else
8878 scan_res_handler = wpa_s->scan_res_handler;
8879
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008880 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
8881 ((wpa_s->wpa_state <= WPA_SCANNING) ||
8882 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008883 wpa_s->manual_scan_passive = manual_scan_passive;
8884 wpa_s->manual_scan_use_id = manual_scan_use_id;
8885 wpa_s->manual_scan_only_new = manual_scan_only_new;
8886 wpa_s->scan_id_count = scan_id_count;
8887 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8888 wpa_s->scan_res_handler = scan_res_handler;
8889 os_free(wpa_s->manual_scan_freqs);
8890 wpa_s->manual_scan_freqs = manual_scan_freqs;
8891 manual_scan_freqs = NULL;
8892
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008893 wpa_s->normal_scans = 0;
8894 wpa_s->scan_req = MANUAL_SCAN_REQ;
8895 wpa_s->after_wps = 0;
8896 wpa_s->known_wps_freq = 0;
8897 wpa_supplicant_req_scan(wpa_s, 0, 0);
8898 if (wpa_s->manual_scan_use_id) {
8899 wpa_s->manual_scan_id++;
8900 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8901 wpa_s->manual_scan_id);
8902 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8903 wpa_s->manual_scan_id);
8904 }
8905 } else if (wpa_s->sched_scanning) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008906 wpa_s->manual_scan_passive = manual_scan_passive;
8907 wpa_s->manual_scan_use_id = manual_scan_use_id;
8908 wpa_s->manual_scan_only_new = manual_scan_only_new;
8909 wpa_s->scan_id_count = scan_id_count;
8910 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8911 wpa_s->scan_res_handler = scan_res_handler;
8912 os_free(wpa_s->manual_scan_freqs);
8913 wpa_s->manual_scan_freqs = manual_scan_freqs;
8914 manual_scan_freqs = NULL;
8915
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008916 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
8917 wpa_supplicant_cancel_sched_scan(wpa_s);
8918 wpa_s->scan_req = MANUAL_SCAN_REQ;
8919 wpa_supplicant_req_scan(wpa_s, 0, 0);
8920 if (wpa_s->manual_scan_use_id) {
8921 wpa_s->manual_scan_id++;
8922 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8923 wpa_s->manual_scan_id);
8924 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8925 wpa_s->manual_scan_id);
8926 }
8927 } else {
8928 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
8929 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8930 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008931
8932done:
8933 os_free(manual_scan_freqs);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008934 os_free(ssid);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008935}
8936
8937
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008938#ifdef CONFIG_TESTING_OPTIONS
8939
8940static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
8941 unsigned int freq, const u8 *dst,
8942 const u8 *src, const u8 *bssid,
8943 const u8 *data, size_t data_len,
8944 enum offchannel_send_action_result
8945 result)
8946{
8947 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8948 " src=" MACSTR " bssid=" MACSTR " result=%s",
8949 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
8950 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
8951 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
8952 "NO_ACK" : "FAILED"));
8953}
8954
8955
8956static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
8957{
8958 char *pos, *param;
8959 size_t len;
8960 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
8961 int res, used;
8962 int freq = 0, no_cck = 0, wait_time = 0;
8963
8964 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8965 * <action=Action frame payload> */
8966
8967 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
8968
8969 pos = cmd;
8970 used = hwaddr_aton2(pos, da);
8971 if (used < 0)
8972 return -1;
8973 pos += used;
8974 while (*pos == ' ')
8975 pos++;
8976 used = hwaddr_aton2(pos, bssid);
8977 if (used < 0)
8978 return -1;
8979 pos += used;
8980
8981 param = os_strstr(pos, " freq=");
8982 if (param) {
8983 param += 6;
8984 freq = atoi(param);
8985 }
8986
8987 param = os_strstr(pos, " no_cck=");
8988 if (param) {
8989 param += 8;
8990 no_cck = atoi(param);
8991 }
8992
8993 param = os_strstr(pos, " wait_time=");
8994 if (param) {
8995 param += 11;
8996 wait_time = atoi(param);
8997 }
8998
8999 param = os_strstr(pos, " action=");
9000 if (param == NULL)
9001 return -1;
9002 param += 8;
9003
9004 len = os_strlen(param);
9005 if (len & 1)
9006 return -1;
9007 len /= 2;
9008
9009 buf = os_malloc(len);
9010 if (buf == NULL)
9011 return -1;
9012
9013 if (hexstr2bin(param, buf, len) < 0) {
9014 os_free(buf);
9015 return -1;
9016 }
9017
9018 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
9019 buf, len, wait_time,
9020 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
9021 os_free(buf);
9022 return res;
9023}
9024
9025
9026static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
9027{
9028 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
9029 offchannel_send_action_done(wpa_s);
9030}
9031
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009032
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009033static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
9034 char *cmd)
9035{
9036 char *pos, *param;
9037 size_t len;
9038 u8 *buf;
9039 int freq = 0, datarate = 0, ssi_signal = 0;
9040 union wpa_event_data event;
9041
9042 if (!wpa_s->ext_mgmt_frame_handling)
9043 return -1;
9044
9045 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
9046
9047 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
9048
9049 pos = cmd;
9050 param = os_strstr(pos, "freq=");
9051 if (param) {
9052 param += 5;
9053 freq = atoi(param);
9054 }
9055
9056 param = os_strstr(pos, " datarate=");
9057 if (param) {
9058 param += 10;
9059 datarate = atoi(param);
9060 }
9061
9062 param = os_strstr(pos, " ssi_signal=");
9063 if (param) {
9064 param += 12;
9065 ssi_signal = atoi(param);
9066 }
9067
9068 param = os_strstr(pos, " frame=");
9069 if (param == NULL)
9070 return -1;
9071 param += 7;
9072
9073 len = os_strlen(param);
9074 if (len & 1)
9075 return -1;
9076 len /= 2;
9077
9078 buf = os_malloc(len);
9079 if (buf == NULL)
9080 return -1;
9081
9082 if (hexstr2bin(param, buf, len) < 0) {
9083 os_free(buf);
9084 return -1;
9085 }
9086
9087 os_memset(&event, 0, sizeof(event));
9088 event.rx_mgmt.freq = freq;
9089 event.rx_mgmt.frame = buf;
9090 event.rx_mgmt.frame_len = len;
9091 event.rx_mgmt.ssi_signal = ssi_signal;
9092 event.rx_mgmt.datarate = datarate;
9093 wpa_s->ext_mgmt_frame_handling = 0;
9094 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
9095 wpa_s->ext_mgmt_frame_handling = 1;
9096
9097 os_free(buf);
9098
9099 return 0;
9100}
9101
9102
Paul Stewart092955c2017-02-06 09:13:09 -08009103static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
9104 char *param)
9105{
9106 struct wpa_scan_res *res;
9107 struct os_reltime now;
9108 char *pos, *end;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009109 int ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08009110
9111 if (!param)
9112 return -1;
9113
9114 if (os_strcmp(param, "START") == 0) {
9115 wpa_bss_update_start(wpa_s);
9116 return 0;
9117 }
9118
9119 if (os_strcmp(param, "END") == 0) {
9120 wpa_bss_update_end(wpa_s, NULL, 1);
9121 return 0;
9122 }
9123
9124 if (os_strncmp(param, "BSS ", 4) != 0)
9125 return -1;
9126 param += 3;
9127
9128 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
9129 if (!res)
9130 return -1;
9131
9132 pos = os_strstr(param, " flags=");
9133 if (pos)
9134 res->flags = strtol(pos + 7, NULL, 16);
9135
9136 pos = os_strstr(param, " bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009137 if (pos && hwaddr_aton(pos + 7, res->bssid))
9138 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009139
9140 pos = os_strstr(param, " freq=");
9141 if (pos)
9142 res->freq = atoi(pos + 6);
9143
9144 pos = os_strstr(param, " beacon_int=");
9145 if (pos)
9146 res->beacon_int = atoi(pos + 12);
9147
9148 pos = os_strstr(param, " caps=");
9149 if (pos)
9150 res->caps = strtol(pos + 6, NULL, 16);
9151
9152 pos = os_strstr(param, " qual=");
9153 if (pos)
9154 res->qual = atoi(pos + 6);
9155
9156 pos = os_strstr(param, " noise=");
9157 if (pos)
9158 res->noise = atoi(pos + 7);
9159
9160 pos = os_strstr(param, " level=");
9161 if (pos)
9162 res->level = atoi(pos + 7);
9163
9164 pos = os_strstr(param, " tsf=");
9165 if (pos)
9166 res->tsf = strtoll(pos + 5, NULL, 16);
9167
9168 pos = os_strstr(param, " age=");
9169 if (pos)
9170 res->age = atoi(pos + 5);
9171
9172 pos = os_strstr(param, " est_throughput=");
9173 if (pos)
9174 res->est_throughput = atoi(pos + 16);
9175
9176 pos = os_strstr(param, " snr=");
9177 if (pos)
9178 res->snr = atoi(pos + 5);
9179
9180 pos = os_strstr(param, " parent_tsf=");
9181 if (pos)
9182 res->parent_tsf = strtoll(pos + 7, NULL, 16);
9183
9184 pos = os_strstr(param, " tsf_bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009185 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
9186 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009187
9188 pos = os_strstr(param, " ie=");
9189 if (pos) {
9190 pos += 4;
9191 end = os_strchr(pos, ' ');
9192 if (!end)
9193 end = pos + os_strlen(pos);
9194 res->ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009195 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
9196 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009197 }
9198
9199 pos = os_strstr(param, " beacon_ie=");
9200 if (pos) {
9201 pos += 11;
9202 end = os_strchr(pos, ' ');
9203 if (!end)
9204 end = pos + os_strlen(pos);
9205 res->beacon_ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009206 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
9207 res->beacon_ie_len))
9208 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08009209 }
9210
9211 os_get_reltime(&now);
9212 wpa_bss_update_scan_res(wpa_s, res, &now);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009213 ret = 0;
9214fail:
Paul Stewart092955c2017-02-06 09:13:09 -08009215 os_free(res);
9216
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009217 return ret;
Paul Stewart092955c2017-02-06 09:13:09 -08009218}
9219
9220
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009221static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
9222{
9223 char *pos, *param;
9224 union wpa_event_data event;
9225 enum wpa_event_type ev;
9226
9227 /* <event name> [parameters..] */
9228
9229 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
9230
9231 pos = cmd;
9232 param = os_strchr(pos, ' ');
9233 if (param)
9234 *param++ = '\0';
9235
9236 os_memset(&event, 0, sizeof(event));
9237
9238 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
9239 ev = EVENT_INTERFACE_ENABLED;
9240 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
9241 ev = EVENT_INTERFACE_DISABLED;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07009242 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
9243 ev = EVENT_AVOID_FREQUENCIES;
9244 if (param == NULL)
9245 param = "";
9246 if (freq_range_list_parse(&event.freq_range, param) < 0)
9247 return -1;
9248 wpa_supplicant_event(wpa_s, ev, &event);
9249 os_free(event.freq_range.range);
9250 return 0;
Paul Stewart092955c2017-02-06 09:13:09 -08009251 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
9252 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009253 } else {
9254 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
9255 cmd);
9256 return -1;
9257 }
9258
9259 wpa_supplicant_event(wpa_s, ev, &event);
9260
9261 return 0;
9262}
9263
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009264
9265static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
9266{
9267 char *pos;
9268 u8 src[ETH_ALEN], *buf;
9269 int used;
9270 size_t len;
9271
9272 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
9273
9274 pos = cmd;
9275 used = hwaddr_aton2(pos, src);
9276 if (used < 0)
9277 return -1;
9278 pos += used;
9279 while (*pos == ' ')
9280 pos++;
9281
9282 len = os_strlen(pos);
9283 if (len & 1)
9284 return -1;
9285 len /= 2;
9286
9287 buf = os_malloc(len);
9288 if (buf == NULL)
9289 return -1;
9290
9291 if (hexstr2bin(pos, buf, len) < 0) {
9292 os_free(buf);
9293 return -1;
9294 }
9295
9296 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
9297 os_free(buf);
9298
9299 return 0;
9300}
9301
9302
9303static u16 ipv4_hdr_checksum(const void *buf, size_t len)
9304{
9305 size_t i;
9306 u32 sum = 0;
9307 const u16 *pos = buf;
9308
9309 for (i = 0; i < len / 2; i++)
9310 sum += *pos++;
9311
9312 while (sum >> 16)
9313 sum = (sum & 0xffff) + (sum >> 16);
9314
9315 return sum ^ 0xffff;
9316}
9317
9318
9319#define HWSIM_PACKETLEN 1500
9320#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
9321
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07009322static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
9323 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009324{
9325 struct wpa_supplicant *wpa_s = ctx;
9326 const struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07009327 struct ip ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009328 const u8 *pos;
9329 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08009330 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009331
Hai Shalom74f70d42019-02-11 14:42:39 -08009332 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
9333 wpa_printf(MSG_DEBUG,
9334 "test data: RX - ignore unexpected length %d",
9335 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009336 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08009337 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009338
9339 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009340 os_memcpy(&ip, eth + 1, sizeof(ip));
9341 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009342
Hai Shalomfdcde762020-04-02 11:19:20 -07009343 if (ip.ip_hl != 5 || ip.ip_v != 4 || ntohs(ip.ip_len) > HWSIM_IP_LEN) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009344 wpa_printf(MSG_DEBUG,
Hai Shalom899fcc72020-10-19 14:38:18 -07009345 "test data: RX - ignore unexpected IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009346 return;
Hai Shalom39bc25d2019-02-06 16:32:13 -08009347 }
Hai Shalombf6e0ba2019-02-11 12:01:50 -08009348
Hai Shalomfdcde762020-04-02 11:19:20 -07009349 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009350 if (*pos != (u8) i) {
9351 wpa_printf(MSG_DEBUG,
9352 "test data: RX - ignore mismatching payload");
9353 return;
9354 }
9355 pos++;
9356 }
9357 extra[0] = '\0';
Hai Shalomfdcde762020-04-02 11:19:20 -07009358 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
9359 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
Hai Shalom74f70d42019-02-11 14:42:39 -08009360 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
9361 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009362}
9363
9364
9365static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
9366 char *cmd)
9367{
9368 int enabled = atoi(cmd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009369 char *pos;
9370 const char *ifname;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009371
9372 if (!enabled) {
9373 if (wpa_s->l2_test) {
9374 l2_packet_deinit(wpa_s->l2_test);
9375 wpa_s->l2_test = NULL;
9376 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
9377 }
9378 return 0;
9379 }
9380
9381 if (wpa_s->l2_test)
9382 return 0;
9383
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009384 pos = os_strstr(cmd, " ifname=");
9385 if (pos)
9386 ifname = pos + 8;
9387 else
9388 ifname = wpa_s->ifname;
9389
9390 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009391 ETHERTYPE_IP, wpas_data_test_rx,
9392 wpa_s, 1);
9393 if (wpa_s->l2_test == NULL)
9394 return -1;
9395
9396 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
9397
9398 return 0;
9399}
9400
9401
9402static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
9403{
9404 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom74f70d42019-02-11 14:42:39 -08009405 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009406 int used;
9407 long int val;
9408 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009409 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009410 struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07009411 struct ip *ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009412 u8 *dpos;
9413 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08009414 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009415
9416 if (wpa_s->l2_test == NULL)
9417 return -1;
9418
Hai Shalom74f70d42019-02-11 14:42:39 -08009419 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009420
9421 pos = cmd;
9422 used = hwaddr_aton2(pos, dst);
9423 if (used < 0)
9424 return -1;
9425 pos += used;
9426 while (*pos == ' ')
9427 pos++;
9428 used = hwaddr_aton2(pos, src);
9429 if (used < 0)
9430 return -1;
9431 pos += used;
9432
Hai Shalom74f70d42019-02-11 14:42:39 -08009433 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009434 if (val < 0 || val > 0xff)
9435 return -1;
9436 tos = val;
9437
Hai Shalom74f70d42019-02-11 14:42:39 -08009438 pos = os_strstr(pos2, " len=");
9439 if (pos) {
9440 i = atoi(pos + 5);
9441 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
9442 return -1;
9443 send_len = i;
9444 }
9445
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009446 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009447 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
9448 os_memcpy(eth->ether_shost, src, ETH_ALEN);
9449 eth->ether_type = htons(ETHERTYPE_IP);
Hai Shalomfdcde762020-04-02 11:19:20 -07009450 ip = (struct ip *) (eth + 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009451 os_memset(ip, 0, sizeof(*ip));
Hai Shalomfdcde762020-04-02 11:19:20 -07009452 ip->ip_hl = 5;
9453 ip->ip_v = 4;
9454 ip->ip_ttl = 64;
9455 ip->ip_tos = tos;
9456 ip->ip_len = htons(send_len);
9457 ip->ip_p = 1;
9458 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
9459 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
9460 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009461 dpos = (u8 *) (ip + 1);
Hai Shalom74f70d42019-02-11 14:42:39 -08009462 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009463 *dpos++ = i;
9464
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009465 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom74f70d42019-02-11 14:42:39 -08009466 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009467 return -1;
9468
9469 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
9470 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
9471
9472 return 0;
9473}
9474
9475
9476static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
9477 char *cmd)
9478{
9479 u8 *buf;
9480 struct ether_header *eth;
9481 struct l2_packet_data *l2 = NULL;
9482 size_t len;
9483 u16 ethertype;
9484 int res = -1;
9485
9486 len = os_strlen(cmd);
9487 if (len & 1 || len < ETH_HLEN * 2)
9488 return -1;
9489 len /= 2;
9490
9491 buf = os_malloc(len);
9492 if (buf == NULL)
9493 return -1;
9494
9495 if (hexstr2bin(cmd, buf, len) < 0)
9496 goto done;
9497
9498 eth = (struct ether_header *) buf;
9499 ethertype = ntohs(eth->ether_type);
9500
9501 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
9502 wpas_data_test_rx, wpa_s, 1);
9503 if (l2 == NULL)
9504 goto done;
9505
9506 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
9507 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
9508done:
9509 if (l2)
9510 l2_packet_deinit(l2);
9511 os_free(buf);
9512
9513 return res < 0 ? -1 : 0;
9514}
9515
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009516
9517static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
9518{
9519#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009520 char *pos;
9521
9522 wpa_trace_fail_after = atoi(cmd);
9523 pos = os_strchr(cmd, ':');
9524 if (pos) {
9525 pos++;
9526 os_strlcpy(wpa_trace_fail_func, pos,
9527 sizeof(wpa_trace_fail_func));
9528 } else {
9529 wpa_trace_fail_after = 0;
9530 }
9531 return 0;
9532#else /* WPA_TRACE_BFD */
9533 return -1;
9534#endif /* WPA_TRACE_BFD */
9535}
9536
9537
9538static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
9539 char *buf, size_t buflen)
9540{
9541#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009542 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
9543 wpa_trace_fail_func);
9544#else /* WPA_TRACE_BFD */
9545 return -1;
9546#endif /* WPA_TRACE_BFD */
9547}
9548
Jouni Malinenc4818362015-10-04 11:45:13 +03009549
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009550static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
9551{
9552#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009553 char *pos;
9554
9555 wpa_trace_test_fail_after = atoi(cmd);
9556 pos = os_strchr(cmd, ':');
9557 if (pos) {
9558 pos++;
9559 os_strlcpy(wpa_trace_test_fail_func, pos,
9560 sizeof(wpa_trace_test_fail_func));
9561 } else {
9562 wpa_trace_test_fail_after = 0;
9563 }
9564 return 0;
9565#else /* WPA_TRACE_BFD */
9566 return -1;
9567#endif /* WPA_TRACE_BFD */
9568}
9569
9570
9571static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
9572 char *buf, size_t buflen)
9573{
9574#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009575 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
9576 wpa_trace_test_fail_func);
9577#else /* WPA_TRACE_BFD */
9578 return -1;
9579#endif /* WPA_TRACE_BFD */
9580}
9581
9582
Jouni Malinenc4818362015-10-04 11:45:13 +03009583static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
9584{
9585 struct wpa_supplicant *wpa_s = eloop_ctx;
9586 int i, count = (intptr_t) timeout_ctx;
9587
9588 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
9589 count);
9590 for (i = 0; i < count; i++) {
9591 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
9592 i + 1, count);
9593 }
9594}
9595
9596
9597static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
9598{
9599 int count;
9600
9601 count = atoi(cmd);
9602 if (count <= 0)
9603 return -1;
9604
9605 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
9606 (void *) (intptr_t) count);
9607}
9608
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009609
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009610static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
9611 const char *cmd)
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009612{
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009613 struct wpabuf *buf;
9614 size_t len;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009615
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009616 len = os_strlen(cmd);
9617 if (len & 1)
9618 return -1;
9619 len /= 2;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009620
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009621 if (len == 0) {
9622 buf = NULL;
9623 } else {
9624 buf = wpabuf_alloc(len);
9625 if (buf == NULL)
9626 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009627
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009628 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
9629 wpabuf_free(buf);
9630 return -1;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009631 }
9632 }
9633
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009634 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
9635 return 0;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009636}
9637
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009638
9639static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
9640{
9641 u8 zero[WPA_TK_MAX_LEN];
9642
9643 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
9644 return -1;
9645
9646 wpa_printf(MSG_INFO, "TESTING: Reset PN");
9647 os_memset(zero, 0, sizeof(zero));
9648
9649 /* First, use a zero key to avoid any possible duplicate key avoidance
9650 * in the driver. */
9651 if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9652 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -07009653 zero, wpa_s->last_tk_len,
9654 KEY_FLAG_PAIRWISE_RX_TX) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009655 return -1;
9656
9657 /* Set the previously configured key to reset its TSC/RSC */
9658 return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9659 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -07009660 wpa_s->last_tk, wpa_s->last_tk_len,
9661 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009662}
9663
9664
9665static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
9666{
9667 const char *pos = cmd;
9668 int error, pairwise;
9669
9670 error = atoi(pos);
9671 pos = os_strchr(pos, ' ');
9672 if (!pos)
9673 return -1;
9674 pairwise = atoi(pos);
9675 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
9676 return 0;
9677}
9678
9679
9680static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
9681{
9682#ifdef CONFIG_SME
9683 struct wpa_driver_associate_params params;
9684 int ret;
9685
9686 os_memset(&params, 0, sizeof(params));
9687 params.bssid = wpa_s->bssid;
9688 params.ssid = wpa_s->sme.ssid;
9689 params.ssid_len = wpa_s->sme.ssid_len;
9690 params.freq.freq = wpa_s->sme.freq;
9691 if (wpa_s->last_assoc_req_wpa_ie) {
9692 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
9693 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
9694 }
9695 params.pairwise_suite = wpa_s->pairwise_cipher;
9696 params.group_suite = wpa_s->group_cipher;
9697 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
9698 params.key_mgmt_suite = wpa_s->key_mgmt;
9699 params.wpa_proto = wpa_s->wpa_proto;
9700 params.mgmt_frame_protection = wpa_s->sme.mfp;
9701 params.rrm_used = wpa_s->rrm.rrm_used;
9702 if (wpa_s->sme.prev_bssid_set)
9703 params.prev_bssid = wpa_s->sme.prev_bssid;
9704 wpa_printf(MSG_INFO, "TESTING: Resend association request");
9705 ret = wpa_drv_associate(wpa_s, &params);
9706 wpa_s->testing_resend_assoc = 1;
9707 return ret;
9708#else /* CONFIG_SME */
9709 return -1;
9710#endif /* CONFIG_SME */
9711}
9712
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009713#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009714
9715
9716static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
9717{
9718 char *pos = cmd;
9719 int frame;
9720 size_t len;
9721 struct wpabuf *buf;
9722 struct ieee802_11_elems elems;
9723
9724 frame = atoi(pos);
9725 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9726 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009727 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009728
9729 pos = os_strchr(pos, ' ');
9730 if (pos == NULL)
9731 return -1;
9732 pos++;
9733
9734 len = os_strlen(pos);
9735 if (len == 0)
9736 return 0;
9737 if (len & 1)
9738 return -1;
9739 len /= 2;
9740
9741 buf = wpabuf_alloc(len);
9742 if (buf == NULL)
9743 return -1;
9744
9745 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
9746 wpabuf_free(buf);
9747 return -1;
9748 }
9749
9750 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
9751 ParseFailed) {
9752 wpabuf_free(buf);
9753 return -1;
9754 }
9755
9756 if (wpa_s->vendor_elem[frame] == NULL) {
9757 wpa_s->vendor_elem[frame] = buf;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009758 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009759 return 0;
9760 }
9761
9762 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
9763 wpabuf_free(buf);
9764 return -1;
9765 }
9766
9767 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
9768 wpabuf_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009769 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009770
9771 return 0;
9772}
9773
9774
9775static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
9776 char *buf, size_t buflen)
9777{
9778 int frame = atoi(cmd);
9779
9780 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9781 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009782 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009783
9784 if (wpa_s->vendor_elem[frame] == NULL)
9785 return 0;
9786
9787 return wpa_snprintf_hex(buf, buflen,
9788 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
9789 wpabuf_len(wpa_s->vendor_elem[frame]));
9790}
9791
9792
9793static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
9794{
9795 char *pos = cmd;
9796 int frame;
9797 size_t len;
9798 u8 *buf;
9799 struct ieee802_11_elems elems;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009800 int res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009801
9802 frame = atoi(pos);
9803 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9804 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009805 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009806
9807 pos = os_strchr(pos, ' ');
9808 if (pos == NULL)
9809 return -1;
9810 pos++;
9811
9812 if (*pos == '*') {
9813 wpabuf_free(wpa_s->vendor_elem[frame]);
9814 wpa_s->vendor_elem[frame] = NULL;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009815 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009816 return 0;
9817 }
9818
9819 if (wpa_s->vendor_elem[frame] == NULL)
9820 return -1;
9821
9822 len = os_strlen(pos);
9823 if (len == 0)
9824 return 0;
9825 if (len & 1)
9826 return -1;
9827 len /= 2;
9828
9829 buf = os_malloc(len);
9830 if (buf == NULL)
9831 return -1;
9832
9833 if (hexstr2bin(pos, buf, len) < 0) {
9834 os_free(buf);
9835 return -1;
9836 }
9837
9838 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
9839 os_free(buf);
9840 return -1;
9841 }
9842
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009843 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009844 os_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009845 return res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009846}
9847
9848
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009849static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
9850{
9851 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009852 size_t len;
9853 const u8 *data;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009854
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009855 /*
9856 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9857 * BSSID[6]
9858 * BSSID Information[4]
9859 * Operating Class[1]
9860 * Channel Number[1]
9861 * PHY Type[1]
9862 * Optional Subelements[variable]
9863 */
9864#define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9865
9866 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009867 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009868 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009869 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009870
9871 data = wpabuf_head_u8(neighbor_rep);
9872 len = wpabuf_len(neighbor_rep);
9873
9874 while (len >= 2 + NR_IE_MIN_LEN) {
9875 const u8 *nr;
9876 char lci[256 * 2 + 1];
9877 char civic[256 * 2 + 1];
9878 u8 nr_len = data[1];
9879 const u8 *pos = data, *end;
9880
9881 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
9882 nr_len < NR_IE_MIN_LEN) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08009883 wpa_dbg(wpa_s, MSG_DEBUG,
9884 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9885 data[0], nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009886 goto out;
9887 }
9888
9889 if (2U + nr_len > len) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08009890 wpa_dbg(wpa_s, MSG_DEBUG,
9891 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9892 data[0], len, nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009893 goto out;
9894 }
9895 pos += 2;
9896 end = pos + nr_len;
9897
9898 nr = pos;
9899 pos += NR_IE_MIN_LEN;
9900
9901 lci[0] = '\0';
9902 civic[0] = '\0';
9903 while (end - pos > 2) {
9904 u8 s_id, s_len;
9905
9906 s_id = *pos++;
9907 s_len = *pos++;
9908 if (s_len > end - pos)
9909 goto out;
9910 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
9911 /* Measurement Token[1] */
9912 /* Measurement Report Mode[1] */
9913 /* Measurement Type[1] */
9914 /* Measurement Report[variable] */
9915 switch (pos[2]) {
9916 case MEASURE_TYPE_LCI:
9917 if (lci[0])
9918 break;
9919 wpa_snprintf_hex(lci, sizeof(lci),
9920 pos, s_len);
9921 break;
9922 case MEASURE_TYPE_LOCATION_CIVIC:
9923 if (civic[0])
9924 break;
9925 wpa_snprintf_hex(civic, sizeof(civic),
9926 pos, s_len);
9927 break;
9928 }
9929 }
9930
9931 pos += s_len;
9932 }
9933
9934 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
9935 "bssid=" MACSTR
9936 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9937 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
9938 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
9939 nr[ETH_ALEN + 6],
9940 lci[0] ? " lci=" : "", lci,
9941 civic[0] ? " civic=" : "", civic);
9942
9943 data = end;
9944 len -= 2 + nr_len;
9945 }
9946
9947out:
9948 wpabuf_free(neighbor_rep);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009949}
9950
9951
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009952static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
9953 char *cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009954{
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009955 struct wpa_ssid_value ssid, *ssid_p = NULL;
9956 int ret, lci = 0, civic = 0;
9957 char *ssid_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009958
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009959 ssid_s = os_strstr(cmd, "ssid=");
9960 if (ssid_s) {
9961 if (ssid_parse(ssid_s + 5, &ssid)) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08009962 wpa_msg(wpa_s, MSG_INFO,
9963 "CTRL: Send Neighbor Report: bad SSID");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009964 return -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009965 }
9966
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009967 ssid_p = &ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009968
9969 /*
9970 * Move cmd after the SSID text that may include "lci" or
9971 * "civic".
9972 */
9973 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
9974 if (cmd)
9975 cmd++;
9976
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009977 }
9978
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009979 if (cmd && os_strstr(cmd, "lci"))
9980 lci = 1;
9981
9982 if (cmd && os_strstr(cmd, "civic"))
9983 civic = 1;
9984
9985 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009986 wpas_ctrl_neighbor_rep_cb,
9987 wpa_s);
9988
9989 return ret;
9990}
9991
9992
9993static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
9994{
9995 eapol_sm_erp_flush(wpa_s->eapol);
9996 return 0;
9997}
9998
9999
10000static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
10001 char *cmd)
10002{
10003 char *token, *context = NULL;
10004 unsigned int enable = ~0, type = 0;
10005 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
10006 u8 *addr = NULL, *mask = NULL;
10007
10008 while ((token = str_token(cmd, " ", &context))) {
10009 if (os_strcasecmp(token, "scan") == 0) {
10010 type |= MAC_ADDR_RAND_SCAN;
10011 } else if (os_strcasecmp(token, "sched") == 0) {
10012 type |= MAC_ADDR_RAND_SCHED_SCAN;
10013 } else if (os_strcasecmp(token, "pno") == 0) {
10014 type |= MAC_ADDR_RAND_PNO;
10015 } else if (os_strcasecmp(token, "all") == 0) {
10016 type = wpa_s->mac_addr_rand_supported;
10017 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
10018 enable = atoi(token + 7);
10019 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
10020 addr = _addr;
10021 if (hwaddr_aton(token + 5, addr)) {
10022 wpa_printf(MSG_INFO,
10023 "CTRL: Invalid MAC address: %s",
10024 token);
10025 return -1;
10026 }
10027 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
10028 mask = _mask;
10029 if (hwaddr_aton(token + 5, mask)) {
10030 wpa_printf(MSG_INFO,
10031 "CTRL: Invalid MAC address mask: %s",
10032 token);
10033 return -1;
10034 }
10035 } else {
10036 wpa_printf(MSG_INFO,
10037 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
10038 token);
10039 return -1;
10040 }
10041 }
10042
10043 if (!type) {
10044 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
10045 return -1;
10046 }
10047
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010048 if (enable > 1) {
10049 wpa_printf(MSG_INFO,
10050 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
10051 return -1;
10052 }
10053
Hai Shalom81f62d82019-07-22 12:10:00 -070010054 if (!enable)
10055 return wpas_disable_mac_addr_randomization(wpa_s, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010056
Hai Shalom81f62d82019-07-22 12:10:00 -070010057 return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010058}
10059
10060
Dmitry Shmidte4663042016-04-04 10:07:49 -070010061static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
10062 char *buf, size_t buflen)
10063{
10064 size_t reply_len;
10065
10066 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
10067#ifdef CONFIG_AP
10068 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
10069 buflen - reply_len);
10070#endif /* CONFIG_AP */
10071 return reply_len;
10072}
10073
10074
10075static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
10076{
10077 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
10078#ifdef CONFIG_AP
10079 wpas_ap_pmksa_cache_flush(wpa_s);
10080#endif /* CONFIG_AP */
10081}
10082
10083
Dmitry Shmidt29333592017-01-09 12:27:11 -080010084#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10085
10086static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
10087 const char *cmd, char *buf, size_t buflen)
10088{
10089 struct rsn_pmksa_cache_entry *entry;
10090 struct wpa_ssid *ssid;
10091 char *pos, *pos2, *end;
10092 int ret;
10093 struct os_reltime now;
10094
10095 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10096 if (!ssid)
10097 return -1;
10098
10099 pos = buf;
10100 end = buf + buflen;
10101
10102 os_get_reltime(&now);
10103
10104 /*
10105 * Entry format:
10106 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10107 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010108 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010109 */
10110
10111 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
10112 entry = entry->next) {
10113 if (entry->network_ctx != ssid)
10114 continue;
10115
10116 pos2 = pos;
10117 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
10118 MAC2STR(entry->aa));
10119 if (os_snprintf_error(end - pos2, ret))
10120 break;
10121 pos2 += ret;
10122
10123 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
10124 PMKID_LEN);
10125
10126 ret = os_snprintf(pos2, end - pos2, " ");
10127 if (os_snprintf_error(end - pos2, ret))
10128 break;
10129 pos2 += ret;
10130
10131 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
10132 entry->pmk_len);
10133
10134 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
10135 (int) (entry->reauth_time - now.sec),
10136 (int) (entry->expiration - now.sec),
10137 entry->akmp,
10138 entry->opportunistic);
10139 if (os_snprintf_error(end - pos2, ret))
10140 break;
10141 pos2 += ret;
10142
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010143 if (entry->fils_cache_id_set) {
10144 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
10145 entry->fils_cache_id[0],
10146 entry->fils_cache_id[1]);
10147 if (os_snprintf_error(end - pos2, ret))
10148 break;
10149 pos2 += ret;
10150 }
10151
Dmitry Shmidt29333592017-01-09 12:27:11 -080010152 ret = os_snprintf(pos2, end - pos2, "\n");
10153 if (os_snprintf_error(end - pos2, ret))
10154 break;
10155 pos2 += ret;
10156
10157 pos = pos2;
10158 }
10159
10160 return pos - buf;
10161}
10162
10163
10164static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
10165 char *cmd)
10166{
10167 struct rsn_pmksa_cache_entry *entry;
10168 struct wpa_ssid *ssid;
10169 char *pos, *pos2;
10170 int ret = -1;
10171 struct os_reltime now;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010172 int reauth_time = 0, expiration = 0, i;
Dmitry Shmidt29333592017-01-09 12:27:11 -080010173
10174 /*
10175 * Entry format:
10176 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
10177 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010178 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -080010179 */
10180
10181 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
10182 if (!ssid)
10183 return -1;
10184
10185 pos = os_strchr(cmd, ' ');
10186 if (!pos)
10187 return -1;
10188 pos++;
10189
10190 entry = os_zalloc(sizeof(*entry));
10191 if (!entry)
10192 return -1;
10193
10194 if (hwaddr_aton(pos, entry->aa))
10195 goto fail;
10196
10197 pos = os_strchr(pos, ' ');
10198 if (!pos)
10199 goto fail;
10200 pos++;
10201
10202 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
10203 goto fail;
10204
10205 pos = os_strchr(pos, ' ');
10206 if (!pos)
10207 goto fail;
10208 pos++;
10209
10210 pos2 = os_strchr(pos, ' ');
10211 if (!pos2)
10212 goto fail;
10213 entry->pmk_len = (pos2 - pos) / 2;
10214 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
10215 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
10216 goto fail;
10217
10218 pos = os_strchr(pos, ' ');
10219 if (!pos)
10220 goto fail;
10221 pos++;
10222
10223 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
10224 &entry->akmp, &entry->opportunistic) != 4)
10225 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010226 for (i = 0; i < 4; i++) {
10227 pos = os_strchr(pos, ' ');
10228 if (!pos) {
10229 if (i < 3)
10230 goto fail;
10231 break;
10232 }
10233 pos++;
10234 }
10235 if (pos) {
10236 if (hexstr2bin(pos, entry->fils_cache_id,
10237 FILS_CACHE_ID_LEN) < 0)
10238 goto fail;
10239 entry->fils_cache_id_set = 1;
10240 }
Dmitry Shmidt29333592017-01-09 12:27:11 -080010241 os_get_reltime(&now);
10242 entry->expiration = now.sec + expiration;
10243 entry->reauth_time = now.sec + reauth_time;
10244
10245 entry->network_ctx = ssid;
10246
10247 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
10248 entry = NULL;
10249 ret = 0;
10250fail:
10251 os_free(entry);
10252 return ret;
10253}
10254
Paul Stewart092955c2017-02-06 09:13:09 -080010255
10256#ifdef CONFIG_MESH
10257
10258static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
10259 const char *cmd, char *buf,
10260 size_t buflen)
10261{
10262 u8 spa[ETH_ALEN];
10263
10264 if (!wpa_s->ifmsh)
10265 return -1;
10266
10267 if (os_strcasecmp(cmd, "any") == 0)
10268 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
10269
10270 if (hwaddr_aton(cmd, spa))
10271 return -1;
10272
10273 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
10274}
10275
10276
10277static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
10278 char *cmd)
10279{
10280 /*
10281 * We do not check mesh interface existance because PMKSA should be
10282 * stored before wpa_s->ifmsh creation to suppress commit message
10283 * creation.
10284 */
10285 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
10286}
10287
10288#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080010289#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10290
10291
Paul Stewart092955c2017-02-06 09:13:09 -080010292#ifdef CONFIG_FILS
10293static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
10294 const char *cmd)
10295{
10296 struct fils_hlp_req *req;
10297 const char *pos;
10298
10299 /* format: <dst> <packet starting from ethertype> */
10300
10301 req = os_zalloc(sizeof(*req));
10302 if (!req)
10303 return -1;
10304
10305 if (hwaddr_aton(cmd, req->dst))
10306 goto fail;
10307
10308 pos = os_strchr(cmd, ' ');
10309 if (!pos)
10310 goto fail;
10311 pos++;
10312 req->pkt = wpabuf_parse_bin(pos);
10313 if (!req->pkt)
10314 goto fail;
10315
10316 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
10317 return 0;
10318fail:
10319 wpabuf_free(req->pkt);
10320 os_free(req);
10321 return -1;
10322}
10323#endif /* CONFIG_FILS */
10324
10325
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010326static int wpas_ctrl_cmd_debug_level(const char *cmd)
10327{
10328 if (os_strcmp(cmd, "PING") == 0 ||
10329 os_strncmp(cmd, "BSS ", 4) == 0 ||
10330 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
10331 os_strncmp(cmd, "STATUS", 6) == 0 ||
10332 os_strncmp(cmd, "STA ", 4) == 0 ||
10333 os_strncmp(cmd, "STA-", 4) == 0)
10334 return MSG_EXCESSIVE;
10335 return MSG_DEBUG;
10336}
10337
10338
Hai Shalom899fcc72020-10-19 14:38:18 -070010339static int wpas_ctrl_iface_configure_mscs(struct wpa_supplicant *wpa_s,
10340 const char *cmd)
10341{
10342 size_t frame_classifier_len;
10343 const char *pos, *end;
10344 struct robust_av_data *robust_av = &wpa_s->robust_av;
10345 int val;
10346
10347 /*
10348 * format:
10349 * <add|remove|change> [up_bitmap=<hex byte>] [up_limit=<integer>]
10350 * [stream_timeout=<in TUs>] [frame_classifier=<hex bytes>]
10351 */
10352 os_memset(robust_av, 0, sizeof(struct robust_av_data));
10353 if (os_strncmp(cmd, "add ", 4) == 0) {
10354 robust_av->request_type = SCS_REQ_ADD;
10355 } else if (os_strcmp(cmd, "remove") == 0) {
10356 robust_av->request_type = SCS_REQ_REMOVE;
10357 robust_av->valid_config = false;
10358 return wpas_send_mscs_req(wpa_s);
10359 } else if (os_strncmp(cmd, "change ", 7) == 0) {
10360 robust_av->request_type = SCS_REQ_CHANGE;
10361 } else {
10362 return -1;
10363 }
10364
10365 pos = os_strstr(cmd, "up_bitmap=");
10366 if (!pos)
10367 return -1;
10368
10369 val = hex2byte(pos + 10);
10370 if (val < 0)
10371 return -1;
10372 robust_av->up_bitmap = val;
10373
10374 pos = os_strstr(cmd, "up_limit=");
10375 if (!pos)
10376 return -1;
10377
10378 robust_av->up_limit = atoi(pos + 9);
10379
10380 pos = os_strstr(cmd, "stream_timeout=");
10381 if (!pos)
10382 return -1;
10383
10384 robust_av->stream_timeout = atoi(pos + 15);
10385 if (robust_av->stream_timeout == 0)
10386 return -1;
10387
10388 pos = os_strstr(cmd, "frame_classifier=");
10389 if (!pos)
10390 return -1;
10391
10392 pos += 17;
10393 end = os_strchr(pos, ' ');
10394 if (!end)
10395 end = pos + os_strlen(pos);
10396
10397 frame_classifier_len = (end - pos) / 2;
10398 if (frame_classifier_len > sizeof(robust_av->frame_classifier) ||
10399 hexstr2bin(pos, robust_av->frame_classifier, frame_classifier_len))
10400 return -1;
10401
10402 robust_av->frame_classifier_len = frame_classifier_len;
10403 robust_av->valid_config = true;
10404
10405 return wpas_send_mscs_req(wpa_s);
10406}
10407
10408
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010409char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
10410 char *buf, size_t *resp_len)
10411{
10412 char *reply;
10413 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010414 int reply_len;
10415
10416 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010417 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
10418 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
10419 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010420 if (wpa_debug_show_keys)
10421 wpa_dbg(wpa_s, MSG_DEBUG,
10422 "Control interface command '%s'", buf);
10423 else
10424 wpa_dbg(wpa_s, MSG_DEBUG,
10425 "Control interface command '%s [REMOVED]'",
10426 os_strncmp(buf, WPA_CTRL_RSP,
10427 os_strlen(WPA_CTRL_RSP)) == 0 ?
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010428 WPA_CTRL_RSP :
10429 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
10430 "SET_NETWORK" : "key-add"));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010431 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010432 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010433 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
10434 (const u8 *) buf, os_strlen(buf));
10435 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010436 int level = wpas_ctrl_cmd_debug_level(buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -070010437 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010438 }
10439
10440 reply = os_malloc(reply_size);
10441 if (reply == NULL) {
10442 *resp_len = 1;
10443 return NULL;
10444 }
10445
10446 os_memcpy(reply, "OK\n", 3);
10447 reply_len = 3;
10448
10449 if (os_strcmp(buf, "PING") == 0) {
10450 os_memcpy(reply, "PONG\n", 5);
10451 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010452 } else if (os_strcmp(buf, "IFNAME") == 0) {
10453 reply_len = os_strlen(wpa_s->ifname);
10454 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010455 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
10456 if (wpa_debug_reopen_file() < 0)
10457 reply_len = -1;
10458 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
10459 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
10460 } else if (os_strcmp(buf, "MIB") == 0) {
10461 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
10462 if (reply_len >= 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010463 reply_len += eapol_sm_get_mib(wpa_s->eapol,
10464 reply + reply_len,
10465 reply_size - reply_len);
Hai Shalom74f70d42019-02-11 14:42:39 -080010466#ifdef CONFIG_MACSEC
10467 reply_len += ieee802_1x_kay_get_mib(
10468 wpa_s->kay, reply + reply_len,
10469 reply_size - reply_len);
10470#endif /* CONFIG_MACSEC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010471 }
10472 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
10473 reply_len = wpa_supplicant_ctrl_iface_status(
10474 wpa_s, buf + 6, reply, reply_size);
10475 } else if (os_strcmp(buf, "PMKSA") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070010476 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070010477 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070010478 wpas_ctrl_iface_pmksa_flush(wpa_s);
Dmitry Shmidt29333592017-01-09 12:27:11 -080010479#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10480 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
10481 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
10482 reply, reply_size);
10483 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
10484 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
10485 reply_len = -1;
Paul Stewart092955c2017-02-06 09:13:09 -080010486#ifdef CONFIG_MESH
10487 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
10488 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
10489 reply, reply_size);
10490 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
10491 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
10492 reply_len = -1;
10493#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080010494#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010495 } else if (os_strncmp(buf, "SET ", 4) == 0) {
10496 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
10497 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010498 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
10499 reply_len = wpa_config_dump_values(wpa_s->conf,
10500 reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010501 } else if (os_strncmp(buf, "GET ", 4) == 0) {
10502 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
10503 reply, reply_size);
10504 } else if (os_strcmp(buf, "LOGON") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070010505 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010506 } else if (os_strcmp(buf, "LOGOFF") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070010507 eapol_sm_notify_logoff(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010508 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
10509 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
10510 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010511 else
10512 wpas_request_connection(wpa_s);
Dmitry Shmidt98660862014-03-11 17:26:21 -070010513 } else if (os_strcmp(buf, "REATTACH") == 0) {
10514 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
10515 !wpa_s->current_ssid)
10516 reply_len = -1;
10517 else {
10518 wpa_s->reattach = 1;
10519 wpas_request_connection(wpa_s);
10520 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010521 } else if (os_strcmp(buf, "RECONNECT") == 0) {
10522 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
10523 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010524 else if (wpa_s->disconnected)
10525 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010526#ifdef IEEE8021X_EAPOL
10527 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
10528 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
10529 reply_len = -1;
10530#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010531#ifdef CONFIG_IEEE80211R
10532 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
10533 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
10534 reply_len = -1;
10535#endif /* CONFIG_IEEE80211R */
10536#ifdef CONFIG_WPS
10537 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
10538 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
10539 if (res == -2) {
10540 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10541 reply_len = 17;
10542 } else if (res)
10543 reply_len = -1;
10544 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
10545 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
10546 if (res == -2) {
10547 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10548 reply_len = 17;
10549 } else if (res)
10550 reply_len = -1;
10551 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
10552 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
10553 reply,
10554 reply_size);
10555 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
10556 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
10557 wpa_s, buf + 14, reply, reply_size);
10558 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
10559 if (wpas_wps_cancel(wpa_s))
10560 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010561#ifdef CONFIG_WPS_NFC
10562 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
10563 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
10564 reply_len = -1;
10565 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
10566 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
10567 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -080010568 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
10569 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
10570 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010571 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
10572 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
10573 wpa_s, buf + 14, reply, reply_size);
10574 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
10575 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
10576 buf + 17))
10577 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010578 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
10579 reply_len = wpas_ctrl_nfc_get_handover_req(
10580 wpa_s, buf + 21, reply, reply_size);
10581 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
10582 reply_len = wpas_ctrl_nfc_get_handover_sel(
10583 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -080010584 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
10585 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
10586 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010587#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010588 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
10589 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
10590 reply_len = -1;
10591#ifdef CONFIG_AP
10592 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
10593 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
10594 wpa_s, buf + 11, reply, reply_size);
10595#endif /* CONFIG_AP */
10596#ifdef CONFIG_WPS_ER
10597 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
10598 if (wpas_wps_er_start(wpa_s, NULL))
10599 reply_len = -1;
10600 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
10601 if (wpas_wps_er_start(wpa_s, buf + 13))
10602 reply_len = -1;
10603 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010604 wpas_wps_er_stop(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010605 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
10606 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
10607 reply_len = -1;
10608 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
10609 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
10610 if (ret == -2) {
10611 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10612 reply_len = 17;
10613 } else if (ret == -3) {
10614 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
10615 reply_len = 18;
10616 } else if (ret == -4) {
10617 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
10618 reply_len = 20;
10619 } else if (ret)
10620 reply_len = -1;
10621 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
10622 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
10623 reply_len = -1;
10624 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
10625 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
10626 buf + 18))
10627 reply_len = -1;
10628 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
10629 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
10630 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010631#ifdef CONFIG_WPS_NFC
10632 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10633 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10634 wpa_s, buf + 24, reply, reply_size);
10635#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010636#endif /* CONFIG_WPS_ER */
10637#endif /* CONFIG_WPS */
10638#ifdef CONFIG_IBSS_RSN
10639 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
10640 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
10641 reply_len = -1;
10642#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010643#ifdef CONFIG_MESH
10644 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
10645 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10646 wpa_s, buf + 19, reply, reply_size);
10647 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
10648 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10649 wpa_s, "", reply, reply_size);
10650 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
10651 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
10652 reply_len = -1;
10653 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
10654 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
10655 buf + 18))
10656 reply_len = -1;
Dmitry Shmidte4663042016-04-04 10:07:49 -070010657 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
10658 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
10659 reply_len = -1;
10660 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
10661 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
10662 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070010663 } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) {
10664 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16))
10665 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010666#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010667#ifdef CONFIG_P2P
10668 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010669 if (p2p_ctrl_find(wpa_s, buf + 8))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010670 reply_len = -1;
10671 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
10672 if (p2p_ctrl_find(wpa_s, ""))
10673 reply_len = -1;
10674 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
10675 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010676 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
10677 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
10678 reply_len = -1;
10679 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10680 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
10681 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010682 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
10683 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
10684 reply_size);
10685 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
10686 if (p2p_ctrl_listen(wpa_s, buf + 11))
10687 reply_len = -1;
10688 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
10689 if (p2p_ctrl_listen(wpa_s, ""))
10690 reply_len = -1;
10691 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
10692 if (wpas_p2p_group_remove(wpa_s, buf + 17))
10693 reply_len = -1;
10694 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070010695 if (p2p_ctrl_group_add(wpa_s, ""))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010696 reply_len = -1;
10697 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
10698 if (p2p_ctrl_group_add(wpa_s, buf + 14))
10699 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010700 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
10701 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
10702 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010703 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
10704 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
10705 reply_len = -1;
10706 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
10707 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
10708 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
10709 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
10710 reply_size);
10711 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10712 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
10713 reply_len = -1;
10714 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
10715 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
10716 reply_len = -1;
10717 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
10718 wpas_p2p_sd_service_update(wpa_s);
10719 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10720 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
10721 reply_len = -1;
10722 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
10723 wpas_p2p_service_flush(wpa_s);
10724 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
10725 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
10726 reply_len = -1;
10727 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
10728 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
10729 reply_len = -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010730 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
10731 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
10732 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010733 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
10734 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
10735 reply_len = -1;
10736 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
10737 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
10738 reply_len = -1;
10739 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
10740 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
10741 reply_size);
10742 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
10743 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
10744 reply_len = -1;
10745 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -070010746 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010747 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
10748 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
10749 reply_len = -1;
10750 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
10751 if (wpas_p2p_cancel(wpa_s))
10752 reply_len = -1;
10753 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
10754 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
10755 reply_len = -1;
10756 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
10757 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
10758 reply_len = -1;
10759 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
10760 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
10761 reply_len = -1;
10762 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
10763 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
10764 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070010765 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
10766 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
10767 reply_len = -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010768 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
10769 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
10770 reply_len = -1;
10771 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
10772 if (wpas_p2p_lo_stop(wpa_s))
10773 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010774#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010775#ifdef CONFIG_WIFI_DISPLAY
10776 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
10777 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
10778 reply_len = -1;
10779 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
10780 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
10781 reply, reply_size);
10782#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010783#ifdef CONFIG_INTERWORKING
10784 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
10785 if (interworking_fetch_anqp(wpa_s) < 0)
10786 reply_len = -1;
10787 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
10788 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010789 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
10790 if (ctrl_interworking_select(wpa_s, NULL) < 0)
10791 reply_len = -1;
10792 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
10793 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010794 reply_len = -1;
10795 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010796 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010797 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010798 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10799 int id;
10800
10801 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
10802 if (id < 0)
10803 reply_len = -1;
10804 else {
10805 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
10806 if (os_snprintf_error(reply_size, reply_len))
10807 reply_len = -1;
10808 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010809 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
10810 if (get_anqp(wpa_s, buf + 9) < 0)
10811 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010812 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
10813 if (gas_request(wpa_s, buf + 12) < 0)
10814 reply_len = -1;
10815 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
10816 reply_len = gas_response_get(wpa_s, buf + 17, reply,
10817 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010818#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -070010819#ifdef CONFIG_HS20
10820 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
10821 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
10822 reply_len = -1;
10823 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10824 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
10825 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010826 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080010827 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
10828 reply_len = -1;
10829 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
10830 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
10831 reply_len = -1;
10832 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
10833 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
10834 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
10835 if (del_hs20_icon(wpa_s, buf + 14) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010836 reply_len = -1;
10837 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010838 if (hs20_fetch_osu(wpa_s, 0) < 0)
10839 reply_len = -1;
10840 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
10841 if (hs20_fetch_osu(wpa_s, 1) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010842 reply_len = -1;
10843 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
10844 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010845#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010846 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
10847 {
10848 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10849 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
10850 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -070010851 else {
10852 /*
10853 * Notify response from timeout to allow the control
10854 * interface response to be sent first.
10855 */
10856 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
10857 wpa_s, NULL);
10858 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010859 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
10860 if (wpa_supplicant_reload_configuration(wpa_s))
10861 reply_len = -1;
10862 } else if (os_strcmp(buf, "TERMINATE") == 0) {
10863 wpa_supplicant_terminate_proc(wpa_s->global);
10864 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
10865 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
10866 reply_len = -1;
Dmitry Shmidte19501d2011-03-16 14:32:18 -070010867 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010868 reply_len = wpa_supplicant_ctrl_iface_blacklist(
10869 wpa_s, buf + 9, reply, reply_size);
10870 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
10871 reply_len = wpa_supplicant_ctrl_iface_log_level(
10872 wpa_s, buf + 9, reply, reply_size);
Vinit Deshpandeda134e92014-12-02 10:59:29 -080010873 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
10874 reply_len = wpa_supplicant_ctrl_iface_list_networks(
10875 wpa_s, buf + 14, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010876 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
10877 reply_len = wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -080010878 wpa_s, NULL, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010879 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070010880 wpas_request_disconnection(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010881 } else if (os_strcmp(buf, "SCAN") == 0) {
10882 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
10883 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
10884 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010885 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
10886 reply_len = wpa_supplicant_ctrl_iface_scan_results(
10887 wpa_s, reply, reply_size);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010888 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
10889 if (wpas_abort_ongoing_scan(wpa_s) < 0)
10890 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010891 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
10892 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
10893 reply_len = -1;
10894 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
10895 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
10896 reply_len = -1;
10897 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
10898 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
10899 reply_len = -1;
10900 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
10901 reply_len = wpa_supplicant_ctrl_iface_add_network(
10902 wpa_s, reply, reply_size);
10903 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
10904 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
10905 reply_len = -1;
10906 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
10907 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
10908 reply_len = -1;
10909 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
10910 reply_len = wpa_supplicant_ctrl_iface_get_network(
10911 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt684785c2014-05-12 13:34:29 -070010912 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010913 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
10914 wpa_s))
Dmitry Shmidt684785c2014-05-12 13:34:29 -070010915 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010916 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
10917 reply_len = wpa_supplicant_ctrl_iface_list_creds(
10918 wpa_s, reply, reply_size);
10919 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
10920 reply_len = wpa_supplicant_ctrl_iface_add_cred(
10921 wpa_s, reply, reply_size);
10922 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
10923 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
10924 reply_len = -1;
10925 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
10926 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
10927 reply_len = -1;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -070010928 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
10929 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
10930 reply,
10931 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010932#ifndef CONFIG_NO_CONFIG_WRITE
10933 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
10934 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
10935 reply_len = -1;
10936#endif /* CONFIG_NO_CONFIG_WRITE */
10937 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
10938 reply_len = wpa_supplicant_ctrl_iface_get_capability(
10939 wpa_s, buf + 15, reply, reply_size);
10940 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
10941 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
10942 reply_len = -1;
10943 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
10944 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
10945 reply_len = -1;
10946 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
10947 reply_len = wpa_supplicant_global_iface_list(
10948 wpa_s->global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010949 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010950 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010951 wpa_s->global, buf + 10, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010952 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
10953 reply_len = wpa_supplicant_ctrl_iface_bss(
10954 wpa_s, buf + 4, reply, reply_size);
10955#ifdef CONFIG_AP
10956 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
10957 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
10958 } else if (os_strncmp(buf, "STA ", 4) == 0) {
10959 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
10960 reply_size);
10961 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
10962 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
10963 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010964 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
10965 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
10966 reply_len = -1;
10967 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
10968 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
10969 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080010970 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
10971 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
10972 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010973 } else if (os_strcmp(buf, "STOP_AP") == 0) {
10974 if (wpas_ap_stop_ap(wpa_s))
10975 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010976#endif /* CONFIG_AP */
10977 } else if (os_strcmp(buf, "SUSPEND") == 0) {
10978 wpas_notify_suspend(wpa_s->global);
10979 } else if (os_strcmp(buf, "RESUME") == 0) {
10980 wpas_notify_resume(wpa_s->global);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010981#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010982 } else if (os_strcmp(buf, "DROP_SA") == 0) {
10983 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010984#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010985 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
10986 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
10987 reply_len = -1;
10988 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010989 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010990 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
10991 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
10992 reply_len = -1;
10993 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
10994 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
10995 buf + 17))
10996 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -070010997 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010998 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010999#ifdef CONFIG_TDLS
11000 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
11001 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
11002 reply_len = -1;
11003 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
11004 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
11005 reply_len = -1;
11006 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
11007 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
11008 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011009 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
11010 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
11011 buf + 17))
11012 reply_len = -1;
11013 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
11014 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
11015 buf + 24))
11016 reply_len = -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -070011017 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
11018 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
11019 wpa_s, buf + 17, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011020#endif /* CONFIG_TDLS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011021 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
11022 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
11023 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
11024 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
11025 reply_len = -1;
11026 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
11027 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
11028 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011029 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
11030 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
11031 reply_size);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080011032 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
11033 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
11034 reply_len = -1;
Yuhao Zhengfcd6f212012-07-27 10:37:52 -070011035 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
11036 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
11037 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070011038#ifdef CONFIG_AUTOSCAN
11039 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
11040 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
11041 reply_len = -1;
11042#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070011043 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
11044 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
11045 reply_size);
Hai Shalomb755a2a2020-04-23 21:49:02 -070011046 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
11047 reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply,
11048 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080011049#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -070011050 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
11051 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
11052 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080011053#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080011054 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
11055 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
11056 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011057 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080011058 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011059 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080011060#ifdef CONFIG_WNM
11061 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
11062 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
11063 reply_len = -1;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080011064 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
11065 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
Dmitry Shmidt44c95782013-05-17 09:51:35 -070011066 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -080011067 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
11068 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
11069 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080011070#endif /* CONFIG_WNM */
Dmitry Shmidt444d5672013-04-01 13:08:44 -070011071 } else if (os_strcmp(buf, "FLUSH") == 0) {
11072 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080011073 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
11074 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
11075 reply_size);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070011076#ifdef CONFIG_TESTING_OPTIONS
11077 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
11078 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
11079 reply_len = -1;
11080 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
11081 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011082 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
11083 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
11084 reply_len = -1;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -070011085 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
11086 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
11087 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011088 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
11089 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
11090 reply_len = -1;
11091 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
11092 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
11093 reply_len = -1;
11094 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
11095 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
11096 reply_len = -1;
11097 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
11098 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
11099 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -080011100 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
11101 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
11102 reply_len = -1;
11103 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
11104 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011105 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
11106 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
11107 reply_len = -1;
11108 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
11109 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
Jouni Malinenc4818362015-10-04 11:45:13 +030011110 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
11111 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
11112 reply_len = -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080011113 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
11114 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
11115 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011116 } else if (os_strcmp(buf, "RESET_PN") == 0) {
11117 if (wpas_ctrl_reset_pn(wpa_s) < 0)
11118 reply_len = -1;
11119 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
11120 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
11121 reply_len = -1;
11122 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
11123 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
11124 reply_len = -1;
Hai Shalom74f70d42019-02-11 14:42:39 -080011125 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
11126 sme_event_unprot_disconnect(
11127 wpa_s, wpa_s->bssid, NULL,
11128 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070011129#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070011130 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
11131 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
11132 reply_len = -1;
11133 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
11134 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
11135 reply_size);
11136 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
11137 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
11138 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011139 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011140 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011141 reply_len = -1;
11142 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
11143 wpas_ctrl_iface_erp_flush(wpa_s);
11144 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
11145 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
11146 reply_len = -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011147 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
11148 reply_len = wpas_ctrl_iface_get_pref_freq_list(
11149 wpa_s, buf + 19, reply, reply_size);
Paul Stewart092955c2017-02-06 09:13:09 -080011150#ifdef CONFIG_FILS
11151 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
11152 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
11153 reply_len = -1;
11154 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
11155 wpas_flush_fils_hlp_req(wpa_s);
11156#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011157#ifdef CONFIG_DPP
11158 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
11159 int res;
11160
11161 res = wpas_dpp_qr_code(wpa_s, buf + 12);
11162 if (res < 0) {
11163 reply_len = -1;
11164 } else {
11165 reply_len = os_snprintf(reply, reply_size, "%d", res);
11166 if (os_snprintf_error(reply_size, reply_len))
11167 reply_len = -1;
11168 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080011169 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
11170 int res;
11171
11172 res = wpas_dpp_nfc_uri(wpa_s, buf + 12);
11173 if (res < 0) {
11174 reply_len = -1;
11175 } else {
11176 reply_len = os_snprintf(reply, reply_size, "%d", res);
11177 if (os_snprintf_error(reply_size, reply_len))
11178 reply_len = -1;
11179 }
Hai Shalomfdcde762020-04-02 11:19:20 -070011180 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
11181 int res;
11182
11183 res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20);
11184 if (res < 0) {
11185 reply_len = -1;
11186 } else {
11187 reply_len = os_snprintf(reply, reply_size, "%d", res);
11188 if (os_snprintf_error(reply_size, reply_len))
11189 reply_len = -1;
11190 }
11191 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
11192 int res;
11193
11194 res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20);
11195 if (res < 0) {
11196 reply_len = -1;
11197 } else {
11198 reply_len = os_snprintf(reply, reply_size, "%d", res);
11199 if (os_snprintf_error(reply_size, reply_len))
11200 reply_len = -1;
11201 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011202 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
11203 int res;
11204
Hai Shalom021b0b52019-04-10 11:17:58 -070011205 res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011206 if (res < 0) {
11207 reply_len = -1;
11208 } else {
11209 reply_len = os_snprintf(reply, reply_size, "%d", res);
11210 if (os_snprintf_error(reply_size, reply_len))
11211 reply_len = -1;
11212 }
11213 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070011214 if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011215 reply_len = -1;
11216 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
11217 const char *uri;
11218
Hai Shalom021b0b52019-04-10 11:17:58 -070011219 uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011220 if (!uri) {
11221 reply_len = -1;
11222 } else {
11223 reply_len = os_snprintf(reply, reply_size, "%s", uri);
11224 if (os_snprintf_error(reply_size, reply_len))
11225 reply_len = -1;
11226 }
11227 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070011228 reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19),
11229 reply, reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -070011230 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
11231 if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18),
11232 os_strchr(buf + 18, ' ')) < 0)
11233 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011234 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
11235 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
11236 reply_len = -1;
11237 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
11238 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
11239 reply_len = -1;
11240 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -070011241 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011242 wpas_dpp_listen_stop(wpa_s);
11243 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
11244 int res;
11245
Hai Shalom021b0b52019-04-10 11:17:58 -070011246 res = dpp_configurator_add(wpa_s->dpp, buf + 20);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011247 if (res < 0) {
11248 reply_len = -1;
11249 } else {
11250 reply_len = os_snprintf(reply, reply_size, "%d", res);
11251 if (os_snprintf_error(reply_size, reply_len))
11252 reply_len = -1;
11253 }
11254 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070011255 if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011256 reply_len = -1;
11257 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -080011258 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011259 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -070011260 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070011261 reply_len = dpp_configurator_get_key_id(wpa_s->dpp,
11262 atoi(buf + 25),
11263 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011264 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
11265 int res;
11266
11267 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
11268 if (res < 0) {
11269 reply_len = -1;
11270 } else {
11271 reply_len = os_snprintf(reply, reply_size, "%d", res);
11272 if (os_snprintf_error(reply_size, reply_len))
11273 reply_len = -1;
11274 }
11275 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
11276 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
11277 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070011278#ifdef CONFIG_DPP2
11279 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
11280 if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0)
11281 reply_len = -1;
11282 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
11283 if (wpas_dpp_controller_start(wpa_s, NULL) < 0)
11284 reply_len = -1;
11285 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
11286 dpp_controller_stop(wpa_s->dpp);
Hai Shalomfdcde762020-04-02 11:19:20 -070011287 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
11288 if (wpas_dpp_chirp(wpa_s, buf + 9) < 0)
11289 reply_len = -1;
11290 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
11291 wpas_dpp_chirp_stop(wpa_s);
Hai Shalom4fbc08f2020-05-18 12:37:00 -070011292 } else if (os_strncmp(buf, "DPP_RECONFIG ", 13) == 0) {
Hai Shalom899fcc72020-10-19 14:38:18 -070011293 if (wpas_dpp_reconfig(wpa_s, buf + 13) < 0)
11294 reply_len = -1;
11295 } else if (os_strncmp(buf, "DPP_CA_SET ", 11) == 0) {
11296 if (wpas_dpp_ca_set(wpa_s, buf + 10) < 0)
Hai Shalom4fbc08f2020-05-18 12:37:00 -070011297 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070011298#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011299#endif /* CONFIG_DPP */
Hai Shalom899fcc72020-10-19 14:38:18 -070011300 } else if (os_strncmp(buf, "MSCS ", 5) == 0) {
11301 if (wpas_ctrl_iface_configure_mscs(wpa_s, buf + 5))
11302 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011303 } else {
11304 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
11305 reply_len = 16;
11306 }
11307
11308 if (reply_len < 0) {
11309 os_memcpy(reply, "FAIL\n", 5);
11310 reply_len = 5;
11311 }
11312
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011313 *resp_len = reply_len;
11314 return reply;
11315}
11316
11317
11318static int wpa_supplicant_global_iface_add(struct wpa_global *global,
11319 char *cmd)
11320{
11321 struct wpa_interface iface;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011322 char *pos, *extra;
11323 struct wpa_supplicant *wpa_s;
11324 unsigned int create_iface = 0;
11325 u8 mac_addr[ETH_ALEN];
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011326 enum wpa_driver_if_type type = WPA_IF_STATION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011327
11328 /*
11329 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011330 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011331 */
11332 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
11333
11334 os_memset(&iface, 0, sizeof(iface));
11335
11336 do {
11337 iface.ifname = pos = cmd;
11338 pos = os_strchr(pos, '\t');
11339 if (pos)
11340 *pos++ = '\0';
11341 if (iface.ifname[0] == '\0')
11342 return -1;
11343 if (pos == NULL)
11344 break;
11345
11346 iface.confname = pos;
11347 pos = os_strchr(pos, '\t');
11348 if (pos)
11349 *pos++ = '\0';
11350 if (iface.confname[0] == '\0')
11351 iface.confname = NULL;
11352 if (pos == NULL)
11353 break;
11354
11355 iface.driver = pos;
11356 pos = os_strchr(pos, '\t');
11357 if (pos)
11358 *pos++ = '\0';
11359 if (iface.driver[0] == '\0')
11360 iface.driver = NULL;
11361 if (pos == NULL)
11362 break;
11363
11364 iface.ctrl_interface = pos;
11365 pos = os_strchr(pos, '\t');
11366 if (pos)
11367 *pos++ = '\0';
11368 if (iface.ctrl_interface[0] == '\0')
11369 iface.ctrl_interface = NULL;
11370 if (pos == NULL)
11371 break;
11372
11373 iface.driver_param = pos;
11374 pos = os_strchr(pos, '\t');
11375 if (pos)
11376 *pos++ = '\0';
11377 if (iface.driver_param[0] == '\0')
11378 iface.driver_param = NULL;
11379 if (pos == NULL)
11380 break;
11381
11382 iface.bridge_ifname = pos;
11383 pos = os_strchr(pos, '\t');
11384 if (pos)
11385 *pos++ = '\0';
11386 if (iface.bridge_ifname[0] == '\0')
11387 iface.bridge_ifname = NULL;
11388 if (pos == NULL)
11389 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011390
11391 extra = pos;
11392 pos = os_strchr(pos, '\t');
11393 if (pos)
11394 *pos++ = '\0';
Dmitry Shmidt83474442015-04-15 13:47:09 -070011395 if (!extra[0])
11396 break;
11397
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011398 if (os_strcmp(extra, "create") == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011399 create_iface = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011400 if (!pos)
11401 break;
11402
11403 if (os_strcmp(pos, "sta") == 0) {
11404 type = WPA_IF_STATION;
11405 } else if (os_strcmp(pos, "ap") == 0) {
11406 type = WPA_IF_AP_BSS;
11407 } else {
11408 wpa_printf(MSG_DEBUG,
11409 "INTERFACE_ADD unsupported interface type: '%s'",
11410 pos);
11411 return -1;
11412 }
11413 } else {
Dmitry Shmidt83474442015-04-15 13:47:09 -070011414 wpa_printf(MSG_DEBUG,
11415 "INTERFACE_ADD unsupported extra parameter: '%s'",
11416 extra);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011417 return -1;
Dmitry Shmidt83474442015-04-15 13:47:09 -070011418 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011419 } while (0);
11420
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011421 if (create_iface) {
11422 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
11423 iface.ifname);
11424 if (!global->ifaces)
11425 return -1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011426 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011427 NULL, NULL, NULL, mac_addr, NULL) < 0) {
11428 wpa_printf(MSG_ERROR,
11429 "CTRL_IFACE interface creation failed");
11430 return -1;
11431 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011432
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011433 wpa_printf(MSG_DEBUG,
11434 "CTRL_IFACE interface '%s' created with MAC addr: "
11435 MACSTR, iface.ifname, MAC2STR(mac_addr));
11436 }
11437
11438 if (wpa_supplicant_get_iface(global, iface.ifname))
11439 goto fail;
11440
11441 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
11442 if (!wpa_s)
11443 goto fail;
11444 wpa_s->added_vif = create_iface;
11445 return 0;
11446
11447fail:
11448 if (create_iface)
11449 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
11450 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011451}
11452
11453
11454static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
11455 char *cmd)
11456{
11457 struct wpa_supplicant *wpa_s;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011458 int ret;
11459 unsigned int delete_iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011460
11461 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
11462
11463 wpa_s = wpa_supplicant_get_iface(global, cmd);
11464 if (wpa_s == NULL)
11465 return -1;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011466 delete_iface = wpa_s->added_vif;
11467 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
11468 if (!ret && delete_iface) {
11469 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
11470 cmd);
11471 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
11472 }
11473 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011474}
11475
11476
11477static void wpa_free_iface_info(struct wpa_interface_info *iface)
11478{
11479 struct wpa_interface_info *prev;
11480
11481 while (iface) {
11482 prev = iface;
11483 iface = iface->next;
11484
11485 os_free(prev->ifname);
11486 os_free(prev->desc);
11487 os_free(prev);
11488 }
11489}
11490
11491
11492static int wpa_supplicant_global_iface_list(struct wpa_global *global,
11493 char *buf, int len)
11494{
11495 int i, res;
11496 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
11497 char *pos, *end;
11498
11499 for (i = 0; wpa_drivers[i]; i++) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070011500 const struct wpa_driver_ops *drv = wpa_drivers[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011501 if (drv->get_interfaces == NULL)
11502 continue;
11503 tmp = drv->get_interfaces(global->drv_priv[i]);
11504 if (tmp == NULL)
11505 continue;
11506
11507 if (last == NULL)
11508 iface = last = tmp;
11509 else
11510 last->next = tmp;
11511 while (last->next)
11512 last = last->next;
11513 }
11514
11515 pos = buf;
11516 end = buf + len;
11517 for (tmp = iface; tmp; tmp = tmp->next) {
11518 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
11519 tmp->drv_name, tmp->ifname,
11520 tmp->desc ? tmp->desc : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011521 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011522 *pos = '\0';
11523 break;
11524 }
11525 pos += res;
11526 }
11527
11528 wpa_free_iface_info(iface);
11529
11530 return pos - buf;
11531}
11532
11533
11534static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011535 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011536 char *buf, int len)
11537{
11538 int res;
11539 char *pos, *end;
11540 struct wpa_supplicant *wpa_s;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011541 int show_ctrl = 0;
11542
11543 if (input)
11544 show_ctrl = !!os_strstr(input, "ctrl");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011545
11546 wpa_s = global->ifaces;
11547 pos = buf;
11548 end = buf + len;
11549
11550 while (wpa_s) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011551 if (show_ctrl)
11552 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
11553 wpa_s->ifname,
11554 wpa_s->conf->ctrl_interface ?
11555 wpa_s->conf->ctrl_interface : "N/A");
11556 else
11557 res = os_snprintf(pos, end - pos, "%s\n",
11558 wpa_s->ifname);
11559
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011560 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011561 *pos = '\0';
11562 break;
11563 }
11564 pos += res;
11565 wpa_s = wpa_s->next;
11566 }
11567 return pos - buf;
11568}
11569
11570
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011571static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
11572 const char *ifname,
11573 char *cmd, size_t *resp_len)
11574{
11575 struct wpa_supplicant *wpa_s;
11576
11577 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11578 if (os_strcmp(ifname, wpa_s->ifname) == 0)
11579 break;
11580 }
11581
11582 if (wpa_s == NULL) {
11583 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
11584 if (resp)
11585 *resp_len = os_strlen(resp);
11586 else
11587 *resp_len = 1;
11588 return resp;
11589 }
11590
11591 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
11592}
11593
11594
11595static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
11596 char *buf, size_t *resp_len)
11597{
11598#ifdef CONFIG_P2P
11599 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011600 "LIST_NETWORKS",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011601 "P2P_FIND",
11602 "P2P_STOP_FIND",
11603 "P2P_LISTEN",
11604 "P2P_GROUP_ADD",
11605 "P2P_GET_PASSPHRASE",
11606 "P2P_SERVICE_UPDATE",
11607 "P2P_SERVICE_FLUSH",
11608 "P2P_FLUSH",
11609 "P2P_CANCEL",
11610 "P2P_PRESENCE_REQ",
11611 "P2P_EXT_LISTEN",
Paul Stewart092955c2017-02-06 09:13:09 -080011612#ifdef CONFIG_AP
11613 "STA-FIRST",
11614#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011615 NULL
11616 };
11617 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080011618#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011619 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080011620#endif /* ANDROID */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011621 "GET_CAPABILITY ",
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011622 "GET_NETWORK ",
11623 "REMOVE_NETWORK ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011624 "P2P_FIND ",
11625 "P2P_CONNECT ",
11626 "P2P_LISTEN ",
11627 "P2P_GROUP_REMOVE ",
11628 "P2P_GROUP_ADD ",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011629 "P2P_GROUP_MEMBER ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011630 "P2P_PROV_DISC ",
11631 "P2P_SERV_DISC_REQ ",
11632 "P2P_SERV_DISC_CANCEL_REQ ",
11633 "P2P_SERV_DISC_RESP ",
11634 "P2P_SERV_DISC_EXTERNAL ",
11635 "P2P_SERVICE_ADD ",
11636 "P2P_SERVICE_DEL ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011637 "P2P_SERVICE_REP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011638 "P2P_REJECT ",
11639 "P2P_INVITE ",
11640 "P2P_PEER ",
11641 "P2P_SET ",
11642 "P2P_UNAUTHORIZE ",
11643 "P2P_PRESENCE_REQ ",
11644 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070011645 "P2P_REMOVE_CLIENT ",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080011646 "WPS_NFC_TOKEN ",
11647 "WPS_NFC_TAG_READ ",
Dmitry Shmidt413dde72014-04-11 10:23:22 -070011648 "NFC_GET_HANDOVER_SEL ",
11649 "NFC_GET_HANDOVER_REQ ",
11650 "NFC_REPORT_HANDOVER ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011651 "P2P_ASP_PROVISION ",
11652 "P2P_ASP_PROVISION_RESP ",
Paul Stewart092955c2017-02-06 09:13:09 -080011653#ifdef CONFIG_AP
11654 "STA ",
11655 "STA-NEXT ",
11656#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011657 NULL
11658 };
11659 int found = 0;
11660 int i;
11661
11662 if (global->p2p_init_wpa_s == NULL)
11663 return NULL;
11664
11665 for (i = 0; !found && cmd[i]; i++) {
11666 if (os_strcmp(buf, cmd[i]) == 0)
11667 found = 1;
11668 }
11669
11670 for (i = 0; !found && prefix[i]; i++) {
11671 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
11672 found = 1;
11673 }
11674
11675 if (found)
11676 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11677 buf, resp_len);
11678#endif /* CONFIG_P2P */
11679 return NULL;
11680}
11681
11682
11683static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
11684 char *buf, size_t *resp_len)
11685{
11686#ifdef CONFIG_WIFI_DISPLAY
11687 if (global->p2p_init_wpa_s == NULL)
11688 return NULL;
11689 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
11690 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
11691 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11692 buf, resp_len);
11693#endif /* CONFIG_WIFI_DISPLAY */
11694 return NULL;
11695}
11696
11697
11698static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
11699 char *buf, size_t *resp_len)
11700{
11701 char *ret;
11702
11703 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
11704 if (ret)
11705 return ret;
11706
11707 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
11708 if (ret)
11709 return ret;
11710
11711 return NULL;
11712}
11713
11714
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011715static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
11716{
11717 char *value;
11718
11719 value = os_strchr(cmd, ' ');
11720 if (value == NULL)
11721 return -1;
11722 *value++ = '\0';
11723
11724 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
11725
11726#ifdef CONFIG_WIFI_DISPLAY
11727 if (os_strcasecmp(cmd, "wifi_display") == 0) {
11728 wifi_display_enable(global, !!atoi(value));
11729 return 0;
11730 }
11731#endif /* CONFIG_WIFI_DISPLAY */
11732
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011733 /* Restore cmd to its original value to allow redirection */
11734 value[-1] = ' ';
11735
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011736 return -1;
11737}
11738
11739
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011740static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
11741 char *cmd)
11742{
11743 struct wpa_supplicant *wpa_s[2]; /* src, dst */
11744 char *p;
11745 unsigned int i;
11746
11747 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11748 * <variable name> */
11749
11750 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
11751 p = os_strchr(cmd, ' ');
11752 if (p == NULL)
11753 return -1;
11754 *p = '\0';
11755
11756 wpa_s[i] = global->ifaces;
11757 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
11758 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
11759 break;
11760 }
11761
11762 if (!wpa_s[i]) {
11763 wpa_printf(MSG_DEBUG,
11764 "CTRL_IFACE: Could not find iface=%s", cmd);
11765 return -1;
11766 }
11767
11768 cmd = p + 1;
11769 }
11770
11771 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
11772}
11773
11774
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011775#ifndef CONFIG_NO_CONFIG_WRITE
11776static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
11777{
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011778 int ret = 0, saved = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011779 struct wpa_supplicant *wpa_s;
11780
11781 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11782 if (!wpa_s->conf->update_config) {
11783 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11784 continue;
11785 }
11786
11787 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
11788 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11789 ret = 1;
11790 } else {
11791 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011792 saved++;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011793 }
11794 }
11795
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011796 if (!saved && !ret) {
11797 wpa_dbg(wpa_s, MSG_DEBUG,
11798 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11799 ret = 1;
11800 }
11801
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011802 return ret;
11803}
11804#endif /* CONFIG_NO_CONFIG_WRITE */
11805
11806
11807static int wpas_global_ctrl_iface_status(struct wpa_global *global,
11808 char *buf, size_t buflen)
11809{
11810 char *pos, *end;
11811 int ret;
11812 struct wpa_supplicant *wpa_s;
11813
11814 pos = buf;
11815 end = buf + buflen;
11816
11817#ifdef CONFIG_P2P
11818 if (global->p2p && !global->p2p_disabled) {
11819 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
11820 "\n"
11821 "p2p_state=%s\n",
11822 MAC2STR(global->p2p_dev_addr),
11823 p2p_get_state_txt(global->p2p));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011824 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011825 return pos - buf;
11826 pos += ret;
11827 } else if (global->p2p) {
11828 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011829 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011830 return pos - buf;
11831 pos += ret;
11832 }
11833#endif /* CONFIG_P2P */
11834
11835#ifdef CONFIG_WIFI_DISPLAY
11836 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
11837 !!global->wifi_display);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011838 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011839 return pos - buf;
11840 pos += ret;
11841#endif /* CONFIG_WIFI_DISPLAY */
11842
11843 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11844 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
11845 "address=" MACSTR "\n",
11846 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011847 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011848 return pos - buf;
11849 pos += ret;
11850 }
11851
11852 return pos - buf;
11853}
11854
11855
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011856#ifdef CONFIG_FST
11857
11858static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
11859 char *cmd, char *buf,
11860 size_t reply_size)
11861{
11862 char ifname[IFNAMSIZ + 1];
11863 struct fst_iface_cfg cfg;
11864 struct wpa_supplicant *wpa_s;
11865 struct fst_wpa_obj iface_obj;
11866
11867 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
11868 wpa_s = wpa_supplicant_get_iface(global, ifname);
11869 if (wpa_s) {
11870 if (wpa_s->fst) {
11871 wpa_printf(MSG_INFO, "FST: Already attached");
11872 return -1;
11873 }
11874 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
11875 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
11876 &iface_obj, &cfg);
11877 if (wpa_s->fst)
11878 return os_snprintf(buf, reply_size, "OK\n");
11879 }
11880 }
11881
11882 return -1;
11883}
11884
11885
11886static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
11887 char *cmd, char *buf,
11888 size_t reply_size)
11889{
11890 char ifname[IFNAMSIZ + 1];
11891 struct wpa_supplicant *wpa_s;
11892
11893 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
11894 wpa_s = wpa_supplicant_get_iface(global, ifname);
11895 if (wpa_s) {
11896 if (!fst_iface_detach(ifname)) {
11897 wpa_s->fst = NULL;
11898 return os_snprintf(buf, reply_size, "OK\n");
11899 }
11900 }
11901 }
11902
11903 return -1;
11904}
11905
11906#endif /* CONFIG_FST */
11907
11908
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011909char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
11910 char *buf, size_t *resp_len)
11911{
11912 char *reply;
11913 const int reply_size = 2048;
11914 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011915 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011916
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011917 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
11918 char *pos = os_strchr(buf + 7, ' ');
11919 if (pos) {
11920 *pos++ = '\0';
11921 return wpas_global_ctrl_iface_ifname(global,
11922 buf + 7, pos,
11923 resp_len);
11924 }
11925 }
11926
11927 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
11928 if (reply)
11929 return reply;
11930
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011931 if (os_strcmp(buf, "PING") == 0)
11932 level = MSG_EXCESSIVE;
11933 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011934 (const u8 *) buf, os_strlen(buf));
11935
11936 reply = os_malloc(reply_size);
11937 if (reply == NULL) {
11938 *resp_len = 1;
11939 return NULL;
11940 }
11941
11942 os_memcpy(reply, "OK\n", 3);
11943 reply_len = 3;
11944
11945 if (os_strcmp(buf, "PING") == 0) {
11946 os_memcpy(reply, "PONG\n", 5);
11947 reply_len = 5;
11948 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
11949 if (wpa_supplicant_global_iface_add(global, buf + 14))
11950 reply_len = -1;
11951 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
11952 if (wpa_supplicant_global_iface_remove(global, buf + 17))
11953 reply_len = -1;
11954 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
11955 reply_len = wpa_supplicant_global_iface_list(
11956 global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011957 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011958 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011959 global, buf + 10, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011960#ifdef CONFIG_FST
11961 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
11962 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
11963 reply,
11964 reply_size);
11965 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
11966 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
11967 reply,
11968 reply_size);
11969 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
11970 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
11971#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011972 } else if (os_strcmp(buf, "TERMINATE") == 0) {
11973 wpa_supplicant_terminate_proc(global);
11974 } else if (os_strcmp(buf, "SUSPEND") == 0) {
11975 wpas_notify_suspend(global);
11976 } else if (os_strcmp(buf, "RESUME") == 0) {
11977 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011978 } else if (os_strncmp(buf, "SET ", 4) == 0) {
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011979 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
11980#ifdef CONFIG_P2P
11981 if (global->p2p_init_wpa_s) {
11982 os_free(reply);
11983 /* Check if P2P redirection would work for this
11984 * command. */
11985 return wpa_supplicant_ctrl_iface_process(
11986 global->p2p_init_wpa_s,
11987 buf, resp_len);
11988 }
11989#endif /* CONFIG_P2P */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011990 reply_len = -1;
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011991 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011992 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
11993 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
11994 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011995#ifndef CONFIG_NO_CONFIG_WRITE
11996 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
11997 if (wpas_global_ctrl_iface_save_config(global))
11998 reply_len = -1;
11999#endif /* CONFIG_NO_CONFIG_WRITE */
12000 } else if (os_strcmp(buf, "STATUS") == 0) {
12001 reply_len = wpas_global_ctrl_iface_status(global, reply,
12002 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080012003#ifdef CONFIG_MODULE_TESTS
12004 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080012005 if (wpas_module_tests() < 0)
12006 reply_len = -1;
12007#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080012008 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
12009 if (wpa_debug_reopen_file() < 0)
12010 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070012011 } else {
12012 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
12013 reply_len = 16;
12014 }
12015
12016 if (reply_len < 0) {
12017 os_memcpy(reply, "FAIL\n", 5);
12018 reply_len = 5;
12019 }
12020
12021 *resp_len = reply_len;
12022 return reply;
12023}