blob: be5ea17bd30a54fcf0ffa8f395a6ca9943b64932 [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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
423 char *cmd)
424{
425 char *value;
426 int ret = 0;
427
428 value = os_strchr(cmd, ' ');
429 if (value == NULL)
430 return -1;
431 *value++ = '\0';
432
433 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
434 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
435 eapol_sm_configure(wpa_s->eapol,
436 atoi(value), -1, -1, -1);
437 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
438 eapol_sm_configure(wpa_s->eapol,
439 -1, atoi(value), -1, -1);
440 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
441 eapol_sm_configure(wpa_s->eapol,
442 -1, -1, atoi(value), -1);
443 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
444 eapol_sm_configure(wpa_s->eapol,
445 -1, -1, -1, atoi(value));
446 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
447 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
Paul Stewart092955c2017-02-06 09:13:09 -0800448 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700449 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800450 } else {
451 value[-1] = '=';
452 wpa_config_process_global(wpa_s->conf, cmd, -1);
453 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700454 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
455 0) {
456 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
Paul Stewart092955c2017-02-06 09:13:09 -0800457 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700458 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800459 } else {
460 value[-1] = '=';
461 wpa_config_process_global(wpa_s->conf, cmd, -1);
462 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700463 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
Paul Stewart092955c2017-02-06 09:13:09 -0800464 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
465 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800467 } else {
468 value[-1] = '=';
469 wpa_config_process_global(wpa_s->conf, cmd, -1);
470 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700471 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
472 wpa_s->wps_fragment_size = atoi(value);
473#ifdef CONFIG_WPS_TESTING
474 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
475 long int val;
476 val = strtol(value, NULL, 0);
477 if (val < 0 || val > 0xff) {
478 ret = -1;
479 wpa_printf(MSG_DEBUG, "WPS: Invalid "
480 "wps_version_number %ld", val);
481 } else {
482 wps_version_number = val;
483 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
484 "version %u.%u",
485 (wps_version_number & 0xf0) >> 4,
486 wps_version_number & 0x0f);
487 }
488 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
489 wps_testing_dummy_cred = atoi(value);
490 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
491 wps_testing_dummy_cred);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800492 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
493 wps_corrupt_pkhash = atoi(value);
494 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
495 wps_corrupt_pkhash);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800496 } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
497 if (value[0] == '\0') {
498 wps_force_auth_types_in_use = 0;
499 } else {
500 wps_force_auth_types = strtol(value, NULL, 0);
501 wps_force_auth_types_in_use = 1;
502 }
503 } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
504 if (value[0] == '\0') {
505 wps_force_encr_types_in_use = 0;
506 } else {
507 wps_force_encr_types = strtol(value, NULL, 0);
508 wps_force_encr_types_in_use = 1;
509 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700510#endif /* CONFIG_WPS_TESTING */
511 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
512 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
513 ret = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800514#ifdef CONFIG_TDLS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700515#ifdef CONFIG_TDLS_TESTING
516 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700517 tdls_testing = strtol(value, NULL, 0);
518 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
519#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
521 int disabled = atoi(value);
522 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
523 if (disabled) {
524 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
525 ret = -1;
526 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
527 ret = -1;
528 wpa_tdls_enable(wpa_s->wpa, !disabled);
529#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800530 } else if (os_strcasecmp(cmd, "pno") == 0) {
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700531 ret = wpas_ctrl_pno(wpa_s, value);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700532 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
533 int disabled = atoi(value);
534 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
535 ret = -1;
536 else if (disabled)
537 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
538 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
539 if (os_strcmp(value, "disable") == 0)
540 wpa_s->set_sta_uapsd = 0;
541 else {
542 int be, bk, vi, vo;
543 char *pos;
544 /* format: BE,BK,VI,VO;max SP Length */
545 be = atoi(value);
546 pos = os_strchr(value, ',');
547 if (pos == NULL)
548 return -1;
549 pos++;
550 bk = atoi(pos);
551 pos = os_strchr(pos, ',');
552 if (pos == NULL)
553 return -1;
554 pos++;
555 vi = atoi(pos);
556 pos = os_strchr(pos, ',');
557 if (pos == NULL)
558 return -1;
559 pos++;
560 vo = atoi(pos);
561 /* ignore max SP Length for now */
562
563 wpa_s->set_sta_uapsd = 1;
564 wpa_s->sta_uapsd = 0;
565 if (be)
566 wpa_s->sta_uapsd |= BIT(0);
567 if (bk)
568 wpa_s->sta_uapsd |= BIT(1);
569 if (vi)
570 wpa_s->sta_uapsd |= BIT(2);
571 if (vo)
572 wpa_s->sta_uapsd |= BIT(3);
573 }
Jouni Malinen21d6bc82012-04-10 16:17:59 -0700574 } else if (os_strcasecmp(cmd, "ps") == 0) {
575 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700576#ifdef CONFIG_WIFI_DISPLAY
577 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800578 int enabled = !!atoi(value);
579 if (enabled && !wpa_s->global->p2p)
580 ret = -1;
581 else
582 wifi_display_enable(wpa_s->global, enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700583#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700584 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
585 ret = set_bssid_filter(wpa_s, value);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800586 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
587 ret = set_disallow_aps(wpa_s, value);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800588 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
589 wpa_s->no_keep_alive = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700590#ifdef CONFIG_DPP
591 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
592 os_free(wpa_s->dpp_configurator_params);
593 wpa_s->dpp_configurator_params = os_strdup(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700594 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
595 wpa_s->dpp_init_max_tries = atoi(value);
596 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
597 wpa_s->dpp_init_retry_time = atoi(value);
598 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
599 wpa_s->dpp_resp_wait_time = atoi(value);
600 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
601 wpa_s->dpp_resp_max_tries = atoi(value);
602 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
603 wpa_s->dpp_resp_retry_time = atoi(value);
604#ifdef CONFIG_TESTING_OPTIONS
605 } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
606 if (hwaddr_aton(value, dpp_pkex_own_mac_override))
607 ret = -1;
608 } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
609 if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
610 ret = -1;
611 } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
612 size_t hex_len = os_strlen(value);
613
614 if (hex_len >
615 2 * sizeof(dpp_pkex_ephemeral_key_override))
616 ret = -1;
617 else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
618 hex_len / 2))
619 ret = -1;
620 else
621 dpp_pkex_ephemeral_key_override_len = hex_len / 2;
622 } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) {
623 size_t hex_len = os_strlen(value);
624
625 if (hex_len > 2 * sizeof(dpp_protocol_key_override))
626 ret = -1;
627 else if (hexstr2bin(value, dpp_protocol_key_override,
628 hex_len / 2))
629 ret = -1;
630 else
631 dpp_protocol_key_override_len = hex_len / 2;
632 } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) {
633 size_t hex_len = os_strlen(value);
634
635 if (hex_len > 2 * sizeof(dpp_nonce_override))
636 ret = -1;
637 else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2))
638 ret = -1;
639 else
640 dpp_nonce_override_len = hex_len / 2;
641#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700642#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700643#ifdef CONFIG_TESTING_OPTIONS
644 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
645 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800646 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
647 wpa_s->ext_eapol_frame_io = !!atoi(value);
648#ifdef CONFIG_AP
649 if (wpa_s->ap_iface) {
650 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
651 wpa_s->ext_eapol_frame_io;
652 }
653#endif /* CONFIG_AP */
654 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
655 wpa_s->extra_roc_dur = atoi(value);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800656 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
657 wpa_s->test_failure = atoi(value);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800658 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
659 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700660 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
661 wpa_s->ignore_auth_resp = !!atoi(value);
662 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
663 wpa_s->ignore_assoc_disallow = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700664 wpa_drv_ignore_assoc_disallow(wpa_s,
665 wpa_s->ignore_assoc_disallow);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800666 } else if (os_strcasecmp(cmd, "ignore_sae_h2e_only") == 0) {
667 wpa_s->ignore_sae_h2e_only = !!atoi(value);
668 } else if (os_strcasecmp(cmd, "extra_sae_rejected_groups") == 0) {
669 char *pos;
670
671 os_free(wpa_s->extra_sae_rejected_groups);
672 wpa_s->extra_sae_rejected_groups = NULL;
673 pos = value;
674 while (pos && pos[0]) {
675 int group;
676
677 group = atoi(pos);
678 wpa_printf(MSG_DEBUG,
679 "TESTING: Extra rejection of SAE group %d",
680 group);
681 if (group)
682 int_array_add_unique(
683 &wpa_s->extra_sae_rejected_groups,
684 group);
685 pos = os_strchr(pos, ' ');
686 if (!pos)
687 break;
688 pos++;
689 }
690 } else if (os_strcasecmp(cmd, "rsnxe_override_assoc") == 0) {
691 wpabuf_free(wpa_s->rsnxe_override_assoc);
692 if (os_strcmp(value, "NULL") == 0)
693 wpa_s->rsnxe_override_assoc = NULL;
694 else
695 wpa_s->rsnxe_override_assoc = wpabuf_parse_bin(value);
696 } else if (os_strcasecmp(cmd, "rsnxe_override_eapol") == 0) {
697 wpabuf_free(wpa_s->rsnxe_override_eapol);
698 if (os_strcmp(value, "NULL") == 0)
699 wpa_s->rsnxe_override_eapol = NULL;
700 else
701 wpa_s->rsnxe_override_eapol = wpabuf_parse_bin(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700702 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
703 wpa_s->reject_btm_req_reason = atoi(value);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800704 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
705 os_free(wpa_s->get_pref_freq_list_override);
706 if (!value[0])
707 wpa_s->get_pref_freq_list_override = NULL;
708 else
709 wpa_s->get_pref_freq_list_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700710 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
711 wpabuf_free(wpa_s->sae_commit_override);
712 if (value[0] == '\0')
713 wpa_s->sae_commit_override = NULL;
714 else
715 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
716#ifdef CONFIG_DPP
717 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
718 os_free(wpa_s->dpp_config_obj_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700719 if (value[0] == '\0')
720 wpa_s->dpp_config_obj_override = NULL;
721 else
722 wpa_s->dpp_config_obj_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700723 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
724 os_free(wpa_s->dpp_discovery_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700725 if (value[0] == '\0')
726 wpa_s->dpp_discovery_override = NULL;
727 else
728 wpa_s->dpp_discovery_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700729 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
730 os_free(wpa_s->dpp_groups_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700731 if (value[0] == '\0')
732 wpa_s->dpp_groups_override = NULL;
733 else
734 wpa_s->dpp_groups_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700735 } else if (os_strcasecmp(cmd,
736 "dpp_ignore_netaccesskey_mismatch") == 0) {
737 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700738 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
739 dpp_test = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700740#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700741#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700742#ifdef CONFIG_FILS
743 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
744 wpa_s->disable_fils = !!atoi(value);
745 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
746 wpa_supplicant_set_default_scan_ies(wpa_s);
747#endif /* CONFIG_FILS */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700748#ifndef CONFIG_NO_CONFIG_BLOBS
749 } else if (os_strcmp(cmd, "blob") == 0) {
750 ret = wpas_ctrl_set_blob(wpa_s, value);
751#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800752 } else if (os_strcasecmp(cmd, "setband") == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700753 ret = wpas_ctrl_set_band(wpa_s, value);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800754#ifdef CONFIG_MBO
755 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
756 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
Paul Stewart092955c2017-02-06 09:13:09 -0800757 if (ret == 0) {
758 value[-1] = '=';
759 wpa_config_process_global(wpa_s->conf, cmd, -1);
760 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800761 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
762 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700763 } else if (os_strcasecmp(cmd, "oce") == 0) {
764 wpa_s->conf->oce = atoi(value);
765 if (wpa_s->conf->oce) {
766 if ((wpa_s->conf->oce & OCE_STA) &&
767 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
768 wpa_s->enable_oce = OCE_STA;
769
770 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
771 (wpa_s->drv_flags &
772 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
773 /* TODO: Need to add STA-CFON support */
774 wpa_printf(MSG_ERROR,
775 "OCE STA-CFON feature is not yet supported");
776 return -1;
777 }
778 } else {
779 wpa_s->enable_oce = 0;
780 }
781 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800782#endif /* CONFIG_MBO */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700783 } else if (os_strcasecmp(cmd, "lci") == 0) {
784 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800785 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
786 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800787 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
788 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
789 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
790 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
791 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
792 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700793 } else if (os_strcasecmp(cmd, "roaming") == 0) {
794 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800795#ifdef CONFIG_WNM
796 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
797 struct wpabuf *elems;
798
799 elems = wpabuf_parse_bin(value);
800 if (!elems)
801 return -1;
802 wnm_set_coloc_intf_elems(wpa_s, elems);
803#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804 } else {
805 value[-1] = '=';
806 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
807 if (ret == 0)
808 wpa_supplicant_update_config(wpa_s);
809 }
810
811 return ret;
812}
813
814
815static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
816 char *cmd, char *buf, size_t buflen)
817{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700818 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700819
820 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
821
822 if (os_strcmp(cmd, "version") == 0) {
823 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700824 } else if (os_strcasecmp(cmd, "country") == 0) {
825 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
826 res = os_snprintf(buf, buflen, "%c%c",
827 wpa_s->conf->country[0],
828 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700829#ifdef CONFIG_WIFI_DISPLAY
830 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800831 int enabled;
832 if (wpa_s->global->p2p == NULL ||
833 wpa_s->global->p2p_disabled)
834 enabled = 0;
835 else
836 enabled = wpa_s->global->wifi_display;
837 res = os_snprintf(buf, buflen, "%d", enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700838#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700839#ifdef CONFIG_TESTING_GET_GTK
840 } else if (os_strcmp(cmd, "gtk") == 0) {
841 if (wpa_s->last_gtk_len == 0)
842 return -1;
843 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
844 wpa_s->last_gtk_len);
845 return res;
846#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800847 } else if (os_strcmp(cmd, "tls_library") == 0) {
848 res = tls_get_library_version(buf, buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700849#ifdef CONFIG_TESTING_OPTIONS
850 } else if (os_strcmp(cmd, "anonce") == 0) {
851 return wpa_snprintf_hex(buf, buflen,
852 wpa_sm_get_anonce(wpa_s->wpa),
853 WPA_NONCE_LEN);
854#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800855 } else {
856 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700857 }
858
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800859 if (os_snprintf_error(buflen, res))
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700860 return -1;
861 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862}
863
864
865#ifdef IEEE8021X_EAPOL
866static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
867 char *addr)
868{
869 u8 bssid[ETH_ALEN];
870 struct wpa_ssid *ssid = wpa_s->current_ssid;
871
872 if (hwaddr_aton(addr, bssid)) {
873 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
874 "'%s'", addr);
875 return -1;
876 }
877
878 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
879 rsn_preauth_deinit(wpa_s->wpa);
880 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
881 return -1;
882
883 return 0;
884}
885#endif /* IEEE8021X_EAPOL */
886
887
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700888#ifdef CONFIG_TDLS
889
890static int wpa_supplicant_ctrl_iface_tdls_discover(
891 struct wpa_supplicant *wpa_s, char *addr)
892{
893 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800894 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700895
896 if (hwaddr_aton(addr, peer)) {
897 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
898 "address '%s'", addr);
899 return -1;
900 }
901
902 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
903 MAC2STR(peer));
904
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800905 if (wpa_tdls_is_external_setup(wpa_s->wpa))
906 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
907 else
908 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
909
910 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700911}
912
913
914static int wpa_supplicant_ctrl_iface_tdls_setup(
915 struct wpa_supplicant *wpa_s, char *addr)
916{
917 u8 peer[ETH_ALEN];
918 int ret;
919
920 if (hwaddr_aton(addr, peer)) {
921 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
922 "address '%s'", addr);
923 return -1;
924 }
925
926 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
927 MAC2STR(peer));
928
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800929 if ((wpa_s->conf->tdls_external_control) &&
930 wpa_tdls_is_external_setup(wpa_s->wpa))
931 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
932
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800933 wpa_tdls_remove(wpa_s->wpa, peer);
934
935 if (wpa_tdls_is_external_setup(wpa_s->wpa))
936 ret = wpa_tdls_start(wpa_s->wpa, peer);
937 else
938 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800939
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700940 return ret;
941}
942
943
944static int wpa_supplicant_ctrl_iface_tdls_teardown(
945 struct wpa_supplicant *wpa_s, char *addr)
946{
947 u8 peer[ETH_ALEN];
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700948 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700949
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700950 if (os_strcmp(addr, "*") == 0) {
951 /* remove everyone */
952 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
953 wpa_tdls_teardown_peers(wpa_s->wpa);
954 return 0;
955 }
956
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700957 if (hwaddr_aton(addr, peer)) {
958 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
959 "address '%s'", addr);
960 return -1;
961 }
962
963 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
964 MAC2STR(peer));
965
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800966 if ((wpa_s->conf->tdls_external_control) &&
967 wpa_tdls_is_external_setup(wpa_s->wpa))
968 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
969
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700970 if (wpa_tdls_is_external_setup(wpa_s->wpa))
971 ret = wpa_tdls_teardown_link(
972 wpa_s->wpa, peer,
973 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
974 else
975 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
976
977 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700978}
979
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700980
981static int ctrl_iface_get_capability_tdls(
982 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
983{
984 int ret;
985
986 ret = os_snprintf(buf, buflen, "%s\n",
987 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
988 (wpa_s->drv_flags &
989 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
990 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800991 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700992 return -1;
993 return ret;
994}
995
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800996
997static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
998 struct wpa_supplicant *wpa_s, char *cmd)
999{
1000 u8 peer[ETH_ALEN];
1001 struct hostapd_freq_params freq_params;
1002 u8 oper_class;
1003 char *pos, *end;
1004
1005 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1006 wpa_printf(MSG_INFO,
1007 "tdls_chanswitch: Only supported with external setup");
1008 return -1;
1009 }
1010
1011 os_memset(&freq_params, 0, sizeof(freq_params));
1012
1013 pos = os_strchr(cmd, ' ');
1014 if (pos == NULL)
1015 return -1;
1016 *pos++ = '\0';
1017
1018 oper_class = strtol(pos, &end, 10);
1019 if (pos == end) {
1020 wpa_printf(MSG_INFO,
1021 "tdls_chanswitch: Invalid op class provided");
1022 return -1;
1023 }
1024
1025 pos = end;
1026 freq_params.freq = atoi(pos);
1027 if (freq_params.freq == 0) {
1028 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
1029 return -1;
1030 }
1031
1032#define SET_FREQ_SETTING(str) \
1033 do { \
1034 const char *pos2 = os_strstr(pos, " " #str "="); \
1035 if (pos2) { \
1036 pos2 += sizeof(" " #str "=") - 1; \
1037 freq_params.str = atoi(pos2); \
1038 } \
1039 } while (0)
1040
1041 SET_FREQ_SETTING(center_freq1);
1042 SET_FREQ_SETTING(center_freq2);
1043 SET_FREQ_SETTING(bandwidth);
1044 SET_FREQ_SETTING(sec_channel_offset);
1045#undef SET_FREQ_SETTING
1046
1047 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1048 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1049
1050 if (hwaddr_aton(cmd, peer)) {
1051 wpa_printf(MSG_DEBUG,
1052 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1053 cmd);
1054 return -1;
1055 }
1056
1057 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1058 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1059 MAC2STR(peer), oper_class, freq_params.freq,
1060 freq_params.center_freq1, freq_params.center_freq2,
1061 freq_params.bandwidth, freq_params.sec_channel_offset,
1062 freq_params.ht_enabled ? " HT" : "",
1063 freq_params.vht_enabled ? " VHT" : "");
1064
1065 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1066 &freq_params);
1067}
1068
1069
1070static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1071 struct wpa_supplicant *wpa_s, char *cmd)
1072{
1073 u8 peer[ETH_ALEN];
1074
1075 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1076 wpa_printf(MSG_INFO,
1077 "tdls_chanswitch: Only supported with external setup");
1078 return -1;
1079 }
1080
1081 if (hwaddr_aton(cmd, peer)) {
1082 wpa_printf(MSG_DEBUG,
1083 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1084 cmd);
1085 return -1;
1086 }
1087
1088 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1089 MAC2STR(peer));
1090
1091 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1092}
1093
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07001094
1095static int wpa_supplicant_ctrl_iface_tdls_link_status(
1096 struct wpa_supplicant *wpa_s, const char *addr,
1097 char *buf, size_t buflen)
1098{
1099 u8 peer[ETH_ALEN];
1100 const char *tdls_status;
1101 int ret;
1102
1103 if (hwaddr_aton(addr, peer)) {
1104 wpa_printf(MSG_DEBUG,
1105 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1106 addr);
1107 return -1;
1108 }
1109 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1110 MAC2STR(peer));
1111
1112 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1113 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1114 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1115 if (os_snprintf_error(buflen, ret))
1116 return -1;
1117
1118 return ret;
1119}
1120
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121#endif /* CONFIG_TDLS */
1122
1123
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001124static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1125{
1126 char *token, *context = NULL;
1127 struct wmm_ac_ts_setup_params params = {
1128 .tsid = 0xff,
1129 .direction = 0xff,
1130 };
1131
1132 while ((token = str_token(cmd, " ", &context))) {
1133 if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
1134 sscanf(token, "up=%i", &params.user_priority) == 1 ||
1135 sscanf(token, "nominal_msdu_size=%i",
1136 &params.nominal_msdu_size) == 1 ||
1137 sscanf(token, "mean_data_rate=%i",
1138 &params.mean_data_rate) == 1 ||
1139 sscanf(token, "min_phy_rate=%i",
1140 &params.minimum_phy_rate) == 1 ||
1141 sscanf(token, "sba=%i",
1142 &params.surplus_bandwidth_allowance) == 1)
1143 continue;
1144
1145 if (os_strcasecmp(token, "downlink") == 0) {
1146 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1147 } else if (os_strcasecmp(token, "uplink") == 0) {
1148 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1149 } else if (os_strcasecmp(token, "bidi") == 0) {
1150 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1151 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1152 params.fixed_nominal_msdu = 1;
1153 } else {
1154 wpa_printf(MSG_DEBUG,
1155 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1156 token);
1157 return -1;
1158 }
1159
1160 }
1161
1162 return wpas_wmm_ac_addts(wpa_s, &params);
1163}
1164
1165
1166static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1167{
1168 u8 tsid = atoi(cmd);
1169
1170 return wpas_wmm_ac_delts(wpa_s, tsid);
1171}
1172
1173
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001174#ifdef CONFIG_IEEE80211R
1175static int wpa_supplicant_ctrl_iface_ft_ds(
1176 struct wpa_supplicant *wpa_s, char *addr)
1177{
1178 u8 target_ap[ETH_ALEN];
1179 struct wpa_bss *bss;
1180 const u8 *mdie;
1181
1182 if (hwaddr_aton(addr, target_ap)) {
1183 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1184 "address '%s'", addr);
1185 return -1;
1186 }
1187
1188 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1189
1190 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1191 if (bss)
1192 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1193 else
1194 mdie = NULL;
1195
1196 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
1197}
1198#endif /* CONFIG_IEEE80211R */
1199
1200
1201#ifdef CONFIG_WPS
1202static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1203 char *cmd)
1204{
1205 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001206#ifdef CONFIG_P2P
1207 u8 p2p_dev_addr[ETH_ALEN];
1208#endif /* CONFIG_P2P */
1209#ifdef CONFIG_AP
1210 u8 *_p2p_dev_addr = NULL;
1211#endif /* CONFIG_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001212 char *pos;
1213 int multi_ap = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001214
Hai Shalom021b0b52019-04-10 11:17:58 -07001215 if (!cmd || os_strcmp(cmd, "any") == 0 ||
1216 os_strncmp(cmd, "any ", 4) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001217 _bssid = NULL;
1218#ifdef CONFIG_P2P
1219 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1220 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1221 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1222 "P2P Device Address '%s'",
1223 cmd + 13);
1224 return -1;
1225 }
1226 _p2p_dev_addr = p2p_dev_addr;
1227#endif /* CONFIG_P2P */
Hai Shalom021b0b52019-04-10 11:17:58 -07001228 } else if (os_strncmp(cmd, "multi_ap=", 9) == 0) {
1229 _bssid = NULL;
1230 multi_ap = atoi(cmd + 9);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001231 } else if (hwaddr_aton(cmd, bssid)) {
1232 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1233 cmd);
1234 return -1;
1235 }
1236
Hai Shalom021b0b52019-04-10 11:17:58 -07001237 if (cmd) {
1238 pos = os_strstr(cmd, " multi_ap=");
1239 if (pos) {
1240 pos += 10;
1241 multi_ap = atoi(pos);
1242 }
1243 }
1244
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001245#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246 if (wpa_s->ap_iface)
1247 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1248#endif /* CONFIG_AP */
1249
Hai Shalom021b0b52019-04-10 11:17:58 -07001250 return wpas_wps_start_pbc(wpa_s, _bssid, 0, multi_ap);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001251}
1252
1253
1254static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1255 char *cmd, char *buf,
1256 size_t buflen)
1257{
1258 u8 bssid[ETH_ALEN], *_bssid = bssid;
1259 char *pin;
1260 int ret;
1261
1262 pin = os_strchr(cmd, ' ');
1263 if (pin)
1264 *pin++ = '\0';
1265
1266 if (os_strcmp(cmd, "any") == 0)
1267 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001268 else if (os_strcmp(cmd, "get") == 0) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001269 if (wps_generate_pin((unsigned int *) &ret) < 0)
1270 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001271 goto done;
1272 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001273 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1274 cmd);
1275 return -1;
1276 }
1277
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001278#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001279 if (wpa_s->ap_iface) {
1280 int timeout = 0;
1281 char *pos;
1282
1283 if (pin) {
1284 pos = os_strchr(pin, ' ');
1285 if (pos) {
1286 *pos++ = '\0';
1287 timeout = atoi(pos);
1288 }
1289 }
1290
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001291 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001292 buf, buflen, timeout);
1293 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001294#endif /* CONFIG_AP */
1295
1296 if (pin) {
1297 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1298 DEV_PW_DEFAULT);
1299 if (ret < 0)
1300 return -1;
1301 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001302 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001303 return -1;
1304 return ret;
1305 }
1306
1307 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1308 if (ret < 0)
1309 return -1;
1310
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001311done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001312 /* Return the generated PIN */
1313 ret = os_snprintf(buf, buflen, "%08d", ret);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001314 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315 return -1;
1316 return ret;
1317}
1318
1319
1320static int wpa_supplicant_ctrl_iface_wps_check_pin(
1321 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1322{
1323 char pin[9];
1324 size_t len;
1325 char *pos;
1326 int ret;
1327
1328 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1329 (u8 *) cmd, os_strlen(cmd));
1330 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1331 if (*pos < '0' || *pos > '9')
1332 continue;
1333 pin[len++] = *pos;
1334 if (len == 9) {
1335 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1336 return -1;
1337 }
1338 }
1339 if (len != 4 && len != 8) {
1340 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1341 return -1;
1342 }
1343 pin[len] = '\0';
1344
1345 if (len == 8) {
1346 unsigned int pin_val;
1347 pin_val = atoi(pin);
1348 if (!wps_pin_valid(pin_val)) {
1349 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1350 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001351 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001352 return -1;
1353 return ret;
1354 }
1355 }
1356
1357 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001358 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001359 return -1;
1360
1361 return ret;
1362}
1363
1364
Dmitry Shmidt04949592012-07-19 12:16:46 -07001365#ifdef CONFIG_WPS_NFC
1366
1367static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1368 char *cmd)
1369{
1370 u8 bssid[ETH_ALEN], *_bssid = bssid;
1371
1372 if (cmd == NULL || cmd[0] == '\0')
1373 _bssid = NULL;
1374 else if (hwaddr_aton(cmd, bssid))
1375 return -1;
1376
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001377 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1378 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001379}
1380
1381
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001382static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1383 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1384{
1385 int ndef;
1386 struct wpabuf *buf;
1387 int res;
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001388 char *pos;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001389
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001390 pos = os_strchr(cmd, ' ');
1391 if (pos)
1392 *pos++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001393 if (os_strcmp(cmd, "WPS") == 0)
1394 ndef = 0;
1395 else if (os_strcmp(cmd, "NDEF") == 0)
1396 ndef = 1;
1397 else
1398 return -1;
1399
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001400 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001401 if (buf == NULL)
1402 return -1;
1403
1404 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1405 wpabuf_len(buf));
1406 reply[res++] = '\n';
1407 reply[res] = '\0';
1408
1409 wpabuf_free(buf);
1410
1411 return res;
1412}
1413
1414
Dmitry Shmidt04949592012-07-19 12:16:46 -07001415static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1416 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1417{
1418 int ndef;
1419 struct wpabuf *buf;
1420 int res;
1421
1422 if (os_strcmp(cmd, "WPS") == 0)
1423 ndef = 0;
1424 else if (os_strcmp(cmd, "NDEF") == 0)
1425 ndef = 1;
1426 else
1427 return -1;
1428
1429 buf = wpas_wps_nfc_token(wpa_s, ndef);
1430 if (buf == NULL)
1431 return -1;
1432
1433 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1434 wpabuf_len(buf));
1435 reply[res++] = '\n';
1436 reply[res] = '\0';
1437
1438 wpabuf_free(buf);
1439
1440 return res;
1441}
1442
1443
1444static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1445 struct wpa_supplicant *wpa_s, char *pos)
1446{
1447 size_t len;
1448 struct wpabuf *buf;
1449 int ret;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001450 char *freq;
1451 int forced_freq = 0;
1452
1453 freq = strstr(pos, " freq=");
1454 if (freq) {
1455 *freq = '\0';
1456 freq += 6;
1457 forced_freq = atoi(freq);
1458 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001459
1460 len = os_strlen(pos);
1461 if (len & 0x01)
1462 return -1;
1463 len /= 2;
1464
1465 buf = wpabuf_alloc(len);
1466 if (buf == NULL)
1467 return -1;
1468 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1469 wpabuf_free(buf);
1470 return -1;
1471 }
1472
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001473 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001474 wpabuf_free(buf);
1475
1476 return ret;
1477}
1478
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001479
1480static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001481 char *reply, size_t max_len,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001482 int ndef)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001483{
1484 struct wpabuf *buf;
1485 int res;
1486
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001487 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001488 if (buf == NULL)
1489 return -1;
1490
1491 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1492 wpabuf_len(buf));
1493 reply[res++] = '\n';
1494 reply[res] = '\0';
1495
1496 wpabuf_free(buf);
1497
1498 return res;
1499}
1500
1501
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001502#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001503static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1504 char *reply, size_t max_len,
1505 int ndef)
1506{
1507 struct wpabuf *buf;
1508 int res;
1509
1510 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1511 if (buf == NULL) {
1512 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1513 return -1;
1514 }
1515
1516 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1517 wpabuf_len(buf));
1518 reply[res++] = '\n';
1519 reply[res] = '\0';
1520
1521 wpabuf_free(buf);
1522
1523 return res;
1524}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001525#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001526
1527
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001528static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1529 char *cmd, char *reply,
1530 size_t max_len)
1531{
1532 char *pos;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001533 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001534
1535 pos = os_strchr(cmd, ' ');
1536 if (pos == NULL)
1537 return -1;
1538 *pos++ = '\0';
1539
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001540 if (os_strcmp(cmd, "WPS") == 0)
1541 ndef = 0;
1542 else if (os_strcmp(cmd, "NDEF") == 0)
1543 ndef = 1;
1544 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001545 return -1;
1546
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001547 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001548 if (!ndef)
1549 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001550 return wpas_ctrl_nfc_get_handover_req_wps(
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001551 wpa_s, reply, max_len, ndef);
1552 }
1553
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001554#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001555 if (os_strcmp(pos, "P2P-CR") == 0) {
1556 return wpas_ctrl_nfc_get_handover_req_p2p(
1557 wpa_s, reply, max_len, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001558 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001559#endif /* CONFIG_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001560
1561 return -1;
1562}
1563
1564
1565static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001566 char *reply, size_t max_len,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001567 int ndef, int cr, char *uuid)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001568{
1569 struct wpabuf *buf;
1570 int res;
1571
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001572 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001573 if (buf == NULL)
1574 return -1;
1575
1576 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1577 wpabuf_len(buf));
1578 reply[res++] = '\n';
1579 reply[res] = '\0';
1580
1581 wpabuf_free(buf);
1582
1583 return res;
1584}
1585
1586
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001587#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001588static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1589 char *reply, size_t max_len,
1590 int ndef, int tag)
1591{
1592 struct wpabuf *buf;
1593 int res;
1594
1595 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1596 if (buf == NULL)
1597 return -1;
1598
1599 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1600 wpabuf_len(buf));
1601 reply[res++] = '\n';
1602 reply[res] = '\0';
1603
1604 wpabuf_free(buf);
1605
1606 return res;
1607}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001608#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001609
1610
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001611static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1612 char *cmd, char *reply,
1613 size_t max_len)
1614{
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001615 char *pos, *pos2;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001616 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001617
1618 pos = os_strchr(cmd, ' ');
1619 if (pos == NULL)
1620 return -1;
1621 *pos++ = '\0';
1622
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001623 if (os_strcmp(cmd, "WPS") == 0)
1624 ndef = 0;
1625 else if (os_strcmp(cmd, "NDEF") == 0)
1626 ndef = 1;
1627 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001628 return -1;
1629
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001630 pos2 = os_strchr(pos, ' ');
1631 if (pos2)
1632 *pos2++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001633 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001634 if (!ndef)
1635 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001636 return wpas_ctrl_nfc_get_handover_sel_wps(
1637 wpa_s, reply, max_len, ndef,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001638 os_strcmp(pos, "WPS-CR") == 0, pos2);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001639 }
1640
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001641#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001642 if (os_strcmp(pos, "P2P-CR") == 0) {
1643 return wpas_ctrl_nfc_get_handover_sel_p2p(
1644 wpa_s, reply, max_len, ndef, 0);
1645 }
1646
1647 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1648 return wpas_ctrl_nfc_get_handover_sel_p2p(
1649 wpa_s, reply, max_len, ndef, 1);
1650 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001651#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001652
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001653 return -1;
1654}
1655
1656
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001657static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1658 char *cmd)
1659{
1660 size_t len;
1661 struct wpabuf *req, *sel;
1662 int ret;
1663 char *pos, *role, *type, *pos2;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001664#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001665 char *freq;
1666 int forced_freq = 0;
1667
1668 freq = strstr(cmd, " freq=");
1669 if (freq) {
1670 *freq = '\0';
1671 freq += 6;
1672 forced_freq = atoi(freq);
1673 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001674#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001675
1676 role = cmd;
1677 pos = os_strchr(role, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001678 if (pos == NULL) {
1679 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001680 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001681 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001682 *pos++ = '\0';
1683
1684 type = pos;
1685 pos = os_strchr(type, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001686 if (pos == NULL) {
1687 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001688 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001689 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001690 *pos++ = '\0';
1691
1692 pos2 = os_strchr(pos, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001693 if (pos2 == NULL) {
1694 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001695 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001696 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001697 *pos2++ = '\0';
1698
1699 len = os_strlen(pos);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001700 if (len & 0x01) {
1701 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001702 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001703 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001704 len /= 2;
1705
1706 req = wpabuf_alloc(len);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001707 if (req == NULL) {
1708 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001709 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001710 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001711 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001712 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001713 wpabuf_free(req);
1714 return -1;
1715 }
1716
1717 len = os_strlen(pos2);
1718 if (len & 0x01) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001719 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001720 wpabuf_free(req);
1721 return -1;
1722 }
1723 len /= 2;
1724
1725 sel = wpabuf_alloc(len);
1726 if (sel == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001727 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001728 wpabuf_free(req);
1729 return -1;
1730 }
1731 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001732 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001733 wpabuf_free(req);
1734 wpabuf_free(sel);
1735 return -1;
1736 }
1737
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001738 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1739 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1740
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001741 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1742 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001743#ifdef CONFIG_AP
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001744 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1745 {
1746 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1747 if (ret < 0)
1748 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001749#endif /* CONFIG_AP */
1750#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001751 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1752 {
1753 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1754 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1755 {
1756 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1757 forced_freq);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001758#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001759 } else {
1760 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1761 "reported: role=%s type=%s", role, type);
1762 ret = -1;
1763 }
1764 wpabuf_free(req);
1765 wpabuf_free(sel);
1766
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001767 if (ret)
1768 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1769
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001770 return ret;
1771}
1772
Dmitry Shmidt04949592012-07-19 12:16:46 -07001773#endif /* CONFIG_WPS_NFC */
1774
1775
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001776static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1777 char *cmd)
1778{
1779 u8 bssid[ETH_ALEN];
1780 char *pin;
1781 char *new_ssid;
1782 char *new_auth;
1783 char *new_encr;
1784 char *new_key;
1785 struct wps_new_ap_settings ap;
1786
1787 pin = os_strchr(cmd, ' ');
1788 if (pin == NULL)
1789 return -1;
1790 *pin++ = '\0';
1791
1792 if (hwaddr_aton(cmd, bssid)) {
1793 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1794 cmd);
1795 return -1;
1796 }
1797
1798 new_ssid = os_strchr(pin, ' ');
1799 if (new_ssid == NULL)
1800 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1801 *new_ssid++ = '\0';
1802
1803 new_auth = os_strchr(new_ssid, ' ');
1804 if (new_auth == NULL)
1805 return -1;
1806 *new_auth++ = '\0';
1807
1808 new_encr = os_strchr(new_auth, ' ');
1809 if (new_encr == NULL)
1810 return -1;
1811 *new_encr++ = '\0';
1812
1813 new_key = os_strchr(new_encr, ' ');
1814 if (new_key == NULL)
1815 return -1;
1816 *new_key++ = '\0';
1817
1818 os_memset(&ap, 0, sizeof(ap));
1819 ap.ssid_hex = new_ssid;
1820 ap.auth = new_auth;
1821 ap.encr = new_encr;
1822 ap.key_hex = new_key;
1823 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1824}
1825
1826
1827#ifdef CONFIG_AP
1828static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1829 char *cmd, char *buf,
1830 size_t buflen)
1831{
1832 int timeout = 300;
1833 char *pos;
1834 const char *pin_txt;
1835
1836 if (!wpa_s->ap_iface)
1837 return -1;
1838
1839 pos = os_strchr(cmd, ' ');
1840 if (pos)
1841 *pos++ = '\0';
1842
1843 if (os_strcmp(cmd, "disable") == 0) {
1844 wpas_wps_ap_pin_disable(wpa_s);
1845 return os_snprintf(buf, buflen, "OK\n");
1846 }
1847
1848 if (os_strcmp(cmd, "random") == 0) {
1849 if (pos)
1850 timeout = atoi(pos);
1851 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1852 if (pin_txt == NULL)
1853 return -1;
1854 return os_snprintf(buf, buflen, "%s", pin_txt);
1855 }
1856
1857 if (os_strcmp(cmd, "get") == 0) {
1858 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1859 if (pin_txt == NULL)
1860 return -1;
1861 return os_snprintf(buf, buflen, "%s", pin_txt);
1862 }
1863
1864 if (os_strcmp(cmd, "set") == 0) {
1865 char *pin;
1866 if (pos == NULL)
1867 return -1;
1868 pin = pos;
1869 pos = os_strchr(pos, ' ');
1870 if (pos) {
1871 *pos++ = '\0';
1872 timeout = atoi(pos);
1873 }
1874 if (os_strlen(pin) > buflen)
1875 return -1;
1876 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1877 return -1;
1878 return os_snprintf(buf, buflen, "%s", pin);
1879 }
1880
1881 return -1;
1882}
1883#endif /* CONFIG_AP */
1884
1885
1886#ifdef CONFIG_WPS_ER
1887static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1888 char *cmd)
1889{
1890 char *uuid = cmd, *pin, *pos;
1891 u8 addr_buf[ETH_ALEN], *addr = NULL;
1892 pin = os_strchr(uuid, ' ');
1893 if (pin == NULL)
1894 return -1;
1895 *pin++ = '\0';
1896 pos = os_strchr(pin, ' ');
1897 if (pos) {
1898 *pos++ = '\0';
1899 if (hwaddr_aton(pos, addr_buf) == 0)
1900 addr = addr_buf;
1901 }
1902 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1903}
1904
1905
1906static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1907 char *cmd)
1908{
1909 char *uuid = cmd, *pin;
1910 pin = os_strchr(uuid, ' ');
1911 if (pin == NULL)
1912 return -1;
1913 *pin++ = '\0';
1914 return wpas_wps_er_learn(wpa_s, uuid, pin);
1915}
1916
1917
1918static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1919 struct wpa_supplicant *wpa_s, char *cmd)
1920{
1921 char *uuid = cmd, *id;
1922 id = os_strchr(uuid, ' ');
1923 if (id == NULL)
1924 return -1;
1925 *id++ = '\0';
1926 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1927}
1928
1929
1930static int wpa_supplicant_ctrl_iface_wps_er_config(
1931 struct wpa_supplicant *wpa_s, char *cmd)
1932{
1933 char *pin;
1934 char *new_ssid;
1935 char *new_auth;
1936 char *new_encr;
1937 char *new_key;
1938 struct wps_new_ap_settings ap;
1939
1940 pin = os_strchr(cmd, ' ');
1941 if (pin == NULL)
1942 return -1;
1943 *pin++ = '\0';
1944
1945 new_ssid = os_strchr(pin, ' ');
1946 if (new_ssid == NULL)
1947 return -1;
1948 *new_ssid++ = '\0';
1949
1950 new_auth = os_strchr(new_ssid, ' ');
1951 if (new_auth == NULL)
1952 return -1;
1953 *new_auth++ = '\0';
1954
1955 new_encr = os_strchr(new_auth, ' ');
1956 if (new_encr == NULL)
1957 return -1;
1958 *new_encr++ = '\0';
1959
1960 new_key = os_strchr(new_encr, ' ');
1961 if (new_key == NULL)
1962 return -1;
1963 *new_key++ = '\0';
1964
1965 os_memset(&ap, 0, sizeof(ap));
1966 ap.ssid_hex = new_ssid;
1967 ap.auth = new_auth;
1968 ap.encr = new_encr;
1969 ap.key_hex = new_key;
1970 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1971}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001972
1973
1974#ifdef CONFIG_WPS_NFC
1975static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1976 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1977{
1978 int ndef;
1979 struct wpabuf *buf;
1980 int res;
1981 char *uuid;
1982
1983 uuid = os_strchr(cmd, ' ');
1984 if (uuid == NULL)
1985 return -1;
1986 *uuid++ = '\0';
1987
1988 if (os_strcmp(cmd, "WPS") == 0)
1989 ndef = 0;
1990 else if (os_strcmp(cmd, "NDEF") == 0)
1991 ndef = 1;
1992 else
1993 return -1;
1994
1995 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1996 if (buf == NULL)
1997 return -1;
1998
1999 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
2000 wpabuf_len(buf));
2001 reply[res++] = '\n';
2002 reply[res] = '\0';
2003
2004 wpabuf_free(buf);
2005
2006 return res;
2007}
2008#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002009#endif /* CONFIG_WPS_ER */
2010
2011#endif /* CONFIG_WPS */
2012
2013
2014#ifdef CONFIG_IBSS_RSN
2015static int wpa_supplicant_ctrl_iface_ibss_rsn(
2016 struct wpa_supplicant *wpa_s, char *addr)
2017{
2018 u8 peer[ETH_ALEN];
2019
2020 if (hwaddr_aton(addr, peer)) {
2021 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
2022 "address '%s'", addr);
2023 return -1;
2024 }
2025
2026 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
2027 MAC2STR(peer));
2028
2029 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
2030}
2031#endif /* CONFIG_IBSS_RSN */
2032
2033
2034static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
2035 char *rsp)
2036{
2037#ifdef IEEE8021X_EAPOL
2038 char *pos, *id_pos;
2039 int id;
2040 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002041
2042 pos = os_strchr(rsp, '-');
2043 if (pos == NULL)
2044 return -1;
2045 *pos++ = '\0';
2046 id_pos = pos;
2047 pos = os_strchr(pos, ':');
2048 if (pos == NULL)
2049 return -1;
2050 *pos++ = '\0';
2051 id = atoi(id_pos);
2052 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
2053 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2054 (u8 *) pos, os_strlen(pos));
2055
2056 ssid = wpa_config_get_network(wpa_s->conf, id);
2057 if (ssid == NULL) {
2058 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2059 "to update", id);
2060 return -1;
2061 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002062
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002063 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2064 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002065#else /* IEEE8021X_EAPOL */
2066 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2067 return -1;
2068#endif /* IEEE8021X_EAPOL */
2069}
2070
2071
2072static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2073 const char *params,
2074 char *buf, size_t buflen)
2075{
2076 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002077 int res, verbose, wps, ret;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002078#ifdef CONFIG_HS20
2079 const u8 *hs20;
2080#endif /* CONFIG_HS20 */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002081 const u8 *sess_id;
2082 size_t sess_id_len;
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002083
Dmitry Shmidt56052862013-10-04 10:23:25 -07002084 if (os_strcmp(params, "-DRIVER") == 0)
2085 return wpa_drv_status(wpa_s, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002086 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002087 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002088 pos = buf;
2089 end = buf + buflen;
2090 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2091 struct wpa_ssid *ssid = wpa_s->current_ssid;
2092 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2093 MAC2STR(wpa_s->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002094 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002095 return pos - buf;
2096 pos += ret;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002097 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2098 wpa_s->assoc_freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002099 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002100 return pos - buf;
2101 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002102 if (ssid) {
2103 u8 *_ssid = ssid->ssid;
2104 size_t ssid_len = ssid->ssid_len;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002105 u8 ssid_buf[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002106 if (ssid_len == 0) {
2107 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2108 if (_res < 0)
2109 ssid_len = 0;
2110 else
2111 ssid_len = _res;
2112 _ssid = ssid_buf;
2113 }
2114 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2115 wpa_ssid_txt(_ssid, ssid_len),
2116 ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002117 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002118 return pos - buf;
2119 pos += ret;
2120
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002121 if (wps && ssid->passphrase &&
2122 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2123 (ssid->mode == WPAS_MODE_AP ||
2124 ssid->mode == WPAS_MODE_P2P_GO)) {
2125 ret = os_snprintf(pos, end - pos,
2126 "passphrase=%s\n",
2127 ssid->passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002128 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002129 return pos - buf;
2130 pos += ret;
2131 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002132 if (ssid->id_str) {
2133 ret = os_snprintf(pos, end - pos,
2134 "id_str=%s\n",
2135 ssid->id_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002136 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002137 return pos - buf;
2138 pos += ret;
2139 }
2140
2141 switch (ssid->mode) {
2142 case WPAS_MODE_INFRA:
2143 ret = os_snprintf(pos, end - pos,
2144 "mode=station\n");
2145 break;
2146 case WPAS_MODE_IBSS:
2147 ret = os_snprintf(pos, end - pos,
2148 "mode=IBSS\n");
2149 break;
2150 case WPAS_MODE_AP:
2151 ret = os_snprintf(pos, end - pos,
2152 "mode=AP\n");
2153 break;
2154 case WPAS_MODE_P2P_GO:
2155 ret = os_snprintf(pos, end - pos,
2156 "mode=P2P GO\n");
2157 break;
2158 case WPAS_MODE_P2P_GROUP_FORMATION:
2159 ret = os_snprintf(pos, end - pos,
2160 "mode=P2P GO - group "
2161 "formation\n");
2162 break;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002163 case WPAS_MODE_MESH:
2164 ret = os_snprintf(pos, end - pos,
2165 "mode=mesh\n");
2166 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002167 default:
2168 ret = 0;
2169 break;
2170 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002171 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002172 return pos - buf;
2173 pos += ret;
2174 }
2175
Hai Shalom021b0b52019-04-10 11:17:58 -07002176 if (wpa_s->connection_set &&
2177 (wpa_s->connection_ht || wpa_s->connection_vht ||
2178 wpa_s->connection_he)) {
2179 ret = os_snprintf(pos, end - pos,
2180 "wifi_generation=%u\n",
2181 wpa_s->connection_he ? 6 :
2182 (wpa_s->connection_vht ? 5 : 4));
2183 if (os_snprintf_error(end - pos, ret))
2184 return pos - buf;
2185 pos += ret;
2186 }
2187
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002188#ifdef CONFIG_AP
2189 if (wpa_s->ap_iface) {
2190 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2191 end - pos,
2192 verbose);
2193 } else
2194#endif /* CONFIG_AP */
2195 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2196 }
Paul Stewart092955c2017-02-06 09:13:09 -08002197#ifdef CONFIG_SME
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002198#ifdef CONFIG_SAE
2199 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002200#ifdef CONFIG_AP
2201 !wpa_s->ap_iface &&
2202#endif /* CONFIG_AP */
2203 wpa_s->sme.sae.state == SAE_ACCEPTED) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002204 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
2205 wpa_s->sme.sae.group);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002206 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002207 return pos - buf;
2208 pos += ret;
2209 }
2210#endif /* CONFIG_SAE */
Paul Stewart092955c2017-02-06 09:13:09 -08002211#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002212 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2213 wpa_supplicant_state_txt(wpa_s->wpa_state));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002214 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002215 return pos - buf;
2216 pos += ret;
2217
2218 if (wpa_s->l2 &&
2219 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2220 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002221 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002222 return pos - buf;
2223 pos += ret;
2224 }
2225
2226#ifdef CONFIG_P2P
2227 if (wpa_s->global->p2p) {
2228 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2229 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002230 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002231 return pos - buf;
2232 pos += ret;
2233 }
2234#endif /* CONFIG_P2P */
2235
2236 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2237 MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002238 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002239 return pos - buf;
2240 pos += ret;
2241
Dmitry Shmidt04949592012-07-19 12:16:46 -07002242#ifdef CONFIG_HS20
2243 if (wpa_s->current_bss &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002244 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2245 HS20_IE_VENDOR_TYPE)) &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002246 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2247 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002248 int release = 1;
2249 if (hs20[1] >= 5) {
2250 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2251 release = rel_num + 1;
2252 }
2253 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002254 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002255 return pos - buf;
2256 pos += ret;
2257 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002258
2259 if (wpa_s->current_ssid) {
2260 struct wpa_cred *cred;
2261 char *type;
2262
2263 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002264 size_t i;
2265
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002266 if (wpa_s->current_ssid->parent_cred != cred)
2267 continue;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002268
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002269 if (cred->provisioning_sp) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002270 ret = os_snprintf(pos, end - pos,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002271 "provisioning_sp=%s\n",
2272 cred->provisioning_sp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002273 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt051af732013-10-22 13:52:46 -07002274 return pos - buf;
2275 pos += ret;
2276 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002277
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002278 if (!cred->domain)
2279 goto no_domain;
2280
2281 i = 0;
2282 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2283 struct wpabuf *names =
2284 wpa_s->current_bss->anqp->domain_name;
2285 for (i = 0; names && i < cred->num_domain; i++)
2286 {
2287 if (domain_name_list_contains(
2288 names, cred->domain[i], 1))
2289 break;
2290 }
2291 if (i == cred->num_domain)
2292 i = 0; /* show first entry by default */
2293 }
2294 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2295 cred->domain[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002296 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002297 return pos - buf;
2298 pos += ret;
2299
2300 no_domain:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002301 if (wpa_s->current_bss == NULL ||
2302 wpa_s->current_bss->anqp == NULL)
2303 res = -1;
2304 else
2305 res = interworking_home_sp_cred(
2306 wpa_s, cred,
2307 wpa_s->current_bss->anqp->domain_name);
2308 if (res > 0)
2309 type = "home";
2310 else if (res == 0)
2311 type = "roaming";
2312 else
2313 type = "unknown";
2314
2315 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002316 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002317 return pos - buf;
2318 pos += ret;
2319
2320 break;
2321 }
2322 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002323#endif /* CONFIG_HS20 */
2324
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002325 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2326 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2327 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2328 verbose);
2329 if (res >= 0)
2330 pos += res;
2331 }
2332
Dmitry Shmidt29333592017-01-09 12:27:11 -08002333#ifdef CONFIG_MACSEC
2334 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2335 if (res > 0)
2336 pos += res;
2337#endif /* CONFIG_MACSEC */
2338
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002339 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2340 if (sess_id) {
2341 char *start = pos;
2342
2343 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2344 if (os_snprintf_error(end - pos, ret))
2345 return start - buf;
2346 pos += ret;
2347 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2348 if (ret <= 0)
2349 return start - buf;
2350 pos += ret;
2351 ret = os_snprintf(pos, end - pos, "\n");
2352 if (os_snprintf_error(end - pos, ret))
2353 return start - buf;
2354 pos += ret;
2355 }
2356
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002357 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2358 if (res >= 0)
2359 pos += res;
2360
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002361#ifdef CONFIG_WPS
2362 {
2363 char uuid_str[100];
2364 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2365 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002366 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002367 return pos - buf;
2368 pos += ret;
2369 }
2370#endif /* CONFIG_WPS */
2371
Roshan Pius3a1667e2018-07-03 15:17:14 -07002372 if (wpa_s->ieee80211ac) {
2373 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2374 if (os_snprintf_error(end - pos, ret))
2375 return pos - buf;
2376 pos += ret;
2377 }
2378
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002379#ifdef ANDROID
vandwalleffc70182014-09-11 11:40:14 -07002380 /*
2381 * Allow using the STATUS command with default behavior, say for debug,
2382 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2383 * events with STATUS-NO_EVENTS.
2384 */
2385 if (os_strcmp(params, "-NO_EVENTS")) {
2386 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2387 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2388 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2389 wpa_s->wpa_state,
2390 MAC2STR(wpa_s->bssid),
2391 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2392 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2393 wpa_s->current_ssid->ssid_len) : "");
2394 if (wpa_s->wpa_state == WPA_COMPLETED) {
2395 struct wpa_ssid *ssid = wpa_s->current_ssid;
2396 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2397 "- connection to " MACSTR
2398 " completed %s [id=%d id_str=%s]",
2399 MAC2STR(wpa_s->bssid), "(auth)",
2400 ssid ? ssid->id : -1,
2401 ssid && ssid->id_str ? ssid->id_str : "");
2402 }
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08002403 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002404#endif /* ANDROID */
2405
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002406 return pos - buf;
2407}
2408
2409
2410static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2411 char *cmd)
2412{
2413 char *pos;
2414 int id;
2415 struct wpa_ssid *ssid;
2416 u8 bssid[ETH_ALEN];
2417
2418 /* cmd: "<network id> <BSSID>" */
2419 pos = os_strchr(cmd, ' ');
2420 if (pos == NULL)
2421 return -1;
2422 *pos++ = '\0';
2423 id = atoi(cmd);
2424 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2425 if (hwaddr_aton(pos, bssid)) {
2426 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2427 return -1;
2428 }
2429
2430 ssid = wpa_config_get_network(wpa_s->conf, id);
2431 if (ssid == NULL) {
2432 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2433 "to update", id);
2434 return -1;
2435 }
2436
2437 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2438 ssid->bssid_set = !is_zero_ether_addr(bssid);
2439
2440 return 0;
2441}
2442
2443
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002444static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002445 char *cmd, char *buf,
2446 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002447{
2448 u8 bssid[ETH_ALEN];
2449 struct wpa_blacklist *e;
2450 char *pos, *end;
2451 int ret;
2452
2453 /* cmd: "BLACKLIST [<BSSID>]" */
2454 if (*cmd == '\0') {
2455 pos = buf;
2456 end = buf + buflen;
2457 e = wpa_s->blacklist;
2458 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002459 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2460 MAC2STR(e->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002461 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002462 return pos - buf;
2463 pos += ret;
2464 e = e->next;
2465 }
2466 return pos - buf;
2467 }
2468
2469 cmd++;
2470 if (os_strncmp(cmd, "clear", 5) == 0) {
2471 wpa_blacklist_clear(wpa_s);
2472 os_memcpy(buf, "OK\n", 3);
2473 return 3;
2474 }
2475
2476 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
2477 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002478 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002479 return -1;
2480 }
2481
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002482 /*
2483 * Add the BSSID twice, so its count will be 2, causing it to be
2484 * skipped when processing scan results.
2485 */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002486 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002487 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002488 return -1;
2489 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002490 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002491 return -1;
2492 os_memcpy(buf, "OK\n", 3);
2493 return 3;
2494}
2495
2496
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002497static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2498 char *cmd, char *buf,
2499 size_t buflen)
2500{
2501 char *pos, *end, *stamp;
2502 int ret;
2503
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002504 /* cmd: "LOG_LEVEL [<level>]" */
2505 if (*cmd == '\0') {
2506 pos = buf;
2507 end = buf + buflen;
2508 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2509 "Timestamp: %d\n",
2510 debug_level_str(wpa_debug_level),
2511 wpa_debug_timestamp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002512 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002513 ret = 0;
2514
2515 return ret;
2516 }
2517
2518 while (*cmd == ' ')
2519 cmd++;
2520
2521 stamp = os_strchr(cmd, ' ');
2522 if (stamp) {
2523 *stamp++ = '\0';
2524 while (*stamp == ' ') {
2525 stamp++;
2526 }
2527 }
2528
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002529 if (os_strlen(cmd)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002530 int level = str_to_debug_level(cmd);
2531 if (level < 0)
2532 return -1;
2533 wpa_debug_level = level;
2534 }
2535
2536 if (stamp && os_strlen(stamp))
2537 wpa_debug_timestamp = atoi(stamp);
2538
2539 os_memcpy(buf, "OK\n", 3);
2540 return 3;
2541}
2542
2543
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002544static int wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002545 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002546{
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002547 char *pos, *end, *prev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002548 struct wpa_ssid *ssid;
2549 int ret;
2550
2551 pos = buf;
2552 end = buf + buflen;
2553 ret = os_snprintf(pos, end - pos,
2554 "network id / ssid / bssid / flags\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002555 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002556 return pos - buf;
2557 pos += ret;
2558
2559 ssid = wpa_s->conf->ssid;
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002560
2561 /* skip over ssids until we find next one */
2562 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2563 int last_id = atoi(cmd + 8);
2564 if (last_id != -1) {
2565 while (ssid != NULL && ssid->id <= last_id) {
2566 ssid = ssid->next;
2567 }
2568 }
2569 }
2570
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002571 while (ssid) {
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002572 prev = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002573 ret = os_snprintf(pos, end - pos, "%d\t%s",
2574 ssid->id,
2575 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002576 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002577 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002578 pos += ret;
2579 if (ssid->bssid_set) {
2580 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2581 MAC2STR(ssid->bssid));
2582 } else {
2583 ret = os_snprintf(pos, end - pos, "\tany");
2584 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002585 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002586 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002587 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002588 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002589 ssid == wpa_s->current_ssid ?
2590 "[CURRENT]" : "",
2591 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002592 ssid->disabled_until.sec ?
2593 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002594 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2595 "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002596 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002597 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002598 pos += ret;
2599 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002600 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002601 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002602 pos += ret;
2603
2604 ssid = ssid->next;
2605 }
2606
2607 return pos - buf;
2608}
2609
2610
2611static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2612{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002613 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002614 ret = os_snprintf(pos, end - pos, "-");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002615 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002616 return pos;
2617 pos += ret;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002618 ret = wpa_write_ciphers(pos, end, cipher, "+");
2619 if (ret < 0)
2620 return pos;
2621 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002622 return pos;
2623}
2624
2625
2626static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2627 const u8 *ie, size_t ie_len)
2628{
2629 struct wpa_ie_data data;
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002630 char *start;
2631 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002632
2633 ret = os_snprintf(pos, end - pos, "[%s-", proto);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002634 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002635 return pos;
2636 pos += ret;
2637
2638 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2639 ret = os_snprintf(pos, end - pos, "?]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002640 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002641 return pos;
2642 pos += ret;
2643 return pos;
2644 }
2645
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002646 start = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002647 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002648 ret = os_snprintf(pos, end - pos, "%sEAP",
2649 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002650 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002651 return pos;
2652 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002653 }
2654 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002655 ret = os_snprintf(pos, end - pos, "%sPSK",
2656 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002657 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002658 return pos;
2659 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002660 }
2661 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002662 ret = os_snprintf(pos, end - pos, "%sNone",
2663 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002664 if (os_snprintf_error(end - pos, ret))
2665 return pos;
2666 pos += ret;
2667 }
2668 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2669 ret = os_snprintf(pos, end - pos, "%sSAE",
2670 pos == start ? "" : "+");
2671 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002672 return pos;
2673 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002674 }
2675#ifdef CONFIG_IEEE80211R
2676 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2677 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002678 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002679 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002680 return pos;
2681 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002682 }
2683 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2684 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002685 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002686 if (os_snprintf_error(end - pos, ret))
2687 return pos;
2688 pos += ret;
2689 }
2690 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2691 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2692 pos == start ? "" : "+");
2693 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002694 return pos;
2695 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002696 }
2697#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002698 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2699 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002700 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002701 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002702 return pos;
2703 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002704 }
2705 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2706 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002707 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002708 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002709 return pos;
2710 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002711 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002712
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002713#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002714 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2715 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2716 pos == start ? "" : "+");
2717 if (os_snprintf_error(end - pos, ret))
2718 return pos;
2719 pos += ret;
2720 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002721#endif /* CONFIG_SUITEB */
2722
2723#ifdef CONFIG_SUITEB192
2724 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2725 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2726 pos == start ? "" : "+");
2727 if (os_snprintf_error(end - pos, ret))
2728 return pos;
2729 pos += ret;
2730 }
2731#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002732
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002733#ifdef CONFIG_FILS
2734 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2735 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2736 pos == start ? "" : "+");
2737 if (os_snprintf_error(end - pos, ret))
2738 return pos;
2739 pos += ret;
2740 }
2741 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2742 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2743 pos == start ? "" : "+");
2744 if (os_snprintf_error(end - pos, ret))
2745 return pos;
2746 pos += ret;
2747 }
2748#ifdef CONFIG_IEEE80211R
2749 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2750 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2751 pos == start ? "" : "+");
2752 if (os_snprintf_error(end - pos, ret))
2753 return pos;
2754 pos += ret;
2755 }
2756 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2757 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2758 pos == start ? "" : "+");
2759 if (os_snprintf_error(end - pos, ret))
2760 return pos;
2761 pos += ret;
2762 }
2763#endif /* CONFIG_IEEE80211R */
2764#endif /* CONFIG_FILS */
2765
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002766#ifdef CONFIG_OWE
2767 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2768 ret = os_snprintf(pos, end - pos, "%sOWE",
2769 pos == start ? "" : "+");
2770 if (os_snprintf_error(end - pos, ret))
2771 return pos;
2772 pos += ret;
2773 }
2774#endif /* CONFIG_OWE */
2775
2776#ifdef CONFIG_DPP
2777 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
2778 ret = os_snprintf(pos, end - pos, "%sDPP",
2779 pos == start ? "" : "+");
2780 if (os_snprintf_error(end - pos, ret))
2781 return pos;
2782 pos += ret;
2783 }
2784#endif /* CONFIG_DPP */
2785
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002786 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2787 ret = os_snprintf(pos, end - pos, "%sOSEN",
2788 pos == start ? "" : "+");
2789 if (os_snprintf_error(end - pos, ret))
2790 return pos;
2791 pos += ret;
2792 }
2793
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002794 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2795
2796 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2797 ret = os_snprintf(pos, end - pos, "-preauth");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002798 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002799 return pos;
2800 pos += ret;
2801 }
2802
2803 ret = os_snprintf(pos, end - pos, "]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002804 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002805 return pos;
2806 pos += ret;
2807
2808 return pos;
2809}
2810
2811
2812#ifdef CONFIG_WPS
2813static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2814 char *pos, char *end,
2815 struct wpabuf *wps_ie)
2816{
2817 int ret;
2818 const char *txt;
2819
2820 if (wps_ie == NULL)
2821 return pos;
2822 if (wps_is_selected_pbc_registrar(wps_ie))
2823 txt = "[WPS-PBC]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002824 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2825 txt = "[WPS-AUTH]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002826 else if (wps_is_selected_pin_registrar(wps_ie))
2827 txt = "[WPS-PIN]";
2828 else
2829 txt = "[WPS]";
2830
2831 ret = os_snprintf(pos, end - pos, "%s", txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002832 if (!os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002833 pos += ret;
2834 wpabuf_free(wps_ie);
2835 return pos;
2836}
2837#endif /* CONFIG_WPS */
2838
2839
2840static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2841 char *pos, char *end,
2842 const struct wpa_bss *bss)
2843{
2844#ifdef CONFIG_WPS
2845 struct wpabuf *wps_ie;
2846 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2847 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2848#else /* CONFIG_WPS */
2849 return pos;
2850#endif /* CONFIG_WPS */
2851}
2852
2853
2854/* Format one result on one text line into a buffer. */
2855static int wpa_supplicant_ctrl_iface_scan_result(
2856 struct wpa_supplicant *wpa_s,
2857 const struct wpa_bss *bss, char *buf, size_t buflen)
2858{
2859 char *pos, *end;
2860 int ret;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002861 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002862
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002863 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002864 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07002865 if (!p2p)
2866 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002867 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2868 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2869 0)
2870 return 0; /* Do not show P2P listen discovery results here */
2871
2872 pos = buf;
2873 end = buf + buflen;
2874
2875 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2876 MAC2STR(bss->bssid), bss->freq, bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002877 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002878 return -1;
2879 pos += ret;
2880 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2881 if (ie)
2882 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2883 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002884 if (ie2) {
2885 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2886 ie2, 2 + ie2[1]);
2887 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002888 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
2889 if (osen_ie)
2890 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
2891 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002892 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
2893 if (owe) {
2894 ret = os_snprintf(pos, end - pos,
2895 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2896 if (os_snprintf_error(end - pos, ret))
2897 return -1;
2898 pos += ret;
2899 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002900 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002901 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002902 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002903 if (os_snprintf_error(end - pos, ret))
2904 return -1;
2905 pos += ret;
2906 }
2907 if (mesh) {
2908 ret = os_snprintf(pos, end - pos, "[MESH]");
2909 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002910 return -1;
2911 pos += ret;
2912 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002913 if (bss_is_dmg(bss)) {
2914 const char *s;
Hai Shalomc3565922019-10-28 11:58:20 -07002915
2916 if (get_ie_ext((const u8 *) (bss + 1), bss->ie_len,
2917 WLAN_EID_EXT_EDMG_OPERATION)) {
2918 ret = os_snprintf(pos, end - pos, "[EDMG]");
2919 if (os_snprintf_error(end - pos, ret))
2920 return -1;
2921 pos += ret;
2922 }
2923
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002924 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002925 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002926 return -1;
2927 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002928 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2929 case IEEE80211_CAP_DMG_IBSS:
2930 s = "[IBSS]";
2931 break;
2932 case IEEE80211_CAP_DMG_AP:
2933 s = "[ESS]";
2934 break;
2935 case IEEE80211_CAP_DMG_PBSS:
2936 s = "[PBSS]";
2937 break;
2938 default:
2939 s = "";
2940 break;
2941 }
2942 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002943 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002944 return -1;
2945 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002946 } else {
2947 if (bss->caps & IEEE80211_CAP_IBSS) {
2948 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002949 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002950 return -1;
2951 pos += ret;
2952 }
2953 if (bss->caps & IEEE80211_CAP_ESS) {
2954 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002955 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002956 return -1;
2957 pos += ret;
2958 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002959 }
2960 if (p2p) {
2961 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002962 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002963 return -1;
2964 pos += ret;
2965 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002966#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002967 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002968 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002969 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002970 return -1;
2971 pos += ret;
2972 }
2973#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002974#ifdef CONFIG_FILS
2975 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
2976 ret = os_snprintf(pos, end - pos, "[FILS]");
2977 if (os_snprintf_error(end - pos, ret))
2978 return -1;
2979 pos += ret;
2980 }
2981#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002982#ifdef CONFIG_FST
2983 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
2984 ret = os_snprintf(pos, end - pos, "[FST]");
2985 if (os_snprintf_error(end - pos, ret))
2986 return -1;
2987 pos += ret;
2988 }
2989#endif /* CONFIG_FST */
Hai Shalom74f70d42019-02-11 14:42:39 -08002990 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
2991 ret = os_snprintf(pos, end - pos, "[UTF-8]");
2992 if (os_snprintf_error(end - pos, ret))
2993 return -1;
2994 pos += ret;
2995 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002996
2997 ret = os_snprintf(pos, end - pos, "\t%s",
2998 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002999 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003000 return -1;
3001 pos += ret;
3002
3003 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003004 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003005 return -1;
3006 pos += ret;
3007
3008 return pos - buf;
3009}
3010
3011
3012static int wpa_supplicant_ctrl_iface_scan_results(
3013 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3014{
3015 char *pos, *end;
3016 struct wpa_bss *bss;
3017 int ret;
3018
3019 pos = buf;
3020 end = buf + buflen;
3021 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
3022 "flags / ssid\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003023 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003024 return pos - buf;
3025 pos += ret;
3026
3027 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
3028 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
3029 end - pos);
3030 if (ret < 0 || ret >= end - pos)
3031 return pos - buf;
3032 pos += ret;
3033 }
3034
3035 return pos - buf;
3036}
3037
3038
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003039#ifdef CONFIG_MESH
3040
3041static int wpa_supplicant_ctrl_iface_mesh_interface_add(
3042 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
3043{
3044 char *pos, ifname[IFNAMSIZ + 1];
3045
3046 ifname[0] = '\0';
3047
3048 pos = os_strstr(cmd, "ifname=");
3049 if (pos) {
3050 pos += 7;
3051 os_strlcpy(ifname, pos, sizeof(ifname));
3052 }
3053
3054 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
3055 return -1;
3056
3057 os_strlcpy(reply, ifname, max_len);
3058 return os_strlen(ifname);
3059}
3060
3061
3062static int wpa_supplicant_ctrl_iface_mesh_group_add(
3063 struct wpa_supplicant *wpa_s, char *cmd)
3064{
3065 int id;
3066 struct wpa_ssid *ssid;
3067
3068 id = atoi(cmd);
3069 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
3070
3071 ssid = wpa_config_get_network(wpa_s->conf, id);
3072 if (ssid == NULL) {
3073 wpa_printf(MSG_DEBUG,
3074 "CTRL_IFACE: Could not find network id=%d", id);
3075 return -1;
3076 }
3077 if (ssid->mode != WPAS_MODE_MESH) {
3078 wpa_printf(MSG_DEBUG,
3079 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3080 return -1;
3081 }
3082 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
3083 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
3084 wpa_printf(MSG_ERROR,
3085 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3086 return -1;
3087 }
3088
3089 /*
3090 * TODO: If necessary write our own group_add function,
3091 * for now we can reuse select_network
3092 */
3093 wpa_supplicant_select_network(wpa_s, ssid);
3094
3095 return 0;
3096}
3097
3098
3099static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3100 struct wpa_supplicant *wpa_s, char *cmd)
3101{
3102 struct wpa_supplicant *orig;
3103 struct wpa_global *global;
3104 int found = 0;
3105
3106 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3107
3108 global = wpa_s->global;
3109 orig = wpa_s;
3110
3111 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3112 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3113 found = 1;
3114 break;
3115 }
3116 }
3117 if (!found) {
3118 wpa_printf(MSG_ERROR,
3119 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3120 cmd);
3121 return -1;
3122 }
3123 if (wpa_s->mesh_if_created && wpa_s == orig) {
3124 wpa_printf(MSG_ERROR,
3125 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3126 return -1;
3127 }
3128
3129 wpa_s->reassociate = 0;
3130 wpa_s->disconnected = 1;
3131 wpa_supplicant_cancel_sched_scan(wpa_s);
3132 wpa_supplicant_cancel_scan(wpa_s);
3133
3134 /*
3135 * TODO: If necessary write our own group_remove function,
3136 * for now we can reuse deauthenticate
3137 */
3138 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3139
3140 if (wpa_s->mesh_if_created)
3141 wpa_supplicant_remove_iface(global, wpa_s, 0);
3142
3143 return 0;
3144}
3145
Dmitry Shmidte4663042016-04-04 10:07:49 -07003146
3147static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3148 struct wpa_supplicant *wpa_s, char *cmd)
3149{
3150 u8 addr[ETH_ALEN];
3151
3152 if (hwaddr_aton(cmd, addr) < 0)
3153 return -1;
3154
3155 return wpas_mesh_peer_remove(wpa_s, addr);
3156}
3157
3158
3159static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3160 struct wpa_supplicant *wpa_s, char *cmd)
3161{
3162 u8 addr[ETH_ALEN];
3163 int duration;
3164 char *pos;
3165
3166 pos = os_strstr(cmd, " duration=");
3167 if (pos) {
3168 *pos = '\0';
3169 duration = atoi(pos + 10);
3170 } else {
3171 duration = -1;
3172 }
3173
3174 if (hwaddr_aton(cmd, addr))
3175 return -1;
3176
3177 return wpas_mesh_peer_add(wpa_s, addr, duration);
3178}
3179
Hai Shalom81f62d82019-07-22 12:10:00 -07003180
3181static int wpa_supplicant_ctrl_iface_mesh_link_probe(
3182 struct wpa_supplicant *wpa_s, char *cmd)
3183{
3184 struct ether_header *eth;
3185 u8 addr[ETH_ALEN];
3186 u8 *buf;
3187 char *pos;
3188 size_t payload_len = 0, len;
3189 int ret = -1;
3190
3191 if (hwaddr_aton(cmd, addr))
3192 return -1;
3193
3194 pos = os_strstr(cmd, " payload=");
3195 if (pos) {
3196 pos = pos + 9;
3197 payload_len = os_strlen(pos);
3198 if (payload_len & 1)
3199 return -1;
3200
3201 payload_len /= 2;
3202 }
3203
3204 len = ETH_HLEN + payload_len;
3205 buf = os_malloc(len);
3206 if (!buf)
3207 return -1;
3208
3209 eth = (struct ether_header *) buf;
3210 os_memcpy(eth->ether_dhost, addr, ETH_ALEN);
3211 os_memcpy(eth->ether_shost, wpa_s->own_addr, ETH_ALEN);
3212 eth->ether_type = htons(ETH_P_802_3);
3213
3214 if (payload_len && hexstr2bin(pos, buf + ETH_HLEN, payload_len) < 0)
3215 goto fail;
3216
3217 ret = wpa_drv_mesh_link_probe(wpa_s, addr, buf, len);
3218fail:
3219 os_free(buf);
3220 return -ret;
3221}
3222
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003223#endif /* CONFIG_MESH */
3224
3225
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003226static int wpa_supplicant_ctrl_iface_select_network(
3227 struct wpa_supplicant *wpa_s, char *cmd)
3228{
3229 int id;
3230 struct wpa_ssid *ssid;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003231 char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003232
3233 /* cmd: "<network id>" or "any" */
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003234 if (os_strncmp(cmd, "any", 3) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003235 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3236 ssid = NULL;
3237 } else {
3238 id = atoi(cmd);
3239 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3240
3241 ssid = wpa_config_get_network(wpa_s->conf, id);
3242 if (ssid == NULL) {
3243 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3244 "network id=%d", id);
3245 return -1;
3246 }
3247 if (ssid->disabled == 2) {
3248 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3249 "SELECT_NETWORK with persistent P2P group");
3250 return -1;
3251 }
3252 }
3253
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003254 pos = os_strstr(cmd, " freq=");
3255 if (pos) {
3256 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3257 if (freqs) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003258 os_free(wpa_s->select_network_scan_freqs);
3259 wpa_s->select_network_scan_freqs = freqs;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003260 }
3261 }
3262
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003263 wpa_s->scan_min_time.sec = 0;
3264 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003265 wpa_supplicant_select_network(wpa_s, ssid);
3266
3267 return 0;
3268}
3269
3270
3271static int wpa_supplicant_ctrl_iface_enable_network(
3272 struct wpa_supplicant *wpa_s, char *cmd)
3273{
3274 int id;
3275 struct wpa_ssid *ssid;
3276
3277 /* cmd: "<network id>" or "all" */
3278 if (os_strcmp(cmd, "all") == 0) {
3279 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3280 ssid = NULL;
3281 } else {
3282 id = atoi(cmd);
3283 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3284
3285 ssid = wpa_config_get_network(wpa_s->conf, id);
3286 if (ssid == NULL) {
3287 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3288 "network id=%d", id);
3289 return -1;
3290 }
3291 if (ssid->disabled == 2) {
3292 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3293 "ENABLE_NETWORK with persistent P2P group");
3294 return -1;
3295 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003296
3297 if (os_strstr(cmd, " no-connect")) {
3298 ssid->disabled = 0;
3299 return 0;
3300 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003301 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003302 wpa_s->scan_min_time.sec = 0;
3303 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003304 wpa_supplicant_enable_network(wpa_s, ssid);
3305
3306 return 0;
3307}
3308
3309
3310static int wpa_supplicant_ctrl_iface_disable_network(
3311 struct wpa_supplicant *wpa_s, char *cmd)
3312{
3313 int id;
3314 struct wpa_ssid *ssid;
3315
3316 /* cmd: "<network id>" or "all" */
3317 if (os_strcmp(cmd, "all") == 0) {
3318 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3319 ssid = NULL;
3320 } else {
3321 id = atoi(cmd);
3322 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3323
3324 ssid = wpa_config_get_network(wpa_s->conf, id);
3325 if (ssid == NULL) {
3326 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3327 "network id=%d", id);
3328 return -1;
3329 }
3330 if (ssid->disabled == 2) {
3331 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3332 "DISABLE_NETWORK with persistent P2P "
3333 "group");
3334 return -1;
3335 }
3336 }
3337 wpa_supplicant_disable_network(wpa_s, ssid);
3338
3339 return 0;
3340}
3341
3342
3343static int wpa_supplicant_ctrl_iface_add_network(
3344 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3345{
3346 struct wpa_ssid *ssid;
3347 int ret;
3348
3349 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3350
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003351 ssid = wpa_supplicant_add_network(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003352 if (ssid == NULL)
3353 return -1;
3354
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003355 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003356 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003357 return -1;
3358 return ret;
3359}
3360
3361
3362static int wpa_supplicant_ctrl_iface_remove_network(
3363 struct wpa_supplicant *wpa_s, char *cmd)
3364{
3365 int id;
3366 struct wpa_ssid *ssid;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003367 int result;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003368
3369 /* cmd: "<network id>" or "all" */
3370 if (os_strcmp(cmd, "all") == 0) {
3371 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003372 if (wpa_s->sched_scanning)
3373 wpa_supplicant_cancel_sched_scan(wpa_s);
3374
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003375 eapol_sm_invalidate_cached_session(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003376 if (wpa_s->current_ssid) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003377#ifdef CONFIG_SME
3378 wpa_s->sme.prev_bssid_set = 0;
3379#endif /* CONFIG_SME */
Jouni Malinen75ecf522011-06-27 15:19:46 -07003380 wpa_sm_set_config(wpa_s->wpa, NULL);
3381 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07003382 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3383 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003384 wpa_supplicant_deauthenticate(
3385 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003386 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003387 ssid = wpa_s->conf->ssid;
3388 while (ssid) {
3389 struct wpa_ssid *remove_ssid = ssid;
3390 id = ssid->id;
3391 ssid = ssid->next;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003392 if (wpa_s->last_ssid == remove_ssid)
3393 wpa_s->last_ssid = NULL;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003394 wpas_notify_network_removed(wpa_s, remove_ssid);
3395 wpa_config_remove_network(wpa_s->conf, id);
3396 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003397 return 0;
3398 }
3399
3400 id = atoi(cmd);
3401 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3402
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003403 result = wpa_supplicant_remove_network(wpa_s, id);
3404 if (result == -1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003405 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3406 "id=%d", id);
3407 return -1;
3408 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003409 if (result == -2) {
Deepthi Gowria831d782012-09-03 11:55:38 +03003410 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3411 "network id=%d", id);
3412 return -1;
3413 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003414 return 0;
3415}
3416
3417
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003418static int wpa_supplicant_ctrl_iface_update_network(
3419 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3420 char *name, char *value)
3421{
Dmitry Shmidte4663042016-04-04 10:07:49 -07003422 int ret;
3423
3424 ret = wpa_config_set(ssid, name, value, 0);
3425 if (ret < 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003426 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3427 "variable '%s'", name);
3428 return -1;
3429 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07003430 if (ret == 1)
3431 return 0; /* No change to the previously configured value */
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003432
3433 if (os_strcmp(name, "bssid") != 0 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003434 os_strcmp(name, "bssid_hint") != 0 &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003435 os_strcmp(name, "priority") != 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003436 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3437
Dmitry Shmidte4663042016-04-04 10:07:49 -07003438 if (wpa_s->current_ssid == ssid ||
3439 wpa_s->current_ssid == NULL) {
3440 /*
3441 * Invalidate the EAP session cache if anything in the
3442 * current or previously used configuration changes.
3443 */
3444 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3445 }
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003446 }
3447
3448 if ((os_strcmp(name, "psk") == 0 &&
3449 value[0] == '"' && ssid->ssid_len) ||
3450 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3451 wpa_config_update_psk(ssid);
3452 else if (os_strcmp(name, "priority") == 0)
3453 wpa_config_update_prio_list(wpa_s->conf);
3454
3455 return 0;
3456}
3457
3458
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003459static int wpa_supplicant_ctrl_iface_set_network(
3460 struct wpa_supplicant *wpa_s, char *cmd)
3461{
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003462 int id, ret, prev_bssid_set, prev_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003463 struct wpa_ssid *ssid;
3464 char *name, *value;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003465 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003466
3467 /* cmd: "<network id> <variable name> <value>" */
3468 name = os_strchr(cmd, ' ');
3469 if (name == NULL)
3470 return -1;
3471 *name++ = '\0';
3472
3473 value = os_strchr(name, ' ');
3474 if (value == NULL)
3475 return -1;
3476 *value++ = '\0';
3477
3478 id = atoi(cmd);
3479 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3480 id, name);
3481 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3482 (u8 *) value, os_strlen(value));
3483
3484 ssid = wpa_config_get_network(wpa_s->conf, id);
3485 if (ssid == NULL) {
3486 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3487 "id=%d", id);
3488 return -1;
3489 }
3490
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003491 prev_bssid_set = ssid->bssid_set;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003492 prev_disabled = ssid->disabled;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003493 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3494 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3495 value);
3496 if (ret == 0 &&
3497 (ssid->bssid_set != prev_bssid_set ||
3498 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3499 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003500
3501 if (prev_disabled != ssid->disabled &&
3502 (prev_disabled == 2 || ssid->disabled == 2))
3503 wpas_notify_network_type_changed(wpa_s, ssid);
3504
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003505 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003506}
3507
3508
3509static int wpa_supplicant_ctrl_iface_get_network(
3510 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3511{
3512 int id;
3513 size_t res;
3514 struct wpa_ssid *ssid;
3515 char *name, *value;
3516
3517 /* cmd: "<network id> <variable name>" */
3518 name = os_strchr(cmd, ' ');
3519 if (name == NULL || buflen == 0)
3520 return -1;
3521 *name++ = '\0';
3522
3523 id = atoi(cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003524 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003525 id, name);
3526
3527 ssid = wpa_config_get_network(wpa_s->conf, id);
3528 if (ssid == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003529 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003530 "id=%d", id);
3531 return -1;
3532 }
3533
3534 value = wpa_config_get_no_key(ssid, name);
3535 if (value == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003536 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003537 "variable '%s'", name);
3538 return -1;
3539 }
3540
3541 res = os_strlcpy(buf, value, buflen);
3542 if (res >= buflen) {
3543 os_free(value);
3544 return -1;
3545 }
3546
3547 os_free(value);
3548
3549 return res;
3550}
3551
3552
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003553static int wpa_supplicant_ctrl_iface_dup_network(
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003554 struct wpa_supplicant *wpa_s, char *cmd,
3555 struct wpa_supplicant *dst_wpa_s)
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003556{
3557 struct wpa_ssid *ssid_s, *ssid_d;
3558 char *name, *id, *value;
3559 int id_s, id_d, ret;
3560
3561 /* cmd: "<src network id> <dst network id> <variable name>" */
3562 id = os_strchr(cmd, ' ');
3563 if (id == NULL)
3564 return -1;
3565 *id++ = '\0';
3566
3567 name = os_strchr(id, ' ');
3568 if (name == NULL)
3569 return -1;
3570 *name++ = '\0';
3571
3572 id_s = atoi(cmd);
3573 id_d = atoi(id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003574
3575 wpa_printf(MSG_DEBUG,
3576 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3577 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003578
3579 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3580 if (ssid_s == NULL) {
3581 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3582 "network id=%d", id_s);
3583 return -1;
3584 }
3585
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003586 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003587 if (ssid_d == NULL) {
3588 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003589 "network id=%d", id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003590 return -1;
3591 }
3592
3593 value = wpa_config_get(ssid_s, name);
3594 if (value == NULL) {
3595 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3596 "variable '%s'", name);
3597 return -1;
3598 }
3599
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003600 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003601 value);
3602
3603 os_free(value);
3604
3605 return ret;
3606}
3607
3608
Dmitry Shmidt04949592012-07-19 12:16:46 -07003609static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3610 char *buf, size_t buflen)
3611{
3612 char *pos, *end;
3613 struct wpa_cred *cred;
3614 int ret;
3615
3616 pos = buf;
3617 end = buf + buflen;
3618 ret = os_snprintf(pos, end - pos,
3619 "cred id / realm / username / domain / imsi\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003620 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003621 return pos - buf;
3622 pos += ret;
3623
3624 cred = wpa_s->conf->cred;
3625 while (cred) {
3626 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3627 cred->id, cred->realm ? cred->realm : "",
3628 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07003629 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003630 cred->imsi ? cred->imsi : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003631 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003632 return pos - buf;
3633 pos += ret;
3634
3635 cred = cred->next;
3636 }
3637
3638 return pos - buf;
3639}
3640
3641
3642static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3643 char *buf, size_t buflen)
3644{
3645 struct wpa_cred *cred;
3646 int ret;
3647
3648 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3649
3650 cred = wpa_config_add_cred(wpa_s->conf);
3651 if (cred == NULL)
3652 return -1;
3653
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003654 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3655
Dmitry Shmidt04949592012-07-19 12:16:46 -07003656 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003657 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003658 return -1;
3659 return ret;
3660}
3661
3662
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003663static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
3664 struct wpa_cred *cred)
3665{
3666 struct wpa_ssid *ssid;
3667 char str[20];
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003668 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003669
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003670 if (cred == NULL) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003671 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3672 return -1;
3673 }
3674
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003675 id = cred->id;
3676 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
3677 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3678 return -1;
3679 }
3680
3681 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
3682
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003683 /* Remove any network entry created based on the removed credential */
3684 ssid = wpa_s->conf->ssid;
3685 while (ssid) {
3686 if (ssid->parent_cred == cred) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003687 int res;
3688
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003689 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
3690 "used the removed credential", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003691 res = os_snprintf(str, sizeof(str), "%d", ssid->id);
3692 if (os_snprintf_error(sizeof(str), res))
3693 str[sizeof(str) - 1] = '\0';
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003694 ssid = ssid->next;
3695 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
3696 } else
3697 ssid = ssid->next;
3698 }
3699
3700 return 0;
3701}
3702
3703
Dmitry Shmidt04949592012-07-19 12:16:46 -07003704static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3705 char *cmd)
3706{
3707 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003708 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003709
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003710 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3711 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003712 if (os_strcmp(cmd, "all") == 0) {
3713 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3714 cred = wpa_s->conf->cred;
3715 while (cred) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003716 prev = cred;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003717 cred = cred->next;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003718 wpas_ctrl_remove_cred(wpa_s, prev);
3719 }
3720 return 0;
3721 }
3722
3723 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3724 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3725 cmd + 8);
3726 cred = wpa_s->conf->cred;
3727 while (cred) {
3728 prev = cred;
3729 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003730 if (prev->domain) {
3731 size_t i;
3732 for (i = 0; i < prev->num_domain; i++) {
3733 if (os_strcmp(prev->domain[i], cmd + 8)
3734 != 0)
3735 continue;
3736 wpas_ctrl_remove_cred(wpa_s, prev);
3737 break;
3738 }
3739 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003740 }
3741 return 0;
3742 }
3743
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003744 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3745 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3746 cmd + 16);
3747 cred = wpa_s->conf->cred;
3748 while (cred) {
3749 prev = cred;
3750 cred = cred->next;
3751 if (prev->provisioning_sp &&
3752 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3753 wpas_ctrl_remove_cred(wpa_s, prev);
3754 }
3755 return 0;
3756 }
3757
Dmitry Shmidt04949592012-07-19 12:16:46 -07003758 id = atoi(cmd);
3759 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3760
3761 cred = wpa_config_get_cred(wpa_s->conf, id);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003762 return wpas_ctrl_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003763}
3764
3765
3766static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3767 char *cmd)
3768{
3769 int id;
3770 struct wpa_cred *cred;
3771 char *name, *value;
3772
3773 /* cmd: "<cred id> <variable name> <value>" */
3774 name = os_strchr(cmd, ' ');
3775 if (name == NULL)
3776 return -1;
3777 *name++ = '\0';
3778
3779 value = os_strchr(name, ' ');
3780 if (value == NULL)
3781 return -1;
3782 *value++ = '\0';
3783
3784 id = atoi(cmd);
3785 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3786 id, name);
3787 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3788 (u8 *) value, os_strlen(value));
3789
3790 cred = wpa_config_get_cred(wpa_s->conf, id);
3791 if (cred == NULL) {
3792 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3793 id);
3794 return -1;
3795 }
3796
3797 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3798 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3799 "variable '%s'", name);
3800 return -1;
3801 }
3802
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003803 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3804
Dmitry Shmidt04949592012-07-19 12:16:46 -07003805 return 0;
3806}
3807
3808
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003809static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3810 char *cmd, char *buf,
3811 size_t buflen)
3812{
3813 int id;
3814 size_t res;
3815 struct wpa_cred *cred;
3816 char *name, *value;
3817
3818 /* cmd: "<cred id> <variable name>" */
3819 name = os_strchr(cmd, ' ');
3820 if (name == NULL)
3821 return -1;
3822 *name++ = '\0';
3823
3824 id = atoi(cmd);
3825 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3826 id, name);
3827
3828 cred = wpa_config_get_cred(wpa_s->conf, id);
3829 if (cred == NULL) {
3830 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3831 id);
3832 return -1;
3833 }
3834
3835 value = wpa_config_get_cred_no_key(cred, name);
3836 if (value == NULL) {
3837 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3838 name);
3839 return -1;
3840 }
3841
3842 res = os_strlcpy(buf, value, buflen);
3843 if (res >= buflen) {
3844 os_free(value);
3845 return -1;
3846 }
3847
3848 os_free(value);
3849
3850 return res;
3851}
3852
3853
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003854#ifndef CONFIG_NO_CONFIG_WRITE
3855static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3856{
3857 int ret;
3858
3859 if (!wpa_s->conf->update_config) {
3860 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3861 "to update configuration (update_config=0)");
3862 return -1;
3863 }
3864
3865 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3866 if (ret) {
3867 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3868 "update configuration");
3869 } else {
3870 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3871 " updated");
3872 }
3873
3874 return ret;
3875}
3876#endif /* CONFIG_NO_CONFIG_WRITE */
3877
3878
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003879struct cipher_info {
3880 unsigned int capa;
3881 const char *name;
3882 int group_only;
3883};
3884
3885static const struct cipher_info ciphers[] = {
3886 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3887 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3888 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3889 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3890 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3891 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3892 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3893 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3894};
3895
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003896static const struct cipher_info ciphers_group_mgmt[] = {
3897 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
3898 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
3899 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
3900 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
3901};
3902
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003903
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003904static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3905 struct wpa_driver_capa *capa,
3906 char *buf, size_t buflen)
3907{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003908 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003909 char *pos, *end;
3910 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003911 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003912
3913 pos = buf;
3914 end = pos + buflen;
3915
3916 if (res < 0) {
3917 if (strict)
3918 return 0;
3919 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3920 if (len >= buflen)
3921 return -1;
3922 return len;
3923 }
3924
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003925 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3926 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3927 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003928 pos == buf ? "" : " ",
3929 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003930 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003931 return pos - buf;
3932 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003933 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003934 }
3935
3936 return pos - buf;
3937}
3938
3939
3940static int ctrl_iface_get_capability_group(int res, char *strict,
3941 struct wpa_driver_capa *capa,
3942 char *buf, size_t buflen)
3943{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003944 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003945 char *pos, *end;
3946 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003947 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003948
3949 pos = buf;
3950 end = pos + buflen;
3951
3952 if (res < 0) {
3953 if (strict)
3954 return 0;
3955 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3956 if (len >= buflen)
3957 return -1;
3958 return len;
3959 }
3960
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003961 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3962 if (capa->enc & ciphers[i].capa) {
3963 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003964 pos == buf ? "" : " ",
3965 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003966 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003967 return pos - buf;
3968 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003969 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003970 }
3971
3972 return pos - buf;
3973}
3974
3975
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003976static int ctrl_iface_get_capability_group_mgmt(int res, char *strict,
3977 struct wpa_driver_capa *capa,
3978 char *buf, size_t buflen)
3979{
3980 int ret;
3981 char *pos, *end;
3982 unsigned int i;
3983
3984 pos = buf;
3985 end = pos + buflen;
3986
3987 if (res < 0)
3988 return 0;
3989
3990 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
3991 if (capa->enc & ciphers_group_mgmt[i].capa) {
3992 ret = os_snprintf(pos, end - pos, "%s%s",
3993 pos == buf ? "" : " ",
3994 ciphers_group_mgmt[i].name);
3995 if (os_snprintf_error(end - pos, ret))
3996 return pos - buf;
3997 pos += ret;
3998 }
3999 }
4000
4001 return pos - buf;
4002}
4003
4004
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004005static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
4006 struct wpa_driver_capa *capa,
4007 char *buf, size_t buflen)
4008{
4009 int ret;
4010 char *pos, *end;
4011 size_t len;
4012
4013 pos = buf;
4014 end = pos + buflen;
4015
4016 if (res < 0) {
4017 if (strict)
4018 return 0;
4019 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
4020 "NONE", buflen);
4021 if (len >= buflen)
4022 return -1;
4023 return len;
4024 }
4025
4026 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004027 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004028 return pos - buf;
4029 pos += ret;
4030
4031 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4032 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
4033 ret = os_snprintf(pos, end - pos, " WPA-EAP");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004034 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004035 return pos - buf;
4036 pos += ret;
4037 }
4038
4039 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
4040 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
4041 ret = os_snprintf(pos, end - pos, " WPA-PSK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004042 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004043 return pos - buf;
4044 pos += ret;
4045 }
4046
4047 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
4048 ret = os_snprintf(pos, end - pos, " WPA-NONE");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004049 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004050 return pos - buf;
4051 pos += ret;
4052 }
4053
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004054#ifdef CONFIG_SUITEB
4055 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
4056 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
4057 if (os_snprintf_error(end - pos, ret))
4058 return pos - buf;
4059 pos += ret;
4060 }
4061#endif /* CONFIG_SUITEB */
4062#ifdef CONFIG_SUITEB192
4063 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
4064 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
4065 if (os_snprintf_error(end - pos, ret))
4066 return pos - buf;
4067 pos += ret;
4068 }
4069#endif /* CONFIG_SUITEB192 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004070#ifdef CONFIG_OWE
4071 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
4072 ret = os_snprintf(pos, end - pos, " OWE");
4073 if (os_snprintf_error(end - pos, ret))
4074 return pos - buf;
4075 pos += ret;
4076 }
4077#endif /* CONFIG_OWE */
4078#ifdef CONFIG_DPP
4079 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
4080 ret = os_snprintf(pos, end - pos, " DPP");
4081 if (os_snprintf_error(end - pos, ret))
4082 return pos - buf;
4083 pos += ret;
4084 }
4085#endif /* CONFIG_DPP */
4086#ifdef CONFIG_FILS
4087 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
4088 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
4089 if (os_snprintf_error(end - pos, ret))
4090 return pos - buf;
4091 pos += ret;
4092 }
4093 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
4094 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
4095 if (os_snprintf_error(end - pos, ret))
4096 return pos - buf;
4097 pos += ret;
4098 }
4099#ifdef CONFIG_IEEE80211R
4100 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
4101 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
4102 if (os_snprintf_error(end - pos, ret))
4103 return pos - buf;
4104 pos += ret;
4105 }
4106 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
4107 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
4108 if (os_snprintf_error(end - pos, ret))
4109 return pos - buf;
4110 pos += ret;
4111 }
4112#endif /* CONFIG_IEEE80211R */
4113#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08004114#ifdef CONFIG_IEEE80211R
4115 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
4116 ret = os_snprintf(pos, end - pos, " FT-PSK");
4117 if (os_snprintf_error(end - pos, ret))
4118 return pos - buf;
4119 pos += ret;
4120 }
4121#endif /* CONFIG_IEEE80211R */
4122#ifdef CONFIG_SAE
4123 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
4124 ret = os_snprintf(pos, end - pos, " SAE");
4125 if (os_snprintf_error(end - pos, ret))
4126 return pos - buf;
4127 pos += ret;
4128 }
4129#endif /* CONFIG_SAE */
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004130
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004131 return pos - buf;
4132}
4133
4134
4135static int ctrl_iface_get_capability_proto(int res, char *strict,
4136 struct wpa_driver_capa *capa,
4137 char *buf, size_t buflen)
4138{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004139 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004140 char *pos, *end;
4141 size_t len;
4142
4143 pos = buf;
4144 end = pos + buflen;
4145
4146 if (res < 0) {
4147 if (strict)
4148 return 0;
4149 len = os_strlcpy(buf, "RSN WPA", buflen);
4150 if (len >= buflen)
4151 return -1;
4152 return len;
4153 }
4154
4155 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4156 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004157 ret = os_snprintf(pos, end - pos, "%sRSN",
4158 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004159 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004160 return pos - buf;
4161 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004162 }
4163
4164 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4165 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004166 ret = os_snprintf(pos, end - pos, "%sWPA",
4167 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004168 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004169 return pos - buf;
4170 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004171 }
4172
4173 return pos - buf;
4174}
4175
4176
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004177static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
4178 int res, char *strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004179 struct wpa_driver_capa *capa,
4180 char *buf, size_t buflen)
4181{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004182 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004183 char *pos, *end;
4184 size_t len;
4185
4186 pos = buf;
4187 end = pos + buflen;
4188
4189 if (res < 0) {
4190 if (strict)
4191 return 0;
4192 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4193 if (len >= buflen)
4194 return -1;
4195 return len;
4196 }
4197
4198 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004199 ret = os_snprintf(pos, end - pos, "%sOPEN",
4200 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004201 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004202 return pos - buf;
4203 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004204 }
4205
4206 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4207 ret = os_snprintf(pos, end - pos, "%sSHARED",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004208 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004209 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004210 return pos - buf;
4211 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004212 }
4213
4214 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004215 ret = os_snprintf(pos, end - pos, "%sLEAP",
4216 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004217 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004218 return pos - buf;
4219 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004220 }
4221
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004222#ifdef CONFIG_SAE
4223 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4224 ret = os_snprintf(pos, end - pos, "%sSAE",
4225 pos == buf ? "" : " ");
4226 if (os_snprintf_error(end - pos, ret))
4227 return pos - buf;
4228 pos += ret;
4229 }
4230#endif /* CONFIG_SAE */
4231
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004232#ifdef CONFIG_FILS
4233 if (wpa_is_fils_supported(wpa_s)) {
4234 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4235 pos == buf ? "" : " ");
4236 if (os_snprintf_error(end - pos, ret))
4237 return pos - buf;
4238 pos += ret;
4239 }
4240
4241#ifdef CONFIG_FILS_SK_PFS
4242 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4243 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4244 pos == buf ? "" : " ");
4245 if (os_snprintf_error(end - pos, ret))
4246 return pos - buf;
4247 pos += ret;
4248 }
4249#endif /* CONFIG_FILS_SK_PFS */
4250#endif /* CONFIG_FILS */
4251
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004252 return pos - buf;
4253}
4254
4255
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004256static int ctrl_iface_get_capability_modes(int res, char *strict,
4257 struct wpa_driver_capa *capa,
4258 char *buf, size_t buflen)
4259{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004260 int ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004261 char *pos, *end;
4262 size_t len;
4263
4264 pos = buf;
4265 end = pos + buflen;
4266
4267 if (res < 0) {
4268 if (strict)
4269 return 0;
4270 len = os_strlcpy(buf, "IBSS AP", buflen);
4271 if (len >= buflen)
4272 return -1;
4273 return len;
4274 }
4275
4276 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004277 ret = os_snprintf(pos, end - pos, "%sIBSS",
4278 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004279 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004280 return pos - buf;
4281 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004282 }
4283
4284 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004285 ret = os_snprintf(pos, end - pos, "%sAP",
4286 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004287 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004288 return pos - buf;
4289 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004290 }
4291
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004292#ifdef CONFIG_MESH
4293 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4294 ret = os_snprintf(pos, end - pos, "%sMESH",
4295 pos == buf ? "" : " ");
4296 if (os_snprintf_error(end - pos, ret))
4297 return pos - buf;
4298 pos += ret;
4299 }
4300#endif /* CONFIG_MESH */
4301
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004302 return pos - buf;
4303}
4304
4305
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004306static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4307 char *buf, size_t buflen)
4308{
4309 struct hostapd_channel_data *chnl;
4310 int ret, i, j;
4311 char *pos, *end, *hmode;
4312
4313 pos = buf;
4314 end = pos + buflen;
4315
4316 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4317 switch (wpa_s->hw.modes[j].mode) {
4318 case HOSTAPD_MODE_IEEE80211B:
4319 hmode = "B";
4320 break;
4321 case HOSTAPD_MODE_IEEE80211G:
4322 hmode = "G";
4323 break;
4324 case HOSTAPD_MODE_IEEE80211A:
4325 hmode = "A";
4326 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004327 case HOSTAPD_MODE_IEEE80211AD:
4328 hmode = "AD";
4329 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004330 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004331 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004332 }
4333 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004334 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004335 return pos - buf;
4336 pos += ret;
4337 chnl = wpa_s->hw.modes[j].channels;
4338 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004339 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4340 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004341 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004342 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004343 return pos - buf;
4344 pos += ret;
4345 }
4346 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004347 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004348 return pos - buf;
4349 pos += ret;
4350 }
4351
4352 return pos - buf;
4353}
4354
4355
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004356static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4357 char *buf, size_t buflen)
4358{
4359 struct hostapd_channel_data *chnl;
4360 int ret, i, j;
4361 char *pos, *end, *hmode;
4362
4363 pos = buf;
4364 end = pos + buflen;
4365
4366 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4367 switch (wpa_s->hw.modes[j].mode) {
4368 case HOSTAPD_MODE_IEEE80211B:
4369 hmode = "B";
4370 break;
4371 case HOSTAPD_MODE_IEEE80211G:
4372 hmode = "G";
4373 break;
4374 case HOSTAPD_MODE_IEEE80211A:
4375 hmode = "A";
4376 break;
4377 case HOSTAPD_MODE_IEEE80211AD:
4378 hmode = "AD";
4379 break;
4380 default:
4381 continue;
4382 }
4383 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4384 hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004385 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004386 return pos - buf;
4387 pos += ret;
4388 chnl = wpa_s->hw.modes[j].channels;
4389 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4390 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4391 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004392 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004393 chnl[i].chan, chnl[i].freq,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004394 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4395 " (NO_IR)" : "",
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004396 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4397 " (DFS)" : "");
4398
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004399 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004400 return pos - buf;
4401 pos += ret;
4402 }
4403 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004404 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004405 return pos - buf;
4406 pos += ret;
4407 }
4408
4409 return pos - buf;
4410}
4411
4412
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004413static int wpa_supplicant_ctrl_iface_get_capability(
4414 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4415 size_t buflen)
4416{
4417 struct wpa_driver_capa capa;
4418 int res;
4419 char *strict;
4420 char field[30];
4421 size_t len;
4422
4423 /* Determine whether or not strict checking was requested */
4424 len = os_strlcpy(field, _field, sizeof(field));
4425 if (len >= sizeof(field))
4426 return -1;
4427 strict = os_strchr(field, ' ');
4428 if (strict != NULL) {
4429 *strict++ = '\0';
4430 if (os_strcmp(strict, "strict") != 0)
4431 return -1;
4432 }
4433
4434 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4435 field, strict ? strict : "");
4436
4437 if (os_strcmp(field, "eap") == 0) {
4438 return eap_get_names(buf, buflen);
4439 }
4440
4441 res = wpa_drv_get_capa(wpa_s, &capa);
4442
4443 if (os_strcmp(field, "pairwise") == 0)
4444 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4445 buf, buflen);
4446
4447 if (os_strcmp(field, "group") == 0)
4448 return ctrl_iface_get_capability_group(res, strict, &capa,
4449 buf, buflen);
4450
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004451 if (os_strcmp(field, "group_mgmt") == 0)
4452 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4453 buf, buflen);
4454
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004455 if (os_strcmp(field, "key_mgmt") == 0)
4456 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
4457 buf, buflen);
4458
4459 if (os_strcmp(field, "proto") == 0)
4460 return ctrl_iface_get_capability_proto(res, strict, &capa,
4461 buf, buflen);
4462
4463 if (os_strcmp(field, "auth_alg") == 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004464 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4465 &capa, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004466
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004467 if (os_strcmp(field, "modes") == 0)
4468 return ctrl_iface_get_capability_modes(res, strict, &capa,
4469 buf, buflen);
4470
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004471 if (os_strcmp(field, "channels") == 0)
4472 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4473
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004474 if (os_strcmp(field, "freq") == 0)
4475 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4476
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004477#ifdef CONFIG_TDLS
4478 if (os_strcmp(field, "tdls") == 0)
4479 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4480#endif /* CONFIG_TDLS */
4481
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004482#ifdef CONFIG_ERP
4483 if (os_strcmp(field, "erp") == 0) {
4484 res = os_snprintf(buf, buflen, "ERP");
4485 if (os_snprintf_error(buflen, res))
4486 return -1;
4487 return res;
4488 }
4489#endif /* CONFIG_EPR */
4490
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004491#ifdef CONFIG_FIPS
4492 if (os_strcmp(field, "fips") == 0) {
4493 res = os_snprintf(buf, buflen, "FIPS");
4494 if (os_snprintf_error(buflen, res))
4495 return -1;
4496 return res;
4497 }
4498#endif /* CONFIG_FIPS */
4499
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004500#ifdef CONFIG_ACS
4501 if (os_strcmp(field, "acs") == 0) {
4502 res = os_snprintf(buf, buflen, "ACS");
4503 if (os_snprintf_error(buflen, res))
4504 return -1;
4505 return res;
4506 }
4507#endif /* CONFIG_ACS */
4508
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004509#ifdef CONFIG_FILS
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004510 if (os_strcmp(field, "fils") == 0) {
4511#ifdef CONFIG_FILS_SK_PFS
4512 if (wpa_is_fils_supported(wpa_s) &&
4513 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4514 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4515 if (os_snprintf_error(buflen, res))
4516 return -1;
4517 return res;
4518 }
4519#endif /* CONFIG_FILS_SK_PFS */
4520
4521 if (wpa_is_fils_supported(wpa_s)) {
4522 res = os_snprintf(buf, buflen, "FILS");
4523 if (os_snprintf_error(buflen, res))
4524 return -1;
4525 return res;
4526 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004527 }
4528#endif /* CONFIG_FILS */
4529
Hai Shalom74f70d42019-02-11 14:42:39 -08004530 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
4531 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
4532 if (os_snprintf_error(buflen, res))
4533 return -1;
4534 return res;
4535 }
4536
Hai Shalom021b0b52019-04-10 11:17:58 -07004537#ifdef CONFIG_DPP
4538 if (os_strcmp(field, "dpp") == 0) {
4539#ifdef CONFIG_DPP2
4540 res = os_snprintf(buf, buflen, "DPP=2");
4541#else /* CONFIG_DPP2 */
4542 res = os_snprintf(buf, buflen, "DPP=1");
4543#endif /* CONFIG_DPP2 */
4544 if (os_snprintf_error(buflen, res))
4545 return -1;
4546 return res;
4547 }
4548#endif /* CONFIG_DPP */
4549
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004550 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4551 field);
4552
4553 return -1;
4554}
4555
4556
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004557#ifdef CONFIG_INTERWORKING
4558static char * anqp_add_hex(char *pos, char *end, const char *title,
4559 struct wpabuf *data)
4560{
4561 char *start = pos;
4562 size_t i;
4563 int ret;
4564 const u8 *d;
4565
4566 if (data == NULL)
4567 return start;
4568
4569 ret = os_snprintf(pos, end - pos, "%s=", title);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004570 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004571 return start;
4572 pos += ret;
4573
4574 d = wpabuf_head_u8(data);
4575 for (i = 0; i < wpabuf_len(data); i++) {
4576 ret = os_snprintf(pos, end - pos, "%02x", *d++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004577 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004578 return start;
4579 pos += ret;
4580 }
4581
4582 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004583 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004584 return start;
4585 pos += ret;
4586
4587 return pos;
4588}
4589#endif /* CONFIG_INTERWORKING */
4590
4591
Dmitry Shmidt29333592017-01-09 12:27:11 -08004592#ifdef CONFIG_FILS
4593static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4594{
4595 char *start = pos;
4596 const u8 *ie, *ie_end;
4597 u16 info, realms;
4598 int ret;
4599
4600 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4601 if (!ie)
4602 return 0;
4603 ie_end = ie + 2 + ie[1];
4604 ie += 2;
4605 if (ie_end - ie < 2)
4606 return -1;
4607
4608 info = WPA_GET_LE16(ie);
4609 ie += 2;
4610 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4611 if (os_snprintf_error(end - pos, ret))
4612 return 0;
4613 pos += ret;
4614
4615 if (info & BIT(7)) {
4616 /* Cache Identifier Included */
4617 if (ie_end - ie < 2)
4618 return -1;
4619 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4620 ie[0], ie[1]);
4621 if (os_snprintf_error(end - pos, ret))
4622 return 0;
4623 pos += ret;
4624 ie += 2;
4625 }
4626
4627 if (info & BIT(8)) {
4628 /* HESSID Included */
4629 if (ie_end - ie < ETH_ALEN)
4630 return -1;
4631 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4632 MAC2STR(ie));
4633 if (os_snprintf_error(end - pos, ret))
4634 return 0;
4635 pos += ret;
4636 ie += ETH_ALEN;
4637 }
4638
4639 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4640 if (realms) {
4641 if (ie_end - ie < realms * 2)
4642 return -1;
4643 ret = os_snprintf(pos, end - pos, "fils_realms=");
4644 if (os_snprintf_error(end - pos, ret))
4645 return 0;
4646 pos += ret;
4647
4648 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
4649 if (ret <= 0)
4650 return 0;
4651 pos += ret;
4652 ie += realms * 2;
4653 ret = os_snprintf(pos, end - pos, "\n");
4654 if (os_snprintf_error(end - pos, ret))
4655 return 0;
4656 pos += ret;
4657 }
4658
4659 return pos - start;
4660}
4661#endif /* CONFIG_FILS */
4662
4663
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004664static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
4665 unsigned long mask, char *buf, size_t buflen)
4666{
4667 size_t i;
4668 int ret;
4669 char *pos, *end;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004670 const u8 *ie, *ie2, *osen_ie, *mesh, *owe;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004671
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004672 pos = buf;
4673 end = buf + buflen;
4674
4675 if (mask & WPA_BSS_MASK_ID) {
4676 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004677 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004678 return 0;
4679 pos += ret;
4680 }
4681
4682 if (mask & WPA_BSS_MASK_BSSID) {
4683 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
4684 MAC2STR(bss->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004685 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004686 return 0;
4687 pos += ret;
4688 }
4689
4690 if (mask & WPA_BSS_MASK_FREQ) {
4691 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004692 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004693 return 0;
4694 pos += ret;
4695 }
4696
4697 if (mask & WPA_BSS_MASK_BEACON_INT) {
4698 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
4699 bss->beacon_int);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004700 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004701 return 0;
4702 pos += ret;
4703 }
4704
4705 if (mask & WPA_BSS_MASK_CAPABILITIES) {
4706 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
4707 bss->caps);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004708 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004709 return 0;
4710 pos += ret;
4711 }
4712
4713 if (mask & WPA_BSS_MASK_QUAL) {
4714 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004715 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004716 return 0;
4717 pos += ret;
4718 }
4719
4720 if (mask & WPA_BSS_MASK_NOISE) {
4721 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004722 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004723 return 0;
4724 pos += ret;
4725 }
4726
4727 if (mask & WPA_BSS_MASK_LEVEL) {
4728 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004729 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004730 return 0;
4731 pos += ret;
4732 }
4733
4734 if (mask & WPA_BSS_MASK_TSF) {
4735 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
4736 (unsigned long long) bss->tsf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004737 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004738 return 0;
4739 pos += ret;
4740 }
4741
4742 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004743 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004744
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004745 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004746 ret = os_snprintf(pos, end - pos, "age=%d\n",
4747 (int) (now.sec - bss->last_update.sec));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004748 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004749 return 0;
4750 pos += ret;
4751 }
4752
4753 if (mask & WPA_BSS_MASK_IE) {
4754 ret = os_snprintf(pos, end - pos, "ie=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004755 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004756 return 0;
4757 pos += ret;
4758
4759 ie = (const u8 *) (bss + 1);
4760 for (i = 0; i < bss->ie_len; i++) {
4761 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004762 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004763 return 0;
4764 pos += ret;
4765 }
4766
4767 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004768 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004769 return 0;
4770 pos += ret;
4771 }
4772
4773 if (mask & WPA_BSS_MASK_FLAGS) {
4774 ret = os_snprintf(pos, end - pos, "flags=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004775 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004776 return 0;
4777 pos += ret;
4778
Dmitry Shmidt29333592017-01-09 12:27:11 -08004779 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
4780
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004781 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
4782 if (ie)
4783 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
4784 2 + ie[1]);
4785 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4786 if (ie2)
Dmitry Shmidt29333592017-01-09 12:27:11 -08004787 pos = wpa_supplicant_ie_txt(pos, end,
4788 mesh ? "RSN" : "WPA2", ie2,
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004789 2 + ie2[1]);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07004790 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
4791 if (osen_ie)
4792 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
4793 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004794 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
4795 if (owe) {
4796 ret = os_snprintf(
4797 pos, end - pos,
4798 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4799 if (os_snprintf_error(end - pos, ret))
4800 return 0;
4801 pos += ret;
4802 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004803 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07004804 if (!ie && !ie2 && !osen_ie &&
4805 (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004806 ret = os_snprintf(pos, end - pos, "[WEP]");
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 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08004811
4812 if (mesh) {
4813 ret = os_snprintf(pos, end - pos, "[MESH]");
4814 if (os_snprintf_error(end - pos, ret))
4815 return 0;
4816 pos += ret;
4817 }
4818
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004819 if (bss_is_dmg(bss)) {
4820 const char *s;
4821 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004822 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004823 return 0;
4824 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004825 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
4826 case IEEE80211_CAP_DMG_IBSS:
4827 s = "[IBSS]";
4828 break;
4829 case IEEE80211_CAP_DMG_AP:
4830 s = "[ESS]";
4831 break;
4832 case IEEE80211_CAP_DMG_PBSS:
4833 s = "[PBSS]";
4834 break;
4835 default:
4836 s = "";
4837 break;
4838 }
4839 ret = os_snprintf(pos, end - pos, "%s", s);
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;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004843 } else {
4844 if (bss->caps & IEEE80211_CAP_IBSS) {
4845 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004846 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004847 return 0;
4848 pos += ret;
4849 }
4850 if (bss->caps & IEEE80211_CAP_ESS) {
4851 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004852 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004853 return 0;
4854 pos += ret;
4855 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004856 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07004857 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
4858 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004859 ret = os_snprintf(pos, end - pos, "[P2P]");
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 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004864#ifdef CONFIG_HS20
4865 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
4866 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004867 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004868 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004869 pos += ret;
4870 }
4871#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004872#ifdef CONFIG_FILS
4873 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
4874 ret = os_snprintf(pos, end - pos, "[FILS]");
4875 if (os_snprintf_error(end - pos, ret))
4876 return 0;
4877 pos += ret;
4878 }
4879#endif /* CONFIG_FILS */
Hai Shalom74f70d42019-02-11 14:42:39 -08004880#ifdef CONFIG_FST
4881 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
4882 ret = os_snprintf(pos, end - pos, "[FST]");
4883 if (os_snprintf_error(end - pos, ret))
4884 return 0;
4885 pos += ret;
4886 }
4887#endif /* CONFIG_FST */
4888 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
4889 ret = os_snprintf(pos, end - pos, "[UTF-8]");
4890 if (os_snprintf_error(end - pos, ret))
4891 return 0;
4892 pos += ret;
4893 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004894
4895 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004896 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004897 return 0;
4898 pos += ret;
4899 }
4900
4901 if (mask & WPA_BSS_MASK_SSID) {
4902 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
4903 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004904 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004905 return 0;
4906 pos += ret;
4907 }
4908
4909#ifdef CONFIG_WPS
4910 if (mask & WPA_BSS_MASK_WPS_SCAN) {
4911 ie = (const u8 *) (bss + 1);
4912 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004913 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004914 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004915 if (ret > 0)
4916 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004917 }
4918#endif /* CONFIG_WPS */
4919
4920#ifdef CONFIG_P2P
4921 if (mask & WPA_BSS_MASK_P2P_SCAN) {
4922 ie = (const u8 *) (bss + 1);
4923 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004924 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004925 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004926 if (ret > 0)
4927 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004928 }
4929#endif /* CONFIG_P2P */
4930
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004931#ifdef CONFIG_WIFI_DISPLAY
4932 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
4933 struct wpabuf *wfd;
4934 ie = (const u8 *) (bss + 1);
4935 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
4936 WFD_IE_VENDOR_TYPE);
4937 if (wfd) {
4938 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004939 if (os_snprintf_error(end - pos, ret)) {
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004940 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004941 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004942 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004943 pos += ret;
4944
4945 pos += wpa_snprintf_hex(pos, end - pos,
4946 wpabuf_head(wfd),
4947 wpabuf_len(wfd));
4948 wpabuf_free(wfd);
4949
4950 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004951 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004952 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004953 pos += ret;
4954 }
4955 }
4956#endif /* CONFIG_WIFI_DISPLAY */
4957
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004958#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004959 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
4960 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004961 struct wpa_bss_anqp_elem *elem;
4962
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004963 pos = anqp_add_hex(pos, end, "anqp_capability_list",
4964 anqp->capability_list);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004965 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004966 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004967 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004968 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004969 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004970 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004971 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004972 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004973 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004974 anqp->nai_realm);
4975 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004976 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004977 anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -08004978 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
4979 anqp->fils_realm_info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004980#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004981 pos = anqp_add_hex(pos, end, "hs20_capability_list",
4982 anqp->hs20_capability_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004983 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004984 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004985 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004986 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004987 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004988 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004989 pos = anqp_add_hex(pos, end, "hs20_operating_class",
4990 anqp->hs20_operating_class);
4991 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
4992 anqp->hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004993 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
4994 anqp->hs20_operator_icon_metadata);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004995 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
4996 anqp->hs20_osu_providers_nai_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004997#endif /* CONFIG_HS20 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004998
4999 dl_list_for_each(elem, &anqp->anqp_elems,
5000 struct wpa_bss_anqp_elem, list) {
5001 char title[20];
5002
5003 os_snprintf(title, sizeof(title), "anqp[%u]",
5004 elem->infoid);
5005 pos = anqp_add_hex(pos, end, title, elem->payload);
5006 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005007 }
5008#endif /* CONFIG_INTERWORKING */
5009
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005010#ifdef CONFIG_MESH
5011 if (mask & WPA_BSS_MASK_MESH_SCAN) {
5012 ie = (const u8 *) (bss + 1);
5013 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005014 if (ret >= end - pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005015 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07005016 if (ret > 0)
5017 pos += ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005018 }
5019#endif /* CONFIG_MESH */
5020
Dmitry Shmidt7f656022015-02-25 14:36:37 -08005021 if (mask & WPA_BSS_MASK_SNR) {
5022 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
5023 if (os_snprintf_error(end - pos, ret))
5024 return 0;
5025 pos += ret;
5026 }
5027
5028 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
5029 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
5030 bss->est_throughput);
5031 if (os_snprintf_error(end - pos, ret))
5032 return 0;
5033 pos += ret;
5034 }
5035
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005036#ifdef CONFIG_FST
5037 if (mask & WPA_BSS_MASK_FST) {
5038 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
5039 if (ret < 0 || ret >= end - pos)
5040 return 0;
5041 pos += ret;
5042 }
5043#endif /* CONFIG_FST */
5044
Dmitry Shmidt29333592017-01-09 12:27:11 -08005045 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
5046 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
5047 bss->last_update_idx);
5048 if (os_snprintf_error(end - pos, ret))
5049 return 0;
5050 pos += ret;
5051 }
5052
5053 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
5054 ret = os_snprintf(pos, end - pos, "beacon_ie=");
5055 if (os_snprintf_error(end - pos, ret))
5056 return 0;
5057 pos += ret;
5058
5059 ie = (const u8 *) (bss + 1);
5060 ie += bss->ie_len;
5061 for (i = 0; i < bss->beacon_ie_len; i++) {
5062 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
5063 if (os_snprintf_error(end - pos, ret))
5064 return 0;
5065 pos += ret;
5066 }
5067
5068 ret = os_snprintf(pos, end - pos, "\n");
5069 if (os_snprintf_error(end - pos, ret))
5070 return 0;
5071 pos += ret;
5072 }
5073
5074#ifdef CONFIG_FILS
5075 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
5076 ret = print_fils_indication(bss, pos, end);
5077 if (ret < 0)
5078 return 0;
5079 pos += ret;
5080 }
5081#endif /* CONFIG_FILS */
5082
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005083 if (mask & WPA_BSS_MASK_DELIM) {
5084 ret = os_snprintf(pos, end - pos, "====\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005085 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005086 return 0;
5087 pos += ret;
5088 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07005089
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005090 return pos - buf;
5091}
5092
Dmitry Shmidt04949592012-07-19 12:16:46 -07005093
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005094static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
5095 const char *cmd, char *buf,
5096 size_t buflen)
5097{
5098 u8 bssid[ETH_ALEN];
5099 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005100 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005101 struct wpa_bss *bsslast = NULL;
5102 struct dl_list *next;
5103 int ret = 0;
5104 int len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005105 char *ctmp, *end = buf + buflen;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005106 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005107
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005108 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
5109 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
5110 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005111 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005112 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
5113 list_id);
5114 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07005115 unsigned int id1, id2;
5116
5117 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
5118 wpa_printf(MSG_INFO, "Wrong BSS range "
5119 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005120 return 0;
5121 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005122
Dmitry Shmidtf8623282013-02-20 14:34:59 -08005123 if (*(cmd + 6) == '-')
5124 id1 = 0;
5125 else
5126 id1 = atoi(cmd + 6);
5127 ctmp++;
5128 if (*ctmp >= '0' && *ctmp <= '9')
5129 id2 = atoi(ctmp);
5130 else
5131 id2 = (unsigned int) -1;
5132 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
5133 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005134 bsslast = dl_list_last(&wpa_s->bss_id,
5135 struct wpa_bss,
5136 list_id);
5137 else {
5138 bsslast = wpa_bss_get_id(wpa_s, id2);
5139 if (bsslast == NULL && bss && id2 > id1) {
5140 struct wpa_bss *tmp = bss;
5141 for (;;) {
5142 next = tmp->list_id.next;
5143 if (next == &wpa_s->bss_id)
5144 break;
5145 tmp = dl_list_entry(
5146 next, struct wpa_bss,
5147 list_id);
5148 if (tmp->id > id2)
5149 break;
5150 bsslast = tmp;
5151 }
5152 }
5153 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005154 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005155 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005156 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005157 else if (os_strncmp(cmd, "LAST", 4) == 0)
5158 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005159 else if (os_strncmp(cmd, "ID-", 3) == 0) {
5160 i = atoi(cmd + 3);
5161 bss = wpa_bss_get_id(wpa_s, i);
5162 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5163 i = atoi(cmd + 5);
5164 bss = wpa_bss_get_id(wpa_s, i);
5165 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005166 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005167 if (next == &wpa_s->bss_id)
5168 bss = NULL;
5169 else
5170 bss = dl_list_entry(next, struct wpa_bss,
5171 list_id);
5172 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005173 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5174 bss = wpa_s->current_bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005175#ifdef CONFIG_P2P
5176 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5177 if (hwaddr_aton(cmd + 13, bssid) == 0)
5178 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5179 else
5180 bss = NULL;
5181#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005182 } else if (hwaddr_aton(cmd, bssid) == 0)
5183 bss = wpa_bss_get_bssid(wpa_s, bssid);
5184 else {
5185 struct wpa_bss *tmp;
5186 i = atoi(cmd);
5187 bss = NULL;
5188 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5189 {
Hai Shalom021b0b52019-04-10 11:17:58 -07005190 if (i == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005191 bss = tmp;
5192 break;
5193 }
Hai Shalom021b0b52019-04-10 11:17:58 -07005194 i--;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005195 }
5196 }
5197
Dmitry Shmidt04949592012-07-19 12:16:46 -07005198 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5199 mask = strtoul(ctmp + 5, NULL, 0x10);
5200 if (mask == 0)
5201 mask = WPA_BSS_MASK_ALL;
5202 }
5203
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005204 if (bss == NULL)
5205 return 0;
5206
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005207 if (bsslast == NULL)
5208 bsslast = bss;
5209 do {
5210 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5211 ret += len;
5212 buf += len;
5213 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005214 if (bss == bsslast) {
5215 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5216 (bss == dl_list_last(&wpa_s->bss_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005217 struct wpa_bss, list_id))) {
5218 int res;
5219
5220 res = os_snprintf(buf - 5, end - buf + 5,
5221 "####\n");
5222 if (os_snprintf_error(end - buf + 5, res)) {
5223 wpa_printf(MSG_DEBUG,
5224 "Could not add end delim");
5225 }
5226 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005227 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005228 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005229 next = bss->list_id.next;
5230 if (next == &wpa_s->bss_id)
5231 break;
5232 bss = dl_list_entry(next, struct wpa_bss, list_id);
5233 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005234
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005235 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005236}
5237
5238
5239static int wpa_supplicant_ctrl_iface_ap_scan(
5240 struct wpa_supplicant *wpa_s, char *cmd)
5241{
5242 int ap_scan = atoi(cmd);
5243 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5244}
5245
5246
5247static int wpa_supplicant_ctrl_iface_scan_interval(
5248 struct wpa_supplicant *wpa_s, char *cmd)
5249{
5250 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005251 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005252}
5253
5254
5255static int wpa_supplicant_ctrl_iface_bss_expire_age(
5256 struct wpa_supplicant *wpa_s, char *cmd)
5257{
5258 int expire_age = atoi(cmd);
5259 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5260}
5261
5262
5263static int wpa_supplicant_ctrl_iface_bss_expire_count(
5264 struct wpa_supplicant *wpa_s, char *cmd)
5265{
5266 int expire_count = atoi(cmd);
5267 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5268}
5269
5270
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005271static void wpa_supplicant_ctrl_iface_bss_flush(
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005272 struct wpa_supplicant *wpa_s, char *cmd)
5273{
5274 int flush_age = atoi(cmd);
5275
5276 if (flush_age == 0)
5277 wpa_bss_flush(wpa_s);
5278 else
5279 wpa_bss_flush_by_age(wpa_s, flush_age);
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005280}
5281
5282
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005283#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005284static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5285{
5286 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5287 /* MLME-DELETEKEYS.request */
5288 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
5289 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
5290 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
5291 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005292 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
5293 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005294
5295 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
5296 0);
5297 /* MLME-SETPROTECTION.request(None) */
5298 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5299 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5300 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5301 wpa_sm_drop_sa(wpa_s->wpa);
5302}
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005303#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005304
5305
5306static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5307 char *addr)
5308{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005309#ifdef CONFIG_NO_SCAN_PROCESSING
5310 return -1;
5311#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005312 u8 bssid[ETH_ALEN];
5313 struct wpa_bss *bss;
5314 struct wpa_ssid *ssid = wpa_s->current_ssid;
5315
5316 if (hwaddr_aton(addr, bssid)) {
5317 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5318 "address '%s'", addr);
5319 return -1;
5320 }
5321
5322 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5323
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005324 if (!ssid) {
5325 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5326 "configuration known for the target AP");
5327 return -1;
5328 }
5329
5330 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005331 if (!bss) {
5332 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
5333 "from BSS table");
5334 return -1;
5335 }
5336
5337 /*
5338 * TODO: Find best network configuration block from configuration to
5339 * allow roaming to other networks
5340 */
5341
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005342 wpa_s->reassociate = 1;
5343 wpa_supplicant_connect(wpa_s, bss, ssid);
5344
5345 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005346#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005347}
5348
5349
5350#ifdef CONFIG_P2P
5351static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
5352{
5353 unsigned int timeout = atoi(cmd);
5354 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005355 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005356 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005357 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005358 unsigned int search_delay;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005359 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005360 u8 seek_count = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005361 int freq = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005362
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005363 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5364 wpa_dbg(wpa_s, MSG_INFO,
5365 "Reject P2P_FIND since interface is disabled");
5366 return -1;
5367 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005368 if (os_strstr(cmd, "type=social"))
5369 type = P2P_FIND_ONLY_SOCIAL;
5370 else if (os_strstr(cmd, "type=progressive"))
5371 type = P2P_FIND_PROGRESSIVE;
5372
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005373 pos = os_strstr(cmd, "dev_id=");
5374 if (pos) {
5375 pos += 7;
5376 if (hwaddr_aton(pos, dev_id))
5377 return -1;
5378 _dev_id = dev_id;
5379 }
5380
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005381 pos = os_strstr(cmd, "dev_type=");
5382 if (pos) {
5383 pos += 9;
5384 if (wps_dev_type_str2bin(pos, dev_type) < 0)
5385 return -1;
5386 _dev_type = dev_type;
5387 }
5388
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005389 pos = os_strstr(cmd, "delay=");
5390 if (pos) {
5391 pos += 6;
5392 search_delay = atoi(pos);
5393 } else
5394 search_delay = wpas_p2p_search_delay(wpa_s);
5395
Dmitry Shmidt41712582015-06-29 11:02:15 -07005396 pos = os_strstr(cmd, "freq=");
5397 if (pos) {
5398 pos += 5;
5399 freq = atoi(pos);
5400 if (freq <= 0)
5401 return -1;
5402 }
5403
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005404 /* Must be searched for last, because it adds nul termination */
5405 pos = os_strstr(cmd, " seek=");
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005406 if (pos)
5407 pos += 6;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005408 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
5409 char *term;
5410
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005411 _seek[seek_count++] = pos;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005412 seek = _seek;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005413 term = os_strchr(pos, ' ');
5414 if (!term)
5415 break;
5416 *term = '\0';
5417 pos = os_strstr(term + 1, "seek=");
5418 if (pos)
5419 pos += 5;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005420 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005421 if (seek_count > P2P_MAX_QUERY_HASH) {
5422 seek[0] = NULL;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005423 seek_count = 1;
5424 }
5425
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005426 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005427 _dev_id, search_delay, seek_count, seek, freq);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005428}
5429
5430
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005431static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
5432{
5433 const char *last = NULL;
5434 const char *token;
5435 long int token_len;
5436 unsigned int i;
5437
5438 /* Expected predefined CPT names delimited by ':' */
5439 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
5440 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
5441 wpa_printf(MSG_ERROR,
5442 "P2PS: CPT name list is too long, expected up to %d names",
5443 P2PS_FEATURE_CAPAB_CPT_MAX);
5444 cpt[0] = 0;
5445 return -1;
5446 }
5447
5448 token_len = last - token;
5449
5450 if (token_len == 3 &&
5451 os_memcmp(token, "UDP", token_len) == 0) {
5452 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5453 } else if (token_len == 3 &&
5454 os_memcmp(token, "MAC", token_len) == 0) {
5455 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
5456 } else {
5457 wpa_printf(MSG_ERROR,
5458 "P2PS: Unsupported CPT name '%s'", token);
5459 cpt[0] = 0;
5460 return -1;
5461 }
5462
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005463 if (isblank((unsigned char) *last)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005464 i++;
5465 break;
5466 }
5467 }
5468 cpt[i] = 0;
5469 return 0;
5470}
5471
5472
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005473static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
5474{
5475 struct p2ps_provision *p2ps_prov;
5476 char *pos;
5477 size_t info_len = 0;
5478 char *info = NULL;
5479 u8 role = P2PS_SETUP_NONE;
5480 long long unsigned val;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005481 int i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005482
5483 pos = os_strstr(cmd, "info=");
5484 if (pos) {
5485 pos += 5;
5486 info_len = os_strlen(pos);
5487
5488 if (info_len) {
5489 info = os_malloc(info_len + 1);
5490 if (info) {
5491 info_len = utf8_unescape(pos, info_len,
5492 info, info_len + 1);
5493 } else
5494 info_len = 0;
5495 }
5496 }
5497
5498 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
5499 if (p2ps_prov == NULL) {
5500 os_free(info);
5501 return NULL;
5502 }
5503
5504 if (info) {
5505 os_memcpy(p2ps_prov->info, info, info_len);
5506 p2ps_prov->info[info_len] = '\0';
5507 os_free(info);
5508 }
5509
5510 pos = os_strstr(cmd, "status=");
5511 if (pos)
5512 p2ps_prov->status = atoi(pos + 7);
5513 else
5514 p2ps_prov->status = -1;
5515
5516 pos = os_strstr(cmd, "adv_id=");
5517 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
5518 goto invalid_args;
5519 p2ps_prov->adv_id = val;
5520
5521 pos = os_strstr(cmd, "method=");
5522 if (pos)
5523 p2ps_prov->method = strtol(pos + 7, NULL, 16);
5524 else
5525 p2ps_prov->method = 0;
5526
5527 pos = os_strstr(cmd, "session=");
5528 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
5529 goto invalid_args;
5530 p2ps_prov->session_id = val;
5531
5532 pos = os_strstr(cmd, "adv_mac=");
5533 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
5534 goto invalid_args;
5535
5536 pos = os_strstr(cmd, "session_mac=");
5537 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
5538 goto invalid_args;
5539
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005540 pos = os_strstr(cmd, "cpt=");
5541 if (pos) {
5542 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
5543 p2ps_prov->cpt_priority))
5544 goto invalid_args;
5545 } else {
5546 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5547 }
5548
5549 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
5550 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
5551
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005552 /* force conncap with tstCap (no sanity checks) */
5553 pos = os_strstr(cmd, "tstCap=");
5554 if (pos) {
5555 role = strtol(pos + 7, NULL, 16);
5556 } else {
5557 pos = os_strstr(cmd, "role=");
5558 if (pos) {
5559 role = strtol(pos + 5, NULL, 16);
5560 if (role != P2PS_SETUP_CLIENT &&
5561 role != P2PS_SETUP_GROUP_OWNER)
5562 role = P2PS_SETUP_NONE;
5563 }
5564 }
5565 p2ps_prov->role = role;
5566
5567 return p2ps_prov;
5568
5569invalid_args:
5570 os_free(p2ps_prov);
5571 return NULL;
5572}
5573
5574
5575static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
5576{
5577 u8 addr[ETH_ALEN];
5578 struct p2ps_provision *p2ps_prov;
5579 char *pos;
5580
5581 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5582
5583 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5584
5585 if (hwaddr_aton(cmd, addr))
5586 return -1;
5587
5588 pos = cmd + 17;
5589 if (*pos != ' ')
5590 return -1;
5591
5592 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5593 if (!p2ps_prov)
5594 return -1;
5595
5596 if (p2ps_prov->status < 0) {
5597 os_free(p2ps_prov);
5598 return -1;
5599 }
5600
5601 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5602 p2ps_prov);
5603}
5604
5605
5606static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
5607{
5608 u8 addr[ETH_ALEN];
5609 struct p2ps_provision *p2ps_prov;
5610 char *pos;
5611
5612 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5613 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5614 */
5615
5616 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5617 if (hwaddr_aton(cmd, addr))
5618 return -1;
5619
5620 pos = cmd + 17;
5621 if (*pos != ' ')
5622 return -1;
5623
5624 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5625 if (!p2ps_prov)
5626 return -1;
5627
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005628 p2ps_prov->pd_seeker = 1;
5629
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005630 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5631 p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005632}
5633
5634
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005635static int parse_freq(int chwidth, int freq2)
5636{
5637 if (freq2 < 0)
5638 return -1;
5639 if (freq2)
Hai Shalom81f62d82019-07-22 12:10:00 -07005640 return CHANWIDTH_80P80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005641
5642 switch (chwidth) {
5643 case 0:
5644 case 20:
5645 case 40:
Hai Shalom81f62d82019-07-22 12:10:00 -07005646 return CHANWIDTH_USE_HT;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005647 case 80:
Hai Shalom81f62d82019-07-22 12:10:00 -07005648 return CHANWIDTH_80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005649 case 160:
Hai Shalom81f62d82019-07-22 12:10:00 -07005650 return CHANWIDTH_160MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005651 default:
5652 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
5653 chwidth);
5654 return -1;
5655 }
5656}
5657
5658
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005659static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
5660 char *buf, size_t buflen)
5661{
5662 u8 addr[ETH_ALEN];
5663 char *pos, *pos2;
5664 char *pin = NULL;
5665 enum p2p_wps_method wps_method;
5666 int new_pin;
5667 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005668 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005669 int join;
5670 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005671 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005672 int go_intent = -1;
5673 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005674 int pd;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005675 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005676 int edmg;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005677 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
5678 size_t group_ssid_len = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08005679 int he;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005680
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005681 if (!wpa_s->global->p2p_init_wpa_s)
5682 return -1;
5683 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
5684 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
5685 wpa_s->global->p2p_init_wpa_s->ifname);
5686 wpa_s = wpa_s->global->p2p_init_wpa_s;
5687 }
5688
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005689 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
Dmitry Shmidt04949592012-07-19 12:16:46 -07005690 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005691 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005692 * [ht40] [vht] [he] [edmg] [auto] [ssid=<hexdump>] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005693
5694 if (hwaddr_aton(cmd, addr))
5695 return -1;
5696
5697 pos = cmd + 17;
5698 if (*pos != ' ')
5699 return -1;
5700 pos++;
5701
5702 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005703 pos2 = os_strstr(pos, " persistent=");
5704 if (pos2) {
5705 struct wpa_ssid *ssid;
5706 persistent_id = atoi(pos2 + 12);
5707 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
5708 if (ssid == NULL || ssid->disabled != 2 ||
5709 ssid->mode != WPAS_MODE_P2P_GO) {
5710 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
5711 "SSID id=%d for persistent P2P group (GO)",
5712 persistent_id);
5713 return -1;
5714 }
5715 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005716 join = os_strstr(pos, " join") != NULL;
5717 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005718 automatic = os_strstr(pos, " auto") != NULL;
5719 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005720 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
5721 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
5722 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08005723 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005724 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005725
5726 pos2 = os_strstr(pos, " go_intent=");
5727 if (pos2) {
5728 pos2 += 11;
5729 go_intent = atoi(pos2);
5730 if (go_intent < 0 || go_intent > 15)
5731 return -1;
5732 }
5733
5734 pos2 = os_strstr(pos, " freq=");
5735 if (pos2) {
5736 pos2 += 6;
5737 freq = atoi(pos2);
5738 if (freq <= 0)
5739 return -1;
5740 }
5741
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005742 pos2 = os_strstr(pos, " freq2=");
5743 if (pos2)
5744 freq2 = atoi(pos2 + 7);
5745
5746 pos2 = os_strstr(pos, " max_oper_chwidth=");
5747 if (pos2)
5748 chwidth = atoi(pos2 + 18);
5749
5750 max_oper_chwidth = parse_freq(chwidth, freq2);
5751 if (max_oper_chwidth < 0)
5752 return -1;
5753
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005754 pos2 = os_strstr(pos, " ssid=");
5755 if (pos2) {
5756 char *end;
5757
5758 pos2 += 6;
5759 end = os_strchr(pos2, ' ');
5760 if (!end)
5761 group_ssid_len = os_strlen(pos2) / 2;
5762 else
5763 group_ssid_len = (end - pos2) / 2;
5764 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
5765 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
5766 return -1;
5767 group_ssid = _group_ssid;
5768 }
5769
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005770 if (os_strncmp(pos, "pin", 3) == 0) {
5771 /* Request random PIN (to be displayed) and enable the PIN */
5772 wps_method = WPS_PIN_DISPLAY;
5773 } else if (os_strncmp(pos, "pbc", 3) == 0) {
5774 wps_method = WPS_PBC;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005775 } else if (os_strstr(pos, "p2ps") != NULL) {
5776 wps_method = WPS_P2PS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005777 } else {
5778 pin = pos;
5779 pos = os_strchr(pin, ' ');
5780 wps_method = WPS_PIN_KEYPAD;
5781 if (pos) {
5782 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005783 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005784 wps_method = WPS_PIN_DISPLAY;
5785 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005786 if (!wps_pin_str_valid(pin)) {
5787 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
5788 return 17;
5789 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005790 }
5791
5792 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005793 persistent_group, automatic, join,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005794 auth, go_intent, freq, freq2, persistent_id,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005795 pd, ht40, vht, max_oper_chwidth, he, edmg,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005796 group_ssid, group_ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005797 if (new_pin == -2) {
5798 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5799 return 25;
5800 }
5801 if (new_pin == -3) {
5802 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5803 return 25;
5804 }
5805 if (new_pin < 0)
5806 return -1;
5807 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
5808 ret = os_snprintf(buf, buflen, "%08d", new_pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005809 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005810 return -1;
5811 return ret;
5812 }
5813
5814 os_memcpy(buf, "OK\n", 3);
5815 return 3;
5816}
5817
5818
5819static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
5820{
5821 unsigned int timeout = atoi(cmd);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005822 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5823 wpa_dbg(wpa_s, MSG_INFO,
5824 "Reject P2P_LISTEN since interface is disabled");
5825 return -1;
5826 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005827 return wpas_p2p_listen(wpa_s, timeout);
5828}
5829
5830
5831static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
5832{
5833 u8 addr[ETH_ALEN];
5834 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005835 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005836
Dmitry Shmidt04949592012-07-19 12:16:46 -07005837 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005838
5839 if (hwaddr_aton(cmd, addr))
5840 return -1;
5841
5842 pos = cmd + 17;
5843 if (*pos != ' ')
5844 return -1;
5845 pos++;
5846
Dmitry Shmidt04949592012-07-19 12:16:46 -07005847 if (os_strstr(pos, " join") != NULL)
5848 use = WPAS_P2P_PD_FOR_JOIN;
5849 else if (os_strstr(pos, " auto") != NULL)
5850 use = WPAS_P2P_PD_AUTO;
5851
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005852 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005853}
5854
5855
5856static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
5857 size_t buflen)
5858{
5859 struct wpa_ssid *ssid = wpa_s->current_ssid;
5860
5861 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
5862 ssid->passphrase == NULL)
5863 return -1;
5864
5865 os_strlcpy(buf, ssid->passphrase, buflen);
5866 return os_strlen(buf);
5867}
5868
5869
5870static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
5871 char *buf, size_t buflen)
5872{
5873 u64 ref;
5874 int res;
5875 u8 dst_buf[ETH_ALEN], *dst;
5876 struct wpabuf *tlvs;
5877 char *pos;
5878 size_t len;
5879
5880 if (hwaddr_aton(cmd, dst_buf))
5881 return -1;
5882 dst = dst_buf;
5883 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
5884 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
5885 dst = NULL;
5886 pos = cmd + 17;
5887 if (*pos != ' ')
5888 return -1;
5889 pos++;
5890
5891 if (os_strncmp(pos, "upnp ", 5) == 0) {
5892 u8 version;
5893 pos += 5;
5894 if (hexstr2bin(pos, &version, 1) < 0)
5895 return -1;
5896 pos += 2;
5897 if (*pos != ' ')
5898 return -1;
5899 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005900 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005901#ifdef CONFIG_WIFI_DISPLAY
5902 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
5903 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
5904#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005905 } else if (os_strncmp(pos, "asp ", 4) == 0) {
5906 char *svc_str;
5907 char *svc_info = NULL;
5908 u32 id;
5909
5910 pos += 4;
5911 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
5912 return -1;
5913
5914 pos = os_strchr(pos, ' ');
5915 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
5916 return -1;
5917
5918 svc_str = pos + 1;
5919
5920 pos = os_strchr(svc_str, ' ');
5921
5922 if (pos)
5923 *pos++ = '\0';
5924
5925 /* All remaining data is the svc_info string */
5926 if (pos && pos[0] && pos[0] != ' ') {
5927 len = os_strlen(pos);
5928
5929 /* Unescape in place */
5930 len = utf8_unescape(pos, len, pos, len);
5931 if (len > 0xff)
5932 return -1;
5933
5934 svc_info = pos;
5935 }
5936
5937 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
5938 svc_str, svc_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005939 } else {
5940 len = os_strlen(pos);
5941 if (len & 1)
5942 return -1;
5943 len /= 2;
5944 tlvs = wpabuf_alloc(len);
5945 if (tlvs == NULL)
5946 return -1;
5947 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
5948 wpabuf_free(tlvs);
5949 return -1;
5950 }
5951
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005952 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005953 wpabuf_free(tlvs);
5954 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005955 if (ref == 0)
5956 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005957 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005958 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005959 return -1;
5960 return res;
5961}
5962
5963
5964static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
5965 char *cmd)
5966{
5967 long long unsigned val;
5968 u64 req;
5969 if (sscanf(cmd, "%llx", &val) != 1)
5970 return -1;
5971 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005972 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005973}
5974
5975
5976static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
5977{
5978 int freq;
5979 u8 dst[ETH_ALEN];
5980 u8 dialog_token;
5981 struct wpabuf *resp_tlvs;
5982 char *pos, *pos2;
5983 size_t len;
5984
5985 pos = os_strchr(cmd, ' ');
5986 if (pos == NULL)
5987 return -1;
5988 *pos++ = '\0';
5989 freq = atoi(cmd);
5990 if (freq == 0)
5991 return -1;
5992
5993 if (hwaddr_aton(pos, dst))
5994 return -1;
5995 pos += 17;
5996 if (*pos != ' ')
5997 return -1;
5998 pos++;
5999
6000 pos2 = os_strchr(pos, ' ');
6001 if (pos2 == NULL)
6002 return -1;
6003 *pos2++ = '\0';
6004 dialog_token = atoi(pos);
6005
6006 len = os_strlen(pos2);
6007 if (len & 1)
6008 return -1;
6009 len /= 2;
6010 resp_tlvs = wpabuf_alloc(len);
6011 if (resp_tlvs == NULL)
6012 return -1;
6013 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
6014 wpabuf_free(resp_tlvs);
6015 return -1;
6016 }
6017
6018 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
6019 wpabuf_free(resp_tlvs);
6020 return 0;
6021}
6022
6023
6024static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
6025 char *cmd)
6026{
Dmitry Shmidt04949592012-07-19 12:16:46 -07006027 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
6028 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006029 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
6030 return 0;
6031}
6032
6033
6034static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
6035 char *cmd)
6036{
6037 char *pos;
6038 size_t len;
6039 struct wpabuf *query, *resp;
6040
6041 pos = os_strchr(cmd, ' ');
6042 if (pos == NULL)
6043 return -1;
6044 *pos++ = '\0';
6045
6046 len = os_strlen(cmd);
6047 if (len & 1)
6048 return -1;
6049 len /= 2;
6050 query = wpabuf_alloc(len);
6051 if (query == NULL)
6052 return -1;
6053 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6054 wpabuf_free(query);
6055 return -1;
6056 }
6057
6058 len = os_strlen(pos);
6059 if (len & 1) {
6060 wpabuf_free(query);
6061 return -1;
6062 }
6063 len /= 2;
6064 resp = wpabuf_alloc(len);
6065 if (resp == NULL) {
6066 wpabuf_free(query);
6067 return -1;
6068 }
6069 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
6070 wpabuf_free(query);
6071 wpabuf_free(resp);
6072 return -1;
6073 }
6074
6075 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
6076 wpabuf_free(query);
6077 wpabuf_free(resp);
6078 return -1;
6079 }
6080 return 0;
6081}
6082
6083
6084static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6085{
6086 char *pos;
6087 u8 version;
6088
6089 pos = os_strchr(cmd, ' ');
6090 if (pos == NULL)
6091 return -1;
6092 *pos++ = '\0';
6093
6094 if (hexstr2bin(cmd, &version, 1) < 0)
6095 return -1;
6096
6097 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
6098}
6099
6100
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006101static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
6102 u8 replace, char *cmd)
6103{
6104 char *pos;
6105 char *adv_str;
6106 u32 auto_accept, adv_id, svc_state, config_methods;
6107 char *svc_info = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006108 char *cpt_prio_str;
6109 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006110
6111 pos = os_strchr(cmd, ' ');
6112 if (pos == NULL)
6113 return -1;
6114 *pos++ = '\0';
6115
6116 /* Auto-Accept value is mandatory, and must be one of the
6117 * single values (0, 1, 2, 4) */
6118 auto_accept = atoi(cmd);
6119 switch (auto_accept) {
6120 case P2PS_SETUP_NONE: /* No auto-accept */
6121 case P2PS_SETUP_NEW:
6122 case P2PS_SETUP_CLIENT:
6123 case P2PS_SETUP_GROUP_OWNER:
6124 break;
6125 default:
6126 return -1;
6127 }
6128
6129 /* Advertisement ID is mandatory */
6130 cmd = pos;
6131 pos = os_strchr(cmd, ' ');
6132 if (pos == NULL)
6133 return -1;
6134 *pos++ = '\0';
6135
6136 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6137 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
6138 return -1;
6139
6140 /* Only allow replacements if exist, and adds if not */
6141 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
6142 if (!replace)
6143 return -1;
6144 } else {
6145 if (replace)
6146 return -1;
6147 }
6148
6149 /* svc_state between 0 - 0xff is mandatory */
6150 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
6151 return -1;
6152
6153 pos = os_strchr(pos, ' ');
6154 if (pos == NULL)
6155 return -1;
6156
6157 /* config_methods is mandatory */
6158 pos++;
6159 if (sscanf(pos, "%x", &config_methods) != 1)
6160 return -1;
6161
6162 if (!(config_methods &
6163 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
6164 return -1;
6165
6166 pos = os_strchr(pos, ' ');
6167 if (pos == NULL)
6168 return -1;
6169
6170 pos++;
6171 adv_str = pos;
6172
6173 /* Advertisement string is mandatory */
6174 if (!pos[0] || pos[0] == ' ')
6175 return -1;
6176
6177 /* Terminate svc string */
6178 pos = os_strchr(pos, ' ');
6179 if (pos != NULL)
6180 *pos++ = '\0';
6181
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006182 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6183 if (cpt_prio_str) {
6184 pos = os_strchr(pos, ' ');
6185 if (pos != NULL)
6186 *pos++ = '\0';
6187
6188 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6189 return -1;
6190 } else {
6191 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6192 cpt_prio[1] = 0;
6193 }
6194
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006195 /* Service and Response Information are optional */
6196 if (pos && pos[0]) {
6197 size_t len;
6198
6199 /* Note the bare ' included, which cannot exist legally
6200 * in unescaped string. */
6201 svc_info = os_strstr(pos, "svc_info='");
6202
6203 if (svc_info) {
6204 svc_info += 9;
6205 len = os_strlen(svc_info);
6206 utf8_unescape(svc_info, len, svc_info, len);
6207 }
6208 }
6209
6210 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6211 (u8) svc_state, (u16) config_methods,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006212 svc_info, cpt_prio);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006213}
6214
6215
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006216static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6217{
6218 char *pos;
6219
6220 pos = os_strchr(cmd, ' ');
6221 if (pos == NULL)
6222 return -1;
6223 *pos++ = '\0';
6224
6225 if (os_strcmp(cmd, "bonjour") == 0)
6226 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6227 if (os_strcmp(cmd, "upnp") == 0)
6228 return p2p_ctrl_service_add_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006229 if (os_strcmp(cmd, "asp") == 0)
6230 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006231 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6232 return -1;
6233}
6234
6235
6236static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6237 char *cmd)
6238{
6239 size_t len;
6240 struct wpabuf *query;
6241 int ret;
6242
6243 len = os_strlen(cmd);
6244 if (len & 1)
6245 return -1;
6246 len /= 2;
6247 query = wpabuf_alloc(len);
6248 if (query == NULL)
6249 return -1;
6250 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6251 wpabuf_free(query);
6252 return -1;
6253 }
6254
6255 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6256 wpabuf_free(query);
6257 return ret;
6258}
6259
6260
6261static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6262{
6263 char *pos;
6264 u8 version;
6265
6266 pos = os_strchr(cmd, ' ');
6267 if (pos == NULL)
6268 return -1;
6269 *pos++ = '\0';
6270
6271 if (hexstr2bin(cmd, &version, 1) < 0)
6272 return -1;
6273
6274 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6275}
6276
6277
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006278static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6279{
6280 u32 adv_id;
6281
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07006282 if (os_strcmp(cmd, "all") == 0) {
6283 wpas_p2p_service_flush_asp(wpa_s);
6284 return 0;
6285 }
6286
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006287 if (sscanf(cmd, "%x", &adv_id) != 1)
6288 return -1;
6289
6290 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6291}
6292
6293
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006294static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6295{
6296 char *pos;
6297
6298 pos = os_strchr(cmd, ' ');
6299 if (pos == NULL)
6300 return -1;
6301 *pos++ = '\0';
6302
6303 if (os_strcmp(cmd, "bonjour") == 0)
6304 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6305 if (os_strcmp(cmd, "upnp") == 0)
6306 return p2p_ctrl_service_del_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006307 if (os_strcmp(cmd, "asp") == 0)
6308 return p2p_ctrl_service_del_asp(wpa_s, pos);
6309 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6310 return -1;
6311}
6312
6313
6314static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6315{
6316 char *pos;
6317
6318 pos = os_strchr(cmd, ' ');
6319 if (pos == NULL)
6320 return -1;
6321 *pos++ = '\0';
6322
6323 if (os_strcmp(cmd, "asp") == 0)
6324 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6325
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006326 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6327 return -1;
6328}
6329
6330
6331static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
6332{
6333 u8 addr[ETH_ALEN];
6334
6335 /* <addr> */
6336
6337 if (hwaddr_aton(cmd, addr))
6338 return -1;
6339
6340 return wpas_p2p_reject(wpa_s, addr);
6341}
6342
6343
6344static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
6345{
6346 char *pos;
6347 int id;
6348 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006349 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006350 int freq = 0, pref_freq = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -08006351 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006352 int edmg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006353
6354 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006355 pos = os_strstr(cmd, " peer=");
6356 if (pos) {
6357 pos += 6;
6358 if (hwaddr_aton(pos, peer))
6359 return -1;
6360 _peer = peer;
6361 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006362 ssid = wpa_config_get_network(wpa_s->conf, id);
6363 if (ssid == NULL || ssid->disabled != 2) {
6364 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6365 "for persistent P2P group",
6366 id);
6367 return -1;
6368 }
6369
Jouni Malinen31be0a42012-08-31 21:20:51 +03006370 pos = os_strstr(cmd, " freq=");
6371 if (pos) {
6372 pos += 6;
6373 freq = atoi(pos);
6374 if (freq <= 0)
6375 return -1;
6376 }
6377
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006378 pos = os_strstr(cmd, " pref=");
6379 if (pos) {
6380 pos += 6;
6381 pref_freq = atoi(pos);
6382 if (pref_freq <= 0)
6383 return -1;
6384 }
6385
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006386 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6387 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6388 vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006389 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006390 edmg = (os_strstr(cmd, " edmg") != NULL) || wpa_s->conf->p2p_go_edmg;
Jouni Malinen31be0a42012-08-31 21:20:51 +03006391
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006392 pos = os_strstr(cmd, "freq2=");
6393 if (pos)
6394 freq2 = atoi(pos + 6);
6395
6396 pos = os_strstr(cmd, " max_oper_chwidth=");
6397 if (pos)
6398 chwidth = atoi(pos + 18);
6399
6400 max_oper_chwidth = parse_freq(chwidth, freq2);
6401 if (max_oper_chwidth < 0)
6402 return -1;
6403
6404 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006405 max_oper_chwidth, pref_freq, he, edmg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006406}
6407
6408
6409static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
6410{
6411 char *pos;
6412 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
6413
6414 pos = os_strstr(cmd, " peer=");
6415 if (!pos)
6416 return -1;
6417
6418 *pos = '\0';
6419 pos += 6;
6420 if (hwaddr_aton(pos, peer)) {
6421 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
6422 return -1;
6423 }
6424
6425 pos = os_strstr(pos, " go_dev_addr=");
6426 if (pos) {
6427 pos += 13;
6428 if (hwaddr_aton(pos, go_dev_addr)) {
6429 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
6430 pos);
6431 return -1;
6432 }
6433 go_dev = go_dev_addr;
6434 }
6435
6436 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
6437}
6438
6439
6440static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
6441{
6442 if (os_strncmp(cmd, "persistent=", 11) == 0)
6443 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
6444 if (os_strncmp(cmd, "group=", 6) == 0)
6445 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
6446
6447 return -1;
6448}
6449
6450
6451static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006452 int id, int freq, int vht_center_freq2,
Hai Shalom74f70d42019-02-11 14:42:39 -08006453 int ht40, int vht, int vht_chwidth,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006454 int he, int edmg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006455{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006456 struct wpa_ssid *ssid;
6457
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006458 ssid = wpa_config_get_network(wpa_s->conf, id);
6459 if (ssid == NULL || ssid->disabled != 2) {
6460 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6461 "for persistent P2P group",
6462 id);
6463 return -1;
6464 }
6465
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006466 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
6467 vht_center_freq2, 0, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006468 vht_chwidth, he, edmg,
6469 NULL, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006470}
6471
6472
6473static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
6474{
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006475 int freq = 0, persistent = 0, group_id = -1;
6476 int vht = wpa_s->conf->p2p_go_vht;
6477 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
Hai Shalom74f70d42019-02-11 14:42:39 -08006478 int he = wpa_s->conf->p2p_go_he;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006479 int edmg = wpa_s->conf->p2p_go_edmg;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006480 int max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006481 char *token, *context = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006482#ifdef CONFIG_ACS
6483 int acs = 0;
6484#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006485
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006486 while ((token = str_token(cmd, " ", &context))) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07006487 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006488 sscanf(token, "persistent=%d", &group_id) == 1 ||
6489 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006490 continue;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006491#ifdef CONFIG_ACS
6492 } else if (os_strcmp(token, "freq=acs") == 0) {
6493 acs = 1;
6494#endif /* CONFIG_ACS */
6495 } else if (sscanf(token, "freq=%d", &freq) == 1) {
6496 continue;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006497 } else if (os_strcmp(token, "ht40") == 0) {
6498 ht40 = 1;
6499 } else if (os_strcmp(token, "vht") == 0) {
6500 vht = 1;
6501 ht40 = 1;
Hai Shalom74f70d42019-02-11 14:42:39 -08006502 } else if (os_strcmp(token, "he") == 0) {
6503 he = 1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006504 } else if (os_strcmp(token, "edmg") == 0) {
6505 edmg = 1;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006506 } else if (os_strcmp(token, "persistent") == 0) {
6507 persistent = 1;
6508 } else {
6509 wpa_printf(MSG_DEBUG,
6510 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6511 token);
6512 return -1;
6513 }
6514 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006515
Roshan Pius3a1667e2018-07-03 15:17:14 -07006516#ifdef CONFIG_ACS
6517 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
6518 (acs || freq == 2 || freq == 5)) {
6519 if (freq == 2 && wpa_s->best_24_freq <= 0) {
6520 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
6521 wpa_s->p2p_go_do_acs = 1;
6522 freq = 0;
6523 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
6524 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
6525 wpa_s->p2p_go_do_acs = 1;
6526 freq = 0;
6527 } else {
6528 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
6529 wpa_s->p2p_go_do_acs = 1;
6530 }
Hai Shalom021b0b52019-04-10 11:17:58 -07006531 } else {
6532 wpa_s->p2p_go_do_acs = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006533 }
6534#endif /* CONFIG_ACS */
6535
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006536 max_oper_chwidth = parse_freq(chwidth, freq2);
6537 if (max_oper_chwidth < 0)
6538 return -1;
6539
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006540 if (group_id >= 0)
6541 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006542 freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006543 max_oper_chwidth, he,
6544 edmg);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006545
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006546 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08006547 max_oper_chwidth, he, edmg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006548}
6549
6550
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006551static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
6552 char *buf, size_t buflen)
6553{
6554 u8 dev_addr[ETH_ALEN];
6555 struct wpa_ssid *ssid;
6556 int res;
6557 const u8 *iaddr;
6558
6559 ssid = wpa_s->current_ssid;
6560 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
6561 hwaddr_aton(cmd, dev_addr))
6562 return -1;
6563
6564 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
6565 if (!iaddr)
6566 return -1;
6567 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
6568 if (os_snprintf_error(buflen, res))
6569 return -1;
6570 return res;
6571}
6572
6573
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006574static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
6575 const u8 *p2p_dev_addr)
6576{
6577 struct wpa_supplicant *wpa_s;
6578
6579 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6580 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
6581 return 1;
6582 }
6583
6584 return 0;
6585}
6586
6587
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006588static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
6589 char *buf, size_t buflen)
6590{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006591 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006592 int next, res;
6593 const struct p2p_peer_info *info;
6594 char *pos, *end;
6595 char devtype[WPS_DEV_TYPE_BUFSIZE];
6596 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006597 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006598
6599 if (!wpa_s->global->p2p)
6600 return -1;
6601
6602 if (os_strcmp(cmd, "FIRST") == 0) {
6603 addr_ptr = NULL;
6604 next = 0;
6605 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
6606 if (hwaddr_aton(cmd + 5, addr) < 0)
6607 return -1;
6608 addr_ptr = addr;
6609 next = 1;
6610 } else {
6611 if (hwaddr_aton(cmd, addr) < 0)
6612 return -1;
6613 addr_ptr = addr;
6614 next = 0;
6615 }
6616
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006617 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
6618 if (info == NULL)
6619 return -1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006620 group_capab = info->group_capab;
6621
6622 if (group_capab &&
6623 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
6624 wpa_printf(MSG_DEBUG,
6625 "P2P: Could not find any BSS with p2p_dev_addr "
6626 MACSTR ", hence override group_capab from 0x%x to 0",
6627 MAC2STR(info->p2p_device_addr), group_capab);
6628 group_capab = 0;
6629 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006630
6631 pos = buf;
6632 end = buf + buflen;
6633
6634 res = os_snprintf(pos, end - pos, MACSTR "\n"
6635 "pri_dev_type=%s\n"
6636 "device_name=%s\n"
6637 "manufacturer=%s\n"
6638 "model_name=%s\n"
6639 "model_number=%s\n"
6640 "serial_number=%s\n"
6641 "config_methods=0x%x\n"
6642 "dev_capab=0x%x\n"
6643 "group_capab=0x%x\n"
6644 "level=%d\n",
6645 MAC2STR(info->p2p_device_addr),
6646 wps_dev_type_bin2str(info->pri_dev_type,
6647 devtype, sizeof(devtype)),
6648 info->device_name,
6649 info->manufacturer,
6650 info->model_name,
6651 info->model_number,
6652 info->serial_number,
6653 info->config_methods,
6654 info->dev_capab,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006655 group_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006656 info->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006657 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006658 return pos - buf;
6659 pos += res;
6660
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006661 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
6662 {
6663 const u8 *t;
6664 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
6665 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
6666 wps_dev_type_bin2str(t, devtype,
6667 sizeof(devtype)));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006668 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006669 return pos - buf;
6670 pos += res;
6671 }
6672
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006673 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006674 if (ssid) {
6675 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006676 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006677 return pos - buf;
6678 pos += res;
6679 }
6680
6681 res = p2p_get_peer_info_txt(info, pos, end - pos);
6682 if (res < 0)
6683 return pos - buf;
6684 pos += res;
6685
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006686 if (info->vendor_elems) {
6687 res = os_snprintf(pos, end - pos, "vendor_elems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006688 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006689 return pos - buf;
6690 pos += res;
6691
6692 pos += wpa_snprintf_hex(pos, end - pos,
6693 wpabuf_head(info->vendor_elems),
6694 wpabuf_len(info->vendor_elems));
6695
6696 res = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006697 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006698 return pos - buf;
6699 pos += res;
6700 }
6701
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006702 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006703}
6704
6705
Dmitry Shmidt04949592012-07-19 12:16:46 -07006706static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
6707 const char *param)
6708{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006709 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006710
6711 if (wpa_s->global->p2p == NULL)
6712 return -1;
6713
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006714 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
6715 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006716
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006717 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
6718 struct wpa_freq_range *freq;
6719 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07006720 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006721 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006722 }
6723
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006724 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006725 return 0;
6726}
6727
6728
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006729static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
6730{
6731 char *param;
6732
6733 if (wpa_s->global->p2p == NULL)
6734 return -1;
6735
6736 param = os_strchr(cmd, ' ');
6737 if (param == NULL)
6738 return -1;
6739 *param++ = '\0';
6740
6741 if (os_strcmp(cmd, "discoverability") == 0) {
6742 p2p_set_client_discoverability(wpa_s->global->p2p,
6743 atoi(param));
6744 return 0;
6745 }
6746
6747 if (os_strcmp(cmd, "managed") == 0) {
6748 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
6749 return 0;
6750 }
6751
6752 if (os_strcmp(cmd, "listen_channel") == 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08006753 char *pos;
6754 u8 channel, op_class;
6755
6756 channel = atoi(param);
6757 pos = os_strchr(param, ' ');
6758 op_class = pos ? atoi(pos) : 81;
6759
6760 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
6761 channel, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006762 }
6763
6764 if (os_strcmp(cmd, "ssid_postfix") == 0) {
6765 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
6766 os_strlen(param));
6767 }
6768
6769 if (os_strcmp(cmd, "noa") == 0) {
6770 char *pos;
6771 int count, start, duration;
6772 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6773 count = atoi(param);
6774 pos = os_strchr(param, ',');
6775 if (pos == NULL)
6776 return -1;
6777 pos++;
6778 start = atoi(pos);
6779 pos = os_strchr(pos, ',');
6780 if (pos == NULL)
6781 return -1;
6782 pos++;
6783 duration = atoi(pos);
6784 if (count < 0 || count > 255 || start < 0 || duration < 0)
6785 return -1;
6786 if (count == 0 && duration > 0)
6787 return -1;
6788 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6789 "start=%d duration=%d", count, start, duration);
6790 return wpas_p2p_set_noa(wpa_s, count, start, duration);
6791 }
6792
6793 if (os_strcmp(cmd, "ps") == 0)
6794 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
6795
6796 if (os_strcmp(cmd, "oppps") == 0)
6797 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
6798
6799 if (os_strcmp(cmd, "ctwindow") == 0)
6800 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
6801
6802 if (os_strcmp(cmd, "disabled") == 0) {
6803 wpa_s->global->p2p_disabled = atoi(param);
6804 wpa_printf(MSG_DEBUG, "P2P functionality %s",
6805 wpa_s->global->p2p_disabled ?
6806 "disabled" : "enabled");
6807 if (wpa_s->global->p2p_disabled) {
6808 wpas_p2p_stop_find(wpa_s);
6809 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6810 p2p_flush(wpa_s->global->p2p);
6811 }
6812 return 0;
6813 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006814
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006815 if (os_strcmp(cmd, "conc_pref") == 0) {
6816 if (os_strcmp(param, "sta") == 0)
6817 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
6818 else if (os_strcmp(param, "p2p") == 0)
6819 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006820 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006821 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006822 return -1;
6823 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006824 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07006825 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006826 return 0;
6827 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006828
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006829 if (os_strcmp(cmd, "force_long_sd") == 0) {
6830 wpa_s->force_long_sd = atoi(param);
6831 return 0;
6832 }
6833
6834 if (os_strcmp(cmd, "peer_filter") == 0) {
6835 u8 addr[ETH_ALEN];
6836 if (hwaddr_aton(param, addr))
6837 return -1;
6838 p2p_set_peer_filter(wpa_s->global->p2p, addr);
6839 return 0;
6840 }
6841
6842 if (os_strcmp(cmd, "cross_connect") == 0)
6843 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
6844
6845 if (os_strcmp(cmd, "go_apsd") == 0) {
6846 if (os_strcmp(param, "disable") == 0)
6847 wpa_s->set_ap_uapsd = 0;
6848 else {
6849 wpa_s->set_ap_uapsd = 1;
6850 wpa_s->ap_uapsd = atoi(param);
6851 }
6852 return 0;
6853 }
6854
6855 if (os_strcmp(cmd, "client_apsd") == 0) {
6856 if (os_strcmp(param, "disable") == 0)
6857 wpa_s->set_sta_uapsd = 0;
6858 else {
6859 int be, bk, vi, vo;
6860 char *pos;
6861 /* format: BE,BK,VI,VO;max SP Length */
6862 be = atoi(param);
6863 pos = os_strchr(param, ',');
6864 if (pos == NULL)
6865 return -1;
6866 pos++;
6867 bk = atoi(pos);
6868 pos = os_strchr(pos, ',');
6869 if (pos == NULL)
6870 return -1;
6871 pos++;
6872 vi = atoi(pos);
6873 pos = os_strchr(pos, ',');
6874 if (pos == NULL)
6875 return -1;
6876 pos++;
6877 vo = atoi(pos);
6878 /* ignore max SP Length for now */
6879
6880 wpa_s->set_sta_uapsd = 1;
6881 wpa_s->sta_uapsd = 0;
6882 if (be)
6883 wpa_s->sta_uapsd |= BIT(0);
6884 if (bk)
6885 wpa_s->sta_uapsd |= BIT(1);
6886 if (vi)
6887 wpa_s->sta_uapsd |= BIT(2);
6888 if (vo)
6889 wpa_s->sta_uapsd |= BIT(3);
6890 }
6891 return 0;
6892 }
6893
Dmitry Shmidt04949592012-07-19 12:16:46 -07006894 if (os_strcmp(cmd, "disallow_freq") == 0)
6895 return p2p_ctrl_disallow_freq(wpa_s, param);
6896
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006897 if (os_strcmp(cmd, "disc_int") == 0) {
6898 int min_disc_int, max_disc_int, max_disc_tu;
6899 char *pos;
6900
6901 pos = param;
6902
6903 min_disc_int = atoi(pos);
6904 pos = os_strchr(pos, ' ');
6905 if (pos == NULL)
6906 return -1;
6907 *pos++ = '\0';
6908
6909 max_disc_int = atoi(pos);
6910 pos = os_strchr(pos, ' ');
6911 if (pos == NULL)
6912 return -1;
6913 *pos++ = '\0';
6914
6915 max_disc_tu = atoi(pos);
6916
6917 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
6918 max_disc_int, max_disc_tu);
6919 }
6920
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07006921 if (os_strcmp(cmd, "per_sta_psk") == 0) {
6922 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
6923 return 0;
6924 }
6925
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006926#ifdef CONFIG_WPS_NFC
6927 if (os_strcmp(cmd, "nfc_tag") == 0)
6928 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
6929#endif /* CONFIG_WPS_NFC */
6930
6931 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
6932 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
6933 return 0;
6934 }
6935
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006936 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
6937 int op_class, chan;
6938
6939 op_class = atoi(param);
6940 param = os_strchr(param, ':');
6941 if (!param)
6942 return -1;
6943 param++;
6944 chan = atoi(param);
6945 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
6946 chan);
6947 return 0;
6948 }
6949
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006950 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6951 cmd);
6952
6953 return -1;
6954}
6955
6956
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006957static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
6958{
6959 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6960 wpa_s->force_long_sd = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006961
6962#ifdef CONFIG_TESTING_OPTIONS
6963 os_free(wpa_s->get_pref_freq_list_override);
6964 wpa_s->get_pref_freq_list_override = NULL;
6965#endif /* CONFIG_TESTING_OPTIONS */
6966
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006967 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006968 wpa_s->parent->p2ps_method_config_any = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006969 if (wpa_s->global->p2p)
6970 p2p_flush(wpa_s->global->p2p);
6971}
6972
6973
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006974static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
6975{
6976 char *pos, *pos2;
6977 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
6978
6979 if (cmd[0]) {
6980 pos = os_strchr(cmd, ' ');
6981 if (pos == NULL)
6982 return -1;
6983 *pos++ = '\0';
6984 dur1 = atoi(cmd);
6985
6986 pos2 = os_strchr(pos, ' ');
6987 if (pos2)
6988 *pos2++ = '\0';
6989 int1 = atoi(pos);
6990 } else
6991 pos2 = NULL;
6992
6993 if (pos2) {
6994 pos = os_strchr(pos2, ' ');
6995 if (pos == NULL)
6996 return -1;
6997 *pos++ = '\0';
6998 dur2 = atoi(pos2);
6999 int2 = atoi(pos);
7000 }
7001
7002 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
7003}
7004
7005
7006static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
7007{
7008 char *pos;
7009 unsigned int period = 0, interval = 0;
7010
7011 if (cmd[0]) {
7012 pos = os_strchr(cmd, ' ');
7013 if (pos == NULL)
7014 return -1;
7015 *pos++ = '\0';
7016 period = atoi(cmd);
7017 interval = atoi(pos);
7018 }
7019
7020 return wpas_p2p_ext_listen(wpa_s, period, interval);
7021}
7022
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07007023
7024static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
7025{
7026 const char *pos;
7027 u8 peer[ETH_ALEN];
7028 int iface_addr = 0;
7029
7030 pos = cmd;
7031 if (os_strncmp(pos, "iface=", 6) == 0) {
7032 iface_addr = 1;
7033 pos += 6;
7034 }
7035 if (hwaddr_aton(pos, peer))
7036 return -1;
7037
7038 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
7039 return 0;
7040}
7041
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007042
7043static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
7044{
7045 int freq = 0, period = 0, interval = 0, count = 0;
7046
7047 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
7048 {
7049 wpa_printf(MSG_DEBUG,
7050 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
7051 return -1;
7052 }
7053
7054 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
7055}
7056
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007057#endif /* CONFIG_P2P */
7058
7059
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007060static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
7061{
7062 struct wpa_freq_range_list ranges;
7063 int *freqs = NULL;
7064 struct hostapd_hw_modes *mode;
7065 u16 i;
7066
7067 if (wpa_s->hw.modes == NULL)
7068 return NULL;
7069
7070 os_memset(&ranges, 0, sizeof(ranges));
7071 if (freq_range_list_parse(&ranges, val) < 0)
7072 return NULL;
7073
7074 for (i = 0; i < wpa_s->hw.num_modes; i++) {
7075 int j;
7076
7077 mode = &wpa_s->hw.modes[i];
7078 for (j = 0; j < mode->num_channels; j++) {
7079 unsigned int freq;
7080
7081 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
7082 continue;
7083
7084 freq = mode->channels[j].freq;
7085 if (!freq_range_list_includes(&ranges, freq))
7086 continue;
7087
7088 int_array_add_unique(&freqs, freq);
7089 }
7090 }
7091
7092 os_free(ranges.range);
7093 return freqs;
7094}
7095
7096
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007097#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007098
7099static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
7100{
7101 int auto_sel = 0;
7102 int *freqs = NULL;
7103
7104 if (param) {
7105 char *pos;
7106
7107 auto_sel = os_strstr(param, "auto") != NULL;
7108
7109 pos = os_strstr(param, "freq=");
7110 if (pos) {
7111 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
7112 if (freqs == NULL)
7113 return -1;
7114 }
7115
7116 }
7117
7118 return interworking_select(wpa_s, auto_sel, freqs);
7119}
7120
7121
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007122static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
7123 int only_add)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007124{
7125 u8 bssid[ETH_ALEN];
7126 struct wpa_bss *bss;
7127
7128 if (hwaddr_aton(dst, bssid)) {
7129 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
7130 return -1;
7131 }
7132
7133 bss = wpa_bss_get_bssid(wpa_s, bssid);
7134 if (bss == NULL) {
7135 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
7136 MAC2STR(bssid));
7137 return -1;
7138 }
7139
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007140 if (bss->ssid_len == 0) {
7141 int found = 0;
7142
7143 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
7144 " does not have SSID information", MAC2STR(bssid));
7145
7146 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
7147 list) {
7148 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
7149 bss->ssid_len > 0) {
7150 found = 1;
7151 break;
7152 }
7153 }
7154
7155 if (!found)
7156 return -1;
7157 wpa_printf(MSG_DEBUG,
7158 "Found another matching BSS entry with SSID");
7159 }
7160
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007161 return interworking_connect(wpa_s, bss, only_add);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007162}
7163
7164
7165static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
7166{
7167 u8 dst_addr[ETH_ALEN];
7168 int used;
7169 char *pos;
7170#define MAX_ANQP_INFO_ID 100
7171 u16 id[MAX_ANQP_INFO_ID];
7172 size_t num_id = 0;
Dmitry Shmidt15907092014-03-25 10:42:57 -07007173 u32 subtypes = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007174 u32 mbo_subtypes = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007175
7176 used = hwaddr_aton2(dst, dst_addr);
7177 if (used < 0)
7178 return -1;
7179 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007180 if (*pos == ' ')
7181 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007182 while (num_id < MAX_ANQP_INFO_ID) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07007183 if (os_strncmp(pos, "hs20:", 5) == 0) {
7184#ifdef CONFIG_HS20
7185 int num = atoi(pos + 5);
7186 if (num <= 0 || num > 31)
7187 return -1;
7188 subtypes |= BIT(num);
7189#else /* CONFIG_HS20 */
7190 return -1;
7191#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007192 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7193#ifdef CONFIG_MBO
7194 int num = atoi(pos + 4);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007195
7196 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007197 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007198 mbo_subtypes |= BIT(num);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007199#else /* CONFIG_MBO */
7200 return -1;
7201#endif /* CONFIG_MBO */
Dmitry Shmidt15907092014-03-25 10:42:57 -07007202 } else {
7203 id[num_id] = atoi(pos);
7204 if (id[num_id])
7205 num_id++;
7206 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007207 pos = os_strchr(pos + 1, ',');
7208 if (pos == NULL)
7209 break;
7210 pos++;
7211 }
7212
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007213 if (num_id == 0 && !subtypes && !mbo_subtypes)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007214 return -1;
7215
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007216 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007217 mbo_subtypes);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007218}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007219
7220
7221static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7222{
7223 u8 dst_addr[ETH_ALEN];
7224 struct wpabuf *advproto, *query = NULL;
7225 int used, ret = -1;
7226 char *pos, *end;
7227 size_t len;
7228
7229 used = hwaddr_aton2(cmd, dst_addr);
7230 if (used < 0)
7231 return -1;
7232
7233 pos = cmd + used;
7234 while (*pos == ' ')
7235 pos++;
7236
7237 /* Advertisement Protocol ID */
7238 end = os_strchr(pos, ' ');
7239 if (end)
7240 len = end - pos;
7241 else
7242 len = os_strlen(pos);
7243 if (len & 0x01)
7244 return -1;
7245 len /= 2;
7246 if (len == 0)
7247 return -1;
7248 advproto = wpabuf_alloc(len);
7249 if (advproto == NULL)
7250 return -1;
7251 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7252 goto fail;
7253
7254 if (end) {
7255 /* Optional Query Request */
7256 pos = end + 1;
7257 while (*pos == ' ')
7258 pos++;
7259
7260 len = os_strlen(pos);
7261 if (len) {
7262 if (len & 0x01)
7263 goto fail;
7264 len /= 2;
7265 if (len == 0)
7266 goto fail;
7267 query = wpabuf_alloc(len);
7268 if (query == NULL)
7269 goto fail;
7270 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7271 goto fail;
7272 }
7273 }
7274
7275 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7276
7277fail:
7278 wpabuf_free(advproto);
7279 wpabuf_free(query);
7280
7281 return ret;
7282}
7283
7284
7285static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7286 size_t buflen)
7287{
7288 u8 addr[ETH_ALEN];
7289 int dialog_token;
7290 int used;
7291 char *pos;
7292 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007293 struct wpabuf *resp;
7294 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007295
7296 used = hwaddr_aton2(cmd, addr);
7297 if (used < 0)
7298 return -1;
7299
7300 pos = cmd + used;
7301 while (*pos == ' ')
7302 pos++;
7303 dialog_token = atoi(pos);
7304
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007305 if (wpa_s->last_gas_resp &&
7306 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
7307 dialog_token == wpa_s->last_gas_dialog_token)
7308 resp = wpa_s->last_gas_resp;
7309 else if (wpa_s->prev_gas_resp &&
7310 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
7311 dialog_token == wpa_s->prev_gas_dialog_token)
7312 resp = wpa_s->prev_gas_resp;
7313 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007314 return -1;
7315
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007316 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007317 start = 0;
7318 requested_len = resp_len;
7319
7320 pos = os_strchr(pos, ' ');
7321 if (pos) {
7322 start = atoi(pos);
7323 if (start > resp_len)
7324 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7325 pos = os_strchr(pos, ',');
7326 if (pos == NULL)
7327 return -1;
7328 pos++;
7329 requested_len = atoi(pos);
7330 if (start + requested_len > resp_len)
7331 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7332 }
7333
7334 if (requested_len * 2 + 1 > buflen)
7335 return os_snprintf(buf, buflen, "FAIL-Too long response");
7336
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007337 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
7338 requested_len);
7339
7340 if (start + requested_len == resp_len) {
7341 /*
7342 * Free memory by dropping the response after it has been
7343 * fetched.
7344 */
7345 if (resp == wpa_s->prev_gas_resp) {
7346 wpabuf_free(wpa_s->prev_gas_resp);
7347 wpa_s->prev_gas_resp = NULL;
7348 } else {
7349 wpabuf_free(wpa_s->last_gas_resp);
7350 wpa_s->last_gas_resp = NULL;
7351 }
7352 }
7353
7354 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007355}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007356#endif /* CONFIG_INTERWORKING */
7357
7358
Dmitry Shmidt04949592012-07-19 12:16:46 -07007359#ifdef CONFIG_HS20
7360
7361static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
7362{
7363 u8 dst_addr[ETH_ALEN];
7364 int used;
7365 char *pos;
7366 u32 subtypes = 0;
7367
7368 used = hwaddr_aton2(dst, dst_addr);
7369 if (used < 0)
7370 return -1;
7371 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007372 if (*pos == ' ')
7373 pos++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007374 for (;;) {
7375 int num = atoi(pos);
7376 if (num <= 0 || num > 31)
7377 return -1;
7378 subtypes |= BIT(num);
7379 pos = os_strchr(pos + 1, ',');
7380 if (pos == NULL)
7381 break;
7382 pos++;
7383 }
7384
7385 if (subtypes == 0)
7386 return -1;
7387
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007388 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007389}
7390
7391
7392static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7393 const u8 *addr, const char *realm)
7394{
7395 u8 *buf;
7396 size_t rlen, len;
7397 int ret;
7398
7399 rlen = os_strlen(realm);
7400 len = 3 + rlen;
7401 buf = os_malloc(len);
7402 if (buf == NULL)
7403 return -1;
7404 buf[0] = 1; /* NAI Home Realm Count */
7405 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
7406 buf[2] = rlen;
7407 os_memcpy(buf + 3, realm, rlen);
7408
7409 ret = hs20_anqp_send_req(wpa_s, addr,
7410 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007411 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007412
7413 os_free(buf);
7414
7415 return ret;
7416}
7417
7418
7419static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7420 char *dst)
7421{
7422 struct wpa_cred *cred = wpa_s->conf->cred;
7423 u8 dst_addr[ETH_ALEN];
7424 int used;
7425 u8 *buf;
7426 size_t len;
7427 int ret;
7428
7429 used = hwaddr_aton2(dst, dst_addr);
7430 if (used < 0)
7431 return -1;
7432
7433 while (dst[used] == ' ')
7434 used++;
7435 if (os_strncmp(dst + used, "realm=", 6) == 0)
7436 return hs20_nai_home_realm_list(wpa_s, dst_addr,
7437 dst + used + 6);
7438
7439 len = os_strlen(dst + used);
7440
7441 if (len == 0 && cred && cred->realm)
7442 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
7443
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07007444 if (len & 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07007445 return -1;
7446 len /= 2;
7447 buf = os_malloc(len);
7448 if (buf == NULL)
7449 return -1;
7450 if (hexstr2bin(dst + used, buf, len) < 0) {
7451 os_free(buf);
7452 return -1;
7453 }
7454
7455 ret = hs20_anqp_send_req(wpa_s, dst_addr,
7456 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007457 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007458 os_free(buf);
7459
7460 return ret;
7461}
7462
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007463
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007464static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
7465 int buflen)
7466{
7467 u8 dst_addr[ETH_ALEN];
7468 int used;
7469 char *ctx = NULL, *icon, *poffset, *psize;
7470
7471 used = hwaddr_aton2(cmd, dst_addr);
7472 if (used < 0)
7473 return -1;
7474 cmd += used;
7475
7476 icon = str_token(cmd, " ", &ctx);
7477 poffset = str_token(cmd, " ", &ctx);
7478 psize = str_token(cmd, " ", &ctx);
7479 if (!icon || !poffset || !psize)
7480 return -1;
7481
7482 wpa_s->fetch_osu_icon_in_progress = 0;
7483 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
7484 reply, buflen);
7485}
7486
7487
7488static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
7489{
7490 u8 dst_addr[ETH_ALEN];
7491 int used;
7492 char *icon;
7493
7494 if (!cmd[0])
7495 return hs20_del_icon(wpa_s, NULL, NULL);
7496
7497 used = hwaddr_aton2(cmd, dst_addr);
7498 if (used < 0)
7499 return -1;
7500
7501 while (cmd[used] == ' ')
7502 used++;
7503 icon = cmd[used] ? &cmd[used] : NULL;
7504
7505 return hs20_del_icon(wpa_s, dst_addr, icon);
7506}
7507
7508
7509static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007510{
7511 u8 dst_addr[ETH_ALEN];
7512 int used;
7513 char *icon;
7514
7515 used = hwaddr_aton2(cmd, dst_addr);
7516 if (used < 0)
7517 return -1;
7518
7519 while (cmd[used] == ' ')
7520 used++;
7521 icon = &cmd[used];
7522
7523 wpa_s->fetch_osu_icon_in_progress = 0;
7524 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007525 (u8 *) icon, os_strlen(icon), inmem);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007526}
7527
Dmitry Shmidt04949592012-07-19 12:16:46 -07007528#endif /* CONFIG_HS20 */
7529
7530
Dmitry Shmidt04949592012-07-19 12:16:46 -07007531#ifdef CONFIG_AUTOSCAN
7532
7533static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
7534 char *cmd)
7535{
7536 enum wpa_states state = wpa_s->wpa_state;
7537 char *new_params = NULL;
7538
7539 if (os_strlen(cmd) > 0) {
7540 new_params = os_strdup(cmd);
7541 if (new_params == NULL)
7542 return -1;
7543 }
7544
7545 os_free(wpa_s->conf->autoscan);
7546 wpa_s->conf->autoscan = new_params;
7547
7548 if (wpa_s->conf->autoscan == NULL)
7549 autoscan_deinit(wpa_s);
7550 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
7551 autoscan_init(wpa_s, 1);
7552 else if (state == WPA_SCANNING)
7553 wpa_supplicant_reinit_autoscan(wpa_s);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007554 else
7555 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
7556 wpa_supplicant_state_txt(state));
Dmitry Shmidt04949592012-07-19 12:16:46 -07007557
7558 return 0;
7559}
7560
7561#endif /* CONFIG_AUTOSCAN */
7562
7563
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007564#ifdef CONFIG_WNM
7565
7566static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
7567{
7568 int enter;
7569 int intval = 0;
7570 char *pos;
7571 int ret;
7572 struct wpabuf *tfs_req = NULL;
7573
7574 if (os_strncmp(cmd, "enter", 5) == 0)
7575 enter = 1;
7576 else if (os_strncmp(cmd, "exit", 4) == 0)
7577 enter = 0;
7578 else
7579 return -1;
7580
7581 pos = os_strstr(cmd, " interval=");
7582 if (pos)
7583 intval = atoi(pos + 10);
7584
7585 pos = os_strstr(cmd, " tfs_req=");
7586 if (pos) {
7587 char *end;
7588 size_t len;
7589 pos += 9;
7590 end = os_strchr(pos, ' ');
7591 if (end)
7592 len = end - pos;
7593 else
7594 len = os_strlen(pos);
7595 if (len & 1)
7596 return -1;
7597 len /= 2;
7598 tfs_req = wpabuf_alloc(len);
7599 if (tfs_req == NULL)
7600 return -1;
7601 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
7602 wpabuf_free(tfs_req);
7603 return -1;
7604 }
7605 }
7606
7607 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
7608 WNM_SLEEP_MODE_EXIT, intval,
7609 tfs_req);
7610 wpabuf_free(tfs_req);
7611
7612 return ret;
7613}
7614
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007615
7616static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
7617{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007618 int query_reason, list = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007619 char *btm_candidates = NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007620
7621 query_reason = atoi(cmd);
7622
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007623 cmd = os_strchr(cmd, ' ');
7624 if (cmd) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007625 if (os_strncmp(cmd, " list", 5) == 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007626 list = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007627 else
7628 btm_candidates = cmd;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007629 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007630
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007631 wpa_printf(MSG_DEBUG,
7632 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7633 query_reason, list ? " candidate list" : "");
7634
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007635 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
7636 btm_candidates,
7637 list);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007638}
7639
Hai Shalom39ba6fc2019-01-22 12:40:38 -08007640
7641static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
7642 char *cmd)
7643{
7644 struct wpabuf *elems;
7645 int ret;
7646
7647 elems = wpabuf_parse_bin(cmd);
7648 if (!elems)
7649 return -1;
7650
7651 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
7652 wpabuf_free(elems);
7653 return ret;
7654}
7655
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007656#endif /* CONFIG_WNM */
7657
7658
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007659static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
7660 size_t buflen)
7661{
7662 struct wpa_signal_info si;
7663 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007664 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007665
7666 ret = wpa_drv_signal_poll(wpa_s, &si);
7667 if (ret)
7668 return -1;
7669
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007670 pos = buf;
7671 end = buf + buflen;
7672
7673 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007674 "NOISE=%d\nFREQUENCY=%u\n",
7675 si.current_signal, si.current_txrate / 1000,
7676 si.current_noise, si.frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007677 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007678 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007679 pos += ret;
7680
7681 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
7682 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007683 channel_width_to_string(si.chanwidth));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007684 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007685 return -1;
7686 pos += ret;
7687 }
7688
Roshan Pius3a1667e2018-07-03 15:17:14 -07007689 if (si.center_frq1 > 0) {
7690 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
7691 si.center_frq1);
7692 if (os_snprintf_error(end - pos, ret))
7693 return -1;
7694 pos += ret;
7695 }
7696
7697 if (si.center_frq2 > 0) {
7698 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
7699 si.center_frq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007700 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007701 return -1;
7702 pos += ret;
7703 }
7704
7705 if (si.avg_signal) {
7706 ret = os_snprintf(pos, end - pos,
7707 "AVG_RSSI=%d\n", si.avg_signal);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007708 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007709 return -1;
7710 pos += ret;
7711 }
7712
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07007713 if (si.avg_beacon_signal) {
7714 ret = os_snprintf(pos, end - pos,
7715 "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
7716 if (os_snprintf_error(end - pos, ret))
7717 return -1;
7718 pos += ret;
7719 }
7720
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007721 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007722}
7723
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03007724
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007725static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
7726 const char *cmd)
7727{
7728 const char *pos;
7729 int threshold = 0;
7730 int hysteresis = 0;
7731
7732 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
7733 wpa_printf(MSG_DEBUG,
7734 "Reject SIGNAL_MONITOR command - bgscan is active");
7735 return -1;
7736 }
7737 pos = os_strstr(cmd, "THRESHOLD=");
7738 if (pos)
7739 threshold = atoi(pos + 10);
7740 pos = os_strstr(cmd, "HYSTERESIS=");
7741 if (pos)
7742 hysteresis = atoi(pos + 11);
7743 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
7744}
7745
7746
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007747#ifdef CONFIG_TESTING_OPTIONS
7748int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
7749 enum wpa_driver_if_type if_type,
7750 unsigned int *num,
7751 unsigned int *freq_list)
7752{
7753 char *pos = wpa_s->get_pref_freq_list_override;
7754 char *end;
7755 unsigned int count = 0;
7756
7757 /* Override string format:
7758 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7759
7760 while (pos) {
7761 if (atoi(pos) == (int) if_type)
7762 break;
7763 pos = os_strchr(pos, ' ');
7764 if (pos)
7765 pos++;
7766 }
7767 if (!pos)
7768 return -1;
7769 pos = os_strchr(pos, ':');
7770 if (!pos)
7771 return -1;
7772 pos++;
7773 end = os_strchr(pos, ' ');
7774 while (pos && (!end || pos < end) && count < *num) {
7775 freq_list[count++] = atoi(pos);
7776 pos = os_strchr(pos, ',');
7777 if (pos)
7778 pos++;
7779 }
7780
7781 *num = count;
7782 return 0;
7783}
7784#endif /* CONFIG_TESTING_OPTIONS */
7785
7786
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007787static int wpas_ctrl_iface_get_pref_freq_list(
7788 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
7789{
7790 unsigned int freq_list[100], num = 100, i;
7791 int ret;
7792 enum wpa_driver_if_type iface_type;
7793 char *pos, *end;
7794
7795 pos = buf;
7796 end = buf + buflen;
7797
7798 /* buf: "<interface_type>" */
7799 if (os_strcmp(cmd, "STATION") == 0)
7800 iface_type = WPA_IF_STATION;
7801 else if (os_strcmp(cmd, "AP") == 0)
7802 iface_type = WPA_IF_AP_BSS;
7803 else if (os_strcmp(cmd, "P2P_GO") == 0)
7804 iface_type = WPA_IF_P2P_GO;
7805 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
7806 iface_type = WPA_IF_P2P_CLIENT;
7807 else if (os_strcmp(cmd, "IBSS") == 0)
7808 iface_type = WPA_IF_IBSS;
7809 else if (os_strcmp(cmd, "TDLS") == 0)
7810 iface_type = WPA_IF_TDLS;
7811 else
7812 return -1;
7813
7814 wpa_printf(MSG_DEBUG,
7815 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
Hai Shalom5f92bc92019-04-18 11:54:11 -07007816 iface_type, cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007817
7818 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
7819 if (ret)
7820 return -1;
7821
7822 for (i = 0; i < num; i++) {
7823 ret = os_snprintf(pos, end - pos, "%s%u",
7824 i > 0 ? "," : "", freq_list[i]);
7825 if (os_snprintf_error(end - pos, ret))
7826 return -1;
7827 pos += ret;
7828 }
7829
7830 return pos - buf;
7831}
7832
7833
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007834static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
7835 char *buf, size_t buflen)
7836{
7837 int ret, i;
7838 char *pos, *end;
7839
7840 ret = os_snprintf(buf, buflen, "%016llX:\n",
7841 (long long unsigned) wpa_s->drv_flags);
7842 if (os_snprintf_error(buflen, ret))
7843 return -1;
7844
7845 pos = buf + ret;
7846 end = buf + buflen;
7847
7848 for (i = 0; i < 64; i++) {
7849 if (wpa_s->drv_flags & (1LLU << i)) {
7850 ret = os_snprintf(pos, end - pos, "%s\n",
7851 driver_flag_to_string(1LLU << i));
7852 if (os_snprintf_error(end - pos, ret))
7853 return -1;
7854 pos += ret;
7855 }
7856 }
7857
7858 return pos - buf;
7859}
7860
7861
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07007862static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
7863 size_t buflen)
7864{
7865 struct hostap_sta_driver_data sta;
7866 int ret;
7867
7868 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
7869 if (ret)
7870 return -1;
7871
7872 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03007873 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007874 if (os_snprintf_error(buflen, ret))
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07007875 return -1;
7876 return ret;
7877}
7878
7879
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007880#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07007881static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
7882 char *buf, size_t buflen)
7883{
7884 int ret;
7885
7886 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07007887 if (ret == 0) {
7888 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
7889 struct p2p_data *p2p = wpa_s->global->p2p;
7890 if (p2p) {
7891 char country[3];
7892 country[0] = cmd[8];
7893 country[1] = cmd[9];
7894 country[2] = 0x04;
7895 p2p_set_country(p2p, country);
7896 }
7897 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007898 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007899 if (os_snprintf_error(buflen, ret))
7900 ret = -1;
Dmitry Shmidt9432e122013-09-12 12:39:30 -07007901 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07007902 return ret;
7903}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007904#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07007905
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07007906
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007907static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
7908 char *buf, size_t buflen)
7909{
7910 int ret;
7911 char *pos;
7912 u8 *data = NULL;
7913 unsigned int vendor_id, subcmd;
7914 struct wpabuf *reply;
7915 size_t data_len = 0;
7916
7917 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7918 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007919 if (!isblank((unsigned char) *pos))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007920 return -EINVAL;
7921
7922 subcmd = strtoul(pos, &pos, 10);
7923
7924 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007925 if (!isblank((unsigned char) *pos++))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007926 return -EINVAL;
7927 data_len = os_strlen(pos);
7928 }
7929
7930 if (data_len) {
7931 data_len /= 2;
7932 data = os_malloc(data_len);
7933 if (!data)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007934 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007935
7936 if (hexstr2bin(pos, data, data_len)) {
7937 wpa_printf(MSG_DEBUG,
7938 "Vendor command: wrong parameter format");
7939 os_free(data);
7940 return -EINVAL;
7941 }
7942 }
7943
7944 reply = wpabuf_alloc((buflen - 1) / 2);
7945 if (!reply) {
7946 os_free(data);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007947 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007948 }
7949
7950 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
7951 reply);
7952
7953 if (ret == 0)
7954 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
7955 wpabuf_len(reply));
7956
7957 wpabuf_free(reply);
7958 os_free(data);
7959
7960 return ret;
7961}
7962
7963
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007964static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
7965{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007966#ifdef CONFIG_P2P
7967 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
7968 wpa_s->global->p2p_init_wpa_s : wpa_s;
7969#endif /* CONFIG_P2P */
7970
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007971 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
7972
Dmitry Shmidt29333592017-01-09 12:27:11 -08007973 if (wpas_abort_ongoing_scan(wpa_s) == 0)
7974 wpa_s->ignore_post_flush_scan_res = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007975
Dmitry Shmidtde47be72016-01-07 12:52:55 -08007976 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
7977 /*
7978 * Avoid possible auto connect re-connection on getting
7979 * disconnected due to state flush.
7980 */
7981 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
7982 }
7983
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007984#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08007985 wpas_p2p_group_remove(p2p_wpa_s, "*");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007986 wpas_p2p_cancel(p2p_wpa_s);
7987 p2p_ctrl_flush(p2p_wpa_s);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007988 wpas_p2p_service_flush(p2p_wpa_s);
7989 p2p_wpa_s->global->p2p_disabled = 0;
7990 p2p_wpa_s->global->p2p_per_sta_psk = 0;
7991 p2p_wpa_s->conf->num_sec_device_types = 0;
7992 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
7993 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
7994 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007995 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08007996 p2p_wpa_s->global->pending_p2ps_group = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007997 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007998#endif /* CONFIG_P2P */
7999
8000#ifdef CONFIG_WPS_TESTING
8001 wps_version_number = 0x20;
8002 wps_testing_dummy_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08008003 wps_corrupt_pkhash = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08008004 wps_force_auth_types_in_use = 0;
8005 wps_force_encr_types_in_use = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008006#endif /* CONFIG_WPS_TESTING */
8007#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008008 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008009 wpas_wps_cancel(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008010 wps_registrar_flush(wpa_s->wps->registrar);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008011#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07008012 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07008013 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008014
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008015#ifdef CONFIG_DPP
8016 wpas_dpp_deinit(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07008017 wpa_s->dpp_init_max_tries = 0;
8018 wpa_s->dpp_init_retry_time = 0;
8019 wpa_s->dpp_resp_wait_time = 0;
8020 wpa_s->dpp_resp_max_tries = 0;
8021 wpa_s->dpp_resp_retry_time = 0;
8022#ifdef CONFIG_TESTING_OPTIONS
8023 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
8024 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
8025 dpp_pkex_ephemeral_key_override_len = 0;
8026 dpp_protocol_key_override_len = 0;
8027 dpp_nonce_override_len = 0;
8028#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008029#endif /* CONFIG_DPP */
8030
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008031#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008032#ifdef CONFIG_TDLS_TESTING
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008033 tdls_testing = 0;
8034#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008035 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
8036 wpa_tdls_enable(wpa_s->wpa, 1);
8037#endif /* CONFIG_TDLS */
8038
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008039 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
8040 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
8041
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008042 wpa_s->no_keep_alive = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08008043 wpa_s->own_disconnect_req = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008044
8045 os_free(wpa_s->disallow_aps_bssid);
8046 wpa_s->disallow_aps_bssid = NULL;
8047 wpa_s->disallow_aps_bssid_count = 0;
8048 os_free(wpa_s->disallow_aps_ssid);
8049 wpa_s->disallow_aps_ssid = NULL;
8050 wpa_s->disallow_aps_ssid_count = 0;
8051
8052 wpa_s->set_sta_uapsd = 0;
8053 wpa_s->sta_uapsd = 0;
8054
8055 wpa_drv_radio_disable(wpa_s, 0);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008056 wpa_blacklist_clear(wpa_s);
Dmitry Shmidt4b060592013-04-29 16:42:49 -07008057 wpa_s->extra_blacklist_count = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008058 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
8059 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08008060 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08008061 wpa_s->conf->auto_interworking = 0;
8062 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008063
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008064 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
8065 rsn_preauth_deinit(wpa_s->wpa);
8066
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008067 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
8068 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
8069 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
8070 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
8071
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008072 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008073 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008074
8075 wpa_s->next_ssid = NULL;
8076
8077#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008078#ifdef CONFIG_HS20
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008079 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08008080 hs20_del_icon(wpa_s, NULL, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008081#endif /* CONFIG_HS20 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08008082#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008083
8084 wpa_s->ext_mgmt_frame_handling = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008085 wpa_s->ext_eapol_frame_io = 0;
8086#ifdef CONFIG_TESTING_OPTIONS
8087 wpa_s->extra_roc_dur = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008088 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08008089 wpa_s->p2p_go_csa_on_inv = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008090 wpa_s->ignore_auth_resp = 0;
8091 wpa_s->ignore_assoc_disallow = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008092 wpa_s->testing_resend_assoc = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008093 wpa_s->ignore_sae_h2e_only = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07008094 wpa_s->reject_btm_req_reason = 0;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08008095 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008096 os_free(wpa_s->get_pref_freq_list_override);
8097 wpa_s->get_pref_freq_list_override = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008098 wpabuf_free(wpa_s->sae_commit_override);
8099 wpa_s->sae_commit_override = NULL;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08008100 os_free(wpa_s->extra_sae_rejected_groups);
8101 wpa_s->extra_sae_rejected_groups = NULL;
8102 wpabuf_free(wpa_s->rsnxe_override_assoc);
8103 wpa_s->rsnxe_override_assoc = NULL;
8104 wpabuf_free(wpa_s->rsnxe_override_eapol);
8105 wpa_s->rsnxe_override_eapol = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07008106#ifdef CONFIG_DPP
8107 os_free(wpa_s->dpp_config_obj_override);
8108 wpa_s->dpp_config_obj_override = NULL;
8109 os_free(wpa_s->dpp_discovery_override);
8110 wpa_s->dpp_discovery_override = NULL;
8111 os_free(wpa_s->dpp_groups_override);
8112 wpa_s->dpp_groups_override = NULL;
8113 dpp_test = DPP_TEST_DISABLED;
8114#endif /* CONFIG_DPP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008115#endif /* CONFIG_TESTING_OPTIONS */
8116
8117 wpa_s->disconnected = 0;
8118 os_free(wpa_s->next_scan_freqs);
8119 wpa_s->next_scan_freqs = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008120 os_free(wpa_s->select_network_scan_freqs);
8121 wpa_s->select_network_scan_freqs = NULL;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008122
8123 wpa_bss_flush(wpa_s);
8124 if (!dl_list_empty(&wpa_s->bss)) {
8125 wpa_printf(MSG_DEBUG,
8126 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
8127 MACSTR " pending_bssid=" MACSTR,
8128 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
8129 MAC2STR(wpa_s->bssid),
8130 MAC2STR(wpa_s->pending_bssid));
8131 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008132
8133 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -08008134 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07008135
8136#ifdef CONFIG_SME
8137 wpa_s->sme.last_unprot_disconnect.sec = 0;
8138#endif /* CONFIG_SME */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008139
8140 wpabuf_free(wpa_s->ric_ies);
8141 wpa_s->ric_ies = NULL;
Hai Shalom74f70d42019-02-11 14:42:39 -08008142
8143 wpa_supplicant_update_channel_list(wpa_s, NULL);
8144
8145 free_bss_tmp_disallowed(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008146}
8147
8148
8149static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
8150 char *buf, size_t buflen)
8151{
8152 struct wpa_radio_work *work;
8153 char *pos, *end;
8154 struct os_reltime now, diff;
8155
8156 pos = buf;
8157 end = buf + buflen;
8158
8159 os_get_reltime(&now);
8160
8161 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8162 {
8163 int ret;
8164
8165 os_reltime_sub(&now, &work->time, &diff);
8166 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
8167 work->type, work->wpa_s->ifname, work->freq,
8168 work->started, diff.sec, diff.usec);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008169 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008170 break;
8171 pos += ret;
8172 }
8173
8174 return pos - buf;
8175}
8176
8177
8178static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
8179{
8180 struct wpa_radio_work *work = eloop_ctx;
8181 struct wpa_external_work *ework = work->ctx;
8182
8183 wpa_dbg(work->wpa_s, MSG_DEBUG,
8184 "Timing out external radio work %u (%s)",
8185 ework->id, work->type);
8186 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008187 work->wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008188 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008189 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008190}
8191
8192
8193static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
8194{
8195 struct wpa_external_work *ework = work->ctx;
8196
8197 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008198 if (work->started)
8199 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8200 work, NULL);
8201
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008202 /*
8203 * work->type points to a buffer in ework, so need to replace
8204 * that here with a fixed string to avoid use of freed memory
8205 * in debug prints.
8206 */
8207 work->type = "freed-ext-work";
8208 work->ctx = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008209 os_free(ework);
8210 return;
8211 }
8212
8213 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
8214 ework->id, ework->type);
8215 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008216 work->wpa_s->ext_work_in_progress = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008217 if (!ework->timeout)
8218 ework->timeout = 10;
8219 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
8220 work, NULL);
8221}
8222
8223
8224static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
8225 char *buf, size_t buflen)
8226{
8227 struct wpa_external_work *ework;
8228 char *pos, *pos2;
8229 size_t type_len;
8230 int ret;
8231 unsigned int freq = 0;
8232
8233 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8234
8235 ework = os_zalloc(sizeof(*ework));
8236 if (ework == NULL)
8237 return -1;
8238
8239 pos = os_strchr(cmd, ' ');
8240 if (pos) {
8241 type_len = pos - cmd;
8242 pos++;
8243
8244 pos2 = os_strstr(pos, "freq=");
8245 if (pos2)
8246 freq = atoi(pos2 + 5);
8247
8248 pos2 = os_strstr(pos, "timeout=");
8249 if (pos2)
8250 ework->timeout = atoi(pos2 + 8);
8251 } else {
8252 type_len = os_strlen(cmd);
8253 }
8254 if (4 + type_len >= sizeof(ework->type))
8255 type_len = sizeof(ework->type) - 4 - 1;
8256 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
8257 os_memcpy(ework->type + 4, cmd, type_len);
8258 ework->type[4 + type_len] = '\0';
8259
8260 wpa_s->ext_work_id++;
8261 if (wpa_s->ext_work_id == 0)
8262 wpa_s->ext_work_id++;
8263 ework->id = wpa_s->ext_work_id;
8264
8265 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
8266 ework) < 0) {
8267 os_free(ework);
8268 return -1;
8269 }
8270
8271 ret = os_snprintf(buf, buflen, "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008272 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008273 return -1;
8274 return ret;
8275}
8276
8277
8278static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
8279{
8280 struct wpa_radio_work *work;
8281 unsigned int id = atoi(cmd);
8282
8283 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8284 {
8285 struct wpa_external_work *ework;
8286
8287 if (os_strncmp(work->type, "ext:", 4) != 0)
8288 continue;
8289 ework = work->ctx;
8290 if (id && ework->id != id)
8291 continue;
8292 wpa_dbg(wpa_s, MSG_DEBUG,
8293 "Completed external radio work %u (%s)",
8294 ework->id, ework->type);
8295 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008296 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008297 radio_work_done(work);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07008298 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008299 return 3; /* "OK\n" */
8300 }
8301
8302 return -1;
8303}
8304
8305
8306static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
8307 char *buf, size_t buflen)
8308{
8309 if (os_strcmp(cmd, "show") == 0)
8310 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
8311 if (os_strncmp(cmd, "add ", 4) == 0)
8312 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
8313 if (os_strncmp(cmd, "done ", 5) == 0)
8314 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
8315 return -1;
8316}
8317
8318
8319void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
8320{
8321 struct wpa_radio_work *work, *tmp;
8322
Dmitry Shmidt18463232014-01-24 12:29:41 -08008323 if (!wpa_s || !wpa_s->radio)
8324 return;
8325
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008326 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
8327 struct wpa_radio_work, list) {
8328 struct wpa_external_work *ework;
8329
8330 if (os_strncmp(work->type, "ext:", 4) != 0)
8331 continue;
8332 ework = work->ctx;
8333 wpa_dbg(wpa_s, MSG_DEBUG,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07008334 "Flushing%s external radio work %u (%s)",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008335 work->started ? " started" : "", ework->id,
8336 ework->type);
8337 if (work->started)
8338 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8339 work, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008340 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008341 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008342 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008343}
8344
8345
Dmitry Shmidt051af732013-10-22 13:52:46 -07008346static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
8347{
8348 struct wpa_supplicant *wpa_s = eloop_ctx;
8349 eapol_sm_notify_ctrl_response(wpa_s->eapol);
8350}
8351
8352
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008353static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
8354 unsigned int *scan_id_count, int scan_id[])
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008355{
8356 const char *pos = value;
8357
8358 while (pos) {
8359 if (*pos == ' ' || *pos == '\0')
8360 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008361 if (*scan_id_count == MAX_SCAN_ID)
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008362 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008363 scan_id[(*scan_id_count)++] = atoi(pos);
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008364 pos = os_strchr(pos, ',');
8365 if (pos)
8366 pos++;
8367 }
8368
8369 return 0;
8370}
8371
8372
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008373static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
8374 char *reply, int reply_size, int *reply_len)
8375{
8376 char *pos;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008377 unsigned int manual_scan_passive = 0;
8378 unsigned int manual_scan_use_id = 0;
8379 unsigned int manual_scan_only_new = 0;
8380 unsigned int scan_only = 0;
8381 unsigned int scan_id_count = 0;
8382 int scan_id[MAX_SCAN_ID];
8383 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
8384 struct wpa_scan_results *scan_res);
8385 int *manual_scan_freqs = NULL;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008386 struct wpa_ssid_value *ssid = NULL, *ns;
8387 unsigned int ssid_count = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008388
8389 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
8390 *reply_len = -1;
8391 return;
8392 }
8393
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008394 if (radio_work_pending(wpa_s, "scan")) {
8395 wpa_printf(MSG_DEBUG,
8396 "Pending scan scheduled - reject new request");
8397 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8398 return;
8399 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008400
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008401#ifdef CONFIG_INTERWORKING
8402 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
8403 wpa_printf(MSG_DEBUG,
8404 "Interworking select in progress - reject new scan");
8405 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8406 return;
8407 }
8408#endif /* CONFIG_INTERWORKING */
8409
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008410 if (params) {
8411 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008412 scan_only = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008413
8414 pos = os_strstr(params, "freq=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008415 if (pos) {
8416 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
8417 pos + 5);
8418 if (manual_scan_freqs == NULL) {
8419 *reply_len = -1;
8420 goto done;
8421 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008422 }
8423
8424 pos = os_strstr(params, "passive=");
8425 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008426 manual_scan_passive = !!atoi(pos + 8);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008427
8428 pos = os_strstr(params, "use_id=");
8429 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008430 manual_scan_use_id = atoi(pos + 7);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008431
8432 pos = os_strstr(params, "only_new=1");
8433 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008434 manual_scan_only_new = 1;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008435
8436 pos = os_strstr(params, "scan_id=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008437 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
8438 scan_id) < 0) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008439 *reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008440 goto done;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008441 }
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008442
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008443 pos = os_strstr(params, "bssid=");
8444 if (pos) {
8445 u8 bssid[ETH_ALEN];
8446
8447 pos += 6;
8448 if (hwaddr_aton(pos, bssid)) {
8449 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
8450 *reply_len = -1;
8451 goto done;
8452 }
8453 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
8454 }
8455
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008456 pos = params;
8457 while (pos && *pos != '\0') {
8458 if (os_strncmp(pos, "ssid ", 5) == 0) {
8459 char *end;
8460
8461 pos += 5;
8462 end = pos;
8463 while (*end) {
8464 if (*end == '\0' || *end == ' ')
8465 break;
8466 end++;
8467 }
8468
8469 ns = os_realloc_array(
8470 ssid, ssid_count + 1,
8471 sizeof(struct wpa_ssid_value));
8472 if (ns == NULL) {
8473 *reply_len = -1;
8474 goto done;
8475 }
8476 ssid = ns;
8477
8478 if ((end - pos) & 0x01 ||
8479 end - pos > 2 * SSID_MAX_LEN ||
8480 hexstr2bin(pos, ssid[ssid_count].ssid,
8481 (end - pos) / 2) < 0) {
8482 wpa_printf(MSG_DEBUG,
8483 "Invalid SSID value '%s'",
8484 pos);
8485 *reply_len = -1;
8486 goto done;
8487 }
8488 ssid[ssid_count].ssid_len = (end - pos) / 2;
8489 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
8490 ssid[ssid_count].ssid,
8491 ssid[ssid_count].ssid_len);
8492 ssid_count++;
8493 pos = end;
8494 }
8495
8496 pos = os_strchr(pos, ' ');
8497 if (pos)
8498 pos++;
8499 }
8500 }
8501
8502 wpa_s->num_ssids_from_scan_req = ssid_count;
8503 os_free(wpa_s->ssids_from_scan_req);
8504 if (ssid_count) {
8505 wpa_s->ssids_from_scan_req = ssid;
8506 ssid = NULL;
8507 } else {
8508 wpa_s->ssids_from_scan_req = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008509 }
8510
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008511 if (scan_only)
8512 scan_res_handler = scan_only_handler;
8513 else if (wpa_s->scan_res_handler == scan_only_handler)
8514 scan_res_handler = NULL;
8515 else
8516 scan_res_handler = wpa_s->scan_res_handler;
8517
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008518 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
8519 ((wpa_s->wpa_state <= WPA_SCANNING) ||
8520 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008521 wpa_s->manual_scan_passive = manual_scan_passive;
8522 wpa_s->manual_scan_use_id = manual_scan_use_id;
8523 wpa_s->manual_scan_only_new = manual_scan_only_new;
8524 wpa_s->scan_id_count = scan_id_count;
8525 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8526 wpa_s->scan_res_handler = scan_res_handler;
8527 os_free(wpa_s->manual_scan_freqs);
8528 wpa_s->manual_scan_freqs = manual_scan_freqs;
8529 manual_scan_freqs = NULL;
8530
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008531 wpa_s->normal_scans = 0;
8532 wpa_s->scan_req = MANUAL_SCAN_REQ;
8533 wpa_s->after_wps = 0;
8534 wpa_s->known_wps_freq = 0;
8535 wpa_supplicant_req_scan(wpa_s, 0, 0);
8536 if (wpa_s->manual_scan_use_id) {
8537 wpa_s->manual_scan_id++;
8538 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8539 wpa_s->manual_scan_id);
8540 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8541 wpa_s->manual_scan_id);
8542 }
8543 } else if (wpa_s->sched_scanning) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008544 wpa_s->manual_scan_passive = manual_scan_passive;
8545 wpa_s->manual_scan_use_id = manual_scan_use_id;
8546 wpa_s->manual_scan_only_new = manual_scan_only_new;
8547 wpa_s->scan_id_count = scan_id_count;
8548 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8549 wpa_s->scan_res_handler = scan_res_handler;
8550 os_free(wpa_s->manual_scan_freqs);
8551 wpa_s->manual_scan_freqs = manual_scan_freqs;
8552 manual_scan_freqs = NULL;
8553
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008554 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
8555 wpa_supplicant_cancel_sched_scan(wpa_s);
8556 wpa_s->scan_req = MANUAL_SCAN_REQ;
8557 wpa_supplicant_req_scan(wpa_s, 0, 0);
8558 if (wpa_s->manual_scan_use_id) {
8559 wpa_s->manual_scan_id++;
8560 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8561 wpa_s->manual_scan_id);
8562 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8563 wpa_s->manual_scan_id);
8564 }
8565 } else {
8566 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
8567 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8568 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008569
8570done:
8571 os_free(manual_scan_freqs);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008572 os_free(ssid);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008573}
8574
8575
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008576#ifdef CONFIG_TESTING_OPTIONS
8577
8578static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
8579 unsigned int freq, const u8 *dst,
8580 const u8 *src, const u8 *bssid,
8581 const u8 *data, size_t data_len,
8582 enum offchannel_send_action_result
8583 result)
8584{
8585 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8586 " src=" MACSTR " bssid=" MACSTR " result=%s",
8587 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
8588 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
8589 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
8590 "NO_ACK" : "FAILED"));
8591}
8592
8593
8594static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
8595{
8596 char *pos, *param;
8597 size_t len;
8598 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
8599 int res, used;
8600 int freq = 0, no_cck = 0, wait_time = 0;
8601
8602 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8603 * <action=Action frame payload> */
8604
8605 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
8606
8607 pos = cmd;
8608 used = hwaddr_aton2(pos, da);
8609 if (used < 0)
8610 return -1;
8611 pos += used;
8612 while (*pos == ' ')
8613 pos++;
8614 used = hwaddr_aton2(pos, bssid);
8615 if (used < 0)
8616 return -1;
8617 pos += used;
8618
8619 param = os_strstr(pos, " freq=");
8620 if (param) {
8621 param += 6;
8622 freq = atoi(param);
8623 }
8624
8625 param = os_strstr(pos, " no_cck=");
8626 if (param) {
8627 param += 8;
8628 no_cck = atoi(param);
8629 }
8630
8631 param = os_strstr(pos, " wait_time=");
8632 if (param) {
8633 param += 11;
8634 wait_time = atoi(param);
8635 }
8636
8637 param = os_strstr(pos, " action=");
8638 if (param == NULL)
8639 return -1;
8640 param += 8;
8641
8642 len = os_strlen(param);
8643 if (len & 1)
8644 return -1;
8645 len /= 2;
8646
8647 buf = os_malloc(len);
8648 if (buf == NULL)
8649 return -1;
8650
8651 if (hexstr2bin(param, buf, len) < 0) {
8652 os_free(buf);
8653 return -1;
8654 }
8655
8656 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
8657 buf, len, wait_time,
8658 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
8659 os_free(buf);
8660 return res;
8661}
8662
8663
8664static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
8665{
8666 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
8667 offchannel_send_action_done(wpa_s);
8668}
8669
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07008670
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008671static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
8672 char *cmd)
8673{
8674 char *pos, *param;
8675 size_t len;
8676 u8 *buf;
8677 int freq = 0, datarate = 0, ssi_signal = 0;
8678 union wpa_event_data event;
8679
8680 if (!wpa_s->ext_mgmt_frame_handling)
8681 return -1;
8682
8683 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8684
8685 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
8686
8687 pos = cmd;
8688 param = os_strstr(pos, "freq=");
8689 if (param) {
8690 param += 5;
8691 freq = atoi(param);
8692 }
8693
8694 param = os_strstr(pos, " datarate=");
8695 if (param) {
8696 param += 10;
8697 datarate = atoi(param);
8698 }
8699
8700 param = os_strstr(pos, " ssi_signal=");
8701 if (param) {
8702 param += 12;
8703 ssi_signal = atoi(param);
8704 }
8705
8706 param = os_strstr(pos, " frame=");
8707 if (param == NULL)
8708 return -1;
8709 param += 7;
8710
8711 len = os_strlen(param);
8712 if (len & 1)
8713 return -1;
8714 len /= 2;
8715
8716 buf = os_malloc(len);
8717 if (buf == NULL)
8718 return -1;
8719
8720 if (hexstr2bin(param, buf, len) < 0) {
8721 os_free(buf);
8722 return -1;
8723 }
8724
8725 os_memset(&event, 0, sizeof(event));
8726 event.rx_mgmt.freq = freq;
8727 event.rx_mgmt.frame = buf;
8728 event.rx_mgmt.frame_len = len;
8729 event.rx_mgmt.ssi_signal = ssi_signal;
8730 event.rx_mgmt.datarate = datarate;
8731 wpa_s->ext_mgmt_frame_handling = 0;
8732 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
8733 wpa_s->ext_mgmt_frame_handling = 1;
8734
8735 os_free(buf);
8736
8737 return 0;
8738}
8739
8740
Paul Stewart092955c2017-02-06 09:13:09 -08008741static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
8742 char *param)
8743{
8744 struct wpa_scan_res *res;
8745 struct os_reltime now;
8746 char *pos, *end;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008747 int ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08008748
8749 if (!param)
8750 return -1;
8751
8752 if (os_strcmp(param, "START") == 0) {
8753 wpa_bss_update_start(wpa_s);
8754 return 0;
8755 }
8756
8757 if (os_strcmp(param, "END") == 0) {
8758 wpa_bss_update_end(wpa_s, NULL, 1);
8759 return 0;
8760 }
8761
8762 if (os_strncmp(param, "BSS ", 4) != 0)
8763 return -1;
8764 param += 3;
8765
8766 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
8767 if (!res)
8768 return -1;
8769
8770 pos = os_strstr(param, " flags=");
8771 if (pos)
8772 res->flags = strtol(pos + 7, NULL, 16);
8773
8774 pos = os_strstr(param, " bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008775 if (pos && hwaddr_aton(pos + 7, res->bssid))
8776 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008777
8778 pos = os_strstr(param, " freq=");
8779 if (pos)
8780 res->freq = atoi(pos + 6);
8781
8782 pos = os_strstr(param, " beacon_int=");
8783 if (pos)
8784 res->beacon_int = atoi(pos + 12);
8785
8786 pos = os_strstr(param, " caps=");
8787 if (pos)
8788 res->caps = strtol(pos + 6, NULL, 16);
8789
8790 pos = os_strstr(param, " qual=");
8791 if (pos)
8792 res->qual = atoi(pos + 6);
8793
8794 pos = os_strstr(param, " noise=");
8795 if (pos)
8796 res->noise = atoi(pos + 7);
8797
8798 pos = os_strstr(param, " level=");
8799 if (pos)
8800 res->level = atoi(pos + 7);
8801
8802 pos = os_strstr(param, " tsf=");
8803 if (pos)
8804 res->tsf = strtoll(pos + 5, NULL, 16);
8805
8806 pos = os_strstr(param, " age=");
8807 if (pos)
8808 res->age = atoi(pos + 5);
8809
8810 pos = os_strstr(param, " est_throughput=");
8811 if (pos)
8812 res->est_throughput = atoi(pos + 16);
8813
8814 pos = os_strstr(param, " snr=");
8815 if (pos)
8816 res->snr = atoi(pos + 5);
8817
8818 pos = os_strstr(param, " parent_tsf=");
8819 if (pos)
8820 res->parent_tsf = strtoll(pos + 7, NULL, 16);
8821
8822 pos = os_strstr(param, " tsf_bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008823 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
8824 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008825
8826 pos = os_strstr(param, " ie=");
8827 if (pos) {
8828 pos += 4;
8829 end = os_strchr(pos, ' ');
8830 if (!end)
8831 end = pos + os_strlen(pos);
8832 res->ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008833 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
8834 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008835 }
8836
8837 pos = os_strstr(param, " beacon_ie=");
8838 if (pos) {
8839 pos += 11;
8840 end = os_strchr(pos, ' ');
8841 if (!end)
8842 end = pos + os_strlen(pos);
8843 res->beacon_ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008844 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
8845 res->beacon_ie_len))
8846 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008847 }
8848
8849 os_get_reltime(&now);
8850 wpa_bss_update_scan_res(wpa_s, res, &now);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008851 ret = 0;
8852fail:
Paul Stewart092955c2017-02-06 09:13:09 -08008853 os_free(res);
8854
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008855 return ret;
Paul Stewart092955c2017-02-06 09:13:09 -08008856}
8857
8858
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07008859static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
8860{
8861 char *pos, *param;
8862 union wpa_event_data event;
8863 enum wpa_event_type ev;
8864
8865 /* <event name> [parameters..] */
8866
8867 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
8868
8869 pos = cmd;
8870 param = os_strchr(pos, ' ');
8871 if (param)
8872 *param++ = '\0';
8873
8874 os_memset(&event, 0, sizeof(event));
8875
8876 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
8877 ev = EVENT_INTERFACE_ENABLED;
8878 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
8879 ev = EVENT_INTERFACE_DISABLED;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07008880 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
8881 ev = EVENT_AVOID_FREQUENCIES;
8882 if (param == NULL)
8883 param = "";
8884 if (freq_range_list_parse(&event.freq_range, param) < 0)
8885 return -1;
8886 wpa_supplicant_event(wpa_s, ev, &event);
8887 os_free(event.freq_range.range);
8888 return 0;
Paul Stewart092955c2017-02-06 09:13:09 -08008889 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
8890 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07008891 } else {
8892 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
8893 cmd);
8894 return -1;
8895 }
8896
8897 wpa_supplicant_event(wpa_s, ev, &event);
8898
8899 return 0;
8900}
8901
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008902
8903static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
8904{
8905 char *pos;
8906 u8 src[ETH_ALEN], *buf;
8907 int used;
8908 size_t len;
8909
8910 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
8911
8912 pos = cmd;
8913 used = hwaddr_aton2(pos, src);
8914 if (used < 0)
8915 return -1;
8916 pos += used;
8917 while (*pos == ' ')
8918 pos++;
8919
8920 len = os_strlen(pos);
8921 if (len & 1)
8922 return -1;
8923 len /= 2;
8924
8925 buf = os_malloc(len);
8926 if (buf == NULL)
8927 return -1;
8928
8929 if (hexstr2bin(pos, buf, len) < 0) {
8930 os_free(buf);
8931 return -1;
8932 }
8933
8934 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
8935 os_free(buf);
8936
8937 return 0;
8938}
8939
8940
8941static u16 ipv4_hdr_checksum(const void *buf, size_t len)
8942{
8943 size_t i;
8944 u32 sum = 0;
8945 const u16 *pos = buf;
8946
8947 for (i = 0; i < len / 2; i++)
8948 sum += *pos++;
8949
8950 while (sum >> 16)
8951 sum = (sum & 0xffff) + (sum >> 16);
8952
8953 return sum ^ 0xffff;
8954}
8955
8956
8957#define HWSIM_PACKETLEN 1500
8958#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8959
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07008960static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
8961 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008962{
8963 struct wpa_supplicant *wpa_s = ctx;
8964 const struct ether_header *eth;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008965 struct iphdr ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008966 const u8 *pos;
8967 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08008968 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008969
Hai Shalom74f70d42019-02-11 14:42:39 -08008970 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
8971 wpa_printf(MSG_DEBUG,
8972 "test data: RX - ignore unexpected length %d",
8973 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008974 return;
Hai Shalom74f70d42019-02-11 14:42:39 -08008975 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008976
8977 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008978 os_memcpy(&ip, eth + 1, sizeof(ip));
8979 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008980
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008981 if (ip.ihl != 5 || ip.version != 4 ||
Hai Shalom74f70d42019-02-11 14:42:39 -08008982 ntohs(ip.tot_len) > HWSIM_IP_LEN) {
8983 wpa_printf(MSG_DEBUG,
8984 "test data: RX - ignore unexpect IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008985 return;
Hai Shalom39bc25d2019-02-06 16:32:13 -08008986 }
Hai Shalombf6e0ba2019-02-11 12:01:50 -08008987
Hai Shalom74f70d42019-02-11 14:42:39 -08008988 for (i = 0; i < ntohs(ip.tot_len) - sizeof(ip); i++) {
8989 if (*pos != (u8) i) {
8990 wpa_printf(MSG_DEBUG,
8991 "test data: RX - ignore mismatching payload");
8992 return;
8993 }
8994 pos++;
8995 }
8996 extra[0] = '\0';
8997 if (ntohs(ip.tot_len) != HWSIM_IP_LEN)
8998 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.tot_len));
8999 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
9000 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009001}
9002
9003
9004static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
9005 char *cmd)
9006{
9007 int enabled = atoi(cmd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009008 char *pos;
9009 const char *ifname;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009010
9011 if (!enabled) {
9012 if (wpa_s->l2_test) {
9013 l2_packet_deinit(wpa_s->l2_test);
9014 wpa_s->l2_test = NULL;
9015 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
9016 }
9017 return 0;
9018 }
9019
9020 if (wpa_s->l2_test)
9021 return 0;
9022
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08009023 pos = os_strstr(cmd, " ifname=");
9024 if (pos)
9025 ifname = pos + 8;
9026 else
9027 ifname = wpa_s->ifname;
9028
9029 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009030 ETHERTYPE_IP, wpas_data_test_rx,
9031 wpa_s, 1);
9032 if (wpa_s->l2_test == NULL)
9033 return -1;
9034
9035 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
9036
9037 return 0;
9038}
9039
9040
9041static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
9042{
9043 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom74f70d42019-02-11 14:42:39 -08009044 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009045 int used;
9046 long int val;
9047 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009048 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009049 struct ether_header *eth;
9050 struct iphdr *ip;
9051 u8 *dpos;
9052 unsigned int i;
Hai Shalom74f70d42019-02-11 14:42:39 -08009053 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009054
9055 if (wpa_s->l2_test == NULL)
9056 return -1;
9057
Hai Shalom74f70d42019-02-11 14:42:39 -08009058 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009059
9060 pos = cmd;
9061 used = hwaddr_aton2(pos, dst);
9062 if (used < 0)
9063 return -1;
9064 pos += used;
9065 while (*pos == ' ')
9066 pos++;
9067 used = hwaddr_aton2(pos, src);
9068 if (used < 0)
9069 return -1;
9070 pos += used;
9071
Hai Shalom74f70d42019-02-11 14:42:39 -08009072 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009073 if (val < 0 || val > 0xff)
9074 return -1;
9075 tos = val;
9076
Hai Shalom74f70d42019-02-11 14:42:39 -08009077 pos = os_strstr(pos2, " len=");
9078 if (pos) {
9079 i = atoi(pos + 5);
9080 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
9081 return -1;
9082 send_len = i;
9083 }
9084
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009085 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009086 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
9087 os_memcpy(eth->ether_shost, src, ETH_ALEN);
9088 eth->ether_type = htons(ETHERTYPE_IP);
9089 ip = (struct iphdr *) (eth + 1);
9090 os_memset(ip, 0, sizeof(*ip));
9091 ip->ihl = 5;
9092 ip->version = 4;
9093 ip->ttl = 64;
9094 ip->tos = tos;
Hai Shalom74f70d42019-02-11 14:42:39 -08009095 ip->tot_len = htons(send_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009096 ip->protocol = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009097 ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
9098 ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009099 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
9100 dpos = (u8 *) (ip + 1);
Hai Shalom74f70d42019-02-11 14:42:39 -08009101 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009102 *dpos++ = i;
9103
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009104 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom74f70d42019-02-11 14:42:39 -08009105 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009106 return -1;
9107
9108 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
9109 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
9110
9111 return 0;
9112}
9113
9114
9115static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
9116 char *cmd)
9117{
9118 u8 *buf;
9119 struct ether_header *eth;
9120 struct l2_packet_data *l2 = NULL;
9121 size_t len;
9122 u16 ethertype;
9123 int res = -1;
9124
9125 len = os_strlen(cmd);
9126 if (len & 1 || len < ETH_HLEN * 2)
9127 return -1;
9128 len /= 2;
9129
9130 buf = os_malloc(len);
9131 if (buf == NULL)
9132 return -1;
9133
9134 if (hexstr2bin(cmd, buf, len) < 0)
9135 goto done;
9136
9137 eth = (struct ether_header *) buf;
9138 ethertype = ntohs(eth->ether_type);
9139
9140 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
9141 wpas_data_test_rx, wpa_s, 1);
9142 if (l2 == NULL)
9143 goto done;
9144
9145 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
9146 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
9147done:
9148 if (l2)
9149 l2_packet_deinit(l2);
9150 os_free(buf);
9151
9152 return res < 0 ? -1 : 0;
9153}
9154
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009155
9156static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
9157{
9158#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009159 char *pos;
9160
9161 wpa_trace_fail_after = atoi(cmd);
9162 pos = os_strchr(cmd, ':');
9163 if (pos) {
9164 pos++;
9165 os_strlcpy(wpa_trace_fail_func, pos,
9166 sizeof(wpa_trace_fail_func));
9167 } else {
9168 wpa_trace_fail_after = 0;
9169 }
9170 return 0;
9171#else /* WPA_TRACE_BFD */
9172 return -1;
9173#endif /* WPA_TRACE_BFD */
9174}
9175
9176
9177static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
9178 char *buf, size_t buflen)
9179{
9180#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009181 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
9182 wpa_trace_fail_func);
9183#else /* WPA_TRACE_BFD */
9184 return -1;
9185#endif /* WPA_TRACE_BFD */
9186}
9187
Jouni Malinenc4818362015-10-04 11:45:13 +03009188
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009189static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
9190{
9191#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009192 char *pos;
9193
9194 wpa_trace_test_fail_after = atoi(cmd);
9195 pos = os_strchr(cmd, ':');
9196 if (pos) {
9197 pos++;
9198 os_strlcpy(wpa_trace_test_fail_func, pos,
9199 sizeof(wpa_trace_test_fail_func));
9200 } else {
9201 wpa_trace_test_fail_after = 0;
9202 }
9203 return 0;
9204#else /* WPA_TRACE_BFD */
9205 return -1;
9206#endif /* WPA_TRACE_BFD */
9207}
9208
9209
9210static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
9211 char *buf, size_t buflen)
9212{
9213#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009214 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
9215 wpa_trace_test_fail_func);
9216#else /* WPA_TRACE_BFD */
9217 return -1;
9218#endif /* WPA_TRACE_BFD */
9219}
9220
9221
Jouni Malinenc4818362015-10-04 11:45:13 +03009222static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
9223{
9224 struct wpa_supplicant *wpa_s = eloop_ctx;
9225 int i, count = (intptr_t) timeout_ctx;
9226
9227 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
9228 count);
9229 for (i = 0; i < count; i++) {
9230 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
9231 i + 1, count);
9232 }
9233}
9234
9235
9236static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
9237{
9238 int count;
9239
9240 count = atoi(cmd);
9241 if (count <= 0)
9242 return -1;
9243
9244 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
9245 (void *) (intptr_t) count);
9246}
9247
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009248
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009249static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
9250 const char *cmd)
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009251{
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009252 struct wpabuf *buf;
9253 size_t len;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009254
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009255 len = os_strlen(cmd);
9256 if (len & 1)
9257 return -1;
9258 len /= 2;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009259
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009260 if (len == 0) {
9261 buf = NULL;
9262 } else {
9263 buf = wpabuf_alloc(len);
9264 if (buf == NULL)
9265 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009266
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009267 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
9268 wpabuf_free(buf);
9269 return -1;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009270 }
9271 }
9272
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009273 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
9274 return 0;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009275}
9276
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009277
9278static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
9279{
9280 u8 zero[WPA_TK_MAX_LEN];
9281
9282 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
9283 return -1;
9284
9285 wpa_printf(MSG_INFO, "TESTING: Reset PN");
9286 os_memset(zero, 0, sizeof(zero));
9287
9288 /* First, use a zero key to avoid any possible duplicate key avoidance
9289 * in the driver. */
9290 if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9291 wpa_s->last_tk_key_idx, 1, zero, 6,
9292 zero, wpa_s->last_tk_len) < 0)
9293 return -1;
9294
9295 /* Set the previously configured key to reset its TSC/RSC */
9296 return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9297 wpa_s->last_tk_key_idx, 1, zero, 6,
9298 wpa_s->last_tk, wpa_s->last_tk_len);
9299}
9300
9301
9302static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
9303{
9304 const char *pos = cmd;
9305 int error, pairwise;
9306
9307 error = atoi(pos);
9308 pos = os_strchr(pos, ' ');
9309 if (!pos)
9310 return -1;
9311 pairwise = atoi(pos);
9312 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
9313 return 0;
9314}
9315
9316
9317static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
9318{
9319#ifdef CONFIG_SME
9320 struct wpa_driver_associate_params params;
9321 int ret;
9322
9323 os_memset(&params, 0, sizeof(params));
9324 params.bssid = wpa_s->bssid;
9325 params.ssid = wpa_s->sme.ssid;
9326 params.ssid_len = wpa_s->sme.ssid_len;
9327 params.freq.freq = wpa_s->sme.freq;
9328 if (wpa_s->last_assoc_req_wpa_ie) {
9329 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
9330 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
9331 }
9332 params.pairwise_suite = wpa_s->pairwise_cipher;
9333 params.group_suite = wpa_s->group_cipher;
9334 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
9335 params.key_mgmt_suite = wpa_s->key_mgmt;
9336 params.wpa_proto = wpa_s->wpa_proto;
9337 params.mgmt_frame_protection = wpa_s->sme.mfp;
9338 params.rrm_used = wpa_s->rrm.rrm_used;
9339 if (wpa_s->sme.prev_bssid_set)
9340 params.prev_bssid = wpa_s->sme.prev_bssid;
9341 wpa_printf(MSG_INFO, "TESTING: Resend association request");
9342 ret = wpa_drv_associate(wpa_s, &params);
9343 wpa_s->testing_resend_assoc = 1;
9344 return ret;
9345#else /* CONFIG_SME */
9346 return -1;
9347#endif /* CONFIG_SME */
9348}
9349
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009350#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009351
9352
9353static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
9354{
9355 char *pos = cmd;
9356 int frame;
9357 size_t len;
9358 struct wpabuf *buf;
9359 struct ieee802_11_elems elems;
9360
9361 frame = atoi(pos);
9362 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9363 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009364 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009365
9366 pos = os_strchr(pos, ' ');
9367 if (pos == NULL)
9368 return -1;
9369 pos++;
9370
9371 len = os_strlen(pos);
9372 if (len == 0)
9373 return 0;
9374 if (len & 1)
9375 return -1;
9376 len /= 2;
9377
9378 buf = wpabuf_alloc(len);
9379 if (buf == NULL)
9380 return -1;
9381
9382 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
9383 wpabuf_free(buf);
9384 return -1;
9385 }
9386
9387 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
9388 ParseFailed) {
9389 wpabuf_free(buf);
9390 return -1;
9391 }
9392
9393 if (wpa_s->vendor_elem[frame] == NULL) {
9394 wpa_s->vendor_elem[frame] = buf;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009395 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009396 return 0;
9397 }
9398
9399 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
9400 wpabuf_free(buf);
9401 return -1;
9402 }
9403
9404 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
9405 wpabuf_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009406 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009407
9408 return 0;
9409}
9410
9411
9412static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
9413 char *buf, size_t buflen)
9414{
9415 int frame = atoi(cmd);
9416
9417 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9418 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009419 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009420
9421 if (wpa_s->vendor_elem[frame] == NULL)
9422 return 0;
9423
9424 return wpa_snprintf_hex(buf, buflen,
9425 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
9426 wpabuf_len(wpa_s->vendor_elem[frame]));
9427}
9428
9429
9430static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
9431{
9432 char *pos = cmd;
9433 int frame;
9434 size_t len;
9435 u8 *buf;
9436 struct ieee802_11_elems elems;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009437 int res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009438
9439 frame = atoi(pos);
9440 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9441 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009442 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009443
9444 pos = os_strchr(pos, ' ');
9445 if (pos == NULL)
9446 return -1;
9447 pos++;
9448
9449 if (*pos == '*') {
9450 wpabuf_free(wpa_s->vendor_elem[frame]);
9451 wpa_s->vendor_elem[frame] = NULL;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009452 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009453 return 0;
9454 }
9455
9456 if (wpa_s->vendor_elem[frame] == NULL)
9457 return -1;
9458
9459 len = os_strlen(pos);
9460 if (len == 0)
9461 return 0;
9462 if (len & 1)
9463 return -1;
9464 len /= 2;
9465
9466 buf = os_malloc(len);
9467 if (buf == NULL)
9468 return -1;
9469
9470 if (hexstr2bin(pos, buf, len) < 0) {
9471 os_free(buf);
9472 return -1;
9473 }
9474
9475 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
9476 os_free(buf);
9477 return -1;
9478 }
9479
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009480 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009481 os_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009482 return res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009483}
9484
9485
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009486static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
9487{
9488 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009489 size_t len;
9490 const u8 *data;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009491
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009492 /*
9493 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9494 * BSSID[6]
9495 * BSSID Information[4]
9496 * Operating Class[1]
9497 * Channel Number[1]
9498 * PHY Type[1]
9499 * Optional Subelements[variable]
9500 */
9501#define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9502
9503 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009504 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009505 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009506 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009507
9508 data = wpabuf_head_u8(neighbor_rep);
9509 len = wpabuf_len(neighbor_rep);
9510
9511 while (len >= 2 + NR_IE_MIN_LEN) {
9512 const u8 *nr;
9513 char lci[256 * 2 + 1];
9514 char civic[256 * 2 + 1];
9515 u8 nr_len = data[1];
9516 const u8 *pos = data, *end;
9517
9518 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
9519 nr_len < NR_IE_MIN_LEN) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08009520 wpa_dbg(wpa_s, MSG_DEBUG,
9521 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9522 data[0], nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009523 goto out;
9524 }
9525
9526 if (2U + nr_len > len) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08009527 wpa_dbg(wpa_s, MSG_DEBUG,
9528 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9529 data[0], len, nr_len);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009530 goto out;
9531 }
9532 pos += 2;
9533 end = pos + nr_len;
9534
9535 nr = pos;
9536 pos += NR_IE_MIN_LEN;
9537
9538 lci[0] = '\0';
9539 civic[0] = '\0';
9540 while (end - pos > 2) {
9541 u8 s_id, s_len;
9542
9543 s_id = *pos++;
9544 s_len = *pos++;
9545 if (s_len > end - pos)
9546 goto out;
9547 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
9548 /* Measurement Token[1] */
9549 /* Measurement Report Mode[1] */
9550 /* Measurement Type[1] */
9551 /* Measurement Report[variable] */
9552 switch (pos[2]) {
9553 case MEASURE_TYPE_LCI:
9554 if (lci[0])
9555 break;
9556 wpa_snprintf_hex(lci, sizeof(lci),
9557 pos, s_len);
9558 break;
9559 case MEASURE_TYPE_LOCATION_CIVIC:
9560 if (civic[0])
9561 break;
9562 wpa_snprintf_hex(civic, sizeof(civic),
9563 pos, s_len);
9564 break;
9565 }
9566 }
9567
9568 pos += s_len;
9569 }
9570
9571 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
9572 "bssid=" MACSTR
9573 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9574 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
9575 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
9576 nr[ETH_ALEN + 6],
9577 lci[0] ? " lci=" : "", lci,
9578 civic[0] ? " civic=" : "", civic);
9579
9580 data = end;
9581 len -= 2 + nr_len;
9582 }
9583
9584out:
9585 wpabuf_free(neighbor_rep);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009586}
9587
9588
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009589static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
9590 char *cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009591{
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009592 struct wpa_ssid_value ssid, *ssid_p = NULL;
9593 int ret, lci = 0, civic = 0;
9594 char *ssid_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009595
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009596 ssid_s = os_strstr(cmd, "ssid=");
9597 if (ssid_s) {
9598 if (ssid_parse(ssid_s + 5, &ssid)) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08009599 wpa_msg(wpa_s, MSG_INFO,
9600 "CTRL: Send Neighbor Report: bad SSID");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009601 return -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009602 }
9603
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009604 ssid_p = &ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009605
9606 /*
9607 * Move cmd after the SSID text that may include "lci" or
9608 * "civic".
9609 */
9610 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
9611 if (cmd)
9612 cmd++;
9613
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009614 }
9615
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009616 if (cmd && os_strstr(cmd, "lci"))
9617 lci = 1;
9618
9619 if (cmd && os_strstr(cmd, "civic"))
9620 civic = 1;
9621
9622 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009623 wpas_ctrl_neighbor_rep_cb,
9624 wpa_s);
9625
9626 return ret;
9627}
9628
9629
9630static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
9631{
9632 eapol_sm_erp_flush(wpa_s->eapol);
9633 return 0;
9634}
9635
9636
9637static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
9638 char *cmd)
9639{
9640 char *token, *context = NULL;
9641 unsigned int enable = ~0, type = 0;
9642 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
9643 u8 *addr = NULL, *mask = NULL;
9644
9645 while ((token = str_token(cmd, " ", &context))) {
9646 if (os_strcasecmp(token, "scan") == 0) {
9647 type |= MAC_ADDR_RAND_SCAN;
9648 } else if (os_strcasecmp(token, "sched") == 0) {
9649 type |= MAC_ADDR_RAND_SCHED_SCAN;
9650 } else if (os_strcasecmp(token, "pno") == 0) {
9651 type |= MAC_ADDR_RAND_PNO;
9652 } else if (os_strcasecmp(token, "all") == 0) {
9653 type = wpa_s->mac_addr_rand_supported;
9654 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
9655 enable = atoi(token + 7);
9656 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
9657 addr = _addr;
9658 if (hwaddr_aton(token + 5, addr)) {
9659 wpa_printf(MSG_INFO,
9660 "CTRL: Invalid MAC address: %s",
9661 token);
9662 return -1;
9663 }
9664 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
9665 mask = _mask;
9666 if (hwaddr_aton(token + 5, mask)) {
9667 wpa_printf(MSG_INFO,
9668 "CTRL: Invalid MAC address mask: %s",
9669 token);
9670 return -1;
9671 }
9672 } else {
9673 wpa_printf(MSG_INFO,
9674 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9675 token);
9676 return -1;
9677 }
9678 }
9679
9680 if (!type) {
9681 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
9682 return -1;
9683 }
9684
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009685 if (enable > 1) {
9686 wpa_printf(MSG_INFO,
9687 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9688 return -1;
9689 }
9690
Hai Shalom81f62d82019-07-22 12:10:00 -07009691 if (!enable)
9692 return wpas_disable_mac_addr_randomization(wpa_s, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009693
Hai Shalom81f62d82019-07-22 12:10:00 -07009694 return wpas_enable_mac_addr_randomization(wpa_s, type, addr, mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009695}
9696
9697
Dmitry Shmidte4663042016-04-04 10:07:49 -07009698static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
9699 char *buf, size_t buflen)
9700{
9701 size_t reply_len;
9702
9703 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
9704#ifdef CONFIG_AP
9705 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
9706 buflen - reply_len);
9707#endif /* CONFIG_AP */
9708 return reply_len;
9709}
9710
9711
9712static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
9713{
9714 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
9715#ifdef CONFIG_AP
9716 wpas_ap_pmksa_cache_flush(wpa_s);
9717#endif /* CONFIG_AP */
9718}
9719
9720
Dmitry Shmidt29333592017-01-09 12:27:11 -08009721#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9722
9723static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
9724 const char *cmd, char *buf, size_t buflen)
9725{
9726 struct rsn_pmksa_cache_entry *entry;
9727 struct wpa_ssid *ssid;
9728 char *pos, *pos2, *end;
9729 int ret;
9730 struct os_reltime now;
9731
9732 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
9733 if (!ssid)
9734 return -1;
9735
9736 pos = buf;
9737 end = buf + buflen;
9738
9739 os_get_reltime(&now);
9740
9741 /*
9742 * Entry format:
9743 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9744 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009745 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -08009746 */
9747
9748 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
9749 entry = entry->next) {
9750 if (entry->network_ctx != ssid)
9751 continue;
9752
9753 pos2 = pos;
9754 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
9755 MAC2STR(entry->aa));
9756 if (os_snprintf_error(end - pos2, ret))
9757 break;
9758 pos2 += ret;
9759
9760 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
9761 PMKID_LEN);
9762
9763 ret = os_snprintf(pos2, end - pos2, " ");
9764 if (os_snprintf_error(end - pos2, ret))
9765 break;
9766 pos2 += ret;
9767
9768 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
9769 entry->pmk_len);
9770
9771 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
9772 (int) (entry->reauth_time - now.sec),
9773 (int) (entry->expiration - now.sec),
9774 entry->akmp,
9775 entry->opportunistic);
9776 if (os_snprintf_error(end - pos2, ret))
9777 break;
9778 pos2 += ret;
9779
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009780 if (entry->fils_cache_id_set) {
9781 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
9782 entry->fils_cache_id[0],
9783 entry->fils_cache_id[1]);
9784 if (os_snprintf_error(end - pos2, ret))
9785 break;
9786 pos2 += ret;
9787 }
9788
Dmitry Shmidt29333592017-01-09 12:27:11 -08009789 ret = os_snprintf(pos2, end - pos2, "\n");
9790 if (os_snprintf_error(end - pos2, ret))
9791 break;
9792 pos2 += ret;
9793
9794 pos = pos2;
9795 }
9796
9797 return pos - buf;
9798}
9799
9800
9801static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
9802 char *cmd)
9803{
9804 struct rsn_pmksa_cache_entry *entry;
9805 struct wpa_ssid *ssid;
9806 char *pos, *pos2;
9807 int ret = -1;
9808 struct os_reltime now;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009809 int reauth_time = 0, expiration = 0, i;
Dmitry Shmidt29333592017-01-09 12:27:11 -08009810
9811 /*
9812 * Entry format:
9813 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9814 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009815 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -08009816 */
9817
9818 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
9819 if (!ssid)
9820 return -1;
9821
9822 pos = os_strchr(cmd, ' ');
9823 if (!pos)
9824 return -1;
9825 pos++;
9826
9827 entry = os_zalloc(sizeof(*entry));
9828 if (!entry)
9829 return -1;
9830
9831 if (hwaddr_aton(pos, entry->aa))
9832 goto fail;
9833
9834 pos = os_strchr(pos, ' ');
9835 if (!pos)
9836 goto fail;
9837 pos++;
9838
9839 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
9840 goto fail;
9841
9842 pos = os_strchr(pos, ' ');
9843 if (!pos)
9844 goto fail;
9845 pos++;
9846
9847 pos2 = os_strchr(pos, ' ');
9848 if (!pos2)
9849 goto fail;
9850 entry->pmk_len = (pos2 - pos) / 2;
9851 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
9852 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
9853 goto fail;
9854
9855 pos = os_strchr(pos, ' ');
9856 if (!pos)
9857 goto fail;
9858 pos++;
9859
9860 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
9861 &entry->akmp, &entry->opportunistic) != 4)
9862 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009863 for (i = 0; i < 4; i++) {
9864 pos = os_strchr(pos, ' ');
9865 if (!pos) {
9866 if (i < 3)
9867 goto fail;
9868 break;
9869 }
9870 pos++;
9871 }
9872 if (pos) {
9873 if (hexstr2bin(pos, entry->fils_cache_id,
9874 FILS_CACHE_ID_LEN) < 0)
9875 goto fail;
9876 entry->fils_cache_id_set = 1;
9877 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08009878 os_get_reltime(&now);
9879 entry->expiration = now.sec + expiration;
9880 entry->reauth_time = now.sec + reauth_time;
9881
9882 entry->network_ctx = ssid;
9883
9884 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
9885 entry = NULL;
9886 ret = 0;
9887fail:
9888 os_free(entry);
9889 return ret;
9890}
9891
Paul Stewart092955c2017-02-06 09:13:09 -08009892
9893#ifdef CONFIG_MESH
9894
9895static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
9896 const char *cmd, char *buf,
9897 size_t buflen)
9898{
9899 u8 spa[ETH_ALEN];
9900
9901 if (!wpa_s->ifmsh)
9902 return -1;
9903
9904 if (os_strcasecmp(cmd, "any") == 0)
9905 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
9906
9907 if (hwaddr_aton(cmd, spa))
9908 return -1;
9909
9910 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
9911}
9912
9913
9914static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
9915 char *cmd)
9916{
9917 /*
9918 * We do not check mesh interface existance because PMKSA should be
9919 * stored before wpa_s->ifmsh creation to suppress commit message
9920 * creation.
9921 */
9922 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
9923}
9924
9925#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -08009926#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9927
9928
Paul Stewart092955c2017-02-06 09:13:09 -08009929#ifdef CONFIG_FILS
9930static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
9931 const char *cmd)
9932{
9933 struct fils_hlp_req *req;
9934 const char *pos;
9935
9936 /* format: <dst> <packet starting from ethertype> */
9937
9938 req = os_zalloc(sizeof(*req));
9939 if (!req)
9940 return -1;
9941
9942 if (hwaddr_aton(cmd, req->dst))
9943 goto fail;
9944
9945 pos = os_strchr(cmd, ' ');
9946 if (!pos)
9947 goto fail;
9948 pos++;
9949 req->pkt = wpabuf_parse_bin(pos);
9950 if (!req->pkt)
9951 goto fail;
9952
9953 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
9954 return 0;
9955fail:
9956 wpabuf_free(req->pkt);
9957 os_free(req);
9958 return -1;
9959}
9960#endif /* CONFIG_FILS */
9961
9962
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009963static int wpas_ctrl_cmd_debug_level(const char *cmd)
9964{
9965 if (os_strcmp(cmd, "PING") == 0 ||
9966 os_strncmp(cmd, "BSS ", 4) == 0 ||
9967 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
9968 os_strncmp(cmd, "STATUS", 6) == 0 ||
9969 os_strncmp(cmd, "STA ", 4) == 0 ||
9970 os_strncmp(cmd, "STA-", 4) == 0)
9971 return MSG_EXCESSIVE;
9972 return MSG_DEBUG;
9973}
9974
9975
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009976char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
9977 char *buf, size_t *resp_len)
9978{
9979 char *reply;
9980 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009981 int reply_len;
9982
9983 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009984 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
9985 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
9986 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009987 if (wpa_debug_show_keys)
9988 wpa_dbg(wpa_s, MSG_DEBUG,
9989 "Control interface command '%s'", buf);
9990 else
9991 wpa_dbg(wpa_s, MSG_DEBUG,
9992 "Control interface command '%s [REMOVED]'",
9993 os_strncmp(buf, WPA_CTRL_RSP,
9994 os_strlen(WPA_CTRL_RSP)) == 0 ?
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009995 WPA_CTRL_RSP :
9996 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
9997 "SET_NETWORK" : "key-add"));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009998 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
Dmitry Shmidt21de2142014-04-08 10:50:52 -07009999 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010000 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
10001 (const u8 *) buf, os_strlen(buf));
10002 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010003 int level = wpas_ctrl_cmd_debug_level(buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -070010004 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010005 }
10006
10007 reply = os_malloc(reply_size);
10008 if (reply == NULL) {
10009 *resp_len = 1;
10010 return NULL;
10011 }
10012
10013 os_memcpy(reply, "OK\n", 3);
10014 reply_len = 3;
10015
10016 if (os_strcmp(buf, "PING") == 0) {
10017 os_memcpy(reply, "PONG\n", 5);
10018 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010019 } else if (os_strcmp(buf, "IFNAME") == 0) {
10020 reply_len = os_strlen(wpa_s->ifname);
10021 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010022 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
10023 if (wpa_debug_reopen_file() < 0)
10024 reply_len = -1;
10025 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
10026 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
10027 } else if (os_strcmp(buf, "MIB") == 0) {
10028 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
10029 if (reply_len >= 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010030 reply_len += eapol_sm_get_mib(wpa_s->eapol,
10031 reply + reply_len,
10032 reply_size - reply_len);
Hai Shalom74f70d42019-02-11 14:42:39 -080010033#ifdef CONFIG_MACSEC
10034 reply_len += ieee802_1x_kay_get_mib(
10035 wpa_s->kay, reply + reply_len,
10036 reply_size - reply_len);
10037#endif /* CONFIG_MACSEC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010038 }
10039 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
10040 reply_len = wpa_supplicant_ctrl_iface_status(
10041 wpa_s, buf + 6, reply, reply_size);
10042 } else if (os_strcmp(buf, "PMKSA") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070010043 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070010044 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -070010045 wpas_ctrl_iface_pmksa_flush(wpa_s);
Dmitry Shmidt29333592017-01-09 12:27:11 -080010046#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
10047 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
10048 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
10049 reply, reply_size);
10050 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
10051 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
10052 reply_len = -1;
Paul Stewart092955c2017-02-06 09:13:09 -080010053#ifdef CONFIG_MESH
10054 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
10055 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
10056 reply, reply_size);
10057 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
10058 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
10059 reply_len = -1;
10060#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -080010061#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010062 } else if (os_strncmp(buf, "SET ", 4) == 0) {
10063 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
10064 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010065 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
10066 reply_len = wpa_config_dump_values(wpa_s->conf,
10067 reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010068 } else if (os_strncmp(buf, "GET ", 4) == 0) {
10069 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
10070 reply, reply_size);
10071 } else if (os_strcmp(buf, "LOGON") == 0) {
10072 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
10073 } else if (os_strcmp(buf, "LOGOFF") == 0) {
10074 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
10075 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
10076 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
10077 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010078 else
10079 wpas_request_connection(wpa_s);
Dmitry Shmidt98660862014-03-11 17:26:21 -070010080 } else if (os_strcmp(buf, "REATTACH") == 0) {
10081 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
10082 !wpa_s->current_ssid)
10083 reply_len = -1;
10084 else {
10085 wpa_s->reattach = 1;
10086 wpas_request_connection(wpa_s);
10087 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010088 } else if (os_strcmp(buf, "RECONNECT") == 0) {
10089 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
10090 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010091 else if (wpa_s->disconnected)
10092 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010093#ifdef IEEE8021X_EAPOL
10094 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
10095 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
10096 reply_len = -1;
10097#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010098#ifdef CONFIG_IEEE80211R
10099 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
10100 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
10101 reply_len = -1;
10102#endif /* CONFIG_IEEE80211R */
10103#ifdef CONFIG_WPS
10104 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
10105 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
10106 if (res == -2) {
10107 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10108 reply_len = 17;
10109 } else if (res)
10110 reply_len = -1;
10111 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
10112 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
10113 if (res == -2) {
10114 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10115 reply_len = 17;
10116 } else if (res)
10117 reply_len = -1;
10118 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
10119 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
10120 reply,
10121 reply_size);
10122 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
10123 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
10124 wpa_s, buf + 14, reply, reply_size);
10125 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
10126 if (wpas_wps_cancel(wpa_s))
10127 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010128#ifdef CONFIG_WPS_NFC
10129 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
10130 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
10131 reply_len = -1;
10132 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
10133 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
10134 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -080010135 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
10136 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
10137 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010138 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
10139 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
10140 wpa_s, buf + 14, reply, reply_size);
10141 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
10142 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
10143 buf + 17))
10144 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010145 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
10146 reply_len = wpas_ctrl_nfc_get_handover_req(
10147 wpa_s, buf + 21, reply, reply_size);
10148 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
10149 reply_len = wpas_ctrl_nfc_get_handover_sel(
10150 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -080010151 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
10152 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
10153 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010154#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010155 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
10156 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
10157 reply_len = -1;
10158#ifdef CONFIG_AP
10159 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
10160 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
10161 wpa_s, buf + 11, reply, reply_size);
10162#endif /* CONFIG_AP */
10163#ifdef CONFIG_WPS_ER
10164 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
10165 if (wpas_wps_er_start(wpa_s, NULL))
10166 reply_len = -1;
10167 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
10168 if (wpas_wps_er_start(wpa_s, buf + 13))
10169 reply_len = -1;
10170 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010171 wpas_wps_er_stop(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010172 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
10173 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
10174 reply_len = -1;
10175 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
10176 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
10177 if (ret == -2) {
10178 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10179 reply_len = 17;
10180 } else if (ret == -3) {
10181 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
10182 reply_len = 18;
10183 } else if (ret == -4) {
10184 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
10185 reply_len = 20;
10186 } else if (ret)
10187 reply_len = -1;
10188 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
10189 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
10190 reply_len = -1;
10191 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
10192 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
10193 buf + 18))
10194 reply_len = -1;
10195 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
10196 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
10197 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010198#ifdef CONFIG_WPS_NFC
10199 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10200 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10201 wpa_s, buf + 24, reply, reply_size);
10202#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010203#endif /* CONFIG_WPS_ER */
10204#endif /* CONFIG_WPS */
10205#ifdef CONFIG_IBSS_RSN
10206 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
10207 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
10208 reply_len = -1;
10209#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010210#ifdef CONFIG_MESH
10211 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
10212 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10213 wpa_s, buf + 19, reply, reply_size);
10214 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
10215 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10216 wpa_s, "", reply, reply_size);
10217 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
10218 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
10219 reply_len = -1;
10220 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
10221 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
10222 buf + 18))
10223 reply_len = -1;
Dmitry Shmidte4663042016-04-04 10:07:49 -070010224 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
10225 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
10226 reply_len = -1;
10227 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
10228 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
10229 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070010230 } else if (os_strncmp(buf, "MESH_LINK_PROBE ", 16) == 0) {
10231 if (wpa_supplicant_ctrl_iface_mesh_link_probe(wpa_s, buf + 16))
10232 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010233#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010234#ifdef CONFIG_P2P
10235 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010236 if (p2p_ctrl_find(wpa_s, buf + 8))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010237 reply_len = -1;
10238 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
10239 if (p2p_ctrl_find(wpa_s, ""))
10240 reply_len = -1;
10241 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
10242 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010243 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
10244 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
10245 reply_len = -1;
10246 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10247 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
10248 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010249 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
10250 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
10251 reply_size);
10252 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
10253 if (p2p_ctrl_listen(wpa_s, buf + 11))
10254 reply_len = -1;
10255 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
10256 if (p2p_ctrl_listen(wpa_s, ""))
10257 reply_len = -1;
10258 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
10259 if (wpas_p2p_group_remove(wpa_s, buf + 17))
10260 reply_len = -1;
10261 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070010262 if (p2p_ctrl_group_add(wpa_s, ""))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010263 reply_len = -1;
10264 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
10265 if (p2p_ctrl_group_add(wpa_s, buf + 14))
10266 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010267 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
10268 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
10269 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010270 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
10271 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
10272 reply_len = -1;
10273 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
10274 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
10275 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
10276 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
10277 reply_size);
10278 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10279 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
10280 reply_len = -1;
10281 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
10282 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
10283 reply_len = -1;
10284 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
10285 wpas_p2p_sd_service_update(wpa_s);
10286 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10287 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
10288 reply_len = -1;
10289 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
10290 wpas_p2p_service_flush(wpa_s);
10291 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
10292 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
10293 reply_len = -1;
10294 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
10295 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
10296 reply_len = -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010297 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
10298 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
10299 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010300 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
10301 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
10302 reply_len = -1;
10303 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
10304 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
10305 reply_len = -1;
10306 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
10307 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
10308 reply_size);
10309 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
10310 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
10311 reply_len = -1;
10312 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -070010313 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010314 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
10315 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
10316 reply_len = -1;
10317 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
10318 if (wpas_p2p_cancel(wpa_s))
10319 reply_len = -1;
10320 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
10321 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
10322 reply_len = -1;
10323 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
10324 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
10325 reply_len = -1;
10326 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
10327 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
10328 reply_len = -1;
10329 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
10330 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
10331 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070010332 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
10333 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
10334 reply_len = -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010335 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
10336 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
10337 reply_len = -1;
10338 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
10339 if (wpas_p2p_lo_stop(wpa_s))
10340 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010341#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010342#ifdef CONFIG_WIFI_DISPLAY
10343 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
10344 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
10345 reply_len = -1;
10346 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
10347 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
10348 reply, reply_size);
10349#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010350#ifdef CONFIG_INTERWORKING
10351 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
10352 if (interworking_fetch_anqp(wpa_s) < 0)
10353 reply_len = -1;
10354 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
10355 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010356 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
10357 if (ctrl_interworking_select(wpa_s, NULL) < 0)
10358 reply_len = -1;
10359 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
10360 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010361 reply_len = -1;
10362 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010363 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010364 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010365 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10366 int id;
10367
10368 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
10369 if (id < 0)
10370 reply_len = -1;
10371 else {
10372 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
10373 if (os_snprintf_error(reply_size, reply_len))
10374 reply_len = -1;
10375 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010376 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
10377 if (get_anqp(wpa_s, buf + 9) < 0)
10378 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010379 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
10380 if (gas_request(wpa_s, buf + 12) < 0)
10381 reply_len = -1;
10382 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
10383 reply_len = gas_response_get(wpa_s, buf + 17, reply,
10384 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010385#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -070010386#ifdef CONFIG_HS20
10387 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
10388 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
10389 reply_len = -1;
10390 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10391 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
10392 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010393 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080010394 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
10395 reply_len = -1;
10396 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
10397 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
10398 reply_len = -1;
10399 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
10400 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
10401 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
10402 if (del_hs20_icon(wpa_s, buf + 14) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010403 reply_len = -1;
10404 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010405 if (hs20_fetch_osu(wpa_s, 0) < 0)
10406 reply_len = -1;
10407 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
10408 if (hs20_fetch_osu(wpa_s, 1) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010409 reply_len = -1;
10410 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
10411 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010412#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010413 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
10414 {
10415 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10416 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
10417 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -070010418 else {
10419 /*
10420 * Notify response from timeout to allow the control
10421 * interface response to be sent first.
10422 */
10423 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
10424 wpa_s, NULL);
10425 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010426 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
10427 if (wpa_supplicant_reload_configuration(wpa_s))
10428 reply_len = -1;
10429 } else if (os_strcmp(buf, "TERMINATE") == 0) {
10430 wpa_supplicant_terminate_proc(wpa_s->global);
10431 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
10432 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
10433 reply_len = -1;
Dmitry Shmidte19501d2011-03-16 14:32:18 -070010434 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010435 reply_len = wpa_supplicant_ctrl_iface_blacklist(
10436 wpa_s, buf + 9, reply, reply_size);
10437 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
10438 reply_len = wpa_supplicant_ctrl_iface_log_level(
10439 wpa_s, buf + 9, reply, reply_size);
Vinit Deshpandeda134e92014-12-02 10:59:29 -080010440 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
10441 reply_len = wpa_supplicant_ctrl_iface_list_networks(
10442 wpa_s, buf + 14, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010443 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
10444 reply_len = wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -080010445 wpa_s, NULL, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010446 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070010447 wpas_request_disconnection(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010448 } else if (os_strcmp(buf, "SCAN") == 0) {
10449 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
10450 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
10451 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010452 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
10453 reply_len = wpa_supplicant_ctrl_iface_scan_results(
10454 wpa_s, reply, reply_size);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010455 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
10456 if (wpas_abort_ongoing_scan(wpa_s) < 0)
10457 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010458 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
10459 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
10460 reply_len = -1;
10461 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
10462 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
10463 reply_len = -1;
10464 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
10465 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
10466 reply_len = -1;
10467 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
10468 reply_len = wpa_supplicant_ctrl_iface_add_network(
10469 wpa_s, reply, reply_size);
10470 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
10471 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
10472 reply_len = -1;
10473 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
10474 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
10475 reply_len = -1;
10476 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
10477 reply_len = wpa_supplicant_ctrl_iface_get_network(
10478 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt684785c2014-05-12 13:34:29 -070010479 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010480 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
10481 wpa_s))
Dmitry Shmidt684785c2014-05-12 13:34:29 -070010482 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010483 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
10484 reply_len = wpa_supplicant_ctrl_iface_list_creds(
10485 wpa_s, reply, reply_size);
10486 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
10487 reply_len = wpa_supplicant_ctrl_iface_add_cred(
10488 wpa_s, reply, reply_size);
10489 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
10490 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
10491 reply_len = -1;
10492 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
10493 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
10494 reply_len = -1;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -070010495 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
10496 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
10497 reply,
10498 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010499#ifndef CONFIG_NO_CONFIG_WRITE
10500 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
10501 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
10502 reply_len = -1;
10503#endif /* CONFIG_NO_CONFIG_WRITE */
10504 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
10505 reply_len = wpa_supplicant_ctrl_iface_get_capability(
10506 wpa_s, buf + 15, reply, reply_size);
10507 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
10508 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
10509 reply_len = -1;
10510 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
10511 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
10512 reply_len = -1;
10513 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
10514 reply_len = wpa_supplicant_global_iface_list(
10515 wpa_s->global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010516 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010517 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010518 wpa_s->global, buf + 10, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010519 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
10520 reply_len = wpa_supplicant_ctrl_iface_bss(
10521 wpa_s, buf + 4, reply, reply_size);
10522#ifdef CONFIG_AP
10523 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
10524 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
10525 } else if (os_strncmp(buf, "STA ", 4) == 0) {
10526 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
10527 reply_size);
10528 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
10529 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
10530 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010531 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
10532 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
10533 reply_len = -1;
10534 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
10535 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
10536 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080010537 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
10538 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
10539 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010540 } else if (os_strcmp(buf, "STOP_AP") == 0) {
10541 if (wpas_ap_stop_ap(wpa_s))
10542 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010543#endif /* CONFIG_AP */
10544 } else if (os_strcmp(buf, "SUSPEND") == 0) {
10545 wpas_notify_suspend(wpa_s->global);
10546 } else if (os_strcmp(buf, "RESUME") == 0) {
10547 wpas_notify_resume(wpa_s->global);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010548#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010549 } else if (os_strcmp(buf, "DROP_SA") == 0) {
10550 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010551#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010552 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
10553 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
10554 reply_len = -1;
10555 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010556 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010557 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
10558 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
10559 reply_len = -1;
10560 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
10561 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
10562 buf + 17))
10563 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -070010564 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010565 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010566#ifdef CONFIG_TDLS
10567 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
10568 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
10569 reply_len = -1;
10570 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
10571 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
10572 reply_len = -1;
10573 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
10574 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
10575 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010576 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
10577 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
10578 buf + 17))
10579 reply_len = -1;
10580 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10581 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
10582 buf + 24))
10583 reply_len = -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -070010584 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
10585 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
10586 wpa_s, buf + 17, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010587#endif /* CONFIG_TDLS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010588 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
10589 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
10590 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
10591 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
10592 reply_len = -1;
10593 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
10594 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
10595 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010596 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
10597 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
10598 reply_size);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080010599 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
10600 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
10601 reply_len = -1;
Yuhao Zhengfcd6f212012-07-27 10:37:52 -070010602 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
10603 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
10604 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010605#ifdef CONFIG_AUTOSCAN
10606 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
10607 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
10608 reply_len = -1;
10609#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010610 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
10611 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
10612 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080010613#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -070010614 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
10615 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
10616 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080010617#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080010618 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
10619 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
10620 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010621 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010622 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010623 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080010624#ifdef CONFIG_WNM
10625 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
10626 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
10627 reply_len = -1;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080010628 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
10629 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
Dmitry Shmidt44c95782013-05-17 09:51:35 -070010630 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -080010631 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
10632 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
10633 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080010634#endif /* CONFIG_WNM */
Dmitry Shmidt444d5672013-04-01 13:08:44 -070010635 } else if (os_strcmp(buf, "FLUSH") == 0) {
10636 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010637 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
10638 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
10639 reply_size);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070010640#ifdef CONFIG_TESTING_OPTIONS
10641 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
10642 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
10643 reply_len = -1;
10644 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
10645 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010646 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
10647 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
10648 reply_len = -1;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -070010649 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
10650 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
10651 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010652 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
10653 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
10654 reply_len = -1;
10655 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
10656 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
10657 reply_len = -1;
10658 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
10659 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
10660 reply_len = -1;
10661 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
10662 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
10663 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010664 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
10665 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
10666 reply_len = -1;
10667 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
10668 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010669 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
10670 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
10671 reply_len = -1;
10672 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
10673 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
Jouni Malinenc4818362015-10-04 11:45:13 +030010674 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
10675 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
10676 reply_len = -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010677 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
10678 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
10679 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010680 } else if (os_strcmp(buf, "RESET_PN") == 0) {
10681 if (wpas_ctrl_reset_pn(wpa_s) < 0)
10682 reply_len = -1;
10683 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
10684 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
10685 reply_len = -1;
10686 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
10687 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
10688 reply_len = -1;
Hai Shalom74f70d42019-02-11 14:42:39 -080010689 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
10690 sme_event_unprot_disconnect(
10691 wpa_s, wpa_s->bssid, NULL,
10692 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070010693#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010694 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
10695 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
10696 reply_len = -1;
10697 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
10698 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
10699 reply_size);
10700 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10701 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
10702 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010703 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010704 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010705 reply_len = -1;
10706 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
10707 wpas_ctrl_iface_erp_flush(wpa_s);
10708 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
10709 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
10710 reply_len = -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010711 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
10712 reply_len = wpas_ctrl_iface_get_pref_freq_list(
10713 wpa_s, buf + 19, reply, reply_size);
Paul Stewart092955c2017-02-06 09:13:09 -080010714#ifdef CONFIG_FILS
10715 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
10716 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
10717 reply_len = -1;
10718 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
10719 wpas_flush_fils_hlp_req(wpa_s);
10720#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010721#ifdef CONFIG_DPP
10722 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
10723 int res;
10724
10725 res = wpas_dpp_qr_code(wpa_s, buf + 12);
10726 if (res < 0) {
10727 reply_len = -1;
10728 } else {
10729 reply_len = os_snprintf(reply, reply_size, "%d", res);
10730 if (os_snprintf_error(reply_size, reply_len))
10731 reply_len = -1;
10732 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080010733 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
10734 int res;
10735
10736 res = wpas_dpp_nfc_uri(wpa_s, buf + 12);
10737 if (res < 0) {
10738 reply_len = -1;
10739 } else {
10740 reply_len = os_snprintf(reply, reply_size, "%d", res);
10741 if (os_snprintf_error(reply_size, reply_len))
10742 reply_len = -1;
10743 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010744 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10745 int res;
10746
Hai Shalom021b0b52019-04-10 11:17:58 -070010747 res = dpp_bootstrap_gen(wpa_s->dpp, buf + 18);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010748 if (res < 0) {
10749 reply_len = -1;
10750 } else {
10751 reply_len = os_snprintf(reply, reply_size, "%d", res);
10752 if (os_snprintf_error(reply_size, reply_len))
10753 reply_len = -1;
10754 }
10755 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070010756 if (dpp_bootstrap_remove(wpa_s->dpp, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010757 reply_len = -1;
10758 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10759 const char *uri;
10760
Hai Shalom021b0b52019-04-10 11:17:58 -070010761 uri = dpp_bootstrap_get_uri(wpa_s->dpp, atoi(buf + 22));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010762 if (!uri) {
10763 reply_len = -1;
10764 } else {
10765 reply_len = os_snprintf(reply, reply_size, "%s", uri);
10766 if (os_snprintf_error(reply_size, reply_len))
10767 reply_len = -1;
10768 }
10769 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070010770 reply_len = dpp_bootstrap_info(wpa_s->dpp, atoi(buf + 19),
10771 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010772 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
10773 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
10774 reply_len = -1;
10775 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
10776 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
10777 reply_len = -1;
10778 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -070010779 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010780 wpas_dpp_listen_stop(wpa_s);
10781 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10782 int res;
10783
Hai Shalom021b0b52019-04-10 11:17:58 -070010784 res = dpp_configurator_add(wpa_s->dpp, buf + 20);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010785 if (res < 0) {
10786 reply_len = -1;
10787 } else {
10788 reply_len = os_snprintf(reply, reply_size, "%d", res);
10789 if (os_snprintf_error(reply_size, reply_len))
10790 reply_len = -1;
10791 }
10792 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070010793 if (dpp_configurator_remove(wpa_s->dpp, buf + 24) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010794 reply_len = -1;
10795 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -080010796 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010797 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -070010798 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -070010799 reply_len = dpp_configurator_get_key_id(wpa_s->dpp,
10800 atoi(buf + 25),
10801 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010802 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
10803 int res;
10804
10805 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
10806 if (res < 0) {
10807 reply_len = -1;
10808 } else {
10809 reply_len = os_snprintf(reply, reply_size, "%d", res);
10810 if (os_snprintf_error(reply_size, reply_len))
10811 reply_len = -1;
10812 }
10813 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
10814 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
10815 reply_len = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -070010816#ifdef CONFIG_DPP2
10817 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
10818 if (wpas_dpp_controller_start(wpa_s, buf + 20) < 0)
10819 reply_len = -1;
10820 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
10821 if (wpas_dpp_controller_start(wpa_s, NULL) < 0)
10822 reply_len = -1;
10823 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
10824 dpp_controller_stop(wpa_s->dpp);
10825#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010826#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010827 } else {
10828 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
10829 reply_len = 16;
10830 }
10831
10832 if (reply_len < 0) {
10833 os_memcpy(reply, "FAIL\n", 5);
10834 reply_len = 5;
10835 }
10836
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010837 *resp_len = reply_len;
10838 return reply;
10839}
10840
10841
10842static int wpa_supplicant_global_iface_add(struct wpa_global *global,
10843 char *cmd)
10844{
10845 struct wpa_interface iface;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010846 char *pos, *extra;
10847 struct wpa_supplicant *wpa_s;
10848 unsigned int create_iface = 0;
10849 u8 mac_addr[ETH_ALEN];
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010850 enum wpa_driver_if_type type = WPA_IF_STATION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010851
10852 /*
10853 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010854 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010855 */
10856 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
10857
10858 os_memset(&iface, 0, sizeof(iface));
10859
10860 do {
10861 iface.ifname = pos = cmd;
10862 pos = os_strchr(pos, '\t');
10863 if (pos)
10864 *pos++ = '\0';
10865 if (iface.ifname[0] == '\0')
10866 return -1;
10867 if (pos == NULL)
10868 break;
10869
10870 iface.confname = pos;
10871 pos = os_strchr(pos, '\t');
10872 if (pos)
10873 *pos++ = '\0';
10874 if (iface.confname[0] == '\0')
10875 iface.confname = NULL;
10876 if (pos == NULL)
10877 break;
10878
10879 iface.driver = pos;
10880 pos = os_strchr(pos, '\t');
10881 if (pos)
10882 *pos++ = '\0';
10883 if (iface.driver[0] == '\0')
10884 iface.driver = NULL;
10885 if (pos == NULL)
10886 break;
10887
10888 iface.ctrl_interface = pos;
10889 pos = os_strchr(pos, '\t');
10890 if (pos)
10891 *pos++ = '\0';
10892 if (iface.ctrl_interface[0] == '\0')
10893 iface.ctrl_interface = NULL;
10894 if (pos == NULL)
10895 break;
10896
10897 iface.driver_param = pos;
10898 pos = os_strchr(pos, '\t');
10899 if (pos)
10900 *pos++ = '\0';
10901 if (iface.driver_param[0] == '\0')
10902 iface.driver_param = NULL;
10903 if (pos == NULL)
10904 break;
10905
10906 iface.bridge_ifname = pos;
10907 pos = os_strchr(pos, '\t');
10908 if (pos)
10909 *pos++ = '\0';
10910 if (iface.bridge_ifname[0] == '\0')
10911 iface.bridge_ifname = NULL;
10912 if (pos == NULL)
10913 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010914
10915 extra = pos;
10916 pos = os_strchr(pos, '\t');
10917 if (pos)
10918 *pos++ = '\0';
Dmitry Shmidt83474442015-04-15 13:47:09 -070010919 if (!extra[0])
10920 break;
10921
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010922 if (os_strcmp(extra, "create") == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010923 create_iface = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010924 if (!pos)
10925 break;
10926
10927 if (os_strcmp(pos, "sta") == 0) {
10928 type = WPA_IF_STATION;
10929 } else if (os_strcmp(pos, "ap") == 0) {
10930 type = WPA_IF_AP_BSS;
10931 } else {
10932 wpa_printf(MSG_DEBUG,
10933 "INTERFACE_ADD unsupported interface type: '%s'",
10934 pos);
10935 return -1;
10936 }
10937 } else {
Dmitry Shmidt83474442015-04-15 13:47:09 -070010938 wpa_printf(MSG_DEBUG,
10939 "INTERFACE_ADD unsupported extra parameter: '%s'",
10940 extra);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010941 return -1;
Dmitry Shmidt83474442015-04-15 13:47:09 -070010942 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010943 } while (0);
10944
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010945 if (create_iface) {
10946 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
10947 iface.ifname);
10948 if (!global->ifaces)
10949 return -1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010950 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010951 NULL, NULL, NULL, mac_addr, NULL) < 0) {
10952 wpa_printf(MSG_ERROR,
10953 "CTRL_IFACE interface creation failed");
10954 return -1;
10955 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010956
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010957 wpa_printf(MSG_DEBUG,
10958 "CTRL_IFACE interface '%s' created with MAC addr: "
10959 MACSTR, iface.ifname, MAC2STR(mac_addr));
10960 }
10961
10962 if (wpa_supplicant_get_iface(global, iface.ifname))
10963 goto fail;
10964
10965 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
10966 if (!wpa_s)
10967 goto fail;
10968 wpa_s->added_vif = create_iface;
10969 return 0;
10970
10971fail:
10972 if (create_iface)
10973 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
10974 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010975}
10976
10977
10978static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
10979 char *cmd)
10980{
10981 struct wpa_supplicant *wpa_s;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010982 int ret;
10983 unsigned int delete_iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010984
10985 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
10986
10987 wpa_s = wpa_supplicant_get_iface(global, cmd);
10988 if (wpa_s == NULL)
10989 return -1;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010990 delete_iface = wpa_s->added_vif;
10991 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
10992 if (!ret && delete_iface) {
10993 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
10994 cmd);
10995 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
10996 }
10997 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010998}
10999
11000
11001static void wpa_free_iface_info(struct wpa_interface_info *iface)
11002{
11003 struct wpa_interface_info *prev;
11004
11005 while (iface) {
11006 prev = iface;
11007 iface = iface->next;
11008
11009 os_free(prev->ifname);
11010 os_free(prev->desc);
11011 os_free(prev);
11012 }
11013}
11014
11015
11016static int wpa_supplicant_global_iface_list(struct wpa_global *global,
11017 char *buf, int len)
11018{
11019 int i, res;
11020 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
11021 char *pos, *end;
11022
11023 for (i = 0; wpa_drivers[i]; i++) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070011024 const struct wpa_driver_ops *drv = wpa_drivers[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011025 if (drv->get_interfaces == NULL)
11026 continue;
11027 tmp = drv->get_interfaces(global->drv_priv[i]);
11028 if (tmp == NULL)
11029 continue;
11030
11031 if (last == NULL)
11032 iface = last = tmp;
11033 else
11034 last->next = tmp;
11035 while (last->next)
11036 last = last->next;
11037 }
11038
11039 pos = buf;
11040 end = buf + len;
11041 for (tmp = iface; tmp; tmp = tmp->next) {
11042 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
11043 tmp->drv_name, tmp->ifname,
11044 tmp->desc ? tmp->desc : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011045 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011046 *pos = '\0';
11047 break;
11048 }
11049 pos += res;
11050 }
11051
11052 wpa_free_iface_info(iface);
11053
11054 return pos - buf;
11055}
11056
11057
11058static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011059 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011060 char *buf, int len)
11061{
11062 int res;
11063 char *pos, *end;
11064 struct wpa_supplicant *wpa_s;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011065 int show_ctrl = 0;
11066
11067 if (input)
11068 show_ctrl = !!os_strstr(input, "ctrl");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011069
11070 wpa_s = global->ifaces;
11071 pos = buf;
11072 end = buf + len;
11073
11074 while (wpa_s) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011075 if (show_ctrl)
11076 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
11077 wpa_s->ifname,
11078 wpa_s->conf->ctrl_interface ?
11079 wpa_s->conf->ctrl_interface : "N/A");
11080 else
11081 res = os_snprintf(pos, end - pos, "%s\n",
11082 wpa_s->ifname);
11083
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011084 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011085 *pos = '\0';
11086 break;
11087 }
11088 pos += res;
11089 wpa_s = wpa_s->next;
11090 }
11091 return pos - buf;
11092}
11093
11094
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011095static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
11096 const char *ifname,
11097 char *cmd, size_t *resp_len)
11098{
11099 struct wpa_supplicant *wpa_s;
11100
11101 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11102 if (os_strcmp(ifname, wpa_s->ifname) == 0)
11103 break;
11104 }
11105
11106 if (wpa_s == NULL) {
11107 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
11108 if (resp)
11109 *resp_len = os_strlen(resp);
11110 else
11111 *resp_len = 1;
11112 return resp;
11113 }
11114
11115 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
11116}
11117
11118
11119static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
11120 char *buf, size_t *resp_len)
11121{
11122#ifdef CONFIG_P2P
11123 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011124 "LIST_NETWORKS",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011125 "P2P_FIND",
11126 "P2P_STOP_FIND",
11127 "P2P_LISTEN",
11128 "P2P_GROUP_ADD",
11129 "P2P_GET_PASSPHRASE",
11130 "P2P_SERVICE_UPDATE",
11131 "P2P_SERVICE_FLUSH",
11132 "P2P_FLUSH",
11133 "P2P_CANCEL",
11134 "P2P_PRESENCE_REQ",
11135 "P2P_EXT_LISTEN",
Paul Stewart092955c2017-02-06 09:13:09 -080011136#ifdef CONFIG_AP
11137 "STA-FIRST",
11138#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011139 NULL
11140 };
11141 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080011142#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011143 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080011144#endif /* ANDROID */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011145 "GET_CAPABILITY ",
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011146 "GET_NETWORK ",
11147 "REMOVE_NETWORK ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011148 "P2P_FIND ",
11149 "P2P_CONNECT ",
11150 "P2P_LISTEN ",
11151 "P2P_GROUP_REMOVE ",
11152 "P2P_GROUP_ADD ",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011153 "P2P_GROUP_MEMBER ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011154 "P2P_PROV_DISC ",
11155 "P2P_SERV_DISC_REQ ",
11156 "P2P_SERV_DISC_CANCEL_REQ ",
11157 "P2P_SERV_DISC_RESP ",
11158 "P2P_SERV_DISC_EXTERNAL ",
11159 "P2P_SERVICE_ADD ",
11160 "P2P_SERVICE_DEL ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011161 "P2P_SERVICE_REP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011162 "P2P_REJECT ",
11163 "P2P_INVITE ",
11164 "P2P_PEER ",
11165 "P2P_SET ",
11166 "P2P_UNAUTHORIZE ",
11167 "P2P_PRESENCE_REQ ",
11168 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070011169 "P2P_REMOVE_CLIENT ",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080011170 "WPS_NFC_TOKEN ",
11171 "WPS_NFC_TAG_READ ",
Dmitry Shmidt413dde72014-04-11 10:23:22 -070011172 "NFC_GET_HANDOVER_SEL ",
11173 "NFC_GET_HANDOVER_REQ ",
11174 "NFC_REPORT_HANDOVER ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011175 "P2P_ASP_PROVISION ",
11176 "P2P_ASP_PROVISION_RESP ",
Paul Stewart092955c2017-02-06 09:13:09 -080011177#ifdef CONFIG_AP
11178 "STA ",
11179 "STA-NEXT ",
11180#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011181 NULL
11182 };
11183 int found = 0;
11184 int i;
11185
11186 if (global->p2p_init_wpa_s == NULL)
11187 return NULL;
11188
11189 for (i = 0; !found && cmd[i]; i++) {
11190 if (os_strcmp(buf, cmd[i]) == 0)
11191 found = 1;
11192 }
11193
11194 for (i = 0; !found && prefix[i]; i++) {
11195 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
11196 found = 1;
11197 }
11198
11199 if (found)
11200 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11201 buf, resp_len);
11202#endif /* CONFIG_P2P */
11203 return NULL;
11204}
11205
11206
11207static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
11208 char *buf, size_t *resp_len)
11209{
11210#ifdef CONFIG_WIFI_DISPLAY
11211 if (global->p2p_init_wpa_s == NULL)
11212 return NULL;
11213 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
11214 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
11215 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11216 buf, resp_len);
11217#endif /* CONFIG_WIFI_DISPLAY */
11218 return NULL;
11219}
11220
11221
11222static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
11223 char *buf, size_t *resp_len)
11224{
11225 char *ret;
11226
11227 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
11228 if (ret)
11229 return ret;
11230
11231 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
11232 if (ret)
11233 return ret;
11234
11235 return NULL;
11236}
11237
11238
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011239static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
11240{
11241 char *value;
11242
11243 value = os_strchr(cmd, ' ');
11244 if (value == NULL)
11245 return -1;
11246 *value++ = '\0';
11247
11248 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
11249
11250#ifdef CONFIG_WIFI_DISPLAY
11251 if (os_strcasecmp(cmd, "wifi_display") == 0) {
11252 wifi_display_enable(global, !!atoi(value));
11253 return 0;
11254 }
11255#endif /* CONFIG_WIFI_DISPLAY */
11256
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011257 /* Restore cmd to its original value to allow redirection */
11258 value[-1] = ' ';
11259
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011260 return -1;
11261}
11262
11263
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011264static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
11265 char *cmd)
11266{
11267 struct wpa_supplicant *wpa_s[2]; /* src, dst */
11268 char *p;
11269 unsigned int i;
11270
11271 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11272 * <variable name> */
11273
11274 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
11275 p = os_strchr(cmd, ' ');
11276 if (p == NULL)
11277 return -1;
11278 *p = '\0';
11279
11280 wpa_s[i] = global->ifaces;
11281 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
11282 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
11283 break;
11284 }
11285
11286 if (!wpa_s[i]) {
11287 wpa_printf(MSG_DEBUG,
11288 "CTRL_IFACE: Could not find iface=%s", cmd);
11289 return -1;
11290 }
11291
11292 cmd = p + 1;
11293 }
11294
11295 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
11296}
11297
11298
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011299#ifndef CONFIG_NO_CONFIG_WRITE
11300static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
11301{
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011302 int ret = 0, saved = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011303 struct wpa_supplicant *wpa_s;
11304
11305 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11306 if (!wpa_s->conf->update_config) {
11307 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11308 continue;
11309 }
11310
11311 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
11312 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11313 ret = 1;
11314 } else {
11315 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011316 saved++;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011317 }
11318 }
11319
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011320 if (!saved && !ret) {
11321 wpa_dbg(wpa_s, MSG_DEBUG,
11322 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11323 ret = 1;
11324 }
11325
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011326 return ret;
11327}
11328#endif /* CONFIG_NO_CONFIG_WRITE */
11329
11330
11331static int wpas_global_ctrl_iface_status(struct wpa_global *global,
11332 char *buf, size_t buflen)
11333{
11334 char *pos, *end;
11335 int ret;
11336 struct wpa_supplicant *wpa_s;
11337
11338 pos = buf;
11339 end = buf + buflen;
11340
11341#ifdef CONFIG_P2P
11342 if (global->p2p && !global->p2p_disabled) {
11343 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
11344 "\n"
11345 "p2p_state=%s\n",
11346 MAC2STR(global->p2p_dev_addr),
11347 p2p_get_state_txt(global->p2p));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011348 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011349 return pos - buf;
11350 pos += ret;
11351 } else if (global->p2p) {
11352 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011353 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011354 return pos - buf;
11355 pos += ret;
11356 }
11357#endif /* CONFIG_P2P */
11358
11359#ifdef CONFIG_WIFI_DISPLAY
11360 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
11361 !!global->wifi_display);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011362 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011363 return pos - buf;
11364 pos += ret;
11365#endif /* CONFIG_WIFI_DISPLAY */
11366
11367 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11368 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
11369 "address=" MACSTR "\n",
11370 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011371 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011372 return pos - buf;
11373 pos += ret;
11374 }
11375
11376 return pos - buf;
11377}
11378
11379
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011380#ifdef CONFIG_FST
11381
11382static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
11383 char *cmd, char *buf,
11384 size_t reply_size)
11385{
11386 char ifname[IFNAMSIZ + 1];
11387 struct fst_iface_cfg cfg;
11388 struct wpa_supplicant *wpa_s;
11389 struct fst_wpa_obj iface_obj;
11390
11391 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
11392 wpa_s = wpa_supplicant_get_iface(global, ifname);
11393 if (wpa_s) {
11394 if (wpa_s->fst) {
11395 wpa_printf(MSG_INFO, "FST: Already attached");
11396 return -1;
11397 }
11398 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
11399 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
11400 &iface_obj, &cfg);
11401 if (wpa_s->fst)
11402 return os_snprintf(buf, reply_size, "OK\n");
11403 }
11404 }
11405
11406 return -1;
11407}
11408
11409
11410static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
11411 char *cmd, char *buf,
11412 size_t reply_size)
11413{
11414 char ifname[IFNAMSIZ + 1];
11415 struct wpa_supplicant *wpa_s;
11416
11417 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
11418 wpa_s = wpa_supplicant_get_iface(global, ifname);
11419 if (wpa_s) {
11420 if (!fst_iface_detach(ifname)) {
11421 wpa_s->fst = NULL;
11422 return os_snprintf(buf, reply_size, "OK\n");
11423 }
11424 }
11425 }
11426
11427 return -1;
11428}
11429
11430#endif /* CONFIG_FST */
11431
11432
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011433char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
11434 char *buf, size_t *resp_len)
11435{
11436 char *reply;
11437 const int reply_size = 2048;
11438 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011439 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011440
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011441 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
11442 char *pos = os_strchr(buf + 7, ' ');
11443 if (pos) {
11444 *pos++ = '\0';
11445 return wpas_global_ctrl_iface_ifname(global,
11446 buf + 7, pos,
11447 resp_len);
11448 }
11449 }
11450
11451 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
11452 if (reply)
11453 return reply;
11454
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011455 if (os_strcmp(buf, "PING") == 0)
11456 level = MSG_EXCESSIVE;
11457 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011458 (const u8 *) buf, os_strlen(buf));
11459
11460 reply = os_malloc(reply_size);
11461 if (reply == NULL) {
11462 *resp_len = 1;
11463 return NULL;
11464 }
11465
11466 os_memcpy(reply, "OK\n", 3);
11467 reply_len = 3;
11468
11469 if (os_strcmp(buf, "PING") == 0) {
11470 os_memcpy(reply, "PONG\n", 5);
11471 reply_len = 5;
11472 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
11473 if (wpa_supplicant_global_iface_add(global, buf + 14))
11474 reply_len = -1;
11475 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
11476 if (wpa_supplicant_global_iface_remove(global, buf + 17))
11477 reply_len = -1;
11478 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
11479 reply_len = wpa_supplicant_global_iface_list(
11480 global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011481 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011482 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011483 global, buf + 10, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011484#ifdef CONFIG_FST
11485 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
11486 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
11487 reply,
11488 reply_size);
11489 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
11490 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
11491 reply,
11492 reply_size);
11493 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
11494 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
11495#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011496 } else if (os_strcmp(buf, "TERMINATE") == 0) {
11497 wpa_supplicant_terminate_proc(global);
11498 } else if (os_strcmp(buf, "SUSPEND") == 0) {
11499 wpas_notify_suspend(global);
11500 } else if (os_strcmp(buf, "RESUME") == 0) {
11501 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011502 } else if (os_strncmp(buf, "SET ", 4) == 0) {
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011503 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
11504#ifdef CONFIG_P2P
11505 if (global->p2p_init_wpa_s) {
11506 os_free(reply);
11507 /* Check if P2P redirection would work for this
11508 * command. */
11509 return wpa_supplicant_ctrl_iface_process(
11510 global->p2p_init_wpa_s,
11511 buf, resp_len);
11512 }
11513#endif /* CONFIG_P2P */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011514 reply_len = -1;
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011515 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011516 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
11517 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
11518 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011519#ifndef CONFIG_NO_CONFIG_WRITE
11520 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
11521 if (wpas_global_ctrl_iface_save_config(global))
11522 reply_len = -1;
11523#endif /* CONFIG_NO_CONFIG_WRITE */
11524 } else if (os_strcmp(buf, "STATUS") == 0) {
11525 reply_len = wpas_global_ctrl_iface_status(global, reply,
11526 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080011527#ifdef CONFIG_MODULE_TESTS
11528 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080011529 if (wpas_module_tests() < 0)
11530 reply_len = -1;
11531#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011532 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
11533 if (wpa_debug_reopen_file() < 0)
11534 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011535 } else {
11536 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
11537 reply_len = 16;
11538 }
11539
11540 if (reply_len < 0) {
11541 os_memcpy(reply, "FAIL\n", 5);
11542 reply_len = 5;
11543 }
11544
11545 *resp_len = reply_len;
11546 return reply;
11547}