blob: e0547f16f01f086ea17614a8777088ec96807950 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant / Control interface (shared code for all backends)
Hai Shalom74f70d42019-02-11 14:42:39 -08003 * Copyright (c) 2004-2019, 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;
699#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700700#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700701#ifdef CONFIG_TESTING_OPTIONS
702 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
703 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800704 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
705 wpa_s->ext_eapol_frame_io = !!atoi(value);
706#ifdef CONFIG_AP
707 if (wpa_s->ap_iface) {
708 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
709 wpa_s->ext_eapol_frame_io;
710 }
711#endif /* CONFIG_AP */
712 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
713 wpa_s->extra_roc_dur = atoi(value);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800714 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
715 wpa_s->test_failure = atoi(value);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800716 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
717 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700718 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
719 wpa_s->ignore_auth_resp = !!atoi(value);
720 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
721 wpa_s->ignore_assoc_disallow = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700722 wpa_drv_ignore_assoc_disallow(wpa_s,
723 wpa_s->ignore_assoc_disallow);
Hai Shalomfdcde762020-04-02 11:19:20 -0700724 } else if (os_strcasecmp(cmd, "disable_sa_query") == 0) {
725 wpa_s->disable_sa_query = !!atoi(value);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800726 } else if (os_strcasecmp(cmd, "ignore_sae_h2e_only") == 0) {
727 wpa_s->ignore_sae_h2e_only = !!atoi(value);
728 } else if (os_strcasecmp(cmd, "extra_sae_rejected_groups") == 0) {
729 char *pos;
730
731 os_free(wpa_s->extra_sae_rejected_groups);
732 wpa_s->extra_sae_rejected_groups = NULL;
733 pos = value;
734 while (pos && pos[0]) {
735 int group;
736
737 group = atoi(pos);
738 wpa_printf(MSG_DEBUG,
739 "TESTING: Extra rejection of SAE group %d",
740 group);
741 if (group)
742 int_array_add_unique(
743 &wpa_s->extra_sae_rejected_groups,
744 group);
745 pos = os_strchr(pos, ' ');
746 if (!pos)
747 break;
748 pos++;
749 }
Hai Shalomb755a2a2020-04-23 21:49:02 -0700750 } else if (os_strcasecmp(cmd, "ft_rsnxe_used") == 0) {
751 wpa_s->ft_rsnxe_used = atoi(value);
Hai Shalomfdcde762020-04-02 11:19:20 -0700752 } else if (os_strcasecmp(cmd, "rsne_override_eapol") == 0) {
753 wpabuf_free(wpa_s->rsne_override_eapol);
754 if (os_strcmp(value, "NULL") == 0)
755 wpa_s->rsne_override_eapol = NULL;
756 else
757 wpa_s->rsne_override_eapol = wpabuf_parse_bin(value);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800758 } else if (os_strcasecmp(cmd, "rsnxe_override_assoc") == 0) {
759 wpabuf_free(wpa_s->rsnxe_override_assoc);
760 if (os_strcmp(value, "NULL") == 0)
761 wpa_s->rsnxe_override_assoc = NULL;
762 else
763 wpa_s->rsnxe_override_assoc = wpabuf_parse_bin(value);
764 } else if (os_strcasecmp(cmd, "rsnxe_override_eapol") == 0) {
765 wpabuf_free(wpa_s->rsnxe_override_eapol);
766 if (os_strcmp(value, "NULL") == 0)
767 wpa_s->rsnxe_override_eapol = NULL;
768 else
769 wpa_s->rsnxe_override_eapol = wpabuf_parse_bin(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700770 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
771 wpa_s->reject_btm_req_reason = atoi(value);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800772 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
773 os_free(wpa_s->get_pref_freq_list_override);
774 if (!value[0])
775 wpa_s->get_pref_freq_list_override = NULL;
776 else
777 wpa_s->get_pref_freq_list_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700778 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
779 wpabuf_free(wpa_s->sae_commit_override);
780 if (value[0] == '\0')
781 wpa_s->sae_commit_override = NULL;
782 else
783 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
Hai Shalomfdcde762020-04-02 11:19:20 -0700784 } else if (os_strcasecmp(cmd, "driver_signal_override") == 0) {
785 ret = wpas_ctrl_iface_set_dso(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700786#ifdef CONFIG_DPP
787 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
788 os_free(wpa_s->dpp_config_obj_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700789 if (value[0] == '\0')
790 wpa_s->dpp_config_obj_override = NULL;
791 else
792 wpa_s->dpp_config_obj_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700793 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
794 os_free(wpa_s->dpp_discovery_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700795 if (value[0] == '\0')
796 wpa_s->dpp_discovery_override = NULL;
797 else
798 wpa_s->dpp_discovery_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700799 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
800 os_free(wpa_s->dpp_groups_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700801 if (value[0] == '\0')
802 wpa_s->dpp_groups_override = NULL;
803 else
804 wpa_s->dpp_groups_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700805 } else if (os_strcasecmp(cmd,
806 "dpp_ignore_netaccesskey_mismatch") == 0) {
807 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700808 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
809 dpp_test = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700810#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700811#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700812#ifdef CONFIG_FILS
813 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
814 wpa_s->disable_fils = !!atoi(value);
815 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
816 wpa_supplicant_set_default_scan_ies(wpa_s);
817#endif /* CONFIG_FILS */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700818#ifndef CONFIG_NO_CONFIG_BLOBS
819 } else if (os_strcmp(cmd, "blob") == 0) {
820 ret = wpas_ctrl_set_blob(wpa_s, value);
821#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800822 } else if (os_strcasecmp(cmd, "setband") == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700823 ret = wpas_ctrl_set_band(wpa_s, value);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800824#ifdef CONFIG_MBO
825 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
826 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
Paul Stewart092955c2017-02-06 09:13:09 -0800827 if (ret == 0) {
828 value[-1] = '=';
829 wpa_config_process_global(wpa_s->conf, cmd, -1);
830 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800831 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
832 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700833 } else if (os_strcasecmp(cmd, "oce") == 0) {
834 wpa_s->conf->oce = atoi(value);
835 if (wpa_s->conf->oce) {
836 if ((wpa_s->conf->oce & OCE_STA) &&
837 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
838 wpa_s->enable_oce = OCE_STA;
839
840 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
841 (wpa_s->drv_flags &
842 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
843 /* TODO: Need to add STA-CFON support */
844 wpa_printf(MSG_ERROR,
845 "OCE STA-CFON feature is not yet supported");
846 return -1;
847 }
848 } else {
849 wpa_s->enable_oce = 0;
850 }
851 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800852#endif /* CONFIG_MBO */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700853 } else if (os_strcasecmp(cmd, "lci") == 0) {
854 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800855 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
856 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800857 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
858 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
859 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
860 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
861 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
862 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700863 } else if (os_strcasecmp(cmd, "roaming") == 0) {
864 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800865#ifdef CONFIG_WNM
866 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
867 struct wpabuf *elems;
868
869 elems = wpabuf_parse_bin(value);
870 if (!elems)
871 return -1;
872 wnm_set_coloc_intf_elems(wpa_s, elems);
873#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700874 } else {
875 value[-1] = '=';
876 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
877 if (ret == 0)
878 wpa_supplicant_update_config(wpa_s);
879 }
880
881 return ret;
882}
883
884
885static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
886 char *cmd, char *buf, size_t buflen)
887{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700888 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700889
890 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
891
892 if (os_strcmp(cmd, "version") == 0) {
893 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700894 } else if (os_strcasecmp(cmd, "country") == 0) {
895 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
896 res = os_snprintf(buf, buflen, "%c%c",
897 wpa_s->conf->country[0],
898 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700899#ifdef CONFIG_WIFI_DISPLAY
900 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800901 int enabled;
902 if (wpa_s->global->p2p == NULL ||
903 wpa_s->global->p2p_disabled)
904 enabled = 0;
905 else
906 enabled = wpa_s->global->wifi_display;
907 res = os_snprintf(buf, buflen, "%d", enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700908#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700909#ifdef CONFIG_TESTING_GET_GTK
910 } else if (os_strcmp(cmd, "gtk") == 0) {
911 if (wpa_s->last_gtk_len == 0)
912 return -1;
913 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
914 wpa_s->last_gtk_len);
915 return res;
916#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800917 } else if (os_strcmp(cmd, "tls_library") == 0) {
918 res = tls_get_library_version(buf, buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700919#ifdef CONFIG_TESTING_OPTIONS
920 } else if (os_strcmp(cmd, "anonce") == 0) {
921 return wpa_snprintf_hex(buf, buflen,
922 wpa_sm_get_anonce(wpa_s->wpa),
923 WPA_NONCE_LEN);
Hai Shalomfdcde762020-04-02 11:19:20 -0700924 } else if (os_strcasecmp(cmd, "last_tk_key_idx") == 0) {
925 res = os_snprintf(buf, buflen, "%d", wpa_s->last_tk_key_idx);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700926#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800927 } else {
928 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700929 }
930
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800931 if (os_snprintf_error(buflen, res))
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700932 return -1;
933 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700934}
935
936
937#ifdef IEEE8021X_EAPOL
938static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
939 char *addr)
940{
941 u8 bssid[ETH_ALEN];
942 struct wpa_ssid *ssid = wpa_s->current_ssid;
943
944 if (hwaddr_aton(addr, bssid)) {
945 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
946 "'%s'", addr);
947 return -1;
948 }
949
950 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
951 rsn_preauth_deinit(wpa_s->wpa);
952 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
953 return -1;
954
955 return 0;
956}
957#endif /* IEEE8021X_EAPOL */
958
959
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700960#ifdef CONFIG_TDLS
961
962static int wpa_supplicant_ctrl_iface_tdls_discover(
963 struct wpa_supplicant *wpa_s, char *addr)
964{
965 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800966 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700967
968 if (hwaddr_aton(addr, peer)) {
969 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
970 "address '%s'", addr);
971 return -1;
972 }
973
974 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
975 MAC2STR(peer));
976
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800977 if (wpa_tdls_is_external_setup(wpa_s->wpa))
978 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
979 else
980 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
981
982 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700983}
984
985
986static int wpa_supplicant_ctrl_iface_tdls_setup(
987 struct wpa_supplicant *wpa_s, char *addr)
988{
989 u8 peer[ETH_ALEN];
990 int ret;
991
992 if (hwaddr_aton(addr, peer)) {
993 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
994 "address '%s'", addr);
995 return -1;
996 }
997
998 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
999 MAC2STR(peer));
1000
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001001 if ((wpa_s->conf->tdls_external_control) &&
1002 wpa_tdls_is_external_setup(wpa_s->wpa))
1003 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
1004
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001005 wpa_tdls_remove(wpa_s->wpa, peer);
1006
1007 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1008 ret = wpa_tdls_start(wpa_s->wpa, peer);
1009 else
1010 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001011
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001012 return ret;
1013}
1014
1015
1016static int wpa_supplicant_ctrl_iface_tdls_teardown(
1017 struct wpa_supplicant *wpa_s, char *addr)
1018{
1019 u8 peer[ETH_ALEN];
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001020 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001021
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001022 if (os_strcmp(addr, "*") == 0) {
1023 /* remove everyone */
1024 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
1025 wpa_tdls_teardown_peers(wpa_s->wpa);
1026 return 0;
1027 }
1028
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001029 if (hwaddr_aton(addr, peer)) {
1030 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
1031 "address '%s'", addr);
1032 return -1;
1033 }
1034
1035 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
1036 MAC2STR(peer));
1037
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001038 if ((wpa_s->conf->tdls_external_control) &&
1039 wpa_tdls_is_external_setup(wpa_s->wpa))
1040 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1041
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001042 if (wpa_tdls_is_external_setup(wpa_s->wpa))
1043 ret = wpa_tdls_teardown_link(
1044 wpa_s->wpa, peer,
1045 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
1046 else
1047 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
1048
1049 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001050}
1051
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001052
1053static int ctrl_iface_get_capability_tdls(
1054 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1055{
1056 int ret;
1057
1058 ret = os_snprintf(buf, buflen, "%s\n",
1059 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
1060 (wpa_s->drv_flags &
1061 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
1062 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001063 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001064 return -1;
1065 return ret;
1066}
1067
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001068
1069static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
1070 struct wpa_supplicant *wpa_s, char *cmd)
1071{
1072 u8 peer[ETH_ALEN];
1073 struct hostapd_freq_params freq_params;
1074 u8 oper_class;
1075 char *pos, *end;
1076
1077 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1078 wpa_printf(MSG_INFO,
1079 "tdls_chanswitch: Only supported with external setup");
1080 return -1;
1081 }
1082
1083 os_memset(&freq_params, 0, sizeof(freq_params));
1084
1085 pos = os_strchr(cmd, ' ');
1086 if (pos == NULL)
1087 return -1;
1088 *pos++ = '\0';
1089
1090 oper_class = strtol(pos, &end, 10);
1091 if (pos == end) {
1092 wpa_printf(MSG_INFO,
1093 "tdls_chanswitch: Invalid op class provided");
1094 return -1;
1095 }
1096
1097 pos = end;
1098 freq_params.freq = atoi(pos);
1099 if (freq_params.freq == 0) {
1100 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
1101 return -1;
1102 }
1103
1104#define SET_FREQ_SETTING(str) \
1105 do { \
1106 const char *pos2 = os_strstr(pos, " " #str "="); \
1107 if (pos2) { \
1108 pos2 += sizeof(" " #str "=") - 1; \
1109 freq_params.str = atoi(pos2); \
1110 } \
1111 } while (0)
1112
1113 SET_FREQ_SETTING(center_freq1);
1114 SET_FREQ_SETTING(center_freq2);
1115 SET_FREQ_SETTING(bandwidth);
1116 SET_FREQ_SETTING(sec_channel_offset);
1117#undef SET_FREQ_SETTING
1118
1119 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1120 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1121
1122 if (hwaddr_aton(cmd, peer)) {
1123 wpa_printf(MSG_DEBUG,
1124 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1125 cmd);
1126 return -1;
1127 }
1128
1129 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1130 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1131 MAC2STR(peer), oper_class, freq_params.freq,
1132 freq_params.center_freq1, freq_params.center_freq2,
1133 freq_params.bandwidth, freq_params.sec_channel_offset,
1134 freq_params.ht_enabled ? " HT" : "",
1135 freq_params.vht_enabled ? " VHT" : "");
1136
1137 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1138 &freq_params);
1139}
1140
1141
1142static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1143 struct wpa_supplicant *wpa_s, char *cmd)
1144{
1145 u8 peer[ETH_ALEN];
1146
1147 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1148 wpa_printf(MSG_INFO,
1149 "tdls_chanswitch: Only supported with external setup");
1150 return -1;
1151 }
1152
1153 if (hwaddr_aton(cmd, peer)) {
1154 wpa_printf(MSG_DEBUG,
1155 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1156 cmd);
1157 return -1;
1158 }
1159
1160 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1161 MAC2STR(peer));
1162
1163 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1164}
1165
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07001166
1167static int wpa_supplicant_ctrl_iface_tdls_link_status(
1168 struct wpa_supplicant *wpa_s, const char *addr,
1169 char *buf, size_t buflen)
1170{
1171 u8 peer[ETH_ALEN];
1172 const char *tdls_status;
1173 int ret;
1174
1175 if (hwaddr_aton(addr, peer)) {
1176 wpa_printf(MSG_DEBUG,
1177 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1178 addr);
1179 return -1;
1180 }
1181 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1182 MAC2STR(peer));
1183
1184 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1185 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1186 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1187 if (os_snprintf_error(buflen, ret))
1188 return -1;
1189
1190 return ret;
1191}
1192
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001193#endif /* CONFIG_TDLS */
1194
1195
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001196static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1197{
1198 char *token, *context = NULL;
1199 struct wmm_ac_ts_setup_params params = {
1200 .tsid = 0xff,
1201 .direction = 0xff,
1202 };
1203
1204 while ((token = str_token(cmd, " ", &context))) {
1205 if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
1206 sscanf(token, "up=%i", &params.user_priority) == 1 ||
1207 sscanf(token, "nominal_msdu_size=%i",
1208 &params.nominal_msdu_size) == 1 ||
1209 sscanf(token, "mean_data_rate=%i",
1210 &params.mean_data_rate) == 1 ||
1211 sscanf(token, "min_phy_rate=%i",
1212 &params.minimum_phy_rate) == 1 ||
1213 sscanf(token, "sba=%i",
1214 &params.surplus_bandwidth_allowance) == 1)
1215 continue;
1216
1217 if (os_strcasecmp(token, "downlink") == 0) {
1218 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1219 } else if (os_strcasecmp(token, "uplink") == 0) {
1220 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1221 } else if (os_strcasecmp(token, "bidi") == 0) {
1222 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1223 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1224 params.fixed_nominal_msdu = 1;
1225 } else {
1226 wpa_printf(MSG_DEBUG,
1227 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1228 token);
1229 return -1;
1230 }
1231
1232 }
1233
1234 return wpas_wmm_ac_addts(wpa_s, &params);
1235}
1236
1237
1238static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1239{
1240 u8 tsid = atoi(cmd);
1241
1242 return wpas_wmm_ac_delts(wpa_s, tsid);
1243}
1244
1245
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246#ifdef CONFIG_IEEE80211R
1247static int wpa_supplicant_ctrl_iface_ft_ds(
1248 struct wpa_supplicant *wpa_s, char *addr)
1249{
1250 u8 target_ap[ETH_ALEN];
1251 struct wpa_bss *bss;
1252 const u8 *mdie;
1253
1254 if (hwaddr_aton(addr, target_ap)) {
1255 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1256 "address '%s'", addr);
1257 return -1;
1258 }
1259
1260 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1261
1262 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1263 if (bss)
1264 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1265 else
1266 mdie = NULL;
1267
1268 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
1269}
1270#endif /* CONFIG_IEEE80211R */
1271
1272
1273#ifdef CONFIG_WPS
1274static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1275 char *cmd)
1276{
1277 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001278#ifdef CONFIG_P2P
1279 u8 p2p_dev_addr[ETH_ALEN];
1280#endif /* CONFIG_P2P */
1281#ifdef CONFIG_AP
1282 u8 *_p2p_dev_addr = NULL;
1283#endif /* CONFIG_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001284 char *pos;
1285 int multi_ap = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001286
Hai Shalom021b0b52019-04-10 11:17:58 -07001287 if (!cmd || os_strcmp(cmd, "any") == 0 ||
1288 os_strncmp(cmd, "any ", 4) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001289 _bssid = NULL;
1290#ifdef CONFIG_P2P
1291 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1292 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1293 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1294 "P2P Device Address '%s'",
1295 cmd + 13);
1296 return -1;
1297 }
1298 _p2p_dev_addr = p2p_dev_addr;
1299#endif /* CONFIG_P2P */
Hai Shalom021b0b52019-04-10 11:17:58 -07001300 } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) {
1301 _bssid = NULL;
1302 multi_ap = atoi(cmd + 9);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001303 } else if (hwaddr_aton(cmd, bssid)) {
1304 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1305 cmd);
1306 return -1;
1307 }
1308
Hai Shalom021b0b52019-04-10 11:17:58 -07001309 if (cmd) {
1310 pos = os_strstr(cmd, " multi_ap=");
1311 if (pos) {
1312 pos += 10;
1313 multi_ap = atoi(pos);
1314 }
1315 }
1316
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001317#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001318 if (wpa_s->ap_iface)
1319 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1320#endif /* CONFIG_AP */
1321
Hai Shalom021b0b52019-04-10 11:17:58 -07001322 return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001323}
1324
1325
1326static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1327 char *cmd, char *buf,
1328 size_t buflen)
1329{
1330 u8 bssid[ETH_ALEN], *_bssid = bssid;
1331 char *pin;
1332 int ret;
1333
1334 pin = os_strchr(cmd, ' ');
1335 if (pin)
1336 *pin++ = '\0';
1337
1338 if (os_strcmp(cmd, "any") == 0)
1339 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001340 else if (os_strcmp(cmd, "get") == 0) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001341 if (wps_generate_pin((unsigned int *) &ret) < 0)
1342 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001343 goto done;
1344 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1346 cmd);
1347 return -1;
1348 }
1349
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001350#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001351 if (wpa_s->ap_iface) {
1352 int timeout = 0;
1353 char *pos;
1354
1355 if (pin) {
1356 pos = os_strchr(pin, ' ');
1357 if (pos) {
1358 *pos++ = '\0';
1359 timeout = atoi(pos);
1360 }
1361 }
1362
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001363 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001364 buf, buflen, timeout);
1365 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001366#endif /* CONFIG_AP */
1367
1368 if (pin) {
1369 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1370 DEV_PW_DEFAULT);
1371 if (ret < 0)
1372 return -1;
1373 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001374 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001375 return -1;
1376 return ret;
1377 }
1378
1379 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1380 if (ret < 0)
1381 return -1;
1382
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001383done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001384 /* Return the generated PIN */
1385 ret = os_snprintf(buf, buflen, "%08d", ret);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001386 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001387 return -1;
1388 return ret;
1389}
1390
1391
1392static int wpa_supplicant_ctrl_iface_wps_check_pin(
1393 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1394{
1395 char pin[9];
1396 size_t len;
1397 char *pos;
1398 int ret;
1399
1400 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1401 (u8 *) cmd, os_strlen(cmd));
1402 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1403 if (*pos < '0' || *pos > '9')
1404 continue;
1405 pin[len++] = *pos;
1406 if (len == 9) {
1407 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1408 return -1;
1409 }
1410 }
1411 if (len != 4 && len != 8) {
1412 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1413 return -1;
1414 }
1415 pin[len] = '\0';
1416
1417 if (len == 8) {
1418 unsigned int pin_val;
1419 pin_val = atoi(pin);
1420 if (!wps_pin_valid(pin_val)) {
1421 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1422 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001423 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001424 return -1;
1425 return ret;
1426 }
1427 }
1428
1429 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001430 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001431 return -1;
1432
1433 return ret;
1434}
1435
1436
Dmitry Shmidt04949592012-07-19 12:16:46 -07001437#ifdef CONFIG_WPS_NFC
1438
1439static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1440 char *cmd)
1441{
1442 u8 bssid[ETH_ALEN], *_bssid = bssid;
1443
1444 if (cmd == NULL || cmd[0] == '\0')
1445 _bssid = NULL;
1446 else if (hwaddr_aton(cmd, bssid))
1447 return -1;
1448
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001449 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1450 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001451}
1452
1453
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001454static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1455 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1456{
1457 int ndef;
1458 struct wpabuf *buf;
1459 int res;
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001460 char *pos;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001461
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001462 pos = os_strchr(cmd, ' ');
1463 if (pos)
1464 *pos++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001465 if (os_strcmp(cmd, "WPS") == 0)
1466 ndef = 0;
1467 else if (os_strcmp(cmd, "NDEF") == 0)
1468 ndef = 1;
1469 else
1470 return -1;
1471
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001472 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001473 if (buf == NULL)
1474 return -1;
1475
1476 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1477 wpabuf_len(buf));
1478 reply[res++] = '\n';
1479 reply[res] = '\0';
1480
1481 wpabuf_free(buf);
1482
1483 return res;
1484}
1485
1486
Dmitry Shmidt04949592012-07-19 12:16:46 -07001487static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1488 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1489{
1490 int ndef;
1491 struct wpabuf *buf;
1492 int res;
1493
1494 if (os_strcmp(cmd, "WPS") == 0)
1495 ndef = 0;
1496 else if (os_strcmp(cmd, "NDEF") == 0)
1497 ndef = 1;
1498 else
1499 return -1;
1500
1501 buf = wpas_wps_nfc_token(wpa_s, ndef);
1502 if (buf == NULL)
1503 return -1;
1504
1505 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1506 wpabuf_len(buf));
1507 reply[res++] = '\n';
1508 reply[res] = '\0';
1509
1510 wpabuf_free(buf);
1511
1512 return res;
1513}
1514
1515
1516static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1517 struct wpa_supplicant *wpa_s, char *pos)
1518{
1519 size_t len;
1520 struct wpabuf *buf;
1521 int ret;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001522 char *freq;
1523 int forced_freq = 0;
1524
1525 freq = strstr(pos, " freq=");
1526 if (freq) {
1527 *freq = '\0';
1528 freq += 6;
1529 forced_freq = atoi(freq);
1530 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001531
1532 len = os_strlen(pos);
1533 if (len & 0x01)
1534 return -1;
1535 len /= 2;
1536
1537 buf = wpabuf_alloc(len);
1538 if (buf == NULL)
1539 return -1;
1540 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1541 wpabuf_free(buf);
1542 return -1;
1543 }
1544
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001545 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001546 wpabuf_free(buf);
1547
1548 return ret;
1549}
1550
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001551
1552static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001553 char *reply, size_t max_len,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001554 int ndef)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001555{
1556 struct wpabuf *buf;
1557 int res;
1558
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001559 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001560 if (buf == NULL)
1561 return -1;
1562
1563 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1564 wpabuf_len(buf));
1565 reply[res++] = '\n';
1566 reply[res] = '\0';
1567
1568 wpabuf_free(buf);
1569
1570 return res;
1571}
1572
1573
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001574#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001575static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1576 char *reply, size_t max_len,
1577 int ndef)
1578{
1579 struct wpabuf *buf;
1580 int res;
1581
1582 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1583 if (buf == NULL) {
1584 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1585 return -1;
1586 }
1587
1588 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1589 wpabuf_len(buf));
1590 reply[res++] = '\n';
1591 reply[res] = '\0';
1592
1593 wpabuf_free(buf);
1594
1595 return res;
1596}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001597#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001598
1599
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001600static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1601 char *cmd, char *reply,
1602 size_t max_len)
1603{
1604 char *pos;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001605 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001606
1607 pos = os_strchr(cmd, ' ');
1608 if (pos == NULL)
1609 return -1;
1610 *pos++ = '\0';
1611
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001612 if (os_strcmp(cmd, "WPS") == 0)
1613 ndef = 0;
1614 else if (os_strcmp(cmd, "NDEF") == 0)
1615 ndef = 1;
1616 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001617 return -1;
1618
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001619 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001620 if (!ndef)
1621 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001622 return wpas_ctrl_nfc_get_handover_req_wps(
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001623 wpa_s, reply, max_len, ndef);
1624 }
1625
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001626#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001627 if (os_strcmp(pos, "P2P-CR") == 0) {
1628 return wpas_ctrl_nfc_get_handover_req_p2p(
1629 wpa_s, reply, max_len, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001630 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001631#endif /* CONFIG_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001632
1633 return -1;
1634}
1635
1636
1637static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001638 char *reply, size_t max_len,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001639 int ndef, int cr, char *uuid)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001640{
1641 struct wpabuf *buf;
1642 int res;
1643
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001644 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001645 if (buf == NULL)
1646 return -1;
1647
1648 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1649 wpabuf_len(buf));
1650 reply[res++] = '\n';
1651 reply[res] = '\0';
1652
1653 wpabuf_free(buf);
1654
1655 return res;
1656}
1657
1658
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001659#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001660static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1661 char *reply, size_t max_len,
1662 int ndef, int tag)
1663{
1664 struct wpabuf *buf;
1665 int res;
1666
1667 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1668 if (buf == NULL)
1669 return -1;
1670
1671 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1672 wpabuf_len(buf));
1673 reply[res++] = '\n';
1674 reply[res] = '\0';
1675
1676 wpabuf_free(buf);
1677
1678 return res;
1679}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001680#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001681
1682
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001683static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1684 char *cmd, char *reply,
1685 size_t max_len)
1686{
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001687 char *pos, *pos2;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001688 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001689
1690 pos = os_strchr(cmd, ' ');
1691 if (pos == NULL)
1692 return -1;
1693 *pos++ = '\0';
1694
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001695 if (os_strcmp(cmd, "WPS") == 0)
1696 ndef = 0;
1697 else if (os_strcmp(cmd, "NDEF") == 0)
1698 ndef = 1;
1699 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001700 return -1;
1701
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001702 pos2 = os_strchr(pos, ' ');
1703 if (pos2)
1704 *pos2++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001705 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001706 if (!ndef)
1707 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001708 return wpas_ctrl_nfc_get_handover_sel_wps(
1709 wpa_s, reply, max_len, ndef,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001710 os_strcmp(pos, "WPS-CR") == 0, pos2);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001711 }
1712
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001713#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001714 if (os_strcmp(pos, "P2P-CR") == 0) {
1715 return wpas_ctrl_nfc_get_handover_sel_p2p(
1716 wpa_s, reply, max_len, ndef, 0);
1717 }
1718
1719 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1720 return wpas_ctrl_nfc_get_handover_sel_p2p(
1721 wpa_s, reply, max_len, ndef, 1);
1722 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001723#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001724
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001725 return -1;
1726}
1727
1728
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001729static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1730 char *cmd)
1731{
1732 size_t len;
1733 struct wpabuf *req, *sel;
1734 int ret;
1735 char *pos, *role, *type, *pos2;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001736#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001737 char *freq;
1738 int forced_freq = 0;
1739
1740 freq = strstr(cmd, " freq=");
1741 if (freq) {
1742 *freq = '\0';
1743 freq += 6;
1744 forced_freq = atoi(freq);
1745 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001746#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001747
1748 role = cmd;
1749 pos = os_strchr(role, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001750 if (pos == NULL) {
1751 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001752 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001753 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001754 *pos++ = '\0';
1755
1756 type = pos;
1757 pos = os_strchr(type, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001758 if (pos == NULL) {
1759 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001760 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001761 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001762 *pos++ = '\0';
1763
1764 pos2 = os_strchr(pos, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001765 if (pos2 == NULL) {
1766 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001767 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001768 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001769 *pos2++ = '\0';
1770
1771 len = os_strlen(pos);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001772 if (len & 0x01) {
1773 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001774 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001775 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001776 len /= 2;
1777
1778 req = wpabuf_alloc(len);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001779 if (req == NULL) {
1780 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001781 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001782 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001783 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001784 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001785 wpabuf_free(req);
1786 return -1;
1787 }
1788
1789 len = os_strlen(pos2);
1790 if (len & 0x01) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001791 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001792 wpabuf_free(req);
1793 return -1;
1794 }
1795 len /= 2;
1796
1797 sel = wpabuf_alloc(len);
1798 if (sel == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001799 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001800 wpabuf_free(req);
1801 return -1;
1802 }
1803 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001804 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001805 wpabuf_free(req);
1806 wpabuf_free(sel);
1807 return -1;
1808 }
1809
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001810 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1811 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1812
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001813 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1814 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001815#ifdef CONFIG_AP
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001816 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1817 {
1818 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1819 if (ret < 0)
1820 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001821#endif /* CONFIG_AP */
1822#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001823 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1824 {
1825 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1826 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1827 {
1828 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1829 forced_freq);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001830#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001831 } else {
1832 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1833 "reported: role=%s type=%s", role, type);
1834 ret = -1;
1835 }
1836 wpabuf_free(req);
1837 wpabuf_free(sel);
1838
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001839 if (ret)
1840 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1841
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001842 return ret;
1843}
1844
Dmitry Shmidt04949592012-07-19 12:16:46 -07001845#endif /* CONFIG_WPS_NFC */
1846
1847
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001848static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1849 char *cmd)
1850{
1851 u8 bssid[ETH_ALEN];
1852 char *pin;
1853 char *new_ssid;
1854 char *new_auth;
1855 char *new_encr;
1856 char *new_key;
1857 struct wps_new_ap_settings ap;
1858
1859 pin = os_strchr(cmd, ' ');
1860 if (pin == NULL)
1861 return -1;
1862 *pin++ = '\0';
1863
1864 if (hwaddr_aton(cmd, bssid)) {
1865 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1866 cmd);
1867 return -1;
1868 }
1869
1870 new_ssid = os_strchr(pin, ' ');
1871 if (new_ssid == NULL)
1872 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1873 *new_ssid++ = '\0';
1874
1875 new_auth = os_strchr(new_ssid, ' ');
1876 if (new_auth == NULL)
1877 return -1;
1878 *new_auth++ = '\0';
1879
1880 new_encr = os_strchr(new_auth, ' ');
1881 if (new_encr == NULL)
1882 return -1;
1883 *new_encr++ = '\0';
1884
1885 new_key = os_strchr(new_encr, ' ');
1886 if (new_key == NULL)
1887 return -1;
1888 *new_key++ = '\0';
1889
1890 os_memset(&ap, 0, sizeof(ap));
1891 ap.ssid_hex = new_ssid;
1892 ap.auth = new_auth;
1893 ap.encr = new_encr;
1894 ap.key_hex = new_key;
1895 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1896}
1897
1898
1899#ifdef CONFIG_AP
1900static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1901 char *cmd, char *buf,
1902 size_t buflen)
1903{
1904 int timeout = 300;
1905 char *pos;
1906 const char *pin_txt;
1907
1908 if (!wpa_s->ap_iface)
1909 return -1;
1910
1911 pos = os_strchr(cmd, ' ');
1912 if (pos)
1913 *pos++ = '\0';
1914
1915 if (os_strcmp(cmd, "disable") == 0) {
1916 wpas_wps_ap_pin_disable(wpa_s);
1917 return os_snprintf(buf, buflen, "OK\n");
1918 }
1919
1920 if (os_strcmp(cmd, "random") == 0) {
1921 if (pos)
1922 timeout = atoi(pos);
1923 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1924 if (pin_txt == NULL)
1925 return -1;
1926 return os_snprintf(buf, buflen, "%s", pin_txt);
1927 }
1928
1929 if (os_strcmp(cmd, "get") == 0) {
1930 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1931 if (pin_txt == NULL)
1932 return -1;
1933 return os_snprintf(buf, buflen, "%s", pin_txt);
1934 }
1935
1936 if (os_strcmp(cmd, "set") == 0) {
1937 char *pin;
1938 if (pos == NULL)
1939 return -1;
1940 pin = pos;
1941 pos = os_strchr(pos, ' ');
1942 if (pos) {
1943 *pos++ = '\0';
1944 timeout = atoi(pos);
1945 }
1946 if (os_strlen(pin) > buflen)
1947 return -1;
1948 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1949 return -1;
1950 return os_snprintf(buf, buflen, "%s", pin);
1951 }
1952
1953 return -1;
1954}
1955#endif /* CONFIG_AP */
1956
1957
1958#ifdef CONFIG_WPS_ER
1959static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1960 char *cmd)
1961{
1962 char *uuid = cmd, *pin, *pos;
1963 u8 addr_buf[ETH_ALEN], *addr = NULL;
1964 pin = os_strchr(uuid, ' ');
1965 if (pin == NULL)
1966 return -1;
1967 *pin++ = '\0';
1968 pos = os_strchr(pin, ' ');
1969 if (pos) {
1970 *pos++ = '\0';
1971 if (hwaddr_aton(pos, addr_buf) == 0)
1972 addr = addr_buf;
1973 }
1974 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1975}
1976
1977
1978static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1979 char *cmd)
1980{
1981 char *uuid = cmd, *pin;
1982 pin = os_strchr(uuid, ' ');
1983 if (pin == NULL)
1984 return -1;
1985 *pin++ = '\0';
1986 return wpas_wps_er_learn(wpa_s, uuid, pin);
1987}
1988
1989
1990static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1991 struct wpa_supplicant *wpa_s, char *cmd)
1992{
1993 char *uuid = cmd, *id;
1994 id = os_strchr(uuid, ' ');
1995 if (id == NULL)
1996 return -1;
1997 *id++ = '\0';
1998 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1999}
2000
2001
2002static int wpa_supplicant_ctrl_iface_wps_er_config(
2003 struct wpa_supplicant *wpa_s, char *cmd)
2004{
2005 char *pin;
2006 char *new_ssid;
2007 char *new_auth;
2008 char *new_encr;
2009 char *new_key;
2010 struct wps_new_ap_settings ap;
2011
2012 pin = os_strchr(cmd, ' ');
2013 if (pin == NULL)
2014 return -1;
2015 *pin++ = '\0';
2016
2017 new_ssid = os_strchr(pin, ' ');
2018 if (new_ssid == NULL)
2019 return -1;
2020 *new_ssid++ = '\0';
2021
2022 new_auth = os_strchr(new_ssid, ' ');
2023 if (new_auth == NULL)
2024 return -1;
2025 *new_auth++ = '\0';
2026
2027 new_encr = os_strchr(new_auth, ' ');
2028 if (new_encr == NULL)
2029 return -1;
2030 *new_encr++ = '\0';
2031
2032 new_key = os_strchr(new_encr, ' ');
2033 if (new_key == NULL)
2034 return -1;
2035 *new_key++ = '\0';
2036
2037 os_memset(&ap, 0, sizeof(ap));
2038 ap.ssid_hex = new_ssid;
2039 ap.auth = new_auth;
2040 ap.encr = new_encr;
2041 ap.key_hex = new_key;
2042 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
2043}
Dmitry Shmidt04949592012-07-19 12:16:46 -07002044
2045
2046#ifdef CONFIG_WPS_NFC
2047static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
2048 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2049{
2050 int ndef;
2051 struct wpabuf *buf;
2052 int res;
2053 char *uuid;
2054
2055 uuid = os_strchr(cmd, ' ');
2056 if (uuid == NULL)
2057 return -1;
2058 *uuid++ = '\0';
2059
2060 if (os_strcmp(cmd, "WPS") == 0)
2061 ndef = 0;
2062 else if (os_strcmp(cmd, "NDEF") == 0)
2063 ndef = 1;
2064 else
2065 return -1;
2066
2067 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
2068 if (buf == NULL)
2069 return -1;
2070
2071 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
2072 wpabuf_len(buf));
2073 reply[res++] = '\n';
2074 reply[res] = '\0';
2075
2076 wpabuf_free(buf);
2077
2078 return res;
2079}
2080#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002081#endif /* CONFIG_WPS_ER */
2082
2083#endif /* CONFIG_WPS */
2084
2085
2086#ifdef CONFIG_IBSS_RSN
2087static int wpa_supplicant_ctrl_iface_ibss_rsn(
2088 struct wpa_supplicant *wpa_s, char *addr)
2089{
2090 u8 peer[ETH_ALEN];
2091
2092 if (hwaddr_aton(addr, peer)) {
2093 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
2094 "address '%s'", addr);
2095 return -1;
2096 }
2097
2098 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
2099 MAC2STR(peer));
2100
2101 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
2102}
2103#endif /* CONFIG_IBSS_RSN */
2104
2105
2106static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
2107 char *rsp)
2108{
2109#ifdef IEEE8021X_EAPOL
2110 char *pos, *id_pos;
2111 int id;
2112 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002113
2114 pos = os_strchr(rsp, '-');
2115 if (pos == NULL)
2116 return -1;
2117 *pos++ = '\0';
2118 id_pos = pos;
2119 pos = os_strchr(pos, ':');
2120 if (pos == NULL)
2121 return -1;
2122 *pos++ = '\0';
2123 id = atoi(id_pos);
2124 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
2125 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2126 (u8 *) pos, os_strlen(pos));
2127
2128 ssid = wpa_config_get_network(wpa_s->conf, id);
2129 if (ssid == NULL) {
2130 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2131 "to update", id);
2132 return -1;
2133 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002134
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002135 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2136 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002137#else /* IEEE8021X_EAPOL */
2138 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2139 return -1;
2140#endif /* IEEE8021X_EAPOL */
2141}
2142
2143
2144static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2145 const char *params,
2146 char *buf, size_t buflen)
2147{
2148 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002149 int res, verbose, wps, ret;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002150#ifdef CONFIG_HS20
2151 const u8 *hs20;
2152#endif /* CONFIG_HS20 */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002153 const u8 *sess_id;
2154 size_t sess_id_len;
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002155
Dmitry Shmidt56052862013-10-04 10:23:25 -07002156 if (os_strcmp(params, "-DRIVER") == 0)
2157 return wpa_drv_status(wpa_s, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002158 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002159 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002160 pos = buf;
2161 end = buf + buflen;
2162 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2163 struct wpa_ssid *ssid = wpa_s->current_ssid;
2164 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2165 MAC2STR(wpa_s->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002166 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002167 return pos - buf;
2168 pos += ret;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002169 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2170 wpa_s->assoc_freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002171 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002172 return pos - buf;
2173 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002174 if (ssid) {
2175 u8 *_ssid = ssid->ssid;
2176 size_t ssid_len = ssid->ssid_len;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002177 u8 ssid_buf[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002178 if (ssid_len == 0) {
2179 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2180 if (_res < 0)
2181 ssid_len = 0;
2182 else
2183 ssid_len = _res;
2184 _ssid = ssid_buf;
2185 }
2186 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2187 wpa_ssid_txt(_ssid, ssid_len),
2188 ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002189 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002190 return pos - buf;
2191 pos += ret;
2192
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002193 if (wps && ssid->passphrase &&
2194 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2195 (ssid->mode == WPAS_MODE_AP ||
2196 ssid->mode == WPAS_MODE_P2P_GO)) {
2197 ret = os_snprintf(pos, end - pos,
2198 "passphrase=%s\n",
2199 ssid->passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002200 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002201 return pos - buf;
2202 pos += ret;
2203 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002204 if (ssid->id_str) {
2205 ret = os_snprintf(pos, end - pos,
2206 "id_str=%s\n",
2207 ssid->id_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002208 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002209 return pos - buf;
2210 pos += ret;
2211 }
2212
2213 switch (ssid->mode) {
2214 case WPAS_MODE_INFRA:
2215 ret = os_snprintf(pos, end - pos,
2216 "mode=station\n");
2217 break;
2218 case WPAS_MODE_IBSS:
2219 ret = os_snprintf(pos, end - pos,
2220 "mode=IBSS\n");
2221 break;
2222 case WPAS_MODE_AP:
2223 ret = os_snprintf(pos, end - pos,
2224 "mode=AP\n");
2225 break;
2226 case WPAS_MODE_P2P_GO:
2227 ret = os_snprintf(pos, end - pos,
2228 "mode=P2P GO\n");
2229 break;
2230 case WPAS_MODE_P2P_GROUP_FORMATION:
2231 ret = os_snprintf(pos, end - pos,
2232 "mode=P2P GO - group "
2233 "formation\n");
2234 break;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002235 case WPAS_MODE_MESH:
2236 ret = os_snprintf(pos, end - pos,
2237 "mode=mesh\n");
2238 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002239 default:
2240 ret = 0;
2241 break;
2242 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002243 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002244 return pos - buf;
2245 pos += ret;
2246 }
2247
Hai Shalom021b0b52019-04-10 11:17:58 -07002248 if (wpa_s->connection_set &&
2249 (wpa_s->connection_ht || wpa_s->connection_vht ||
2250 wpa_s->connection_he)) {
2251 ret = os_snprintf(pos, end - pos,
2252 "wifi_generation=%u\n",
2253 wpa_s->connection_he ? 6 :
2254 (wpa_s->connection_vht ? 5 : 4));
2255 if (os_snprintf_error(end - pos, ret))
2256 return pos - buf;
2257 pos += ret;
2258 }
2259
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002260#ifdef CONFIG_AP
2261 if (wpa_s->ap_iface) {
2262 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2263 end - pos,
2264 verbose);
2265 } else
2266#endif /* CONFIG_AP */
2267 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2268 }
Paul Stewart092955c2017-02-06 09:13:09 -08002269#ifdef CONFIG_SME
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002270#ifdef CONFIG_SAE
2271 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002272#ifdef CONFIG_AP
2273 !wpa_s->ap_iface &&
2274#endif /* CONFIG_AP */
2275 wpa_s->sme.sae.state == SAE_ACCEPTED) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002276 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
2277 wpa_s->sme.sae.group);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002278 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002279 return pos - buf;
2280 pos += ret;
2281 }
2282#endif /* CONFIG_SAE */
Paul Stewart092955c2017-02-06 09:13:09 -08002283#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002284 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2285 wpa_supplicant_state_txt(wpa_s->wpa_state));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002286 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002287 return pos - buf;
2288 pos += ret;
2289
2290 if (wpa_s->l2 &&
2291 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2292 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002293 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002294 return pos - buf;
2295 pos += ret;
2296 }
2297
2298#ifdef CONFIG_P2P
2299 if (wpa_s->global->p2p) {
2300 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2301 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002302 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002303 return pos - buf;
2304 pos += ret;
2305 }
2306#endif /* CONFIG_P2P */
2307
2308 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2309 MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002310 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002311 return pos - buf;
2312 pos += ret;
2313
Dmitry Shmidt04949592012-07-19 12:16:46 -07002314#ifdef CONFIG_HS20
2315 if (wpa_s->current_bss &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002316 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2317 HS20_IE_VENDOR_TYPE)) &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002318 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2319 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002320 int release = 1;
2321 if (hs20[1] >= 5) {
2322 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2323 release = rel_num + 1;
2324 }
2325 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002326 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002327 return pos - buf;
2328 pos += ret;
2329 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002330
2331 if (wpa_s->current_ssid) {
2332 struct wpa_cred *cred;
2333 char *type;
2334
2335 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002336 size_t i;
2337
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002338 if (wpa_s->current_ssid->parent_cred != cred)
2339 continue;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002340
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002341 if (cred->provisioning_sp) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002342 ret = os_snprintf(pos, end - pos,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002343 "provisioning_sp=%s\n",
2344 cred->provisioning_sp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002345 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt051af732013-10-22 13:52:46 -07002346 return pos - buf;
2347 pos += ret;
2348 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002349
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002350 if (!cred->domain)
2351 goto no_domain;
2352
2353 i = 0;
2354 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2355 struct wpabuf *names =
2356 wpa_s->current_bss->anqp->domain_name;
2357 for (i = 0; names && i < cred->num_domain; i++)
2358 {
2359 if (domain_name_list_contains(
2360 names, cred->domain[i], 1))
2361 break;
2362 }
2363 if (i == cred->num_domain)
2364 i = 0; /* show first entry by default */
2365 }
2366 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2367 cred->domain[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002368 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002369 return pos - buf;
2370 pos += ret;
2371
2372 no_domain:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002373 if (wpa_s->current_bss == NULL ||
2374 wpa_s->current_bss->anqp == NULL)
2375 res = -1;
2376 else
2377 res = interworking_home_sp_cred(
2378 wpa_s, cred,
2379 wpa_s->current_bss->anqp->domain_name);
2380 if (res > 0)
2381 type = "home";
2382 else if (res == 0)
2383 type = "roaming";
2384 else
2385 type = "unknown";
2386
2387 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002388 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002389 return pos - buf;
2390 pos += ret;
2391
2392 break;
2393 }
2394 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002395#endif /* CONFIG_HS20 */
2396
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002397 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2398 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2399 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2400 verbose);
2401 if (res >= 0)
2402 pos += res;
2403 }
2404
Dmitry Shmidt29333592017-01-09 12:27:11 -08002405#ifdef CONFIG_MACSEC
2406 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2407 if (res > 0)
2408 pos += res;
2409#endif /* CONFIG_MACSEC */
2410
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002411 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2412 if (sess_id) {
2413 char *start = pos;
2414
2415 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2416 if (os_snprintf_error(end - pos, ret))
2417 return start - buf;
2418 pos += ret;
2419 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2420 if (ret <= 0)
2421 return start - buf;
2422 pos += ret;
2423 ret = os_snprintf(pos, end - pos, "\n");
2424 if (os_snprintf_error(end - pos, ret))
2425 return start - buf;
2426 pos += ret;
2427 }
2428
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002429 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2430 if (res >= 0)
2431 pos += res;
2432
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002433#ifdef CONFIG_WPS
2434 {
2435 char uuid_str[100];
2436 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2437 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002438 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002439 return pos - buf;
2440 pos += ret;
2441 }
2442#endif /* CONFIG_WPS */
2443
Roshan Pius3a1667e2018-07-03 15:17:14 -07002444 if (wpa_s->ieee80211ac) {
2445 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2446 if (os_snprintf_error(end - pos, ret))
2447 return pos - buf;
2448 pos += ret;
2449 }
2450
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002451#ifdef ANDROID
vandwalleffc70182014-09-11 11:40:14 -07002452 /*
2453 * Allow using the STATUS command with default behavior, say for debug,
2454 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2455 * events with STATUS-NO_EVENTS.
2456 */
2457 if (os_strcmp(params, "-NO_EVENTS")) {
2458 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2459 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2460 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2461 wpa_s->wpa_state,
2462 MAC2STR(wpa_s->bssid),
2463 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2464 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2465 wpa_s->current_ssid->ssid_len) : "");
2466 if (wpa_s->wpa_state == WPA_COMPLETED) {
2467 struct wpa_ssid *ssid = wpa_s->current_ssid;
2468 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2469 "- connection to " MACSTR
2470 " completed %s [id=%d id_str=%s]",
2471 MAC2STR(wpa_s->bssid), "(auth)",
2472 ssid ? ssid->id : -1,
2473 ssid && ssid->id_str ? ssid->id_str : "");
2474 }
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08002475 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002476#endif /* ANDROID */
2477
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002478 return pos - buf;
2479}
2480
2481
2482static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2483 char *cmd)
2484{
2485 char *pos;
2486 int id;
2487 struct wpa_ssid *ssid;
2488 u8 bssid[ETH_ALEN];
2489
2490 /* cmd: "<network id> <BSSID>" */
2491 pos = os_strchr(cmd, ' ');
2492 if (pos == NULL)
2493 return -1;
2494 *pos++ = '\0';
2495 id = atoi(cmd);
2496 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2497 if (hwaddr_aton(pos, bssid)) {
2498 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2499 return -1;
2500 }
2501
2502 ssid = wpa_config_get_network(wpa_s->conf, id);
2503 if (ssid == NULL) {
2504 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2505 "to update", id);
2506 return -1;
2507 }
2508
2509 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2510 ssid->bssid_set = !is_zero_ether_addr(bssid);
2511
2512 return 0;
2513}
2514
2515
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002516static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002517 char *cmd, char *buf,
2518 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002519{
2520 u8 bssid[ETH_ALEN];
2521 struct wpa_blacklist *e;
2522 char *pos, *end;
2523 int ret;
2524
2525 /* cmd: "BLACKLIST [<BSSID>]" */
2526 if (*cmd == '\0') {
2527 pos = buf;
2528 end = buf + buflen;
2529 e = wpa_s->blacklist;
2530 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002531 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2532 MAC2STR(e->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002533 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002534 return pos - buf;
2535 pos += ret;
2536 e = e->next;
2537 }
2538 return pos - buf;
2539 }
2540
2541 cmd++;
2542 if (os_strncmp(cmd, "clear", 5) == 0) {
2543 wpa_blacklist_clear(wpa_s);
2544 os_memcpy(buf, "OK\n", 3);
2545 return 3;
2546 }
2547
2548 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
2549 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002550 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002551 return -1;
2552 }
2553
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002554 /*
2555 * Add the BSSID twice, so its count will be 2, causing it to be
2556 * skipped when processing scan results.
2557 */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002558 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002559 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002560 return -1;
2561 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002562 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002563 return -1;
2564 os_memcpy(buf, "OK\n", 3);
2565 return 3;
2566}
2567
2568
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002569static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2570 char *cmd, char *buf,
2571 size_t buflen)
2572{
2573 char *pos, *end, *stamp;
2574 int ret;
2575
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002576 /* cmd: "LOG_LEVEL [<level>]" */
2577 if (*cmd == '\0') {
2578 pos = buf;
2579 end = buf + buflen;
2580 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2581 "Timestamp: %d\n",
2582 debug_level_str(wpa_debug_level),
2583 wpa_debug_timestamp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002584 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002585 ret = 0;
2586
2587 return ret;
2588 }
2589
2590 while (*cmd == ' ')
2591 cmd++;
2592
2593 stamp = os_strchr(cmd, ' ');
2594 if (stamp) {
2595 *stamp++ = '\0';
2596 while (*stamp == ' ') {
2597 stamp++;
2598 }
2599 }
2600
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002601 if (os_strlen(cmd)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002602 int level = str_to_debug_level(cmd);
2603 if (level < 0)
2604 return -1;
2605 wpa_debug_level = level;
2606 }
2607
2608 if (stamp && os_strlen(stamp))
2609 wpa_debug_timestamp = atoi(stamp);
2610
2611 os_memcpy(buf, "OK\n", 3);
2612 return 3;
2613}
2614
2615
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002616static int wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002617 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002618{
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002619 char *pos, *end, *prev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002620 struct wpa_ssid *ssid;
2621 int ret;
2622
2623 pos = buf;
2624 end = buf + buflen;
2625 ret = os_snprintf(pos, end - pos,
2626 "network id / ssid / bssid / flags\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002627 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002628 return pos - buf;
2629 pos += ret;
2630
2631 ssid = wpa_s->conf->ssid;
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002632
2633 /* skip over ssids until we find next one */
2634 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2635 int last_id = atoi(cmd + 8);
2636 if (last_id != -1) {
2637 while (ssid != NULL && ssid->id <= last_id) {
2638 ssid = ssid->next;
2639 }
2640 }
2641 }
2642
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002643 while (ssid) {
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002644 prev = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002645 ret = os_snprintf(pos, end - pos, "%d\t%s",
2646 ssid->id,
2647 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002648 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002649 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002650 pos += ret;
2651 if (ssid->bssid_set) {
2652 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2653 MAC2STR(ssid->bssid));
2654 } else {
2655 ret = os_snprintf(pos, end - pos, "\tany");
2656 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002657 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002658 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002659 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002660 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002661 ssid == wpa_s->current_ssid ?
2662 "[CURRENT]" : "",
2663 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002664 ssid->disabled_until.sec ?
2665 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002666 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2667 "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002668 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002669 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002670 pos += ret;
2671 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002672 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002673 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002674 pos += ret;
2675
2676 ssid = ssid->next;
2677 }
2678
2679 return pos - buf;
2680}
2681
2682
2683static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2684{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002685 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002686 ret = os_snprintf(pos, end - pos, "-");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002687 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002688 return pos;
2689 pos += ret;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002690 ret = wpa_write_ciphers(pos, end, cipher, "+");
2691 if (ret < 0)
2692 return pos;
2693 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002694 return pos;
2695}
2696
2697
2698static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2699 const u8 *ie, size_t ie_len)
2700{
2701 struct wpa_ie_data data;
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002702 char *start;
2703 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002704
2705 ret = os_snprintf(pos, end - pos, "[%s-", proto);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002706 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002707 return pos;
2708 pos += ret;
2709
2710 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2711 ret = os_snprintf(pos, end - pos, "?]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002712 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002713 return pos;
2714 pos += ret;
2715 return pos;
2716 }
2717
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002718 start = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002719 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002720 ret = os_snprintf(pos, end - pos, "%sEAP",
2721 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002722 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002723 return pos;
2724 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002725 }
2726 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002727 ret = os_snprintf(pos, end - pos, "%sPSK",
2728 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002729 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002730 return pos;
2731 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002732 }
2733 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002734 ret = os_snprintf(pos, end - pos, "%sNone",
2735 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002736 if (os_snprintf_error(end - pos, ret))
2737 return pos;
2738 pos += ret;
2739 }
2740 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2741 ret = os_snprintf(pos, end - pos, "%sSAE",
2742 pos == start ? "" : "+");
2743 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002744 return pos;
2745 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002746 }
2747#ifdef CONFIG_IEEE80211R
2748 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2749 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002750 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002751 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002752 return pos;
2753 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002754 }
2755 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2756 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002757 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002758 if (os_snprintf_error(end - pos, ret))
2759 return pos;
2760 pos += ret;
2761 }
2762 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2763 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2764 pos == start ? "" : "+");
2765 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002766 return pos;
2767 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002768 }
2769#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002770 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2771 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002772 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002773 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 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2778 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002779 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002780 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002781 return pos;
2782 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002783 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002784
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002785#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002786 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2787 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2788 pos == start ? "" : "+");
2789 if (os_snprintf_error(end - pos, ret))
2790 return pos;
2791 pos += ret;
2792 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002793#endif /* CONFIG_SUITEB */
2794
2795#ifdef CONFIG_SUITEB192
2796 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2797 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2798 pos == start ? "" : "+");
2799 if (os_snprintf_error(end - pos, ret))
2800 return pos;
2801 pos += ret;
2802 }
2803#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002804
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002805#ifdef CONFIG_FILS
2806 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2807 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2808 pos == start ? "" : "+");
2809 if (os_snprintf_error(end - pos, ret))
2810 return pos;
2811 pos += ret;
2812 }
2813 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2814 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2815 pos == start ? "" : "+");
2816 if (os_snprintf_error(end - pos, ret))
2817 return pos;
2818 pos += ret;
2819 }
2820#ifdef CONFIG_IEEE80211R
2821 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2822 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2823 pos == start ? "" : "+");
2824 if (os_snprintf_error(end - pos, ret))
2825 return pos;
2826 pos += ret;
2827 }
2828 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2829 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2830 pos == start ? "" : "+");
2831 if (os_snprintf_error(end - pos, ret))
2832 return pos;
2833 pos += ret;
2834 }
2835#endif /* CONFIG_IEEE80211R */
2836#endif /* CONFIG_FILS */
2837
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002838#ifdef CONFIG_OWE
2839 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2840 ret = os_snprintf(pos, end - pos, "%sOWE",
2841 pos == start ? "" : "+");
2842 if (os_snprintf_error(end - pos, ret))
2843 return pos;
2844 pos += ret;
2845 }
2846#endif /* CONFIG_OWE */
2847
2848#ifdef CONFIG_DPP
2849 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
2850 ret = os_snprintf(pos, end - pos, "%sDPP",
2851 pos == start ? "" : "+");
2852 if (os_snprintf_error(end - pos, ret))
2853 return pos;
2854 pos += ret;
2855 }
2856#endif /* CONFIG_DPP */
2857
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002858 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2859 ret = os_snprintf(pos, end - pos, "%sOSEN",
2860 pos == start ? "" : "+");
2861 if (os_snprintf_error(end - pos, ret))
2862 return pos;
2863 pos += ret;
2864 }
2865
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002866 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2867
2868 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2869 ret = os_snprintf(pos, end - pos, "-preauth");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002870 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002871 return pos;
2872 pos += ret;
2873 }
2874
2875 ret = os_snprintf(pos, end - pos, "]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002876 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002877 return pos;
2878 pos += ret;
2879
2880 return pos;
2881}
2882
2883
2884#ifdef CONFIG_WPS
2885static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2886 char *pos, char *end,
2887 struct wpabuf *wps_ie)
2888{
2889 int ret;
2890 const char *txt;
2891
2892 if (wps_ie == NULL)
2893 return pos;
2894 if (wps_is_selected_pbc_registrar(wps_ie))
2895 txt = "[WPS-PBC]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002896 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2897 txt = "[WPS-AUTH]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002898 else if (wps_is_selected_pin_registrar(wps_ie))
2899 txt = "[WPS-PIN]";
2900 else
2901 txt = "[WPS]";
2902
2903 ret = os_snprintf(pos, end - pos, "%s", txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002904 if (!os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002905 pos += ret;
2906 wpabuf_free(wps_ie);
2907 return pos;
2908}
2909#endif /* CONFIG_WPS */
2910
2911
2912static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2913 char *pos, char *end,
2914 const struct wpa_bss *bss)
2915{
2916#ifdef CONFIG_WPS
2917 struct wpabuf *wps_ie;
2918 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2919 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2920#else /* CONFIG_WPS */
2921 return pos;
2922#endif /* CONFIG_WPS */
2923}
2924
2925
2926/* Format one result on one text line into a buffer. */
2927static int wpa_supplicant_ctrl_iface_scan_result(
2928 struct wpa_supplicant *wpa_s,
2929 const struct wpa_bss *bss, char *buf, size_t buflen)
2930{
2931 char *pos, *end;
2932 int ret;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002933 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002934
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002935 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002936 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07002937 if (!p2p)
2938 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002939 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2940 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2941 0)
2942 return 0; /* Do not show P2P listen discovery results here */
2943
2944 pos = buf;
2945 end = buf + buflen;
2946
2947 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2948 MAC2STR(bss->bssid), bss->freq, bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002949 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002950 return -1;
2951 pos += ret;
2952 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2953 if (ie)
2954 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2955 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002956 if (ie2) {
2957 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2958 ie2, 2 + ie2[1]);
2959 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002960 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
2961 if (osen_ie)
2962 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
2963 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002964 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
2965 if (owe) {
2966 ret = os_snprintf(pos, end - pos,
2967 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2968 if (os_snprintf_error(end - pos, ret))
2969 return -1;
2970 pos += ret;
2971 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002972 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002973 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002974 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002975 if (os_snprintf_error(end - pos, ret))
2976 return -1;
2977 pos += ret;
2978 }
2979 if (mesh) {
2980 ret = os_snprintf(pos, end - pos, "[MESH]");
2981 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002982 return -1;
2983 pos += ret;
2984 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002985 if (bss_is_dmg(bss)) {
2986 const char *s;
Hai Shalomc3565922019-10-28 11:58:20 -07002987
2988 if (get_ie_ext((const u8 *) (bss + 1), bss->ie_len,
2989 WLAN_EID_EXT_EDMG_OPERATION)) {
2990 ret = os_snprintf(pos, end - pos, "[EDMG]");
2991 if (os_snprintf_error(end - pos, ret))
2992 return -1;
2993 pos += ret;
2994 }
2995
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002996 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002997 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002998 return -1;
2999 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003000 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3001 case IEEE80211_CAP_DMG_IBSS:
3002 s = "[IBSS]";
3003 break;
3004 case IEEE80211_CAP_DMG_AP:
3005 s = "[ESS]";
3006 break;
3007 case IEEE80211_CAP_DMG_PBSS:
3008 s = "[PBSS]";
3009 break;
3010 default:
3011 s = "";
3012 break;
3013 }
3014 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003015 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003016 return -1;
3017 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003018 } else {
3019 if (bss->caps & IEEE80211_CAP_IBSS) {
3020 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003021 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003022 return -1;
3023 pos += ret;
3024 }
3025 if (bss->caps & IEEE80211_CAP_ESS) {
3026 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003027 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003028 return -1;
3029 pos += ret;
3030 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003031 }
3032 if (p2p) {
3033 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003034 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003035 return -1;
3036 pos += ret;
3037 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003038#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003039 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003040 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003041 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003042 return -1;
3043 pos += ret;
3044 }
3045#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003046#ifdef CONFIG_FILS
3047 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
3048 ret = os_snprintf(pos, end - pos, "[FILS]");
3049 if (os_snprintf_error(end - pos, ret))
3050 return -1;
3051 pos += ret;
3052 }
3053#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003054#ifdef CONFIG_FST
3055 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
3056 ret = os_snprintf(pos, end - pos, "[FST]");
3057 if (os_snprintf_error(end - pos, ret))
3058 return -1;
3059 pos += ret;
3060 }
3061#endif /* CONFIG_FST */
Hai Shalom74f70d42019-02-11 14:42:39 -08003062 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
3063 ret = os_snprintf(pos, end - pos, "[UTF-8]");
3064 if (os_snprintf_error(end - pos, ret))
3065 return -1;
3066 pos += ret;
3067 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003068
3069 ret = os_snprintf(pos, end - pos, "\t%s",
3070 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003071 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003072 return -1;
3073 pos += ret;
3074
3075 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003076 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003077 return -1;
3078 pos += ret;
3079
3080 return pos - buf;
3081}
3082
3083
3084static int wpa_supplicant_ctrl_iface_scan_results(
3085 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3086{
3087 char *pos, *end;
3088 struct wpa_bss *bss;
3089 int ret;
3090
3091 pos = buf;
3092 end = buf + buflen;
3093 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
3094 "flags / ssid\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003095 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003096 return pos - buf;
3097 pos += ret;
3098
3099 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3100 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
3101 end - pos);
3102 if (ret < 0 || ret >= end - pos)
3103 return pos - buf;
3104 pos += ret;
3105 }
3106
3107 return pos - buf;
3108}
3109
3110
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003111#ifdef CONFIG_MESH
3112
3113static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3114 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
3115{
3116 char *pos, ifname[IFNAMSIZ + 1];
3117
3118 ifname[0] = '\0';
3119
3120 pos = os_strstr(cmd, "ifname=");
3121 if (pos) {
3122 pos += 7;
3123 os_strlcpy(ifname, pos, sizeof(ifname));
3124 }
3125
3126 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
3127 return -1;
3128
3129 os_strlcpy(reply, ifname, max_len);
3130 return os_strlen(ifname);
3131}
3132
3133
3134static int wpa_supplicant_ctrl_iface_mesh_group_add(
3135 struct wpa_supplicant *wpa_s, char *cmd)
3136{
3137 int id;
3138 struct wpa_ssid *ssid;
3139
3140 id = atoi(cmd);
3141 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
3142
3143 ssid = wpa_config_get_network(wpa_s->conf, id);
3144 if (ssid == NULL) {
3145 wpa_printf(MSG_DEBUG,
3146 "CTRL_IFACE: Could not find network id=%d", id);
3147 return -1;
3148 }
3149 if (ssid->mode != WPAS_MODE_MESH) {
3150 wpa_printf(MSG_DEBUG,
3151 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3152 return -1;
3153 }
3154 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
3155 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
3156 wpa_printf(MSG_ERROR,
3157 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3158 return -1;
3159 }
3160
3161 /*
3162 * TODO: If necessary write our own group_add function,
3163 * for now we can reuse select_network
3164 */
3165 wpa_supplicant_select_network(wpa_s, ssid);
3166
3167 return 0;
3168}
3169
3170
3171static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3172 struct wpa_supplicant *wpa_s, char *cmd)
3173{
3174 struct wpa_supplicant *orig;
3175 struct wpa_global *global;
3176 int found = 0;
3177
3178 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3179
3180 global = wpa_s->global;
3181 orig = wpa_s;
3182
3183 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3184 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3185 found = 1;
3186 break;
3187 }
3188 }
3189 if (!found) {
3190 wpa_printf(MSG_ERROR,
3191 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3192 cmd);
3193 return -1;
3194 }
3195 if (wpa_s->mesh_if_created && wpa_s == orig) {
3196 wpa_printf(MSG_ERROR,
3197 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3198 return -1;
3199 }
3200
3201 wpa_s->reassociate = 0;
3202 wpa_s->disconnected = 1;
3203 wpa_supplicant_cancel_sched_scan(wpa_s);
3204 wpa_supplicant_cancel_scan(wpa_s);
3205
3206 /*
3207 * TODO: If necessary write our own group_remove function,
3208 * for now we can reuse deauthenticate
3209 */
3210 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3211
3212 if (wpa_s->mesh_if_created)
3213 wpa_supplicant_remove_iface(global, wpa_s, 0);
3214
3215 return 0;
3216}
3217
Dmitry Shmidte4663042016-04-04 10:07:49 -07003218
3219static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3220 struct wpa_supplicant *wpa_s, char *cmd)
3221{
3222 u8 addr[ETH_ALEN];
3223
3224 if (hwaddr_aton(cmd, addr) < 0)
3225 return -1;
3226
3227 return wpas_mesh_peer_remove(wpa_s, addr);
3228}
3229
3230
3231static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3232 struct wpa_supplicant *wpa_s, char *cmd)
3233{
3234 u8 addr[ETH_ALEN];
3235 int duration;
3236 char *pos;
3237
3238 pos = os_strstr(cmd, " duration=");
3239 if (pos) {
3240 *pos = '\0';
3241 duration = atoi(pos + 10);
3242 } else {
3243 duration = -1;
3244 }
3245
3246 if (hwaddr_aton(cmd, addr))
3247 return -1;
3248
3249 return wpas_mesh_peer_add(wpa_s, addr, duration);
3250}
3251
Hai Shalom81f62d82019-07-22 12:10:00 -07003252
3253static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3254 struct wpa_supplicant *wpa_s, char *cmd)
3255{
3256 struct ether_header *eth;
3257 u8 addr[ETH_ALEN];
3258 u8 *buf;
3259 char *pos;
3260 size_t payload_len = 0, len;
3261 int ret = -1;
3262
3263 if (hwaddr_aton(cmd, addr))
3264 return -1;
3265
3266 pos = os_strstr(cmd, " payload=");
3267 if (pos) {
3268 pos = pos + 9;
3269 payload_len = os_strlen(pos);
3270 if (payload_len & 1)
3271 return -1;
3272
3273 payload_len /= 2;
3274 }
3275
3276 len = ETH_HLEN + payload_len;
3277 buf = os_malloc(len);
3278 if (!buf)
3279 return -1;
3280
3281 eth = (struct ether_header *) buf;
3282 os_memcpy(eth->ether_dhost, addr, ETH_ALEN);
3283 os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN);
3284 eth->ether_type = htons(ETH_P_802_3);
3285
3286 if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0)
3287 goto fail;
3288
3289 ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len);
3290fail:
3291 os_free(buf);
3292 return -ret;
3293}
3294
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003295#endif /* CONFIG_MESH */
3296
3297
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003298static int wpa_supplicant_ctrl_iface_select_network(
3299 struct wpa_supplicant *wpa_s, char *cmd)
3300{
3301 int id;
3302 struct wpa_ssid *ssid;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003303 char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003304
3305 /* cmd: "<network id>" or "any" */
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003306 if (os_strncmp(cmd, "any", 3) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003307 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3308 ssid = NULL;
3309 } else {
3310 id = atoi(cmd);
3311 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3312
3313 ssid = wpa_config_get_network(wpa_s->conf, id);
3314 if (ssid == NULL) {
3315 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3316 "network id=%d", id);
3317 return -1;
3318 }
3319 if (ssid->disabled == 2) {
3320 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3321 "SELECT_NETWORK with persistent P2P group");
3322 return -1;
3323 }
3324 }
3325
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003326 pos = os_strstr(cmd, " freq=");
3327 if (pos) {
3328 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3329 if (freqs) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003330 os_free(wpa_s->select_network_scan_freqs);
3331 wpa_s->select_network_scan_freqs = freqs;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003332 }
3333 }
3334
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003335 wpa_s->scan_min_time.sec = 0;
3336 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003337 wpa_supplicant_select_network(wpa_s, ssid);
3338
3339 return 0;
3340}
3341
3342
3343static int wpa_supplicant_ctrl_iface_enable_network(
3344 struct wpa_supplicant *wpa_s, char *cmd)
3345{
3346 int id;
3347 struct wpa_ssid *ssid;
3348
3349 /* cmd: "<network id>" or "all" */
3350 if (os_strcmp(cmd, "all") == 0) {
3351 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3352 ssid = NULL;
3353 } else {
3354 id = atoi(cmd);
3355 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3356
3357 ssid = wpa_config_get_network(wpa_s->conf, id);
3358 if (ssid == NULL) {
3359 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3360 "network id=%d", id);
3361 return -1;
3362 }
3363 if (ssid->disabled == 2) {
3364 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3365 "ENABLE_NETWORK with persistent P2P group");
3366 return -1;
3367 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003368
3369 if (os_strstr(cmd, " no-connect")) {
3370 ssid->disabled = 0;
3371 return 0;
3372 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003373 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003374 wpa_s->scan_min_time.sec = 0;
3375 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003376 wpa_supplicant_enable_network(wpa_s, ssid);
3377
3378 return 0;
3379}
3380
3381
3382static int wpa_supplicant_ctrl_iface_disable_network(
3383 struct wpa_supplicant *wpa_s, char *cmd)
3384{
3385 int id;
3386 struct wpa_ssid *ssid;
3387
3388 /* cmd: "<network id>" or "all" */
3389 if (os_strcmp(cmd, "all") == 0) {
3390 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3391 ssid = NULL;
3392 } else {
3393 id = atoi(cmd);
3394 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3395
3396 ssid = wpa_config_get_network(wpa_s->conf, id);
3397 if (ssid == NULL) {
3398 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3399 "network id=%d", id);
3400 return -1;
3401 }
3402 if (ssid->disabled == 2) {
3403 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3404 "DISABLE_NETWORK with persistent P2P "
3405 "group");
3406 return -1;
3407 }
3408 }
3409 wpa_supplicant_disable_network(wpa_s, ssid);
3410
3411 return 0;
3412}
3413
3414
3415static int wpa_supplicant_ctrl_iface_add_network(
3416 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3417{
3418 struct wpa_ssid *ssid;
3419 int ret;
3420
3421 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3422
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003423 ssid = wpa_supplicant_add_network(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003424 if (ssid == NULL)
3425 return -1;
3426
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003427 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003428 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003429 return -1;
3430 return ret;
3431}
3432
3433
3434static int wpa_supplicant_ctrl_iface_remove_network(
3435 struct wpa_supplicant *wpa_s, char *cmd)
3436{
3437 int id;
3438 struct wpa_ssid *ssid;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003439 int result;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003440
3441 /* cmd: "<network id>" or "all" */
3442 if (os_strcmp(cmd, "all") == 0) {
3443 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003444 if (wpa_s->sched_scanning)
3445 wpa_supplicant_cancel_sched_scan(wpa_s);
3446
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003447 eapol_sm_invalidate_cached_session(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003448 if (wpa_s->current_ssid) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003449#ifdef CONFIG_SME
3450 wpa_s->sme.prev_bssid_set = 0;
3451#endif /* CONFIG_SME */
Jouni Malinen75ecf522011-06-27 15:19:46 -07003452 wpa_sm_set_config(wpa_s->wpa, NULL);
3453 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07003454 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3455 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003456 wpa_supplicant_deauthenticate(
3457 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003458 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003459 ssid = wpa_s->conf->ssid;
3460 while (ssid) {
3461 struct wpa_ssid *remove_ssid = ssid;
3462 id = ssid->id;
3463 ssid = ssid->next;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003464 if (wpa_s->last_ssid == remove_ssid)
3465 wpa_s->last_ssid = NULL;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003466 wpas_notify_network_removed(wpa_s, remove_ssid);
3467 wpa_config_remove_network(wpa_s->conf, id);
3468 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003469 return 0;
3470 }
3471
3472 id = atoi(cmd);
3473 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3474
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003475 result = wpa_supplicant_remove_network(wpa_s, id);
3476 if (result == -1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003477 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3478 "id=%d", id);
3479 return -1;
3480 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003481 if (result == -2) {
Deepthi Gowria831d782012-09-03 11:55:38 +03003482 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3483 "network id=%d", id);
3484 return -1;
3485 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003486 return 0;
3487}
3488
3489
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003490static int wpa_supplicant_ctrl_iface_update_network(
3491 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3492 char *name, char *value)
3493{
Dmitry Shmidte4663042016-04-04 10:07:49 -07003494 int ret;
3495
3496 ret = wpa_config_set(ssid, name, value, 0);
3497 if (ret < 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003498 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3499 "variable '%s'", name);
3500 return -1;
3501 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07003502 if (ret == 1)
3503 return 0; /* No change to the previously configured value */
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003504
3505 if (os_strcmp(name, "bssid") != 0 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003506 os_strcmp(name, "bssid_hint") != 0 &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003507 os_strcmp(name, "priority") != 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003508 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3509
Dmitry Shmidte4663042016-04-04 10:07:49 -07003510 if (wpa_s->current_ssid == ssid ||
3511 wpa_s->current_ssid == NULL) {
3512 /*
3513 * Invalidate the EAP session cache if anything in the
3514 * current or previously used configuration changes.
3515 */
3516 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3517 }
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003518 }
3519
3520 if ((os_strcmp(name, "psk") == 0 &&
3521 value[0] == '"' && ssid->ssid_len) ||
3522 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3523 wpa_config_update_psk(ssid);
3524 else if (os_strcmp(name, "priority") == 0)
3525 wpa_config_update_prio_list(wpa_s->conf);
3526
3527 return 0;
3528}
3529
3530
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003531static int wpa_supplicant_ctrl_iface_set_network(
3532 struct wpa_supplicant *wpa_s, char *cmd)
3533{
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003534 int id, ret, prev_bssid_set, prev_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003535 struct wpa_ssid *ssid;
3536 char *name, *value;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003537 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003538
3539 /* cmd: "<network id> <variable name> <value>" */
3540 name = os_strchr(cmd, ' ');
3541 if (name == NULL)
3542 return -1;
3543 *name++ = '\0';
3544
3545 value = os_strchr(name, ' ');
3546 if (value == NULL)
3547 return -1;
3548 *value++ = '\0';
3549
3550 id = atoi(cmd);
3551 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3552 id, name);
3553 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3554 (u8 *) value, os_strlen(value));
3555
3556 ssid = wpa_config_get_network(wpa_s->conf, id);
3557 if (ssid == NULL) {
3558 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3559 "id=%d", id);
3560 return -1;
3561 }
3562
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003563 prev_bssid_set = ssid->bssid_set;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003564 prev_disabled = ssid->disabled;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003565 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3566 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3567 value);
3568 if (ret == 0 &&
3569 (ssid->bssid_set != prev_bssid_set ||
3570 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3571 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003572
3573 if (prev_disabled != ssid->disabled &&
3574 (prev_disabled == 2 || ssid->disabled == 2))
3575 wpas_notify_network_type_changed(wpa_s, ssid);
3576
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003577 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003578}
3579
3580
3581static int wpa_supplicant_ctrl_iface_get_network(
3582 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3583{
3584 int id;
3585 size_t res;
3586 struct wpa_ssid *ssid;
3587 char *name, *value;
3588
3589 /* cmd: "<network id> <variable name>" */
3590 name = os_strchr(cmd, ' ');
3591 if (name == NULL || buflen == 0)
3592 return -1;
3593 *name++ = '\0';
3594
3595 id = atoi(cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003596 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003597 id, name);
3598
3599 ssid = wpa_config_get_network(wpa_s->conf, id);
3600 if (ssid == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003601 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003602 "id=%d", id);
3603 return -1;
3604 }
3605
3606 value = wpa_config_get_no_key(ssid, name);
3607 if (value == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003608 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003609 "variable '%s'", name);
3610 return -1;
3611 }
3612
3613 res = os_strlcpy(buf, value, buflen);
3614 if (res >= buflen) {
3615 os_free(value);
3616 return -1;
3617 }
3618
3619 os_free(value);
3620
3621 return res;
3622}
3623
3624
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003625static int wpa_supplicant_ctrl_iface_dup_network(
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003626 struct wpa_supplicant *wpa_s, char *cmd,
3627 struct wpa_supplicant *dst_wpa_s)
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003628{
3629 struct wpa_ssid *ssid_s, *ssid_d;
3630 char *name, *id, *value;
3631 int id_s, id_d, ret;
3632
3633 /* cmd: "<src network id> <dst network id> <variable name>" */
3634 id = os_strchr(cmd, ' ');
3635 if (id == NULL)
3636 return -1;
3637 *id++ = '\0';
3638
3639 name = os_strchr(id, ' ');
3640 if (name == NULL)
3641 return -1;
3642 *name++ = '\0';
3643
3644 id_s = atoi(cmd);
3645 id_d = atoi(id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003646
3647 wpa_printf(MSG_DEBUG,
3648 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3649 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003650
3651 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3652 if (ssid_s == NULL) {
3653 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3654 "network id=%d", id_s);
3655 return -1;
3656 }
3657
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003658 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003659 if (ssid_d == NULL) {
3660 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003661 "network id=%d", id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003662 return -1;
3663 }
3664
3665 value = wpa_config_get(ssid_s, name);
3666 if (value == NULL) {
3667 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3668 "variable '%s'", name);
3669 return -1;
3670 }
3671
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003672 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003673 value);
3674
3675 os_free(value);
3676
3677 return ret;
3678}
3679
3680
Dmitry Shmidt04949592012-07-19 12:16:46 -07003681static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3682 char *buf, size_t buflen)
3683{
3684 char *pos, *end;
3685 struct wpa_cred *cred;
3686 int ret;
3687
3688 pos = buf;
3689 end = buf + buflen;
3690 ret = os_snprintf(pos, end - pos,
3691 "cred id / realm / username / domain / imsi\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003692 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003693 return pos - buf;
3694 pos += ret;
3695
3696 cred = wpa_s->conf->cred;
3697 while (cred) {
3698 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3699 cred->id, cred->realm ? cred->realm : "",
3700 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07003701 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003702 cred->imsi ? cred->imsi : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003703 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003704 return pos - buf;
3705 pos += ret;
3706
3707 cred = cred->next;
3708 }
3709
3710 return pos - buf;
3711}
3712
3713
3714static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3715 char *buf, size_t buflen)
3716{
3717 struct wpa_cred *cred;
3718 int ret;
3719
3720 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3721
3722 cred = wpa_config_add_cred(wpa_s->conf);
3723 if (cred == NULL)
3724 return -1;
3725
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003726 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3727
Dmitry Shmidt04949592012-07-19 12:16:46 -07003728 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003729 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003730 return -1;
3731 return ret;
3732}
3733
3734
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003735static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
3736 struct wpa_cred *cred)
3737{
3738 struct wpa_ssid *ssid;
3739 char str[20];
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003740 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003741
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003742 if (cred == NULL) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003743 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3744 return -1;
3745 }
3746
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003747 id = cred->id;
3748 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
3749 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3750 return -1;
3751 }
3752
3753 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
3754
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003755 /* Remove any network entry created based on the removed credential */
3756 ssid = wpa_s->conf->ssid;
3757 while (ssid) {
3758 if (ssid->parent_cred == cred) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003759 int res;
3760
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003761 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
3762 "used the removed credential", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003763 res = os_snprintf(str, sizeof(str), "%d", ssid->id);
3764 if (os_snprintf_error(sizeof(str), res))
3765 str[sizeof(str) - 1] = '\0';
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003766 ssid = ssid->next;
3767 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
3768 } else
3769 ssid = ssid->next;
3770 }
3771
3772 return 0;
3773}
3774
3775
Dmitry Shmidt04949592012-07-19 12:16:46 -07003776static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3777 char *cmd)
3778{
3779 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003780 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003781
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003782 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3783 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003784 if (os_strcmp(cmd, "all") == 0) {
3785 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3786 cred = wpa_s->conf->cred;
3787 while (cred) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003788 prev = cred;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003789 cred = cred->next;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003790 wpas_ctrl_remove_cred(wpa_s, prev);
3791 }
3792 return 0;
3793 }
3794
3795 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3796 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3797 cmd + 8);
3798 cred = wpa_s->conf->cred;
3799 while (cred) {
3800 prev = cred;
3801 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003802 if (prev->domain) {
3803 size_t i;
3804 for (i = 0; i < prev->num_domain; i++) {
3805 if (os_strcmp(prev->domain[i], cmd + 8)
3806 != 0)
3807 continue;
3808 wpas_ctrl_remove_cred(wpa_s, prev);
3809 break;
3810 }
3811 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003812 }
3813 return 0;
3814 }
3815
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003816 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3817 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3818 cmd + 16);
3819 cred = wpa_s->conf->cred;
3820 while (cred) {
3821 prev = cred;
3822 cred = cred->next;
3823 if (prev->provisioning_sp &&
3824 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3825 wpas_ctrl_remove_cred(wpa_s, prev);
3826 }
3827 return 0;
3828 }
3829
Dmitry Shmidt04949592012-07-19 12:16:46 -07003830 id = atoi(cmd);
3831 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3832
3833 cred = wpa_config_get_cred(wpa_s->conf, id);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003834 return wpas_ctrl_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003835}
3836
3837
3838static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3839 char *cmd)
3840{
3841 int id;
3842 struct wpa_cred *cred;
3843 char *name, *value;
3844
3845 /* cmd: "<cred id> <variable name> <value>" */
3846 name = os_strchr(cmd, ' ');
3847 if (name == NULL)
3848 return -1;
3849 *name++ = '\0';
3850
3851 value = os_strchr(name, ' ');
3852 if (value == NULL)
3853 return -1;
3854 *value++ = '\0';
3855
3856 id = atoi(cmd);
3857 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3858 id, name);
3859 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3860 (u8 *) value, os_strlen(value));
3861
3862 cred = wpa_config_get_cred(wpa_s->conf, id);
3863 if (cred == NULL) {
3864 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3865 id);
3866 return -1;
3867 }
3868
3869 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3870 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3871 "variable '%s'", name);
3872 return -1;
3873 }
3874
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003875 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3876
Dmitry Shmidt04949592012-07-19 12:16:46 -07003877 return 0;
3878}
3879
3880
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003881static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3882 char *cmd, char *buf,
3883 size_t buflen)
3884{
3885 int id;
3886 size_t res;
3887 struct wpa_cred *cred;
3888 char *name, *value;
3889
3890 /* cmd: "<cred id> <variable name>" */
3891 name = os_strchr(cmd, ' ');
3892 if (name == NULL)
3893 return -1;
3894 *name++ = '\0';
3895
3896 id = atoi(cmd);
3897 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3898 id, name);
3899
3900 cred = wpa_config_get_cred(wpa_s->conf, id);
3901 if (cred == NULL) {
3902 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3903 id);
3904 return -1;
3905 }
3906
3907 value = wpa_config_get_cred_no_key(cred, name);
3908 if (value == NULL) {
3909 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3910 name);
3911 return -1;
3912 }
3913
3914 res = os_strlcpy(buf, value, buflen);
3915 if (res >= buflen) {
3916 os_free(value);
3917 return -1;
3918 }
3919
3920 os_free(value);
3921
3922 return res;
3923}
3924
3925
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003926#ifndef CONFIG_NO_CONFIG_WRITE
3927static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3928{
3929 int ret;
3930
3931 if (!wpa_s->conf->update_config) {
3932 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3933 "to update configuration (update_config=0)");
3934 return -1;
3935 }
3936
3937 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3938 if (ret) {
3939 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3940 "update configuration");
3941 } else {
3942 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3943 " updated");
3944 }
3945
3946 return ret;
3947}
3948#endif /* CONFIG_NO_CONFIG_WRITE */
3949
3950
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003951struct cipher_info {
3952 unsigned int capa;
3953 const char *name;
3954 int group_only;
3955};
3956
3957static const struct cipher_info ciphers[] = {
3958 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3959 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3960 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3961 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07003962#ifndef CONFIG_NO_TKIP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003963 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
Hai Shalomb755a2a2020-04-23 21:49:02 -07003964#endif /* CONFIG_NO_TKIP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003965 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
Hai Shalomfdcde762020-04-02 11:19:20 -07003966#ifdef CONFIG_WEP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003967 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3968 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003969#endif /* CONFIG_WEP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003970};
3971
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003972static const struct cipher_info ciphers_group_mgmt[] = {
3973 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
3974 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
3975 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
3976 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
3977};
3978
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003979
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003980static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3981 struct wpa_driver_capa *capa,
3982 char *buf, size_t buflen)
3983{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003984 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003985 char *pos, *end;
3986 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003987 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003988
3989 pos = buf;
3990 end = pos + buflen;
3991
3992 if (res < 0) {
3993 if (strict)
3994 return 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07003995#ifdef CONFIG_NO_TKIP
3996 len = os_strlcpy(buf, "CCMP NONE", buflen);
3997#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003998 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07003999#endif /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004000 if (len >= buflen)
4001 return -1;
4002 return len;
4003 }
4004
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004005 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4006 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
4007 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004008 pos == buf ? "" : " ",
4009 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004010 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004011 return pos - buf;
4012 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004013 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004014 }
4015
4016 return pos - buf;
4017}
4018
4019
4020static int ctrl_iface_get_capability_group(int res, char *strict,
4021 struct wpa_driver_capa *capa,
4022 char *buf, size_t buflen)
4023{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004024 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004025 char *pos, *end;
4026 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004027 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004028
4029 pos = buf;
4030 end = pos + buflen;
4031
4032 if (res < 0) {
4033 if (strict)
4034 return 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07004035#ifdef CONFIG_WEP
Hai Shalomb755a2a2020-04-23 21:49:02 -07004036#ifdef CONFIG_NO_TKIP
4037 len = os_strlcpy(buf, "CCMP WEP104 WEP40", buflen);
4038#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004039 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004040#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004041#else /* CONFIG_WEP */
Hai Shalomb755a2a2020-04-23 21:49:02 -07004042#ifdef CONFIG_NO_TKIP
4043 len = os_strlcpy(buf, "CCMP", buflen);
4044#else /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004045 len = os_strlcpy(buf, "CCMP TKIP", buflen);
Hai Shalomb755a2a2020-04-23 21:49:02 -07004046#endif /* CONFIG_NO_TKIP */
Hai Shalomfdcde762020-04-02 11:19:20 -07004047#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004048 if (len >= buflen)
4049 return -1;
4050 return len;
4051 }
4052
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004053 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
4054 if (capa->enc & ciphers[i].capa) {
4055 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004056 pos == buf ? "" : " ",
4057 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004058 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004059 return pos - buf;
4060 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004061 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004062 }
4063
4064 return pos - buf;
4065}
4066
4067
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004068static int ctrl_iface_get_capability_group_mgmt(int res, char *strict,
4069 struct wpa_driver_capa *capa,
4070 char *buf, size_t buflen)
4071{
4072 int ret;
4073 char *pos, *end;
4074 unsigned int i;
4075
4076 pos = buf;
4077 end = pos + buflen;
4078
4079 if (res < 0)
4080 return 0;
4081
4082 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
4083 if (capa->enc & ciphers_group_mgmt[i].capa) {
4084 ret = os_snprintf(pos, end - pos, "%s%s",
4085 pos == buf ? "" : " ",
4086 ciphers_group_mgmt[i].name);
4087 if (os_snprintf_error(end - pos, ret))
4088 return pos - buf;
4089 pos += ret;
4090 }
4091 }
4092
4093 return pos - buf;
4094}
4095
4096
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004097static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
4098 struct wpa_driver_capa *capa,
4099 char *buf, size_t buflen)
4100{
4101 int ret;
4102 char *pos, *end;
4103 size_t len;
4104
4105 pos = buf;
4106 end = pos + buflen;
4107
4108 if (res < 0) {
4109 if (strict)
4110 return 0;
4111 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4112 "NONE", buflen);
4113 if (len >= buflen)
4114 return -1;
4115 return len;
4116 }
4117
4118 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004119 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004120 return pos - buf;
4121 pos += ret;
4122
4123 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4124 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
4125 ret = os_snprintf(pos, end - pos, " WPA-EAP");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004126 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004127 return pos - buf;
4128 pos += ret;
4129 }
4130
4131 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
4132 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
4133 ret = os_snprintf(pos, end - pos, " WPA-PSK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004134 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004135 return pos - buf;
4136 pos += ret;
4137 }
4138
4139 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
4140 ret = os_snprintf(pos, end - pos, " WPA-NONE");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004141 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004142 return pos - buf;
4143 pos += ret;
4144 }
4145
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004146#ifdef CONFIG_SUITEB
4147 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
4148 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
4149 if (os_snprintf_error(end - pos, ret))
4150 return pos - buf;
4151 pos += ret;
4152 }
4153#endif /* CONFIG_SUITEB */
4154#ifdef CONFIG_SUITEB192
4155 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
4156 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
4157 if (os_snprintf_error(end - pos, ret))
4158 return pos - buf;
4159 pos += ret;
4160 }
4161#endif /* CONFIG_SUITEB192 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004162#ifdef CONFIG_OWE
4163 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
4164 ret = os_snprintf(pos, end - pos, " OWE");
4165 if (os_snprintf_error(end - pos, ret))
4166 return pos - buf;
4167 pos += ret;
4168 }
4169#endif /* CONFIG_OWE */
4170#ifdef CONFIG_DPP
4171 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
4172 ret = os_snprintf(pos, end - pos, " DPP");
4173 if (os_snprintf_error(end - pos, ret))
4174 return pos - buf;
4175 pos += ret;
4176 }
4177#endif /* CONFIG_DPP */
4178#ifdef CONFIG_FILS
4179 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
4180 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
4181 if (os_snprintf_error(end - pos, ret))
4182 return pos - buf;
4183 pos += ret;
4184 }
4185 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
4186 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
4187 if (os_snprintf_error(end - pos, ret))
4188 return pos - buf;
4189 pos += ret;
4190 }
4191#ifdef CONFIG_IEEE80211R
4192 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
4193 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
4194 if (os_snprintf_error(end - pos, ret))
4195 return pos - buf;
4196 pos += ret;
4197 }
4198 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
4199 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
4200 if (os_snprintf_error(end - pos, ret))
4201 return pos - buf;
4202 pos += ret;
4203 }
4204#endif /* CONFIG_IEEE80211R */
4205#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08004206#ifdef CONFIG_IEEE80211R
4207 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
4208 ret = os_snprintf(pos, end - pos, " FT-PSK");
4209 if (os_snprintf_error(end - pos, ret))
4210 return pos - buf;
4211 pos += ret;
4212 }
4213#endif /* CONFIG_IEEE80211R */
4214#ifdef CONFIG_SAE
4215 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
4216 ret = os_snprintf(pos, end - pos, " SAE");
4217 if (os_snprintf_error(end - pos, ret))
4218 return pos - buf;
4219 pos += ret;
4220 }
4221#endif /* CONFIG_SAE */
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004222
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004223 return pos - buf;
4224}
4225
4226
4227static int ctrl_iface_get_capability_proto(int res, char *strict,
4228 struct wpa_driver_capa *capa,
4229 char *buf, size_t buflen)
4230{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004231 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004232 char *pos, *end;
4233 size_t len;
4234
4235 pos = buf;
4236 end = pos + buflen;
4237
4238 if (res < 0) {
4239 if (strict)
4240 return 0;
4241 len = os_strlcpy(buf, "RSN WPA", buflen);
4242 if (len >= buflen)
4243 return -1;
4244 return len;
4245 }
4246
4247 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4248 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004249 ret = os_snprintf(pos, end - pos, "%sRSN",
4250 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004251 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004252 return pos - buf;
4253 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004254 }
4255
4256 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4257 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004258 ret = os_snprintf(pos, end - pos, "%sWPA",
4259 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004260 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004261 return pos - buf;
4262 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004263 }
4264
4265 return pos - buf;
4266}
4267
4268
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004269static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
4270 int res, char *strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004271 struct wpa_driver_capa *capa,
4272 char *buf, size_t buflen)
4273{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004274 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004275 char *pos, *end;
4276 size_t len;
4277
4278 pos = buf;
4279 end = pos + buflen;
4280
4281 if (res < 0) {
4282 if (strict)
4283 return 0;
4284 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4285 if (len >= buflen)
4286 return -1;
4287 return len;
4288 }
4289
4290 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004291 ret = os_snprintf(pos, end - pos, "%sOPEN",
4292 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004293 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004294 return pos - buf;
4295 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004296 }
4297
4298 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4299 ret = os_snprintf(pos, end - pos, "%sSHARED",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004300 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004301 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004302 return pos - buf;
4303 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004304 }
4305
4306 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004307 ret = os_snprintf(pos, end - pos, "%sLEAP",
4308 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004309 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004310 return pos - buf;
4311 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004312 }
4313
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004314#ifdef CONFIG_SAE
4315 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4316 ret = os_snprintf(pos, end - pos, "%sSAE",
4317 pos == buf ? "" : " ");
4318 if (os_snprintf_error(end - pos, ret))
4319 return pos - buf;
4320 pos += ret;
4321 }
4322#endif /* CONFIG_SAE */
4323
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004324#ifdef CONFIG_FILS
4325 if (wpa_is_fils_supported(wpa_s)) {
4326 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4327 pos == buf ? "" : " ");
4328 if (os_snprintf_error(end - pos, ret))
4329 return pos - buf;
4330 pos += ret;
4331 }
4332
4333#ifdef CONFIG_FILS_SK_PFS
4334 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4335 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4336 pos == buf ? "" : " ");
4337 if (os_snprintf_error(end - pos, ret))
4338 return pos - buf;
4339 pos += ret;
4340 }
4341#endif /* CONFIG_FILS_SK_PFS */
4342#endif /* CONFIG_FILS */
4343
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004344 return pos - buf;
4345}
4346
4347
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004348static int ctrl_iface_get_capability_modes(int res, char *strict,
4349 struct wpa_driver_capa *capa,
4350 char *buf, size_t buflen)
4351{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004352 int ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004353 char *pos, *end;
4354 size_t len;
4355
4356 pos = buf;
4357 end = pos + buflen;
4358
4359 if (res < 0) {
4360 if (strict)
4361 return 0;
4362 len = os_strlcpy(buf, "IBSS AP", buflen);
4363 if (len >= buflen)
4364 return -1;
4365 return len;
4366 }
4367
4368 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004369 ret = os_snprintf(pos, end - pos, "%sIBSS",
4370 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004371 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004372 return pos - buf;
4373 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004374 }
4375
4376 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004377 ret = os_snprintf(pos, end - pos, "%sAP",
4378 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004379 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004380 return pos - buf;
4381 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004382 }
4383
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004384#ifdef CONFIG_MESH
4385 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4386 ret = os_snprintf(pos, end - pos, "%sMESH",
4387 pos == buf ? "" : " ");
4388 if (os_snprintf_error(end - pos, ret))
4389 return pos - buf;
4390 pos += ret;
4391 }
4392#endif /* CONFIG_MESH */
4393
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004394 return pos - buf;
4395}
4396
4397
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004398static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4399 char *buf, size_t buflen)
4400{
4401 struct hostapd_channel_data *chnl;
4402 int ret, i, j;
4403 char *pos, *end, *hmode;
4404
4405 pos = buf;
4406 end = pos + buflen;
4407
4408 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4409 switch (wpa_s->hw.modes[j].mode) {
4410 case HOSTAPD_MODE_IEEE80211B:
4411 hmode = "B";
4412 break;
4413 case HOSTAPD_MODE_IEEE80211G:
4414 hmode = "G";
4415 break;
4416 case HOSTAPD_MODE_IEEE80211A:
4417 hmode = "A";
4418 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004419 case HOSTAPD_MODE_IEEE80211AD:
4420 hmode = "AD";
4421 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004422 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004423 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004424 }
4425 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004426 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004427 return pos - buf;
4428 pos += ret;
4429 chnl = wpa_s->hw.modes[j].channels;
4430 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004431 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4432 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004433 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004434 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004435 return pos - buf;
4436 pos += ret;
4437 }
4438 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004439 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004440 return pos - buf;
4441 pos += ret;
4442 }
4443
4444 return pos - buf;
4445}
4446
4447
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004448static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4449 char *buf, size_t buflen)
4450{
4451 struct hostapd_channel_data *chnl;
4452 int ret, i, j;
4453 char *pos, *end, *hmode;
4454
4455 pos = buf;
4456 end = pos + buflen;
4457
4458 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4459 switch (wpa_s->hw.modes[j].mode) {
4460 case HOSTAPD_MODE_IEEE80211B:
4461 hmode = "B";
4462 break;
4463 case HOSTAPD_MODE_IEEE80211G:
4464 hmode = "G";
4465 break;
4466 case HOSTAPD_MODE_IEEE80211A:
4467 hmode = "A";
4468 break;
4469 case HOSTAPD_MODE_IEEE80211AD:
4470 hmode = "AD";
4471 break;
4472 default:
4473 continue;
4474 }
4475 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4476 hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004477 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004478 return pos - buf;
4479 pos += ret;
4480 chnl = wpa_s->hw.modes[j].channels;
4481 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4482 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4483 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004484 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004485 chnl[i].chan, chnl[i].freq,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004486 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4487 " (NO_IR)" : "",
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004488 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4489 " (DFS)" : "");
4490
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004491 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004492 return pos - buf;
4493 pos += ret;
4494 }
4495 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004496 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004497 return pos - buf;
4498 pos += ret;
4499 }
4500
4501 return pos - buf;
4502}
4503
4504
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004505static int wpa_supplicant_ctrl_iface_get_capability(
4506 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4507 size_t buflen)
4508{
4509 struct wpa_driver_capa capa;
4510 int res;
4511 char *strict;
4512 char field[30];
4513 size_t len;
4514
4515 /* Determine whether or not strict checking was requested */
4516 len = os_strlcpy(field, _field, sizeof(field));
4517 if (len >= sizeof(field))
4518 return -1;
4519 strict = os_strchr(field, ' ');
4520 if (strict != NULL) {
4521 *strict++ = '\0';
4522 if (os_strcmp(strict, "strict") != 0)
4523 return -1;
4524 }
4525
4526 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4527 field, strict ? strict : "");
4528
4529 if (os_strcmp(field, "eap") == 0) {
4530 return eap_get_names(buf, buflen);
4531 }
4532
4533 res = wpa_drv_get_capa(wpa_s, &capa);
4534
4535 if (os_strcmp(field, "pairwise") == 0)
4536 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4537 buf, buflen);
4538
4539 if (os_strcmp(field, "group") == 0)
4540 return ctrl_iface_get_capability_group(res, strict, &capa,
4541 buf, buflen);
4542
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004543 if (os_strcmp(field, "group_mgmt") == 0)
4544 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4545 buf, buflen);
4546
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004547 if (os_strcmp(field, "key_mgmt") == 0)
4548 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
4549 buf, buflen);
4550
4551 if (os_strcmp(field, "proto") == 0)
4552 return ctrl_iface_get_capability_proto(res, strict, &capa,
4553 buf, buflen);
4554
4555 if (os_strcmp(field, "auth_alg") == 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004556 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4557 &capa, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004558
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004559 if (os_strcmp(field, "modes") == 0)
4560 return ctrl_iface_get_capability_modes(res, strict, &capa,
4561 buf, buflen);
4562
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004563 if (os_strcmp(field, "channels") == 0)
4564 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4565
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004566 if (os_strcmp(field, "freq") == 0)
4567 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4568
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004569#ifdef CONFIG_TDLS
4570 if (os_strcmp(field, "tdls") == 0)
4571 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4572#endif /* CONFIG_TDLS */
4573
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004574#ifdef CONFIG_ERP
4575 if (os_strcmp(field, "erp") == 0) {
4576 res = os_snprintf(buf, buflen, "ERP");
4577 if (os_snprintf_error(buflen, res))
4578 return -1;
4579 return res;
4580 }
4581#endif /* CONFIG_EPR */
4582
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004583#ifdef CONFIG_FIPS
4584 if (os_strcmp(field, "fips") == 0) {
4585 res = os_snprintf(buf, buflen, "FIPS");
4586 if (os_snprintf_error(buflen, res))
4587 return -1;
4588 return res;
4589 }
4590#endif /* CONFIG_FIPS */
4591
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004592#ifdef CONFIG_ACS
4593 if (os_strcmp(field, "acs") == 0) {
4594 res = os_snprintf(buf, buflen, "ACS");
4595 if (os_snprintf_error(buflen, res))
4596 return -1;
4597 return res;
4598 }
4599#endif /* CONFIG_ACS */
4600
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004601#ifdef CONFIG_FILS
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004602 if (os_strcmp(field, "fils") == 0) {
4603#ifdef CONFIG_FILS_SK_PFS
4604 if (wpa_is_fils_supported(wpa_s) &&
4605 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4606 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4607 if (os_snprintf_error(buflen, res))
4608 return -1;
4609 return res;
4610 }
4611#endif /* CONFIG_FILS_SK_PFS */
4612
4613 if (wpa_is_fils_supported(wpa_s)) {
4614 res = os_snprintf(buf, buflen, "FILS");
4615 if (os_snprintf_error(buflen, res))
4616 return -1;
4617 return res;
4618 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004619 }
4620#endif /* CONFIG_FILS */
4621
Hai Shalom74f70d42019-02-11 14:42:39 -08004622 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
4623 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
4624 if (os_snprintf_error(buflen, res))
4625 return -1;
4626 return res;
4627 }
4628
Hai Shalom021b0b52019-04-10 11:17:58 -07004629#ifdef CONFIG_DPP
4630 if (os_strcmp(field, "dpp") == 0) {
4631#ifdef CONFIG_DPP2
4632 res = os_snprintf(buf, buflen, "DPP=2");
4633#else /* CONFIG_DPP2 */
4634 res = os_snprintf(buf, buflen, "DPP=1");
4635#endif /* CONFIG_DPP2 */
4636 if (os_snprintf_error(buflen, res))
4637 return -1;
4638 return res;
4639 }
4640#endif /* CONFIG_DPP */
4641
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004642 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4643 field);
4644
4645 return -1;
4646}
4647
4648
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004649#ifdef CONFIG_INTERWORKING
4650static char * anqp_add_hex(char *pos, char *end, const char *title,
4651 struct wpabuf *data)
4652{
4653 char *start = pos;
4654 size_t i;
4655 int ret;
4656 const u8 *d;
4657
4658 if (data == NULL)
4659 return start;
4660
4661 ret = os_snprintf(pos, end - pos, "%s=", title);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004662 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004663 return start;
4664 pos += ret;
4665
4666 d = wpabuf_head_u8(data);
4667 for (i = 0; i < wpabuf_len(data); i++) {
4668 ret = os_snprintf(pos, end - pos, "%02x", *d++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004669 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004670 return start;
4671 pos += ret;
4672 }
4673
4674 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004675 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004676 return start;
4677 pos += ret;
4678
4679 return pos;
4680}
4681#endif /* CONFIG_INTERWORKING */
4682
4683
Dmitry Shmidt29333592017-01-09 12:27:11 -08004684#ifdef CONFIG_FILS
4685static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4686{
4687 char *start = pos;
4688 const u8 *ie, *ie_end;
4689 u16 info, realms;
4690 int ret;
4691
4692 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4693 if (!ie)
4694 return 0;
4695 ie_end = ie + 2 + ie[1];
4696 ie += 2;
4697 if (ie_end - ie < 2)
4698 return -1;
4699
4700 info = WPA_GET_LE16(ie);
4701 ie += 2;
4702 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4703 if (os_snprintf_error(end - pos, ret))
4704 return 0;
4705 pos += ret;
4706
4707 if (info & BIT(7)) {
4708 /* Cache Identifier Included */
4709 if (ie_end - ie < 2)
4710 return -1;
4711 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4712 ie[0], ie[1]);
4713 if (os_snprintf_error(end - pos, ret))
4714 return 0;
4715 pos += ret;
4716 ie += 2;
4717 }
4718
4719 if (info & BIT(8)) {
4720 /* HESSID Included */
4721 if (ie_end - ie < ETH_ALEN)
4722 return -1;
4723 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4724 MAC2STR(ie));
4725 if (os_snprintf_error(end - pos, ret))
4726 return 0;
4727 pos += ret;
4728 ie += ETH_ALEN;
4729 }
4730
4731 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4732 if (realms) {
4733 if (ie_end - ie < realms * 2)
4734 return -1;
4735 ret = os_snprintf(pos, end - pos, "fils_realms=");
4736 if (os_snprintf_error(end - pos, ret))
4737 return 0;
4738 pos += ret;
4739
4740 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
4741 if (ret <= 0)
4742 return 0;
4743 pos += ret;
4744 ie += realms * 2;
4745 ret = os_snprintf(pos, end - pos, "\n");
4746 if (os_snprintf_error(end - pos, ret))
4747 return 0;
4748 pos += ret;
4749 }
4750
4751 return pos - start;
4752}
4753#endif /* CONFIG_FILS */
4754
4755
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004756static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
4757 unsigned long mask, char *buf, size_t buflen)
4758{
4759 size_t i;
4760 int ret;
4761 char *pos, *end;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004762 const u8 *ie, *ie2, *osen_ie, *mesh, *owe;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004763
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004764 pos = buf;
4765 end = buf + buflen;
4766
4767 if (mask & WPA_BSS_MASK_ID) {
4768 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004769 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004770 return 0;
4771 pos += ret;
4772 }
4773
4774 if (mask & WPA_BSS_MASK_BSSID) {
4775 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
4776 MAC2STR(bss->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004777 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004778 return 0;
4779 pos += ret;
4780 }
4781
4782 if (mask & WPA_BSS_MASK_FREQ) {
4783 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004784 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004785 return 0;
4786 pos += ret;
4787 }
4788
4789 if (mask & WPA_BSS_MASK_BEACON_INT) {
4790 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
4791 bss->beacon_int);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004792 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004793 return 0;
4794 pos += ret;
4795 }
4796
4797 if (mask & WPA_BSS_MASK_CAPABILITIES) {
4798 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
4799 bss->caps);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004800 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004801 return 0;
4802 pos += ret;
4803 }
4804
4805 if (mask & WPA_BSS_MASK_QUAL) {
4806 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004807 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004808 return 0;
4809 pos += ret;
4810 }
4811
4812 if (mask & WPA_BSS_MASK_NOISE) {
4813 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004814 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004815 return 0;
4816 pos += ret;
4817 }
4818
4819 if (mask & WPA_BSS_MASK_LEVEL) {
4820 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004821 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004822 return 0;
4823 pos += ret;
4824 }
4825
4826 if (mask & WPA_BSS_MASK_TSF) {
4827 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
4828 (unsigned long long) bss->tsf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004829 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004830 return 0;
4831 pos += ret;
4832 }
4833
4834 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004835 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004836
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004837 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004838 ret = os_snprintf(pos, end - pos, "age=%d\n",
4839 (int) (now.sec - bss->last_update.sec));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004840 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004841 return 0;
4842 pos += ret;
4843 }
4844
4845 if (mask & WPA_BSS_MASK_IE) {
4846 ret = os_snprintf(pos, end - pos, "ie=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004847 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004848 return 0;
4849 pos += ret;
4850
4851 ie = (const u8 *) (bss + 1);
4852 for (i = 0; i < bss->ie_len; i++) {
4853 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004854 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004855 return 0;
4856 pos += ret;
4857 }
4858
4859 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004860 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004861 return 0;
4862 pos += ret;
4863 }
4864
4865 if (mask & WPA_BSS_MASK_FLAGS) {
4866 ret = os_snprintf(pos, end - pos, "flags=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004867 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004868 return 0;
4869 pos += ret;
4870
Dmitry Shmidt29333592017-01-09 12:27:11 -08004871 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
4872
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004873 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
4874 if (ie)
4875 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
4876 2 + ie[1]);
4877 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4878 if (ie2)
Dmitry Shmidt29333592017-01-09 12:27:11 -08004879 pos = wpa_supplicant_ie_txt(pos, end,
4880 mesh ? "RSN" : "WPA2", ie2,
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004881 2 + ie2[1]);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07004882 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
4883 if (osen_ie)
4884 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
4885 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004886 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
4887 if (owe) {
4888 ret = os_snprintf(
4889 pos, end - pos,
4890 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4891 if (os_snprintf_error(end - pos, ret))
4892 return 0;
4893 pos += ret;
4894 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004895 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07004896 if (!ie && !ie2 && !osen_ie &&
4897 (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004898 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004899 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004900 return 0;
4901 pos += ret;
4902 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08004903
4904 if (mesh) {
4905 ret = os_snprintf(pos, end - pos, "[MESH]");
4906 if (os_snprintf_error(end - pos, ret))
4907 return 0;
4908 pos += ret;
4909 }
4910
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004911 if (bss_is_dmg(bss)) {
4912 const char *s;
4913 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004914 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004915 return 0;
4916 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004917 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
4918 case IEEE80211_CAP_DMG_IBSS:
4919 s = "[IBSS]";
4920 break;
4921 case IEEE80211_CAP_DMG_AP:
4922 s = "[ESS]";
4923 break;
4924 case IEEE80211_CAP_DMG_PBSS:
4925 s = "[PBSS]";
4926 break;
4927 default:
4928 s = "";
4929 break;
4930 }
4931 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004932 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004933 return 0;
4934 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004935 } else {
4936 if (bss->caps & IEEE80211_CAP_IBSS) {
4937 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004938 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004939 return 0;
4940 pos += ret;
4941 }
4942 if (bss->caps & IEEE80211_CAP_ESS) {
4943 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004944 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004945 return 0;
4946 pos += ret;
4947 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004948 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07004949 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
4950 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004951 ret = os_snprintf(pos, end - pos, "[P2P]");
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 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004956#ifdef CONFIG_HS20
4957 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
4958 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004959 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004960 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004961 pos += ret;
4962 }
4963#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004964#ifdef CONFIG_FILS
4965 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
4966 ret = os_snprintf(pos, end - pos, "[FILS]");
4967 if (os_snprintf_error(end - pos, ret))
4968 return 0;
4969 pos += ret;
4970 }
4971#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08004972#ifdef CONFIG_FST
4973 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
4974 ret = os_snprintf(pos, end - pos, "[FST]");
4975 if (os_snprintf_error(end - pos, ret))
4976 return 0;
4977 pos += ret;
4978 }
4979#endif /* CONFIG_FST */
4980 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
4981 ret = os_snprintf(pos, end - pos, "[UTF-8]");
4982 if (os_snprintf_error(end - pos, ret))
4983 return 0;
4984 pos += ret;
4985 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004986
4987 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004988 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004989 return 0;
4990 pos += ret;
4991 }
4992
4993 if (mask & WPA_BSS_MASK_SSID) {
4994 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
4995 wpa_ssid_txt(bss->ssid, bss->ssid_len));
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#ifdef CONFIG_WPS
5002 if (mask & WPA_BSS_MASK_WPS_SCAN) {
5003 ie = (const u8 *) (bss + 1);
5004 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005005 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005006 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005007 if (ret > 0)
5008 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005009 }
5010#endif /* CONFIG_WPS */
5011
5012#ifdef CONFIG_P2P
5013 if (mask & WPA_BSS_MASK_P2P_SCAN) {
5014 ie = (const u8 *) (bss + 1);
5015 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005016 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005017 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005018 if (ret > 0)
5019 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005020 }
5021#endif /* CONFIG_P2P */
5022
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005023#ifdef CONFIG_WIFI_DISPLAY
5024 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
5025 struct wpabuf *wfd;
5026 ie = (const u8 *) (bss + 1);
5027 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
5028 WFD_IE_VENDOR_TYPE);
5029 if (wfd) {
5030 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005031 if (os_snprintf_error(end - pos, ret)) {
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005032 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005033 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08005034 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005035 pos += ret;
5036
5037 pos += wpa_snprintf_hex(pos, end - pos,
5038 wpabuf_head(wfd),
5039 wpabuf_len(wfd));
5040 wpabuf_free(wfd);
5041
5042 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005043 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005044 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005045 pos += ret;
5046 }
5047 }
5048#endif /* CONFIG_WIFI_DISPLAY */
5049
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005050#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005051 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
5052 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005053 struct wpa_bss_anqp_elem *elem;
5054
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005055 pos = anqp_add_hex(pos, end, "anqp_capability_list",
5056 anqp->capability_list);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005057 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005058 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005059 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005060 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005061 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005062 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005063 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005064 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005065 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005066 anqp->nai_realm);
5067 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005068 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005069 anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -08005070 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
5071 anqp->fils_realm_info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005072#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005073 pos = anqp_add_hex(pos, end, "hs20_capability_list",
5074 anqp->hs20_capability_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005075 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005076 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005077 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005078 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005079 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07005080 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08005081 pos = anqp_add_hex(pos, end, "hs20_operating_class",
5082 anqp->hs20_operating_class);
5083 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
5084 anqp->hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -07005085 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
5086 anqp->hs20_operator_icon_metadata);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08005087 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
5088 anqp->hs20_osu_providers_nai_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005089#endif /* CONFIG_HS20 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005090
5091 dl_list_for_each(elem, &anqp->anqp_elems,
5092 struct wpa_bss_anqp_elem, list) {
5093 char title[20];
5094
5095 os_snprintf(title, sizeof(title), "anqp[%u]",
5096 elem->infoid);
5097 pos = anqp_add_hex(pos, end, title, elem->payload);
5098 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005099 }
5100#endif /* CONFIG_INTERWORKING */
5101
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005102#ifdef CONFIG_MESH
5103 if (mask & WPA_BSS_MASK_MESH_SCAN) {
5104 ie = (const u8 *) (bss + 1);
5105 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005106 if (ret >= end - pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005107 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005108 if (ret > 0)
5109 pos += ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005110 }
5111#endif /* CONFIG_MESH */
5112
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005113 if (mask & WPA_BSS_MASK_SNR) {
5114 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
5115 if (os_snprintf_error(end - pos, ret))
5116 return 0;
5117 pos += ret;
5118 }
5119
5120 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
5121 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
5122 bss->est_throughput);
5123 if (os_snprintf_error(end - pos, ret))
5124 return 0;
5125 pos += ret;
5126 }
5127
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005128#ifdef CONFIG_FST
5129 if (mask & WPA_BSS_MASK_FST) {
5130 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
5131 if (ret < 0 || ret >= end - pos)
5132 return 0;
5133 pos += ret;
5134 }
5135#endif /* CONFIG_FST */
5136
Dmitry Shmidt29333592017-01-09 12:27:11 -08005137 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
5138 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
5139 bss->last_update_idx);
5140 if (os_snprintf_error(end - pos, ret))
5141 return 0;
5142 pos += ret;
5143 }
5144
5145 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
5146 ret = os_snprintf(pos, end - pos, "beacon_ie=");
5147 if (os_snprintf_error(end - pos, ret))
5148 return 0;
5149 pos += ret;
5150
5151 ie = (const u8 *) (bss + 1);
5152 ie += bss->ie_len;
5153 for (i = 0; i < bss->beacon_ie_len; i++) {
5154 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
5155 if (os_snprintf_error(end - pos, ret))
5156 return 0;
5157 pos += ret;
5158 }
5159
5160 ret = os_snprintf(pos, end - pos, "\n");
5161 if (os_snprintf_error(end - pos, ret))
5162 return 0;
5163 pos += ret;
5164 }
5165
5166#ifdef CONFIG_FILS
5167 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
5168 ret = print_fils_indication(bss, pos, end);
5169 if (ret < 0)
5170 return 0;
5171 pos += ret;
5172 }
5173#endif /* CONFIG_FILS */
5174
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005175 if (mask & WPA_BSS_MASK_DELIM) {
5176 ret = os_snprintf(pos, end - pos, "====\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005177 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005178 return 0;
5179 pos += ret;
5180 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07005181
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005182 return pos - buf;
5183}
5184
Dmitry Shmidt04949592012-07-19 12:16:46 -07005185
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005186static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
5187 const char *cmd, char *buf,
5188 size_t buflen)
5189{
5190 u8 bssid[ETH_ALEN];
5191 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005192 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005193 struct wpa_bss *bsslast = NULL;
5194 struct dl_list *next;
5195 int ret = 0;
5196 int len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005197 char *ctmp, *end = buf + buflen;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005198 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005199
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005200 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
5201 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
5202 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005203 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005204 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
5205 list_id);
5206 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005207 unsigned int id1, id2;
5208
5209 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
5210 wpa_printf(MSG_INFO, "Wrong BSS range "
5211 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005212 return 0;
5213 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005214
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005215 if (*(cmd + 6) == '-')
5216 id1 = 0;
5217 else
5218 id1 = atoi(cmd + 6);
5219 ctmp++;
5220 if (*ctmp >= '0' && *ctmp <= '9')
5221 id2 = atoi(ctmp);
5222 else
5223 id2 = (unsigned int) -1;
5224 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
5225 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005226 bsslast = dl_list_last(&wpa_s->bss_id,
5227 struct wpa_bss,
5228 list_id);
5229 else {
5230 bsslast = wpa_bss_get_id(wpa_s, id2);
5231 if (bsslast == NULL && bss && id2 > id1) {
5232 struct wpa_bss *tmp = bss;
5233 for (;;) {
5234 next = tmp->list_id.next;
5235 if (next == &wpa_s->bss_id)
5236 break;
5237 tmp = dl_list_entry(
5238 next, struct wpa_bss,
5239 list_id);
5240 if (tmp->id > id2)
5241 break;
5242 bsslast = tmp;
5243 }
5244 }
5245 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005246 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005247 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005248 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005249 else if (os_strncmp(cmd, "LAST", 4) == 0)
5250 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005251 else if (os_strncmp(cmd, "ID-", 3) == 0) {
5252 i = atoi(cmd + 3);
5253 bss = wpa_bss_get_id(wpa_s, i);
5254 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5255 i = atoi(cmd + 5);
5256 bss = wpa_bss_get_id(wpa_s, i);
5257 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005258 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005259 if (next == &wpa_s->bss_id)
5260 bss = NULL;
5261 else
5262 bss = dl_list_entry(next, struct wpa_bss,
5263 list_id);
5264 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005265 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5266 bss = wpa_s->current_bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005267#ifdef CONFIG_P2P
5268 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5269 if (hwaddr_aton(cmd + 13, bssid) == 0)
5270 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5271 else
5272 bss = NULL;
5273#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005274 } else if (hwaddr_aton(cmd, bssid) == 0)
5275 bss = wpa_bss_get_bssid(wpa_s, bssid);
5276 else {
5277 struct wpa_bss *tmp;
5278 i = atoi(cmd);
5279 bss = NULL;
5280 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5281 {
Hai Shalom021b0b52019-04-10 11:17:58 -07005282 if (i == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005283 bss = tmp;
5284 break;
5285 }
Hai Shalom021b0b52019-04-10 11:17:58 -07005286 i--;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005287 }
5288 }
5289
Dmitry Shmidt04949592012-07-19 12:16:46 -07005290 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5291 mask = strtoul(ctmp + 5, NULL, 0x10);
5292 if (mask == 0)
5293 mask = WPA_BSS_MASK_ALL;
5294 }
5295
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005296 if (bss == NULL)
5297 return 0;
5298
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005299 if (bsslast == NULL)
5300 bsslast = bss;
5301 do {
5302 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5303 ret += len;
5304 buf += len;
5305 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005306 if (bss == bsslast) {
5307 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5308 (bss == dl_list_last(&wpa_s->bss_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005309 struct wpa_bss, list_id))) {
5310 int res;
5311
5312 res = os_snprintf(buf - 5, end - buf + 5,
5313 "####\n");
5314 if (os_snprintf_error(end - buf + 5, res)) {
5315 wpa_printf(MSG_DEBUG,
5316 "Could not add end delim");
5317 }
5318 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005319 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005320 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005321 next = bss->list_id.next;
5322 if (next == &wpa_s->bss_id)
5323 break;
5324 bss = dl_list_entry(next, struct wpa_bss, list_id);
5325 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005326
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005327 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005328}
5329
5330
5331static int wpa_supplicant_ctrl_iface_ap_scan(
5332 struct wpa_supplicant *wpa_s, char *cmd)
5333{
5334 int ap_scan = atoi(cmd);
5335 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5336}
5337
5338
5339static int wpa_supplicant_ctrl_iface_scan_interval(
5340 struct wpa_supplicant *wpa_s, char *cmd)
5341{
5342 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005343 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005344}
5345
5346
5347static int wpa_supplicant_ctrl_iface_bss_expire_age(
5348 struct wpa_supplicant *wpa_s, char *cmd)
5349{
5350 int expire_age = atoi(cmd);
5351 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5352}
5353
5354
5355static int wpa_supplicant_ctrl_iface_bss_expire_count(
5356 struct wpa_supplicant *wpa_s, char *cmd)
5357{
5358 int expire_count = atoi(cmd);
5359 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5360}
5361
5362
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005363static void wpa_supplicant_ctrl_iface_bss_flush(
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005364 struct wpa_supplicant *wpa_s, char *cmd)
5365{
5366 int flush_age = atoi(cmd);
5367
5368 if (flush_age == 0)
5369 wpa_bss_flush(wpa_s);
5370 else
5371 wpa_bss_flush_by_age(wpa_s, flush_age);
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005372}
5373
5374
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005375#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005376static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5377{
5378 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5379 /* MLME-DELETEKEYS.request */
Hai Shalomfdcde762020-04-02 11:19:20 -07005380 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL,
5381 0, KEY_FLAG_GROUP);
5382 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL,
5383 0, KEY_FLAG_GROUP);
5384 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL,
5385 0, KEY_FLAG_GROUP);
5386 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL,
5387 0, KEY_FLAG_GROUP);
5388 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL,
5389 0, KEY_FLAG_GROUP);
5390 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL,
5391 0, KEY_FLAG_GROUP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005392
5393 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
Hai Shalomfdcde762020-04-02 11:19:20 -07005394 0, KEY_FLAG_PAIRWISE);
5395 if (wpa_sm_ext_key_id(wpa_s->wpa))
5396 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 1, 0,
5397 NULL, 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005398 /* MLME-SETPROTECTION.request(None) */
5399 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5400 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5401 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5402 wpa_sm_drop_sa(wpa_s->wpa);
5403}
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005404#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005405
5406
5407static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5408 char *addr)
5409{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005410#ifdef CONFIG_NO_SCAN_PROCESSING
5411 return -1;
5412#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005413 u8 bssid[ETH_ALEN];
5414 struct wpa_bss *bss;
5415 struct wpa_ssid *ssid = wpa_s->current_ssid;
5416
5417 if (hwaddr_aton(addr, bssid)) {
5418 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5419 "address '%s'", addr);
5420 return -1;
5421 }
5422
5423 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5424
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005425 if (!ssid) {
5426 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5427 "configuration known for the target AP");
5428 return -1;
5429 }
5430
5431 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005432 if (!bss) {
5433 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
5434 "from BSS table");
5435 return -1;
5436 }
5437
5438 /*
5439 * TODO: Find best network configuration block from configuration to
5440 * allow roaming to other networks
5441 */
5442
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005443 wpa_s->reassociate = 1;
5444 wpa_supplicant_connect(wpa_s, bss, ssid);
5445
5446 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005447#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005448}
5449
5450
5451#ifdef CONFIG_P2P
5452static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
5453{
5454 unsigned int timeout = atoi(cmd);
5455 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005456 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005457 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005458 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005459 unsigned int search_delay;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005460 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005461 u8 seek_count = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005462 int freq = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005463
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005464 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5465 wpa_dbg(wpa_s, MSG_INFO,
5466 "Reject P2P_FIND since interface is disabled");
5467 return -1;
5468 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005469 if (os_strstr(cmd, "type=social"))
5470 type = P2P_FIND_ONLY_SOCIAL;
5471 else if (os_strstr(cmd, "type=progressive"))
5472 type = P2P_FIND_PROGRESSIVE;
5473
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005474 pos = os_strstr(cmd, "dev_id=");
5475 if (pos) {
5476 pos += 7;
5477 if (hwaddr_aton(pos, dev_id))
5478 return -1;
5479 _dev_id = dev_id;
5480 }
5481
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005482 pos = os_strstr(cmd, "dev_type=");
5483 if (pos) {
5484 pos += 9;
5485 if (wps_dev_type_str2bin(pos, dev_type) < 0)
5486 return -1;
5487 _dev_type = dev_type;
5488 }
5489
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005490 pos = os_strstr(cmd, "delay=");
5491 if (pos) {
5492 pos += 6;
5493 search_delay = atoi(pos);
5494 } else
5495 search_delay = wpas_p2p_search_delay(wpa_s);
5496
Dmitry Shmidt41712582015-06-29 11:02:15 -07005497 pos = os_strstr(cmd, "freq=");
5498 if (pos) {
5499 pos += 5;
5500 freq = atoi(pos);
5501 if (freq <= 0)
5502 return -1;
5503 }
5504
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005505 /* Must be searched for last, because it adds nul termination */
5506 pos = os_strstr(cmd, " seek=");
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005507 if (pos)
5508 pos += 6;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005509 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
5510 char *term;
5511
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005512 _seek[seek_count++] = pos;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005513 seek = _seek;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005514 term = os_strchr(pos, ' ');
5515 if (!term)
5516 break;
5517 *term = '\0';
5518 pos = os_strstr(term + 1, "seek=");
5519 if (pos)
5520 pos += 5;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005521 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005522 if (seek_count > P2P_MAX_QUERY_HASH) {
5523 seek[0] = NULL;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005524 seek_count = 1;
5525 }
5526
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005527 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005528 _dev_id, search_delay, seek_count, seek, freq);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005529}
5530
5531
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005532static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
5533{
5534 const char *last = NULL;
5535 const char *token;
5536 long int token_len;
5537 unsigned int i;
5538
5539 /* Expected predefined CPT names delimited by ':' */
5540 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
5541 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
5542 wpa_printf(MSG_ERROR,
5543 "P2PS: CPT name list is too long, expected up to %d names",
5544 P2PS_FEATURE_CAPAB_CPT_MAX);
5545 cpt[0] = 0;
5546 return -1;
5547 }
5548
5549 token_len = last - token;
5550
5551 if (token_len == 3 &&
5552 os_memcmp(token, "UDP", token_len) == 0) {
5553 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5554 } else if (token_len == 3 &&
5555 os_memcmp(token, "MAC", token_len) == 0) {
5556 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
5557 } else {
5558 wpa_printf(MSG_ERROR,
5559 "P2PS: Unsupported CPT name '%s'", token);
5560 cpt[0] = 0;
5561 return -1;
5562 }
5563
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005564 if (isblank((unsigned char) *last)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005565 i++;
5566 break;
5567 }
5568 }
5569 cpt[i] = 0;
5570 return 0;
5571}
5572
5573
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005574static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
5575{
5576 struct p2ps_provision *p2ps_prov;
5577 char *pos;
5578 size_t info_len = 0;
5579 char *info = NULL;
5580 u8 role = P2PS_SETUP_NONE;
5581 long long unsigned val;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005582 int i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005583
5584 pos = os_strstr(cmd, "info=");
5585 if (pos) {
5586 pos += 5;
5587 info_len = os_strlen(pos);
5588
5589 if (info_len) {
5590 info = os_malloc(info_len + 1);
5591 if (info) {
5592 info_len = utf8_unescape(pos, info_len,
5593 info, info_len + 1);
5594 } else
5595 info_len = 0;
5596 }
5597 }
5598
5599 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
5600 if (p2ps_prov == NULL) {
5601 os_free(info);
5602 return NULL;
5603 }
5604
5605 if (info) {
5606 os_memcpy(p2ps_prov->info, info, info_len);
5607 p2ps_prov->info[info_len] = '\0';
5608 os_free(info);
5609 }
5610
5611 pos = os_strstr(cmd, "status=");
5612 if (pos)
5613 p2ps_prov->status = atoi(pos + 7);
5614 else
5615 p2ps_prov->status = -1;
5616
5617 pos = os_strstr(cmd, "adv_id=");
5618 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
5619 goto invalid_args;
5620 p2ps_prov->adv_id = val;
5621
5622 pos = os_strstr(cmd, "method=");
5623 if (pos)
5624 p2ps_prov->method = strtol(pos + 7, NULL, 16);
5625 else
5626 p2ps_prov->method = 0;
5627
5628 pos = os_strstr(cmd, "session=");
5629 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
5630 goto invalid_args;
5631 p2ps_prov->session_id = val;
5632
5633 pos = os_strstr(cmd, "adv_mac=");
5634 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
5635 goto invalid_args;
5636
5637 pos = os_strstr(cmd, "session_mac=");
5638 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
5639 goto invalid_args;
5640
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005641 pos = os_strstr(cmd, "cpt=");
5642 if (pos) {
5643 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
5644 p2ps_prov->cpt_priority))
5645 goto invalid_args;
5646 } else {
5647 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5648 }
5649
5650 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
5651 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
5652
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005653 /* force conncap with tstCap (no sanity checks) */
5654 pos = os_strstr(cmd, "tstCap=");
5655 if (pos) {
5656 role = strtol(pos + 7, NULL, 16);
5657 } else {
5658 pos = os_strstr(cmd, "role=");
5659 if (pos) {
5660 role = strtol(pos + 5, NULL, 16);
5661 if (role != P2PS_SETUP_CLIENT &&
5662 role != P2PS_SETUP_GROUP_OWNER)
5663 role = P2PS_SETUP_NONE;
5664 }
5665 }
5666 p2ps_prov->role = role;
5667
5668 return p2ps_prov;
5669
5670invalid_args:
5671 os_free(p2ps_prov);
5672 return NULL;
5673}
5674
5675
5676static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
5677{
5678 u8 addr[ETH_ALEN];
5679 struct p2ps_provision *p2ps_prov;
5680 char *pos;
5681
5682 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5683
5684 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5685
5686 if (hwaddr_aton(cmd, addr))
5687 return -1;
5688
5689 pos = cmd + 17;
5690 if (*pos != ' ')
5691 return -1;
5692
5693 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5694 if (!p2ps_prov)
5695 return -1;
5696
5697 if (p2ps_prov->status < 0) {
5698 os_free(p2ps_prov);
5699 return -1;
5700 }
5701
5702 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5703 p2ps_prov);
5704}
5705
5706
5707static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
5708{
5709 u8 addr[ETH_ALEN];
5710 struct p2ps_provision *p2ps_prov;
5711 char *pos;
5712
5713 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5714 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5715 */
5716
5717 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5718 if (hwaddr_aton(cmd, addr))
5719 return -1;
5720
5721 pos = cmd + 17;
5722 if (*pos != ' ')
5723 return -1;
5724
5725 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5726 if (!p2ps_prov)
5727 return -1;
5728
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005729 p2ps_prov->pd_seeker = 1;
5730
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005731 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5732 p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005733}
5734
5735
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005736static int parse_freq(int chwidth, int freq2)
5737{
5738 if (freq2 < 0)
5739 return -1;
5740 if (freq2)
Hai Shalom81f62d82019-07-22 12:10:00 -07005741 return CHANWIDTH_80P80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005742
5743 switch (chwidth) {
5744 case 0:
5745 case 20:
5746 case 40:
Hai Shalom81f62d82019-07-22 12:10:00 -07005747 return CHANWIDTH_USE_HT;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005748 case 80:
Hai Shalom81f62d82019-07-22 12:10:00 -07005749 return CHANWIDTH_80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005750 case 160:
Hai Shalom81f62d82019-07-22 12:10:00 -07005751 return CHANWIDTH_160MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005752 default:
5753 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
5754 chwidth);
5755 return -1;
5756 }
5757}
5758
5759
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005760static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
5761 char *buf, size_t buflen)
5762{
5763 u8 addr[ETH_ALEN];
5764 char *pos, *pos2;
5765 char *pin = NULL;
5766 enum p2p_wps_method wps_method;
5767 int new_pin;
5768 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005769 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005770 int join;
5771 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005772 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005773 int go_intent = -1;
5774 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005775 int pd;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005776 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005777 int edmg;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005778 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
5779 size_t group_ssid_len = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08005780 int he;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005781
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005782 if (!wpa_s->global->p2p_init_wpa_s)
5783 return -1;
5784 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
5785 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
5786 wpa_s->global->p2p_init_wpa_s->ifname);
5787 wpa_s = wpa_s->global->p2p_init_wpa_s;
5788 }
5789
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005790 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
Dmitry Shmidt04949592012-07-19 12:16:46 -07005791 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005792 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005793 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005794
5795 if (hwaddr_aton(cmd, addr))
5796 return -1;
5797
5798 pos = cmd + 17;
5799 if (*pos != ' ')
5800 return -1;
5801 pos++;
5802
5803 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005804 pos2 = os_strstr(pos, " persistent=");
5805 if (pos2) {
5806 struct wpa_ssid *ssid;
5807 persistent_id = atoi(pos2 + 12);
5808 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
5809 if (ssid == NULL || ssid->disabled != 2 ||
5810 ssid->mode != WPAS_MODE_P2P_GO) {
5811 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
5812 "SSID id=%d for persistent P2P group (GO)",
5813 persistent_id);
5814 return -1;
5815 }
5816 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005817 join = os_strstr(pos, " join") != NULL;
5818 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005819 automatic = os_strstr(pos, " auto") != NULL;
5820 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005821 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
5822 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
5823 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08005824 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005825 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005826
5827 pos2 = os_strstr(pos, " go_intent=");
5828 if (pos2) {
5829 pos2 += 11;
5830 go_intent = atoi(pos2);
5831 if (go_intent < 0 || go_intent > 15)
5832 return -1;
5833 }
5834
5835 pos2 = os_strstr(pos, " freq=");
5836 if (pos2) {
5837 pos2 += 6;
5838 freq = atoi(pos2);
5839 if (freq <= 0)
5840 return -1;
5841 }
5842
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005843 pos2 = os_strstr(pos, " freq2=");
5844 if (pos2)
5845 freq2 = atoi(pos2 + 7);
5846
5847 pos2 = os_strstr(pos, " max_oper_chwidth=");
5848 if (pos2)
5849 chwidth = atoi(pos2 + 18);
5850
5851 max_oper_chwidth = parse_freq(chwidth, freq2);
5852 if (max_oper_chwidth < 0)
5853 return -1;
5854
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005855 pos2 = os_strstr(pos, " ssid=");
5856 if (pos2) {
5857 char *end;
5858
5859 pos2 += 6;
5860 end = os_strchr(pos2, ' ');
5861 if (!end)
5862 group_ssid_len = os_strlen(pos2) / 2;
5863 else
5864 group_ssid_len = (end - pos2) / 2;
5865 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
5866 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
5867 return -1;
5868 group_ssid = _group_ssid;
5869 }
5870
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005871 if (os_strncmp(pos, "pin", 3) == 0) {
5872 /* Request random PIN (to be displayed) and enable the PIN */
5873 wps_method = WPS_PIN_DISPLAY;
5874 } else if (os_strncmp(pos, "pbc", 3) == 0) {
5875 wps_method = WPS_PBC;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005876 } else if (os_strstr(pos, "p2ps") != NULL) {
5877 wps_method = WPS_P2PS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005878 } else {
5879 pin = pos;
5880 pos = os_strchr(pin, ' ');
5881 wps_method = WPS_PIN_KEYPAD;
5882 if (pos) {
5883 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005884 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005885 wps_method = WPS_PIN_DISPLAY;
5886 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005887 if (!wps_pin_str_valid(pin)) {
5888 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
5889 return 17;
5890 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005891 }
5892
5893 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005894 persistent_group, automatic, join,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005895 auth, go_intent, freq, freq2, persistent_id,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005896 pd, ht40, vht, max_oper_chwidth, he, edmg,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005897 group_ssid, group_ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005898 if (new_pin == -2) {
5899 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5900 return 25;
5901 }
5902 if (new_pin == -3) {
5903 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5904 return 25;
5905 }
5906 if (new_pin < 0)
5907 return -1;
5908 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
5909 ret = os_snprintf(buf, buflen, "%08d", new_pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005910 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005911 return -1;
5912 return ret;
5913 }
5914
5915 os_memcpy(buf, "OK\n", 3);
5916 return 3;
5917}
5918
5919
5920static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
5921{
5922 unsigned int timeout = atoi(cmd);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005923 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5924 wpa_dbg(wpa_s, MSG_INFO,
5925 "Reject P2P_LISTEN since interface is disabled");
5926 return -1;
5927 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005928 return wpas_p2p_listen(wpa_s, timeout);
5929}
5930
5931
5932static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
5933{
5934 u8 addr[ETH_ALEN];
5935 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005936 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005937
Dmitry Shmidt04949592012-07-19 12:16:46 -07005938 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005939
5940 if (hwaddr_aton(cmd, addr))
5941 return -1;
5942
5943 pos = cmd + 17;
5944 if (*pos != ' ')
5945 return -1;
5946 pos++;
5947
Dmitry Shmidt04949592012-07-19 12:16:46 -07005948 if (os_strstr(pos, " join") != NULL)
5949 use = WPAS_P2P_PD_FOR_JOIN;
5950 else if (os_strstr(pos, " auto") != NULL)
5951 use = WPAS_P2P_PD_AUTO;
5952
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005953 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005954}
5955
5956
5957static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
5958 size_t buflen)
5959{
5960 struct wpa_ssid *ssid = wpa_s->current_ssid;
5961
5962 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
5963 ssid->passphrase == NULL)
5964 return -1;
5965
5966 os_strlcpy(buf, ssid->passphrase, buflen);
5967 return os_strlen(buf);
5968}
5969
5970
5971static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
5972 char *buf, size_t buflen)
5973{
5974 u64 ref;
5975 int res;
5976 u8 dst_buf[ETH_ALEN], *dst;
5977 struct wpabuf *tlvs;
5978 char *pos;
5979 size_t len;
5980
5981 if (hwaddr_aton(cmd, dst_buf))
5982 return -1;
5983 dst = dst_buf;
5984 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
5985 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
5986 dst = NULL;
5987 pos = cmd + 17;
5988 if (*pos != ' ')
5989 return -1;
5990 pos++;
5991
5992 if (os_strncmp(pos, "upnp ", 5) == 0) {
5993 u8 version;
5994 pos += 5;
5995 if (hexstr2bin(pos, &version, 1) < 0)
5996 return -1;
5997 pos += 2;
5998 if (*pos != ' ')
5999 return -1;
6000 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006001 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006002#ifdef CONFIG_WIFI_DISPLAY
6003 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
6004 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
6005#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006006 } else if (os_strncmp(pos, "asp ", 4) == 0) {
6007 char *svc_str;
6008 char *svc_info = NULL;
6009 u32 id;
6010
6011 pos += 4;
6012 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
6013 return -1;
6014
6015 pos = os_strchr(pos, ' ');
6016 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
6017 return -1;
6018
6019 svc_str = pos + 1;
6020
6021 pos = os_strchr(svc_str, ' ');
6022
6023 if (pos)
6024 *pos++ = '\0';
6025
6026 /* All remaining data is the svc_info string */
6027 if (pos && pos[0] && pos[0] != ' ') {
6028 len = os_strlen(pos);
6029
6030 /* Unescape in place */
6031 len = utf8_unescape(pos, len, pos, len);
6032 if (len > 0xff)
6033 return -1;
6034
6035 svc_info = pos;
6036 }
6037
6038 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
6039 svc_str, svc_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006040 } else {
6041 len = os_strlen(pos);
6042 if (len & 1)
6043 return -1;
6044 len /= 2;
6045 tlvs = wpabuf_alloc(len);
6046 if (tlvs == NULL)
6047 return -1;
6048 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
6049 wpabuf_free(tlvs);
6050 return -1;
6051 }
6052
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006053 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006054 wpabuf_free(tlvs);
6055 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006056 if (ref == 0)
6057 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006058 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006059 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006060 return -1;
6061 return res;
6062}
6063
6064
6065static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
6066 char *cmd)
6067{
6068 long long unsigned val;
6069 u64 req;
6070 if (sscanf(cmd, "%llx", &val) != 1)
6071 return -1;
6072 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006073 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006074}
6075
6076
6077static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
6078{
6079 int freq;
6080 u8 dst[ETH_ALEN];
6081 u8 dialog_token;
6082 struct wpabuf *resp_tlvs;
6083 char *pos, *pos2;
6084 size_t len;
6085
6086 pos = os_strchr(cmd, ' ');
6087 if (pos == NULL)
6088 return -1;
6089 *pos++ = '\0';
6090 freq = atoi(cmd);
6091 if (freq == 0)
6092 return -1;
6093
6094 if (hwaddr_aton(pos, dst))
6095 return -1;
6096 pos += 17;
6097 if (*pos != ' ')
6098 return -1;
6099 pos++;
6100
6101 pos2 = os_strchr(pos, ' ');
6102 if (pos2 == NULL)
6103 return -1;
6104 *pos2++ = '\0';
6105 dialog_token = atoi(pos);
6106
6107 len = os_strlen(pos2);
6108 if (len & 1)
6109 return -1;
6110 len /= 2;
6111 resp_tlvs = wpabuf_alloc(len);
6112 if (resp_tlvs == NULL)
6113 return -1;
6114 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
6115 wpabuf_free(resp_tlvs);
6116 return -1;
6117 }
6118
6119 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
6120 wpabuf_free(resp_tlvs);
6121 return 0;
6122}
6123
6124
6125static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
6126 char *cmd)
6127{
Dmitry Shmidt04949592012-07-19 12:16:46 -07006128 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
6129 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006130 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
6131 return 0;
6132}
6133
6134
6135static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
6136 char *cmd)
6137{
6138 char *pos;
6139 size_t len;
6140 struct wpabuf *query, *resp;
6141
6142 pos = os_strchr(cmd, ' ');
6143 if (pos == NULL)
6144 return -1;
6145 *pos++ = '\0';
6146
6147 len = os_strlen(cmd);
6148 if (len & 1)
6149 return -1;
6150 len /= 2;
6151 query = wpabuf_alloc(len);
6152 if (query == NULL)
6153 return -1;
6154 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6155 wpabuf_free(query);
6156 return -1;
6157 }
6158
6159 len = os_strlen(pos);
6160 if (len & 1) {
6161 wpabuf_free(query);
6162 return -1;
6163 }
6164 len /= 2;
6165 resp = wpabuf_alloc(len);
6166 if (resp == NULL) {
6167 wpabuf_free(query);
6168 return -1;
6169 }
6170 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
6171 wpabuf_free(query);
6172 wpabuf_free(resp);
6173 return -1;
6174 }
6175
6176 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
6177 wpabuf_free(query);
6178 wpabuf_free(resp);
6179 return -1;
6180 }
6181 return 0;
6182}
6183
6184
6185static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6186{
6187 char *pos;
6188 u8 version;
6189
6190 pos = os_strchr(cmd, ' ');
6191 if (pos == NULL)
6192 return -1;
6193 *pos++ = '\0';
6194
6195 if (hexstr2bin(cmd, &version, 1) < 0)
6196 return -1;
6197
6198 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
6199}
6200
6201
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006202static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
6203 u8 replace, char *cmd)
6204{
6205 char *pos;
6206 char *adv_str;
6207 u32 auto_accept, adv_id, svc_state, config_methods;
6208 char *svc_info = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006209 char *cpt_prio_str;
6210 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006211
6212 pos = os_strchr(cmd, ' ');
6213 if (pos == NULL)
6214 return -1;
6215 *pos++ = '\0';
6216
6217 /* Auto-Accept value is mandatory, and must be one of the
6218 * single values (0, 1, 2, 4) */
6219 auto_accept = atoi(cmd);
6220 switch (auto_accept) {
6221 case P2PS_SETUP_NONE: /* No auto-accept */
6222 case P2PS_SETUP_NEW:
6223 case P2PS_SETUP_CLIENT:
6224 case P2PS_SETUP_GROUP_OWNER:
6225 break;
6226 default:
6227 return -1;
6228 }
6229
6230 /* Advertisement ID is mandatory */
6231 cmd = pos;
6232 pos = os_strchr(cmd, ' ');
6233 if (pos == NULL)
6234 return -1;
6235 *pos++ = '\0';
6236
6237 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6238 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
6239 return -1;
6240
6241 /* Only allow replacements if exist, and adds if not */
6242 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
6243 if (!replace)
6244 return -1;
6245 } else {
6246 if (replace)
6247 return -1;
6248 }
6249
6250 /* svc_state between 0 - 0xff is mandatory */
6251 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
6252 return -1;
6253
6254 pos = os_strchr(pos, ' ');
6255 if (pos == NULL)
6256 return -1;
6257
6258 /* config_methods is mandatory */
6259 pos++;
6260 if (sscanf(pos, "%x", &config_methods) != 1)
6261 return -1;
6262
6263 if (!(config_methods &
6264 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
6265 return -1;
6266
6267 pos = os_strchr(pos, ' ');
6268 if (pos == NULL)
6269 return -1;
6270
6271 pos++;
6272 adv_str = pos;
6273
6274 /* Advertisement string is mandatory */
6275 if (!pos[0] || pos[0] == ' ')
6276 return -1;
6277
6278 /* Terminate svc string */
6279 pos = os_strchr(pos, ' ');
6280 if (pos != NULL)
6281 *pos++ = '\0';
6282
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006283 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6284 if (cpt_prio_str) {
6285 pos = os_strchr(pos, ' ');
6286 if (pos != NULL)
6287 *pos++ = '\0';
6288
6289 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6290 return -1;
6291 } else {
6292 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6293 cpt_prio[1] = 0;
6294 }
6295
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006296 /* Service and Response Information are optional */
6297 if (pos && pos[0]) {
6298 size_t len;
6299
6300 /* Note the bare ' included, which cannot exist legally
6301 * in unescaped string. */
6302 svc_info = os_strstr(pos, "svc_info='");
6303
6304 if (svc_info) {
6305 svc_info += 9;
6306 len = os_strlen(svc_info);
6307 utf8_unescape(svc_info, len, svc_info, len);
6308 }
6309 }
6310
6311 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6312 (u8) svc_state, (u16) config_methods,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006313 svc_info, cpt_prio);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006314}
6315
6316
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006317static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6318{
6319 char *pos;
6320
6321 pos = os_strchr(cmd, ' ');
6322 if (pos == NULL)
6323 return -1;
6324 *pos++ = '\0';
6325
6326 if (os_strcmp(cmd, "bonjour") == 0)
6327 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6328 if (os_strcmp(cmd, "upnp") == 0)
6329 return p2p_ctrl_service_add_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006330 if (os_strcmp(cmd, "asp") == 0)
6331 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006332 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6333 return -1;
6334}
6335
6336
6337static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6338 char *cmd)
6339{
6340 size_t len;
6341 struct wpabuf *query;
6342 int ret;
6343
6344 len = os_strlen(cmd);
6345 if (len & 1)
6346 return -1;
6347 len /= 2;
6348 query = wpabuf_alloc(len);
6349 if (query == NULL)
6350 return -1;
6351 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6352 wpabuf_free(query);
6353 return -1;
6354 }
6355
6356 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6357 wpabuf_free(query);
6358 return ret;
6359}
6360
6361
6362static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6363{
6364 char *pos;
6365 u8 version;
6366
6367 pos = os_strchr(cmd, ' ');
6368 if (pos == NULL)
6369 return -1;
6370 *pos++ = '\0';
6371
6372 if (hexstr2bin(cmd, &version, 1) < 0)
6373 return -1;
6374
6375 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6376}
6377
6378
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006379static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6380{
6381 u32 adv_id;
6382
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07006383 if (os_strcmp(cmd, "all") == 0) {
6384 wpas_p2p_service_flush_asp(wpa_s);
6385 return 0;
6386 }
6387
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006388 if (sscanf(cmd, "%x", &adv_id) != 1)
6389 return -1;
6390
6391 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6392}
6393
6394
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006395static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6396{
6397 char *pos;
6398
6399 pos = os_strchr(cmd, ' ');
6400 if (pos == NULL)
6401 return -1;
6402 *pos++ = '\0';
6403
6404 if (os_strcmp(cmd, "bonjour") == 0)
6405 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6406 if (os_strcmp(cmd, "upnp") == 0)
6407 return p2p_ctrl_service_del_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006408 if (os_strcmp(cmd, "asp") == 0)
6409 return p2p_ctrl_service_del_asp(wpa_s, pos);
6410 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6411 return -1;
6412}
6413
6414
6415static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6416{
6417 char *pos;
6418
6419 pos = os_strchr(cmd, ' ');
6420 if (pos == NULL)
6421 return -1;
6422 *pos++ = '\0';
6423
6424 if (os_strcmp(cmd, "asp") == 0)
6425 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6426
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006427 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6428 return -1;
6429}
6430
6431
6432static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
6433{
6434 u8 addr[ETH_ALEN];
6435
6436 /* <addr> */
6437
6438 if (hwaddr_aton(cmd, addr))
6439 return -1;
6440
6441 return wpas_p2p_reject(wpa_s, addr);
6442}
6443
6444
6445static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
6446{
6447 char *pos;
6448 int id;
6449 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006450 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006451 int freq = 0, pref_freq = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08006452 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006453 int edmg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006454
6455 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006456 pos = os_strstr(cmd, " peer=");
6457 if (pos) {
6458 pos += 6;
6459 if (hwaddr_aton(pos, peer))
6460 return -1;
6461 _peer = peer;
6462 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006463 ssid = wpa_config_get_network(wpa_s->conf, id);
6464 if (ssid == NULL || ssid->disabled != 2) {
6465 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6466 "for persistent P2P group",
6467 id);
6468 return -1;
6469 }
6470
Jouni Malinen31be0a42012-08-31 21:20:51 +03006471 pos = os_strstr(cmd, " freq=");
6472 if (pos) {
6473 pos += 6;
6474 freq = atoi(pos);
6475 if (freq <= 0)
6476 return -1;
6477 }
6478
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006479 pos = os_strstr(cmd, " pref=");
6480 if (pos) {
6481 pos += 6;
6482 pref_freq = atoi(pos);
6483 if (pref_freq <= 0)
6484 return -1;
6485 }
6486
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006487 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6488 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6489 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006490 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006491 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Jouni Malinen31be0a42012-08-31 21:20:51 +03006492
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006493 pos = os_strstr(cmd, "freq2=");
6494 if (pos)
6495 freq2 = atoi(pos + 6);
6496
6497 pos = os_strstr(cmd, " max_oper_chwidth=");
6498 if (pos)
6499 chwidth = atoi(pos + 18);
6500
6501 max_oper_chwidth = parse_freq(chwidth, freq2);
6502 if (max_oper_chwidth < 0)
6503 return -1;
6504
6505 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006506 max_oper_chwidth, pref_freq, he, edmg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006507}
6508
6509
6510static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
6511{
6512 char *pos;
6513 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
6514
6515 pos = os_strstr(cmd, " peer=");
6516 if (!pos)
6517 return -1;
6518
6519 *pos = '\0';
6520 pos += 6;
6521 if (hwaddr_aton(pos, peer)) {
6522 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
6523 return -1;
6524 }
6525
6526 pos = os_strstr(pos, " go_dev_addr=");
6527 if (pos) {
6528 pos += 13;
6529 if (hwaddr_aton(pos, go_dev_addr)) {
6530 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
6531 pos);
6532 return -1;
6533 }
6534 go_dev = go_dev_addr;
6535 }
6536
6537 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
6538}
6539
6540
6541static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
6542{
6543 if (os_strncmp(cmd, "persistent=", 11) == 0)
6544 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
6545 if (os_strncmp(cmd, "group=", 6) == 0)
6546 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
6547
6548 return -1;
6549}
6550
6551
6552static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006553 int id, int freq, int vht_center_freq2,
Hai Shalom74f70d42019-02-11 14:42:39 -08006554 int ht40, int vht, int vht_chwidth,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006555 int he, int edmg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006556{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006557 struct wpa_ssid *ssid;
6558
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006559 ssid = wpa_config_get_network(wpa_s->conf, id);
6560 if (ssid == NULL || ssid->disabled != 2) {
6561 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6562 "for persistent P2P group",
6563 id);
6564 return -1;
6565 }
6566
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006567 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
6568 vht_center_freq2, 0, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006569 vht_chwidth, he, edmg,
6570 NULL, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006571}
6572
6573
6574static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
6575{
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006576 int freq = 0, persistent = 0, group_id = -1;
6577 int vht = wpa_s->conf->p2p_go_vht;
6578 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006579 int he = wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006580 int edmg = wpa_s->conf->p2p_go_edmg;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006581 int max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006582 char *token, *context = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006583#ifdef CONFIG_ACS
6584 int acs = 0;
6585#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006586
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006587 while ((token = str_token(cmd, " ", &context))) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07006588 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006589 sscanf(token, "persistent=%d", &group_id) == 1 ||
6590 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006591 continue;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006592#ifdef CONFIG_ACS
6593 } else if (os_strcmp(token, "freq=acs") == 0) {
6594 acs = 1;
6595#endif /* CONFIG_ACS */
6596 } else if (sscanf(token, "freq=%d", &freq) == 1) {
6597 continue;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006598 } else if (os_strcmp(token, "ht40") == 0) {
6599 ht40 = 1;
6600 } else if (os_strcmp(token, "vht") == 0) {
6601 vht = 1;
6602 ht40 = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08006603 } else if (os_strcmp(token, "he") == 0) {
6604 he = 1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006605 } else if (os_strcmp(token, "edmg") == 0) {
6606 edmg = 1;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006607 } else if (os_strcmp(token, "persistent") == 0) {
6608 persistent = 1;
6609 } else {
6610 wpa_printf(MSG_DEBUG,
6611 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6612 token);
6613 return -1;
6614 }
6615 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006616
Roshan Pius3a1667e2018-07-03 15:17:14 -07006617#ifdef CONFIG_ACS
6618 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
6619 (acs || freq == 2 || freq == 5)) {
6620 if (freq == 2 && wpa_s->best_24_freq <= 0) {
6621 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
6622 wpa_s->p2p_go_do_acs = 1;
6623 freq = 0;
6624 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
6625 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
6626 wpa_s->p2p_go_do_acs = 1;
6627 freq = 0;
6628 } else {
6629 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
6630 wpa_s->p2p_go_do_acs = 1;
6631 }
Hai Shalom021b0b52019-04-10 11:17:58 -07006632 } else {
6633 wpa_s->p2p_go_do_acs = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006634 }
6635#endif /* CONFIG_ACS */
6636
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006637 max_oper_chwidth = parse_freq(chwidth, freq2);
6638 if (max_oper_chwidth < 0)
6639 return -1;
6640
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006641 if (group_id >= 0)
6642 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006643 freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006644 max_oper_chwidth, he,
6645 edmg);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006646
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006647 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006648 max_oper_chwidth, he, edmg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006649}
6650
6651
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006652static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
6653 char *buf, size_t buflen)
6654{
6655 u8 dev_addr[ETH_ALEN];
6656 struct wpa_ssid *ssid;
6657 int res;
6658 const u8 *iaddr;
6659
6660 ssid = wpa_s->current_ssid;
6661 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
6662 hwaddr_aton(cmd, dev_addr))
6663 return -1;
6664
6665 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
6666 if (!iaddr)
6667 return -1;
6668 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
6669 if (os_snprintf_error(buflen, res))
6670 return -1;
6671 return res;
6672}
6673
6674
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006675static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
6676 const u8 *p2p_dev_addr)
6677{
6678 struct wpa_supplicant *wpa_s;
6679
6680 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6681 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
6682 return 1;
6683 }
6684
6685 return 0;
6686}
6687
6688
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006689static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
6690 char *buf, size_t buflen)
6691{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006692 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006693 int next, res;
6694 const struct p2p_peer_info *info;
6695 char *pos, *end;
6696 char devtype[WPS_DEV_TYPE_BUFSIZE];
6697 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006698 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006699
6700 if (!wpa_s->global->p2p)
6701 return -1;
6702
6703 if (os_strcmp(cmd, "FIRST") == 0) {
6704 addr_ptr = NULL;
6705 next = 0;
6706 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
6707 if (hwaddr_aton(cmd + 5, addr) < 0)
6708 return -1;
6709 addr_ptr = addr;
6710 next = 1;
6711 } else {
6712 if (hwaddr_aton(cmd, addr) < 0)
6713 return -1;
6714 addr_ptr = addr;
6715 next = 0;
6716 }
6717
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006718 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
6719 if (info == NULL)
6720 return -1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006721 group_capab = info->group_capab;
6722
6723 if (group_capab &&
6724 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
6725 wpa_printf(MSG_DEBUG,
6726 "P2P: Could not find any BSS with p2p_dev_addr "
6727 MACSTR ", hence override group_capab from 0x%x to 0",
6728 MAC2STR(info->p2p_device_addr), group_capab);
6729 group_capab = 0;
6730 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006731
6732 pos = buf;
6733 end = buf + buflen;
6734
6735 res = os_snprintf(pos, end - pos, MACSTR "\n"
6736 "pri_dev_type=%s\n"
6737 "device_name=%s\n"
6738 "manufacturer=%s\n"
6739 "model_name=%s\n"
6740 "model_number=%s\n"
6741 "serial_number=%s\n"
6742 "config_methods=0x%x\n"
6743 "dev_capab=0x%x\n"
6744 "group_capab=0x%x\n"
6745 "level=%d\n",
6746 MAC2STR(info->p2p_device_addr),
6747 wps_dev_type_bin2str(info->pri_dev_type,
6748 devtype, sizeof(devtype)),
6749 info->device_name,
6750 info->manufacturer,
6751 info->model_name,
6752 info->model_number,
6753 info->serial_number,
6754 info->config_methods,
6755 info->dev_capab,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006756 group_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006757 info->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006758 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006759 return pos - buf;
6760 pos += res;
6761
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006762 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
6763 {
6764 const u8 *t;
6765 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
6766 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
6767 wps_dev_type_bin2str(t, devtype,
6768 sizeof(devtype)));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006769 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006770 return pos - buf;
6771 pos += res;
6772 }
6773
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006774 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006775 if (ssid) {
6776 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006777 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006778 return pos - buf;
6779 pos += res;
6780 }
6781
6782 res = p2p_get_peer_info_txt(info, pos, end - pos);
6783 if (res < 0)
6784 return pos - buf;
6785 pos += res;
6786
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006787 if (info->vendor_elems) {
6788 res = os_snprintf(pos, end - pos, "vendor_elems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006789 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006790 return pos - buf;
6791 pos += res;
6792
6793 pos += wpa_snprintf_hex(pos, end - pos,
6794 wpabuf_head(info->vendor_elems),
6795 wpabuf_len(info->vendor_elems));
6796
6797 res = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006798 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006799 return pos - buf;
6800 pos += res;
6801 }
6802
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006803 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006804}
6805
6806
Dmitry Shmidt04949592012-07-19 12:16:46 -07006807static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
6808 const char *param)
6809{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006810 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006811
6812 if (wpa_s->global->p2p == NULL)
6813 return -1;
6814
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006815 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
6816 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006817
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006818 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
6819 struct wpa_freq_range *freq;
6820 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07006821 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006822 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006823 }
6824
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006825 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006826 return 0;
6827}
6828
6829
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006830static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
6831{
6832 char *param;
6833
6834 if (wpa_s->global->p2p == NULL)
6835 return -1;
6836
6837 param = os_strchr(cmd, ' ');
6838 if (param == NULL)
6839 return -1;
6840 *param++ = '\0';
6841
6842 if (os_strcmp(cmd, "discoverability") == 0) {
6843 p2p_set_client_discoverability(wpa_s->global->p2p,
6844 atoi(param));
6845 return 0;
6846 }
6847
6848 if (os_strcmp(cmd, "managed") == 0) {
6849 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
6850 return 0;
6851 }
6852
6853 if (os_strcmp(cmd, "listen_channel") == 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08006854 char *pos;
6855 u8 channel, op_class;
6856
6857 channel = atoi(param);
6858 pos = os_strchr(param, ' ');
6859 op_class = pos ? atoi(pos) : 81;
6860
6861 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
6862 channel, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006863 }
6864
6865 if (os_strcmp(cmd, "ssid_postfix") == 0) {
6866 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
6867 os_strlen(param));
6868 }
6869
6870 if (os_strcmp(cmd, "noa") == 0) {
6871 char *pos;
6872 int count, start, duration;
6873 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6874 count = atoi(param);
6875 pos = os_strchr(param, ',');
6876 if (pos == NULL)
6877 return -1;
6878 pos++;
6879 start = atoi(pos);
6880 pos = os_strchr(pos, ',');
6881 if (pos == NULL)
6882 return -1;
6883 pos++;
6884 duration = atoi(pos);
6885 if (count < 0 || count > 255 || start < 0 || duration < 0)
6886 return -1;
6887 if (count == 0 && duration > 0)
6888 return -1;
6889 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6890 "start=%d duration=%d", count, start, duration);
6891 return wpas_p2p_set_noa(wpa_s, count, start, duration);
6892 }
6893
6894 if (os_strcmp(cmd, "ps") == 0)
6895 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
6896
6897 if (os_strcmp(cmd, "oppps") == 0)
6898 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
6899
6900 if (os_strcmp(cmd, "ctwindow") == 0)
6901 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
6902
6903 if (os_strcmp(cmd, "disabled") == 0) {
6904 wpa_s->global->p2p_disabled = atoi(param);
6905 wpa_printf(MSG_DEBUG, "P2P functionality %s",
6906 wpa_s->global->p2p_disabled ?
6907 "disabled" : "enabled");
6908 if (wpa_s->global->p2p_disabled) {
6909 wpas_p2p_stop_find(wpa_s);
6910 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6911 p2p_flush(wpa_s->global->p2p);
6912 }
6913 return 0;
6914 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006915
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006916 if (os_strcmp(cmd, "conc_pref") == 0) {
6917 if (os_strcmp(param, "sta") == 0)
6918 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
6919 else if (os_strcmp(param, "p2p") == 0)
6920 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006921 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006922 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006923 return -1;
6924 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006925 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07006926 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006927 return 0;
6928 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006929
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006930 if (os_strcmp(cmd, "force_long_sd") == 0) {
6931 wpa_s->force_long_sd = atoi(param);
6932 return 0;
6933 }
6934
6935 if (os_strcmp(cmd, "peer_filter") == 0) {
6936 u8 addr[ETH_ALEN];
6937 if (hwaddr_aton(param, addr))
6938 return -1;
6939 p2p_set_peer_filter(wpa_s->global->p2p, addr);
6940 return 0;
6941 }
6942
6943 if (os_strcmp(cmd, "cross_connect") == 0)
6944 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
6945
6946 if (os_strcmp(cmd, "go_apsd") == 0) {
6947 if (os_strcmp(param, "disable") == 0)
6948 wpa_s->set_ap_uapsd = 0;
6949 else {
6950 wpa_s->set_ap_uapsd = 1;
6951 wpa_s->ap_uapsd = atoi(param);
6952 }
6953 return 0;
6954 }
6955
6956 if (os_strcmp(cmd, "client_apsd") == 0) {
6957 if (os_strcmp(param, "disable") == 0)
6958 wpa_s->set_sta_uapsd = 0;
6959 else {
6960 int be, bk, vi, vo;
6961 char *pos;
6962 /* format: BE,BK,VI,VO;max SP Length */
6963 be = atoi(param);
6964 pos = os_strchr(param, ',');
6965 if (pos == NULL)
6966 return -1;
6967 pos++;
6968 bk = atoi(pos);
6969 pos = os_strchr(pos, ',');
6970 if (pos == NULL)
6971 return -1;
6972 pos++;
6973 vi = atoi(pos);
6974 pos = os_strchr(pos, ',');
6975 if (pos == NULL)
6976 return -1;
6977 pos++;
6978 vo = atoi(pos);
6979 /* ignore max SP Length for now */
6980
6981 wpa_s->set_sta_uapsd = 1;
6982 wpa_s->sta_uapsd = 0;
6983 if (be)
6984 wpa_s->sta_uapsd |= BIT(0);
6985 if (bk)
6986 wpa_s->sta_uapsd |= BIT(1);
6987 if (vi)
6988 wpa_s->sta_uapsd |= BIT(2);
6989 if (vo)
6990 wpa_s->sta_uapsd |= BIT(3);
6991 }
6992 return 0;
6993 }
6994
Dmitry Shmidt04949592012-07-19 12:16:46 -07006995 if (os_strcmp(cmd, "disallow_freq") == 0)
6996 return p2p_ctrl_disallow_freq(wpa_s, param);
6997
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006998 if (os_strcmp(cmd, "disc_int") == 0) {
6999 int min_disc_int, max_disc_int, max_disc_tu;
7000 char *pos;
7001
7002 pos = param;
7003
7004 min_disc_int = atoi(pos);
7005 pos = os_strchr(pos, ' ');
7006 if (pos == NULL)
7007 return -1;
7008 *pos++ = '\0';
7009
7010 max_disc_int = atoi(pos);
7011 pos = os_strchr(pos, ' ');
7012 if (pos == NULL)
7013 return -1;
7014 *pos++ = '\0';
7015
7016 max_disc_tu = atoi(pos);
7017
7018 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
7019 max_disc_int, max_disc_tu);
7020 }
7021
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007022 if (os_strcmp(cmd, "per_sta_psk") == 0) {
7023 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
7024 return 0;
7025 }
7026
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007027#ifdef CONFIG_WPS_NFC
7028 if (os_strcmp(cmd, "nfc_tag") == 0)
7029 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
7030#endif /* CONFIG_WPS_NFC */
7031
7032 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
7033 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
7034 return 0;
7035 }
7036
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007037 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
7038 int op_class, chan;
7039
7040 op_class = atoi(param);
7041 param = os_strchr(param, ':');
7042 if (!param)
7043 return -1;
7044 param++;
7045 chan = atoi(param);
7046 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
7047 chan);
7048 return 0;
7049 }
7050
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007051 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
7052 cmd);
7053
7054 return -1;
7055}
7056
7057
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007058static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
7059{
7060 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
7061 wpa_s->force_long_sd = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007062
7063#ifdef CONFIG_TESTING_OPTIONS
7064 os_free(wpa_s->get_pref_freq_list_override);
7065 wpa_s->get_pref_freq_list_override = NULL;
7066#endif /* CONFIG_TESTING_OPTIONS */
7067
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007068 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007069 wpa_s->parent->p2ps_method_config_any = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007070 if (wpa_s->global->p2p)
7071 p2p_flush(wpa_s->global->p2p);
7072}
7073
7074
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007075static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
7076{
7077 char *pos, *pos2;
7078 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
7079
7080 if (cmd[0]) {
7081 pos = os_strchr(cmd, ' ');
7082 if (pos == NULL)
7083 return -1;
7084 *pos++ = '\0';
7085 dur1 = atoi(cmd);
7086
7087 pos2 = os_strchr(pos, ' ');
7088 if (pos2)
7089 *pos2++ = '\0';
7090 int1 = atoi(pos);
7091 } else
7092 pos2 = NULL;
7093
7094 if (pos2) {
7095 pos = os_strchr(pos2, ' ');
7096 if (pos == NULL)
7097 return -1;
7098 *pos++ = '\0';
7099 dur2 = atoi(pos2);
7100 int2 = atoi(pos);
7101 }
7102
7103 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
7104}
7105
7106
7107static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
7108{
7109 char *pos;
7110 unsigned int period = 0, interval = 0;
7111
7112 if (cmd[0]) {
7113 pos = os_strchr(cmd, ' ');
7114 if (pos == NULL)
7115 return -1;
7116 *pos++ = '\0';
7117 period = atoi(cmd);
7118 interval = atoi(pos);
7119 }
7120
7121 return wpas_p2p_ext_listen(wpa_s, period, interval);
7122}
7123
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007124
7125static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
7126{
7127 const char *pos;
7128 u8 peer[ETH_ALEN];
7129 int iface_addr = 0;
7130
7131 pos = cmd;
7132 if (os_strncmp(pos, "iface=", 6) == 0) {
7133 iface_addr = 1;
7134 pos += 6;
7135 }
7136 if (hwaddr_aton(pos, peer))
7137 return -1;
7138
7139 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
7140 return 0;
7141}
7142
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007143
7144static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
7145{
7146 int freq = 0, period = 0, interval = 0, count = 0;
7147
7148 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
7149 {
7150 wpa_printf(MSG_DEBUG,
7151 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
7152 return -1;
7153 }
7154
7155 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
7156}
7157
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007158#endif /* CONFIG_P2P */
7159
7160
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007161static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
7162{
7163 struct wpa_freq_range_list ranges;
7164 int *freqs = NULL;
7165 struct hostapd_hw_modes *mode;
7166 u16 i;
7167
7168 if (wpa_s->hw.modes == NULL)
7169 return NULL;
7170
7171 os_memset(&ranges, 0, sizeof(ranges));
7172 if (freq_range_list_parse(&ranges, val) < 0)
7173 return NULL;
7174
7175 for (i = 0; i < wpa_s->hw.num_modes; i++) {
7176 int j;
7177
7178 mode = &wpa_s->hw.modes[i];
7179 for (j = 0; j < mode->num_channels; j++) {
7180 unsigned int freq;
7181
7182 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
7183 continue;
7184
7185 freq = mode->channels[j].freq;
7186 if (!freq_range_list_includes(&ranges, freq))
7187 continue;
7188
7189 int_array_add_unique(&freqs, freq);
7190 }
7191 }
7192
7193 os_free(ranges.range);
7194 return freqs;
7195}
7196
7197
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007198#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007199
7200static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
7201{
7202 int auto_sel = 0;
7203 int *freqs = NULL;
7204
7205 if (param) {
7206 char *pos;
7207
7208 auto_sel = os_strstr(param, "auto") != NULL;
7209
7210 pos = os_strstr(param, "freq=");
7211 if (pos) {
7212 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
7213 if (freqs == NULL)
7214 return -1;
7215 }
7216
7217 }
7218
7219 return interworking_select(wpa_s, auto_sel, freqs);
7220}
7221
7222
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007223static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
7224 int only_add)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007225{
7226 u8 bssid[ETH_ALEN];
7227 struct wpa_bss *bss;
7228
7229 if (hwaddr_aton(dst, bssid)) {
7230 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
7231 return -1;
7232 }
7233
Hai Shalomfdcde762020-04-02 11:19:20 -07007234 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007235 if (bss == NULL) {
7236 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
7237 MAC2STR(bssid));
7238 return -1;
7239 }
7240
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007241 if (bss->ssid_len == 0) {
7242 int found = 0;
7243
7244 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
7245 " does not have SSID information", MAC2STR(bssid));
7246
7247 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
7248 list) {
7249 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
7250 bss->ssid_len > 0) {
7251 found = 1;
7252 break;
7253 }
7254 }
7255
7256 if (!found)
7257 return -1;
7258 wpa_printf(MSG_DEBUG,
7259 "Found another matching BSS entry with SSID");
7260 }
7261
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007262 return interworking_connect(wpa_s, bss, only_add);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007263}
7264
7265
7266static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
7267{
7268 u8 dst_addr[ETH_ALEN];
7269 int used;
7270 char *pos;
7271#define MAX_ANQP_INFO_ID 100
7272 u16 id[MAX_ANQP_INFO_ID];
7273 size_t num_id = 0;
Dmitry Shmidt15907092014-03-25 10:42:57 -07007274 u32 subtypes = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007275 u32 mbo_subtypes = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007276
7277 used = hwaddr_aton2(dst, dst_addr);
7278 if (used < 0)
7279 return -1;
7280 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007281 if (*pos == ' ')
7282 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007283 while (num_id < MAX_ANQP_INFO_ID) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07007284 if (os_strncmp(pos, "hs20:", 5) == 0) {
7285#ifdef CONFIG_HS20
7286 int num = atoi(pos + 5);
7287 if (num <= 0 || num > 31)
7288 return -1;
7289 subtypes |= BIT(num);
7290#else /* CONFIG_HS20 */
7291 return -1;
7292#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007293 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7294#ifdef CONFIG_MBO
7295 int num = atoi(pos + 4);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007296
7297 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007298 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007299 mbo_subtypes |= BIT(num);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007300#else /* CONFIG_MBO */
7301 return -1;
7302#endif /* CONFIG_MBO */
Dmitry Shmidt15907092014-03-25 10:42:57 -07007303 } else {
7304 id[num_id] = atoi(pos);
7305 if (id[num_id])
7306 num_id++;
7307 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007308 pos = os_strchr(pos + 1, ',');
7309 if (pos == NULL)
7310 break;
7311 pos++;
7312 }
7313
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007314 if (num_id == 0 && !subtypes && !mbo_subtypes)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007315 return -1;
7316
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007317 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007318 mbo_subtypes);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007319}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007320
7321
7322static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7323{
7324 u8 dst_addr[ETH_ALEN];
7325 struct wpabuf *advproto, *query = NULL;
7326 int used, ret = -1;
7327 char *pos, *end;
7328 size_t len;
7329
7330 used = hwaddr_aton2(cmd, dst_addr);
7331 if (used < 0)
7332 return -1;
7333
7334 pos = cmd + used;
7335 while (*pos == ' ')
7336 pos++;
7337
7338 /* Advertisement Protocol ID */
7339 end = os_strchr(pos, ' ');
7340 if (end)
7341 len = end - pos;
7342 else
7343 len = os_strlen(pos);
7344 if (len & 0x01)
7345 return -1;
7346 len /= 2;
7347 if (len == 0)
7348 return -1;
7349 advproto = wpabuf_alloc(len);
7350 if (advproto == NULL)
7351 return -1;
7352 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7353 goto fail;
7354
7355 if (end) {
7356 /* Optional Query Request */
7357 pos = end + 1;
7358 while (*pos == ' ')
7359 pos++;
7360
7361 len = os_strlen(pos);
7362 if (len) {
7363 if (len & 0x01)
7364 goto fail;
7365 len /= 2;
7366 if (len == 0)
7367 goto fail;
7368 query = wpabuf_alloc(len);
7369 if (query == NULL)
7370 goto fail;
7371 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7372 goto fail;
7373 }
7374 }
7375
7376 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7377
7378fail:
7379 wpabuf_free(advproto);
7380 wpabuf_free(query);
7381
7382 return ret;
7383}
7384
7385
7386static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7387 size_t buflen)
7388{
7389 u8 addr[ETH_ALEN];
7390 int dialog_token;
7391 int used;
7392 char *pos;
7393 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007394 struct wpabuf *resp;
7395 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007396
7397 used = hwaddr_aton2(cmd, addr);
7398 if (used < 0)
7399 return -1;
7400
7401 pos = cmd + used;
7402 while (*pos == ' ')
7403 pos++;
7404 dialog_token = atoi(pos);
7405
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007406 if (wpa_s->last_gas_resp &&
7407 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
7408 dialog_token == wpa_s->last_gas_dialog_token)
7409 resp = wpa_s->last_gas_resp;
7410 else if (wpa_s->prev_gas_resp &&
7411 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
7412 dialog_token == wpa_s->prev_gas_dialog_token)
7413 resp = wpa_s->prev_gas_resp;
7414 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007415 return -1;
7416
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007417 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007418 start = 0;
7419 requested_len = resp_len;
7420
7421 pos = os_strchr(pos, ' ');
7422 if (pos) {
7423 start = atoi(pos);
7424 if (start > resp_len)
7425 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7426 pos = os_strchr(pos, ',');
7427 if (pos == NULL)
7428 return -1;
7429 pos++;
7430 requested_len = atoi(pos);
7431 if (start + requested_len > resp_len)
7432 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7433 }
7434
7435 if (requested_len * 2 + 1 > buflen)
7436 return os_snprintf(buf, buflen, "FAIL-Too long response");
7437
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007438 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
7439 requested_len);
7440
7441 if (start + requested_len == resp_len) {
7442 /*
7443 * Free memory by dropping the response after it has been
7444 * fetched.
7445 */
7446 if (resp == wpa_s->prev_gas_resp) {
7447 wpabuf_free(wpa_s->prev_gas_resp);
7448 wpa_s->prev_gas_resp = NULL;
7449 } else {
7450 wpabuf_free(wpa_s->last_gas_resp);
7451 wpa_s->last_gas_resp = NULL;
7452 }
7453 }
7454
7455 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007456}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007457#endif /* CONFIG_INTERWORKING */
7458
7459
Dmitry Shmidt04949592012-07-19 12:16:46 -07007460#ifdef CONFIG_HS20
7461
7462static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
7463{
7464 u8 dst_addr[ETH_ALEN];
7465 int used;
7466 char *pos;
7467 u32 subtypes = 0;
7468
7469 used = hwaddr_aton2(dst, dst_addr);
7470 if (used < 0)
7471 return -1;
7472 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007473 if (*pos == ' ')
7474 pos++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007475 for (;;) {
7476 int num = atoi(pos);
7477 if (num <= 0 || num > 31)
7478 return -1;
7479 subtypes |= BIT(num);
7480 pos = os_strchr(pos + 1, ',');
7481 if (pos == NULL)
7482 break;
7483 pos++;
7484 }
7485
7486 if (subtypes == 0)
7487 return -1;
7488
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007489 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007490}
7491
7492
7493static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7494 const u8 *addr, const char *realm)
7495{
7496 u8 *buf;
7497 size_t rlen, len;
7498 int ret;
7499
7500 rlen = os_strlen(realm);
7501 len = 3 + rlen;
7502 buf = os_malloc(len);
7503 if (buf == NULL)
7504 return -1;
7505 buf[0] = 1; /* NAI Home Realm Count */
7506 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
7507 buf[2] = rlen;
7508 os_memcpy(buf + 3, realm, rlen);
7509
7510 ret = hs20_anqp_send_req(wpa_s, addr,
7511 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007512 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007513
7514 os_free(buf);
7515
7516 return ret;
7517}
7518
7519
7520static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7521 char *dst)
7522{
7523 struct wpa_cred *cred = wpa_s->conf->cred;
7524 u8 dst_addr[ETH_ALEN];
7525 int used;
7526 u8 *buf;
7527 size_t len;
7528 int ret;
7529
7530 used = hwaddr_aton2(dst, dst_addr);
7531 if (used < 0)
7532 return -1;
7533
7534 while (dst[used] == ' ')
7535 used++;
7536 if (os_strncmp(dst + used, "realm=", 6) == 0)
7537 return hs20_nai_home_realm_list(wpa_s, dst_addr,
7538 dst + used + 6);
7539
7540 len = os_strlen(dst + used);
7541
7542 if (len == 0 && cred && cred->realm)
7543 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
7544
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07007545 if (len & 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07007546 return -1;
7547 len /= 2;
7548 buf = os_malloc(len);
7549 if (buf == NULL)
7550 return -1;
7551 if (hexstr2bin(dst + used, buf, len) < 0) {
7552 os_free(buf);
7553 return -1;
7554 }
7555
7556 ret = hs20_anqp_send_req(wpa_s, dst_addr,
7557 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007558 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007559 os_free(buf);
7560
7561 return ret;
7562}
7563
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007564
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007565static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
7566 int buflen)
7567{
7568 u8 dst_addr[ETH_ALEN];
7569 int used;
7570 char *ctx = NULL, *icon, *poffset, *psize;
7571
7572 used = hwaddr_aton2(cmd, dst_addr);
7573 if (used < 0)
7574 return -1;
7575 cmd += used;
7576
7577 icon = str_token(cmd, " ", &ctx);
7578 poffset = str_token(cmd, " ", &ctx);
7579 psize = str_token(cmd, " ", &ctx);
7580 if (!icon || !poffset || !psize)
7581 return -1;
7582
7583 wpa_s->fetch_osu_icon_in_progress = 0;
7584 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
7585 reply, buflen);
7586}
7587
7588
7589static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
7590{
7591 u8 dst_addr[ETH_ALEN];
7592 int used;
7593 char *icon;
7594
7595 if (!cmd[0])
7596 return hs20_del_icon(wpa_s, NULL, NULL);
7597
7598 used = hwaddr_aton2(cmd, dst_addr);
7599 if (used < 0)
7600 return -1;
7601
7602 while (cmd[used] == ' ')
7603 used++;
7604 icon = cmd[used] ? &cmd[used] : NULL;
7605
7606 return hs20_del_icon(wpa_s, dst_addr, icon);
7607}
7608
7609
7610static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007611{
7612 u8 dst_addr[ETH_ALEN];
7613 int used;
7614 char *icon;
7615
7616 used = hwaddr_aton2(cmd, dst_addr);
7617 if (used < 0)
7618 return -1;
7619
7620 while (cmd[used] == ' ')
7621 used++;
7622 icon = &cmd[used];
7623
7624 wpa_s->fetch_osu_icon_in_progress = 0;
7625 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007626 (u8 *) icon, os_strlen(icon), inmem);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007627}
7628
Dmitry Shmidt04949592012-07-19 12:16:46 -07007629#endif /* CONFIG_HS20 */
7630
7631
Dmitry Shmidt04949592012-07-19 12:16:46 -07007632#ifdef CONFIG_AUTOSCAN
7633
7634static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
7635 char *cmd)
7636{
7637 enum wpa_states state = wpa_s->wpa_state;
7638 char *new_params = NULL;
7639
7640 if (os_strlen(cmd) > 0) {
7641 new_params = os_strdup(cmd);
7642 if (new_params == NULL)
7643 return -1;
7644 }
7645
7646 os_free(wpa_s->conf->autoscan);
7647 wpa_s->conf->autoscan = new_params;
7648
7649 if (wpa_s->conf->autoscan == NULL)
7650 autoscan_deinit(wpa_s);
7651 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
7652 autoscan_init(wpa_s, 1);
7653 else if (state == WPA_SCANNING)
7654 wpa_supplicant_reinit_autoscan(wpa_s);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007655 else
7656 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
7657 wpa_supplicant_state_txt(state));
Dmitry Shmidt04949592012-07-19 12:16:46 -07007658
7659 return 0;
7660}
7661
7662#endif /* CONFIG_AUTOSCAN */
7663
7664
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007665#ifdef CONFIG_WNM
7666
7667static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
7668{
7669 int enter;
7670 int intval = 0;
7671 char *pos;
7672 int ret;
7673 struct wpabuf *tfs_req = NULL;
7674
7675 if (os_strncmp(cmd, "enter", 5) == 0)
7676 enter = 1;
7677 else if (os_strncmp(cmd, "exit", 4) == 0)
7678 enter = 0;
7679 else
7680 return -1;
7681
7682 pos = os_strstr(cmd, " interval=");
7683 if (pos)
7684 intval = atoi(pos + 10);
7685
7686 pos = os_strstr(cmd, " tfs_req=");
7687 if (pos) {
7688 char *end;
7689 size_t len;
7690 pos += 9;
7691 end = os_strchr(pos, ' ');
7692 if (end)
7693 len = end - pos;
7694 else
7695 len = os_strlen(pos);
7696 if (len & 1)
7697 return -1;
7698 len /= 2;
7699 tfs_req = wpabuf_alloc(len);
7700 if (tfs_req == NULL)
7701 return -1;
7702 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
7703 wpabuf_free(tfs_req);
7704 return -1;
7705 }
7706 }
7707
7708 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
7709 WNM_SLEEP_MODE_EXIT, intval,
7710 tfs_req);
7711 wpabuf_free(tfs_req);
7712
7713 return ret;
7714}
7715
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007716
7717static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
7718{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007719 int query_reason, list = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007720 char *btm_candidates = NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007721
7722 query_reason = atoi(cmd);
7723
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007724 cmd = os_strchr(cmd, ' ');
7725 if (cmd) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007726 if (os_strncmp(cmd, " list", 5) == 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007727 list = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007728 else
7729 btm_candidates = cmd;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007730 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007731
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007732 wpa_printf(MSG_DEBUG,
7733 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7734 query_reason, list ? " candidate list" : "");
7735
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007736 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
7737 btm_candidates,
7738 list);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007739}
7740
Hai Shalom39ba6fc2019-01-22 12:40:38 -08007741
7742static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
7743 char *cmd)
7744{
7745 struct wpabuf *elems;
7746 int ret;
7747
7748 elems = wpabuf_parse_bin(cmd);
7749 if (!elems)
7750 return -1;
7751
7752 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
7753 wpabuf_free(elems);
7754 return ret;
7755}
7756
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007757#endif /* CONFIG_WNM */
7758
7759
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007760static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
7761 size_t buflen)
7762{
7763 struct wpa_signal_info si;
7764 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007765 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007766
7767 ret = wpa_drv_signal_poll(wpa_s, &si);
7768 if (ret)
7769 return -1;
7770
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007771 pos = buf;
7772 end = buf + buflen;
7773
7774 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007775 "NOISE=%d\nFREQUENCY=%u\n",
7776 si.current_signal, si.current_txrate / 1000,
7777 si.current_noise, si.frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007778 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007779 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007780 pos += ret;
7781
7782 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
7783 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007784 channel_width_to_string(si.chanwidth));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007785 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007786 return -1;
7787 pos += ret;
7788 }
7789
Roshan Pius3a1667e2018-07-03 15:17:14 -07007790 if (si.center_frq1 > 0) {
7791 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
7792 si.center_frq1);
7793 if (os_snprintf_error(end - pos, ret))
7794 return -1;
7795 pos += ret;
7796 }
7797
7798 if (si.center_frq2 > 0) {
7799 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
7800 si.center_frq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007801 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007802 return -1;
7803 pos += ret;
7804 }
7805
7806 if (si.avg_signal) {
7807 ret = os_snprintf(pos, end - pos,
7808 "AVG_RSSI=%d\n", si.avg_signal);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007809 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007810 return -1;
7811 pos += ret;
7812 }
7813
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07007814 if (si.avg_beacon_signal) {
7815 ret = os_snprintf(pos, end - pos,
7816 "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
7817 if (os_snprintf_error(end - pos, ret))
7818 return -1;
7819 pos += ret;
7820 }
7821
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007822 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007823}
7824
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03007825
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007826static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
7827 const char *cmd)
7828{
7829 const char *pos;
7830 int threshold = 0;
7831 int hysteresis = 0;
7832
7833 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
7834 wpa_printf(MSG_DEBUG,
7835 "Reject SIGNAL_MONITOR command - bgscan is active");
7836 return -1;
7837 }
7838 pos = os_strstr(cmd, "THRESHOLD=");
7839 if (pos)
7840 threshold = atoi(pos + 10);
7841 pos = os_strstr(cmd, "HYSTERESIS=");
7842 if (pos)
7843 hysteresis = atoi(pos + 11);
7844 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
7845}
7846
7847
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007848#ifdef CONFIG_TESTING_OPTIONS
7849int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
7850 enum wpa_driver_if_type if_type,
7851 unsigned int *num,
7852 unsigned int *freq_list)
7853{
7854 char *pos = wpa_s->get_pref_freq_list_override;
7855 char *end;
7856 unsigned int count = 0;
7857
7858 /* Override string format:
7859 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7860
7861 while (pos) {
7862 if (atoi(pos) == (int) if_type)
7863 break;
7864 pos = os_strchr(pos, ' ');
7865 if (pos)
7866 pos++;
7867 }
7868 if (!pos)
7869 return -1;
7870 pos = os_strchr(pos, ':');
7871 if (!pos)
7872 return -1;
7873 pos++;
7874 end = os_strchr(pos, ' ');
7875 while (pos && (!end || pos < end) && count < *num) {
7876 freq_list[count++] = atoi(pos);
7877 pos = os_strchr(pos, ',');
7878 if (pos)
7879 pos++;
7880 }
7881
7882 *num = count;
7883 return 0;
7884}
7885#endif /* CONFIG_TESTING_OPTIONS */
7886
7887
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007888static int wpas_ctrl_iface_get_pref_freq_list(
7889 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
7890{
7891 unsigned int freq_list[100], num = 100, i;
7892 int ret;
7893 enum wpa_driver_if_type iface_type;
7894 char *pos, *end;
7895
7896 pos = buf;
7897 end = buf + buflen;
7898
7899 /* buf: "<interface_type>" */
7900 if (os_strcmp(cmd, "STATION") == 0)
7901 iface_type = WPA_IF_STATION;
7902 else if (os_strcmp(cmd, "AP") == 0)
7903 iface_type = WPA_IF_AP_BSS;
7904 else if (os_strcmp(cmd, "P2P_GO") == 0)
7905 iface_type = WPA_IF_P2P_GO;
7906 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
7907 iface_type = WPA_IF_P2P_CLIENT;
7908 else if (os_strcmp(cmd, "IBSS") == 0)
7909 iface_type = WPA_IF_IBSS;
7910 else if (os_strcmp(cmd, "TDLS") == 0)
7911 iface_type = WPA_IF_TDLS;
7912 else
7913 return -1;
7914
7915 wpa_printf(MSG_DEBUG,
7916 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
Hai Shalom5f92bc92019-04-18 11:54:11 -07007917 iface_type, cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007918
7919 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
7920 if (ret)
7921 return -1;
7922
7923 for (i = 0; i < num; i++) {
7924 ret = os_snprintf(pos, end - pos, "%s%u",
7925 i > 0 ? "," : "", freq_list[i]);
7926 if (os_snprintf_error(end - pos, ret))
7927 return -1;
7928 pos += ret;
7929 }
7930
7931 return pos - buf;
7932}
7933
7934
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007935static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
7936 char *buf, size_t buflen)
7937{
7938 int ret, i;
7939 char *pos, *end;
7940
7941 ret = os_snprintf(buf, buflen, "%016llX:\n",
7942 (long long unsigned) wpa_s->drv_flags);
7943 if (os_snprintf_error(buflen, ret))
7944 return -1;
7945
7946 pos = buf + ret;
7947 end = buf + buflen;
7948
7949 for (i = 0; i < 64; i++) {
7950 if (wpa_s->drv_flags & (1LLU << i)) {
7951 ret = os_snprintf(pos, end - pos, "%s\n",
7952 driver_flag_to_string(1LLU << i));
7953 if (os_snprintf_error(end - pos, ret))
7954 return -1;
7955 pos += ret;
7956 }
7957 }
7958
7959 return pos - buf;
7960}
7961
7962
Hai Shalomb755a2a2020-04-23 21:49:02 -07007963static int wpas_ctrl_iface_driver_flags2(struct wpa_supplicant *wpa_s,
7964 char *buf, size_t buflen)
7965{
7966 int ret, i;
7967 char *pos, *end;
7968
7969 ret = os_snprintf(buf, buflen, "%016llX:\n",
7970 (long long unsigned) wpa_s->drv_flags2);
7971 if (os_snprintf_error(buflen, ret))
7972 return -1;
7973
7974 pos = buf + ret;
7975 end = buf + buflen;
7976
7977 for (i = 0; i < 64; i++) {
7978 if (wpa_s->drv_flags2 & (1LLU << i)) {
7979 ret = os_snprintf(pos, end - pos, "%s\n",
7980 driver_flag2_to_string(1LLU << i));
7981 if (os_snprintf_error(end - pos, ret))
7982 return -1;
7983 pos += ret;
7984 }
7985 }
7986
7987 return pos - buf;
7988}
7989
7990
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07007991static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
7992 size_t buflen)
7993{
7994 struct hostap_sta_driver_data sta;
7995 int ret;
7996
7997 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
7998 if (ret)
7999 return -1;
8000
8001 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03008002 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008003 if (os_snprintf_error(buflen, ret))
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07008004 return -1;
8005 return ret;
8006}
8007
8008
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008009#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008010static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8011 char *buf, size_t buflen)
8012{
8013 int ret;
8014
8015 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008016 if (ret == 0) {
8017 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
8018 struct p2p_data *p2p = wpa_s->global->p2p;
8019 if (p2p) {
8020 char country[3];
8021 country[0] = cmd[8];
8022 country[1] = cmd[9];
8023 country[2] = 0x04;
8024 p2p_set_country(p2p, country);
8025 }
8026 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008027 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008028 if (os_snprintf_error(buflen, ret))
8029 ret = -1;
Dmitry Shmidt9432e122013-09-12 12:39:30 -07008030 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008031 return ret;
8032}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008033#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07008034
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07008035
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008036static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
8037 char *buf, size_t buflen)
8038{
8039 int ret;
8040 char *pos;
8041 u8 *data = NULL;
8042 unsigned int vendor_id, subcmd;
8043 struct wpabuf *reply;
8044 size_t data_len = 0;
8045
8046 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
8047 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008048 if (!isblank((unsigned char) *pos))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008049 return -EINVAL;
8050
8051 subcmd = strtoul(pos, &pos, 10);
8052
8053 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008054 if (!isblank((unsigned char) *pos++))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008055 return -EINVAL;
8056 data_len = os_strlen(pos);
8057 }
8058
8059 if (data_len) {
8060 data_len /= 2;
8061 data = os_malloc(data_len);
8062 if (!data)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008063 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008064
8065 if (hexstr2bin(pos, data, data_len)) {
8066 wpa_printf(MSG_DEBUG,
8067 "Vendor command: wrong parameter format");
8068 os_free(data);
8069 return -EINVAL;
8070 }
8071 }
8072
8073 reply = wpabuf_alloc((buflen - 1) / 2);
8074 if (!reply) {
8075 os_free(data);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008076 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008077 }
8078
8079 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
8080 reply);
8081
8082 if (ret == 0)
8083 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
8084 wpabuf_len(reply));
8085
8086 wpabuf_free(reply);
8087 os_free(data);
8088
8089 return ret;
8090}
8091
8092
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008093static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
8094{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008095#ifdef CONFIG_P2P
8096 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
8097 wpa_s->global->p2p_init_wpa_s : wpa_s;
8098#endif /* CONFIG_P2P */
8099
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008100 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
8101
Dmitry Shmidt29333592017-01-09 12:27:11 -08008102 if (wpas_abort_ongoing_scan(wpa_s) == 0)
8103 wpa_s->ignore_post_flush_scan_res = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008104
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008105 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
8106 /*
8107 * Avoid possible auto connect re-connection on getting
8108 * disconnected due to state flush.
8109 */
8110 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
8111 }
8112
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008113#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008114 wpas_p2p_group_remove(p2p_wpa_s, "*");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008115 wpas_p2p_cancel(p2p_wpa_s);
8116 p2p_ctrl_flush(p2p_wpa_s);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008117 wpas_p2p_service_flush(p2p_wpa_s);
8118 p2p_wpa_s->global->p2p_disabled = 0;
8119 p2p_wpa_s->global->p2p_per_sta_psk = 0;
8120 p2p_wpa_s->conf->num_sec_device_types = 0;
8121 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
8122 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
8123 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008124 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08008125 p2p_wpa_s->global->pending_p2ps_group = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008126 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008127#endif /* CONFIG_P2P */
8128
8129#ifdef CONFIG_WPS_TESTING
8130 wps_version_number = 0x20;
8131 wps_testing_dummy_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08008132 wps_corrupt_pkhash = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008133 wps_force_auth_types_in_use = 0;
8134 wps_force_encr_types_in_use = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008135#endif /* CONFIG_WPS_TESTING */
8136#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008137 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008138 wpas_wps_cancel(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008139 wps_registrar_flush(wpa_s->wps->registrar);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008140#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07008141 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008142 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008143
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008144#ifdef CONFIG_DPP
8145 wpas_dpp_deinit(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07008146 wpa_s->dpp_init_max_tries = 0;
8147 wpa_s->dpp_init_retry_time = 0;
8148 wpa_s->dpp_resp_wait_time = 0;
8149 wpa_s->dpp_resp_max_tries = 0;
8150 wpa_s->dpp_resp_retry_time = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008151#ifdef CONFIG_DPP2
8152 wpas_dpp_chirp_stop(wpa_s);
8153 wpa_s->dpp_pfs_fallback = 0;
8154#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07008155#ifdef CONFIG_TESTING_OPTIONS
8156 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
8157 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
8158 dpp_pkex_ephemeral_key_override_len = 0;
8159 dpp_protocol_key_override_len = 0;
8160 dpp_nonce_override_len = 0;
8161#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008162#endif /* CONFIG_DPP */
8163
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008164#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008165#ifdef CONFIG_TDLS_TESTING
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008166 tdls_testing = 0;
8167#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008168 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
8169 wpa_tdls_enable(wpa_s->wpa, 1);
8170#endif /* CONFIG_TDLS */
8171
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008172 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
8173 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
Hai Shalomfdcde762020-04-02 11:19:20 -07008174 wpa_s->last_michael_mic_error.sec = 0;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008175
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008176 wpa_s->no_keep_alive = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08008177 wpa_s->own_disconnect_req = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008178 wpa_s->own_reconnect_req = 0;
8179 wpa_s->deny_ptk0_rekey = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008180
8181 os_free(wpa_s->disallow_aps_bssid);
8182 wpa_s->disallow_aps_bssid = NULL;
8183 wpa_s->disallow_aps_bssid_count = 0;
8184 os_free(wpa_s->disallow_aps_ssid);
8185 wpa_s->disallow_aps_ssid = NULL;
8186 wpa_s->disallow_aps_ssid_count = 0;
8187
8188 wpa_s->set_sta_uapsd = 0;
8189 wpa_s->sta_uapsd = 0;
8190
8191 wpa_drv_radio_disable(wpa_s, 0);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008192 wpa_blacklist_clear(wpa_s);
Dmitry Shmidt4b060592013-04-29 16:42:49 -07008193 wpa_s->extra_blacklist_count = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008194 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
8195 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08008196 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08008197 wpa_s->conf->auto_interworking = 0;
8198 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008199
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008200 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
8201 rsn_preauth_deinit(wpa_s->wpa);
8202
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008203 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
8204 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
8205 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
Hai Shalome21d4e82020-04-29 16:34:06 -07008206 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008207
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008208 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008209 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008210
8211 wpa_s->next_ssid = NULL;
8212
8213#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008214#ifdef CONFIG_HS20
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008215 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008216 hs20_del_icon(wpa_s, NULL, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008217#endif /* CONFIG_HS20 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008218#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008219
8220 wpa_s->ext_mgmt_frame_handling = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008221 wpa_s->ext_eapol_frame_io = 0;
8222#ifdef CONFIG_TESTING_OPTIONS
8223 wpa_s->extra_roc_dur = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008224 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008225 wpa_s->p2p_go_csa_on_inv = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008226 wpa_s->ignore_auth_resp = 0;
8227 wpa_s->ignore_assoc_disallow = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008228 wpa_s->disable_sa_query = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008229 wpa_s->testing_resend_assoc = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008230 wpa_s->ignore_sae_h2e_only = 0;
Hai Shalomb755a2a2020-04-23 21:49:02 -07008231 wpa_s->ft_rsnxe_used = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008232 wpa_s->reject_btm_req_reason = 0;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008233 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008234 os_free(wpa_s->get_pref_freq_list_override);
8235 wpa_s->get_pref_freq_list_override = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008236 wpabuf_free(wpa_s->sae_commit_override);
8237 wpa_s->sae_commit_override = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008238 os_free(wpa_s->extra_sae_rejected_groups);
8239 wpa_s->extra_sae_rejected_groups = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008240 wpabuf_free(wpa_s->rsne_override_eapol);
8241 wpa_s->rsne_override_eapol = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008242 wpabuf_free(wpa_s->rsnxe_override_assoc);
8243 wpa_s->rsnxe_override_assoc = NULL;
8244 wpabuf_free(wpa_s->rsnxe_override_eapol);
8245 wpa_s->rsnxe_override_eapol = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008246 wpas_clear_driver_signal_override(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07008247#ifdef CONFIG_DPP
8248 os_free(wpa_s->dpp_config_obj_override);
8249 wpa_s->dpp_config_obj_override = NULL;
8250 os_free(wpa_s->dpp_discovery_override);
8251 wpa_s->dpp_discovery_override = NULL;
8252 os_free(wpa_s->dpp_groups_override);
8253 wpa_s->dpp_groups_override = NULL;
8254 dpp_test = DPP_TEST_DISABLED;
8255#endif /* CONFIG_DPP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008256#endif /* CONFIG_TESTING_OPTIONS */
8257
8258 wpa_s->disconnected = 0;
8259 os_free(wpa_s->next_scan_freqs);
8260 wpa_s->next_scan_freqs = NULL;
Hai Shalomfdcde762020-04-02 11:19:20 -07008261 os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN);
8262 wpa_s->next_scan_bssid_wildcard_ssid = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008263 os_free(wpa_s->select_network_scan_freqs);
8264 wpa_s->select_network_scan_freqs = NULL;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008265
8266 wpa_bss_flush(wpa_s);
8267 if (!dl_list_empty(&wpa_s->bss)) {
8268 wpa_printf(MSG_DEBUG,
8269 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8270 MACSTR " pending_bssid=" MACSTR,
8271 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
8272 MAC2STR(wpa_s->bssid),
8273 MAC2STR(wpa_s->pending_bssid));
8274 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008275
8276 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -08008277 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008278
8279#ifdef CONFIG_SME
8280 wpa_s->sme.last_unprot_disconnect.sec = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -07008281 wpa_s->sme.auth_alg = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008282#endif /* CONFIG_SME */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008283
8284 wpabuf_free(wpa_s->ric_ies);
8285 wpa_s->ric_ies = NULL;
Hai Shalom74f70d42019-02-11 14:42:39 -08008286
8287 wpa_supplicant_update_channel_list(wpa_s, NULL);
8288
8289 free_bss_tmp_disallowed(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008290}
8291
8292
8293static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
8294 char *buf, size_t buflen)
8295{
8296 struct wpa_radio_work *work;
8297 char *pos, *end;
8298 struct os_reltime now, diff;
8299
8300 pos = buf;
8301 end = buf + buflen;
8302
8303 os_get_reltime(&now);
8304
8305 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8306 {
8307 int ret;
8308
8309 os_reltime_sub(&now, &work->time, &diff);
8310 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
8311 work->type, work->wpa_s->ifname, work->freq,
8312 work->started, diff.sec, diff.usec);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008313 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008314 break;
8315 pos += ret;
8316 }
8317
8318 return pos - buf;
8319}
8320
8321
8322static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
8323{
8324 struct wpa_radio_work *work = eloop_ctx;
8325 struct wpa_external_work *ework = work->ctx;
8326
8327 wpa_dbg(work->wpa_s, MSG_DEBUG,
8328 "Timing out external radio work %u (%s)",
8329 ework->id, work->type);
8330 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008331 work->wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008332 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008333 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008334}
8335
8336
8337static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
8338{
8339 struct wpa_external_work *ework = work->ctx;
8340
8341 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008342 if (work->started)
8343 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8344 work, NULL);
8345
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008346 /*
8347 * work->type points to a buffer in ework, so need to replace
8348 * that here with a fixed string to avoid use of freed memory
8349 * in debug prints.
8350 */
8351 work->type = "freed-ext-work";
8352 work->ctx = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008353 os_free(ework);
8354 return;
8355 }
8356
8357 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
8358 ework->id, ework->type);
8359 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008360 work->wpa_s->ext_work_in_progress = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008361 if (!ework->timeout)
8362 ework->timeout = 10;
8363 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
8364 work, NULL);
8365}
8366
8367
8368static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
8369 char *buf, size_t buflen)
8370{
8371 struct wpa_external_work *ework;
8372 char *pos, *pos2;
8373 size_t type_len;
8374 int ret;
8375 unsigned int freq = 0;
8376
8377 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8378
8379 ework = os_zalloc(sizeof(*ework));
8380 if (ework == NULL)
8381 return -1;
8382
8383 pos = os_strchr(cmd, ' ');
8384 if (pos) {
8385 type_len = pos - cmd;
8386 pos++;
8387
8388 pos2 = os_strstr(pos, "freq=");
8389 if (pos2)
8390 freq = atoi(pos2 + 5);
8391
8392 pos2 = os_strstr(pos, "timeout=");
8393 if (pos2)
8394 ework->timeout = atoi(pos2 + 8);
8395 } else {
8396 type_len = os_strlen(cmd);
8397 }
8398 if (4 + type_len >= sizeof(ework->type))
8399 type_len = sizeof(ework->type) - 4 - 1;
8400 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
8401 os_memcpy(ework->type + 4, cmd, type_len);
8402 ework->type[4 + type_len] = '\0';
8403
8404 wpa_s->ext_work_id++;
8405 if (wpa_s->ext_work_id == 0)
8406 wpa_s->ext_work_id++;
8407 ework->id = wpa_s->ext_work_id;
8408
8409 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
8410 ework) < 0) {
8411 os_free(ework);
8412 return -1;
8413 }
8414
8415 ret = os_snprintf(buf, buflen, "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008416 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008417 return -1;
8418 return ret;
8419}
8420
8421
8422static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
8423{
8424 struct wpa_radio_work *work;
8425 unsigned int id = atoi(cmd);
8426
8427 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8428 {
8429 struct wpa_external_work *ework;
8430
8431 if (os_strncmp(work->type, "ext:", 4) != 0)
8432 continue;
8433 ework = work->ctx;
8434 if (id && ework->id != id)
8435 continue;
8436 wpa_dbg(wpa_s, MSG_DEBUG,
8437 "Completed external radio work %u (%s)",
8438 ework->id, ework->type);
8439 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008440 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008441 radio_work_done(work);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07008442 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008443 return 3; /* "OK\n" */
8444 }
8445
8446 return -1;
8447}
8448
8449
8450static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
8451 char *buf, size_t buflen)
8452{
8453 if (os_strcmp(cmd, "show") == 0)
8454 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
8455 if (os_strncmp(cmd, "add ", 4) == 0)
8456 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
8457 if (os_strncmp(cmd, "done ", 5) == 0)
8458 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
8459 return -1;
8460}
8461
8462
8463void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
8464{
8465 struct wpa_radio_work *work, *tmp;
8466
Dmitry Shmidt18463232014-01-24 12:29:41 -08008467 if (!wpa_s || !wpa_s->radio)
8468 return;
8469
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008470 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
8471 struct wpa_radio_work, list) {
8472 struct wpa_external_work *ework;
8473
8474 if (os_strncmp(work->type, "ext:", 4) != 0)
8475 continue;
8476 ework = work->ctx;
8477 wpa_dbg(wpa_s, MSG_DEBUG,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07008478 "Flushing%s external radio work %u (%s)",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008479 work->started ? " started" : "", ework->id,
8480 ework->type);
8481 if (work->started)
8482 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8483 work, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008484 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008485 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008486 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008487}
8488
8489
Dmitry Shmidt051af732013-10-22 13:52:46 -07008490static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
8491{
8492 struct wpa_supplicant *wpa_s = eloop_ctx;
8493 eapol_sm_notify_ctrl_response(wpa_s->eapol);
8494}
8495
8496
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008497static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
8498 unsigned int *scan_id_count, int scan_id[])
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008499{
8500 const char *pos = value;
8501
8502 while (pos) {
8503 if (*pos == ' ' || *pos == '\0')
8504 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008505 if (*scan_id_count == MAX_SCAN_ID)
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008506 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008507 scan_id[(*scan_id_count)++] = atoi(pos);
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008508 pos = os_strchr(pos, ',');
8509 if (pos)
8510 pos++;
8511 }
8512
8513 return 0;
8514}
8515
8516
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008517static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
8518 char *reply, int reply_size, int *reply_len)
8519{
8520 char *pos;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008521 unsigned int manual_scan_passive = 0;
8522 unsigned int manual_scan_use_id = 0;
8523 unsigned int manual_scan_only_new = 0;
8524 unsigned int scan_only = 0;
8525 unsigned int scan_id_count = 0;
8526 int scan_id[MAX_SCAN_ID];
8527 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
8528 struct wpa_scan_results *scan_res);
8529 int *manual_scan_freqs = NULL;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008530 struct wpa_ssid_value *ssid = NULL, *ns;
8531 unsigned int ssid_count = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008532
8533 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
8534 *reply_len = -1;
8535 return;
8536 }
8537
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008538 if (radio_work_pending(wpa_s, "scan")) {
8539 wpa_printf(MSG_DEBUG,
8540 "Pending scan scheduled - reject new request");
8541 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8542 return;
8543 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008544
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008545#ifdef CONFIG_INTERWORKING
8546 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
8547 wpa_printf(MSG_DEBUG,
8548 "Interworking select in progress - reject new scan");
8549 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8550 return;
8551 }
8552#endif /* CONFIG_INTERWORKING */
8553
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008554 if (params) {
8555 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008556 scan_only = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008557
8558 pos = os_strstr(params, "freq=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008559 if (pos) {
8560 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
8561 pos + 5);
8562 if (manual_scan_freqs == NULL) {
8563 *reply_len = -1;
8564 goto done;
8565 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008566 }
8567
8568 pos = os_strstr(params, "passive=");
8569 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008570 manual_scan_passive = !!atoi(pos + 8);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008571
8572 pos = os_strstr(params, "use_id=");
8573 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008574 manual_scan_use_id = atoi(pos + 7);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008575
8576 pos = os_strstr(params, "only_new=1");
8577 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008578 manual_scan_only_new = 1;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008579
8580 pos = os_strstr(params, "scan_id=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008581 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
8582 scan_id) < 0) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008583 *reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008584 goto done;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008585 }
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008586
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008587 pos = os_strstr(params, "bssid=");
8588 if (pos) {
8589 u8 bssid[ETH_ALEN];
8590
8591 pos += 6;
8592 if (hwaddr_aton(pos, bssid)) {
8593 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
8594 *reply_len = -1;
8595 goto done;
8596 }
8597 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
Hai Shalomfdcde762020-04-02 11:19:20 -07008598
8599 wpa_s->next_scan_bssid_wildcard_ssid =
8600 os_strstr(params, "wildcard_ssid=1") != NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008601 }
8602
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008603 pos = params;
8604 while (pos && *pos != '\0') {
8605 if (os_strncmp(pos, "ssid ", 5) == 0) {
8606 char *end;
8607
8608 pos += 5;
8609 end = pos;
8610 while (*end) {
8611 if (*end == '\0' || *end == ' ')
8612 break;
8613 end++;
8614 }
8615
8616 ns = os_realloc_array(
8617 ssid, ssid_count + 1,
8618 sizeof(struct wpa_ssid_value));
8619 if (ns == NULL) {
8620 *reply_len = -1;
8621 goto done;
8622 }
8623 ssid = ns;
8624
8625 if ((end - pos) & 0x01 ||
8626 end - pos > 2 * SSID_MAX_LEN ||
8627 hexstr2bin(pos, ssid[ssid_count].ssid,
8628 (end - pos) / 2) < 0) {
8629 wpa_printf(MSG_DEBUG,
8630 "Invalid SSID value '%s'",
8631 pos);
8632 *reply_len = -1;
8633 goto done;
8634 }
8635 ssid[ssid_count].ssid_len = (end - pos) / 2;
8636 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
8637 ssid[ssid_count].ssid,
8638 ssid[ssid_count].ssid_len);
8639 ssid_count++;
8640 pos = end;
8641 }
8642
8643 pos = os_strchr(pos, ' ');
8644 if (pos)
8645 pos++;
8646 }
8647 }
8648
8649 wpa_s->num_ssids_from_scan_req = ssid_count;
8650 os_free(wpa_s->ssids_from_scan_req);
8651 if (ssid_count) {
8652 wpa_s->ssids_from_scan_req = ssid;
8653 ssid = NULL;
8654 } else {
8655 wpa_s->ssids_from_scan_req = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008656 }
8657
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008658 if (scan_only)
8659 scan_res_handler = scan_only_handler;
8660 else if (wpa_s->scan_res_handler == scan_only_handler)
8661 scan_res_handler = NULL;
8662 else
8663 scan_res_handler = wpa_s->scan_res_handler;
8664
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008665 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
8666 ((wpa_s->wpa_state <= WPA_SCANNING) ||
8667 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008668 wpa_s->manual_scan_passive = manual_scan_passive;
8669 wpa_s->manual_scan_use_id = manual_scan_use_id;
8670 wpa_s->manual_scan_only_new = manual_scan_only_new;
8671 wpa_s->scan_id_count = scan_id_count;
8672 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8673 wpa_s->scan_res_handler = scan_res_handler;
8674 os_free(wpa_s->manual_scan_freqs);
8675 wpa_s->manual_scan_freqs = manual_scan_freqs;
8676 manual_scan_freqs = NULL;
8677
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008678 wpa_s->normal_scans = 0;
8679 wpa_s->scan_req = MANUAL_SCAN_REQ;
8680 wpa_s->after_wps = 0;
8681 wpa_s->known_wps_freq = 0;
8682 wpa_supplicant_req_scan(wpa_s, 0, 0);
8683 if (wpa_s->manual_scan_use_id) {
8684 wpa_s->manual_scan_id++;
8685 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8686 wpa_s->manual_scan_id);
8687 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8688 wpa_s->manual_scan_id);
8689 }
8690 } else if (wpa_s->sched_scanning) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008691 wpa_s->manual_scan_passive = manual_scan_passive;
8692 wpa_s->manual_scan_use_id = manual_scan_use_id;
8693 wpa_s->manual_scan_only_new = manual_scan_only_new;
8694 wpa_s->scan_id_count = scan_id_count;
8695 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8696 wpa_s->scan_res_handler = scan_res_handler;
8697 os_free(wpa_s->manual_scan_freqs);
8698 wpa_s->manual_scan_freqs = manual_scan_freqs;
8699 manual_scan_freqs = NULL;
8700
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008701 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
8702 wpa_supplicant_cancel_sched_scan(wpa_s);
8703 wpa_s->scan_req = MANUAL_SCAN_REQ;
8704 wpa_supplicant_req_scan(wpa_s, 0, 0);
8705 if (wpa_s->manual_scan_use_id) {
8706 wpa_s->manual_scan_id++;
8707 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8708 wpa_s->manual_scan_id);
8709 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8710 wpa_s->manual_scan_id);
8711 }
8712 } else {
8713 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
8714 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8715 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008716
8717done:
8718 os_free(manual_scan_freqs);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008719 os_free(ssid);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008720}
8721
8722
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008723#ifdef CONFIG_TESTING_OPTIONS
8724
8725static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
8726 unsigned int freq, const u8 *dst,
8727 const u8 *src, const u8 *bssid,
8728 const u8 *data, size_t data_len,
8729 enum offchannel_send_action_result
8730 result)
8731{
8732 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8733 " src=" MACSTR " bssid=" MACSTR " result=%s",
8734 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
8735 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
8736 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
8737 "NO_ACK" : "FAILED"));
8738}
8739
8740
8741static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
8742{
8743 char *pos, *param;
8744 size_t len;
8745 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
8746 int res, used;
8747 int freq = 0, no_cck = 0, wait_time = 0;
8748
8749 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8750 * <action=Action frame payload> */
8751
8752 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
8753
8754 pos = cmd;
8755 used = hwaddr_aton2(pos, da);
8756 if (used < 0)
8757 return -1;
8758 pos += used;
8759 while (*pos == ' ')
8760 pos++;
8761 used = hwaddr_aton2(pos, bssid);
8762 if (used < 0)
8763 return -1;
8764 pos += used;
8765
8766 param = os_strstr(pos, " freq=");
8767 if (param) {
8768 param += 6;
8769 freq = atoi(param);
8770 }
8771
8772 param = os_strstr(pos, " no_cck=");
8773 if (param) {
8774 param += 8;
8775 no_cck = atoi(param);
8776 }
8777
8778 param = os_strstr(pos, " wait_time=");
8779 if (param) {
8780 param += 11;
8781 wait_time = atoi(param);
8782 }
8783
8784 param = os_strstr(pos, " action=");
8785 if (param == NULL)
8786 return -1;
8787 param += 8;
8788
8789 len = os_strlen(param);
8790 if (len & 1)
8791 return -1;
8792 len /= 2;
8793
8794 buf = os_malloc(len);
8795 if (buf == NULL)
8796 return -1;
8797
8798 if (hexstr2bin(param, buf, len) < 0) {
8799 os_free(buf);
8800 return -1;
8801 }
8802
8803 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
8804 buf, len, wait_time,
8805 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
8806 os_free(buf);
8807 return res;
8808}
8809
8810
8811static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
8812{
8813 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
8814 offchannel_send_action_done(wpa_s);
8815}
8816
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07008817
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008818static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
8819 char *cmd)
8820{
8821 char *pos, *param;
8822 size_t len;
8823 u8 *buf;
8824 int freq = 0, datarate = 0, ssi_signal = 0;
8825 union wpa_event_data event;
8826
8827 if (!wpa_s->ext_mgmt_frame_handling)
8828 return -1;
8829
8830 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8831
8832 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
8833
8834 pos = cmd;
8835 param = os_strstr(pos, "freq=");
8836 if (param) {
8837 param += 5;
8838 freq = atoi(param);
8839 }
8840
8841 param = os_strstr(pos, " datarate=");
8842 if (param) {
8843 param += 10;
8844 datarate = atoi(param);
8845 }
8846
8847 param = os_strstr(pos, " ssi_signal=");
8848 if (param) {
8849 param += 12;
8850 ssi_signal = atoi(param);
8851 }
8852
8853 param = os_strstr(pos, " frame=");
8854 if (param == NULL)
8855 return -1;
8856 param += 7;
8857
8858 len = os_strlen(param);
8859 if (len & 1)
8860 return -1;
8861 len /= 2;
8862
8863 buf = os_malloc(len);
8864 if (buf == NULL)
8865 return -1;
8866
8867 if (hexstr2bin(param, buf, len) < 0) {
8868 os_free(buf);
8869 return -1;
8870 }
8871
8872 os_memset(&event, 0, sizeof(event));
8873 event.rx_mgmt.freq = freq;
8874 event.rx_mgmt.frame = buf;
8875 event.rx_mgmt.frame_len = len;
8876 event.rx_mgmt.ssi_signal = ssi_signal;
8877 event.rx_mgmt.datarate = datarate;
8878 wpa_s->ext_mgmt_frame_handling = 0;
8879 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
8880 wpa_s->ext_mgmt_frame_handling = 1;
8881
8882 os_free(buf);
8883
8884 return 0;
8885}
8886
8887
Paul Stewart092955c2017-02-06 09:13:09 -08008888static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
8889 char *param)
8890{
8891 struct wpa_scan_res *res;
8892 struct os_reltime now;
8893 char *pos, *end;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008894 int ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08008895
8896 if (!param)
8897 return -1;
8898
8899 if (os_strcmp(param, "START") == 0) {
8900 wpa_bss_update_start(wpa_s);
8901 return 0;
8902 }
8903
8904 if (os_strcmp(param, "END") == 0) {
8905 wpa_bss_update_end(wpa_s, NULL, 1);
8906 return 0;
8907 }
8908
8909 if (os_strncmp(param, "BSS ", 4) != 0)
8910 return -1;
8911 param += 3;
8912
8913 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
8914 if (!res)
8915 return -1;
8916
8917 pos = os_strstr(param, " flags=");
8918 if (pos)
8919 res->flags = strtol(pos + 7, NULL, 16);
8920
8921 pos = os_strstr(param, " bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008922 if (pos && hwaddr_aton(pos + 7, res->bssid))
8923 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008924
8925 pos = os_strstr(param, " freq=");
8926 if (pos)
8927 res->freq = atoi(pos + 6);
8928
8929 pos = os_strstr(param, " beacon_int=");
8930 if (pos)
8931 res->beacon_int = atoi(pos + 12);
8932
8933 pos = os_strstr(param, " caps=");
8934 if (pos)
8935 res->caps = strtol(pos + 6, NULL, 16);
8936
8937 pos = os_strstr(param, " qual=");
8938 if (pos)
8939 res->qual = atoi(pos + 6);
8940
8941 pos = os_strstr(param, " noise=");
8942 if (pos)
8943 res->noise = atoi(pos + 7);
8944
8945 pos = os_strstr(param, " level=");
8946 if (pos)
8947 res->level = atoi(pos + 7);
8948
8949 pos = os_strstr(param, " tsf=");
8950 if (pos)
8951 res->tsf = strtoll(pos + 5, NULL, 16);
8952
8953 pos = os_strstr(param, " age=");
8954 if (pos)
8955 res->age = atoi(pos + 5);
8956
8957 pos = os_strstr(param, " est_throughput=");
8958 if (pos)
8959 res->est_throughput = atoi(pos + 16);
8960
8961 pos = os_strstr(param, " snr=");
8962 if (pos)
8963 res->snr = atoi(pos + 5);
8964
8965 pos = os_strstr(param, " parent_tsf=");
8966 if (pos)
8967 res->parent_tsf = strtoll(pos + 7, NULL, 16);
8968
8969 pos = os_strstr(param, " tsf_bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008970 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
8971 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008972
8973 pos = os_strstr(param, " ie=");
8974 if (pos) {
8975 pos += 4;
8976 end = os_strchr(pos, ' ');
8977 if (!end)
8978 end = pos + os_strlen(pos);
8979 res->ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008980 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
8981 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008982 }
8983
8984 pos = os_strstr(param, " beacon_ie=");
8985 if (pos) {
8986 pos += 11;
8987 end = os_strchr(pos, ' ');
8988 if (!end)
8989 end = pos + os_strlen(pos);
8990 res->beacon_ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008991 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
8992 res->beacon_ie_len))
8993 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008994 }
8995
8996 os_get_reltime(&now);
8997 wpa_bss_update_scan_res(wpa_s, res, &now);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008998 ret = 0;
8999fail:
Paul Stewart092955c2017-02-06 09:13:09 -08009000 os_free(res);
9001
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08009002 return ret;
Paul Stewart092955c2017-02-06 09:13:09 -08009003}
9004
9005
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009006static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
9007{
9008 char *pos, *param;
9009 union wpa_event_data event;
9010 enum wpa_event_type ev;
9011
9012 /* <event name> [parameters..] */
9013
9014 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
9015
9016 pos = cmd;
9017 param = os_strchr(pos, ' ');
9018 if (param)
9019 *param++ = '\0';
9020
9021 os_memset(&event, 0, sizeof(event));
9022
9023 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
9024 ev = EVENT_INTERFACE_ENABLED;
9025 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
9026 ev = EVENT_INTERFACE_DISABLED;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07009027 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
9028 ev = EVENT_AVOID_FREQUENCIES;
9029 if (param == NULL)
9030 param = "";
9031 if (freq_range_list_parse(&event.freq_range, param) < 0)
9032 return -1;
9033 wpa_supplicant_event(wpa_s, ev, &event);
9034 os_free(event.freq_range.range);
9035 return 0;
Paul Stewart092955c2017-02-06 09:13:09 -08009036 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
9037 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07009038 } else {
9039 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
9040 cmd);
9041 return -1;
9042 }
9043
9044 wpa_supplicant_event(wpa_s, ev, &event);
9045
9046 return 0;
9047}
9048
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009049
9050static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
9051{
9052 char *pos;
9053 u8 src[ETH_ALEN], *buf;
9054 int used;
9055 size_t len;
9056
9057 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
9058
9059 pos = cmd;
9060 used = hwaddr_aton2(pos, src);
9061 if (used < 0)
9062 return -1;
9063 pos += used;
9064 while (*pos == ' ')
9065 pos++;
9066
9067 len = os_strlen(pos);
9068 if (len & 1)
9069 return -1;
9070 len /= 2;
9071
9072 buf = os_malloc(len);
9073 if (buf == NULL)
9074 return -1;
9075
9076 if (hexstr2bin(pos, buf, len) < 0) {
9077 os_free(buf);
9078 return -1;
9079 }
9080
9081 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
9082 os_free(buf);
9083
9084 return 0;
9085}
9086
9087
9088static u16 ipv4_hdr_checksum(const void *buf, size_t len)
9089{
9090 size_t i;
9091 u32 sum = 0;
9092 const u16 *pos = buf;
9093
9094 for (i = 0; i < len / 2; i++)
9095 sum += *pos++;
9096
9097 while (sum >> 16)
9098 sum = (sum & 0xffff) + (sum >> 16);
9099
9100 return sum ^ 0xffff;
9101}
9102
9103
9104#define HWSIM_PACKETLEN 1500
9105#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
9106
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07009107static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
9108 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009109{
9110 struct wpa_supplicant *wpa_s = ctx;
9111 const struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07009112 struct ip ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009113 const u8 *pos;
9114 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08009115 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009116
Hai Shalom74f70d42019-02-11 14:42:39 -08009117 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
9118 wpa_printf(MSG_DEBUG,
9119 "test data: RX - ignore unexpected length %d",
9120 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009121 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08009122 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009123
9124 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009125 os_memcpy(&ip, eth + 1, sizeof(ip));
9126 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009127
Hai Shalomfdcde762020-04-02 11:19:20 -07009128 if (ip.ip_hl != 5 || ip.ip_v != 4 || ntohs(ip.ip_len) > HWSIM_IP_LEN) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009129 wpa_printf(MSG_DEBUG,
9130 "test data: RX - ignore unexpect IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009131 return;
Hai Shalom39bc25d2019-02-06 16:32:13 -08009132 }
Hai Shalombf6e0ba2019-02-11 12:01:50 -08009133
Hai Shalomfdcde762020-04-02 11:19:20 -07009134 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
Hai Shalom74f70d42019-02-11 14:42:39 -08009135 if (*pos != (u8) i) {
9136 wpa_printf(MSG_DEBUG,
9137 "test data: RX - ignore mismatching payload");
9138 return;
9139 }
9140 pos++;
9141 }
9142 extra[0] = '\0';
Hai Shalomfdcde762020-04-02 11:19:20 -07009143 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
9144 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
Hai Shalom74f70d42019-02-11 14:42:39 -08009145 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
9146 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009147}
9148
9149
9150static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
9151 char *cmd)
9152{
9153 int enabled = atoi(cmd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009154 char *pos;
9155 const char *ifname;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009156
9157 if (!enabled) {
9158 if (wpa_s->l2_test) {
9159 l2_packet_deinit(wpa_s->l2_test);
9160 wpa_s->l2_test = NULL;
9161 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
9162 }
9163 return 0;
9164 }
9165
9166 if (wpa_s->l2_test)
9167 return 0;
9168
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009169 pos = os_strstr(cmd, " ifname=");
9170 if (pos)
9171 ifname = pos + 8;
9172 else
9173 ifname = wpa_s->ifname;
9174
9175 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009176 ETHERTYPE_IP, wpas_data_test_rx,
9177 wpa_s, 1);
9178 if (wpa_s->l2_test == NULL)
9179 return -1;
9180
9181 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
9182
9183 return 0;
9184}
9185
9186
9187static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
9188{
9189 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom74f70d42019-02-11 14:42:39 -08009190 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009191 int used;
9192 long int val;
9193 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009194 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009195 struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07009196 struct ip *ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009197 u8 *dpos;
9198 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08009199 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009200
9201 if (wpa_s->l2_test == NULL)
9202 return -1;
9203
Hai Shalom74f70d42019-02-11 14:42:39 -08009204 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009205
9206 pos = cmd;
9207 used = hwaddr_aton2(pos, dst);
9208 if (used < 0)
9209 return -1;
9210 pos += used;
9211 while (*pos == ' ')
9212 pos++;
9213 used = hwaddr_aton2(pos, src);
9214 if (used < 0)
9215 return -1;
9216 pos += used;
9217
Hai Shalom74f70d42019-02-11 14:42:39 -08009218 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009219 if (val < 0 || val > 0xff)
9220 return -1;
9221 tos = val;
9222
Hai Shalom74f70d42019-02-11 14:42:39 -08009223 pos = os_strstr(pos2, " len=");
9224 if (pos) {
9225 i = atoi(pos + 5);
9226 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
9227 return -1;
9228 send_len = i;
9229 }
9230
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009231 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009232 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
9233 os_memcpy(eth->ether_shost, src, ETH_ALEN);
9234 eth->ether_type = htons(ETHERTYPE_IP);
Hai Shalomfdcde762020-04-02 11:19:20 -07009235 ip = (struct ip *) (eth + 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009236 os_memset(ip, 0, sizeof(*ip));
Hai Shalomfdcde762020-04-02 11:19:20 -07009237 ip->ip_hl = 5;
9238 ip->ip_v = 4;
9239 ip->ip_ttl = 64;
9240 ip->ip_tos = tos;
9241 ip->ip_len = htons(send_len);
9242 ip->ip_p = 1;
9243 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
9244 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
9245 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009246 dpos = (u8 *) (ip + 1);
Hai Shalom74f70d42019-02-11 14:42:39 -08009247 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009248 *dpos++ = i;
9249
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009250 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom74f70d42019-02-11 14:42:39 -08009251 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009252 return -1;
9253
9254 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
9255 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
9256
9257 return 0;
9258}
9259
9260
9261static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
9262 char *cmd)
9263{
9264 u8 *buf;
9265 struct ether_header *eth;
9266 struct l2_packet_data *l2 = NULL;
9267 size_t len;
9268 u16 ethertype;
9269 int res = -1;
9270
9271 len = os_strlen(cmd);
9272 if (len & 1 || len < ETH_HLEN * 2)
9273 return -1;
9274 len /= 2;
9275
9276 buf = os_malloc(len);
9277 if (buf == NULL)
9278 return -1;
9279
9280 if (hexstr2bin(cmd, buf, len) < 0)
9281 goto done;
9282
9283 eth = (struct ether_header *) buf;
9284 ethertype = ntohs(eth->ether_type);
9285
9286 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
9287 wpas_data_test_rx, wpa_s, 1);
9288 if (l2 == NULL)
9289 goto done;
9290
9291 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
9292 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
9293done:
9294 if (l2)
9295 l2_packet_deinit(l2);
9296 os_free(buf);
9297
9298 return res < 0 ? -1 : 0;
9299}
9300
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009301
9302static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
9303{
9304#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009305 char *pos;
9306
9307 wpa_trace_fail_after = atoi(cmd);
9308 pos = os_strchr(cmd, ':');
9309 if (pos) {
9310 pos++;
9311 os_strlcpy(wpa_trace_fail_func, pos,
9312 sizeof(wpa_trace_fail_func));
9313 } else {
9314 wpa_trace_fail_after = 0;
9315 }
9316 return 0;
9317#else /* WPA_TRACE_BFD */
9318 return -1;
9319#endif /* WPA_TRACE_BFD */
9320}
9321
9322
9323static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
9324 char *buf, size_t buflen)
9325{
9326#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009327 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
9328 wpa_trace_fail_func);
9329#else /* WPA_TRACE_BFD */
9330 return -1;
9331#endif /* WPA_TRACE_BFD */
9332}
9333
Jouni Malinenc4818362015-10-04 11:45:13 +03009334
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009335static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
9336{
9337#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009338 char *pos;
9339
9340 wpa_trace_test_fail_after = atoi(cmd);
9341 pos = os_strchr(cmd, ':');
9342 if (pos) {
9343 pos++;
9344 os_strlcpy(wpa_trace_test_fail_func, pos,
9345 sizeof(wpa_trace_test_fail_func));
9346 } else {
9347 wpa_trace_test_fail_after = 0;
9348 }
9349 return 0;
9350#else /* WPA_TRACE_BFD */
9351 return -1;
9352#endif /* WPA_TRACE_BFD */
9353}
9354
9355
9356static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
9357 char *buf, size_t buflen)
9358{
9359#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009360 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
9361 wpa_trace_test_fail_func);
9362#else /* WPA_TRACE_BFD */
9363 return -1;
9364#endif /* WPA_TRACE_BFD */
9365}
9366
9367
Jouni Malinenc4818362015-10-04 11:45:13 +03009368static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
9369{
9370 struct wpa_supplicant *wpa_s = eloop_ctx;
9371 int i, count = (intptr_t) timeout_ctx;
9372
9373 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
9374 count);
9375 for (i = 0; i < count; i++) {
9376 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
9377 i + 1, count);
9378 }
9379}
9380
9381
9382static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
9383{
9384 int count;
9385
9386 count = atoi(cmd);
9387 if (count <= 0)
9388 return -1;
9389
9390 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
9391 (void *) (intptr_t) count);
9392}
9393
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009394
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009395static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
9396 const char *cmd)
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009397{
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009398 struct wpabuf *buf;
9399 size_t len;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009400
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009401 len = os_strlen(cmd);
9402 if (len & 1)
9403 return -1;
9404 len /= 2;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009405
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009406 if (len == 0) {
9407 buf = NULL;
9408 } else {
9409 buf = wpabuf_alloc(len);
9410 if (buf == NULL)
9411 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009412
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009413 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
9414 wpabuf_free(buf);
9415 return -1;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009416 }
9417 }
9418
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009419 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
9420 return 0;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009421}
9422
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009423
9424static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
9425{
9426 u8 zero[WPA_TK_MAX_LEN];
9427
9428 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
9429 return -1;
9430
9431 wpa_printf(MSG_INFO, "TESTING: Reset PN");
9432 os_memset(zero, 0, sizeof(zero));
9433
9434 /* First, use a zero key to avoid any possible duplicate key avoidance
9435 * in the driver. */
9436 if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9437 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -07009438 zero, wpa_s->last_tk_len,
9439 KEY_FLAG_PAIRWISE_RX_TX) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009440 return -1;
9441
9442 /* Set the previously configured key to reset its TSC/RSC */
9443 return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9444 wpa_s->last_tk_key_idx, 1, zero, 6,
Hai Shalomfdcde762020-04-02 11:19:20 -07009445 wpa_s->last_tk, wpa_s->last_tk_len,
9446 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009447}
9448
9449
9450static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
9451{
9452 const char *pos = cmd;
9453 int error, pairwise;
9454
9455 error = atoi(pos);
9456 pos = os_strchr(pos, ' ');
9457 if (!pos)
9458 return -1;
9459 pairwise = atoi(pos);
9460 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
9461 return 0;
9462}
9463
9464
9465static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
9466{
9467#ifdef CONFIG_SME
9468 struct wpa_driver_associate_params params;
9469 int ret;
9470
9471 os_memset(&params, 0, sizeof(params));
9472 params.bssid = wpa_s->bssid;
9473 params.ssid = wpa_s->sme.ssid;
9474 params.ssid_len = wpa_s->sme.ssid_len;
9475 params.freq.freq = wpa_s->sme.freq;
9476 if (wpa_s->last_assoc_req_wpa_ie) {
9477 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
9478 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
9479 }
9480 params.pairwise_suite = wpa_s->pairwise_cipher;
9481 params.group_suite = wpa_s->group_cipher;
9482 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
9483 params.key_mgmt_suite = wpa_s->key_mgmt;
9484 params.wpa_proto = wpa_s->wpa_proto;
9485 params.mgmt_frame_protection = wpa_s->sme.mfp;
9486 params.rrm_used = wpa_s->rrm.rrm_used;
9487 if (wpa_s->sme.prev_bssid_set)
9488 params.prev_bssid = wpa_s->sme.prev_bssid;
9489 wpa_printf(MSG_INFO, "TESTING: Resend association request");
9490 ret = wpa_drv_associate(wpa_s, &params);
9491 wpa_s->testing_resend_assoc = 1;
9492 return ret;
9493#else /* CONFIG_SME */
9494 return -1;
9495#endif /* CONFIG_SME */
9496}
9497
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009498#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009499
9500
9501static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
9502{
9503 char *pos = cmd;
9504 int frame;
9505 size_t len;
9506 struct wpabuf *buf;
9507 struct ieee802_11_elems elems;
9508
9509 frame = atoi(pos);
9510 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9511 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009512 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009513
9514 pos = os_strchr(pos, ' ');
9515 if (pos == NULL)
9516 return -1;
9517 pos++;
9518
9519 len = os_strlen(pos);
9520 if (len == 0)
9521 return 0;
9522 if (len & 1)
9523 return -1;
9524 len /= 2;
9525
9526 buf = wpabuf_alloc(len);
9527 if (buf == NULL)
9528 return -1;
9529
9530 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
9531 wpabuf_free(buf);
9532 return -1;
9533 }
9534
9535 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
9536 ParseFailed) {
9537 wpabuf_free(buf);
9538 return -1;
9539 }
9540
9541 if (wpa_s->vendor_elem[frame] == NULL) {
9542 wpa_s->vendor_elem[frame] = buf;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009543 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009544 return 0;
9545 }
9546
9547 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
9548 wpabuf_free(buf);
9549 return -1;
9550 }
9551
9552 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
9553 wpabuf_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009554 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009555
9556 return 0;
9557}
9558
9559
9560static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
9561 char *buf, size_t buflen)
9562{
9563 int frame = atoi(cmd);
9564
9565 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9566 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009567 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009568
9569 if (wpa_s->vendor_elem[frame] == NULL)
9570 return 0;
9571
9572 return wpa_snprintf_hex(buf, buflen,
9573 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
9574 wpabuf_len(wpa_s->vendor_elem[frame]));
9575}
9576
9577
9578static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
9579{
9580 char *pos = cmd;
9581 int frame;
9582 size_t len;
9583 u8 *buf;
9584 struct ieee802_11_elems elems;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009585 int res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009586
9587 frame = atoi(pos);
9588 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9589 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009590 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009591
9592 pos = os_strchr(pos, ' ');
9593 if (pos == NULL)
9594 return -1;
9595 pos++;
9596
9597 if (*pos == '*') {
9598 wpabuf_free(wpa_s->vendor_elem[frame]);
9599 wpa_s->vendor_elem[frame] = NULL;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009600 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009601 return 0;
9602 }
9603
9604 if (wpa_s->vendor_elem[frame] == NULL)
9605 return -1;
9606
9607 len = os_strlen(pos);
9608 if (len == 0)
9609 return 0;
9610 if (len & 1)
9611 return -1;
9612 len /= 2;
9613
9614 buf = os_malloc(len);
9615 if (buf == NULL)
9616 return -1;
9617
9618 if (hexstr2bin(pos, buf, len) < 0) {
9619 os_free(buf);
9620 return -1;
9621 }
9622
9623 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
9624 os_free(buf);
9625 return -1;
9626 }
9627
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009628 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009629 os_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009630 return res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009631}
9632
9633
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009634static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
9635{
9636 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009637 size_t len;
9638 const u8 *data;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009639
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009640 /*
9641 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9642 * BSSID[6]
9643 * BSSID Information[4]
9644 * Operating Class[1]
9645 * Channel Number[1]
9646 * PHY Type[1]
9647 * Optional Subelements[variable]
9648 */
9649#define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9650
9651 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009652 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009653 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009654 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009655
9656 data = wpabuf_head_u8(neighbor_rep);
9657 len = wpabuf_len(neighbor_rep);
9658
9659 while (len >= 2 + NR_IE_MIN_LEN) {
9660 const u8 *nr;
9661 char lci[256 * 2 + 1];
9662 char civic[256 * 2 + 1];
9663 u8 nr_len = data[1];
9664 const u8 *pos = data, *end;
9665
9666 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
9667 nr_len < NR_IE_MIN_LEN) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08009668 wpa_dbg(wpa_s, MSG_DEBUG,
9669 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9670 data[0], nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009671 goto out;
9672 }
9673
9674 if (2U + nr_len > len) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08009675 wpa_dbg(wpa_s, MSG_DEBUG,
9676 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9677 data[0], len, nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009678 goto out;
9679 }
9680 pos += 2;
9681 end = pos + nr_len;
9682
9683 nr = pos;
9684 pos += NR_IE_MIN_LEN;
9685
9686 lci[0] = '\0';
9687 civic[0] = '\0';
9688 while (end - pos > 2) {
9689 u8 s_id, s_len;
9690
9691 s_id = *pos++;
9692 s_len = *pos++;
9693 if (s_len > end - pos)
9694 goto out;
9695 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
9696 /* Measurement Token[1] */
9697 /* Measurement Report Mode[1] */
9698 /* Measurement Type[1] */
9699 /* Measurement Report[variable] */
9700 switch (pos[2]) {
9701 case MEASURE_TYPE_LCI:
9702 if (lci[0])
9703 break;
9704 wpa_snprintf_hex(lci, sizeof(lci),
9705 pos, s_len);
9706 break;
9707 case MEASURE_TYPE_LOCATION_CIVIC:
9708 if (civic[0])
9709 break;
9710 wpa_snprintf_hex(civic, sizeof(civic),
9711 pos, s_len);
9712 break;
9713 }
9714 }
9715
9716 pos += s_len;
9717 }
9718
9719 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
9720 "bssid=" MACSTR
9721 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9722 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
9723 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
9724 nr[ETH_ALEN + 6],
9725 lci[0] ? " lci=" : "", lci,
9726 civic[0] ? " civic=" : "", civic);
9727
9728 data = end;
9729 len -= 2 + nr_len;
9730 }
9731
9732out:
9733 wpabuf_free(neighbor_rep);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009734}
9735
9736
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009737static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
9738 char *cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009739{
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009740 struct wpa_ssid_value ssid, *ssid_p = NULL;
9741 int ret, lci = 0, civic = 0;
9742 char *ssid_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009743
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009744 ssid_s = os_strstr(cmd, "ssid=");
9745 if (ssid_s) {
9746 if (ssid_parse(ssid_s + 5, &ssid)) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08009747 wpa_msg(wpa_s, MSG_INFO,
9748 "CTRL: Send Neighbor Report: bad SSID");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009749 return -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009750 }
9751
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009752 ssid_p = &ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009753
9754 /*
9755 * Move cmd after the SSID text that may include "lci" or
9756 * "civic".
9757 */
9758 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
9759 if (cmd)
9760 cmd++;
9761
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009762 }
9763
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009764 if (cmd && os_strstr(cmd, "lci"))
9765 lci = 1;
9766
9767 if (cmd && os_strstr(cmd, "civic"))
9768 civic = 1;
9769
9770 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009771 wpas_ctrl_neighbor_rep_cb,
9772 wpa_s);
9773
9774 return ret;
9775}
9776
9777
9778static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
9779{
9780 eapol_sm_erp_flush(wpa_s->eapol);
9781 return 0;
9782}
9783
9784
9785static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
9786 char *cmd)
9787{
9788 char *token, *context = NULL;
9789 unsigned int enable = ~0, type = 0;
9790 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
9791 u8 *addr = NULL, *mask = NULL;
9792
9793 while ((token = str_token(cmd, " ", &context))) {
9794 if (os_strcasecmp(token, "scan") == 0) {
9795 type |= MAC_ADDR_RAND_SCAN;
9796 } else if (os_strcasecmp(token, "sched") == 0) {
9797 type |= MAC_ADDR_RAND_SCHED_SCAN;
9798 } else if (os_strcasecmp(token, "pno") == 0) {
9799 type |= MAC_ADDR_RAND_PNO;
9800 } else if (os_strcasecmp(token, "all") == 0) {
9801 type = wpa_s->mac_addr_rand_supported;
9802 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
9803 enable = atoi(token + 7);
9804 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
9805 addr = _addr;
9806 if (hwaddr_aton(token + 5, addr)) {
9807 wpa_printf(MSG_INFO,
9808 "CTRL: Invalid MAC address: %s",
9809 token);
9810 return -1;
9811 }
9812 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
9813 mask = _mask;
9814 if (hwaddr_aton(token + 5, mask)) {
9815 wpa_printf(MSG_INFO,
9816 "CTRL: Invalid MAC address mask: %s",
9817 token);
9818 return -1;
9819 }
9820 } else {
9821 wpa_printf(MSG_INFO,
9822 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9823 token);
9824 return -1;
9825 }
9826 }
9827
9828 if (!type) {
9829 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
9830 return -1;
9831 }
9832
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009833 if (enable > 1) {
9834 wpa_printf(MSG_INFO,
9835 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9836 return -1;
9837 }
9838
Hai Shalom81f62d82019-07-22 12:10:00 -07009839 if (!enable)
9840 return wpas_disable_mac_addr_randomization(wpa_s, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009841
Hai Shalom81f62d82019-07-22 12:10:00 -07009842 return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009843}
9844
9845
Dmitry Shmidte4663042016-04-04 10:07:49 -07009846static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
9847 char *buf, size_t buflen)
9848{
9849 size_t reply_len;
9850
9851 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
9852#ifdef CONFIG_AP
9853 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
9854 buflen - reply_len);
9855#endif /* CONFIG_AP */
9856 return reply_len;
9857}
9858
9859
9860static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
9861{
9862 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
9863#ifdef CONFIG_AP
9864 wpas_ap_pmksa_cache_flush(wpa_s);
9865#endif /* CONFIG_AP */
9866}
9867
9868
Dmitry Shmidt29333592017-01-09 12:27:11 -08009869#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9870
9871static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
9872 const char *cmd, char *buf, size_t buflen)
9873{
9874 struct rsn_pmksa_cache_entry *entry;
9875 struct wpa_ssid *ssid;
9876 char *pos, *pos2, *end;
9877 int ret;
9878 struct os_reltime now;
9879
9880 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
9881 if (!ssid)
9882 return -1;
9883
9884 pos = buf;
9885 end = buf + buflen;
9886
9887 os_get_reltime(&now);
9888
9889 /*
9890 * Entry format:
9891 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9892 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009893 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -08009894 */
9895
9896 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
9897 entry = entry->next) {
9898 if (entry->network_ctx != ssid)
9899 continue;
9900
9901 pos2 = pos;
9902 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
9903 MAC2STR(entry->aa));
9904 if (os_snprintf_error(end - pos2, ret))
9905 break;
9906 pos2 += ret;
9907
9908 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
9909 PMKID_LEN);
9910
9911 ret = os_snprintf(pos2, end - pos2, " ");
9912 if (os_snprintf_error(end - pos2, ret))
9913 break;
9914 pos2 += ret;
9915
9916 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
9917 entry->pmk_len);
9918
9919 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
9920 (int) (entry->reauth_time - now.sec),
9921 (int) (entry->expiration - now.sec),
9922 entry->akmp,
9923 entry->opportunistic);
9924 if (os_snprintf_error(end - pos2, ret))
9925 break;
9926 pos2 += ret;
9927
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009928 if (entry->fils_cache_id_set) {
9929 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
9930 entry->fils_cache_id[0],
9931 entry->fils_cache_id[1]);
9932 if (os_snprintf_error(end - pos2, ret))
9933 break;
9934 pos2 += ret;
9935 }
9936
Dmitry Shmidt29333592017-01-09 12:27:11 -08009937 ret = os_snprintf(pos2, end - pos2, "\n");
9938 if (os_snprintf_error(end - pos2, ret))
9939 break;
9940 pos2 += ret;
9941
9942 pos = pos2;
9943 }
9944
9945 return pos - buf;
9946}
9947
9948
9949static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
9950 char *cmd)
9951{
9952 struct rsn_pmksa_cache_entry *entry;
9953 struct wpa_ssid *ssid;
9954 char *pos, *pos2;
9955 int ret = -1;
9956 struct os_reltime now;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009957 int reauth_time = 0, expiration = 0, i;
Dmitry Shmidt29333592017-01-09 12:27:11 -08009958
9959 /*
9960 * Entry format:
9961 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9962 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009963 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -08009964 */
9965
9966 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
9967 if (!ssid)
9968 return -1;
9969
9970 pos = os_strchr(cmd, ' ');
9971 if (!pos)
9972 return -1;
9973 pos++;
9974
9975 entry = os_zalloc(sizeof(*entry));
9976 if (!entry)
9977 return -1;
9978
9979 if (hwaddr_aton(pos, entry->aa))
9980 goto fail;
9981
9982 pos = os_strchr(pos, ' ');
9983 if (!pos)
9984 goto fail;
9985 pos++;
9986
9987 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
9988 goto fail;
9989
9990 pos = os_strchr(pos, ' ');
9991 if (!pos)
9992 goto fail;
9993 pos++;
9994
9995 pos2 = os_strchr(pos, ' ');
9996 if (!pos2)
9997 goto fail;
9998 entry->pmk_len = (pos2 - pos) / 2;
9999 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
10000 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
10001 goto fail;
10002
10003 pos = os_strchr(pos, ' ');
10004 if (!pos)
10005 goto fail;
10006 pos++;
10007
10008 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
10009 &entry->akmp, &entry->opportunistic) != 4)
10010 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010011 for (i = 0; i < 4; i++) {
10012 pos = os_strchr(pos, ' ');
10013 if (!pos) {
10014 if (i < 3)
10015 goto fail;
10016 break;
10017 }
10018 pos++;
10019 }
10020 if (pos) {
10021 if (hexstr2bin(pos, entry->fils_cache_id,
10022 FILS_CACHE_ID_LEN) < 0)
10023 goto fail;
10024 entry->fils_cache_id_set = 1;
10025 }
Dmitry Shmidt29333592017-01-09 12:27:11 -080010026 os_get_reltime(&now);
10027 entry->expiration = now.sec + expiration;
10028 entry->reauth_time = now.sec + reauth_time;
10029
10030 entry->network_ctx = ssid;
10031
10032 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
10033 entry = NULL;
10034 ret = 0;
10035fail:
10036 os_free(entry);
10037 return ret;
10038}
10039
Paul Stewart092955c2017-02-06 09:13:09 -080010040
10041#ifdef CONFIG_MESH
10042
10043static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
10044 const char *cmd, char *buf,
10045 size_t buflen)
10046{
10047 u8 spa[ETH_ALEN];
10048
10049 if (!wpa_s->ifmsh)
10050 return -1;
10051
10052 if (os_strcasecmp(cmd, "any") == 0)
10053 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
10054
10055 if (hwaddr_aton(cmd, spa))
10056 return -1;
10057
10058 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
10059}
10060
10061
10062static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
10063 char *cmd)
10064{
10065 /*
10066 * We do not check mesh interface existance because PMKSA should be
10067 * stored before wpa_s->ifmsh creation to suppress commit message
10068 * creation.
10069 */
10070 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
10071}
10072
10073#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080010074#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
10075
10076
Paul Stewart092955c2017-02-06 09:13:09 -080010077#ifdef CONFIG_FILS
10078static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
10079 const char *cmd)
10080{
10081 struct fils_hlp_req *req;
10082 const char *pos;
10083
10084 /* format: <dst> <packet starting from ethertype> */
10085
10086 req = os_zalloc(sizeof(*req));
10087 if (!req)
10088 return -1;
10089
10090 if (hwaddr_aton(cmd, req->dst))
10091 goto fail;
10092
10093 pos = os_strchr(cmd, ' ');
10094 if (!pos)
10095 goto fail;
10096 pos++;
10097 req->pkt = wpabuf_parse_bin(pos);
10098 if (!req->pkt)
10099 goto fail;
10100
10101 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
10102 return 0;
10103fail:
10104 wpabuf_free(req->pkt);
10105 os_free(req);
10106 return -1;
10107}
10108#endif /* CONFIG_FILS */
10109
10110
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010111static int wpas_ctrl_cmd_debug_level(const char *cmd)
10112{
10113 if (os_strcmp(cmd, "PING") == 0 ||
10114 os_strncmp(cmd, "BSS ", 4) == 0 ||
10115 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
10116 os_strncmp(cmd, "STATUS", 6) == 0 ||
10117 os_strncmp(cmd, "STA ", 4) == 0 ||
10118 os_strncmp(cmd, "STA-", 4) == 0)
10119 return MSG_EXCESSIVE;
10120 return MSG_DEBUG;
10121}
10122
10123
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010124char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
10125 char *buf, size_t *resp_len)
10126{
10127 char *reply;
10128 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010129 int reply_len;
10130
10131 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010132 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
10133 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
10134 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010135 if (wpa_debug_show_keys)
10136 wpa_dbg(wpa_s, MSG_DEBUG,
10137 "Control interface command '%s'", buf);
10138 else
10139 wpa_dbg(wpa_s, MSG_DEBUG,
10140 "Control interface command '%s [REMOVED]'",
10141 os_strncmp(buf, WPA_CTRL_RSP,
10142 os_strlen(WPA_CTRL_RSP)) == 0 ?
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010143 WPA_CTRL_RSP :
10144 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
10145 "SET_NETWORK" : "key-add"));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010146 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010147 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010148 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
10149 (const u8 *) buf, os_strlen(buf));
10150 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010151 int level = wpas_ctrl_cmd_debug_level(buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -070010152 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010153 }
10154
10155 reply = os_malloc(reply_size);
10156 if (reply == NULL) {
10157 *resp_len = 1;
10158 return NULL;
10159 }
10160
10161 os_memcpy(reply, "OK\n", 3);
10162 reply_len = 3;
10163
10164 if (os_strcmp(buf, "PING") == 0) {
10165 os_memcpy(reply, "PONG\n", 5);
10166 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010167 } else if (os_strcmp(buf, "IFNAME") == 0) {
10168 reply_len = os_strlen(wpa_s->ifname);
10169 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010170 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
10171 if (wpa_debug_reopen_file() < 0)
10172 reply_len = -1;
10173 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
10174 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
10175 } else if (os_strcmp(buf, "MIB") == 0) {
10176 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
10177 if (reply_len >= 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010178 reply_len += eapol_sm_get_mib(wpa_s->eapol,
10179 reply + reply_len,
10180 reply_size - reply_len);
Hai Shalom74f70d42019-02-11 14:42:39 -080010181#ifdef CONFIG_MACSEC
10182 reply_len += ieee802_1x_kay_get_mib(
10183 wpa_s->kay, reply + reply_len,
10184 reply_size - reply_len);
10185#endif /* CONFIG_MACSEC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010186 }
10187 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
10188 reply_len = wpa_supplicant_ctrl_iface_status(
10189 wpa_s, buf + 6, reply, reply_size);
10190 } else if (os_strcmp(buf, "PMKSA") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070010191 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070010192 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070010193 wpas_ctrl_iface_pmksa_flush(wpa_s);
Dmitry Shmidt29333592017-01-09 12:27:11 -080010194#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10195 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
10196 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
10197 reply, reply_size);
10198 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
10199 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
10200 reply_len = -1;
Paul Stewart092955c2017-02-06 09:13:09 -080010201#ifdef CONFIG_MESH
10202 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
10203 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
10204 reply, reply_size);
10205 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
10206 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
10207 reply_len = -1;
10208#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080010209#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010210 } else if (os_strncmp(buf, "SET ", 4) == 0) {
10211 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
10212 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010213 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
10214 reply_len = wpa_config_dump_values(wpa_s->conf,
10215 reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010216 } else if (os_strncmp(buf, "GET ", 4) == 0) {
10217 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
10218 reply, reply_size);
10219 } else if (os_strcmp(buf, "LOGON") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070010220 eapol_sm_notify_logoff(wpa_s->eapol, false);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010221 } else if (os_strcmp(buf, "LOGOFF") == 0) {
Hai Shalome21d4e82020-04-29 16:34:06 -070010222 eapol_sm_notify_logoff(wpa_s->eapol, true);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010223 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
10224 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
10225 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010226 else
10227 wpas_request_connection(wpa_s);
Dmitry Shmidt98660862014-03-11 17:26:21 -070010228 } else if (os_strcmp(buf, "REATTACH") == 0) {
10229 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
10230 !wpa_s->current_ssid)
10231 reply_len = -1;
10232 else {
10233 wpa_s->reattach = 1;
10234 wpas_request_connection(wpa_s);
10235 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010236 } else if (os_strcmp(buf, "RECONNECT") == 0) {
10237 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
10238 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010239 else if (wpa_s->disconnected)
10240 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010241#ifdef IEEE8021X_EAPOL
10242 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
10243 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
10244 reply_len = -1;
10245#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010246#ifdef CONFIG_IEEE80211R
10247 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
10248 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
10249 reply_len = -1;
10250#endif /* CONFIG_IEEE80211R */
10251#ifdef CONFIG_WPS
10252 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
10253 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
10254 if (res == -2) {
10255 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10256 reply_len = 17;
10257 } else if (res)
10258 reply_len = -1;
10259 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
10260 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
10261 if (res == -2) {
10262 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10263 reply_len = 17;
10264 } else if (res)
10265 reply_len = -1;
10266 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
10267 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
10268 reply,
10269 reply_size);
10270 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
10271 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
10272 wpa_s, buf + 14, reply, reply_size);
10273 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
10274 if (wpas_wps_cancel(wpa_s))
10275 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010276#ifdef CONFIG_WPS_NFC
10277 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
10278 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
10279 reply_len = -1;
10280 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
10281 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
10282 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -080010283 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
10284 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
10285 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010286 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
10287 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
10288 wpa_s, buf + 14, reply, reply_size);
10289 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
10290 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
10291 buf + 17))
10292 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010293 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
10294 reply_len = wpas_ctrl_nfc_get_handover_req(
10295 wpa_s, buf + 21, reply, reply_size);
10296 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
10297 reply_len = wpas_ctrl_nfc_get_handover_sel(
10298 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -080010299 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
10300 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
10301 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010302#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010303 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
10304 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
10305 reply_len = -1;
10306#ifdef CONFIG_AP
10307 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
10308 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
10309 wpa_s, buf + 11, reply, reply_size);
10310#endif /* CONFIG_AP */
10311#ifdef CONFIG_WPS_ER
10312 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
10313 if (wpas_wps_er_start(wpa_s, NULL))
10314 reply_len = -1;
10315 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
10316 if (wpas_wps_er_start(wpa_s, buf + 13))
10317 reply_len = -1;
10318 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010319 wpas_wps_er_stop(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010320 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
10321 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
10322 reply_len = -1;
10323 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
10324 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
10325 if (ret == -2) {
10326 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10327 reply_len = 17;
10328 } else if (ret == -3) {
10329 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
10330 reply_len = 18;
10331 } else if (ret == -4) {
10332 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
10333 reply_len = 20;
10334 } else if (ret)
10335 reply_len = -1;
10336 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
10337 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
10338 reply_len = -1;
10339 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
10340 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
10341 buf + 18))
10342 reply_len = -1;
10343 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
10344 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
10345 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010346#ifdef CONFIG_WPS_NFC
10347 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10348 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10349 wpa_s, buf + 24, reply, reply_size);
10350#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010351#endif /* CONFIG_WPS_ER */
10352#endif /* CONFIG_WPS */
10353#ifdef CONFIG_IBSS_RSN
10354 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
10355 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
10356 reply_len = -1;
10357#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010358#ifdef CONFIG_MESH
10359 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
10360 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10361 wpa_s, buf + 19, reply, reply_size);
10362 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
10363 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10364 wpa_s, "", reply, reply_size);
10365 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
10366 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
10367 reply_len = -1;
10368 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
10369 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
10370 buf + 18))
10371 reply_len = -1;
Dmitry Shmidte4663042016-04-04 10:07:49 -070010372 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
10373 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
10374 reply_len = -1;
10375 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
10376 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
10377 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070010378 } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) {
10379 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16))
10380 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010381#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010382#ifdef CONFIG_P2P
10383 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010384 if (p2p_ctrl_find(wpa_s, buf + 8))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010385 reply_len = -1;
10386 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
10387 if (p2p_ctrl_find(wpa_s, ""))
10388 reply_len = -1;
10389 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
10390 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010391 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
10392 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
10393 reply_len = -1;
10394 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10395 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
10396 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010397 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
10398 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
10399 reply_size);
10400 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
10401 if (p2p_ctrl_listen(wpa_s, buf + 11))
10402 reply_len = -1;
10403 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
10404 if (p2p_ctrl_listen(wpa_s, ""))
10405 reply_len = -1;
10406 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
10407 if (wpas_p2p_group_remove(wpa_s, buf + 17))
10408 reply_len = -1;
10409 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070010410 if (p2p_ctrl_group_add(wpa_s, ""))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010411 reply_len = -1;
10412 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
10413 if (p2p_ctrl_group_add(wpa_s, buf + 14))
10414 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010415 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
10416 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
10417 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010418 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
10419 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
10420 reply_len = -1;
10421 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
10422 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
10423 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
10424 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
10425 reply_size);
10426 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10427 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
10428 reply_len = -1;
10429 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
10430 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
10431 reply_len = -1;
10432 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
10433 wpas_p2p_sd_service_update(wpa_s);
10434 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10435 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
10436 reply_len = -1;
10437 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
10438 wpas_p2p_service_flush(wpa_s);
10439 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
10440 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
10441 reply_len = -1;
10442 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
10443 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
10444 reply_len = -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010445 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
10446 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
10447 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010448 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
10449 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
10450 reply_len = -1;
10451 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
10452 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
10453 reply_len = -1;
10454 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
10455 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
10456 reply_size);
10457 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
10458 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
10459 reply_len = -1;
10460 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -070010461 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010462 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
10463 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
10464 reply_len = -1;
10465 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
10466 if (wpas_p2p_cancel(wpa_s))
10467 reply_len = -1;
10468 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
10469 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
10470 reply_len = -1;
10471 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
10472 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
10473 reply_len = -1;
10474 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
10475 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
10476 reply_len = -1;
10477 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
10478 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
10479 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070010480 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
10481 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
10482 reply_len = -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010483 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
10484 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
10485 reply_len = -1;
10486 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
10487 if (wpas_p2p_lo_stop(wpa_s))
10488 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010489#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010490#ifdef CONFIG_WIFI_DISPLAY
10491 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
10492 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
10493 reply_len = -1;
10494 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
10495 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
10496 reply, reply_size);
10497#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010498#ifdef CONFIG_INTERWORKING
10499 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
10500 if (interworking_fetch_anqp(wpa_s) < 0)
10501 reply_len = -1;
10502 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
10503 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010504 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
10505 if (ctrl_interworking_select(wpa_s, NULL) < 0)
10506 reply_len = -1;
10507 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
10508 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010509 reply_len = -1;
10510 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010511 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010512 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010513 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10514 int id;
10515
10516 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
10517 if (id < 0)
10518 reply_len = -1;
10519 else {
10520 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
10521 if (os_snprintf_error(reply_size, reply_len))
10522 reply_len = -1;
10523 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010524 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
10525 if (get_anqp(wpa_s, buf + 9) < 0)
10526 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010527 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
10528 if (gas_request(wpa_s, buf + 12) < 0)
10529 reply_len = -1;
10530 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
10531 reply_len = gas_response_get(wpa_s, buf + 17, reply,
10532 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010533#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -070010534#ifdef CONFIG_HS20
10535 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
10536 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
10537 reply_len = -1;
10538 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10539 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
10540 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010541 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080010542 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
10543 reply_len = -1;
10544 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
10545 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
10546 reply_len = -1;
10547 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
10548 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
10549 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
10550 if (del_hs20_icon(wpa_s, buf + 14) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010551 reply_len = -1;
10552 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010553 if (hs20_fetch_osu(wpa_s, 0) < 0)
10554 reply_len = -1;
10555 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
10556 if (hs20_fetch_osu(wpa_s, 1) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010557 reply_len = -1;
10558 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
10559 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010560#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010561 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
10562 {
10563 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10564 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
10565 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -070010566 else {
10567 /*
10568 * Notify response from timeout to allow the control
10569 * interface response to be sent first.
10570 */
10571 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
10572 wpa_s, NULL);
10573 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010574 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
10575 if (wpa_supplicant_reload_configuration(wpa_s))
10576 reply_len = -1;
10577 } else if (os_strcmp(buf, "TERMINATE") == 0) {
10578 wpa_supplicant_terminate_proc(wpa_s->global);
10579 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
10580 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
10581 reply_len = -1;
Dmitry Shmidte19501d2011-03-16 14:32:18 -070010582 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010583 reply_len = wpa_supplicant_ctrl_iface_blacklist(
10584 wpa_s, buf + 9, reply, reply_size);
10585 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
10586 reply_len = wpa_supplicant_ctrl_iface_log_level(
10587 wpa_s, buf + 9, reply, reply_size);
Vinit Deshpandeda134e92014-12-02 10:59:29 -080010588 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
10589 reply_len = wpa_supplicant_ctrl_iface_list_networks(
10590 wpa_s, buf + 14, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010591 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
10592 reply_len = wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -080010593 wpa_s, NULL, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010594 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070010595 wpas_request_disconnection(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010596 } else if (os_strcmp(buf, "SCAN") == 0) {
10597 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
10598 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
10599 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010600 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
10601 reply_len = wpa_supplicant_ctrl_iface_scan_results(
10602 wpa_s, reply, reply_size);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010603 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
10604 if (wpas_abort_ongoing_scan(wpa_s) < 0)
10605 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010606 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
10607 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
10608 reply_len = -1;
10609 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
10610 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
10611 reply_len = -1;
10612 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
10613 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
10614 reply_len = -1;
10615 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
10616 reply_len = wpa_supplicant_ctrl_iface_add_network(
10617 wpa_s, reply, reply_size);
10618 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
10619 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
10620 reply_len = -1;
10621 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
10622 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
10623 reply_len = -1;
10624 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
10625 reply_len = wpa_supplicant_ctrl_iface_get_network(
10626 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt684785c2014-05-12 13:34:29 -070010627 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010628 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
10629 wpa_s))
Dmitry Shmidt684785c2014-05-12 13:34:29 -070010630 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010631 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
10632 reply_len = wpa_supplicant_ctrl_iface_list_creds(
10633 wpa_s, reply, reply_size);
10634 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
10635 reply_len = wpa_supplicant_ctrl_iface_add_cred(
10636 wpa_s, reply, reply_size);
10637 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
10638 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
10639 reply_len = -1;
10640 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
10641 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
10642 reply_len = -1;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -070010643 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
10644 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
10645 reply,
10646 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010647#ifndef CONFIG_NO_CONFIG_WRITE
10648 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
10649 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
10650 reply_len = -1;
10651#endif /* CONFIG_NO_CONFIG_WRITE */
10652 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
10653 reply_len = wpa_supplicant_ctrl_iface_get_capability(
10654 wpa_s, buf + 15, reply, reply_size);
10655 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
10656 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
10657 reply_len = -1;
10658 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
10659 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
10660 reply_len = -1;
10661 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
10662 reply_len = wpa_supplicant_global_iface_list(
10663 wpa_s->global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010664 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010665 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010666 wpa_s->global, buf + 10, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010667 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
10668 reply_len = wpa_supplicant_ctrl_iface_bss(
10669 wpa_s, buf + 4, reply, reply_size);
10670#ifdef CONFIG_AP
10671 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
10672 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
10673 } else if (os_strncmp(buf, "STA ", 4) == 0) {
10674 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
10675 reply_size);
10676 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
10677 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
10678 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010679 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
10680 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
10681 reply_len = -1;
10682 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
10683 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
10684 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080010685 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
10686 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
10687 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010688 } else if (os_strcmp(buf, "STOP_AP") == 0) {
10689 if (wpas_ap_stop_ap(wpa_s))
10690 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010691#endif /* CONFIG_AP */
10692 } else if (os_strcmp(buf, "SUSPEND") == 0) {
10693 wpas_notify_suspend(wpa_s->global);
10694 } else if (os_strcmp(buf, "RESUME") == 0) {
10695 wpas_notify_resume(wpa_s->global);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010696#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010697 } else if (os_strcmp(buf, "DROP_SA") == 0) {
10698 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010699#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010700 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
10701 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
10702 reply_len = -1;
10703 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010704 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010705 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
10706 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
10707 reply_len = -1;
10708 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
10709 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
10710 buf + 17))
10711 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -070010712 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010713 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010714#ifdef CONFIG_TDLS
10715 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
10716 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
10717 reply_len = -1;
10718 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
10719 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
10720 reply_len = -1;
10721 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
10722 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
10723 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010724 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
10725 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
10726 buf + 17))
10727 reply_len = -1;
10728 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10729 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
10730 buf + 24))
10731 reply_len = -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -070010732 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
10733 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
10734 wpa_s, buf + 17, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010735#endif /* CONFIG_TDLS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010736 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
10737 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
10738 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
10739 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
10740 reply_len = -1;
10741 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
10742 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
10743 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010744 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
10745 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
10746 reply_size);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080010747 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
10748 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
10749 reply_len = -1;
Yuhao Zhengfcd6f212012-07-27 10:37:52 -070010750 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
10751 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
10752 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010753#ifdef CONFIG_AUTOSCAN
10754 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
10755 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
10756 reply_len = -1;
10757#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010758 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
10759 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
10760 reply_size);
Hai Shalomb755a2a2020-04-23 21:49:02 -070010761 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
10762 reply_len = wpas_ctrl_iface_driver_flags2(wpa_s, reply,
10763 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080010764#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -070010765 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
10766 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
10767 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080010768#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080010769 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
10770 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
10771 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010772 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010773 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010774 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080010775#ifdef CONFIG_WNM
10776 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
10777 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
10778 reply_len = -1;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080010779 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
10780 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
Dmitry Shmidt44c95782013-05-17 09:51:35 -070010781 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -080010782 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
10783 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
10784 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080010785#endif /* CONFIG_WNM */
Dmitry Shmidt444d5672013-04-01 13:08:44 -070010786 } else if (os_strcmp(buf, "FLUSH") == 0) {
10787 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010788 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
10789 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
10790 reply_size);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070010791#ifdef CONFIG_TESTING_OPTIONS
10792 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
10793 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
10794 reply_len = -1;
10795 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
10796 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010797 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
10798 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
10799 reply_len = -1;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -070010800 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
10801 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
10802 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010803 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
10804 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
10805 reply_len = -1;
10806 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
10807 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
10808 reply_len = -1;
10809 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
10810 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
10811 reply_len = -1;
10812 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
10813 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
10814 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010815 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
10816 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
10817 reply_len = -1;
10818 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
10819 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010820 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
10821 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
10822 reply_len = -1;
10823 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
10824 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
Jouni Malinenc4818362015-10-04 11:45:13 +030010825 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
10826 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
10827 reply_len = -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010828 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
10829 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
10830 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010831 } else if (os_strcmp(buf, "RESET_PN") == 0) {
10832 if (wpas_ctrl_reset_pn(wpa_s) < 0)
10833 reply_len = -1;
10834 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
10835 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
10836 reply_len = -1;
10837 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
10838 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
10839 reply_len = -1;
Hai Shalom74f70d42019-02-11 14:42:39 -080010840 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
10841 sme_event_unprot_disconnect(
10842 wpa_s, wpa_s->bssid, NULL,
10843 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070010844#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010845 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
10846 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
10847 reply_len = -1;
10848 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
10849 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
10850 reply_size);
10851 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10852 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
10853 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010854 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010855 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010856 reply_len = -1;
10857 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
10858 wpas_ctrl_iface_erp_flush(wpa_s);
10859 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
10860 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
10861 reply_len = -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010862 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
10863 reply_len = wpas_ctrl_iface_get_pref_freq_list(
10864 wpa_s, buf + 19, reply, reply_size);
Paul Stewart092955c2017-02-06 09:13:09 -080010865#ifdef CONFIG_FILS
10866 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
10867 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
10868 reply_len = -1;
10869 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
10870 wpas_flush_fils_hlp_req(wpa_s);
10871#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010872#ifdef CONFIG_DPP
10873 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
10874 int res;
10875
10876 res = wpas_dpp_qr_code(wpa_s, buf + 12);
10877 if (res < 0) {
10878 reply_len = -1;
10879 } else {
10880 reply_len = os_snprintf(reply, reply_size, "%d", res);
10881 if (os_snprintf_error(reply_size, reply_len))
10882 reply_len = -1;
10883 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010884 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
10885 int res;
10886
10887 res = wpas_dpp_nfc_uri(wpa_s, buf + 12);
10888 if (res < 0) {
10889 reply_len = -1;
10890 } else {
10891 reply_len = os_snprintf(reply, reply_size, "%d", res);
10892 if (os_snprintf_error(reply_size, reply_len))
10893 reply_len = -1;
10894 }
Hai Shalomfdcde762020-04-02 11:19:20 -070010895 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
10896 int res;
10897
10898 res = wpas_dpp_nfc_handover_req(wpa_s, buf + 20);
10899 if (res < 0) {
10900 reply_len = -1;
10901 } else {
10902 reply_len = os_snprintf(reply, reply_size, "%d", res);
10903 if (os_snprintf_error(reply_size, reply_len))
10904 reply_len = -1;
10905 }
10906 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
10907 int res;
10908
10909 res = wpas_dpp_nfc_handover_sel(wpa_s, buf + 20);
10910 if (res < 0) {
10911 reply_len = -1;
10912 } else {
10913 reply_len = os_snprintf(reply, reply_size, "%d", res);
10914 if (os_snprintf_error(reply_size, reply_len))
10915 reply_len = -1;
10916 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010917 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10918 int res;
10919
Hai Shalom021b0b52019-04-10 11:17:58 -070010920 res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010921 if (res < 0) {
10922 reply_len = -1;
10923 } else {
10924 reply_len = os_snprintf(reply, reply_size, "%d", res);
10925 if (os_snprintf_error(reply_size, reply_len))
10926 reply_len = -1;
10927 }
10928 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070010929 if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010930 reply_len = -1;
10931 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10932 const char *uri;
10933
Hai Shalom021b0b52019-04-10 11:17:58 -070010934 uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010935 if (!uri) {
10936 reply_len = -1;
10937 } else {
10938 reply_len = os_snprintf(reply, reply_size, "%s", uri);
10939 if (os_snprintf_error(reply_size, reply_len))
10940 reply_len = -1;
10941 }
10942 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070010943 reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19),
10944 reply, reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -070010945 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
10946 if (dpp_bootstrap_set(wpa_s->dpp, atoi(buf + 18),
10947 os_strchr(buf + 18, ' ')) < 0)
10948 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010949 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
10950 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
10951 reply_len = -1;
10952 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
10953 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
10954 reply_len = -1;
10955 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -070010956 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010957 wpas_dpp_listen_stop(wpa_s);
10958 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10959 int res;
10960
Hai Shalom021b0b52019-04-10 11:17:58 -070010961 res = dpp_configurator_add(wpa_s->dpp, buf + 20);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010962 if (res < 0) {
10963 reply_len = -1;
10964 } else {
10965 reply_len = os_snprintf(reply, reply_size, "%d", res);
10966 if (os_snprintf_error(reply_size, reply_len))
10967 reply_len = -1;
10968 }
10969 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070010970 if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010971 reply_len = -1;
10972 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -080010973 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010974 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -070010975 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070010976 reply_len = dpp_configurator_get_key_id(wpa_s->dpp,
10977 atoi(buf + 25),
10978 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010979 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
10980 int res;
10981
10982 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
10983 if (res < 0) {
10984 reply_len = -1;
10985 } else {
10986 reply_len = os_snprintf(reply, reply_size, "%d", res);
10987 if (os_snprintf_error(reply_size, reply_len))
10988 reply_len = -1;
10989 }
10990 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
10991 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
10992 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070010993#ifdef CONFIG_DPP2
10994 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
10995 if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0)
10996 reply_len = -1;
10997 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
10998 if (wpas_dpp_controller_start(wpa_s, NULL) < 0)
10999 reply_len = -1;
11000 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
11001 dpp_controller_stop(wpa_s->dpp);
Hai Shalomfdcde762020-04-02 11:19:20 -070011002 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
11003 if (wpas_dpp_chirp(wpa_s, buf + 9) < 0)
11004 reply_len = -1;
11005 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
11006 wpas_dpp_chirp_stop(wpa_s);
Hai Shalom81f62d82019-07-22 12:10:00 -070011007#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011008#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011009 } else {
11010 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
11011 reply_len = 16;
11012 }
11013
11014 if (reply_len < 0) {
11015 os_memcpy(reply, "FAIL\n", 5);
11016 reply_len = 5;
11017 }
11018
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011019 *resp_len = reply_len;
11020 return reply;
11021}
11022
11023
11024static int wpa_supplicant_global_iface_add(struct wpa_global *global,
11025 char *cmd)
11026{
11027 struct wpa_interface iface;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011028 char *pos, *extra;
11029 struct wpa_supplicant *wpa_s;
11030 unsigned int create_iface = 0;
11031 u8 mac_addr[ETH_ALEN];
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011032 enum wpa_driver_if_type type = WPA_IF_STATION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011033
11034 /*
11035 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011036 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011037 */
11038 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
11039
11040 os_memset(&iface, 0, sizeof(iface));
11041
11042 do {
11043 iface.ifname = pos = cmd;
11044 pos = os_strchr(pos, '\t');
11045 if (pos)
11046 *pos++ = '\0';
11047 if (iface.ifname[0] == '\0')
11048 return -1;
11049 if (pos == NULL)
11050 break;
11051
11052 iface.confname = pos;
11053 pos = os_strchr(pos, '\t');
11054 if (pos)
11055 *pos++ = '\0';
11056 if (iface.confname[0] == '\0')
11057 iface.confname = NULL;
11058 if (pos == NULL)
11059 break;
11060
11061 iface.driver = pos;
11062 pos = os_strchr(pos, '\t');
11063 if (pos)
11064 *pos++ = '\0';
11065 if (iface.driver[0] == '\0')
11066 iface.driver = NULL;
11067 if (pos == NULL)
11068 break;
11069
11070 iface.ctrl_interface = pos;
11071 pos = os_strchr(pos, '\t');
11072 if (pos)
11073 *pos++ = '\0';
11074 if (iface.ctrl_interface[0] == '\0')
11075 iface.ctrl_interface = NULL;
11076 if (pos == NULL)
11077 break;
11078
11079 iface.driver_param = pos;
11080 pos = os_strchr(pos, '\t');
11081 if (pos)
11082 *pos++ = '\0';
11083 if (iface.driver_param[0] == '\0')
11084 iface.driver_param = NULL;
11085 if (pos == NULL)
11086 break;
11087
11088 iface.bridge_ifname = pos;
11089 pos = os_strchr(pos, '\t');
11090 if (pos)
11091 *pos++ = '\0';
11092 if (iface.bridge_ifname[0] == '\0')
11093 iface.bridge_ifname = NULL;
11094 if (pos == NULL)
11095 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011096
11097 extra = pos;
11098 pos = os_strchr(pos, '\t');
11099 if (pos)
11100 *pos++ = '\0';
Dmitry Shmidt83474442015-04-15 13:47:09 -070011101 if (!extra[0])
11102 break;
11103
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011104 if (os_strcmp(extra, "create") == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011105 create_iface = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011106 if (!pos)
11107 break;
11108
11109 if (os_strcmp(pos, "sta") == 0) {
11110 type = WPA_IF_STATION;
11111 } else if (os_strcmp(pos, "ap") == 0) {
11112 type = WPA_IF_AP_BSS;
11113 } else {
11114 wpa_printf(MSG_DEBUG,
11115 "INTERFACE_ADD unsupported interface type: '%s'",
11116 pos);
11117 return -1;
11118 }
11119 } else {
Dmitry Shmidt83474442015-04-15 13:47:09 -070011120 wpa_printf(MSG_DEBUG,
11121 "INTERFACE_ADD unsupported extra parameter: '%s'",
11122 extra);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011123 return -1;
Dmitry Shmidt83474442015-04-15 13:47:09 -070011124 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011125 } while (0);
11126
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011127 if (create_iface) {
11128 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
11129 iface.ifname);
11130 if (!global->ifaces)
11131 return -1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080011132 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011133 NULL, NULL, NULL, mac_addr, NULL) < 0) {
11134 wpa_printf(MSG_ERROR,
11135 "CTRL_IFACE interface creation failed");
11136 return -1;
11137 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011138
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011139 wpa_printf(MSG_DEBUG,
11140 "CTRL_IFACE interface '%s' created with MAC addr: "
11141 MACSTR, iface.ifname, MAC2STR(mac_addr));
11142 }
11143
11144 if (wpa_supplicant_get_iface(global, iface.ifname))
11145 goto fail;
11146
11147 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
11148 if (!wpa_s)
11149 goto fail;
11150 wpa_s->added_vif = create_iface;
11151 return 0;
11152
11153fail:
11154 if (create_iface)
11155 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
11156 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011157}
11158
11159
11160static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
11161 char *cmd)
11162{
11163 struct wpa_supplicant *wpa_s;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011164 int ret;
11165 unsigned int delete_iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011166
11167 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
11168
11169 wpa_s = wpa_supplicant_get_iface(global, cmd);
11170 if (wpa_s == NULL)
11171 return -1;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070011172 delete_iface = wpa_s->added_vif;
11173 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
11174 if (!ret && delete_iface) {
11175 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
11176 cmd);
11177 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
11178 }
11179 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011180}
11181
11182
11183static void wpa_free_iface_info(struct wpa_interface_info *iface)
11184{
11185 struct wpa_interface_info *prev;
11186
11187 while (iface) {
11188 prev = iface;
11189 iface = iface->next;
11190
11191 os_free(prev->ifname);
11192 os_free(prev->desc);
11193 os_free(prev);
11194 }
11195}
11196
11197
11198static int wpa_supplicant_global_iface_list(struct wpa_global *global,
11199 char *buf, int len)
11200{
11201 int i, res;
11202 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
11203 char *pos, *end;
11204
11205 for (i = 0; wpa_drivers[i]; i++) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070011206 const struct wpa_driver_ops *drv = wpa_drivers[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011207 if (drv->get_interfaces == NULL)
11208 continue;
11209 tmp = drv->get_interfaces(global->drv_priv[i]);
11210 if (tmp == NULL)
11211 continue;
11212
11213 if (last == NULL)
11214 iface = last = tmp;
11215 else
11216 last->next = tmp;
11217 while (last->next)
11218 last = last->next;
11219 }
11220
11221 pos = buf;
11222 end = buf + len;
11223 for (tmp = iface; tmp; tmp = tmp->next) {
11224 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
11225 tmp->drv_name, tmp->ifname,
11226 tmp->desc ? tmp->desc : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011227 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011228 *pos = '\0';
11229 break;
11230 }
11231 pos += res;
11232 }
11233
11234 wpa_free_iface_info(iface);
11235
11236 return pos - buf;
11237}
11238
11239
11240static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011241 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011242 char *buf, int len)
11243{
11244 int res;
11245 char *pos, *end;
11246 struct wpa_supplicant *wpa_s;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011247 int show_ctrl = 0;
11248
11249 if (input)
11250 show_ctrl = !!os_strstr(input, "ctrl");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011251
11252 wpa_s = global->ifaces;
11253 pos = buf;
11254 end = buf + len;
11255
11256 while (wpa_s) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011257 if (show_ctrl)
11258 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
11259 wpa_s->ifname,
11260 wpa_s->conf->ctrl_interface ?
11261 wpa_s->conf->ctrl_interface : "N/A");
11262 else
11263 res = os_snprintf(pos, end - pos, "%s\n",
11264 wpa_s->ifname);
11265
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011266 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011267 *pos = '\0';
11268 break;
11269 }
11270 pos += res;
11271 wpa_s = wpa_s->next;
11272 }
11273 return pos - buf;
11274}
11275
11276
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011277static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
11278 const char *ifname,
11279 char *cmd, size_t *resp_len)
11280{
11281 struct wpa_supplicant *wpa_s;
11282
11283 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11284 if (os_strcmp(ifname, wpa_s->ifname) == 0)
11285 break;
11286 }
11287
11288 if (wpa_s == NULL) {
11289 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
11290 if (resp)
11291 *resp_len = os_strlen(resp);
11292 else
11293 *resp_len = 1;
11294 return resp;
11295 }
11296
11297 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
11298}
11299
11300
11301static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
11302 char *buf, size_t *resp_len)
11303{
11304#ifdef CONFIG_P2P
11305 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011306 "LIST_NETWORKS",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011307 "P2P_FIND",
11308 "P2P_STOP_FIND",
11309 "P2P_LISTEN",
11310 "P2P_GROUP_ADD",
11311 "P2P_GET_PASSPHRASE",
11312 "P2P_SERVICE_UPDATE",
11313 "P2P_SERVICE_FLUSH",
11314 "P2P_FLUSH",
11315 "P2P_CANCEL",
11316 "P2P_PRESENCE_REQ",
11317 "P2P_EXT_LISTEN",
Paul Stewart092955c2017-02-06 09:13:09 -080011318#ifdef CONFIG_AP
11319 "STA-FIRST",
11320#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011321 NULL
11322 };
11323 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080011324#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011325 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080011326#endif /* ANDROID */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011327 "GET_CAPABILITY ",
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011328 "GET_NETWORK ",
11329 "REMOVE_NETWORK ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011330 "P2P_FIND ",
11331 "P2P_CONNECT ",
11332 "P2P_LISTEN ",
11333 "P2P_GROUP_REMOVE ",
11334 "P2P_GROUP_ADD ",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011335 "P2P_GROUP_MEMBER ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011336 "P2P_PROV_DISC ",
11337 "P2P_SERV_DISC_REQ ",
11338 "P2P_SERV_DISC_CANCEL_REQ ",
11339 "P2P_SERV_DISC_RESP ",
11340 "P2P_SERV_DISC_EXTERNAL ",
11341 "P2P_SERVICE_ADD ",
11342 "P2P_SERVICE_DEL ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011343 "P2P_SERVICE_REP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011344 "P2P_REJECT ",
11345 "P2P_INVITE ",
11346 "P2P_PEER ",
11347 "P2P_SET ",
11348 "P2P_UNAUTHORIZE ",
11349 "P2P_PRESENCE_REQ ",
11350 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070011351 "P2P_REMOVE_CLIENT ",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080011352 "WPS_NFC_TOKEN ",
11353 "WPS_NFC_TAG_READ ",
Dmitry Shmidt413dde72014-04-11 10:23:22 -070011354 "NFC_GET_HANDOVER_SEL ",
11355 "NFC_GET_HANDOVER_REQ ",
11356 "NFC_REPORT_HANDOVER ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011357 "P2P_ASP_PROVISION ",
11358 "P2P_ASP_PROVISION_RESP ",
Paul Stewart092955c2017-02-06 09:13:09 -080011359#ifdef CONFIG_AP
11360 "STA ",
11361 "STA-NEXT ",
11362#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011363 NULL
11364 };
11365 int found = 0;
11366 int i;
11367
11368 if (global->p2p_init_wpa_s == NULL)
11369 return NULL;
11370
11371 for (i = 0; !found && cmd[i]; i++) {
11372 if (os_strcmp(buf, cmd[i]) == 0)
11373 found = 1;
11374 }
11375
11376 for (i = 0; !found && prefix[i]; i++) {
11377 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
11378 found = 1;
11379 }
11380
11381 if (found)
11382 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11383 buf, resp_len);
11384#endif /* CONFIG_P2P */
11385 return NULL;
11386}
11387
11388
11389static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
11390 char *buf, size_t *resp_len)
11391{
11392#ifdef CONFIG_WIFI_DISPLAY
11393 if (global->p2p_init_wpa_s == NULL)
11394 return NULL;
11395 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
11396 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
11397 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11398 buf, resp_len);
11399#endif /* CONFIG_WIFI_DISPLAY */
11400 return NULL;
11401}
11402
11403
11404static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
11405 char *buf, size_t *resp_len)
11406{
11407 char *ret;
11408
11409 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
11410 if (ret)
11411 return ret;
11412
11413 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
11414 if (ret)
11415 return ret;
11416
11417 return NULL;
11418}
11419
11420
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011421static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
11422{
11423 char *value;
11424
11425 value = os_strchr(cmd, ' ');
11426 if (value == NULL)
11427 return -1;
11428 *value++ = '\0';
11429
11430 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
11431
11432#ifdef CONFIG_WIFI_DISPLAY
11433 if (os_strcasecmp(cmd, "wifi_display") == 0) {
11434 wifi_display_enable(global, !!atoi(value));
11435 return 0;
11436 }
11437#endif /* CONFIG_WIFI_DISPLAY */
11438
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011439 /* Restore cmd to its original value to allow redirection */
11440 value[-1] = ' ';
11441
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011442 return -1;
11443}
11444
11445
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011446static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
11447 char *cmd)
11448{
11449 struct wpa_supplicant *wpa_s[2]; /* src, dst */
11450 char *p;
11451 unsigned int i;
11452
11453 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11454 * <variable name> */
11455
11456 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
11457 p = os_strchr(cmd, ' ');
11458 if (p == NULL)
11459 return -1;
11460 *p = '\0';
11461
11462 wpa_s[i] = global->ifaces;
11463 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
11464 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
11465 break;
11466 }
11467
11468 if (!wpa_s[i]) {
11469 wpa_printf(MSG_DEBUG,
11470 "CTRL_IFACE: Could not find iface=%s", cmd);
11471 return -1;
11472 }
11473
11474 cmd = p + 1;
11475 }
11476
11477 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
11478}
11479
11480
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011481#ifndef CONFIG_NO_CONFIG_WRITE
11482static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
11483{
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011484 int ret = 0, saved = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011485 struct wpa_supplicant *wpa_s;
11486
11487 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11488 if (!wpa_s->conf->update_config) {
11489 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11490 continue;
11491 }
11492
11493 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
11494 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11495 ret = 1;
11496 } else {
11497 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011498 saved++;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011499 }
11500 }
11501
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011502 if (!saved && !ret) {
11503 wpa_dbg(wpa_s, MSG_DEBUG,
11504 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11505 ret = 1;
11506 }
11507
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011508 return ret;
11509}
11510#endif /* CONFIG_NO_CONFIG_WRITE */
11511
11512
11513static int wpas_global_ctrl_iface_status(struct wpa_global *global,
11514 char *buf, size_t buflen)
11515{
11516 char *pos, *end;
11517 int ret;
11518 struct wpa_supplicant *wpa_s;
11519
11520 pos = buf;
11521 end = buf + buflen;
11522
11523#ifdef CONFIG_P2P
11524 if (global->p2p && !global->p2p_disabled) {
11525 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
11526 "\n"
11527 "p2p_state=%s\n",
11528 MAC2STR(global->p2p_dev_addr),
11529 p2p_get_state_txt(global->p2p));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011530 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011531 return pos - buf;
11532 pos += ret;
11533 } else if (global->p2p) {
11534 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011535 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011536 return pos - buf;
11537 pos += ret;
11538 }
11539#endif /* CONFIG_P2P */
11540
11541#ifdef CONFIG_WIFI_DISPLAY
11542 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
11543 !!global->wifi_display);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011544 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011545 return pos - buf;
11546 pos += ret;
11547#endif /* CONFIG_WIFI_DISPLAY */
11548
11549 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11550 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
11551 "address=" MACSTR "\n",
11552 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011553 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011554 return pos - buf;
11555 pos += ret;
11556 }
11557
11558 return pos - buf;
11559}
11560
11561
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011562#ifdef CONFIG_FST
11563
11564static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
11565 char *cmd, char *buf,
11566 size_t reply_size)
11567{
11568 char ifname[IFNAMSIZ + 1];
11569 struct fst_iface_cfg cfg;
11570 struct wpa_supplicant *wpa_s;
11571 struct fst_wpa_obj iface_obj;
11572
11573 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
11574 wpa_s = wpa_supplicant_get_iface(global, ifname);
11575 if (wpa_s) {
11576 if (wpa_s->fst) {
11577 wpa_printf(MSG_INFO, "FST: Already attached");
11578 return -1;
11579 }
11580 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
11581 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
11582 &iface_obj, &cfg);
11583 if (wpa_s->fst)
11584 return os_snprintf(buf, reply_size, "OK\n");
11585 }
11586 }
11587
11588 return -1;
11589}
11590
11591
11592static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
11593 char *cmd, char *buf,
11594 size_t reply_size)
11595{
11596 char ifname[IFNAMSIZ + 1];
11597 struct wpa_supplicant *wpa_s;
11598
11599 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
11600 wpa_s = wpa_supplicant_get_iface(global, ifname);
11601 if (wpa_s) {
11602 if (!fst_iface_detach(ifname)) {
11603 wpa_s->fst = NULL;
11604 return os_snprintf(buf, reply_size, "OK\n");
11605 }
11606 }
11607 }
11608
11609 return -1;
11610}
11611
11612#endif /* CONFIG_FST */
11613
11614
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011615char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
11616 char *buf, size_t *resp_len)
11617{
11618 char *reply;
11619 const int reply_size = 2048;
11620 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011621 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011622
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011623 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
11624 char *pos = os_strchr(buf + 7, ' ');
11625 if (pos) {
11626 *pos++ = '\0';
11627 return wpas_global_ctrl_iface_ifname(global,
11628 buf + 7, pos,
11629 resp_len);
11630 }
11631 }
11632
11633 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
11634 if (reply)
11635 return reply;
11636
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011637 if (os_strcmp(buf, "PING") == 0)
11638 level = MSG_EXCESSIVE;
11639 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011640 (const u8 *) buf, os_strlen(buf));
11641
11642 reply = os_malloc(reply_size);
11643 if (reply == NULL) {
11644 *resp_len = 1;
11645 return NULL;
11646 }
11647
11648 os_memcpy(reply, "OK\n", 3);
11649 reply_len = 3;
11650
11651 if (os_strcmp(buf, "PING") == 0) {
11652 os_memcpy(reply, "PONG\n", 5);
11653 reply_len = 5;
11654 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
11655 if (wpa_supplicant_global_iface_add(global, buf + 14))
11656 reply_len = -1;
11657 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
11658 if (wpa_supplicant_global_iface_remove(global, buf + 17))
11659 reply_len = -1;
11660 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
11661 reply_len = wpa_supplicant_global_iface_list(
11662 global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011663 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011664 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011665 global, buf + 10, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011666#ifdef CONFIG_FST
11667 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
11668 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
11669 reply,
11670 reply_size);
11671 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
11672 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
11673 reply,
11674 reply_size);
11675 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
11676 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
11677#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011678 } else if (os_strcmp(buf, "TERMINATE") == 0) {
11679 wpa_supplicant_terminate_proc(global);
11680 } else if (os_strcmp(buf, "SUSPEND") == 0) {
11681 wpas_notify_suspend(global);
11682 } else if (os_strcmp(buf, "RESUME") == 0) {
11683 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011684 } else if (os_strncmp(buf, "SET ", 4) == 0) {
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011685 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
11686#ifdef CONFIG_P2P
11687 if (global->p2p_init_wpa_s) {
11688 os_free(reply);
11689 /* Check if P2P redirection would work for this
11690 * command. */
11691 return wpa_supplicant_ctrl_iface_process(
11692 global->p2p_init_wpa_s,
11693 buf, resp_len);
11694 }
11695#endif /* CONFIG_P2P */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011696 reply_len = -1;
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011697 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011698 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
11699 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
11700 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011701#ifndef CONFIG_NO_CONFIG_WRITE
11702 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
11703 if (wpas_global_ctrl_iface_save_config(global))
11704 reply_len = -1;
11705#endif /* CONFIG_NO_CONFIG_WRITE */
11706 } else if (os_strcmp(buf, "STATUS") == 0) {
11707 reply_len = wpas_global_ctrl_iface_status(global, reply,
11708 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080011709#ifdef CONFIG_MODULE_TESTS
11710 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080011711 if (wpas_module_tests() < 0)
11712 reply_len = -1;
11713#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011714 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
11715 if (wpa_debug_reopen_file() < 0)
11716 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011717 } else {
11718 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
11719 reply_len = 16;
11720 }
11721
11722 if (reply_len < 0) {
11723 os_memcpy(reply, "FAIL\n", 5);
11724 reply_len = 5;
11725 }
11726
11727 *resp_len = reply_len;
11728 return reply;
11729}