blob: a0db9e42f658ca9f1f1950aeea5d72e458cc2fc4 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant / Control interface (shared code for all backends)
Hai Shalom39bc25d2019-02-06 16:32:13 -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
11#include <net/ethernet.h>
12#include <netinet/ip.h>
13#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014
15#include "utils/common.h"
16#include "utils/eloop.h"
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080017#include "utils/uuid.h"
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -070018#include "utils/module_tests.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019#include "common/version.h"
20#include "common/ieee802_11_defs.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070021#include "common/ieee802_11_common.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include "common/wpa_ctrl.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070023#ifdef CONFIG_DPP
24#include "common/dpp.h"
25#endif /* CONFIG_DPP */
Dmitry Shmidtff787d52015-01-12 13:01:47 -080026#include "crypto/tls.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080027#include "ap/hostapd.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "eap_peer/eap.h"
29#include "eapol_supp/eapol_supp_sm.h"
30#include "rsn_supp/wpa.h"
31#include "rsn_supp/preauth.h"
32#include "rsn_supp/pmksa_cache.h"
33#include "l2_packet/l2_packet.h"
34#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080035#include "fst/fst.h"
36#include "fst/fst_ctrl_iface.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "config.h"
38#include "wpa_supplicant_i.h"
39#include "driver_i.h"
40#include "wps_supplicant.h"
41#include "ibss_rsn.h"
42#include "ap.h"
43#include "p2p_supplicant.h"
44#include "p2p/p2p.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070045#include "hs20_supplicant.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070046#include "wifi_display.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070047#include "notify.h"
48#include "bss.h"
49#include "scan.h"
50#include "ctrl_iface.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080051#include "interworking.h"
Dmitry Shmidte19501d2011-03-16 14:32:18 -070052#include "blacklist.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070053#include "autoscan.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080054#include "wnm_sta.h"
Dmitry Shmidt818ea482014-03-10 13:15:21 -070055#include "offchannel.h"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070056#include "drivers/driver.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080057#include "mesh.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070058#include "dpp_supplicant.h"
Hai Shalom39bc25d2019-02-06 16:32:13 -080059#include "sme.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070060
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070061static int wpa_supplicant_global_iface_list(struct wpa_global *global,
62 char *buf, int len);
63static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080064 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070065 char *buf, int len);
Dmitry Shmidtd11f0192014-03-24 12:09:47 -070066static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
67 char *val);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070068
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070069
Dmitry Shmidt04949592012-07-19 12:16:46 -070070static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
71{
72 char *pos;
73 u8 addr[ETH_ALEN], *filter = NULL, *n;
74 size_t count = 0;
75
76 pos = val;
77 while (pos) {
78 if (*pos == '\0')
79 break;
80 if (hwaddr_aton(pos, addr)) {
81 os_free(filter);
82 return -1;
83 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070084 n = os_realloc_array(filter, count + 1, ETH_ALEN);
Dmitry Shmidt04949592012-07-19 12:16:46 -070085 if (n == NULL) {
86 os_free(filter);
87 return -1;
88 }
89 filter = n;
90 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
91 count++;
92
93 pos = os_strchr(pos, ' ');
94 if (pos)
95 pos++;
96 }
97
98 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
99 os_free(wpa_s->bssid_filter);
100 wpa_s->bssid_filter = filter;
101 wpa_s->bssid_filter_count = count;
102
103 return 0;
104}
105
106
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800107static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
108{
109 char *pos;
110 u8 addr[ETH_ALEN], *bssid = NULL, *n;
111 struct wpa_ssid_value *ssid = NULL, *ns;
112 size_t count = 0, ssid_count = 0;
113 struct wpa_ssid *c;
114
115 /*
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800116 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800117 * SSID_SPEC ::= ssid <SSID_HEX>
118 * BSSID_SPEC ::= bssid <BSSID_HEX>
119 */
120
121 pos = val;
122 while (pos) {
123 if (*pos == '\0')
124 break;
125 if (os_strncmp(pos, "bssid ", 6) == 0) {
126 int res;
127 pos += 6;
128 res = hwaddr_aton2(pos, addr);
129 if (res < 0) {
130 os_free(ssid);
131 os_free(bssid);
132 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
133 "BSSID value '%s'", pos);
134 return -1;
135 }
136 pos += res;
137 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
138 if (n == NULL) {
139 os_free(ssid);
140 os_free(bssid);
141 return -1;
142 }
143 bssid = n;
144 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
145 count++;
146 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
147 char *end;
148 pos += 5;
149
150 end = pos;
151 while (*end) {
152 if (*end == '\0' || *end == ' ')
153 break;
154 end++;
155 }
156
157 ns = os_realloc_array(ssid, ssid_count + 1,
158 sizeof(struct wpa_ssid_value));
159 if (ns == NULL) {
160 os_free(ssid);
161 os_free(bssid);
162 return -1;
163 }
164 ssid = ns;
165
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700166 if ((end - pos) & 0x01 ||
167 end - pos > 2 * SSID_MAX_LEN ||
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800168 hexstr2bin(pos, ssid[ssid_count].ssid,
169 (end - pos) / 2) < 0) {
170 os_free(ssid);
171 os_free(bssid);
172 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
173 "SSID value '%s'", pos);
174 return -1;
175 }
176 ssid[ssid_count].ssid_len = (end - pos) / 2;
177 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
178 ssid[ssid_count].ssid,
179 ssid[ssid_count].ssid_len);
180 ssid_count++;
181 pos = end;
182 } else {
183 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
184 "'%s'", pos);
185 os_free(ssid);
186 os_free(bssid);
187 return -1;
188 }
189
190 pos = os_strchr(pos, ' ');
191 if (pos)
192 pos++;
193 }
194
195 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
196 os_free(wpa_s->disallow_aps_bssid);
197 wpa_s->disallow_aps_bssid = bssid;
198 wpa_s->disallow_aps_bssid_count = count;
199
200 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
201 os_free(wpa_s->disallow_aps_ssid);
202 wpa_s->disallow_aps_ssid = ssid;
203 wpa_s->disallow_aps_ssid_count = ssid_count;
204
205 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
206 return 0;
207
208 c = wpa_s->current_ssid;
209 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
210 return 0;
211
212 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
213 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
214 return 0;
215
216 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
217 "because current AP was marked disallowed");
218
219#ifdef CONFIG_SME
220 wpa_s->sme.prev_bssid_set = 0;
221#endif /* CONFIG_SME */
222 wpa_s->reassociate = 1;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800223 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800224 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
225 wpa_supplicant_req_scan(wpa_s, 0, 0);
226
227 return 0;
228}
229
230
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700231#ifndef CONFIG_NO_CONFIG_BLOBS
232static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
233{
234 char *name = pos;
235 struct wpa_config_blob *blob;
236 size_t len;
237
238 pos = os_strchr(pos, ' ');
239 if (pos == NULL)
240 return -1;
241 *pos++ = '\0';
242 len = os_strlen(pos);
243 if (len & 1)
244 return -1;
245
246 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
247 blob = os_zalloc(sizeof(*blob));
248 if (blob == NULL)
249 return -1;
250 blob->name = os_strdup(name);
251 blob->data = os_malloc(len / 2);
252 if (blob->name == NULL || blob->data == NULL) {
253 wpa_config_free_blob(blob);
254 return -1;
255 }
256
257 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
258 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
259 wpa_config_free_blob(blob);
260 return -1;
261 }
262 blob->len = len / 2;
263
264 wpa_config_set_blob(wpa_s->conf, blob);
265
266 return 0;
267}
268#endif /* CONFIG_NO_CONFIG_BLOBS */
269
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700270
271static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
272{
273 char *params;
274 char *pos;
275 int *freqs = NULL;
276 int ret;
277
278 if (atoi(cmd)) {
279 params = os_strchr(cmd, ' ');
280 os_free(wpa_s->manual_sched_scan_freqs);
281 if (params) {
282 params++;
283 pos = os_strstr(params, "freq=");
284 if (pos)
285 freqs = freq_range_to_channel_list(wpa_s,
286 pos + 5);
287 }
288 wpa_s->manual_sched_scan_freqs = freqs;
289 ret = wpas_start_pno(wpa_s);
290 } else {
291 ret = wpas_stop_pno(wpa_s);
292 }
293 return ret;
294}
295
296
Ravi Joshie6ccb162015-07-16 17:45:41 -0700297static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band)
298{
299 union wpa_event_data event;
300
301 if (os_strcmp(band, "AUTO") == 0)
302 wpa_s->setband = WPA_SETBAND_AUTO;
303 else if (os_strcmp(band, "5G") == 0)
304 wpa_s->setband = WPA_SETBAND_5G;
305 else if (os_strcmp(band, "2G") == 0)
306 wpa_s->setband = WPA_SETBAND_2G;
307 else
308 return -1;
309
310 if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) {
311 os_memset(&event, 0, sizeof(event));
312 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
313 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
314 wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
315 }
316
317 return 0;
318}
319
320
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700321static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s,
322 const char *cmd)
323{
324 struct wpabuf *lci;
325
326 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
327 wpabuf_free(wpa_s->lci);
328 wpa_s->lci = NULL;
329 return 0;
330 }
331
332 lci = wpabuf_parse_bin(cmd);
333 if (!lci)
334 return -1;
335
336 if (os_get_reltime(&wpa_s->lci_time)) {
337 wpabuf_free(lci);
338 return -1;
339 }
340
341 wpabuf_free(wpa_s->lci);
342 wpa_s->lci = lci;
343
344 return 0;
345}
346
347
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800348static int
349wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd)
350{
351 int relative_rssi;
352
353 if (os_strcmp(cmd, "disable") == 0) {
354 wpa_s->srp.relative_rssi_set = 0;
355 return 0;
356 }
357
358 relative_rssi = atoi(cmd);
359 if (relative_rssi < 0 || relative_rssi > 100)
360 return -1;
361 wpa_s->srp.relative_rssi = relative_rssi;
362 wpa_s->srp.relative_rssi_set = 1;
363 return 0;
364}
365
366
367static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s,
368 const char *cmd)
369{
370 char *pos;
371 int adjust_rssi;
372
373 /* <band>:adjust_value */
374 pos = os_strchr(cmd, ':');
375 if (!pos)
376 return -1;
377 pos++;
378 adjust_rssi = atoi(pos);
379 if (adjust_rssi < -100 || adjust_rssi > 100)
380 return -1;
381
382 if (os_strncmp(cmd, "2G", 2) == 0)
383 wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G;
384 else if (os_strncmp(cmd, "5G", 2) == 0)
385 wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G;
386 else
387 return -1;
388
389 wpa_s->srp.relative_adjust_rssi = adjust_rssi;
390
391 return 0;
392}
393
394
395static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s,
396 const char *cmd)
397{
398 struct wpabuf *ric_ies;
399
400 if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
401 wpabuf_free(wpa_s->ric_ies);
402 wpa_s->ric_ies = NULL;
403 return 0;
404 }
405
406 ric_ies = wpabuf_parse_bin(cmd);
407 if (!ric_ies)
408 return -1;
409
410 wpabuf_free(wpa_s->ric_ies);
411 wpa_s->ric_ies = ric_ies;
412
413 return 0;
414}
415
416
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700417static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
418 char *cmd)
419{
420 char *value;
421 int ret = 0;
422
423 value = os_strchr(cmd, ' ');
424 if (value == NULL)
425 return -1;
426 *value++ = '\0';
427
428 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
429 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
430 eapol_sm_configure(wpa_s->eapol,
431 atoi(value), -1, -1, -1);
432 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
433 eapol_sm_configure(wpa_s->eapol,
434 -1, atoi(value), -1, -1);
435 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
436 eapol_sm_configure(wpa_s->eapol,
437 -1, -1, atoi(value), -1);
438 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
439 eapol_sm_configure(wpa_s->eapol,
440 -1, -1, -1, atoi(value));
441 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
442 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
Paul Stewart092955c2017-02-06 09:13:09 -0800443 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800445 } else {
446 value[-1] = '=';
447 wpa_config_process_global(wpa_s->conf, cmd, -1);
448 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700449 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
450 0) {
451 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
Paul Stewart092955c2017-02-06 09:13:09 -0800452 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700453 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800454 } else {
455 value[-1] = '=';
456 wpa_config_process_global(wpa_s->conf, cmd, -1);
457 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700458 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
Paul Stewart092955c2017-02-06 09:13:09 -0800459 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
460 atoi(value))) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700461 ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -0800462 } else {
463 value[-1] = '=';
464 wpa_config_process_global(wpa_s->conf, cmd, -1);
465 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
467 wpa_s->wps_fragment_size = atoi(value);
468#ifdef CONFIG_WPS_TESTING
469 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
470 long int val;
471 val = strtol(value, NULL, 0);
472 if (val < 0 || val > 0xff) {
473 ret = -1;
474 wpa_printf(MSG_DEBUG, "WPS: Invalid "
475 "wps_version_number %ld", val);
476 } else {
477 wps_version_number = val;
478 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
479 "version %u.%u",
480 (wps_version_number & 0xf0) >> 4,
481 wps_version_number & 0x0f);
482 }
483 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
484 wps_testing_dummy_cred = atoi(value);
485 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
486 wps_testing_dummy_cred);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800487 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
488 wps_corrupt_pkhash = atoi(value);
489 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
490 wps_corrupt_pkhash);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800491 } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
492 if (value[0] == '\0') {
493 wps_force_auth_types_in_use = 0;
494 } else {
495 wps_force_auth_types = strtol(value, NULL, 0);
496 wps_force_auth_types_in_use = 1;
497 }
498 } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
499 if (value[0] == '\0') {
500 wps_force_encr_types_in_use = 0;
501 } else {
502 wps_force_encr_types = strtol(value, NULL, 0);
503 wps_force_encr_types_in_use = 1;
504 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700505#endif /* CONFIG_WPS_TESTING */
506 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
507 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
508 ret = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800509#ifdef CONFIG_TDLS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700510#ifdef CONFIG_TDLS_TESTING
511 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700512 tdls_testing = strtol(value, NULL, 0);
513 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
514#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700515 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
516 int disabled = atoi(value);
517 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
518 if (disabled) {
519 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
520 ret = -1;
521 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
522 ret = -1;
523 wpa_tdls_enable(wpa_s->wpa, !disabled);
524#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800525 } else if (os_strcasecmp(cmd, "pno") == 0) {
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700526 ret = wpas_ctrl_pno(wpa_s, value);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700527 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
528 int disabled = atoi(value);
529 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
530 ret = -1;
531 else if (disabled)
532 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
533 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
534 if (os_strcmp(value, "disable") == 0)
535 wpa_s->set_sta_uapsd = 0;
536 else {
537 int be, bk, vi, vo;
538 char *pos;
539 /* format: BE,BK,VI,VO;max SP Length */
540 be = atoi(value);
541 pos = os_strchr(value, ',');
542 if (pos == NULL)
543 return -1;
544 pos++;
545 bk = atoi(pos);
546 pos = os_strchr(pos, ',');
547 if (pos == NULL)
548 return -1;
549 pos++;
550 vi = atoi(pos);
551 pos = os_strchr(pos, ',');
552 if (pos == NULL)
553 return -1;
554 pos++;
555 vo = atoi(pos);
556 /* ignore max SP Length for now */
557
558 wpa_s->set_sta_uapsd = 1;
559 wpa_s->sta_uapsd = 0;
560 if (be)
561 wpa_s->sta_uapsd |= BIT(0);
562 if (bk)
563 wpa_s->sta_uapsd |= BIT(1);
564 if (vi)
565 wpa_s->sta_uapsd |= BIT(2);
566 if (vo)
567 wpa_s->sta_uapsd |= BIT(3);
568 }
Jouni Malinen21d6bc82012-04-10 16:17:59 -0700569 } else if (os_strcasecmp(cmd, "ps") == 0) {
570 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700571#ifdef CONFIG_WIFI_DISPLAY
572 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800573 int enabled = !!atoi(value);
574 if (enabled && !wpa_s->global->p2p)
575 ret = -1;
576 else
577 wifi_display_enable(wpa_s->global, enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700578#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700579 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
580 ret = set_bssid_filter(wpa_s, value);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800581 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
582 ret = set_disallow_aps(wpa_s, value);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800583 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
584 wpa_s->no_keep_alive = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700585#ifdef CONFIG_DPP
586 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
587 os_free(wpa_s->dpp_configurator_params);
588 wpa_s->dpp_configurator_params = os_strdup(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700589 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
590 wpa_s->dpp_init_max_tries = atoi(value);
591 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
592 wpa_s->dpp_init_retry_time = atoi(value);
593 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
594 wpa_s->dpp_resp_wait_time = atoi(value);
595 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
596 wpa_s->dpp_resp_max_tries = atoi(value);
597 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
598 wpa_s->dpp_resp_retry_time = atoi(value);
599#ifdef CONFIG_TESTING_OPTIONS
600 } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
601 if (hwaddr_aton(value, dpp_pkex_own_mac_override))
602 ret = -1;
603 } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
604 if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
605 ret = -1;
606 } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
607 size_t hex_len = os_strlen(value);
608
609 if (hex_len >
610 2 * sizeof(dpp_pkex_ephemeral_key_override))
611 ret = -1;
612 else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
613 hex_len / 2))
614 ret = -1;
615 else
616 dpp_pkex_ephemeral_key_override_len = hex_len / 2;
617 } else if (os_strcasecmp(cmd, "dpp_protocol_key_override") == 0) {
618 size_t hex_len = os_strlen(value);
619
620 if (hex_len > 2 * sizeof(dpp_protocol_key_override))
621 ret = -1;
622 else if (hexstr2bin(value, dpp_protocol_key_override,
623 hex_len / 2))
624 ret = -1;
625 else
626 dpp_protocol_key_override_len = hex_len / 2;
627 } else if (os_strcasecmp(cmd, "dpp_nonce_override") == 0) {
628 size_t hex_len = os_strlen(value);
629
630 if (hex_len > 2 * sizeof(dpp_nonce_override))
631 ret = -1;
632 else if (hexstr2bin(value, dpp_nonce_override, hex_len / 2))
633 ret = -1;
634 else
635 dpp_nonce_override_len = hex_len / 2;
636#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700637#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700638#ifdef CONFIG_TESTING_OPTIONS
639 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
640 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800641 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
642 wpa_s->ext_eapol_frame_io = !!atoi(value);
643#ifdef CONFIG_AP
644 if (wpa_s->ap_iface) {
645 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
646 wpa_s->ext_eapol_frame_io;
647 }
648#endif /* CONFIG_AP */
649 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
650 wpa_s->extra_roc_dur = atoi(value);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800651 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
652 wpa_s->test_failure = atoi(value);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800653 } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
654 wpa_s->p2p_go_csa_on_inv = !!atoi(value);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700655 } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
656 wpa_s->ignore_auth_resp = !!atoi(value);
657 } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
658 wpa_s->ignore_assoc_disallow = !!atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700659 wpa_drv_ignore_assoc_disallow(wpa_s,
660 wpa_s->ignore_assoc_disallow);
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700661 } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
662 wpa_s->reject_btm_req_reason = atoi(value);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800663 } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
664 os_free(wpa_s->get_pref_freq_list_override);
665 if (!value[0])
666 wpa_s->get_pref_freq_list_override = NULL;
667 else
668 wpa_s->get_pref_freq_list_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700669 } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
670 wpabuf_free(wpa_s->sae_commit_override);
671 if (value[0] == '\0')
672 wpa_s->sae_commit_override = NULL;
673 else
674 wpa_s->sae_commit_override = wpabuf_parse_bin(value);
675#ifdef CONFIG_DPP
676 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
677 os_free(wpa_s->dpp_config_obj_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700678 if (value[0] == '\0')
679 wpa_s->dpp_config_obj_override = NULL;
680 else
681 wpa_s->dpp_config_obj_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700682 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
683 os_free(wpa_s->dpp_discovery_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700684 if (value[0] == '\0')
685 wpa_s->dpp_discovery_override = NULL;
686 else
687 wpa_s->dpp_discovery_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700688 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
689 os_free(wpa_s->dpp_groups_override);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700690 if (value[0] == '\0')
691 wpa_s->dpp_groups_override = NULL;
692 else
693 wpa_s->dpp_groups_override = os_strdup(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700694 } else if (os_strcasecmp(cmd,
695 "dpp_ignore_netaccesskey_mismatch") == 0) {
696 wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700697 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
698 dpp_test = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700699#endif /* CONFIG_DPP */
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700700#endif /* CONFIG_TESTING_OPTIONS */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700701#ifdef CONFIG_FILS
702 } else if (os_strcasecmp(cmd, "disable_fils") == 0) {
703 wpa_s->disable_fils = !!atoi(value);
704 wpa_drv_disable_fils(wpa_s, wpa_s->disable_fils);
705 wpa_supplicant_set_default_scan_ies(wpa_s);
706#endif /* CONFIG_FILS */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700707#ifndef CONFIG_NO_CONFIG_BLOBS
708 } else if (os_strcmp(cmd, "blob") == 0) {
709 ret = wpas_ctrl_set_blob(wpa_s, value);
710#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800711 } else if (os_strcasecmp(cmd, "setband") == 0) {
Ravi Joshie6ccb162015-07-16 17:45:41 -0700712 ret = wpas_ctrl_set_band(wpa_s, value);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800713#ifdef CONFIG_MBO
714 } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
715 ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
Paul Stewart092955c2017-02-06 09:13:09 -0800716 if (ret == 0) {
717 value[-1] = '=';
718 wpa_config_process_global(wpa_s->conf, cmd, -1);
719 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800720 } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
721 wpas_mbo_update_cell_capa(wpa_s, atoi(value));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700722 } else if (os_strcasecmp(cmd, "oce") == 0) {
723 wpa_s->conf->oce = atoi(value);
724 if (wpa_s->conf->oce) {
725 if ((wpa_s->conf->oce & OCE_STA) &&
726 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
727 wpa_s->enable_oce = OCE_STA;
728
729 if ((wpa_s->conf->oce & OCE_STA_CFON) &&
730 (wpa_s->drv_flags &
731 WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
732 /* TODO: Need to add STA-CFON support */
733 wpa_printf(MSG_ERROR,
734 "OCE STA-CFON feature is not yet supported");
735 return -1;
736 }
737 } else {
738 wpa_s->enable_oce = 0;
739 }
740 wpa_supplicant_set_default_scan_ies(wpa_s);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800741#endif /* CONFIG_MBO */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700742 } else if (os_strcasecmp(cmd, "lci") == 0) {
743 ret = wpas_ctrl_iface_set_lci(wpa_s, value);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800744 } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
745 ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800746 } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
747 ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
748 } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
749 ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
750 } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
751 ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700752 } else if (os_strcasecmp(cmd, "roaming") == 0) {
753 ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800754#ifdef CONFIG_WNM
755 } else if (os_strcasecmp(cmd, "coloc_intf_elems") == 0) {
756 struct wpabuf *elems;
757
758 elems = wpabuf_parse_bin(value);
759 if (!elems)
760 return -1;
761 wnm_set_coloc_intf_elems(wpa_s, elems);
762#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763 } else {
764 value[-1] = '=';
765 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
766 if (ret == 0)
767 wpa_supplicant_update_config(wpa_s);
768 }
769
770 return ret;
771}
772
773
774static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
775 char *cmd, char *buf, size_t buflen)
776{
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700777 int res = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700778
779 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
780
781 if (os_strcmp(cmd, "version") == 0) {
782 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700783 } else if (os_strcasecmp(cmd, "country") == 0) {
784 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
785 res = os_snprintf(buf, buflen, "%c%c",
786 wpa_s->conf->country[0],
787 wpa_s->conf->country[1]);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700788#ifdef CONFIG_WIFI_DISPLAY
789 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
Dmitry Shmidted003d22014-02-06 10:09:12 -0800790 int enabled;
791 if (wpa_s->global->p2p == NULL ||
792 wpa_s->global->p2p_disabled)
793 enabled = 0;
794 else
795 enabled = wpa_s->global->wifi_display;
796 res = os_snprintf(buf, buflen, "%d", enabled);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700797#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700798#ifdef CONFIG_TESTING_GET_GTK
799 } else if (os_strcmp(cmd, "gtk") == 0) {
800 if (wpa_s->last_gtk_len == 0)
801 return -1;
802 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
803 wpa_s->last_gtk_len);
804 return res;
805#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800806 } else if (os_strcmp(cmd, "tls_library") == 0) {
807 res = tls_get_library_version(buf, buflen);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700808#ifdef CONFIG_TESTING_OPTIONS
809 } else if (os_strcmp(cmd, "anonce") == 0) {
810 return wpa_snprintf_hex(buf, buflen,
811 wpa_sm_get_anonce(wpa_s->wpa),
812 WPA_NONCE_LEN);
813#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800814 } else {
815 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700816 }
817
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800818 if (os_snprintf_error(buflen, res))
Dmitry Shmidt6f3bdcf2011-04-19 16:42:47 -0700819 return -1;
820 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700821}
822
823
824#ifdef IEEE8021X_EAPOL
825static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
826 char *addr)
827{
828 u8 bssid[ETH_ALEN];
829 struct wpa_ssid *ssid = wpa_s->current_ssid;
830
831 if (hwaddr_aton(addr, bssid)) {
832 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
833 "'%s'", addr);
834 return -1;
835 }
836
837 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
838 rsn_preauth_deinit(wpa_s->wpa);
839 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
840 return -1;
841
842 return 0;
843}
844#endif /* IEEE8021X_EAPOL */
845
846
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847#ifdef CONFIG_TDLS
848
849static int wpa_supplicant_ctrl_iface_tdls_discover(
850 struct wpa_supplicant *wpa_s, char *addr)
851{
852 u8 peer[ETH_ALEN];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800853 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700854
855 if (hwaddr_aton(addr, peer)) {
856 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
857 "address '%s'", addr);
858 return -1;
859 }
860
861 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
862 MAC2STR(peer));
863
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800864 if (wpa_tdls_is_external_setup(wpa_s->wpa))
865 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
866 else
867 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
868
869 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870}
871
872
873static int wpa_supplicant_ctrl_iface_tdls_setup(
874 struct wpa_supplicant *wpa_s, char *addr)
875{
876 u8 peer[ETH_ALEN];
877 int ret;
878
879 if (hwaddr_aton(addr, peer)) {
880 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
881 "address '%s'", addr);
882 return -1;
883 }
884
885 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
886 MAC2STR(peer));
887
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800888 if ((wpa_s->conf->tdls_external_control) &&
889 wpa_tdls_is_external_setup(wpa_s->wpa))
890 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
891
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800892 wpa_tdls_remove(wpa_s->wpa, peer);
893
894 if (wpa_tdls_is_external_setup(wpa_s->wpa))
895 ret = wpa_tdls_start(wpa_s->wpa, peer);
896 else
897 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800898
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700899 return ret;
900}
901
902
903static int wpa_supplicant_ctrl_iface_tdls_teardown(
904 struct wpa_supplicant *wpa_s, char *addr)
905{
906 u8 peer[ETH_ALEN];
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700907 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700908
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700909 if (os_strcmp(addr, "*") == 0) {
910 /* remove everyone */
911 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
912 wpa_tdls_teardown_peers(wpa_s->wpa);
913 return 0;
914 }
915
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700916 if (hwaddr_aton(addr, peer)) {
917 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
918 "address '%s'", addr);
919 return -1;
920 }
921
922 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
923 MAC2STR(peer));
924
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800925 if ((wpa_s->conf->tdls_external_control) &&
926 wpa_tdls_is_external_setup(wpa_s->wpa))
927 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
928
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700929 if (wpa_tdls_is_external_setup(wpa_s->wpa))
930 ret = wpa_tdls_teardown_link(
931 wpa_s->wpa, peer,
932 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
933 else
934 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
935
936 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700937}
938
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700939
940static int ctrl_iface_get_capability_tdls(
941 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
942{
943 int ret;
944
945 ret = os_snprintf(buf, buflen, "%s\n",
946 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
947 (wpa_s->drv_flags &
948 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
949 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800950 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700951 return -1;
952 return ret;
953}
954
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800955
956static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
957 struct wpa_supplicant *wpa_s, char *cmd)
958{
959 u8 peer[ETH_ALEN];
960 struct hostapd_freq_params freq_params;
961 u8 oper_class;
962 char *pos, *end;
963
964 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
965 wpa_printf(MSG_INFO,
966 "tdls_chanswitch: Only supported with external setup");
967 return -1;
968 }
969
970 os_memset(&freq_params, 0, sizeof(freq_params));
971
972 pos = os_strchr(cmd, ' ');
973 if (pos == NULL)
974 return -1;
975 *pos++ = '\0';
976
977 oper_class = strtol(pos, &end, 10);
978 if (pos == end) {
979 wpa_printf(MSG_INFO,
980 "tdls_chanswitch: Invalid op class provided");
981 return -1;
982 }
983
984 pos = end;
985 freq_params.freq = atoi(pos);
986 if (freq_params.freq == 0) {
987 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
988 return -1;
989 }
990
991#define SET_FREQ_SETTING(str) \
992 do { \
993 const char *pos2 = os_strstr(pos, " " #str "="); \
994 if (pos2) { \
995 pos2 += sizeof(" " #str "=") - 1; \
996 freq_params.str = atoi(pos2); \
997 } \
998 } while (0)
999
1000 SET_FREQ_SETTING(center_freq1);
1001 SET_FREQ_SETTING(center_freq2);
1002 SET_FREQ_SETTING(bandwidth);
1003 SET_FREQ_SETTING(sec_channel_offset);
1004#undef SET_FREQ_SETTING
1005
1006 freq_params.ht_enabled = !!os_strstr(pos, " ht");
1007 freq_params.vht_enabled = !!os_strstr(pos, " vht");
1008
1009 if (hwaddr_aton(cmd, peer)) {
1010 wpa_printf(MSG_DEBUG,
1011 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
1012 cmd);
1013 return -1;
1014 }
1015
1016 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
1017 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
1018 MAC2STR(peer), oper_class, freq_params.freq,
1019 freq_params.center_freq1, freq_params.center_freq2,
1020 freq_params.bandwidth, freq_params.sec_channel_offset,
1021 freq_params.ht_enabled ? " HT" : "",
1022 freq_params.vht_enabled ? " VHT" : "");
1023
1024 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
1025 &freq_params);
1026}
1027
1028
1029static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
1030 struct wpa_supplicant *wpa_s, char *cmd)
1031{
1032 u8 peer[ETH_ALEN];
1033
1034 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
1035 wpa_printf(MSG_INFO,
1036 "tdls_chanswitch: Only supported with external setup");
1037 return -1;
1038 }
1039
1040 if (hwaddr_aton(cmd, peer)) {
1041 wpa_printf(MSG_DEBUG,
1042 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
1043 cmd);
1044 return -1;
1045 }
1046
1047 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
1048 MAC2STR(peer));
1049
1050 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
1051}
1052
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -07001053
1054static int wpa_supplicant_ctrl_iface_tdls_link_status(
1055 struct wpa_supplicant *wpa_s, const char *addr,
1056 char *buf, size_t buflen)
1057{
1058 u8 peer[ETH_ALEN];
1059 const char *tdls_status;
1060 int ret;
1061
1062 if (hwaddr_aton(addr, peer)) {
1063 wpa_printf(MSG_DEBUG,
1064 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
1065 addr);
1066 return -1;
1067 }
1068 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
1069 MAC2STR(peer));
1070
1071 tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
1072 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
1073 ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
1074 if (os_snprintf_error(buflen, ret))
1075 return -1;
1076
1077 return ret;
1078}
1079
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001080#endif /* CONFIG_TDLS */
1081
1082
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001083static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
1084{
1085 char *token, *context = NULL;
1086 struct wmm_ac_ts_setup_params params = {
1087 .tsid = 0xff,
1088 .direction = 0xff,
1089 };
1090
1091 while ((token = str_token(cmd, " ", &context))) {
1092 if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
1093 sscanf(token, "up=%i", &params.user_priority) == 1 ||
1094 sscanf(token, "nominal_msdu_size=%i",
1095 &params.nominal_msdu_size) == 1 ||
1096 sscanf(token, "mean_data_rate=%i",
1097 &params.mean_data_rate) == 1 ||
1098 sscanf(token, "min_phy_rate=%i",
1099 &params.minimum_phy_rate) == 1 ||
1100 sscanf(token, "sba=%i",
1101 &params.surplus_bandwidth_allowance) == 1)
1102 continue;
1103
1104 if (os_strcasecmp(token, "downlink") == 0) {
1105 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
1106 } else if (os_strcasecmp(token, "uplink") == 0) {
1107 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
1108 } else if (os_strcasecmp(token, "bidi") == 0) {
1109 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
1110 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
1111 params.fixed_nominal_msdu = 1;
1112 } else {
1113 wpa_printf(MSG_DEBUG,
1114 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
1115 token);
1116 return -1;
1117 }
1118
1119 }
1120
1121 return wpas_wmm_ac_addts(wpa_s, &params);
1122}
1123
1124
1125static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
1126{
1127 u8 tsid = atoi(cmd);
1128
1129 return wpas_wmm_ac_delts(wpa_s, tsid);
1130}
1131
1132
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001133#ifdef CONFIG_IEEE80211R
1134static int wpa_supplicant_ctrl_iface_ft_ds(
1135 struct wpa_supplicant *wpa_s, char *addr)
1136{
1137 u8 target_ap[ETH_ALEN];
1138 struct wpa_bss *bss;
1139 const u8 *mdie;
1140
1141 if (hwaddr_aton(addr, target_ap)) {
1142 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
1143 "address '%s'", addr);
1144 return -1;
1145 }
1146
1147 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
1148
1149 bss = wpa_bss_get_bssid(wpa_s, target_ap);
1150 if (bss)
1151 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
1152 else
1153 mdie = NULL;
1154
1155 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
1156}
1157#endif /* CONFIG_IEEE80211R */
1158
1159
1160#ifdef CONFIG_WPS
1161static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
1162 char *cmd)
1163{
1164 u8 bssid[ETH_ALEN], *_bssid = bssid;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001165#ifdef CONFIG_P2P
1166 u8 p2p_dev_addr[ETH_ALEN];
1167#endif /* CONFIG_P2P */
1168#ifdef CONFIG_AP
1169 u8 *_p2p_dev_addr = NULL;
1170#endif /* CONFIG_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001171
Dmitry Shmidtc0a8db02013-11-08 11:18:33 -08001172 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001173 _bssid = NULL;
1174#ifdef CONFIG_P2P
1175 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
1176 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
1177 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
1178 "P2P Device Address '%s'",
1179 cmd + 13);
1180 return -1;
1181 }
1182 _p2p_dev_addr = p2p_dev_addr;
1183#endif /* CONFIG_P2P */
1184 } else if (hwaddr_aton(cmd, bssid)) {
1185 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
1186 cmd);
1187 return -1;
1188 }
1189
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001190#ifdef CONFIG_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001191 if (wpa_s->ap_iface)
1192 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
1193#endif /* CONFIG_AP */
1194
1195 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
1196}
1197
1198
1199static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
1200 char *cmd, char *buf,
1201 size_t buflen)
1202{
1203 u8 bssid[ETH_ALEN], *_bssid = bssid;
1204 char *pin;
1205 int ret;
1206
1207 pin = os_strchr(cmd, ' ');
1208 if (pin)
1209 *pin++ = '\0';
1210
1211 if (os_strcmp(cmd, "any") == 0)
1212 _bssid = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001213 else if (os_strcmp(cmd, "get") == 0) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001214 if (wps_generate_pin((unsigned int *) &ret) < 0)
1215 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001216 goto done;
1217 } else if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001218 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1219 cmd);
1220 return -1;
1221 }
1222
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001223#ifdef CONFIG_AP
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001224 if (wpa_s->ap_iface) {
1225 int timeout = 0;
1226 char *pos;
1227
1228 if (pin) {
1229 pos = os_strchr(pin, ' ');
1230 if (pos) {
1231 *pos++ = '\0';
1232 timeout = atoi(pos);
1233 }
1234 }
1235
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001236 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001237 buf, buflen, timeout);
1238 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001239#endif /* CONFIG_AP */
1240
1241 if (pin) {
1242 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
1243 DEV_PW_DEFAULT);
1244 if (ret < 0)
1245 return -1;
1246 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001247 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001248 return -1;
1249 return ret;
1250 }
1251
1252 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
1253 if (ret < 0)
1254 return -1;
1255
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001256done:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001257 /* Return the generated PIN */
1258 ret = os_snprintf(buf, buflen, "%08d", ret);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001259 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001260 return -1;
1261 return ret;
1262}
1263
1264
1265static int wpa_supplicant_ctrl_iface_wps_check_pin(
1266 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1267{
1268 char pin[9];
1269 size_t len;
1270 char *pos;
1271 int ret;
1272
1273 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
1274 (u8 *) cmd, os_strlen(cmd));
1275 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
1276 if (*pos < '0' || *pos > '9')
1277 continue;
1278 pin[len++] = *pos;
1279 if (len == 9) {
1280 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
1281 return -1;
1282 }
1283 }
1284 if (len != 4 && len != 8) {
1285 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
1286 return -1;
1287 }
1288 pin[len] = '\0';
1289
1290 if (len == 8) {
1291 unsigned int pin_val;
1292 pin_val = atoi(pin);
1293 if (!wps_pin_valid(pin_val)) {
1294 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
1295 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001296 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001297 return -1;
1298 return ret;
1299 }
1300 }
1301
1302 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001303 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001304 return -1;
1305
1306 return ret;
1307}
1308
1309
Dmitry Shmidt04949592012-07-19 12:16:46 -07001310#ifdef CONFIG_WPS_NFC
1311
1312static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
1313 char *cmd)
1314{
1315 u8 bssid[ETH_ALEN], *_bssid = bssid;
1316
1317 if (cmd == NULL || cmd[0] == '\0')
1318 _bssid = NULL;
1319 else if (hwaddr_aton(cmd, bssid))
1320 return -1;
1321
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001322 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1323 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001324}
1325
1326
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001327static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1328 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1329{
1330 int ndef;
1331 struct wpabuf *buf;
1332 int res;
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001333 char *pos;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001334
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001335 pos = os_strchr(cmd, ' ');
1336 if (pos)
1337 *pos++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001338 if (os_strcmp(cmd, "WPS") == 0)
1339 ndef = 0;
1340 else if (os_strcmp(cmd, "NDEF") == 0)
1341 ndef = 1;
1342 else
1343 return -1;
1344
Dmitry Shmidt1e78e762013-04-02 11:05:36 -07001345 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001346 if (buf == NULL)
1347 return -1;
1348
1349 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1350 wpabuf_len(buf));
1351 reply[res++] = '\n';
1352 reply[res] = '\0';
1353
1354 wpabuf_free(buf);
1355
1356 return res;
1357}
1358
1359
Dmitry Shmidt04949592012-07-19 12:16:46 -07001360static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1361 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1362{
1363 int ndef;
1364 struct wpabuf *buf;
1365 int res;
1366
1367 if (os_strcmp(cmd, "WPS") == 0)
1368 ndef = 0;
1369 else if (os_strcmp(cmd, "NDEF") == 0)
1370 ndef = 1;
1371 else
1372 return -1;
1373
1374 buf = wpas_wps_nfc_token(wpa_s, ndef);
1375 if (buf == NULL)
1376 return -1;
1377
1378 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1379 wpabuf_len(buf));
1380 reply[res++] = '\n';
1381 reply[res] = '\0';
1382
1383 wpabuf_free(buf);
1384
1385 return res;
1386}
1387
1388
1389static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1390 struct wpa_supplicant *wpa_s, char *pos)
1391{
1392 size_t len;
1393 struct wpabuf *buf;
1394 int ret;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001395 char *freq;
1396 int forced_freq = 0;
1397
1398 freq = strstr(pos, " freq=");
1399 if (freq) {
1400 *freq = '\0';
1401 freq += 6;
1402 forced_freq = atoi(freq);
1403 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001404
1405 len = os_strlen(pos);
1406 if (len & 0x01)
1407 return -1;
1408 len /= 2;
1409
1410 buf = wpabuf_alloc(len);
1411 if (buf == NULL)
1412 return -1;
1413 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1414 wpabuf_free(buf);
1415 return -1;
1416 }
1417
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001418 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001419 wpabuf_free(buf);
1420
1421 return ret;
1422}
1423
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001424
1425static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001426 char *reply, size_t max_len,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001427 int ndef)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001428{
1429 struct wpabuf *buf;
1430 int res;
1431
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001432 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001433 if (buf == NULL)
1434 return -1;
1435
1436 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1437 wpabuf_len(buf));
1438 reply[res++] = '\n';
1439 reply[res] = '\0';
1440
1441 wpabuf_free(buf);
1442
1443 return res;
1444}
1445
1446
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001447#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001448static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1449 char *reply, size_t max_len,
1450 int ndef)
1451{
1452 struct wpabuf *buf;
1453 int res;
1454
1455 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1456 if (buf == NULL) {
1457 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1458 return -1;
1459 }
1460
1461 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1462 wpabuf_len(buf));
1463 reply[res++] = '\n';
1464 reply[res] = '\0';
1465
1466 wpabuf_free(buf);
1467
1468 return res;
1469}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001470#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001471
1472
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001473static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1474 char *cmd, char *reply,
1475 size_t max_len)
1476{
1477 char *pos;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001478 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001479
1480 pos = os_strchr(cmd, ' ');
1481 if (pos == NULL)
1482 return -1;
1483 *pos++ = '\0';
1484
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001485 if (os_strcmp(cmd, "WPS") == 0)
1486 ndef = 0;
1487 else if (os_strcmp(cmd, "NDEF") == 0)
1488 ndef = 1;
1489 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001490 return -1;
1491
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001492 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001493 if (!ndef)
1494 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001495 return wpas_ctrl_nfc_get_handover_req_wps(
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001496 wpa_s, reply, max_len, ndef);
1497 }
1498
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001499#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001500 if (os_strcmp(pos, "P2P-CR") == 0) {
1501 return wpas_ctrl_nfc_get_handover_req_p2p(
1502 wpa_s, reply, max_len, ndef);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001503 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001504#endif /* CONFIG_P2P */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001505
1506 return -1;
1507}
1508
1509
1510static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001511 char *reply, size_t max_len,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001512 int ndef, int cr, char *uuid)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001513{
1514 struct wpabuf *buf;
1515 int res;
1516
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001517 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001518 if (buf == NULL)
1519 return -1;
1520
1521 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1522 wpabuf_len(buf));
1523 reply[res++] = '\n';
1524 reply[res] = '\0';
1525
1526 wpabuf_free(buf);
1527
1528 return res;
1529}
1530
1531
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001532#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001533static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1534 char *reply, size_t max_len,
1535 int ndef, int tag)
1536{
1537 struct wpabuf *buf;
1538 int res;
1539
1540 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1541 if (buf == NULL)
1542 return -1;
1543
1544 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1545 wpabuf_len(buf));
1546 reply[res++] = '\n';
1547 reply[res] = '\0';
1548
1549 wpabuf_free(buf);
1550
1551 return res;
1552}
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001553#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001554
1555
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001556static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1557 char *cmd, char *reply,
1558 size_t max_len)
1559{
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001560 char *pos, *pos2;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001561 int ndef;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001562
1563 pos = os_strchr(cmd, ' ');
1564 if (pos == NULL)
1565 return -1;
1566 *pos++ = '\0';
1567
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001568 if (os_strcmp(cmd, "WPS") == 0)
1569 ndef = 0;
1570 else if (os_strcmp(cmd, "NDEF") == 0)
1571 ndef = 1;
1572 else
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001573 return -1;
1574
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001575 pos2 = os_strchr(pos, ' ');
1576 if (pos2)
1577 *pos2++ = '\0';
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001578 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001579 if (!ndef)
1580 return -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001581 return wpas_ctrl_nfc_get_handover_sel_wps(
1582 wpa_s, reply, max_len, ndef,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -08001583 os_strcmp(pos, "WPS-CR") == 0, pos2);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001584 }
1585
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001586#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001587 if (os_strcmp(pos, "P2P-CR") == 0) {
1588 return wpas_ctrl_nfc_get_handover_sel_p2p(
1589 wpa_s, reply, max_len, ndef, 0);
1590 }
1591
1592 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1593 return wpas_ctrl_nfc_get_handover_sel_p2p(
1594 wpa_s, reply, max_len, ndef, 1);
1595 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001596#endif /* CONFIG_P2P */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001597
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001598 return -1;
1599}
1600
1601
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001602static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1603 char *cmd)
1604{
1605 size_t len;
1606 struct wpabuf *req, *sel;
1607 int ret;
1608 char *pos, *role, *type, *pos2;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001609#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001610 char *freq;
1611 int forced_freq = 0;
1612
1613 freq = strstr(cmd, " freq=");
1614 if (freq) {
1615 *freq = '\0';
1616 freq += 6;
1617 forced_freq = atoi(freq);
1618 }
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001619#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001620
1621 role = cmd;
1622 pos = os_strchr(role, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001623 if (pos == NULL) {
1624 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001625 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001626 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001627 *pos++ = '\0';
1628
1629 type = pos;
1630 pos = os_strchr(type, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001631 if (pos == NULL) {
1632 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001633 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001634 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001635 *pos++ = '\0';
1636
1637 pos2 = os_strchr(pos, ' ');
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001638 if (pos2 == NULL) {
1639 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001640 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001641 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001642 *pos2++ = '\0';
1643
1644 len = os_strlen(pos);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001645 if (len & 0x01) {
1646 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001647 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001648 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001649 len /= 2;
1650
1651 req = wpabuf_alloc(len);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001652 if (req == NULL) {
1653 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001654 return -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001655 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001656 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001657 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001658 wpabuf_free(req);
1659 return -1;
1660 }
1661
1662 len = os_strlen(pos2);
1663 if (len & 0x01) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001664 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001665 wpabuf_free(req);
1666 return -1;
1667 }
1668 len /= 2;
1669
1670 sel = wpabuf_alloc(len);
1671 if (sel == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001672 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001673 wpabuf_free(req);
1674 return -1;
1675 }
1676 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001677 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001678 wpabuf_free(req);
1679 wpabuf_free(sel);
1680 return -1;
1681 }
1682
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001683 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1684 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1685
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001686 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1687 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001688#ifdef CONFIG_AP
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001689 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1690 {
1691 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1692 if (ret < 0)
1693 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001694#endif /* CONFIG_AP */
1695#ifdef CONFIG_P2P
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001696 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1697 {
1698 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1699 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1700 {
1701 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1702 forced_freq);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001703#endif /* CONFIG_P2P */
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001704 } else {
1705 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1706 "reported: role=%s type=%s", role, type);
1707 ret = -1;
1708 }
1709 wpabuf_free(req);
1710 wpabuf_free(sel);
1711
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001712 if (ret)
1713 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1714
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001715 return ret;
1716}
1717
Dmitry Shmidt04949592012-07-19 12:16:46 -07001718#endif /* CONFIG_WPS_NFC */
1719
1720
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001721static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1722 char *cmd)
1723{
1724 u8 bssid[ETH_ALEN];
1725 char *pin;
1726 char *new_ssid;
1727 char *new_auth;
1728 char *new_encr;
1729 char *new_key;
1730 struct wps_new_ap_settings ap;
1731
1732 pin = os_strchr(cmd, ' ');
1733 if (pin == NULL)
1734 return -1;
1735 *pin++ = '\0';
1736
1737 if (hwaddr_aton(cmd, bssid)) {
1738 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1739 cmd);
1740 return -1;
1741 }
1742
1743 new_ssid = os_strchr(pin, ' ');
1744 if (new_ssid == NULL)
1745 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1746 *new_ssid++ = '\0';
1747
1748 new_auth = os_strchr(new_ssid, ' ');
1749 if (new_auth == NULL)
1750 return -1;
1751 *new_auth++ = '\0';
1752
1753 new_encr = os_strchr(new_auth, ' ');
1754 if (new_encr == NULL)
1755 return -1;
1756 *new_encr++ = '\0';
1757
1758 new_key = os_strchr(new_encr, ' ');
1759 if (new_key == NULL)
1760 return -1;
1761 *new_key++ = '\0';
1762
1763 os_memset(&ap, 0, sizeof(ap));
1764 ap.ssid_hex = new_ssid;
1765 ap.auth = new_auth;
1766 ap.encr = new_encr;
1767 ap.key_hex = new_key;
1768 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1769}
1770
1771
1772#ifdef CONFIG_AP
1773static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1774 char *cmd, char *buf,
1775 size_t buflen)
1776{
1777 int timeout = 300;
1778 char *pos;
1779 const char *pin_txt;
1780
1781 if (!wpa_s->ap_iface)
1782 return -1;
1783
1784 pos = os_strchr(cmd, ' ');
1785 if (pos)
1786 *pos++ = '\0';
1787
1788 if (os_strcmp(cmd, "disable") == 0) {
1789 wpas_wps_ap_pin_disable(wpa_s);
1790 return os_snprintf(buf, buflen, "OK\n");
1791 }
1792
1793 if (os_strcmp(cmd, "random") == 0) {
1794 if (pos)
1795 timeout = atoi(pos);
1796 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1797 if (pin_txt == NULL)
1798 return -1;
1799 return os_snprintf(buf, buflen, "%s", pin_txt);
1800 }
1801
1802 if (os_strcmp(cmd, "get") == 0) {
1803 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1804 if (pin_txt == NULL)
1805 return -1;
1806 return os_snprintf(buf, buflen, "%s", pin_txt);
1807 }
1808
1809 if (os_strcmp(cmd, "set") == 0) {
1810 char *pin;
1811 if (pos == NULL)
1812 return -1;
1813 pin = pos;
1814 pos = os_strchr(pos, ' ');
1815 if (pos) {
1816 *pos++ = '\0';
1817 timeout = atoi(pos);
1818 }
1819 if (os_strlen(pin) > buflen)
1820 return -1;
1821 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1822 return -1;
1823 return os_snprintf(buf, buflen, "%s", pin);
1824 }
1825
1826 return -1;
1827}
1828#endif /* CONFIG_AP */
1829
1830
1831#ifdef CONFIG_WPS_ER
1832static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1833 char *cmd)
1834{
1835 char *uuid = cmd, *pin, *pos;
1836 u8 addr_buf[ETH_ALEN], *addr = NULL;
1837 pin = os_strchr(uuid, ' ');
1838 if (pin == NULL)
1839 return -1;
1840 *pin++ = '\0';
1841 pos = os_strchr(pin, ' ');
1842 if (pos) {
1843 *pos++ = '\0';
1844 if (hwaddr_aton(pos, addr_buf) == 0)
1845 addr = addr_buf;
1846 }
1847 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1848}
1849
1850
1851static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1852 char *cmd)
1853{
1854 char *uuid = cmd, *pin;
1855 pin = os_strchr(uuid, ' ');
1856 if (pin == NULL)
1857 return -1;
1858 *pin++ = '\0';
1859 return wpas_wps_er_learn(wpa_s, uuid, pin);
1860}
1861
1862
1863static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1864 struct wpa_supplicant *wpa_s, char *cmd)
1865{
1866 char *uuid = cmd, *id;
1867 id = os_strchr(uuid, ' ');
1868 if (id == NULL)
1869 return -1;
1870 *id++ = '\0';
1871 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1872}
1873
1874
1875static int wpa_supplicant_ctrl_iface_wps_er_config(
1876 struct wpa_supplicant *wpa_s, char *cmd)
1877{
1878 char *pin;
1879 char *new_ssid;
1880 char *new_auth;
1881 char *new_encr;
1882 char *new_key;
1883 struct wps_new_ap_settings ap;
1884
1885 pin = os_strchr(cmd, ' ');
1886 if (pin == NULL)
1887 return -1;
1888 *pin++ = '\0';
1889
1890 new_ssid = os_strchr(pin, ' ');
1891 if (new_ssid == NULL)
1892 return -1;
1893 *new_ssid++ = '\0';
1894
1895 new_auth = os_strchr(new_ssid, ' ');
1896 if (new_auth == NULL)
1897 return -1;
1898 *new_auth++ = '\0';
1899
1900 new_encr = os_strchr(new_auth, ' ');
1901 if (new_encr == NULL)
1902 return -1;
1903 *new_encr++ = '\0';
1904
1905 new_key = os_strchr(new_encr, ' ');
1906 if (new_key == NULL)
1907 return -1;
1908 *new_key++ = '\0';
1909
1910 os_memset(&ap, 0, sizeof(ap));
1911 ap.ssid_hex = new_ssid;
1912 ap.auth = new_auth;
1913 ap.encr = new_encr;
1914 ap.key_hex = new_key;
1915 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1916}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001917
1918
1919#ifdef CONFIG_WPS_NFC
1920static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1921 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1922{
1923 int ndef;
1924 struct wpabuf *buf;
1925 int res;
1926 char *uuid;
1927
1928 uuid = os_strchr(cmd, ' ');
1929 if (uuid == NULL)
1930 return -1;
1931 *uuid++ = '\0';
1932
1933 if (os_strcmp(cmd, "WPS") == 0)
1934 ndef = 0;
1935 else if (os_strcmp(cmd, "NDEF") == 0)
1936 ndef = 1;
1937 else
1938 return -1;
1939
1940 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1941 if (buf == NULL)
1942 return -1;
1943
1944 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1945 wpabuf_len(buf));
1946 reply[res++] = '\n';
1947 reply[res] = '\0';
1948
1949 wpabuf_free(buf);
1950
1951 return res;
1952}
1953#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001954#endif /* CONFIG_WPS_ER */
1955
1956#endif /* CONFIG_WPS */
1957
1958
1959#ifdef CONFIG_IBSS_RSN
1960static int wpa_supplicant_ctrl_iface_ibss_rsn(
1961 struct wpa_supplicant *wpa_s, char *addr)
1962{
1963 u8 peer[ETH_ALEN];
1964
1965 if (hwaddr_aton(addr, peer)) {
1966 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1967 "address '%s'", addr);
1968 return -1;
1969 }
1970
1971 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1972 MAC2STR(peer));
1973
1974 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1975}
1976#endif /* CONFIG_IBSS_RSN */
1977
1978
1979static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1980 char *rsp)
1981{
1982#ifdef IEEE8021X_EAPOL
1983 char *pos, *id_pos;
1984 int id;
1985 struct wpa_ssid *ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001986
1987 pos = os_strchr(rsp, '-');
1988 if (pos == NULL)
1989 return -1;
1990 *pos++ = '\0';
1991 id_pos = pos;
1992 pos = os_strchr(pos, ':');
1993 if (pos == NULL)
1994 return -1;
1995 *pos++ = '\0';
1996 id = atoi(id_pos);
1997 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1998 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1999 (u8 *) pos, os_strlen(pos));
2000
2001 ssid = wpa_config_get_network(wpa_s->conf, id);
2002 if (ssid == NULL) {
2003 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2004 "to update", id);
2005 return -1;
2006 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002007
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002008 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
2009 pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002010#else /* IEEE8021X_EAPOL */
2011 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
2012 return -1;
2013#endif /* IEEE8021X_EAPOL */
2014}
2015
2016
2017static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
2018 const char *params,
2019 char *buf, size_t buflen)
2020{
2021 char *pos, *end, tmp[30];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002022 int res, verbose, wps, ret;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002023#ifdef CONFIG_HS20
2024 const u8 *hs20;
2025#endif /* CONFIG_HS20 */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002026 const u8 *sess_id;
2027 size_t sess_id_len;
Dmitry Shmidt44da0252011-08-23 12:30:30 -07002028
Dmitry Shmidt56052862013-10-04 10:23:25 -07002029 if (os_strcmp(params, "-DRIVER") == 0)
2030 return wpa_drv_status(wpa_s, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002031 verbose = os_strcmp(params, "-VERBOSE") == 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002032 wps = os_strcmp(params, "-WPS") == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002033 pos = buf;
2034 end = buf + buflen;
2035 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
2036 struct wpa_ssid *ssid = wpa_s->current_ssid;
2037 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2038 MAC2STR(wpa_s->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002039 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002040 return pos - buf;
2041 pos += ret;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002042 ret = os_snprintf(pos, end - pos, "freq=%u\n",
2043 wpa_s->assoc_freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002044 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002045 return pos - buf;
2046 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002047 if (ssid) {
2048 u8 *_ssid = ssid->ssid;
2049 size_t ssid_len = ssid->ssid_len;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -07002050 u8 ssid_buf[SSID_MAX_LEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002051 if (ssid_len == 0) {
2052 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
2053 if (_res < 0)
2054 ssid_len = 0;
2055 else
2056 ssid_len = _res;
2057 _ssid = ssid_buf;
2058 }
2059 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
2060 wpa_ssid_txt(_ssid, ssid_len),
2061 ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002062 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002063 return pos - buf;
2064 pos += ret;
2065
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002066 if (wps && ssid->passphrase &&
2067 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
2068 (ssid->mode == WPAS_MODE_AP ||
2069 ssid->mode == WPAS_MODE_P2P_GO)) {
2070 ret = os_snprintf(pos, end - pos,
2071 "passphrase=%s\n",
2072 ssid->passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002073 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002074 return pos - buf;
2075 pos += ret;
2076 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002077 if (ssid->id_str) {
2078 ret = os_snprintf(pos, end - pos,
2079 "id_str=%s\n",
2080 ssid->id_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002081 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002082 return pos - buf;
2083 pos += ret;
2084 }
2085
2086 switch (ssid->mode) {
2087 case WPAS_MODE_INFRA:
2088 ret = os_snprintf(pos, end - pos,
2089 "mode=station\n");
2090 break;
2091 case WPAS_MODE_IBSS:
2092 ret = os_snprintf(pos, end - pos,
2093 "mode=IBSS\n");
2094 break;
2095 case WPAS_MODE_AP:
2096 ret = os_snprintf(pos, end - pos,
2097 "mode=AP\n");
2098 break;
2099 case WPAS_MODE_P2P_GO:
2100 ret = os_snprintf(pos, end - pos,
2101 "mode=P2P GO\n");
2102 break;
2103 case WPAS_MODE_P2P_GROUP_FORMATION:
2104 ret = os_snprintf(pos, end - pos,
2105 "mode=P2P GO - group "
2106 "formation\n");
2107 break;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002108 case WPAS_MODE_MESH:
2109 ret = os_snprintf(pos, end - pos,
2110 "mode=mesh\n");
2111 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002112 default:
2113 ret = 0;
2114 break;
2115 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002116 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002117 return pos - buf;
2118 pos += ret;
2119 }
2120
2121#ifdef CONFIG_AP
2122 if (wpa_s->ap_iface) {
2123 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
2124 end - pos,
2125 verbose);
2126 } else
2127#endif /* CONFIG_AP */
2128 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
2129 }
Paul Stewart092955c2017-02-06 09:13:09 -08002130#ifdef CONFIG_SME
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002131#ifdef CONFIG_SAE
2132 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07002133#ifdef CONFIG_AP
2134 !wpa_s->ap_iface &&
2135#endif /* CONFIG_AP */
2136 wpa_s->sme.sae.state == SAE_ACCEPTED) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002137 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
2138 wpa_s->sme.sae.group);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002139 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002140 return pos - buf;
2141 pos += ret;
2142 }
2143#endif /* CONFIG_SAE */
Paul Stewart092955c2017-02-06 09:13:09 -08002144#endif /* CONFIG_SME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002145 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
2146 wpa_supplicant_state_txt(wpa_s->wpa_state));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002147 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002148 return pos - buf;
2149 pos += ret;
2150
2151 if (wpa_s->l2 &&
2152 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
2153 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002154 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002155 return pos - buf;
2156 pos += ret;
2157 }
2158
2159#ifdef CONFIG_P2P
2160 if (wpa_s->global->p2p) {
2161 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
2162 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002163 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002164 return pos - buf;
2165 pos += ret;
2166 }
2167#endif /* CONFIG_P2P */
2168
2169 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
2170 MAC2STR(wpa_s->own_addr));
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
Dmitry Shmidt04949592012-07-19 12:16:46 -07002175#ifdef CONFIG_HS20
2176 if (wpa_s->current_bss &&
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002177 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
2178 HS20_IE_VENDOR_TYPE)) &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002179 wpa_s->wpa_proto == WPA_PROTO_RSN &&
2180 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002181 int release = 1;
2182 if (hs20[1] >= 5) {
2183 u8 rel_num = (hs20[6] & 0xf0) >> 4;
2184 release = rel_num + 1;
2185 }
2186 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002187 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002188 return pos - buf;
2189 pos += ret;
2190 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002191
2192 if (wpa_s->current_ssid) {
2193 struct wpa_cred *cred;
2194 char *type;
2195
2196 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002197 size_t i;
2198
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002199 if (wpa_s->current_ssid->parent_cred != cred)
2200 continue;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002201
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002202 if (cred->provisioning_sp) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07002203 ret = os_snprintf(pos, end - pos,
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002204 "provisioning_sp=%s\n",
2205 cred->provisioning_sp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002206 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt051af732013-10-22 13:52:46 -07002207 return pos - buf;
2208 pos += ret;
2209 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002210
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002211 if (!cred->domain)
2212 goto no_domain;
2213
2214 i = 0;
2215 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
2216 struct wpabuf *names =
2217 wpa_s->current_bss->anqp->domain_name;
2218 for (i = 0; names && i < cred->num_domain; i++)
2219 {
2220 if (domain_name_list_contains(
2221 names, cred->domain[i], 1))
2222 break;
2223 }
2224 if (i == cred->num_domain)
2225 i = 0; /* show first entry by default */
2226 }
2227 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
2228 cred->domain[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002229 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002230 return pos - buf;
2231 pos += ret;
2232
2233 no_domain:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002234 if (wpa_s->current_bss == NULL ||
2235 wpa_s->current_bss->anqp == NULL)
2236 res = -1;
2237 else
2238 res = interworking_home_sp_cred(
2239 wpa_s, cred,
2240 wpa_s->current_bss->anqp->domain_name);
2241 if (res > 0)
2242 type = "home";
2243 else if (res == 0)
2244 type = "roaming";
2245 else
2246 type = "unknown";
2247
2248 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002249 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002250 return pos - buf;
2251 pos += ret;
2252
2253 break;
2254 }
2255 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002256#endif /* CONFIG_HS20 */
2257
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002258 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
2259 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
2260 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
2261 verbose);
2262 if (res >= 0)
2263 pos += res;
2264 }
2265
Dmitry Shmidt29333592017-01-09 12:27:11 -08002266#ifdef CONFIG_MACSEC
2267 res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
2268 if (res > 0)
2269 pos += res;
2270#endif /* CONFIG_MACSEC */
2271
Dmitry Shmidt216983b2015-02-06 10:50:36 -08002272 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
2273 if (sess_id) {
2274 char *start = pos;
2275
2276 ret = os_snprintf(pos, end - pos, "eap_session_id=");
2277 if (os_snprintf_error(end - pos, ret))
2278 return start - buf;
2279 pos += ret;
2280 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
2281 if (ret <= 0)
2282 return start - buf;
2283 pos += ret;
2284 ret = os_snprintf(pos, end - pos, "\n");
2285 if (os_snprintf_error(end - pos, ret))
2286 return start - buf;
2287 pos += ret;
2288 }
2289
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002290 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
2291 if (res >= 0)
2292 pos += res;
2293
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002294#ifdef CONFIG_WPS
2295 {
2296 char uuid_str[100];
2297 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
2298 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002299 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002300 return pos - buf;
2301 pos += ret;
2302 }
2303#endif /* CONFIG_WPS */
2304
Roshan Pius3a1667e2018-07-03 15:17:14 -07002305 if (wpa_s->ieee80211ac) {
2306 ret = os_snprintf(pos, end - pos, "ieee80211ac=1\n");
2307 if (os_snprintf_error(end - pos, ret))
2308 return pos - buf;
2309 pos += ret;
2310 }
2311
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002312#ifdef ANDROID
vandwalleffc70182014-09-11 11:40:14 -07002313 /*
2314 * Allow using the STATUS command with default behavior, say for debug,
2315 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2316 * events with STATUS-NO_EVENTS.
2317 */
2318 if (os_strcmp(params, "-NO_EVENTS")) {
2319 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
2320 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
2321 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
2322 wpa_s->wpa_state,
2323 MAC2STR(wpa_s->bssid),
2324 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
2325 wpa_ssid_txt(wpa_s->current_ssid->ssid,
2326 wpa_s->current_ssid->ssid_len) : "");
2327 if (wpa_s->wpa_state == WPA_COMPLETED) {
2328 struct wpa_ssid *ssid = wpa_s->current_ssid;
2329 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
2330 "- connection to " MACSTR
2331 " completed %s [id=%d id_str=%s]",
2332 MAC2STR(wpa_s->bssid), "(auth)",
2333 ssid ? ssid->id : -1,
2334 ssid && ssid->id_str ? ssid->id_str : "");
2335 }
Irfan Sheriffbf5edf42012-01-11 16:54:57 -08002336 }
Dmitry Shmidt2fd7fa62011-12-19 11:19:09 -08002337#endif /* ANDROID */
2338
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002339 return pos - buf;
2340}
2341
2342
2343static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2344 char *cmd)
2345{
2346 char *pos;
2347 int id;
2348 struct wpa_ssid *ssid;
2349 u8 bssid[ETH_ALEN];
2350
2351 /* cmd: "<network id> <BSSID>" */
2352 pos = os_strchr(cmd, ' ');
2353 if (pos == NULL)
2354 return -1;
2355 *pos++ = '\0';
2356 id = atoi(cmd);
2357 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2358 if (hwaddr_aton(pos, bssid)) {
2359 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2360 return -1;
2361 }
2362
2363 ssid = wpa_config_get_network(wpa_s->conf, id);
2364 if (ssid == NULL) {
2365 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2366 "to update", id);
2367 return -1;
2368 }
2369
2370 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2371 ssid->bssid_set = !is_zero_ether_addr(bssid);
2372
2373 return 0;
2374}
2375
2376
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002377static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002378 char *cmd, char *buf,
2379 size_t buflen)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002380{
2381 u8 bssid[ETH_ALEN];
2382 struct wpa_blacklist *e;
2383 char *pos, *end;
2384 int ret;
2385
2386 /* cmd: "BLACKLIST [<BSSID>]" */
2387 if (*cmd == '\0') {
2388 pos = buf;
2389 end = buf + buflen;
2390 e = wpa_s->blacklist;
2391 while (e) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002392 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2393 MAC2STR(e->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002394 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002395 return pos - buf;
2396 pos += ret;
2397 e = e->next;
2398 }
2399 return pos - buf;
2400 }
2401
2402 cmd++;
2403 if (os_strncmp(cmd, "clear", 5) == 0) {
2404 wpa_blacklist_clear(wpa_s);
2405 os_memcpy(buf, "OK\n", 3);
2406 return 3;
2407 }
2408
2409 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
2410 if (hwaddr_aton(cmd, bssid)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002411 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002412 return -1;
2413 }
2414
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002415 /*
2416 * Add the BSSID twice, so its count will be 2, causing it to be
2417 * skipped when processing scan results.
2418 */
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002419 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002420 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002421 return -1;
2422 ret = wpa_blacklist_add(wpa_s, bssid);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002423 if (ret < 0)
Dmitry Shmidte19501d2011-03-16 14:32:18 -07002424 return -1;
2425 os_memcpy(buf, "OK\n", 3);
2426 return 3;
2427}
2428
2429
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002430static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2431 char *cmd, char *buf,
2432 size_t buflen)
2433{
2434 char *pos, *end, *stamp;
2435 int ret;
2436
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002437 /* cmd: "LOG_LEVEL [<level>]" */
2438 if (*cmd == '\0') {
2439 pos = buf;
2440 end = buf + buflen;
2441 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2442 "Timestamp: %d\n",
2443 debug_level_str(wpa_debug_level),
2444 wpa_debug_timestamp);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002445 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002446 ret = 0;
2447
2448 return ret;
2449 }
2450
2451 while (*cmd == ' ')
2452 cmd++;
2453
2454 stamp = os_strchr(cmd, ' ');
2455 if (stamp) {
2456 *stamp++ = '\0';
2457 while (*stamp == ' ') {
2458 stamp++;
2459 }
2460 }
2461
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002462 if (os_strlen(cmd)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002463 int level = str_to_debug_level(cmd);
2464 if (level < 0)
2465 return -1;
2466 wpa_debug_level = level;
2467 }
2468
2469 if (stamp && os_strlen(stamp))
2470 wpa_debug_timestamp = atoi(stamp);
2471
2472 os_memcpy(buf, "OK\n", 3);
2473 return 3;
2474}
2475
2476
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002477static int wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002478 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002479{
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002480 char *pos, *end, *prev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002481 struct wpa_ssid *ssid;
2482 int ret;
2483
2484 pos = buf;
2485 end = buf + buflen;
2486 ret = os_snprintf(pos, end - pos,
2487 "network id / ssid / bssid / flags\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002488 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002489 return pos - buf;
2490 pos += ret;
2491
2492 ssid = wpa_s->conf->ssid;
Vinit Deshpandeda134e92014-12-02 10:59:29 -08002493
2494 /* skip over ssids until we find next one */
2495 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2496 int last_id = atoi(cmd + 8);
2497 if (last_id != -1) {
2498 while (ssid != NULL && ssid->id <= last_id) {
2499 ssid = ssid->next;
2500 }
2501 }
2502 }
2503
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002504 while (ssid) {
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002505 prev = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002506 ret = os_snprintf(pos, end - pos, "%d\t%s",
2507 ssid->id,
2508 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002509 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002510 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002511 pos += ret;
2512 if (ssid->bssid_set) {
2513 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2514 MAC2STR(ssid->bssid));
2515 } else {
2516 ret = os_snprintf(pos, end - pos, "\tany");
2517 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002518 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002519 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002520 pos += ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002521 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002522 ssid == wpa_s->current_ssid ?
2523 "[CURRENT]" : "",
2524 ssid->disabled ? "[DISABLED]" : "",
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002525 ssid->disabled_until.sec ?
2526 "[TEMP-DISABLED]" : "",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002527 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2528 "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002529 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002530 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002531 pos += ret;
2532 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002533 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt9e37fc22014-12-03 11:48:46 -08002534 return prev - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002535 pos += ret;
2536
2537 ssid = ssid->next;
2538 }
2539
2540 return pos - buf;
2541}
2542
2543
2544static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2545{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002546 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002547 ret = os_snprintf(pos, end - pos, "-");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002548 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002549 return pos;
2550 pos += ret;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08002551 ret = wpa_write_ciphers(pos, end, cipher, "+");
2552 if (ret < 0)
2553 return pos;
2554 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002555 return pos;
2556}
2557
2558
2559static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2560 const u8 *ie, size_t ie_len)
2561{
2562 struct wpa_ie_data data;
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002563 char *start;
2564 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002565
2566 ret = os_snprintf(pos, end - pos, "[%s-", proto);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002567 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002568 return pos;
2569 pos += ret;
2570
2571 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2572 ret = os_snprintf(pos, end - pos, "?]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002573 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002574 return pos;
2575 pos += ret;
2576 return pos;
2577 }
2578
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002579 start = pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002580 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002581 ret = os_snprintf(pos, end - pos, "%sEAP",
2582 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002583 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002584 return pos;
2585 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002586 }
2587 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002588 ret = os_snprintf(pos, end - pos, "%sPSK",
2589 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002590 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002591 return pos;
2592 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002593 }
2594 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002595 ret = os_snprintf(pos, end - pos, "%sNone",
2596 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002597 if (os_snprintf_error(end - pos, ret))
2598 return pos;
2599 pos += ret;
2600 }
2601 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2602 ret = os_snprintf(pos, end - pos, "%sSAE",
2603 pos == start ? "" : "+");
2604 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002605 return pos;
2606 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002607 }
2608#ifdef CONFIG_IEEE80211R
2609 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2610 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002611 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002612 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002613 return pos;
2614 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002615 }
2616 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2617 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002618 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002619 if (os_snprintf_error(end - pos, ret))
2620 return pos;
2621 pos += ret;
2622 }
2623 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2624 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2625 pos == start ? "" : "+");
2626 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002627 return pos;
2628 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002629 }
2630#endif /* CONFIG_IEEE80211R */
2631#ifdef CONFIG_IEEE80211W
2632 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2633 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002634 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002635 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002636 return pos;
2637 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002638 }
2639 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2640 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002641 pos == start ? "" : "+");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002642 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002643 return pos;
2644 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002645 }
2646#endif /* CONFIG_IEEE80211W */
2647
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002648#ifdef CONFIG_SUITEB
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002649 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2650 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2651 pos == start ? "" : "+");
2652 if (os_snprintf_error(end - pos, ret))
2653 return pos;
2654 pos += ret;
2655 }
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002656#endif /* CONFIG_SUITEB */
2657
2658#ifdef CONFIG_SUITEB192
2659 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2660 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2661 pos == start ? "" : "+");
2662 if (os_snprintf_error(end - pos, ret))
2663 return pos;
2664 pos += ret;
2665 }
2666#endif /* CONFIG_SUITEB192 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002667
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002668#ifdef CONFIG_FILS
2669 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
2670 ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
2671 pos == start ? "" : "+");
2672 if (os_snprintf_error(end - pos, ret))
2673 return pos;
2674 pos += ret;
2675 }
2676 if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
2677 ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
2678 pos == start ? "" : "+");
2679 if (os_snprintf_error(end - pos, ret))
2680 return pos;
2681 pos += ret;
2682 }
2683#ifdef CONFIG_IEEE80211R
2684 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
2685 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
2686 pos == start ? "" : "+");
2687 if (os_snprintf_error(end - pos, ret))
2688 return pos;
2689 pos += ret;
2690 }
2691 if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
2692 ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
2693 pos == start ? "" : "+");
2694 if (os_snprintf_error(end - pos, ret))
2695 return pos;
2696 pos += ret;
2697 }
2698#endif /* CONFIG_IEEE80211R */
2699#endif /* CONFIG_FILS */
2700
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002701#ifdef CONFIG_OWE
2702 if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
2703 ret = os_snprintf(pos, end - pos, "%sOWE",
2704 pos == start ? "" : "+");
2705 if (os_snprintf_error(end - pos, ret))
2706 return pos;
2707 pos += ret;
2708 }
2709#endif /* CONFIG_OWE */
2710
2711#ifdef CONFIG_DPP
2712 if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
2713 ret = os_snprintf(pos, end - pos, "%sDPP",
2714 pos == start ? "" : "+");
2715 if (os_snprintf_error(end - pos, ret))
2716 return pos;
2717 pos += ret;
2718 }
2719#endif /* CONFIG_DPP */
2720
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002721 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2722 ret = os_snprintf(pos, end - pos, "%sOSEN",
2723 pos == start ? "" : "+");
2724 if (os_snprintf_error(end - pos, ret))
2725 return pos;
2726 pos += ret;
2727 }
2728
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002729 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2730
2731 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2732 ret = os_snprintf(pos, end - pos, "-preauth");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002733 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002734 return pos;
2735 pos += ret;
2736 }
2737
2738 ret = os_snprintf(pos, end - pos, "]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002739 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002740 return pos;
2741 pos += ret;
2742
2743 return pos;
2744}
2745
2746
2747#ifdef CONFIG_WPS
2748static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2749 char *pos, char *end,
2750 struct wpabuf *wps_ie)
2751{
2752 int ret;
2753 const char *txt;
2754
2755 if (wps_ie == NULL)
2756 return pos;
2757 if (wps_is_selected_pbc_registrar(wps_ie))
2758 txt = "[WPS-PBC]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002759 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2760 txt = "[WPS-AUTH]";
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002761 else if (wps_is_selected_pin_registrar(wps_ie))
2762 txt = "[WPS-PIN]";
2763 else
2764 txt = "[WPS]";
2765
2766 ret = os_snprintf(pos, end - pos, "%s", txt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002767 if (!os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002768 pos += ret;
2769 wpabuf_free(wps_ie);
2770 return pos;
2771}
2772#endif /* CONFIG_WPS */
2773
2774
2775static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2776 char *pos, char *end,
2777 const struct wpa_bss *bss)
2778{
2779#ifdef CONFIG_WPS
2780 struct wpabuf *wps_ie;
2781 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2782 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2783#else /* CONFIG_WPS */
2784 return pos;
2785#endif /* CONFIG_WPS */
2786}
2787
2788
2789/* Format one result on one text line into a buffer. */
2790static int wpa_supplicant_ctrl_iface_scan_result(
2791 struct wpa_supplicant *wpa_s,
2792 const struct wpa_bss *bss, char *buf, size_t buflen)
2793{
2794 char *pos, *end;
2795 int ret;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002796 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002797
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002798 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002799 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt96571392013-10-14 12:54:46 -07002800 if (!p2p)
2801 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002802 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2803 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2804 0)
2805 return 0; /* Do not show P2P listen discovery results here */
2806
2807 pos = buf;
2808 end = buf + buflen;
2809
2810 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2811 MAC2STR(bss->bssid), bss->freq, bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002812 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002813 return -1;
2814 pos += ret;
2815 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2816 if (ie)
2817 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2818 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002819 if (ie2) {
2820 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2821 ie2, 2 + ie2[1]);
2822 }
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002823 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
2824 if (osen_ie)
2825 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
2826 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002827 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
2828 if (owe) {
2829 ret = os_snprintf(pos, end - pos,
2830 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
2831 if (os_snprintf_error(end - pos, ret))
2832 return -1;
2833 pos += ret;
2834 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002835 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07002836 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002837 ret = os_snprintf(pos, end - pos, "[WEP]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002838 if (os_snprintf_error(end - pos, ret))
2839 return -1;
2840 pos += ret;
2841 }
2842 if (mesh) {
2843 ret = os_snprintf(pos, end - pos, "[MESH]");
2844 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002845 return -1;
2846 pos += ret;
2847 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002848 if (bss_is_dmg(bss)) {
2849 const char *s;
2850 ret = os_snprintf(pos, end - pos, "[DMG]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002851 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002852 return -1;
2853 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002854 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2855 case IEEE80211_CAP_DMG_IBSS:
2856 s = "[IBSS]";
2857 break;
2858 case IEEE80211_CAP_DMG_AP:
2859 s = "[ESS]";
2860 break;
2861 case IEEE80211_CAP_DMG_PBSS:
2862 s = "[PBSS]";
2863 break;
2864 default:
2865 s = "";
2866 break;
2867 }
2868 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002869 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002870 return -1;
2871 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002872 } else {
2873 if (bss->caps & IEEE80211_CAP_IBSS) {
2874 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002875 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002876 return -1;
2877 pos += ret;
2878 }
2879 if (bss->caps & IEEE80211_CAP_ESS) {
2880 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002881 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07002882 return -1;
2883 pos += ret;
2884 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002885 }
2886 if (p2p) {
2887 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002888 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002889 return -1;
2890 pos += ret;
2891 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07002892#ifdef CONFIG_HS20
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002893 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07002894 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002895 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07002896 return -1;
2897 pos += ret;
2898 }
2899#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002900#ifdef CONFIG_FILS
2901 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
2902 ret = os_snprintf(pos, end - pos, "[FILS]");
2903 if (os_snprintf_error(end - pos, ret))
2904 return -1;
2905 pos += ret;
2906 }
2907#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002908#ifdef CONFIG_FST
2909 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
2910 ret = os_snprintf(pos, end - pos, "[FST]");
2911 if (os_snprintf_error(end - pos, ret))
2912 return -1;
2913 pos += ret;
2914 }
2915#endif /* CONFIG_FST */
Hai Shalom39bc25d2019-02-06 16:32:13 -08002916 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
2917 ret = os_snprintf(pos, end - pos, "[UTF-8]");
2918 if (os_snprintf_error(end - pos, ret))
2919 return -1;
2920 pos += ret;
2921 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002922
2923 ret = os_snprintf(pos, end - pos, "\t%s",
2924 wpa_ssid_txt(bss->ssid, bss->ssid_len));
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;
2928
2929 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002930 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002931 return -1;
2932 pos += ret;
2933
2934 return pos - buf;
2935}
2936
2937
2938static int wpa_supplicant_ctrl_iface_scan_results(
2939 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2940{
2941 char *pos, *end;
2942 struct wpa_bss *bss;
2943 int ret;
2944
2945 pos = buf;
2946 end = buf + buflen;
2947 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2948 "flags / ssid\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002949 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002950 return pos - buf;
2951 pos += ret;
2952
2953 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2954 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2955 end - pos);
2956 if (ret < 0 || ret >= end - pos)
2957 return pos - buf;
2958 pos += ret;
2959 }
2960
2961 return pos - buf;
2962}
2963
2964
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002965#ifdef CONFIG_MESH
2966
2967static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2968 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2969{
2970 char *pos, ifname[IFNAMSIZ + 1];
2971
2972 ifname[0] = '\0';
2973
2974 pos = os_strstr(cmd, "ifname=");
2975 if (pos) {
2976 pos += 7;
2977 os_strlcpy(ifname, pos, sizeof(ifname));
2978 }
2979
2980 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
2981 return -1;
2982
2983 os_strlcpy(reply, ifname, max_len);
2984 return os_strlen(ifname);
2985}
2986
2987
2988static int wpa_supplicant_ctrl_iface_mesh_group_add(
2989 struct wpa_supplicant *wpa_s, char *cmd)
2990{
2991 int id;
2992 struct wpa_ssid *ssid;
2993
2994 id = atoi(cmd);
2995 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
2996
2997 ssid = wpa_config_get_network(wpa_s->conf, id);
2998 if (ssid == NULL) {
2999 wpa_printf(MSG_DEBUG,
3000 "CTRL_IFACE: Could not find network id=%d", id);
3001 return -1;
3002 }
3003 if (ssid->mode != WPAS_MODE_MESH) {
3004 wpa_printf(MSG_DEBUG,
3005 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
3006 return -1;
3007 }
3008 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
3009 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
3010 wpa_printf(MSG_ERROR,
3011 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
3012 return -1;
3013 }
3014
3015 /*
3016 * TODO: If necessary write our own group_add function,
3017 * for now we can reuse select_network
3018 */
3019 wpa_supplicant_select_network(wpa_s, ssid);
3020
3021 return 0;
3022}
3023
3024
3025static int wpa_supplicant_ctrl_iface_mesh_group_remove(
3026 struct wpa_supplicant *wpa_s, char *cmd)
3027{
3028 struct wpa_supplicant *orig;
3029 struct wpa_global *global;
3030 int found = 0;
3031
3032 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
3033
3034 global = wpa_s->global;
3035 orig = wpa_s;
3036
3037 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3038 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
3039 found = 1;
3040 break;
3041 }
3042 }
3043 if (!found) {
3044 wpa_printf(MSG_ERROR,
3045 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
3046 cmd);
3047 return -1;
3048 }
3049 if (wpa_s->mesh_if_created && wpa_s == orig) {
3050 wpa_printf(MSG_ERROR,
3051 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
3052 return -1;
3053 }
3054
3055 wpa_s->reassociate = 0;
3056 wpa_s->disconnected = 1;
3057 wpa_supplicant_cancel_sched_scan(wpa_s);
3058 wpa_supplicant_cancel_scan(wpa_s);
3059
3060 /*
3061 * TODO: If necessary write our own group_remove function,
3062 * for now we can reuse deauthenticate
3063 */
3064 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
3065
3066 if (wpa_s->mesh_if_created)
3067 wpa_supplicant_remove_iface(global, wpa_s, 0);
3068
3069 return 0;
3070}
3071
Dmitry Shmidte4663042016-04-04 10:07:49 -07003072
3073static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
3074 struct wpa_supplicant *wpa_s, char *cmd)
3075{
3076 u8 addr[ETH_ALEN];
3077
3078 if (hwaddr_aton(cmd, addr) < 0)
3079 return -1;
3080
3081 return wpas_mesh_peer_remove(wpa_s, addr);
3082}
3083
3084
3085static int wpa_supplicant_ctrl_iface_mesh_peer_add(
3086 struct wpa_supplicant *wpa_s, char *cmd)
3087{
3088 u8 addr[ETH_ALEN];
3089 int duration;
3090 char *pos;
3091
3092 pos = os_strstr(cmd, " duration=");
3093 if (pos) {
3094 *pos = '\0';
3095 duration = atoi(pos + 10);
3096 } else {
3097 duration = -1;
3098 }
3099
3100 if (hwaddr_aton(cmd, addr))
3101 return -1;
3102
3103 return wpas_mesh_peer_add(wpa_s, addr, duration);
3104}
3105
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003106#endif /* CONFIG_MESH */
3107
3108
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003109static int wpa_supplicant_ctrl_iface_select_network(
3110 struct wpa_supplicant *wpa_s, char *cmd)
3111{
3112 int id;
3113 struct wpa_ssid *ssid;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003114 char *pos;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003115
3116 /* cmd: "<network id>" or "any" */
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003117 if (os_strncmp(cmd, "any", 3) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003118 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
3119 ssid = NULL;
3120 } else {
3121 id = atoi(cmd);
3122 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
3123
3124 ssid = wpa_config_get_network(wpa_s->conf, id);
3125 if (ssid == NULL) {
3126 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3127 "network id=%d", id);
3128 return -1;
3129 }
3130 if (ssid->disabled == 2) {
3131 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3132 "SELECT_NETWORK with persistent P2P group");
3133 return -1;
3134 }
3135 }
3136
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003137 pos = os_strstr(cmd, " freq=");
3138 if (pos) {
3139 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
3140 if (freqs) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003141 os_free(wpa_s->select_network_scan_freqs);
3142 wpa_s->select_network_scan_freqs = freqs;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003143 }
3144 }
3145
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003146 wpa_s->scan_min_time.sec = 0;
3147 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003148 wpa_supplicant_select_network(wpa_s, ssid);
3149
3150 return 0;
3151}
3152
3153
3154static int wpa_supplicant_ctrl_iface_enable_network(
3155 struct wpa_supplicant *wpa_s, char *cmd)
3156{
3157 int id;
3158 struct wpa_ssid *ssid;
3159
3160 /* cmd: "<network id>" or "all" */
3161 if (os_strcmp(cmd, "all") == 0) {
3162 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
3163 ssid = NULL;
3164 } else {
3165 id = atoi(cmd);
3166 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
3167
3168 ssid = wpa_config_get_network(wpa_s->conf, id);
3169 if (ssid == NULL) {
3170 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3171 "network id=%d", id);
3172 return -1;
3173 }
3174 if (ssid->disabled == 2) {
3175 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3176 "ENABLE_NETWORK with persistent P2P group");
3177 return -1;
3178 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003179
3180 if (os_strstr(cmd, " no-connect")) {
3181 ssid->disabled = 0;
3182 return 0;
3183 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003184 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003185 wpa_s->scan_min_time.sec = 0;
3186 wpa_s->scan_min_time.usec = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003187 wpa_supplicant_enable_network(wpa_s, ssid);
3188
3189 return 0;
3190}
3191
3192
3193static int wpa_supplicant_ctrl_iface_disable_network(
3194 struct wpa_supplicant *wpa_s, char *cmd)
3195{
3196 int id;
3197 struct wpa_ssid *ssid;
3198
3199 /* cmd: "<network id>" or "all" */
3200 if (os_strcmp(cmd, "all") == 0) {
3201 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
3202 ssid = NULL;
3203 } else {
3204 id = atoi(cmd);
3205 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
3206
3207 ssid = wpa_config_get_network(wpa_s->conf, id);
3208 if (ssid == NULL) {
3209 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3210 "network id=%d", id);
3211 return -1;
3212 }
3213 if (ssid->disabled == 2) {
3214 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
3215 "DISABLE_NETWORK with persistent P2P "
3216 "group");
3217 return -1;
3218 }
3219 }
3220 wpa_supplicant_disable_network(wpa_s, ssid);
3221
3222 return 0;
3223}
3224
3225
3226static int wpa_supplicant_ctrl_iface_add_network(
3227 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
3228{
3229 struct wpa_ssid *ssid;
3230 int ret;
3231
3232 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
3233
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003234 ssid = wpa_supplicant_add_network(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003235 if (ssid == NULL)
3236 return -1;
3237
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003238 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003239 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003240 return -1;
3241 return ret;
3242}
3243
3244
3245static int wpa_supplicant_ctrl_iface_remove_network(
3246 struct wpa_supplicant *wpa_s, char *cmd)
3247{
3248 int id;
3249 struct wpa_ssid *ssid;
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003250 int result;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003251
3252 /* cmd: "<network id>" or "all" */
3253 if (os_strcmp(cmd, "all") == 0) {
3254 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
Dmitry Shmidt2f023192013-03-12 12:44:17 -07003255 if (wpa_s->sched_scanning)
3256 wpa_supplicant_cancel_sched_scan(wpa_s);
3257
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003258 eapol_sm_invalidate_cached_session(wpa_s->eapol);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003259 if (wpa_s->current_ssid) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07003260#ifdef CONFIG_SME
3261 wpa_s->sme.prev_bssid_set = 0;
3262#endif /* CONFIG_SME */
Jouni Malinen75ecf522011-06-27 15:19:46 -07003263 wpa_sm_set_config(wpa_s->wpa, NULL);
3264 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07003265 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
3266 wpa_s->own_disconnect_req = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003267 wpa_supplicant_deauthenticate(
3268 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003269 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003270 ssid = wpa_s->conf->ssid;
3271 while (ssid) {
3272 struct wpa_ssid *remove_ssid = ssid;
3273 id = ssid->id;
3274 ssid = ssid->next;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003275 if (wpa_s->last_ssid == remove_ssid)
3276 wpa_s->last_ssid = NULL;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003277 wpas_notify_network_removed(wpa_s, remove_ssid);
3278 wpa_config_remove_network(wpa_s->conf, id);
3279 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003280 return 0;
3281 }
3282
3283 id = atoi(cmd);
3284 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
3285
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003286 result = wpa_supplicant_remove_network(wpa_s, id);
3287 if (result == -1) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003288 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3289 "id=%d", id);
3290 return -1;
3291 }
Dmitry Shmidtd13095b2016-08-22 14:02:19 -07003292 if (result == -2) {
Deepthi Gowria831d782012-09-03 11:55:38 +03003293 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
3294 "network id=%d", id);
3295 return -1;
3296 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003297 return 0;
3298}
3299
3300
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003301static int wpa_supplicant_ctrl_iface_update_network(
3302 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
3303 char *name, char *value)
3304{
Dmitry Shmidte4663042016-04-04 10:07:49 -07003305 int ret;
3306
3307 ret = wpa_config_set(ssid, name, value, 0);
3308 if (ret < 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003309 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
3310 "variable '%s'", name);
3311 return -1;
3312 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07003313 if (ret == 1)
3314 return 0; /* No change to the previously configured value */
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003315
3316 if (os_strcmp(name, "bssid") != 0 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003317 os_strcmp(name, "bssid_hint") != 0 &&
Dmitry Shmidte4663042016-04-04 10:07:49 -07003318 os_strcmp(name, "priority") != 0) {
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003319 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
3320
Dmitry Shmidte4663042016-04-04 10:07:49 -07003321 if (wpa_s->current_ssid == ssid ||
3322 wpa_s->current_ssid == NULL) {
3323 /*
3324 * Invalidate the EAP session cache if anything in the
3325 * current or previously used configuration changes.
3326 */
3327 eapol_sm_invalidate_cached_session(wpa_s->eapol);
3328 }
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003329 }
3330
3331 if ((os_strcmp(name, "psk") == 0 &&
3332 value[0] == '"' && ssid->ssid_len) ||
3333 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
3334 wpa_config_update_psk(ssid);
3335 else if (os_strcmp(name, "priority") == 0)
3336 wpa_config_update_prio_list(wpa_s->conf);
3337
3338 return 0;
3339}
3340
3341
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003342static int wpa_supplicant_ctrl_iface_set_network(
3343 struct wpa_supplicant *wpa_s, char *cmd)
3344{
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003345 int id, ret, prev_bssid_set, prev_disabled;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003346 struct wpa_ssid *ssid;
3347 char *name, *value;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003348 u8 prev_bssid[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003349
3350 /* cmd: "<network id> <variable name> <value>" */
3351 name = os_strchr(cmd, ' ');
3352 if (name == NULL)
3353 return -1;
3354 *name++ = '\0';
3355
3356 value = os_strchr(name, ' ');
3357 if (value == NULL)
3358 return -1;
3359 *value++ = '\0';
3360
3361 id = atoi(cmd);
3362 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3363 id, name);
3364 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3365 (u8 *) value, os_strlen(value));
3366
3367 ssid = wpa_config_get_network(wpa_s->conf, id);
3368 if (ssid == NULL) {
3369 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3370 "id=%d", id);
3371 return -1;
3372 }
3373
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003374 prev_bssid_set = ssid->bssid_set;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003375 prev_disabled = ssid->disabled;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003376 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
3377 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
3378 value);
3379 if (ret == 0 &&
3380 (ssid->bssid_set != prev_bssid_set ||
3381 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
3382 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003383
3384 if (prev_disabled != ssid->disabled &&
3385 (prev_disabled == 2 || ssid->disabled == 2))
3386 wpas_notify_network_type_changed(wpa_s, ssid);
3387
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003388 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003389}
3390
3391
3392static int wpa_supplicant_ctrl_iface_get_network(
3393 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3394{
3395 int id;
3396 size_t res;
3397 struct wpa_ssid *ssid;
3398 char *name, *value;
3399
3400 /* cmd: "<network id> <variable name>" */
3401 name = os_strchr(cmd, ' ');
3402 if (name == NULL || buflen == 0)
3403 return -1;
3404 *name++ = '\0';
3405
3406 id = atoi(cmd);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003407 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003408 id, name);
3409
3410 ssid = wpa_config_get_network(wpa_s->conf, id);
3411 if (ssid == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003412 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003413 "id=%d", id);
3414 return -1;
3415 }
3416
3417 value = wpa_config_get_no_key(ssid, name);
3418 if (value == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003419 wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003420 "variable '%s'", name);
3421 return -1;
3422 }
3423
3424 res = os_strlcpy(buf, value, buflen);
3425 if (res >= buflen) {
3426 os_free(value);
3427 return -1;
3428 }
3429
3430 os_free(value);
3431
3432 return res;
3433}
3434
3435
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003436static int wpa_supplicant_ctrl_iface_dup_network(
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003437 struct wpa_supplicant *wpa_s, char *cmd,
3438 struct wpa_supplicant *dst_wpa_s)
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003439{
3440 struct wpa_ssid *ssid_s, *ssid_d;
3441 char *name, *id, *value;
3442 int id_s, id_d, ret;
3443
3444 /* cmd: "<src network id> <dst network id> <variable name>" */
3445 id = os_strchr(cmd, ' ');
3446 if (id == NULL)
3447 return -1;
3448 *id++ = '\0';
3449
3450 name = os_strchr(id, ' ');
3451 if (name == NULL)
3452 return -1;
3453 *name++ = '\0';
3454
3455 id_s = atoi(cmd);
3456 id_d = atoi(id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003457
3458 wpa_printf(MSG_DEBUG,
3459 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3460 wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003461
3462 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3463 if (ssid_s == NULL) {
3464 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3465 "network id=%d", id_s);
3466 return -1;
3467 }
3468
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003469 ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003470 if (ssid_d == NULL) {
3471 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003472 "network id=%d", id_d);
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003473 return -1;
3474 }
3475
3476 value = wpa_config_get(ssid_s, name);
3477 if (value == NULL) {
3478 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3479 "variable '%s'", name);
3480 return -1;
3481 }
3482
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003483 ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
Dmitry Shmidt684785c2014-05-12 13:34:29 -07003484 value);
3485
3486 os_free(value);
3487
3488 return ret;
3489}
3490
3491
Dmitry Shmidt04949592012-07-19 12:16:46 -07003492static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3493 char *buf, size_t buflen)
3494{
3495 char *pos, *end;
3496 struct wpa_cred *cred;
3497 int ret;
3498
3499 pos = buf;
3500 end = buf + buflen;
3501 ret = os_snprintf(pos, end - pos,
3502 "cred id / realm / username / domain / imsi\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003503 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003504 return pos - buf;
3505 pos += ret;
3506
3507 cred = wpa_s->conf->cred;
3508 while (cred) {
3509 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3510 cred->id, cred->realm ? cred->realm : "",
3511 cred->username ? cred->username : "",
Dmitry Shmidt051af732013-10-22 13:52:46 -07003512 cred->domain ? cred->domain[0] : "",
Dmitry Shmidt04949592012-07-19 12:16:46 -07003513 cred->imsi ? cred->imsi : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003514 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003515 return pos - buf;
3516 pos += ret;
3517
3518 cred = cred->next;
3519 }
3520
3521 return pos - buf;
3522}
3523
3524
3525static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3526 char *buf, size_t buflen)
3527{
3528 struct wpa_cred *cred;
3529 int ret;
3530
3531 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3532
3533 cred = wpa_config_add_cred(wpa_s->conf);
3534 if (cred == NULL)
3535 return -1;
3536
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003537 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3538
Dmitry Shmidt04949592012-07-19 12:16:46 -07003539 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003540 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt04949592012-07-19 12:16:46 -07003541 return -1;
3542 return ret;
3543}
3544
3545
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003546static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
3547 struct wpa_cred *cred)
3548{
3549 struct wpa_ssid *ssid;
3550 char str[20];
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003551 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003552
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003553 if (cred == NULL) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003554 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3555 return -1;
3556 }
3557
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003558 id = cred->id;
3559 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
3560 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3561 return -1;
3562 }
3563
3564 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
3565
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003566 /* Remove any network entry created based on the removed credential */
3567 ssid = wpa_s->conf->ssid;
3568 while (ssid) {
3569 if (ssid->parent_cred == cred) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003570 int res;
3571
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003572 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
3573 "used the removed credential", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003574 res = os_snprintf(str, sizeof(str), "%d", ssid->id);
3575 if (os_snprintf_error(sizeof(str), res))
3576 str[sizeof(str) - 1] = '\0';
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003577 ssid = ssid->next;
3578 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
3579 } else
3580 ssid = ssid->next;
3581 }
3582
3583 return 0;
3584}
3585
3586
Dmitry Shmidt04949592012-07-19 12:16:46 -07003587static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3588 char *cmd)
3589{
3590 int id;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003591 struct wpa_cred *cred, *prev;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003592
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003593 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3594 * "provisioning_sp=<FQDN> */
Dmitry Shmidt04949592012-07-19 12:16:46 -07003595 if (os_strcmp(cmd, "all") == 0) {
3596 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3597 cred = wpa_s->conf->cred;
3598 while (cred) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003599 prev = cred;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003600 cred = cred->next;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003601 wpas_ctrl_remove_cred(wpa_s, prev);
3602 }
3603 return 0;
3604 }
3605
3606 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3607 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3608 cmd + 8);
3609 cred = wpa_s->conf->cred;
3610 while (cred) {
3611 prev = cred;
3612 cred = cred->next;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003613 if (prev->domain) {
3614 size_t i;
3615 for (i = 0; i < prev->num_domain; i++) {
3616 if (os_strcmp(prev->domain[i], cmd + 8)
3617 != 0)
3618 continue;
3619 wpas_ctrl_remove_cred(wpa_s, prev);
3620 break;
3621 }
3622 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003623 }
3624 return 0;
3625 }
3626
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003627 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3628 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3629 cmd + 16);
3630 cred = wpa_s->conf->cred;
3631 while (cred) {
3632 prev = cred;
3633 cred = cred->next;
3634 if (prev->provisioning_sp &&
3635 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3636 wpas_ctrl_remove_cred(wpa_s, prev);
3637 }
3638 return 0;
3639 }
3640
Dmitry Shmidt04949592012-07-19 12:16:46 -07003641 id = atoi(cmd);
3642 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3643
3644 cred = wpa_config_get_cred(wpa_s->conf, id);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003645 return wpas_ctrl_remove_cred(wpa_s, cred);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003646}
3647
3648
3649static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3650 char *cmd)
3651{
3652 int id;
3653 struct wpa_cred *cred;
3654 char *name, *value;
3655
3656 /* cmd: "<cred id> <variable name> <value>" */
3657 name = os_strchr(cmd, ' ');
3658 if (name == NULL)
3659 return -1;
3660 *name++ = '\0';
3661
3662 value = os_strchr(name, ' ');
3663 if (value == NULL)
3664 return -1;
3665 *value++ = '\0';
3666
3667 id = atoi(cmd);
3668 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3669 id, name);
3670 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3671 (u8 *) value, os_strlen(value));
3672
3673 cred = wpa_config_get_cred(wpa_s->conf, id);
3674 if (cred == NULL) {
3675 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3676 id);
3677 return -1;
3678 }
3679
3680 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3681 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3682 "variable '%s'", name);
3683 return -1;
3684 }
3685
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003686 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3687
Dmitry Shmidt04949592012-07-19 12:16:46 -07003688 return 0;
3689}
3690
3691
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -07003692static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3693 char *cmd, char *buf,
3694 size_t buflen)
3695{
3696 int id;
3697 size_t res;
3698 struct wpa_cred *cred;
3699 char *name, *value;
3700
3701 /* cmd: "<cred id> <variable name>" */
3702 name = os_strchr(cmd, ' ');
3703 if (name == NULL)
3704 return -1;
3705 *name++ = '\0';
3706
3707 id = atoi(cmd);
3708 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3709 id, name);
3710
3711 cred = wpa_config_get_cred(wpa_s->conf, id);
3712 if (cred == NULL) {
3713 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3714 id);
3715 return -1;
3716 }
3717
3718 value = wpa_config_get_cred_no_key(cred, name);
3719 if (value == NULL) {
3720 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3721 name);
3722 return -1;
3723 }
3724
3725 res = os_strlcpy(buf, value, buflen);
3726 if (res >= buflen) {
3727 os_free(value);
3728 return -1;
3729 }
3730
3731 os_free(value);
3732
3733 return res;
3734}
3735
3736
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003737#ifndef CONFIG_NO_CONFIG_WRITE
3738static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3739{
3740 int ret;
3741
3742 if (!wpa_s->conf->update_config) {
3743 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3744 "to update configuration (update_config=0)");
3745 return -1;
3746 }
3747
3748 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3749 if (ret) {
3750 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3751 "update configuration");
3752 } else {
3753 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3754 " updated");
3755 }
3756
3757 return ret;
3758}
3759#endif /* CONFIG_NO_CONFIG_WRITE */
3760
3761
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003762struct cipher_info {
3763 unsigned int capa;
3764 const char *name;
3765 int group_only;
3766};
3767
3768static const struct cipher_info ciphers[] = {
3769 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3770 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3771 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3772 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3773 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3774 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3775 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3776 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3777};
3778
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003779static const struct cipher_info ciphers_group_mgmt[] = {
3780 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
3781 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
3782 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
3783 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
3784};
3785
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003786
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003787static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3788 struct wpa_driver_capa *capa,
3789 char *buf, size_t buflen)
3790{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003791 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003792 char *pos, *end;
3793 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003794 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003795
3796 pos = buf;
3797 end = pos + buflen;
3798
3799 if (res < 0) {
3800 if (strict)
3801 return 0;
3802 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3803 if (len >= buflen)
3804 return -1;
3805 return len;
3806 }
3807
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003808 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3809 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3810 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003811 pos == buf ? "" : " ",
3812 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003813 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003814 return pos - buf;
3815 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003816 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003817 }
3818
3819 return pos - buf;
3820}
3821
3822
3823static int ctrl_iface_get_capability_group(int res, char *strict,
3824 struct wpa_driver_capa *capa,
3825 char *buf, size_t buflen)
3826{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003827 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003828 char *pos, *end;
3829 size_t len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003830 unsigned int i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003831
3832 pos = buf;
3833 end = pos + buflen;
3834
3835 if (res < 0) {
3836 if (strict)
3837 return 0;
3838 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3839 if (len >= buflen)
3840 return -1;
3841 return len;
3842 }
3843
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003844 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3845 if (capa->enc & ciphers[i].capa) {
3846 ret = os_snprintf(pos, end - pos, "%s%s",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08003847 pos == buf ? "" : " ",
3848 ciphers[i].name);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003849 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003850 return pos - buf;
3851 pos += ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003852 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003853 }
3854
3855 return pos - buf;
3856}
3857
3858
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003859static int ctrl_iface_get_capability_group_mgmt(int res, char *strict,
3860 struct wpa_driver_capa *capa,
3861 char *buf, size_t buflen)
3862{
3863 int ret;
3864 char *pos, *end;
3865 unsigned int i;
3866
3867 pos = buf;
3868 end = pos + buflen;
3869
3870 if (res < 0)
3871 return 0;
3872
3873 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
3874 if (capa->enc & ciphers_group_mgmt[i].capa) {
3875 ret = os_snprintf(pos, end - pos, "%s%s",
3876 pos == buf ? "" : " ",
3877 ciphers_group_mgmt[i].name);
3878 if (os_snprintf_error(end - pos, ret))
3879 return pos - buf;
3880 pos += ret;
3881 }
3882 }
3883
3884 return pos - buf;
3885}
3886
3887
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003888static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3889 struct wpa_driver_capa *capa,
3890 char *buf, size_t buflen)
3891{
3892 int ret;
3893 char *pos, *end;
3894 size_t len;
3895
3896 pos = buf;
3897 end = pos + buflen;
3898
3899 if (res < 0) {
3900 if (strict)
3901 return 0;
3902 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3903 "NONE", buflen);
3904 if (len >= buflen)
3905 return -1;
3906 return len;
3907 }
3908
3909 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003910 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003911 return pos - buf;
3912 pos += ret;
3913
3914 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3915 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3916 ret = os_snprintf(pos, end - pos, " WPA-EAP");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003917 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003918 return pos - buf;
3919 pos += ret;
3920 }
3921
3922 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3923 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3924 ret = os_snprintf(pos, end - pos, " WPA-PSK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003925 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003926 return pos - buf;
3927 pos += ret;
3928 }
3929
3930 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3931 ret = os_snprintf(pos, end - pos, " WPA-NONE");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003932 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003933 return pos - buf;
3934 pos += ret;
3935 }
3936
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003937#ifdef CONFIG_SUITEB
3938 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
3939 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
3940 if (os_snprintf_error(end - pos, ret))
3941 return pos - buf;
3942 pos += ret;
3943 }
3944#endif /* CONFIG_SUITEB */
3945#ifdef CONFIG_SUITEB192
3946 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
3947 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
3948 if (os_snprintf_error(end - pos, ret))
3949 return pos - buf;
3950 pos += ret;
3951 }
3952#endif /* CONFIG_SUITEB192 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003953#ifdef CONFIG_OWE
3954 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
3955 ret = os_snprintf(pos, end - pos, " OWE");
3956 if (os_snprintf_error(end - pos, ret))
3957 return pos - buf;
3958 pos += ret;
3959 }
3960#endif /* CONFIG_OWE */
3961#ifdef CONFIG_DPP
3962 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
3963 ret = os_snprintf(pos, end - pos, " DPP");
3964 if (os_snprintf_error(end - pos, ret))
3965 return pos - buf;
3966 pos += ret;
3967 }
3968#endif /* CONFIG_DPP */
3969#ifdef CONFIG_FILS
3970 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
3971 ret = os_snprintf(pos, end - pos, " FILS-SHA256");
3972 if (os_snprintf_error(end - pos, ret))
3973 return pos - buf;
3974 pos += ret;
3975 }
3976 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
3977 ret = os_snprintf(pos, end - pos, " FILS-SHA384");
3978 if (os_snprintf_error(end - pos, ret))
3979 return pos - buf;
3980 pos += ret;
3981 }
3982#ifdef CONFIG_IEEE80211R
3983 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
3984 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
3985 if (os_snprintf_error(end - pos, ret))
3986 return pos - buf;
3987 pos += ret;
3988 }
3989 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
3990 ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
3991 if (os_snprintf_error(end - pos, ret))
3992 return pos - buf;
3993 pos += ret;
3994 }
3995#endif /* CONFIG_IEEE80211R */
3996#endif /* CONFIG_FILS */
Hai Shalom39bc25d2019-02-06 16:32:13 -08003997#ifdef CONFIG_IEEE80211R
3998 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK) {
3999 ret = os_snprintf(pos, end - pos, " FT-PSK");
4000 if (os_snprintf_error(end - pos, ret))
4001 return pos - buf;
4002 pos += ret;
4003 }
4004#endif /* CONFIG_IEEE80211R */
4005#ifdef CONFIG_SAE
4006 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SAE) {
4007 ret = os_snprintf(pos, end - pos, " SAE");
4008 if (os_snprintf_error(end - pos, ret))
4009 return pos - buf;
4010 pos += ret;
4011 }
4012#endif /* CONFIG_SAE */
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004013
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004014 return pos - buf;
4015}
4016
4017
4018static int ctrl_iface_get_capability_proto(int res, char *strict,
4019 struct wpa_driver_capa *capa,
4020 char *buf, size_t buflen)
4021{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004022 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004023 char *pos, *end;
4024 size_t len;
4025
4026 pos = buf;
4027 end = pos + buflen;
4028
4029 if (res < 0) {
4030 if (strict)
4031 return 0;
4032 len = os_strlcpy(buf, "RSN WPA", buflen);
4033 if (len >= buflen)
4034 return -1;
4035 return len;
4036 }
4037
4038 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
4039 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004040 ret = os_snprintf(pos, end - pos, "%sRSN",
4041 pos == buf ? "" : " ");
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;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004045 }
4046
4047 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
4048 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004049 ret = os_snprintf(pos, end - pos, "%sWPA",
4050 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004051 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004052 return pos - buf;
4053 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004054 }
4055
4056 return pos - buf;
4057}
4058
4059
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004060static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
4061 int res, char *strict,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004062 struct wpa_driver_capa *capa,
4063 char *buf, size_t buflen)
4064{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004065 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004066 char *pos, *end;
4067 size_t len;
4068
4069 pos = buf;
4070 end = pos + buflen;
4071
4072 if (res < 0) {
4073 if (strict)
4074 return 0;
4075 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
4076 if (len >= buflen)
4077 return -1;
4078 return len;
4079 }
4080
4081 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004082 ret = os_snprintf(pos, end - pos, "%sOPEN",
4083 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004084 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004085 return pos - buf;
4086 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004087 }
4088
4089 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
4090 ret = os_snprintf(pos, end - pos, "%sSHARED",
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004091 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004092 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004093 return pos - buf;
4094 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004095 }
4096
4097 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004098 ret = os_snprintf(pos, end - pos, "%sLEAP",
4099 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004100 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004101 return pos - buf;
4102 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004103 }
4104
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004105#ifdef CONFIG_SAE
4106 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
4107 ret = os_snprintf(pos, end - pos, "%sSAE",
4108 pos == buf ? "" : " ");
4109 if (os_snprintf_error(end - pos, ret))
4110 return pos - buf;
4111 pos += ret;
4112 }
4113#endif /* CONFIG_SAE */
4114
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004115#ifdef CONFIG_FILS
4116 if (wpa_is_fils_supported(wpa_s)) {
4117 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
4118 pos == buf ? "" : " ");
4119 if (os_snprintf_error(end - pos, ret))
4120 return pos - buf;
4121 pos += ret;
4122 }
4123
4124#ifdef CONFIG_FILS_SK_PFS
4125 if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
4126 ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
4127 pos == buf ? "" : " ");
4128 if (os_snprintf_error(end - pos, ret))
4129 return pos - buf;
4130 pos += ret;
4131 }
4132#endif /* CONFIG_FILS_SK_PFS */
4133#endif /* CONFIG_FILS */
4134
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004135 return pos - buf;
4136}
4137
4138
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004139static int ctrl_iface_get_capability_modes(int res, char *strict,
4140 struct wpa_driver_capa *capa,
4141 char *buf, size_t buflen)
4142{
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004143 int ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004144 char *pos, *end;
4145 size_t len;
4146
4147 pos = buf;
4148 end = pos + buflen;
4149
4150 if (res < 0) {
4151 if (strict)
4152 return 0;
4153 len = os_strlcpy(buf, "IBSS AP", buflen);
4154 if (len >= buflen)
4155 return -1;
4156 return len;
4157 }
4158
4159 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004160 ret = os_snprintf(pos, end - pos, "%sIBSS",
4161 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004162 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004163 return pos - buf;
4164 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004165 }
4166
4167 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08004168 ret = os_snprintf(pos, end - pos, "%sAP",
4169 pos == buf ? "" : " ");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004170 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004171 return pos - buf;
4172 pos += ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004173 }
4174
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004175#ifdef CONFIG_MESH
4176 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
4177 ret = os_snprintf(pos, end - pos, "%sMESH",
4178 pos == buf ? "" : " ");
4179 if (os_snprintf_error(end - pos, ret))
4180 return pos - buf;
4181 pos += ret;
4182 }
4183#endif /* CONFIG_MESH */
4184
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004185 return pos - buf;
4186}
4187
4188
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004189static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
4190 char *buf, size_t buflen)
4191{
4192 struct hostapd_channel_data *chnl;
4193 int ret, i, j;
4194 char *pos, *end, *hmode;
4195
4196 pos = buf;
4197 end = pos + buflen;
4198
4199 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4200 switch (wpa_s->hw.modes[j].mode) {
4201 case HOSTAPD_MODE_IEEE80211B:
4202 hmode = "B";
4203 break;
4204 case HOSTAPD_MODE_IEEE80211G:
4205 hmode = "G";
4206 break;
4207 case HOSTAPD_MODE_IEEE80211A:
4208 hmode = "A";
4209 break;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004210 case HOSTAPD_MODE_IEEE80211AD:
4211 hmode = "AD";
4212 break;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004213 default:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004214 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004215 }
4216 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004217 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004218 return pos - buf;
4219 pos += ret;
4220 chnl = wpa_s->hw.modes[j].channels;
4221 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004222 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4223 continue;
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004224 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004225 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004226 return pos - buf;
4227 pos += ret;
4228 }
4229 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004230 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004231 return pos - buf;
4232 pos += ret;
4233 }
4234
4235 return pos - buf;
4236}
4237
4238
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004239static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
4240 char *buf, size_t buflen)
4241{
4242 struct hostapd_channel_data *chnl;
4243 int ret, i, j;
4244 char *pos, *end, *hmode;
4245
4246 pos = buf;
4247 end = pos + buflen;
4248
4249 for (j = 0; j < wpa_s->hw.num_modes; j++) {
4250 switch (wpa_s->hw.modes[j].mode) {
4251 case HOSTAPD_MODE_IEEE80211B:
4252 hmode = "B";
4253 break;
4254 case HOSTAPD_MODE_IEEE80211G:
4255 hmode = "G";
4256 break;
4257 case HOSTAPD_MODE_IEEE80211A:
4258 hmode = "A";
4259 break;
4260 case HOSTAPD_MODE_IEEE80211AD:
4261 hmode = "AD";
4262 break;
4263 default:
4264 continue;
4265 }
4266 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
4267 hmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004268 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004269 return pos - buf;
4270 pos += ret;
4271 chnl = wpa_s->hw.modes[j].channels;
4272 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
4273 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
4274 continue;
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004275 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004276 chnl[i].chan, chnl[i].freq,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004277 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
4278 " (NO_IR)" : "",
Dmitry Shmidt5da5e352014-02-03 13:30:46 -08004279 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
4280 " (DFS)" : "");
4281
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004282 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004283 return pos - buf;
4284 pos += ret;
4285 }
4286 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004287 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004288 return pos - buf;
4289 pos += ret;
4290 }
4291
4292 return pos - buf;
4293}
4294
4295
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004296static int wpa_supplicant_ctrl_iface_get_capability(
4297 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
4298 size_t buflen)
4299{
4300 struct wpa_driver_capa capa;
4301 int res;
4302 char *strict;
4303 char field[30];
4304 size_t len;
4305
4306 /* Determine whether or not strict checking was requested */
4307 len = os_strlcpy(field, _field, sizeof(field));
4308 if (len >= sizeof(field))
4309 return -1;
4310 strict = os_strchr(field, ' ');
4311 if (strict != NULL) {
4312 *strict++ = '\0';
4313 if (os_strcmp(strict, "strict") != 0)
4314 return -1;
4315 }
4316
4317 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4318 field, strict ? strict : "");
4319
4320 if (os_strcmp(field, "eap") == 0) {
4321 return eap_get_names(buf, buflen);
4322 }
4323
4324 res = wpa_drv_get_capa(wpa_s, &capa);
4325
4326 if (os_strcmp(field, "pairwise") == 0)
4327 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
4328 buf, buflen);
4329
4330 if (os_strcmp(field, "group") == 0)
4331 return ctrl_iface_get_capability_group(res, strict, &capa,
4332 buf, buflen);
4333
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004334 if (os_strcmp(field, "group_mgmt") == 0)
4335 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
4336 buf, buflen);
4337
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004338 if (os_strcmp(field, "key_mgmt") == 0)
4339 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
4340 buf, buflen);
4341
4342 if (os_strcmp(field, "proto") == 0)
4343 return ctrl_iface_get_capability_proto(res, strict, &capa,
4344 buf, buflen);
4345
4346 if (os_strcmp(field, "auth_alg") == 0)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004347 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
4348 &capa, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004349
Dmitry Shmidt700a1372013-03-15 14:14:44 -07004350 if (os_strcmp(field, "modes") == 0)
4351 return ctrl_iface_get_capability_modes(res, strict, &capa,
4352 buf, buflen);
4353
Dmitry Shmidt0e6d08e2012-07-10 12:49:30 -07004354 if (os_strcmp(field, "channels") == 0)
4355 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
4356
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004357 if (os_strcmp(field, "freq") == 0)
4358 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
4359
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07004360#ifdef CONFIG_TDLS
4361 if (os_strcmp(field, "tdls") == 0)
4362 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
4363#endif /* CONFIG_TDLS */
4364
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004365#ifdef CONFIG_ERP
4366 if (os_strcmp(field, "erp") == 0) {
4367 res = os_snprintf(buf, buflen, "ERP");
4368 if (os_snprintf_error(buflen, res))
4369 return -1;
4370 return res;
4371 }
4372#endif /* CONFIG_EPR */
4373
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004374#ifdef CONFIG_FIPS
4375 if (os_strcmp(field, "fips") == 0) {
4376 res = os_snprintf(buf, buflen, "FIPS");
4377 if (os_snprintf_error(buflen, res))
4378 return -1;
4379 return res;
4380 }
4381#endif /* CONFIG_FIPS */
4382
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08004383#ifdef CONFIG_ACS
4384 if (os_strcmp(field, "acs") == 0) {
4385 res = os_snprintf(buf, buflen, "ACS");
4386 if (os_snprintf_error(buflen, res))
4387 return -1;
4388 return res;
4389 }
4390#endif /* CONFIG_ACS */
4391
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004392#ifdef CONFIG_FILS
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004393 if (os_strcmp(field, "fils") == 0) {
4394#ifdef CONFIG_FILS_SK_PFS
4395 if (wpa_is_fils_supported(wpa_s) &&
4396 wpa_is_fils_sk_pfs_supported(wpa_s)) {
4397 res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
4398 if (os_snprintf_error(buflen, res))
4399 return -1;
4400 return res;
4401 }
4402#endif /* CONFIG_FILS_SK_PFS */
4403
4404 if (wpa_is_fils_supported(wpa_s)) {
4405 res = os_snprintf(buf, buflen, "FILS");
4406 if (os_snprintf_error(buflen, res))
4407 return -1;
4408 return res;
4409 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004410 }
4411#endif /* CONFIG_FILS */
4412
Hai Shalom39bc25d2019-02-06 16:32:13 -08004413 if (os_strcmp(field, "multibss") == 0 && wpa_s->multi_bss_support) {
4414 res = os_snprintf(buf, buflen, "MULTIBSS-STA");
4415 if (os_snprintf_error(buflen, res))
4416 return -1;
4417 return res;
4418 }
4419
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004420 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4421 field);
4422
4423 return -1;
4424}
4425
4426
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004427#ifdef CONFIG_INTERWORKING
4428static char * anqp_add_hex(char *pos, char *end, const char *title,
4429 struct wpabuf *data)
4430{
4431 char *start = pos;
4432 size_t i;
4433 int ret;
4434 const u8 *d;
4435
4436 if (data == NULL)
4437 return start;
4438
4439 ret = os_snprintf(pos, end - pos, "%s=", title);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004440 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004441 return start;
4442 pos += ret;
4443
4444 d = wpabuf_head_u8(data);
4445 for (i = 0; i < wpabuf_len(data); i++) {
4446 ret = os_snprintf(pos, end - pos, "%02x", *d++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004447 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004448 return start;
4449 pos += ret;
4450 }
4451
4452 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004453 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004454 return start;
4455 pos += ret;
4456
4457 return pos;
4458}
4459#endif /* CONFIG_INTERWORKING */
4460
4461
Dmitry Shmidt29333592017-01-09 12:27:11 -08004462#ifdef CONFIG_FILS
4463static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
4464{
4465 char *start = pos;
4466 const u8 *ie, *ie_end;
4467 u16 info, realms;
4468 int ret;
4469
4470 ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
4471 if (!ie)
4472 return 0;
4473 ie_end = ie + 2 + ie[1];
4474 ie += 2;
4475 if (ie_end - ie < 2)
4476 return -1;
4477
4478 info = WPA_GET_LE16(ie);
4479 ie += 2;
4480 ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
4481 if (os_snprintf_error(end - pos, ret))
4482 return 0;
4483 pos += ret;
4484
4485 if (info & BIT(7)) {
4486 /* Cache Identifier Included */
4487 if (ie_end - ie < 2)
4488 return -1;
4489 ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
4490 ie[0], ie[1]);
4491 if (os_snprintf_error(end - pos, ret))
4492 return 0;
4493 pos += ret;
4494 ie += 2;
4495 }
4496
4497 if (info & BIT(8)) {
4498 /* HESSID Included */
4499 if (ie_end - ie < ETH_ALEN)
4500 return -1;
4501 ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
4502 MAC2STR(ie));
4503 if (os_snprintf_error(end - pos, ret))
4504 return 0;
4505 pos += ret;
4506 ie += ETH_ALEN;
4507 }
4508
4509 realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
4510 if (realms) {
4511 if (ie_end - ie < realms * 2)
4512 return -1;
4513 ret = os_snprintf(pos, end - pos, "fils_realms=");
4514 if (os_snprintf_error(end - pos, ret))
4515 return 0;
4516 pos += ret;
4517
4518 ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
4519 if (ret <= 0)
4520 return 0;
4521 pos += ret;
4522 ie += realms * 2;
4523 ret = os_snprintf(pos, end - pos, "\n");
4524 if (os_snprintf_error(end - pos, ret))
4525 return 0;
4526 pos += ret;
4527 }
4528
4529 return pos - start;
4530}
4531#endif /* CONFIG_FILS */
4532
4533
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004534static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
4535 unsigned long mask, char *buf, size_t buflen)
4536{
4537 size_t i;
4538 int ret;
4539 char *pos, *end;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004540 const u8 *ie, *ie2, *osen_ie, *mesh, *owe;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004541
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004542 pos = buf;
4543 end = buf + buflen;
4544
4545 if (mask & WPA_BSS_MASK_ID) {
4546 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004547 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004548 return 0;
4549 pos += ret;
4550 }
4551
4552 if (mask & WPA_BSS_MASK_BSSID) {
4553 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
4554 MAC2STR(bss->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004555 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004556 return 0;
4557 pos += ret;
4558 }
4559
4560 if (mask & WPA_BSS_MASK_FREQ) {
4561 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004562 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004563 return 0;
4564 pos += ret;
4565 }
4566
4567 if (mask & WPA_BSS_MASK_BEACON_INT) {
4568 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
4569 bss->beacon_int);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004570 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004571 return 0;
4572 pos += ret;
4573 }
4574
4575 if (mask & WPA_BSS_MASK_CAPABILITIES) {
4576 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
4577 bss->caps);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004578 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004579 return 0;
4580 pos += ret;
4581 }
4582
4583 if (mask & WPA_BSS_MASK_QUAL) {
4584 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004585 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004586 return 0;
4587 pos += ret;
4588 }
4589
4590 if (mask & WPA_BSS_MASK_NOISE) {
4591 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004592 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004593 return 0;
4594 pos += ret;
4595 }
4596
4597 if (mask & WPA_BSS_MASK_LEVEL) {
4598 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004599 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004600 return 0;
4601 pos += ret;
4602 }
4603
4604 if (mask & WPA_BSS_MASK_TSF) {
4605 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
4606 (unsigned long long) bss->tsf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004607 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004608 return 0;
4609 pos += ret;
4610 }
4611
4612 if (mask & WPA_BSS_MASK_AGE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004613 struct os_reltime now;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004614
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004615 os_get_reltime(&now);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004616 ret = os_snprintf(pos, end - pos, "age=%d\n",
4617 (int) (now.sec - bss->last_update.sec));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004618 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004619 return 0;
4620 pos += ret;
4621 }
4622
4623 if (mask & WPA_BSS_MASK_IE) {
4624 ret = os_snprintf(pos, end - pos, "ie=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004625 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004626 return 0;
4627 pos += ret;
4628
4629 ie = (const u8 *) (bss + 1);
4630 for (i = 0; i < bss->ie_len; i++) {
4631 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004632 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004633 return 0;
4634 pos += ret;
4635 }
4636
4637 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004638 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004639 return 0;
4640 pos += ret;
4641 }
4642
4643 if (mask & WPA_BSS_MASK_FLAGS) {
4644 ret = os_snprintf(pos, end - pos, "flags=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004645 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004646 return 0;
4647 pos += ret;
4648
Dmitry Shmidt29333592017-01-09 12:27:11 -08004649 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
4650
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004651 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
4652 if (ie)
4653 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
4654 2 + ie[1]);
4655 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4656 if (ie2)
Dmitry Shmidt29333592017-01-09 12:27:11 -08004657 pos = wpa_supplicant_ie_txt(pos, end,
4658 mesh ? "RSN" : "WPA2", ie2,
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004659 2 + ie2[1]);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07004660 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
4661 if (osen_ie)
4662 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
4663 osen_ie, 2 + osen_ie[1]);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07004664 owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
4665 if (owe) {
4666 ret = os_snprintf(
4667 pos, end - pos,
4668 ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
4669 if (os_snprintf_error(end - pos, ret))
4670 return 0;
4671 pos += ret;
4672 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004673 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -07004674 if (!ie && !ie2 && !osen_ie &&
4675 (bss->caps & IEEE80211_CAP_PRIVACY)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004676 ret = os_snprintf(pos, end - pos, "[WEP]");
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 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08004681
4682 if (mesh) {
4683 ret = os_snprintf(pos, end - pos, "[MESH]");
4684 if (os_snprintf_error(end - pos, ret))
4685 return 0;
4686 pos += ret;
4687 }
4688
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004689 if (bss_is_dmg(bss)) {
4690 const char *s;
4691 ret = os_snprintf(pos, end - pos, "[DMG]");
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;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004695 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
4696 case IEEE80211_CAP_DMG_IBSS:
4697 s = "[IBSS]";
4698 break;
4699 case IEEE80211_CAP_DMG_AP:
4700 s = "[ESS]";
4701 break;
4702 case IEEE80211_CAP_DMG_PBSS:
4703 s = "[PBSS]";
4704 break;
4705 default:
4706 s = "";
4707 break;
4708 }
4709 ret = os_snprintf(pos, end - pos, "%s", s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004710 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004711 return 0;
4712 pos += ret;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004713 } else {
4714 if (bss->caps & IEEE80211_CAP_IBSS) {
4715 ret = os_snprintf(pos, end - pos, "[IBSS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004716 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004717 return 0;
4718 pos += ret;
4719 }
4720 if (bss->caps & IEEE80211_CAP_ESS) {
4721 ret = os_snprintf(pos, end - pos, "[ESS]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004722 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004723 return 0;
4724 pos += ret;
4725 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004726 }
Dmitry Shmidt96571392013-10-14 12:54:46 -07004727 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
4728 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004729 ret = os_snprintf(pos, end - pos, "[P2P]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004730 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004731 return 0;
4732 pos += ret;
4733 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004734#ifdef CONFIG_HS20
4735 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
4736 ret = os_snprintf(pos, end - pos, "[HS20]");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004737 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004738 return 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004739 pos += ret;
4740 }
4741#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08004742#ifdef CONFIG_FILS
4743 if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
4744 ret = os_snprintf(pos, end - pos, "[FILS]");
4745 if (os_snprintf_error(end - pos, ret))
4746 return 0;
4747 pos += ret;
4748 }
4749#endif /* CONFIG_FILS */
Hai Shalom39bc25d2019-02-06 16:32:13 -08004750#ifdef CONFIG_FST
4751 if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
4752 ret = os_snprintf(pos, end - pos, "[FST]");
4753 if (os_snprintf_error(end - pos, ret))
4754 return 0;
4755 pos += ret;
4756 }
4757#endif /* CONFIG_FST */
4758 if (wpa_bss_ext_capab(bss, WLAN_EXT_CAPAB_UTF_8_SSID)) {
4759 ret = os_snprintf(pos, end - pos, "[UTF-8]");
4760 if (os_snprintf_error(end - pos, ret))
4761 return 0;
4762 pos += ret;
4763 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004764
4765 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004766 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004767 return 0;
4768 pos += ret;
4769 }
4770
4771 if (mask & WPA_BSS_MASK_SSID) {
4772 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
4773 wpa_ssid_txt(bss->ssid, bss->ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004774 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004775 return 0;
4776 pos += ret;
4777 }
4778
4779#ifdef CONFIG_WPS
4780 if (mask & WPA_BSS_MASK_WPS_SCAN) {
4781 ie = (const u8 *) (bss + 1);
4782 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004783 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004784 return 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004785 if (ret > 0)
4786 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004787 }
4788#endif /* CONFIG_WPS */
4789
4790#ifdef CONFIG_P2P
4791 if (mask & WPA_BSS_MASK_P2P_SCAN) {
4792 ie = (const u8 *) (bss + 1);
4793 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004794 if (ret >= end - pos)
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004795 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004796 if (ret > 0)
4797 pos += ret;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004798 }
4799#endif /* CONFIG_P2P */
4800
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004801#ifdef CONFIG_WIFI_DISPLAY
4802 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
4803 struct wpabuf *wfd;
4804 ie = (const u8 *) (bss + 1);
4805 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
4806 WFD_IE_VENDOR_TYPE);
4807 if (wfd) {
4808 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004809 if (os_snprintf_error(end - pos, ret)) {
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004810 wpabuf_free(wfd);
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004811 return 0;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004812 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004813 pos += ret;
4814
4815 pos += wpa_snprintf_hex(pos, end - pos,
4816 wpabuf_head(wfd),
4817 wpabuf_len(wfd));
4818 wpabuf_free(wfd);
4819
4820 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004821 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004822 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004823 pos += ret;
4824 }
4825 }
4826#endif /* CONFIG_WIFI_DISPLAY */
4827
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004828#ifdef CONFIG_INTERWORKING
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004829 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
4830 struct wpa_bss_anqp *anqp = bss->anqp;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004831 struct wpa_bss_anqp_elem *elem;
4832
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004833 pos = anqp_add_hex(pos, end, "anqp_capability_list",
4834 anqp->capability_list);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004835 pos = anqp_add_hex(pos, end, "anqp_venue_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004836 anqp->venue_name);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004837 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004838 anqp->network_auth_type);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004839 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004840 anqp->roaming_consortium);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004841 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004842 anqp->ip_addr_type_availability);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004843 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004844 anqp->nai_realm);
4845 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004846 pos = anqp_add_hex(pos, end, "anqp_domain_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004847 anqp->domain_name);
Dmitry Shmidt29333592017-01-09 12:27:11 -08004848 pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
4849 anqp->fils_realm_info);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004850#ifdef CONFIG_HS20
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004851 pos = anqp_add_hex(pos, end, "hs20_capability_list",
4852 anqp->hs20_capability_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004853 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004854 anqp->hs20_operator_friendly_name);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004855 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004856 anqp->hs20_wan_metrics);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004857 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07004858 anqp->hs20_connection_capability);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004859 pos = anqp_add_hex(pos, end, "hs20_operating_class",
4860 anqp->hs20_operating_class);
4861 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
4862 anqp->hs20_osu_providers_list);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004863 pos = anqp_add_hex(pos, end, "hs20_operator_icon_metadata",
4864 anqp->hs20_operator_icon_metadata);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08004865 pos = anqp_add_hex(pos, end, "hs20_osu_providers_nai_list",
4866 anqp->hs20_osu_providers_nai_list);
Dmitry Shmidt04949592012-07-19 12:16:46 -07004867#endif /* CONFIG_HS20 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004868
4869 dl_list_for_each(elem, &anqp->anqp_elems,
4870 struct wpa_bss_anqp_elem, list) {
4871 char title[20];
4872
4873 os_snprintf(title, sizeof(title), "anqp[%u]",
4874 elem->infoid);
4875 pos = anqp_add_hex(pos, end, title, elem->payload);
4876 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004877 }
4878#endif /* CONFIG_INTERWORKING */
4879
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004880#ifdef CONFIG_MESH
4881 if (mask & WPA_BSS_MASK_MESH_SCAN) {
4882 ie = (const u8 *) (bss + 1);
4883 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004884 if (ret >= end - pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004885 return 0;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07004886 if (ret > 0)
4887 pos += ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004888 }
4889#endif /* CONFIG_MESH */
4890
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004891 if (mask & WPA_BSS_MASK_SNR) {
4892 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
4893 if (os_snprintf_error(end - pos, ret))
4894 return 0;
4895 pos += ret;
4896 }
4897
4898 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
4899 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
4900 bss->est_throughput);
4901 if (os_snprintf_error(end - pos, ret))
4902 return 0;
4903 pos += ret;
4904 }
4905
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004906#ifdef CONFIG_FST
4907 if (mask & WPA_BSS_MASK_FST) {
4908 ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
4909 if (ret < 0 || ret >= end - pos)
4910 return 0;
4911 pos += ret;
4912 }
4913#endif /* CONFIG_FST */
4914
Dmitry Shmidt29333592017-01-09 12:27:11 -08004915 if (mask & WPA_BSS_MASK_UPDATE_IDX) {
4916 ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
4917 bss->last_update_idx);
4918 if (os_snprintf_error(end - pos, ret))
4919 return 0;
4920 pos += ret;
4921 }
4922
4923 if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
4924 ret = os_snprintf(pos, end - pos, "beacon_ie=");
4925 if (os_snprintf_error(end - pos, ret))
4926 return 0;
4927 pos += ret;
4928
4929 ie = (const u8 *) (bss + 1);
4930 ie += bss->ie_len;
4931 for (i = 0; i < bss->beacon_ie_len; i++) {
4932 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
4933 if (os_snprintf_error(end - pos, ret))
4934 return 0;
4935 pos += ret;
4936 }
4937
4938 ret = os_snprintf(pos, end - pos, "\n");
4939 if (os_snprintf_error(end - pos, ret))
4940 return 0;
4941 pos += ret;
4942 }
4943
4944#ifdef CONFIG_FILS
4945 if (mask & WPA_BSS_MASK_FILS_INDICATION) {
4946 ret = print_fils_indication(bss, pos, end);
4947 if (ret < 0)
4948 return 0;
4949 pos += ret;
4950 }
4951#endif /* CONFIG_FILS */
4952
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004953 if (mask & WPA_BSS_MASK_DELIM) {
4954 ret = os_snprintf(pos, end - pos, "====\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004955 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08004956 return 0;
4957 pos += ret;
4958 }
Irfan Sheriffe2ea0082012-08-13 10:56:16 -07004959
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004960 return pos - buf;
4961}
4962
Dmitry Shmidt04949592012-07-19 12:16:46 -07004963
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004964static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
4965 const char *cmd, char *buf,
4966 size_t buflen)
4967{
4968 u8 bssid[ETH_ALEN];
4969 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004970 struct wpa_bss *bss;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004971 struct wpa_bss *bsslast = NULL;
4972 struct dl_list *next;
4973 int ret = 0;
4974 int len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004975 char *ctmp, *end = buf + buflen;
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004976 unsigned long mask = WPA_BSS_MASK_ALL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004977
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004978 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
4979 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
4980 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
Dmitry Shmidt04949592012-07-19 12:16:46 -07004981 list_id);
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004982 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
4983 list_id);
4984 } else { /* N1-N2 */
Dmitry Shmidt04949592012-07-19 12:16:46 -07004985 unsigned int id1, id2;
4986
4987 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
4988 wpa_printf(MSG_INFO, "Wrong BSS range "
4989 "format");
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07004990 return 0;
4991 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07004992
Dmitry Shmidtf8623282013-02-20 14:34:59 -08004993 if (*(cmd + 6) == '-')
4994 id1 = 0;
4995 else
4996 id1 = atoi(cmd + 6);
4997 ctmp++;
4998 if (*ctmp >= '0' && *ctmp <= '9')
4999 id2 = atoi(ctmp);
5000 else
5001 id2 = (unsigned int) -1;
5002 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
5003 if (id2 == (unsigned int) -1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005004 bsslast = dl_list_last(&wpa_s->bss_id,
5005 struct wpa_bss,
5006 list_id);
5007 else {
5008 bsslast = wpa_bss_get_id(wpa_s, id2);
5009 if (bsslast == NULL && bss && id2 > id1) {
5010 struct wpa_bss *tmp = bss;
5011 for (;;) {
5012 next = tmp->list_id.next;
5013 if (next == &wpa_s->bss_id)
5014 break;
5015 tmp = dl_list_entry(
5016 next, struct wpa_bss,
5017 list_id);
5018 if (tmp->id > id2)
5019 break;
5020 bsslast = tmp;
5021 }
5022 }
5023 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005024 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005025 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
Dmitry Shmidt04949592012-07-19 12:16:46 -07005026 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005027 else if (os_strncmp(cmd, "LAST", 4) == 0)
5028 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005029 else if (os_strncmp(cmd, "ID-", 3) == 0) {
5030 i = atoi(cmd + 3);
5031 bss = wpa_bss_get_id(wpa_s, i);
5032 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5033 i = atoi(cmd + 5);
5034 bss = wpa_bss_get_id(wpa_s, i);
5035 if (bss) {
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005036 next = bss->list_id.next;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005037 if (next == &wpa_s->bss_id)
5038 bss = NULL;
5039 else
5040 bss = dl_list_entry(next, struct wpa_bss,
5041 list_id);
5042 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08005043 } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
5044 bss = wpa_s->current_bss;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005045#ifdef CONFIG_P2P
5046 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
5047 if (hwaddr_aton(cmd + 13, bssid) == 0)
5048 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
5049 else
5050 bss = NULL;
5051#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005052 } else if (hwaddr_aton(cmd, bssid) == 0)
5053 bss = wpa_bss_get_bssid(wpa_s, bssid);
5054 else {
5055 struct wpa_bss *tmp;
5056 i = atoi(cmd);
5057 bss = NULL;
5058 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
5059 {
5060 if (i-- == 0) {
5061 bss = tmp;
5062 break;
5063 }
5064 }
5065 }
5066
Dmitry Shmidt04949592012-07-19 12:16:46 -07005067 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
5068 mask = strtoul(ctmp + 5, NULL, 0x10);
5069 if (mask == 0)
5070 mask = WPA_BSS_MASK_ALL;
5071 }
5072
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005073 if (bss == NULL)
5074 return 0;
5075
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005076 if (bsslast == NULL)
5077 bsslast = bss;
5078 do {
5079 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
5080 ret += len;
5081 buf += len;
5082 buflen -= len;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005083 if (bss == bsslast) {
5084 if ((mask & WPA_BSS_MASK_DELIM) && len &&
5085 (bss == dl_list_last(&wpa_s->bss_id,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005086 struct wpa_bss, list_id))) {
5087 int res;
5088
5089 res = os_snprintf(buf - 5, end - buf + 5,
5090 "####\n");
5091 if (os_snprintf_error(end - buf + 5, res)) {
5092 wpa_printf(MSG_DEBUG,
5093 "Could not add end delim");
5094 }
5095 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005096 break;
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08005097 }
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005098 next = bss->list_id.next;
5099 if (next == &wpa_s->bss_id)
5100 break;
5101 bss = dl_list_entry(next, struct wpa_bss, list_id);
5102 } while (bss && len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005103
Dmitry Shmidtf2df2f22012-03-26 12:43:26 -07005104 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005105}
5106
5107
5108static int wpa_supplicant_ctrl_iface_ap_scan(
5109 struct wpa_supplicant *wpa_s, char *cmd)
5110{
5111 int ap_scan = atoi(cmd);
5112 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
5113}
5114
5115
5116static int wpa_supplicant_ctrl_iface_scan_interval(
5117 struct wpa_supplicant *wpa_s, char *cmd)
5118{
5119 int scan_int = atoi(cmd);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005120 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005121}
5122
5123
5124static int wpa_supplicant_ctrl_iface_bss_expire_age(
5125 struct wpa_supplicant *wpa_s, char *cmd)
5126{
5127 int expire_age = atoi(cmd);
5128 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
5129}
5130
5131
5132static int wpa_supplicant_ctrl_iface_bss_expire_count(
5133 struct wpa_supplicant *wpa_s, char *cmd)
5134{
5135 int expire_count = atoi(cmd);
5136 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
5137}
5138
5139
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005140static void wpa_supplicant_ctrl_iface_bss_flush(
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005141 struct wpa_supplicant *wpa_s, char *cmd)
5142{
5143 int flush_age = atoi(cmd);
5144
5145 if (flush_age == 0)
5146 wpa_bss_flush(wpa_s);
5147 else
5148 wpa_bss_flush_by_age(wpa_s, flush_age);
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -07005149}
5150
5151
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005152#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005153static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
5154{
5155 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
5156 /* MLME-DELETEKEYS.request */
5157 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
5158 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
5159 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
5160 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
5161#ifdef CONFIG_IEEE80211W
5162 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
5163 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
5164#endif /* CONFIG_IEEE80211W */
5165
5166 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
5167 0);
5168 /* MLME-SETPROTECTION.request(None) */
5169 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
5170 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
5171 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
5172 wpa_sm_drop_sa(wpa_s->wpa);
5173}
Dmitry Shmidt21de2142014-04-08 10:50:52 -07005174#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005175
5176
5177static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
5178 char *addr)
5179{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005180#ifdef CONFIG_NO_SCAN_PROCESSING
5181 return -1;
5182#else /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005183 u8 bssid[ETH_ALEN];
5184 struct wpa_bss *bss;
5185 struct wpa_ssid *ssid = wpa_s->current_ssid;
5186
5187 if (hwaddr_aton(addr, bssid)) {
5188 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
5189 "address '%s'", addr);
5190 return -1;
5191 }
5192
5193 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
5194
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005195 if (!ssid) {
5196 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
5197 "configuration known for the target AP");
5198 return -1;
5199 }
5200
5201 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005202 if (!bss) {
5203 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
5204 "from BSS table");
5205 return -1;
5206 }
5207
5208 /*
5209 * TODO: Find best network configuration block from configuration to
5210 * allow roaming to other networks
5211 */
5212
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005213 wpa_s->reassociate = 1;
5214 wpa_supplicant_connect(wpa_s, bss, ssid);
5215
5216 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005217#endif /* CONFIG_NO_SCAN_PROCESSING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005218}
5219
5220
5221#ifdef CONFIG_P2P
5222static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
5223{
5224 unsigned int timeout = atoi(cmd);
5225 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005226 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005227 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005228 char *pos;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005229 unsigned int search_delay;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005230 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005231 u8 seek_count = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005232 int freq = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005233
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005234 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5235 wpa_dbg(wpa_s, MSG_INFO,
5236 "Reject P2P_FIND since interface is disabled");
5237 return -1;
5238 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005239 if (os_strstr(cmd, "type=social"))
5240 type = P2P_FIND_ONLY_SOCIAL;
5241 else if (os_strstr(cmd, "type=progressive"))
5242 type = P2P_FIND_PROGRESSIVE;
5243
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005244 pos = os_strstr(cmd, "dev_id=");
5245 if (pos) {
5246 pos += 7;
5247 if (hwaddr_aton(pos, dev_id))
5248 return -1;
5249 _dev_id = dev_id;
5250 }
5251
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005252 pos = os_strstr(cmd, "dev_type=");
5253 if (pos) {
5254 pos += 9;
5255 if (wps_dev_type_str2bin(pos, dev_type) < 0)
5256 return -1;
5257 _dev_type = dev_type;
5258 }
5259
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005260 pos = os_strstr(cmd, "delay=");
5261 if (pos) {
5262 pos += 6;
5263 search_delay = atoi(pos);
5264 } else
5265 search_delay = wpas_p2p_search_delay(wpa_s);
5266
Dmitry Shmidt41712582015-06-29 11:02:15 -07005267 pos = os_strstr(cmd, "freq=");
5268 if (pos) {
5269 pos += 5;
5270 freq = atoi(pos);
5271 if (freq <= 0)
5272 return -1;
5273 }
5274
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005275 /* Must be searched for last, because it adds nul termination */
5276 pos = os_strstr(cmd, " seek=");
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005277 if (pos)
5278 pos += 6;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005279 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
5280 char *term;
5281
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005282 _seek[seek_count++] = pos;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005283 seek = _seek;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07005284 term = os_strchr(pos, ' ');
5285 if (!term)
5286 break;
5287 *term = '\0';
5288 pos = os_strstr(term + 1, "seek=");
5289 if (pos)
5290 pos += 5;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005291 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005292 if (seek_count > P2P_MAX_QUERY_HASH) {
5293 seek[0] = NULL;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005294 seek_count = 1;
5295 }
5296
Dmitry Shmidt344abd32014-01-14 13:17:00 -08005297 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005298 _dev_id, search_delay, seek_count, seek, freq);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005299}
5300
5301
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005302static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
5303{
5304 const char *last = NULL;
5305 const char *token;
5306 long int token_len;
5307 unsigned int i;
5308
5309 /* Expected predefined CPT names delimited by ':' */
5310 for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
5311 if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
5312 wpa_printf(MSG_ERROR,
5313 "P2PS: CPT name list is too long, expected up to %d names",
5314 P2PS_FEATURE_CAPAB_CPT_MAX);
5315 cpt[0] = 0;
5316 return -1;
5317 }
5318
5319 token_len = last - token;
5320
5321 if (token_len == 3 &&
5322 os_memcmp(token, "UDP", token_len) == 0) {
5323 cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5324 } else if (token_len == 3 &&
5325 os_memcmp(token, "MAC", token_len) == 0) {
5326 cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
5327 } else {
5328 wpa_printf(MSG_ERROR,
5329 "P2PS: Unsupported CPT name '%s'", token);
5330 cpt[0] = 0;
5331 return -1;
5332 }
5333
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005334 if (isblank((unsigned char) *last)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005335 i++;
5336 break;
5337 }
5338 }
5339 cpt[i] = 0;
5340 return 0;
5341}
5342
5343
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005344static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
5345{
5346 struct p2ps_provision *p2ps_prov;
5347 char *pos;
5348 size_t info_len = 0;
5349 char *info = NULL;
5350 u8 role = P2PS_SETUP_NONE;
5351 long long unsigned val;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005352 int i;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005353
5354 pos = os_strstr(cmd, "info=");
5355 if (pos) {
5356 pos += 5;
5357 info_len = os_strlen(pos);
5358
5359 if (info_len) {
5360 info = os_malloc(info_len + 1);
5361 if (info) {
5362 info_len = utf8_unescape(pos, info_len,
5363 info, info_len + 1);
5364 } else
5365 info_len = 0;
5366 }
5367 }
5368
5369 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
5370 if (p2ps_prov == NULL) {
5371 os_free(info);
5372 return NULL;
5373 }
5374
5375 if (info) {
5376 os_memcpy(p2ps_prov->info, info, info_len);
5377 p2ps_prov->info[info_len] = '\0';
5378 os_free(info);
5379 }
5380
5381 pos = os_strstr(cmd, "status=");
5382 if (pos)
5383 p2ps_prov->status = atoi(pos + 7);
5384 else
5385 p2ps_prov->status = -1;
5386
5387 pos = os_strstr(cmd, "adv_id=");
5388 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
5389 goto invalid_args;
5390 p2ps_prov->adv_id = val;
5391
5392 pos = os_strstr(cmd, "method=");
5393 if (pos)
5394 p2ps_prov->method = strtol(pos + 7, NULL, 16);
5395 else
5396 p2ps_prov->method = 0;
5397
5398 pos = os_strstr(cmd, "session=");
5399 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
5400 goto invalid_args;
5401 p2ps_prov->session_id = val;
5402
5403 pos = os_strstr(cmd, "adv_mac=");
5404 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
5405 goto invalid_args;
5406
5407 pos = os_strstr(cmd, "session_mac=");
5408 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
5409 goto invalid_args;
5410
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005411 pos = os_strstr(cmd, "cpt=");
5412 if (pos) {
5413 if (p2ps_ctrl_parse_cpt_priority(pos + 4,
5414 p2ps_prov->cpt_priority))
5415 goto invalid_args;
5416 } else {
5417 p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
5418 }
5419
5420 for (i = 0; p2ps_prov->cpt_priority[i]; i++)
5421 p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
5422
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005423 /* force conncap with tstCap (no sanity checks) */
5424 pos = os_strstr(cmd, "tstCap=");
5425 if (pos) {
5426 role = strtol(pos + 7, NULL, 16);
5427 } else {
5428 pos = os_strstr(cmd, "role=");
5429 if (pos) {
5430 role = strtol(pos + 5, NULL, 16);
5431 if (role != P2PS_SETUP_CLIENT &&
5432 role != P2PS_SETUP_GROUP_OWNER)
5433 role = P2PS_SETUP_NONE;
5434 }
5435 }
5436 p2ps_prov->role = role;
5437
5438 return p2ps_prov;
5439
5440invalid_args:
5441 os_free(p2ps_prov);
5442 return NULL;
5443}
5444
5445
5446static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
5447{
5448 u8 addr[ETH_ALEN];
5449 struct p2ps_provision *p2ps_prov;
5450 char *pos;
5451
5452 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5453
5454 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5455
5456 if (hwaddr_aton(cmd, addr))
5457 return -1;
5458
5459 pos = cmd + 17;
5460 if (*pos != ' ')
5461 return -1;
5462
5463 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5464 if (!p2ps_prov)
5465 return -1;
5466
5467 if (p2ps_prov->status < 0) {
5468 os_free(p2ps_prov);
5469 return -1;
5470 }
5471
5472 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5473 p2ps_prov);
5474}
5475
5476
5477static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
5478{
5479 u8 addr[ETH_ALEN];
5480 struct p2ps_provision *p2ps_prov;
5481 char *pos;
5482
5483 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5484 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5485 */
5486
5487 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
5488 if (hwaddr_aton(cmd, addr))
5489 return -1;
5490
5491 pos = cmd + 17;
5492 if (*pos != ' ')
5493 return -1;
5494
5495 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
5496 if (!p2ps_prov)
5497 return -1;
5498
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005499 p2ps_prov->pd_seeker = 1;
5500
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005501 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
5502 p2ps_prov);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005503}
5504
5505
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005506static int parse_freq(int chwidth, int freq2)
5507{
5508 if (freq2 < 0)
5509 return -1;
5510 if (freq2)
5511 return VHT_CHANWIDTH_80P80MHZ;
5512
5513 switch (chwidth) {
5514 case 0:
5515 case 20:
5516 case 40:
5517 return VHT_CHANWIDTH_USE_HT;
5518 case 80:
5519 return VHT_CHANWIDTH_80MHZ;
5520 case 160:
5521 return VHT_CHANWIDTH_160MHZ;
5522 default:
5523 wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
5524 chwidth);
5525 return -1;
5526 }
5527}
5528
5529
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005530static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
5531 char *buf, size_t buflen)
5532{
5533 u8 addr[ETH_ALEN];
5534 char *pos, *pos2;
5535 char *pin = NULL;
5536 enum p2p_wps_method wps_method;
5537 int new_pin;
5538 int ret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005539 int persistent_group, persistent_id = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005540 int join;
5541 int auth;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005542 int automatic;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005543 int go_intent = -1;
5544 int freq = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005545 int pd;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005546 int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005547 u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
5548 size_t group_ssid_len = 0;
Hai Shalom39bc25d2019-02-06 16:32:13 -08005549 int he;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005550
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08005551 if (!wpa_s->global->p2p_init_wpa_s)
5552 return -1;
5553 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
5554 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
5555 wpa_s->global->p2p_init_wpa_s->ifname);
5556 wpa_s = wpa_s->global->p2p_init_wpa_s;
5557 }
5558
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005559 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
Dmitry Shmidt04949592012-07-19 12:16:46 -07005560 * [persistent|persistent=<network id>]
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005561 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
Hai Shalom39bc25d2019-02-06 16:32:13 -08005562 * [ht40] [vht] [he] [auto] [ssid=<hexdump>] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005563
5564 if (hwaddr_aton(cmd, addr))
5565 return -1;
5566
5567 pos = cmd + 17;
5568 if (*pos != ' ')
5569 return -1;
5570 pos++;
5571
5572 persistent_group = os_strstr(pos, " persistent") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005573 pos2 = os_strstr(pos, " persistent=");
5574 if (pos2) {
5575 struct wpa_ssid *ssid;
5576 persistent_id = atoi(pos2 + 12);
5577 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
5578 if (ssid == NULL || ssid->disabled != 2 ||
5579 ssid->mode != WPAS_MODE_P2P_GO) {
5580 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
5581 "SSID id=%d for persistent P2P group (GO)",
5582 persistent_id);
5583 return -1;
5584 }
5585 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005586 join = os_strstr(pos, " join") != NULL;
5587 auth = os_strstr(pos, " auth") != NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005588 automatic = os_strstr(pos, " auto") != NULL;
5589 pd = os_strstr(pos, " provdisc") != NULL;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005590 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
5591 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
5592 vht;
Hai Shalom39bc25d2019-02-06 16:32:13 -08005593 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005594
5595 pos2 = os_strstr(pos, " go_intent=");
5596 if (pos2) {
5597 pos2 += 11;
5598 go_intent = atoi(pos2);
5599 if (go_intent < 0 || go_intent > 15)
5600 return -1;
5601 }
5602
5603 pos2 = os_strstr(pos, " freq=");
5604 if (pos2) {
5605 pos2 += 6;
5606 freq = atoi(pos2);
5607 if (freq <= 0)
5608 return -1;
5609 }
5610
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005611 pos2 = os_strstr(pos, " freq2=");
5612 if (pos2)
5613 freq2 = atoi(pos2 + 7);
5614
5615 pos2 = os_strstr(pos, " max_oper_chwidth=");
5616 if (pos2)
5617 chwidth = atoi(pos2 + 18);
5618
5619 max_oper_chwidth = parse_freq(chwidth, freq2);
5620 if (max_oper_chwidth < 0)
5621 return -1;
5622
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005623 pos2 = os_strstr(pos, " ssid=");
5624 if (pos2) {
5625 char *end;
5626
5627 pos2 += 6;
5628 end = os_strchr(pos2, ' ');
5629 if (!end)
5630 group_ssid_len = os_strlen(pos2) / 2;
5631 else
5632 group_ssid_len = (end - pos2) / 2;
5633 if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
5634 hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
5635 return -1;
5636 group_ssid = _group_ssid;
5637 }
5638
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005639 if (os_strncmp(pos, "pin", 3) == 0) {
5640 /* Request random PIN (to be displayed) and enable the PIN */
5641 wps_method = WPS_PIN_DISPLAY;
5642 } else if (os_strncmp(pos, "pbc", 3) == 0) {
5643 wps_method = WPS_PBC;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07005644 } else if (os_strstr(pos, "p2ps") != NULL) {
5645 wps_method = WPS_P2PS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005646 } else {
5647 pin = pos;
5648 pos = os_strchr(pin, ' ');
5649 wps_method = WPS_PIN_KEYPAD;
5650 if (pos) {
5651 *pos++ = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005652 if (os_strncmp(pos, "display", 7) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005653 wps_method = WPS_PIN_DISPLAY;
5654 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07005655 if (!wps_pin_str_valid(pin)) {
5656 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
5657 return 17;
5658 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005659 }
5660
5661 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
Dmitry Shmidt04949592012-07-19 12:16:46 -07005662 persistent_group, automatic, join,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08005663 auth, go_intent, freq, freq2, persistent_id,
Hai Shalom39bc25d2019-02-06 16:32:13 -08005664 pd, ht40, vht, max_oper_chwidth, he,
Dmitry Shmidtde47be72016-01-07 12:52:55 -08005665 group_ssid, group_ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005666 if (new_pin == -2) {
5667 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5668 return 25;
5669 }
5670 if (new_pin == -3) {
5671 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5672 return 25;
5673 }
5674 if (new_pin < 0)
5675 return -1;
5676 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
5677 ret = os_snprintf(buf, buflen, "%08d", new_pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005678 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005679 return -1;
5680 return ret;
5681 }
5682
5683 os_memcpy(buf, "OK\n", 3);
5684 return 3;
5685}
5686
5687
5688static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
5689{
5690 unsigned int timeout = atoi(cmd);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07005691 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5692 wpa_dbg(wpa_s, MSG_INFO,
5693 "Reject P2P_LISTEN since interface is disabled");
5694 return -1;
5695 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005696 return wpas_p2p_listen(wpa_s, timeout);
5697}
5698
5699
5700static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
5701{
5702 u8 addr[ETH_ALEN];
5703 char *pos;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005704 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005705
Dmitry Shmidt04949592012-07-19 12:16:46 -07005706 /* <addr> <config method> [join|auto] */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005707
5708 if (hwaddr_aton(cmd, addr))
5709 return -1;
5710
5711 pos = cmd + 17;
5712 if (*pos != ' ')
5713 return -1;
5714 pos++;
5715
Dmitry Shmidt04949592012-07-19 12:16:46 -07005716 if (os_strstr(pos, " join") != NULL)
5717 use = WPAS_P2P_PD_FOR_JOIN;
5718 else if (os_strstr(pos, " auto") != NULL)
5719 use = WPAS_P2P_PD_AUTO;
5720
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005721 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005722}
5723
5724
5725static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
5726 size_t buflen)
5727{
5728 struct wpa_ssid *ssid = wpa_s->current_ssid;
5729
5730 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
5731 ssid->passphrase == NULL)
5732 return -1;
5733
5734 os_strlcpy(buf, ssid->passphrase, buflen);
5735 return os_strlen(buf);
5736}
5737
5738
5739static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
5740 char *buf, size_t buflen)
5741{
5742 u64 ref;
5743 int res;
5744 u8 dst_buf[ETH_ALEN], *dst;
5745 struct wpabuf *tlvs;
5746 char *pos;
5747 size_t len;
5748
5749 if (hwaddr_aton(cmd, dst_buf))
5750 return -1;
5751 dst = dst_buf;
5752 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
5753 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
5754 dst = NULL;
5755 pos = cmd + 17;
5756 if (*pos != ' ')
5757 return -1;
5758 pos++;
5759
5760 if (os_strncmp(pos, "upnp ", 5) == 0) {
5761 u8 version;
5762 pos += 5;
5763 if (hexstr2bin(pos, &version, 1) < 0)
5764 return -1;
5765 pos += 2;
5766 if (*pos != ' ')
5767 return -1;
5768 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005769 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005770#ifdef CONFIG_WIFI_DISPLAY
5771 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
5772 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
5773#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005774 } else if (os_strncmp(pos, "asp ", 4) == 0) {
5775 char *svc_str;
5776 char *svc_info = NULL;
5777 u32 id;
5778
5779 pos += 4;
5780 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
5781 return -1;
5782
5783 pos = os_strchr(pos, ' ');
5784 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
5785 return -1;
5786
5787 svc_str = pos + 1;
5788
5789 pos = os_strchr(svc_str, ' ');
5790
5791 if (pos)
5792 *pos++ = '\0';
5793
5794 /* All remaining data is the svc_info string */
5795 if (pos && pos[0] && pos[0] != ' ') {
5796 len = os_strlen(pos);
5797
5798 /* Unescape in place */
5799 len = utf8_unescape(pos, len, pos, len);
5800 if (len > 0xff)
5801 return -1;
5802
5803 svc_info = pos;
5804 }
5805
5806 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
5807 svc_str, svc_info);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005808 } else {
5809 len = os_strlen(pos);
5810 if (len & 1)
5811 return -1;
5812 len /= 2;
5813 tlvs = wpabuf_alloc(len);
5814 if (tlvs == NULL)
5815 return -1;
5816 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
5817 wpabuf_free(tlvs);
5818 return -1;
5819 }
5820
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005821 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005822 wpabuf_free(tlvs);
5823 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005824 if (ref == 0)
5825 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005826 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005827 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005828 return -1;
5829 return res;
5830}
5831
5832
5833static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
5834 char *cmd)
5835{
5836 long long unsigned val;
5837 u64 req;
5838 if (sscanf(cmd, "%llx", &val) != 1)
5839 return -1;
5840 req = val;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005841 return wpas_p2p_sd_cancel_request(wpa_s, req);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005842}
5843
5844
5845static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
5846{
5847 int freq;
5848 u8 dst[ETH_ALEN];
5849 u8 dialog_token;
5850 struct wpabuf *resp_tlvs;
5851 char *pos, *pos2;
5852 size_t len;
5853
5854 pos = os_strchr(cmd, ' ');
5855 if (pos == NULL)
5856 return -1;
5857 *pos++ = '\0';
5858 freq = atoi(cmd);
5859 if (freq == 0)
5860 return -1;
5861
5862 if (hwaddr_aton(pos, dst))
5863 return -1;
5864 pos += 17;
5865 if (*pos != ' ')
5866 return -1;
5867 pos++;
5868
5869 pos2 = os_strchr(pos, ' ');
5870 if (pos2 == NULL)
5871 return -1;
5872 *pos2++ = '\0';
5873 dialog_token = atoi(pos);
5874
5875 len = os_strlen(pos2);
5876 if (len & 1)
5877 return -1;
5878 len /= 2;
5879 resp_tlvs = wpabuf_alloc(len);
5880 if (resp_tlvs == NULL)
5881 return -1;
5882 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
5883 wpabuf_free(resp_tlvs);
5884 return -1;
5885 }
5886
5887 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
5888 wpabuf_free(resp_tlvs);
5889 return 0;
5890}
5891
5892
5893static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
5894 char *cmd)
5895{
Dmitry Shmidt04949592012-07-19 12:16:46 -07005896 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
5897 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005898 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
5899 return 0;
5900}
5901
5902
5903static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
5904 char *cmd)
5905{
5906 char *pos;
5907 size_t len;
5908 struct wpabuf *query, *resp;
5909
5910 pos = os_strchr(cmd, ' ');
5911 if (pos == NULL)
5912 return -1;
5913 *pos++ = '\0';
5914
5915 len = os_strlen(cmd);
5916 if (len & 1)
5917 return -1;
5918 len /= 2;
5919 query = wpabuf_alloc(len);
5920 if (query == NULL)
5921 return -1;
5922 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
5923 wpabuf_free(query);
5924 return -1;
5925 }
5926
5927 len = os_strlen(pos);
5928 if (len & 1) {
5929 wpabuf_free(query);
5930 return -1;
5931 }
5932 len /= 2;
5933 resp = wpabuf_alloc(len);
5934 if (resp == NULL) {
5935 wpabuf_free(query);
5936 return -1;
5937 }
5938 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
5939 wpabuf_free(query);
5940 wpabuf_free(resp);
5941 return -1;
5942 }
5943
5944 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
5945 wpabuf_free(query);
5946 wpabuf_free(resp);
5947 return -1;
5948 }
5949 return 0;
5950}
5951
5952
5953static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
5954{
5955 char *pos;
5956 u8 version;
5957
5958 pos = os_strchr(cmd, ' ');
5959 if (pos == NULL)
5960 return -1;
5961 *pos++ = '\0';
5962
5963 if (hexstr2bin(cmd, &version, 1) < 0)
5964 return -1;
5965
5966 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
5967}
5968
5969
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005970static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
5971 u8 replace, char *cmd)
5972{
5973 char *pos;
5974 char *adv_str;
5975 u32 auto_accept, adv_id, svc_state, config_methods;
5976 char *svc_info = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005977 char *cpt_prio_str;
5978 u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
Dmitry Shmidt216983b2015-02-06 10:50:36 -08005979
5980 pos = os_strchr(cmd, ' ');
5981 if (pos == NULL)
5982 return -1;
5983 *pos++ = '\0';
5984
5985 /* Auto-Accept value is mandatory, and must be one of the
5986 * single values (0, 1, 2, 4) */
5987 auto_accept = atoi(cmd);
5988 switch (auto_accept) {
5989 case P2PS_SETUP_NONE: /* No auto-accept */
5990 case P2PS_SETUP_NEW:
5991 case P2PS_SETUP_CLIENT:
5992 case P2PS_SETUP_GROUP_OWNER:
5993 break;
5994 default:
5995 return -1;
5996 }
5997
5998 /* Advertisement ID is mandatory */
5999 cmd = pos;
6000 pos = os_strchr(cmd, ' ');
6001 if (pos == NULL)
6002 return -1;
6003 *pos++ = '\0';
6004
6005 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
6006 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
6007 return -1;
6008
6009 /* Only allow replacements if exist, and adds if not */
6010 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
6011 if (!replace)
6012 return -1;
6013 } else {
6014 if (replace)
6015 return -1;
6016 }
6017
6018 /* svc_state between 0 - 0xff is mandatory */
6019 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
6020 return -1;
6021
6022 pos = os_strchr(pos, ' ');
6023 if (pos == NULL)
6024 return -1;
6025
6026 /* config_methods is mandatory */
6027 pos++;
6028 if (sscanf(pos, "%x", &config_methods) != 1)
6029 return -1;
6030
6031 if (!(config_methods &
6032 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
6033 return -1;
6034
6035 pos = os_strchr(pos, ' ');
6036 if (pos == NULL)
6037 return -1;
6038
6039 pos++;
6040 adv_str = pos;
6041
6042 /* Advertisement string is mandatory */
6043 if (!pos[0] || pos[0] == ' ')
6044 return -1;
6045
6046 /* Terminate svc string */
6047 pos = os_strchr(pos, ' ');
6048 if (pos != NULL)
6049 *pos++ = '\0';
6050
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006051 cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
6052 if (cpt_prio_str) {
6053 pos = os_strchr(pos, ' ');
6054 if (pos != NULL)
6055 *pos++ = '\0';
6056
6057 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
6058 return -1;
6059 } else {
6060 cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
6061 cpt_prio[1] = 0;
6062 }
6063
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006064 /* Service and Response Information are optional */
6065 if (pos && pos[0]) {
6066 size_t len;
6067
6068 /* Note the bare ' included, which cannot exist legally
6069 * in unescaped string. */
6070 svc_info = os_strstr(pos, "svc_info='");
6071
6072 if (svc_info) {
6073 svc_info += 9;
6074 len = os_strlen(svc_info);
6075 utf8_unescape(svc_info, len, svc_info, len);
6076 }
6077 }
6078
6079 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
6080 (u8) svc_state, (u16) config_methods,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006081 svc_info, cpt_prio);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006082}
6083
6084
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006085static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
6086{
6087 char *pos;
6088
6089 pos = os_strchr(cmd, ' ');
6090 if (pos == NULL)
6091 return -1;
6092 *pos++ = '\0';
6093
6094 if (os_strcmp(cmd, "bonjour") == 0)
6095 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
6096 if (os_strcmp(cmd, "upnp") == 0)
6097 return p2p_ctrl_service_add_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006098 if (os_strcmp(cmd, "asp") == 0)
6099 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006100 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6101 return -1;
6102}
6103
6104
6105static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
6106 char *cmd)
6107{
6108 size_t len;
6109 struct wpabuf *query;
6110 int ret;
6111
6112 len = os_strlen(cmd);
6113 if (len & 1)
6114 return -1;
6115 len /= 2;
6116 query = wpabuf_alloc(len);
6117 if (query == NULL)
6118 return -1;
6119 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
6120 wpabuf_free(query);
6121 return -1;
6122 }
6123
6124 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
6125 wpabuf_free(query);
6126 return ret;
6127}
6128
6129
6130static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
6131{
6132 char *pos;
6133 u8 version;
6134
6135 pos = os_strchr(cmd, ' ');
6136 if (pos == NULL)
6137 return -1;
6138 *pos++ = '\0';
6139
6140 if (hexstr2bin(cmd, &version, 1) < 0)
6141 return -1;
6142
6143 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
6144}
6145
6146
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006147static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
6148{
6149 u32 adv_id;
6150
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07006151 if (os_strcmp(cmd, "all") == 0) {
6152 wpas_p2p_service_flush_asp(wpa_s);
6153 return 0;
6154 }
6155
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006156 if (sscanf(cmd, "%x", &adv_id) != 1)
6157 return -1;
6158
6159 return wpas_p2p_service_del_asp(wpa_s, adv_id);
6160}
6161
6162
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006163static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
6164{
6165 char *pos;
6166
6167 pos = os_strchr(cmd, ' ');
6168 if (pos == NULL)
6169 return -1;
6170 *pos++ = '\0';
6171
6172 if (os_strcmp(cmd, "bonjour") == 0)
6173 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
6174 if (os_strcmp(cmd, "upnp") == 0)
6175 return p2p_ctrl_service_del_upnp(wpa_s, pos);
Dmitry Shmidt216983b2015-02-06 10:50:36 -08006176 if (os_strcmp(cmd, "asp") == 0)
6177 return p2p_ctrl_service_del_asp(wpa_s, pos);
6178 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6179 return -1;
6180}
6181
6182
6183static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
6184{
6185 char *pos;
6186
6187 pos = os_strchr(cmd, ' ');
6188 if (pos == NULL)
6189 return -1;
6190 *pos++ = '\0';
6191
6192 if (os_strcmp(cmd, "asp") == 0)
6193 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
6194
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006195 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
6196 return -1;
6197}
6198
6199
6200static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
6201{
6202 u8 addr[ETH_ALEN];
6203
6204 /* <addr> */
6205
6206 if (hwaddr_aton(cmd, addr))
6207 return -1;
6208
6209 return wpas_p2p_reject(wpa_s, addr);
6210}
6211
6212
6213static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
6214{
6215 char *pos;
6216 int id;
6217 struct wpa_ssid *ssid;
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006218 u8 *_peer = NULL, peer[ETH_ALEN];
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006219 int freq = 0, pref_freq = 0;
Hai Shalom39bc25d2019-02-06 16:32:13 -08006220 int ht40, vht, he, max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006221
6222 id = atoi(cmd);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006223 pos = os_strstr(cmd, " peer=");
6224 if (pos) {
6225 pos += 6;
6226 if (hwaddr_aton(pos, peer))
6227 return -1;
6228 _peer = peer;
6229 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006230 ssid = wpa_config_get_network(wpa_s->conf, id);
6231 if (ssid == NULL || ssid->disabled != 2) {
6232 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6233 "for persistent P2P group",
6234 id);
6235 return -1;
6236 }
6237
Jouni Malinen31be0a42012-08-31 21:20:51 +03006238 pos = os_strstr(cmd, " freq=");
6239 if (pos) {
6240 pos += 6;
6241 freq = atoi(pos);
6242 if (freq <= 0)
6243 return -1;
6244 }
6245
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -08006246 pos = os_strstr(cmd, " pref=");
6247 if (pos) {
6248 pos += 6;
6249 pref_freq = atoi(pos);
6250 if (pref_freq <= 0)
6251 return -1;
6252 }
6253
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006254 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
6255 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
6256 vht;
Hai Shalom39bc25d2019-02-06 16:32:13 -08006257 he = (os_strstr(cmd, " he") != NULL) || wpa_s->conf->p2p_go_he;
Jouni Malinen31be0a42012-08-31 21:20:51 +03006258
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006259 pos = os_strstr(cmd, "freq2=");
6260 if (pos)
6261 freq2 = atoi(pos + 6);
6262
6263 pos = os_strstr(cmd, " max_oper_chwidth=");
6264 if (pos)
6265 chwidth = atoi(pos + 18);
6266
6267 max_oper_chwidth = parse_freq(chwidth, freq2);
6268 if (max_oper_chwidth < 0)
6269 return -1;
6270
6271 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
Hai Shalom39bc25d2019-02-06 16:32:13 -08006272 max_oper_chwidth, pref_freq, he);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006273}
6274
6275
6276static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
6277{
6278 char *pos;
6279 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
6280
6281 pos = os_strstr(cmd, " peer=");
6282 if (!pos)
6283 return -1;
6284
6285 *pos = '\0';
6286 pos += 6;
6287 if (hwaddr_aton(pos, peer)) {
6288 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
6289 return -1;
6290 }
6291
6292 pos = os_strstr(pos, " go_dev_addr=");
6293 if (pos) {
6294 pos += 13;
6295 if (hwaddr_aton(pos, go_dev_addr)) {
6296 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
6297 pos);
6298 return -1;
6299 }
6300 go_dev = go_dev_addr;
6301 }
6302
6303 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
6304}
6305
6306
6307static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
6308{
6309 if (os_strncmp(cmd, "persistent=", 11) == 0)
6310 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
6311 if (os_strncmp(cmd, "group=", 6) == 0)
6312 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
6313
6314 return -1;
6315}
6316
6317
6318static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006319 int id, int freq, int vht_center_freq2,
Hai Shalom39bc25d2019-02-06 16:32:13 -08006320 int ht40, int vht, int vht_chwidth,
6321 int he)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006322{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006323 struct wpa_ssid *ssid;
6324
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006325 ssid = wpa_config_get_network(wpa_s->conf, id);
6326 if (ssid == NULL || ssid->disabled != 2) {
6327 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
6328 "for persistent P2P group",
6329 id);
6330 return -1;
6331 }
6332
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006333 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
6334 vht_center_freq2, 0, ht40, vht,
Hai Shalom39bc25d2019-02-06 16:32:13 -08006335 vht_chwidth, he, NULL, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006336}
6337
6338
6339static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
6340{
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006341 int freq = 0, persistent = 0, group_id = -1;
6342 int vht = wpa_s->conf->p2p_go_vht;
6343 int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
Hai Shalom39bc25d2019-02-06 16:32:13 -08006344 int he = wpa_s->conf->p2p_go_he;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006345 int max_oper_chwidth, chwidth = 0, freq2 = 0;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006346 char *token, *context = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006347#ifdef CONFIG_ACS
6348 int acs = 0;
6349#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006350
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006351 while ((token = str_token(cmd, " ", &context))) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07006352 if (sscanf(token, "freq2=%d", &freq2) == 1 ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006353 sscanf(token, "persistent=%d", &group_id) == 1 ||
6354 sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006355 continue;
Roshan Pius3a1667e2018-07-03 15:17:14 -07006356#ifdef CONFIG_ACS
6357 } else if (os_strcmp(token, "freq=acs") == 0) {
6358 acs = 1;
6359#endif /* CONFIG_ACS */
6360 } else if (sscanf(token, "freq=%d", &freq) == 1) {
6361 continue;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006362 } else if (os_strcmp(token, "ht40") == 0) {
6363 ht40 = 1;
6364 } else if (os_strcmp(token, "vht") == 0) {
6365 vht = 1;
6366 ht40 = 1;
Hai Shalom39bc25d2019-02-06 16:32:13 -08006367 } else if (os_strcmp(token, "he") == 0) {
6368 he = 1;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006369 } else if (os_strcmp(token, "persistent") == 0) {
6370 persistent = 1;
6371 } else {
6372 wpa_printf(MSG_DEBUG,
6373 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6374 token);
6375 return -1;
6376 }
6377 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006378
Roshan Pius3a1667e2018-07-03 15:17:14 -07006379#ifdef CONFIG_ACS
6380 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
6381 (acs || freq == 2 || freq == 5)) {
6382 if (freq == 2 && wpa_s->best_24_freq <= 0) {
6383 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
6384 wpa_s->p2p_go_do_acs = 1;
6385 freq = 0;
6386 } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
6387 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
6388 wpa_s->p2p_go_do_acs = 1;
6389 freq = 0;
6390 } else {
6391 wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
6392 wpa_s->p2p_go_do_acs = 1;
6393 }
6394 }
6395#endif /* CONFIG_ACS */
6396
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006397 max_oper_chwidth = parse_freq(chwidth, freq2);
6398 if (max_oper_chwidth < 0)
6399 return -1;
6400
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07006401 if (group_id >= 0)
6402 return p2p_ctrl_group_add_persistent(wpa_s, group_id,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006403 freq, freq2, ht40, vht,
Hai Shalom39bc25d2019-02-06 16:32:13 -08006404 max_oper_chwidth, he);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006405
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006406 return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
Hai Shalom39bc25d2019-02-06 16:32:13 -08006407 max_oper_chwidth, he);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006408}
6409
6410
Dmitry Shmidt849734c2016-05-27 09:59:01 -07006411static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
6412 char *buf, size_t buflen)
6413{
6414 u8 dev_addr[ETH_ALEN];
6415 struct wpa_ssid *ssid;
6416 int res;
6417 const u8 *iaddr;
6418
6419 ssid = wpa_s->current_ssid;
6420 if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
6421 hwaddr_aton(cmd, dev_addr))
6422 return -1;
6423
6424 iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
6425 if (!iaddr)
6426 return -1;
6427 res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
6428 if (os_snprintf_error(buflen, res))
6429 return -1;
6430 return res;
6431}
6432
6433
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006434static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
6435 const u8 *p2p_dev_addr)
6436{
6437 struct wpa_supplicant *wpa_s;
6438
6439 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6440 if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
6441 return 1;
6442 }
6443
6444 return 0;
6445}
6446
6447
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006448static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
6449 char *buf, size_t buflen)
6450{
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006451 u8 addr[ETH_ALEN], *addr_ptr, group_capab;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006452 int next, res;
6453 const struct p2p_peer_info *info;
6454 char *pos, *end;
6455 char devtype[WPS_DEV_TYPE_BUFSIZE];
6456 struct wpa_ssid *ssid;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006457 size_t i;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006458
6459 if (!wpa_s->global->p2p)
6460 return -1;
6461
6462 if (os_strcmp(cmd, "FIRST") == 0) {
6463 addr_ptr = NULL;
6464 next = 0;
6465 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
6466 if (hwaddr_aton(cmd + 5, addr) < 0)
6467 return -1;
6468 addr_ptr = addr;
6469 next = 1;
6470 } else {
6471 if (hwaddr_aton(cmd, addr) < 0)
6472 return -1;
6473 addr_ptr = addr;
6474 next = 0;
6475 }
6476
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006477 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
6478 if (info == NULL)
6479 return -1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006480 group_capab = info->group_capab;
6481
6482 if (group_capab &&
6483 !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
6484 wpa_printf(MSG_DEBUG,
6485 "P2P: Could not find any BSS with p2p_dev_addr "
6486 MACSTR ", hence override group_capab from 0x%x to 0",
6487 MAC2STR(info->p2p_device_addr), group_capab);
6488 group_capab = 0;
6489 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006490
6491 pos = buf;
6492 end = buf + buflen;
6493
6494 res = os_snprintf(pos, end - pos, MACSTR "\n"
6495 "pri_dev_type=%s\n"
6496 "device_name=%s\n"
6497 "manufacturer=%s\n"
6498 "model_name=%s\n"
6499 "model_number=%s\n"
6500 "serial_number=%s\n"
6501 "config_methods=0x%x\n"
6502 "dev_capab=0x%x\n"
6503 "group_capab=0x%x\n"
6504 "level=%d\n",
6505 MAC2STR(info->p2p_device_addr),
6506 wps_dev_type_bin2str(info->pri_dev_type,
6507 devtype, sizeof(devtype)),
6508 info->device_name,
6509 info->manufacturer,
6510 info->model_name,
6511 info->model_number,
6512 info->serial_number,
6513 info->config_methods,
6514 info->dev_capab,
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006515 group_capab,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006516 info->level);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006517 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006518 return pos - buf;
6519 pos += res;
6520
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006521 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
6522 {
6523 const u8 *t;
6524 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
6525 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
6526 wps_dev_type_bin2str(t, devtype,
6527 sizeof(devtype)));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006528 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006529 return pos - buf;
6530 pos += res;
6531 }
6532
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006533 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006534 if (ssid) {
6535 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006536 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006537 return pos - buf;
6538 pos += res;
6539 }
6540
6541 res = p2p_get_peer_info_txt(info, pos, end - pos);
6542 if (res < 0)
6543 return pos - buf;
6544 pos += res;
6545
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006546 if (info->vendor_elems) {
6547 res = os_snprintf(pos, end - pos, "vendor_elems=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006548 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006549 return pos - buf;
6550 pos += res;
6551
6552 pos += wpa_snprintf_hex(pos, end - pos,
6553 wpabuf_head(info->vendor_elems),
6554 wpabuf_len(info->vendor_elems));
6555
6556 res = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006557 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07006558 return pos - buf;
6559 pos += res;
6560 }
6561
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006562 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006563}
6564
6565
Dmitry Shmidt04949592012-07-19 12:16:46 -07006566static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
6567 const char *param)
6568{
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006569 unsigned int i;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006570
6571 if (wpa_s->global->p2p == NULL)
6572 return -1;
6573
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006574 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
6575 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07006576
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006577 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
6578 struct wpa_freq_range *freq;
6579 freq = &wpa_s->global->p2p_disallow_freq.range[i];
Dmitry Shmidt04949592012-07-19 12:16:46 -07006580 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
Dmitry Shmidt4ce9c872013-10-24 11:08:13 -07006581 freq->min, freq->max);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006582 }
6583
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006584 wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
Dmitry Shmidt04949592012-07-19 12:16:46 -07006585 return 0;
6586}
6587
6588
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006589static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
6590{
6591 char *param;
6592
6593 if (wpa_s->global->p2p == NULL)
6594 return -1;
6595
6596 param = os_strchr(cmd, ' ');
6597 if (param == NULL)
6598 return -1;
6599 *param++ = '\0';
6600
6601 if (os_strcmp(cmd, "discoverability") == 0) {
6602 p2p_set_client_discoverability(wpa_s->global->p2p,
6603 atoi(param));
6604 return 0;
6605 }
6606
6607 if (os_strcmp(cmd, "managed") == 0) {
6608 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
6609 return 0;
6610 }
6611
6612 if (os_strcmp(cmd, "listen_channel") == 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08006613 char *pos;
6614 u8 channel, op_class;
6615
6616 channel = atoi(param);
6617 pos = os_strchr(param, ' ');
6618 op_class = pos ? atoi(pos) : 81;
6619
6620 return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
6621 channel, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006622 }
6623
6624 if (os_strcmp(cmd, "ssid_postfix") == 0) {
6625 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
6626 os_strlen(param));
6627 }
6628
6629 if (os_strcmp(cmd, "noa") == 0) {
6630 char *pos;
6631 int count, start, duration;
6632 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6633 count = atoi(param);
6634 pos = os_strchr(param, ',');
6635 if (pos == NULL)
6636 return -1;
6637 pos++;
6638 start = atoi(pos);
6639 pos = os_strchr(pos, ',');
6640 if (pos == NULL)
6641 return -1;
6642 pos++;
6643 duration = atoi(pos);
6644 if (count < 0 || count > 255 || start < 0 || duration < 0)
6645 return -1;
6646 if (count == 0 && duration > 0)
6647 return -1;
6648 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6649 "start=%d duration=%d", count, start, duration);
6650 return wpas_p2p_set_noa(wpa_s, count, start, duration);
6651 }
6652
6653 if (os_strcmp(cmd, "ps") == 0)
6654 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
6655
6656 if (os_strcmp(cmd, "oppps") == 0)
6657 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
6658
6659 if (os_strcmp(cmd, "ctwindow") == 0)
6660 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
6661
6662 if (os_strcmp(cmd, "disabled") == 0) {
6663 wpa_s->global->p2p_disabled = atoi(param);
6664 wpa_printf(MSG_DEBUG, "P2P functionality %s",
6665 wpa_s->global->p2p_disabled ?
6666 "disabled" : "enabled");
6667 if (wpa_s->global->p2p_disabled) {
6668 wpas_p2p_stop_find(wpa_s);
6669 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6670 p2p_flush(wpa_s->global->p2p);
6671 }
6672 return 0;
6673 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006674
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006675 if (os_strcmp(cmd, "conc_pref") == 0) {
6676 if (os_strcmp(param, "sta") == 0)
6677 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
6678 else if (os_strcmp(param, "p2p") == 0)
6679 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006680 else {
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006681 wpa_printf(MSG_INFO, "Invalid conc_pref value");
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006682 return -1;
6683 }
Dmitry Shmidt2fb777c2012-05-02 12:29:53 -07006684 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
Dmitry Shmidt04949592012-07-19 12:16:46 -07006685 "%s", param);
Dmitry Shmidt687922c2012-03-26 14:02:32 -07006686 return 0;
6687 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07006688
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006689 if (os_strcmp(cmd, "force_long_sd") == 0) {
6690 wpa_s->force_long_sd = atoi(param);
6691 return 0;
6692 }
6693
6694 if (os_strcmp(cmd, "peer_filter") == 0) {
6695 u8 addr[ETH_ALEN];
6696 if (hwaddr_aton(param, addr))
6697 return -1;
6698 p2p_set_peer_filter(wpa_s->global->p2p, addr);
6699 return 0;
6700 }
6701
6702 if (os_strcmp(cmd, "cross_connect") == 0)
6703 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
6704
6705 if (os_strcmp(cmd, "go_apsd") == 0) {
6706 if (os_strcmp(param, "disable") == 0)
6707 wpa_s->set_ap_uapsd = 0;
6708 else {
6709 wpa_s->set_ap_uapsd = 1;
6710 wpa_s->ap_uapsd = atoi(param);
6711 }
6712 return 0;
6713 }
6714
6715 if (os_strcmp(cmd, "client_apsd") == 0) {
6716 if (os_strcmp(param, "disable") == 0)
6717 wpa_s->set_sta_uapsd = 0;
6718 else {
6719 int be, bk, vi, vo;
6720 char *pos;
6721 /* format: BE,BK,VI,VO;max SP Length */
6722 be = atoi(param);
6723 pos = os_strchr(param, ',');
6724 if (pos == NULL)
6725 return -1;
6726 pos++;
6727 bk = atoi(pos);
6728 pos = os_strchr(pos, ',');
6729 if (pos == NULL)
6730 return -1;
6731 pos++;
6732 vi = atoi(pos);
6733 pos = os_strchr(pos, ',');
6734 if (pos == NULL)
6735 return -1;
6736 pos++;
6737 vo = atoi(pos);
6738 /* ignore max SP Length for now */
6739
6740 wpa_s->set_sta_uapsd = 1;
6741 wpa_s->sta_uapsd = 0;
6742 if (be)
6743 wpa_s->sta_uapsd |= BIT(0);
6744 if (bk)
6745 wpa_s->sta_uapsd |= BIT(1);
6746 if (vi)
6747 wpa_s->sta_uapsd |= BIT(2);
6748 if (vo)
6749 wpa_s->sta_uapsd |= BIT(3);
6750 }
6751 return 0;
6752 }
6753
Dmitry Shmidt04949592012-07-19 12:16:46 -07006754 if (os_strcmp(cmd, "disallow_freq") == 0)
6755 return p2p_ctrl_disallow_freq(wpa_s, param);
6756
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08006757 if (os_strcmp(cmd, "disc_int") == 0) {
6758 int min_disc_int, max_disc_int, max_disc_tu;
6759 char *pos;
6760
6761 pos = param;
6762
6763 min_disc_int = atoi(pos);
6764 pos = os_strchr(pos, ' ');
6765 if (pos == NULL)
6766 return -1;
6767 *pos++ = '\0';
6768
6769 max_disc_int = atoi(pos);
6770 pos = os_strchr(pos, ' ');
6771 if (pos == NULL)
6772 return -1;
6773 *pos++ = '\0';
6774
6775 max_disc_tu = atoi(pos);
6776
6777 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
6778 max_disc_int, max_disc_tu);
6779 }
6780
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07006781 if (os_strcmp(cmd, "per_sta_psk") == 0) {
6782 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
6783 return 0;
6784 }
6785
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08006786#ifdef CONFIG_WPS_NFC
6787 if (os_strcmp(cmd, "nfc_tag") == 0)
6788 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
6789#endif /* CONFIG_WPS_NFC */
6790
6791 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
6792 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
6793 return 0;
6794 }
6795
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08006796 if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
6797 int op_class, chan;
6798
6799 op_class = atoi(param);
6800 param = os_strchr(param, ':');
6801 if (!param)
6802 return -1;
6803 param++;
6804 chan = atoi(param);
6805 p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
6806 chan);
6807 return 0;
6808 }
6809
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006810 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6811 cmd);
6812
6813 return -1;
6814}
6815
6816
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006817static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
6818{
6819 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6820 wpa_s->force_long_sd = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07006821
6822#ifdef CONFIG_TESTING_OPTIONS
6823 os_free(wpa_s->get_pref_freq_list_override);
6824 wpa_s->get_pref_freq_list_override = NULL;
6825#endif /* CONFIG_TESTING_OPTIONS */
6826
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006827 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006828 wpa_s->parent->p2ps_method_config_any = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07006829 if (wpa_s->global->p2p)
6830 p2p_flush(wpa_s->global->p2p);
6831}
6832
6833
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006834static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
6835{
6836 char *pos, *pos2;
6837 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
6838
6839 if (cmd[0]) {
6840 pos = os_strchr(cmd, ' ');
6841 if (pos == NULL)
6842 return -1;
6843 *pos++ = '\0';
6844 dur1 = atoi(cmd);
6845
6846 pos2 = os_strchr(pos, ' ');
6847 if (pos2)
6848 *pos2++ = '\0';
6849 int1 = atoi(pos);
6850 } else
6851 pos2 = NULL;
6852
6853 if (pos2) {
6854 pos = os_strchr(pos2, ' ');
6855 if (pos == NULL)
6856 return -1;
6857 *pos++ = '\0';
6858 dur2 = atoi(pos2);
6859 int2 = atoi(pos);
6860 }
6861
6862 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
6863}
6864
6865
6866static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
6867{
6868 char *pos;
6869 unsigned int period = 0, interval = 0;
6870
6871 if (cmd[0]) {
6872 pos = os_strchr(cmd, ' ');
6873 if (pos == NULL)
6874 return -1;
6875 *pos++ = '\0';
6876 period = atoi(cmd);
6877 interval = atoi(pos);
6878 }
6879
6880 return wpas_p2p_ext_listen(wpa_s, period, interval);
6881}
6882
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07006883
6884static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
6885{
6886 const char *pos;
6887 u8 peer[ETH_ALEN];
6888 int iface_addr = 0;
6889
6890 pos = cmd;
6891 if (os_strncmp(pos, "iface=", 6) == 0) {
6892 iface_addr = 1;
6893 pos += 6;
6894 }
6895 if (hwaddr_aton(pos, peer))
6896 return -1;
6897
6898 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
6899 return 0;
6900}
6901
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07006902
6903static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
6904{
6905 int freq = 0, period = 0, interval = 0, count = 0;
6906
6907 if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
6908 {
6909 wpa_printf(MSG_DEBUG,
6910 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
6911 return -1;
6912 }
6913
6914 return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
6915}
6916
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006917#endif /* CONFIG_P2P */
6918
6919
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006920static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
6921{
6922 struct wpa_freq_range_list ranges;
6923 int *freqs = NULL;
6924 struct hostapd_hw_modes *mode;
6925 u16 i;
6926
6927 if (wpa_s->hw.modes == NULL)
6928 return NULL;
6929
6930 os_memset(&ranges, 0, sizeof(ranges));
6931 if (freq_range_list_parse(&ranges, val) < 0)
6932 return NULL;
6933
6934 for (i = 0; i < wpa_s->hw.num_modes; i++) {
6935 int j;
6936
6937 mode = &wpa_s->hw.modes[i];
6938 for (j = 0; j < mode->num_channels; j++) {
6939 unsigned int freq;
6940
6941 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
6942 continue;
6943
6944 freq = mode->channels[j].freq;
6945 if (!freq_range_list_includes(&ranges, freq))
6946 continue;
6947
6948 int_array_add_unique(&freqs, freq);
6949 }
6950 }
6951
6952 os_free(ranges.range);
6953 return freqs;
6954}
6955
6956
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006957#ifdef CONFIG_INTERWORKING
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006958
6959static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
6960{
6961 int auto_sel = 0;
6962 int *freqs = NULL;
6963
6964 if (param) {
6965 char *pos;
6966
6967 auto_sel = os_strstr(param, "auto") != NULL;
6968
6969 pos = os_strstr(param, "freq=");
6970 if (pos) {
6971 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
6972 if (freqs == NULL)
6973 return -1;
6974 }
6975
6976 }
6977
6978 return interworking_select(wpa_s, auto_sel, freqs);
6979}
6980
6981
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006982static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
6983 int only_add)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006984{
6985 u8 bssid[ETH_ALEN];
6986 struct wpa_bss *bss;
6987
6988 if (hwaddr_aton(dst, bssid)) {
6989 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
6990 return -1;
6991 }
6992
6993 bss = wpa_bss_get_bssid(wpa_s, bssid);
6994 if (bss == NULL) {
6995 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
6996 MAC2STR(bssid));
6997 return -1;
6998 }
6999
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007000 if (bss->ssid_len == 0) {
7001 int found = 0;
7002
7003 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
7004 " does not have SSID information", MAC2STR(bssid));
7005
7006 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
7007 list) {
7008 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
7009 bss->ssid_len > 0) {
7010 found = 1;
7011 break;
7012 }
7013 }
7014
7015 if (!found)
7016 return -1;
7017 wpa_printf(MSG_DEBUG,
7018 "Found another matching BSS entry with SSID");
7019 }
7020
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007021 return interworking_connect(wpa_s, bss, only_add);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007022}
7023
7024
7025static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
7026{
7027 u8 dst_addr[ETH_ALEN];
7028 int used;
7029 char *pos;
7030#define MAX_ANQP_INFO_ID 100
7031 u16 id[MAX_ANQP_INFO_ID];
7032 size_t num_id = 0;
Dmitry Shmidt15907092014-03-25 10:42:57 -07007033 u32 subtypes = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007034 u32 mbo_subtypes = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007035
7036 used = hwaddr_aton2(dst, dst_addr);
7037 if (used < 0)
7038 return -1;
7039 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007040 if (*pos == ' ')
7041 pos++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007042 while (num_id < MAX_ANQP_INFO_ID) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07007043 if (os_strncmp(pos, "hs20:", 5) == 0) {
7044#ifdef CONFIG_HS20
7045 int num = atoi(pos + 5);
7046 if (num <= 0 || num > 31)
7047 return -1;
7048 subtypes |= BIT(num);
7049#else /* CONFIG_HS20 */
7050 return -1;
7051#endif /* CONFIG_HS20 */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007052 } else if (os_strncmp(pos, "mbo:", 4) == 0) {
7053#ifdef CONFIG_MBO
7054 int num = atoi(pos + 4);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007055
7056 if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007057 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007058 mbo_subtypes |= BIT(num);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007059#else /* CONFIG_MBO */
7060 return -1;
7061#endif /* CONFIG_MBO */
Dmitry Shmidt15907092014-03-25 10:42:57 -07007062 } else {
7063 id[num_id] = atoi(pos);
7064 if (id[num_id])
7065 num_id++;
7066 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007067 pos = os_strchr(pos + 1, ',');
7068 if (pos == NULL)
7069 break;
7070 pos++;
7071 }
7072
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007073 if (num_id == 0 && !subtypes && !mbo_subtypes)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007074 return -1;
7075
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007076 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007077 mbo_subtypes);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007078}
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007079
7080
7081static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
7082{
7083 u8 dst_addr[ETH_ALEN];
7084 struct wpabuf *advproto, *query = NULL;
7085 int used, ret = -1;
7086 char *pos, *end;
7087 size_t len;
7088
7089 used = hwaddr_aton2(cmd, dst_addr);
7090 if (used < 0)
7091 return -1;
7092
7093 pos = cmd + used;
7094 while (*pos == ' ')
7095 pos++;
7096
7097 /* Advertisement Protocol ID */
7098 end = os_strchr(pos, ' ');
7099 if (end)
7100 len = end - pos;
7101 else
7102 len = os_strlen(pos);
7103 if (len & 0x01)
7104 return -1;
7105 len /= 2;
7106 if (len == 0)
7107 return -1;
7108 advproto = wpabuf_alloc(len);
7109 if (advproto == NULL)
7110 return -1;
7111 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
7112 goto fail;
7113
7114 if (end) {
7115 /* Optional Query Request */
7116 pos = end + 1;
7117 while (*pos == ' ')
7118 pos++;
7119
7120 len = os_strlen(pos);
7121 if (len) {
7122 if (len & 0x01)
7123 goto fail;
7124 len /= 2;
7125 if (len == 0)
7126 goto fail;
7127 query = wpabuf_alloc(len);
7128 if (query == NULL)
7129 goto fail;
7130 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
7131 goto fail;
7132 }
7133 }
7134
7135 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
7136
7137fail:
7138 wpabuf_free(advproto);
7139 wpabuf_free(query);
7140
7141 return ret;
7142}
7143
7144
7145static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
7146 size_t buflen)
7147{
7148 u8 addr[ETH_ALEN];
7149 int dialog_token;
7150 int used;
7151 char *pos;
7152 size_t resp_len, start, requested_len;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007153 struct wpabuf *resp;
7154 int ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007155
7156 used = hwaddr_aton2(cmd, addr);
7157 if (used < 0)
7158 return -1;
7159
7160 pos = cmd + used;
7161 while (*pos == ' ')
7162 pos++;
7163 dialog_token = atoi(pos);
7164
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007165 if (wpa_s->last_gas_resp &&
7166 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
7167 dialog_token == wpa_s->last_gas_dialog_token)
7168 resp = wpa_s->last_gas_resp;
7169 else if (wpa_s->prev_gas_resp &&
7170 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
7171 dialog_token == wpa_s->prev_gas_dialog_token)
7172 resp = wpa_s->prev_gas_resp;
7173 else
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007174 return -1;
7175
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007176 resp_len = wpabuf_len(resp);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007177 start = 0;
7178 requested_len = resp_len;
7179
7180 pos = os_strchr(pos, ' ');
7181 if (pos) {
7182 start = atoi(pos);
7183 if (start > resp_len)
7184 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7185 pos = os_strchr(pos, ',');
7186 if (pos == NULL)
7187 return -1;
7188 pos++;
7189 requested_len = atoi(pos);
7190 if (start + requested_len > resp_len)
7191 return os_snprintf(buf, buflen, "FAIL-Invalid range");
7192 }
7193
7194 if (requested_len * 2 + 1 > buflen)
7195 return os_snprintf(buf, buflen, "FAIL-Too long response");
7196
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007197 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
7198 requested_len);
7199
7200 if (start + requested_len == resp_len) {
7201 /*
7202 * Free memory by dropping the response after it has been
7203 * fetched.
7204 */
7205 if (resp == wpa_s->prev_gas_resp) {
7206 wpabuf_free(wpa_s->prev_gas_resp);
7207 wpa_s->prev_gas_resp = NULL;
7208 } else {
7209 wpabuf_free(wpa_s->last_gas_resp);
7210 wpa_s->last_gas_resp = NULL;
7211 }
7212 }
7213
7214 return ret;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07007215}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007216#endif /* CONFIG_INTERWORKING */
7217
7218
Dmitry Shmidt04949592012-07-19 12:16:46 -07007219#ifdef CONFIG_HS20
7220
7221static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
7222{
7223 u8 dst_addr[ETH_ALEN];
7224 int used;
7225 char *pos;
7226 u32 subtypes = 0;
7227
7228 used = hwaddr_aton2(dst, dst_addr);
7229 if (used < 0)
7230 return -1;
7231 pos = dst + used;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007232 if (*pos == ' ')
7233 pos++;
Dmitry Shmidt04949592012-07-19 12:16:46 -07007234 for (;;) {
7235 int num = atoi(pos);
7236 if (num <= 0 || num > 31)
7237 return -1;
7238 subtypes |= BIT(num);
7239 pos = os_strchr(pos + 1, ',');
7240 if (pos == NULL)
7241 break;
7242 pos++;
7243 }
7244
7245 if (subtypes == 0)
7246 return -1;
7247
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007248 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007249}
7250
7251
7252static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7253 const u8 *addr, const char *realm)
7254{
7255 u8 *buf;
7256 size_t rlen, len;
7257 int ret;
7258
7259 rlen = os_strlen(realm);
7260 len = 3 + rlen;
7261 buf = os_malloc(len);
7262 if (buf == NULL)
7263 return -1;
7264 buf[0] = 1; /* NAI Home Realm Count */
7265 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
7266 buf[2] = rlen;
7267 os_memcpy(buf + 3, realm, rlen);
7268
7269 ret = hs20_anqp_send_req(wpa_s, addr,
7270 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007271 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007272
7273 os_free(buf);
7274
7275 return ret;
7276}
7277
7278
7279static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
7280 char *dst)
7281{
7282 struct wpa_cred *cred = wpa_s->conf->cred;
7283 u8 dst_addr[ETH_ALEN];
7284 int used;
7285 u8 *buf;
7286 size_t len;
7287 int ret;
7288
7289 used = hwaddr_aton2(dst, dst_addr);
7290 if (used < 0)
7291 return -1;
7292
7293 while (dst[used] == ' ')
7294 used++;
7295 if (os_strncmp(dst + used, "realm=", 6) == 0)
7296 return hs20_nai_home_realm_list(wpa_s, dst_addr,
7297 dst + used + 6);
7298
7299 len = os_strlen(dst + used);
7300
7301 if (len == 0 && cred && cred->realm)
7302 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
7303
Dmitry Shmidt623d63a2014-06-13 11:05:14 -07007304 if (len & 1)
Dmitry Shmidt04949592012-07-19 12:16:46 -07007305 return -1;
7306 len /= 2;
7307 buf = os_malloc(len);
7308 if (buf == NULL)
7309 return -1;
7310 if (hexstr2bin(dst + used, buf, len) < 0) {
7311 os_free(buf);
7312 return -1;
7313 }
7314
7315 ret = hs20_anqp_send_req(wpa_s, dst_addr,
7316 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007317 buf, len, 0);
Dmitry Shmidt04949592012-07-19 12:16:46 -07007318 os_free(buf);
7319
7320 return ret;
7321}
7322
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007323
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007324static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
7325 int buflen)
7326{
7327 u8 dst_addr[ETH_ALEN];
7328 int used;
7329 char *ctx = NULL, *icon, *poffset, *psize;
7330
7331 used = hwaddr_aton2(cmd, dst_addr);
7332 if (used < 0)
7333 return -1;
7334 cmd += used;
7335
7336 icon = str_token(cmd, " ", &ctx);
7337 poffset = str_token(cmd, " ", &ctx);
7338 psize = str_token(cmd, " ", &ctx);
7339 if (!icon || !poffset || !psize)
7340 return -1;
7341
7342 wpa_s->fetch_osu_icon_in_progress = 0;
7343 return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
7344 reply, buflen);
7345}
7346
7347
7348static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
7349{
7350 u8 dst_addr[ETH_ALEN];
7351 int used;
7352 char *icon;
7353
7354 if (!cmd[0])
7355 return hs20_del_icon(wpa_s, NULL, NULL);
7356
7357 used = hwaddr_aton2(cmd, dst_addr);
7358 if (used < 0)
7359 return -1;
7360
7361 while (cmd[used] == ' ')
7362 used++;
7363 icon = cmd[used] ? &cmd[used] : NULL;
7364
7365 return hs20_del_icon(wpa_s, dst_addr, icon);
7366}
7367
7368
7369static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007370{
7371 u8 dst_addr[ETH_ALEN];
7372 int used;
7373 char *icon;
7374
7375 used = hwaddr_aton2(cmd, dst_addr);
7376 if (used < 0)
7377 return -1;
7378
7379 while (cmd[used] == ' ')
7380 used++;
7381 icon = &cmd[used];
7382
7383 wpa_s->fetch_osu_icon_in_progress = 0;
7384 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007385 (u8 *) icon, os_strlen(icon), inmem);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007386}
7387
Dmitry Shmidt04949592012-07-19 12:16:46 -07007388#endif /* CONFIG_HS20 */
7389
7390
Dmitry Shmidt04949592012-07-19 12:16:46 -07007391#ifdef CONFIG_AUTOSCAN
7392
7393static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
7394 char *cmd)
7395{
7396 enum wpa_states state = wpa_s->wpa_state;
7397 char *new_params = NULL;
7398
7399 if (os_strlen(cmd) > 0) {
7400 new_params = os_strdup(cmd);
7401 if (new_params == NULL)
7402 return -1;
7403 }
7404
7405 os_free(wpa_s->conf->autoscan);
7406 wpa_s->conf->autoscan = new_params;
7407
7408 if (wpa_s->conf->autoscan == NULL)
7409 autoscan_deinit(wpa_s);
7410 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
7411 autoscan_init(wpa_s, 1);
7412 else if (state == WPA_SCANNING)
7413 wpa_supplicant_reinit_autoscan(wpa_s);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08007414 else
7415 wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
7416 wpa_supplicant_state_txt(state));
Dmitry Shmidt04949592012-07-19 12:16:46 -07007417
7418 return 0;
7419}
7420
7421#endif /* CONFIG_AUTOSCAN */
7422
7423
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007424#ifdef CONFIG_WNM
7425
7426static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
7427{
7428 int enter;
7429 int intval = 0;
7430 char *pos;
7431 int ret;
7432 struct wpabuf *tfs_req = NULL;
7433
7434 if (os_strncmp(cmd, "enter", 5) == 0)
7435 enter = 1;
7436 else if (os_strncmp(cmd, "exit", 4) == 0)
7437 enter = 0;
7438 else
7439 return -1;
7440
7441 pos = os_strstr(cmd, " interval=");
7442 if (pos)
7443 intval = atoi(pos + 10);
7444
7445 pos = os_strstr(cmd, " tfs_req=");
7446 if (pos) {
7447 char *end;
7448 size_t len;
7449 pos += 9;
7450 end = os_strchr(pos, ' ');
7451 if (end)
7452 len = end - pos;
7453 else
7454 len = os_strlen(pos);
7455 if (len & 1)
7456 return -1;
7457 len /= 2;
7458 tfs_req = wpabuf_alloc(len);
7459 if (tfs_req == NULL)
7460 return -1;
7461 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
7462 wpabuf_free(tfs_req);
7463 return -1;
7464 }
7465 }
7466
7467 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
7468 WNM_SLEEP_MODE_EXIT, intval,
7469 tfs_req);
7470 wpabuf_free(tfs_req);
7471
7472 return ret;
7473}
7474
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007475
7476static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
7477{
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007478 int query_reason, list = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007479 char *btm_candidates = NULL;
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007480
7481 query_reason = atoi(cmd);
7482
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007483 cmd = os_strchr(cmd, ' ');
7484 if (cmd) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007485 if (os_strncmp(cmd, " list", 5) == 0)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007486 list = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007487 else
7488 btm_candidates = cmd;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007489 }
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007490
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007491 wpa_printf(MSG_DEBUG,
7492 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7493 query_reason, list ? " candidate list" : "");
7494
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007495 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
7496 btm_candidates,
7497 list);
Dmitry Shmidt44c95782013-05-17 09:51:35 -07007498}
7499
Hai Shalom39ba6fc2019-01-22 12:40:38 -08007500
7501static int wpas_ctrl_iface_coloc_intf_report(struct wpa_supplicant *wpa_s,
7502 char *cmd)
7503{
7504 struct wpabuf *elems;
7505 int ret;
7506
7507 elems = wpabuf_parse_bin(cmd);
7508 if (!elems)
7509 return -1;
7510
7511 ret = wnm_send_coloc_intf_report(wpa_s, 0, elems);
7512 wpabuf_free(elems);
7513 return ret;
7514}
7515
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08007516#endif /* CONFIG_WNM */
7517
7518
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007519static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
7520 size_t buflen)
7521{
7522 struct wpa_signal_info si;
7523 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007524 char *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007525
7526 ret = wpa_drv_signal_poll(wpa_s, &si);
7527 if (ret)
7528 return -1;
7529
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007530 pos = buf;
7531 end = buf + buflen;
7532
7533 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007534 "NOISE=%d\nFREQUENCY=%u\n",
7535 si.current_signal, si.current_txrate / 1000,
7536 si.current_noise, si.frequency);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007537 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007538 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007539 pos += ret;
7540
7541 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
7542 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007543 channel_width_to_string(si.chanwidth));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007544 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007545 return -1;
7546 pos += ret;
7547 }
7548
Roshan Pius3a1667e2018-07-03 15:17:14 -07007549 if (si.center_frq1 > 0) {
7550 ret = os_snprintf(pos, end - pos, "CENTER_FRQ1=%d\n",
7551 si.center_frq1);
7552 if (os_snprintf_error(end - pos, ret))
7553 return -1;
7554 pos += ret;
7555 }
7556
7557 if (si.center_frq2 > 0) {
7558 ret = os_snprintf(pos, end - pos, "CENTER_FRQ2=%d\n",
7559 si.center_frq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007560 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007561 return -1;
7562 pos += ret;
7563 }
7564
7565 if (si.avg_signal) {
7566 ret = os_snprintf(pos, end - pos,
7567 "AVG_RSSI=%d\n", si.avg_signal);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007568 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007569 return -1;
7570 pos += ret;
7571 }
7572
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07007573 if (si.avg_beacon_signal) {
7574 ret = os_snprintf(pos, end - pos,
7575 "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
7576 if (os_snprintf_error(end - pos, ret))
7577 return -1;
7578 pos += ret;
7579 }
7580
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007581 return pos - buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007582}
7583
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03007584
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007585static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
7586 const char *cmd)
7587{
7588 const char *pos;
7589 int threshold = 0;
7590 int hysteresis = 0;
7591
7592 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
7593 wpa_printf(MSG_DEBUG,
7594 "Reject SIGNAL_MONITOR command - bgscan is active");
7595 return -1;
7596 }
7597 pos = os_strstr(cmd, "THRESHOLD=");
7598 if (pos)
7599 threshold = atoi(pos + 10);
7600 pos = os_strstr(cmd, "HYSTERESIS=");
7601 if (pos)
7602 hysteresis = atoi(pos + 11);
7603 return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
7604}
7605
7606
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007607#ifdef CONFIG_TESTING_OPTIONS
7608int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
7609 enum wpa_driver_if_type if_type,
7610 unsigned int *num,
7611 unsigned int *freq_list)
7612{
7613 char *pos = wpa_s->get_pref_freq_list_override;
7614 char *end;
7615 unsigned int count = 0;
7616
7617 /* Override string format:
7618 * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
7619
7620 while (pos) {
7621 if (atoi(pos) == (int) if_type)
7622 break;
7623 pos = os_strchr(pos, ' ');
7624 if (pos)
7625 pos++;
7626 }
7627 if (!pos)
7628 return -1;
7629 pos = os_strchr(pos, ':');
7630 if (!pos)
7631 return -1;
7632 pos++;
7633 end = os_strchr(pos, ' ');
7634 while (pos && (!end || pos < end) && count < *num) {
7635 freq_list[count++] = atoi(pos);
7636 pos = os_strchr(pos, ',');
7637 if (pos)
7638 pos++;
7639 }
7640
7641 *num = count;
7642 return 0;
7643}
7644#endif /* CONFIG_TESTING_OPTIONS */
7645
7646
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007647static int wpas_ctrl_iface_get_pref_freq_list(
7648 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
7649{
7650 unsigned int freq_list[100], num = 100, i;
7651 int ret;
7652 enum wpa_driver_if_type iface_type;
7653 char *pos, *end;
7654
7655 pos = buf;
7656 end = buf + buflen;
7657
7658 /* buf: "<interface_type>" */
7659 if (os_strcmp(cmd, "STATION") == 0)
7660 iface_type = WPA_IF_STATION;
7661 else if (os_strcmp(cmd, "AP") == 0)
7662 iface_type = WPA_IF_AP_BSS;
7663 else if (os_strcmp(cmd, "P2P_GO") == 0)
7664 iface_type = WPA_IF_P2P_GO;
7665 else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
7666 iface_type = WPA_IF_P2P_CLIENT;
7667 else if (os_strcmp(cmd, "IBSS") == 0)
7668 iface_type = WPA_IF_IBSS;
7669 else if (os_strcmp(cmd, "TDLS") == 0)
7670 iface_type = WPA_IF_TDLS;
7671 else
7672 return -1;
7673
7674 wpa_printf(MSG_DEBUG,
7675 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7676 iface_type, buf);
7677
7678 ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
7679 if (ret)
7680 return -1;
7681
7682 for (i = 0; i < num; i++) {
7683 ret = os_snprintf(pos, end - pos, "%s%u",
7684 i > 0 ? "," : "", freq_list[i]);
7685 if (os_snprintf_error(end - pos, ret))
7686 return -1;
7687 pos += ret;
7688 }
7689
7690 return pos - buf;
7691}
7692
7693
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007694static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
7695 char *buf, size_t buflen)
7696{
7697 int ret, i;
7698 char *pos, *end;
7699
7700 ret = os_snprintf(buf, buflen, "%016llX:\n",
7701 (long long unsigned) wpa_s->drv_flags);
7702 if (os_snprintf_error(buflen, ret))
7703 return -1;
7704
7705 pos = buf + ret;
7706 end = buf + buflen;
7707
7708 for (i = 0; i < 64; i++) {
7709 if (wpa_s->drv_flags & (1LLU << i)) {
7710 ret = os_snprintf(pos, end - pos, "%s\n",
7711 driver_flag_to_string(1LLU << i));
7712 if (os_snprintf_error(end - pos, ret))
7713 return -1;
7714 pos += ret;
7715 }
7716 }
7717
7718 return pos - buf;
7719}
7720
7721
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07007722static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
7723 size_t buflen)
7724{
7725 struct hostap_sta_driver_data sta;
7726 int ret;
7727
7728 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
7729 if (ret)
7730 return -1;
7731
7732 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03007733 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007734 if (os_snprintf_error(buflen, ret))
Yuhao Zhengfcd6f212012-07-27 10:37:52 -07007735 return -1;
7736 return ret;
7737}
7738
7739
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007740#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07007741static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
7742 char *buf, size_t buflen)
7743{
7744 int ret;
7745
7746 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
Dmitry Shmidt9432e122013-09-12 12:39:30 -07007747 if (ret == 0) {
7748 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
7749 struct p2p_data *p2p = wpa_s->global->p2p;
7750 if (p2p) {
7751 char country[3];
7752 country[0] = cmd[8];
7753 country[1] = cmd[9];
7754 country[2] = 0x04;
7755 p2p_set_country(p2p, country);
7756 }
7757 }
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007758 ret = os_snprintf(buf, buflen, "%s\n", "OK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007759 if (os_snprintf_error(buflen, ret))
7760 ret = -1;
Dmitry Shmidt9432e122013-09-12 12:39:30 -07007761 }
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07007762 return ret;
7763}
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007764#endif /* ANDROID */
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -07007765
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07007766
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007767static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
7768 char *buf, size_t buflen)
7769{
7770 int ret;
7771 char *pos;
7772 u8 *data = NULL;
7773 unsigned int vendor_id, subcmd;
7774 struct wpabuf *reply;
7775 size_t data_len = 0;
7776
7777 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7778 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007779 if (!isblank((unsigned char) *pos))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007780 return -EINVAL;
7781
7782 subcmd = strtoul(pos, &pos, 10);
7783
7784 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08007785 if (!isblank((unsigned char) *pos++))
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007786 return -EINVAL;
7787 data_len = os_strlen(pos);
7788 }
7789
7790 if (data_len) {
7791 data_len /= 2;
7792 data = os_malloc(data_len);
7793 if (!data)
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007794 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007795
7796 if (hexstr2bin(pos, data, data_len)) {
7797 wpa_printf(MSG_DEBUG,
7798 "Vendor command: wrong parameter format");
7799 os_free(data);
7800 return -EINVAL;
7801 }
7802 }
7803
7804 reply = wpabuf_alloc((buflen - 1) / 2);
7805 if (!reply) {
7806 os_free(data);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007807 return -1;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007808 }
7809
7810 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
7811 reply);
7812
7813 if (ret == 0)
7814 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
7815 wpabuf_len(reply));
7816
7817 wpabuf_free(reply);
7818 os_free(data);
7819
7820 return ret;
7821}
7822
7823
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007824static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
7825{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007826#ifdef CONFIG_P2P
7827 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
7828 wpa_s->global->p2p_init_wpa_s : wpa_s;
7829#endif /* CONFIG_P2P */
7830
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007831 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
7832
Dmitry Shmidt29333592017-01-09 12:27:11 -08007833 if (wpas_abort_ongoing_scan(wpa_s) == 0)
7834 wpa_s->ignore_post_flush_scan_res = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007835
Dmitry Shmidtde47be72016-01-07 12:52:55 -08007836 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
7837 /*
7838 * Avoid possible auto connect re-connection on getting
7839 * disconnected due to state flush.
7840 */
7841 wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
7842 }
7843
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007844#ifdef CONFIG_P2P
Dmitry Shmidtde47be72016-01-07 12:52:55 -08007845 wpas_p2p_group_remove(p2p_wpa_s, "*");
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007846 wpas_p2p_cancel(p2p_wpa_s);
7847 p2p_ctrl_flush(p2p_wpa_s);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007848 wpas_p2p_service_flush(p2p_wpa_s);
7849 p2p_wpa_s->global->p2p_disabled = 0;
7850 p2p_wpa_s->global->p2p_per_sta_psk = 0;
7851 p2p_wpa_s->conf->num_sec_device_types = 0;
7852 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
7853 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
7854 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007855 p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
Dmitry Shmidt216983b2015-02-06 10:50:36 -08007856 p2p_wpa_s->global->pending_p2ps_group = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007857 p2p_wpa_s->global->pending_p2ps_group_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007858#endif /* CONFIG_P2P */
7859
7860#ifdef CONFIG_WPS_TESTING
7861 wps_version_number = 0x20;
7862 wps_testing_dummy_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08007863 wps_corrupt_pkhash = 0;
Dmitry Shmidtde47be72016-01-07 12:52:55 -08007864 wps_force_auth_types_in_use = 0;
7865 wps_force_encr_types_in_use = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007866#endif /* CONFIG_WPS_TESTING */
7867#ifdef CONFIG_WPS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007868 wpa_s->wps_fragment_size = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007869 wpas_wps_cancel(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007870 wps_registrar_flush(wpa_s->wps->registrar);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007871#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07007872 wpa_s->after_wps = 0;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07007873 wpa_s->known_wps_freq = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007874
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007875#ifdef CONFIG_DPP
7876 wpas_dpp_deinit(wpa_s);
Roshan Pius3a1667e2018-07-03 15:17:14 -07007877 wpa_s->dpp_init_max_tries = 0;
7878 wpa_s->dpp_init_retry_time = 0;
7879 wpa_s->dpp_resp_wait_time = 0;
7880 wpa_s->dpp_resp_max_tries = 0;
7881 wpa_s->dpp_resp_retry_time = 0;
7882#ifdef CONFIG_TESTING_OPTIONS
7883 os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
7884 os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
7885 dpp_pkex_ephemeral_key_override_len = 0;
7886 dpp_protocol_key_override_len = 0;
7887 dpp_nonce_override_len = 0;
7888#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007889#endif /* CONFIG_DPP */
7890
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007891#ifdef CONFIG_TDLS
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007892#ifdef CONFIG_TDLS_TESTING
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007893 tdls_testing = 0;
7894#endif /* CONFIG_TDLS_TESTING */
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007895 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
7896 wpa_tdls_enable(wpa_s->wpa, 1);
7897#endif /* CONFIG_TDLS */
7898
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07007899 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
7900 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
7901
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007902 wpa_s->no_keep_alive = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08007903 wpa_s->own_disconnect_req = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007904
7905 os_free(wpa_s->disallow_aps_bssid);
7906 wpa_s->disallow_aps_bssid = NULL;
7907 wpa_s->disallow_aps_bssid_count = 0;
7908 os_free(wpa_s->disallow_aps_ssid);
7909 wpa_s->disallow_aps_ssid = NULL;
7910 wpa_s->disallow_aps_ssid_count = 0;
7911
7912 wpa_s->set_sta_uapsd = 0;
7913 wpa_s->sta_uapsd = 0;
7914
7915 wpa_drv_radio_disable(wpa_s, 0);
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007916 wpa_blacklist_clear(wpa_s);
Dmitry Shmidt4b060592013-04-29 16:42:49 -07007917 wpa_s->extra_blacklist_count = 0;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07007918 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
7919 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
Dmitry Shmidt344abd32014-01-14 13:17:00 -08007920 wpa_config_flush_blobs(wpa_s->conf);
Dmitry Shmidt18463232014-01-24 12:29:41 -08007921 wpa_s->conf->auto_interworking = 0;
7922 wpa_s->conf->okc = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007923
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007924 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
7925 rsn_preauth_deinit(wpa_s->wpa);
7926
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007927 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
7928 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
7929 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
7930 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
7931
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08007932 radio_remove_works(wpa_s, NULL, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007933 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007934
7935 wpa_s->next_ssid = NULL;
7936
7937#ifdef CONFIG_INTERWORKING
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007938#ifdef CONFIG_HS20
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007939 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08007940 hs20_del_icon(wpa_s, NULL, NULL);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007941#endif /* CONFIG_HS20 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08007942#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt818ea482014-03-10 13:15:21 -07007943
7944 wpa_s->ext_mgmt_frame_handling = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007945 wpa_s->ext_eapol_frame_io = 0;
7946#ifdef CONFIG_TESTING_OPTIONS
7947 wpa_s->extra_roc_dur = 0;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007948 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007949 wpa_s->p2p_go_csa_on_inv = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07007950 wpa_s->ignore_auth_resp = 0;
7951 wpa_s->ignore_assoc_disallow = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007952 wpa_s->testing_resend_assoc = 0;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07007953 wpa_s->reject_btm_req_reason = 0;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08007954 wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007955 os_free(wpa_s->get_pref_freq_list_override);
7956 wpa_s->get_pref_freq_list_override = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007957 wpabuf_free(wpa_s->sae_commit_override);
7958 wpa_s->sae_commit_override = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -07007959#ifdef CONFIG_DPP
7960 os_free(wpa_s->dpp_config_obj_override);
7961 wpa_s->dpp_config_obj_override = NULL;
7962 os_free(wpa_s->dpp_discovery_override);
7963 wpa_s->dpp_discovery_override = NULL;
7964 os_free(wpa_s->dpp_groups_override);
7965 wpa_s->dpp_groups_override = NULL;
7966 dpp_test = DPP_TEST_DISABLED;
7967#endif /* CONFIG_DPP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007968#endif /* CONFIG_TESTING_OPTIONS */
7969
7970 wpa_s->disconnected = 0;
7971 os_free(wpa_s->next_scan_freqs);
7972 wpa_s->next_scan_freqs = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07007973 os_free(wpa_s->select_network_scan_freqs);
7974 wpa_s->select_network_scan_freqs = NULL;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007975
7976 wpa_bss_flush(wpa_s);
7977 if (!dl_list_empty(&wpa_s->bss)) {
7978 wpa_printf(MSG_DEBUG,
7979 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7980 MACSTR " pending_bssid=" MACSTR,
7981 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
7982 MAC2STR(wpa_s->bssid),
7983 MAC2STR(wpa_s->pending_bssid));
7984 }
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07007985
7986 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
Dmitry Shmidtb70d0bb2015-11-16 10:43:06 -08007987 wpa_s->wnmsleep_used = 0;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07007988
7989#ifdef CONFIG_SME
7990 wpa_s->sme.last_unprot_disconnect.sec = 0;
7991#endif /* CONFIG_SME */
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08007992
7993 wpabuf_free(wpa_s->ric_ies);
7994 wpa_s->ric_ies = NULL;
Hai Shalom39bc25d2019-02-06 16:32:13 -08007995
7996 wpa_supplicant_update_channel_list(wpa_s, NULL);
7997
7998 free_bss_tmp_disallowed(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007999}
8000
8001
8002static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
8003 char *buf, size_t buflen)
8004{
8005 struct wpa_radio_work *work;
8006 char *pos, *end;
8007 struct os_reltime now, diff;
8008
8009 pos = buf;
8010 end = buf + buflen;
8011
8012 os_get_reltime(&now);
8013
8014 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8015 {
8016 int ret;
8017
8018 os_reltime_sub(&now, &work->time, &diff);
8019 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
8020 work->type, work->wpa_s->ifname, work->freq,
8021 work->started, diff.sec, diff.usec);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008022 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008023 break;
8024 pos += ret;
8025 }
8026
8027 return pos - buf;
8028}
8029
8030
8031static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
8032{
8033 struct wpa_radio_work *work = eloop_ctx;
8034 struct wpa_external_work *ework = work->ctx;
8035
8036 wpa_dbg(work->wpa_s, MSG_DEBUG,
8037 "Timing out external radio work %u (%s)",
8038 ework->id, work->type);
8039 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008040 work->wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008041 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008042 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008043}
8044
8045
8046static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
8047{
8048 struct wpa_external_work *ework = work->ctx;
8049
8050 if (deinit) {
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08008051 if (work->started)
8052 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8053 work, NULL);
8054
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008055 /*
8056 * work->type points to a buffer in ework, so need to replace
8057 * that here with a fixed string to avoid use of freed memory
8058 * in debug prints.
8059 */
8060 work->type = "freed-ext-work";
8061 work->ctx = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008062 os_free(ework);
8063 return;
8064 }
8065
8066 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
8067 ework->id, ework->type);
8068 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008069 work->wpa_s->ext_work_in_progress = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008070 if (!ework->timeout)
8071 ework->timeout = 10;
8072 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
8073 work, NULL);
8074}
8075
8076
8077static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
8078 char *buf, size_t buflen)
8079{
8080 struct wpa_external_work *ework;
8081 char *pos, *pos2;
8082 size_t type_len;
8083 int ret;
8084 unsigned int freq = 0;
8085
8086 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
8087
8088 ework = os_zalloc(sizeof(*ework));
8089 if (ework == NULL)
8090 return -1;
8091
8092 pos = os_strchr(cmd, ' ');
8093 if (pos) {
8094 type_len = pos - cmd;
8095 pos++;
8096
8097 pos2 = os_strstr(pos, "freq=");
8098 if (pos2)
8099 freq = atoi(pos2 + 5);
8100
8101 pos2 = os_strstr(pos, "timeout=");
8102 if (pos2)
8103 ework->timeout = atoi(pos2 + 8);
8104 } else {
8105 type_len = os_strlen(cmd);
8106 }
8107 if (4 + type_len >= sizeof(ework->type))
8108 type_len = sizeof(ework->type) - 4 - 1;
8109 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
8110 os_memcpy(ework->type + 4, cmd, type_len);
8111 ework->type[4 + type_len] = '\0';
8112
8113 wpa_s->ext_work_id++;
8114 if (wpa_s->ext_work_id == 0)
8115 wpa_s->ext_work_id++;
8116 ework->id = wpa_s->ext_work_id;
8117
8118 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
8119 ework) < 0) {
8120 os_free(ework);
8121 return -1;
8122 }
8123
8124 ret = os_snprintf(buf, buflen, "%u", ework->id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008125 if (os_snprintf_error(buflen, ret))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008126 return -1;
8127 return ret;
8128}
8129
8130
8131static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
8132{
8133 struct wpa_radio_work *work;
8134 unsigned int id = atoi(cmd);
8135
8136 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
8137 {
8138 struct wpa_external_work *ework;
8139
8140 if (os_strncmp(work->type, "ext:", 4) != 0)
8141 continue;
8142 ework = work->ctx;
8143 if (id && ework->id != id)
8144 continue;
8145 wpa_dbg(wpa_s, MSG_DEBUG,
8146 "Completed external radio work %u (%s)",
8147 ework->id, ework->type);
8148 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008149 wpa_s->ext_work_in_progress = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008150 radio_work_done(work);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07008151 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008152 return 3; /* "OK\n" */
8153 }
8154
8155 return -1;
8156}
8157
8158
8159static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
8160 char *buf, size_t buflen)
8161{
8162 if (os_strcmp(cmd, "show") == 0)
8163 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
8164 if (os_strncmp(cmd, "add ", 4) == 0)
8165 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
8166 if (os_strncmp(cmd, "done ", 5) == 0)
8167 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
8168 return -1;
8169}
8170
8171
8172void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
8173{
8174 struct wpa_radio_work *work, *tmp;
8175
Dmitry Shmidt18463232014-01-24 12:29:41 -08008176 if (!wpa_s || !wpa_s->radio)
8177 return;
8178
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008179 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
8180 struct wpa_radio_work, list) {
8181 struct wpa_external_work *ework;
8182
8183 if (os_strncmp(work->type, "ext:", 4) != 0)
8184 continue;
8185 ework = work->ctx;
8186 wpa_dbg(wpa_s, MSG_DEBUG,
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07008187 "Flushing%s external radio work %u (%s)",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008188 work->started ? " started" : "", ework->id,
8189 ework->type);
8190 if (work->started)
8191 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
8192 work, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008193 radio_work_done(work);
Dmitry Shmidt71757432014-06-02 13:50:35 -07008194 os_free(ework);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008195 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -07008196}
8197
8198
Dmitry Shmidt051af732013-10-22 13:52:46 -07008199static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
8200{
8201 struct wpa_supplicant *wpa_s = eloop_ctx;
8202 eapol_sm_notify_ctrl_response(wpa_s->eapol);
8203}
8204
8205
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008206static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
8207 unsigned int *scan_id_count, int scan_id[])
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008208{
8209 const char *pos = value;
8210
8211 while (pos) {
8212 if (*pos == ' ' || *pos == '\0')
8213 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008214 if (*scan_id_count == MAX_SCAN_ID)
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008215 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008216 scan_id[(*scan_id_count)++] = atoi(pos);
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008217 pos = os_strchr(pos, ',');
8218 if (pos)
8219 pos++;
8220 }
8221
8222 return 0;
8223}
8224
8225
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008226static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
8227 char *reply, int reply_size, int *reply_len)
8228{
8229 char *pos;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008230 unsigned int manual_scan_passive = 0;
8231 unsigned int manual_scan_use_id = 0;
8232 unsigned int manual_scan_only_new = 0;
8233 unsigned int scan_only = 0;
8234 unsigned int scan_id_count = 0;
8235 int scan_id[MAX_SCAN_ID];
8236 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
8237 struct wpa_scan_results *scan_res);
8238 int *manual_scan_freqs = NULL;
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008239 struct wpa_ssid_value *ssid = NULL, *ns;
8240 unsigned int ssid_count = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008241
8242 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
8243 *reply_len = -1;
8244 return;
8245 }
8246
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008247 if (radio_work_pending(wpa_s, "scan")) {
8248 wpa_printf(MSG_DEBUG,
8249 "Pending scan scheduled - reject new request");
8250 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8251 return;
8252 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008253
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008254#ifdef CONFIG_INTERWORKING
8255 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
8256 wpa_printf(MSG_DEBUG,
8257 "Interworking select in progress - reject new scan");
8258 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8259 return;
8260 }
8261#endif /* CONFIG_INTERWORKING */
8262
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008263 if (params) {
8264 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008265 scan_only = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008266
8267 pos = os_strstr(params, "freq=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008268 if (pos) {
8269 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
8270 pos + 5);
8271 if (manual_scan_freqs == NULL) {
8272 *reply_len = -1;
8273 goto done;
8274 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008275 }
8276
8277 pos = os_strstr(params, "passive=");
8278 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008279 manual_scan_passive = !!atoi(pos + 8);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008280
8281 pos = os_strstr(params, "use_id=");
8282 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008283 manual_scan_use_id = atoi(pos + 7);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008284
8285 pos = os_strstr(params, "only_new=1");
8286 if (pos)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008287 manual_scan_only_new = 1;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008288
8289 pos = os_strstr(params, "scan_id=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008290 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
8291 scan_id) < 0) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008292 *reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008293 goto done;
Dmitry Shmidtc2817022014-07-02 10:32:10 -07008294 }
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008295
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07008296 pos = os_strstr(params, "bssid=");
8297 if (pos) {
8298 u8 bssid[ETH_ALEN];
8299
8300 pos += 6;
8301 if (hwaddr_aton(pos, bssid)) {
8302 wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
8303 *reply_len = -1;
8304 goto done;
8305 }
8306 os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
8307 }
8308
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008309 pos = params;
8310 while (pos && *pos != '\0') {
8311 if (os_strncmp(pos, "ssid ", 5) == 0) {
8312 char *end;
8313
8314 pos += 5;
8315 end = pos;
8316 while (*end) {
8317 if (*end == '\0' || *end == ' ')
8318 break;
8319 end++;
8320 }
8321
8322 ns = os_realloc_array(
8323 ssid, ssid_count + 1,
8324 sizeof(struct wpa_ssid_value));
8325 if (ns == NULL) {
8326 *reply_len = -1;
8327 goto done;
8328 }
8329 ssid = ns;
8330
8331 if ((end - pos) & 0x01 ||
8332 end - pos > 2 * SSID_MAX_LEN ||
8333 hexstr2bin(pos, ssid[ssid_count].ssid,
8334 (end - pos) / 2) < 0) {
8335 wpa_printf(MSG_DEBUG,
8336 "Invalid SSID value '%s'",
8337 pos);
8338 *reply_len = -1;
8339 goto done;
8340 }
8341 ssid[ssid_count].ssid_len = (end - pos) / 2;
8342 wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
8343 ssid[ssid_count].ssid,
8344 ssid[ssid_count].ssid_len);
8345 ssid_count++;
8346 pos = end;
8347 }
8348
8349 pos = os_strchr(pos, ' ');
8350 if (pos)
8351 pos++;
8352 }
8353 }
8354
8355 wpa_s->num_ssids_from_scan_req = ssid_count;
8356 os_free(wpa_s->ssids_from_scan_req);
8357 if (ssid_count) {
8358 wpa_s->ssids_from_scan_req = ssid;
8359 ssid = NULL;
8360 } else {
8361 wpa_s->ssids_from_scan_req = NULL;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008362 }
8363
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008364 if (scan_only)
8365 scan_res_handler = scan_only_handler;
8366 else if (wpa_s->scan_res_handler == scan_only_handler)
8367 scan_res_handler = NULL;
8368 else
8369 scan_res_handler = wpa_s->scan_res_handler;
8370
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008371 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
8372 ((wpa_s->wpa_state <= WPA_SCANNING) ||
8373 (wpa_s->wpa_state == WPA_COMPLETED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008374 wpa_s->manual_scan_passive = manual_scan_passive;
8375 wpa_s->manual_scan_use_id = manual_scan_use_id;
8376 wpa_s->manual_scan_only_new = manual_scan_only_new;
8377 wpa_s->scan_id_count = scan_id_count;
8378 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8379 wpa_s->scan_res_handler = scan_res_handler;
8380 os_free(wpa_s->manual_scan_freqs);
8381 wpa_s->manual_scan_freqs = manual_scan_freqs;
8382 manual_scan_freqs = NULL;
8383
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008384 wpa_s->normal_scans = 0;
8385 wpa_s->scan_req = MANUAL_SCAN_REQ;
8386 wpa_s->after_wps = 0;
8387 wpa_s->known_wps_freq = 0;
8388 wpa_supplicant_req_scan(wpa_s, 0, 0);
8389 if (wpa_s->manual_scan_use_id) {
8390 wpa_s->manual_scan_id++;
8391 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8392 wpa_s->manual_scan_id);
8393 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8394 wpa_s->manual_scan_id);
8395 }
8396 } else if (wpa_s->sched_scanning) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008397 wpa_s->manual_scan_passive = manual_scan_passive;
8398 wpa_s->manual_scan_use_id = manual_scan_use_id;
8399 wpa_s->manual_scan_only_new = manual_scan_only_new;
8400 wpa_s->scan_id_count = scan_id_count;
8401 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
8402 wpa_s->scan_res_handler = scan_res_handler;
8403 os_free(wpa_s->manual_scan_freqs);
8404 wpa_s->manual_scan_freqs = manual_scan_freqs;
8405 manual_scan_freqs = NULL;
8406
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008407 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
8408 wpa_supplicant_cancel_sched_scan(wpa_s);
8409 wpa_s->scan_req = MANUAL_SCAN_REQ;
8410 wpa_supplicant_req_scan(wpa_s, 0, 0);
8411 if (wpa_s->manual_scan_use_id) {
8412 wpa_s->manual_scan_id++;
8413 *reply_len = os_snprintf(reply, reply_size, "%u\n",
8414 wpa_s->manual_scan_id);
8415 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
8416 wpa_s->manual_scan_id);
8417 }
8418 } else {
8419 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
8420 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
8421 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008422
8423done:
8424 os_free(manual_scan_freqs);
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07008425 os_free(ssid);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008426}
8427
8428
Dmitry Shmidt818ea482014-03-10 13:15:21 -07008429#ifdef CONFIG_TESTING_OPTIONS
8430
8431static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
8432 unsigned int freq, const u8 *dst,
8433 const u8 *src, const u8 *bssid,
8434 const u8 *data, size_t data_len,
8435 enum offchannel_send_action_result
8436 result)
8437{
8438 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
8439 " src=" MACSTR " bssid=" MACSTR " result=%s",
8440 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
8441 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
8442 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
8443 "NO_ACK" : "FAILED"));
8444}
8445
8446
8447static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
8448{
8449 char *pos, *param;
8450 size_t len;
8451 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
8452 int res, used;
8453 int freq = 0, no_cck = 0, wait_time = 0;
8454
8455 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
8456 * <action=Action frame payload> */
8457
8458 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
8459
8460 pos = cmd;
8461 used = hwaddr_aton2(pos, da);
8462 if (used < 0)
8463 return -1;
8464 pos += used;
8465 while (*pos == ' ')
8466 pos++;
8467 used = hwaddr_aton2(pos, bssid);
8468 if (used < 0)
8469 return -1;
8470 pos += used;
8471
8472 param = os_strstr(pos, " freq=");
8473 if (param) {
8474 param += 6;
8475 freq = atoi(param);
8476 }
8477
8478 param = os_strstr(pos, " no_cck=");
8479 if (param) {
8480 param += 8;
8481 no_cck = atoi(param);
8482 }
8483
8484 param = os_strstr(pos, " wait_time=");
8485 if (param) {
8486 param += 11;
8487 wait_time = atoi(param);
8488 }
8489
8490 param = os_strstr(pos, " action=");
8491 if (param == NULL)
8492 return -1;
8493 param += 8;
8494
8495 len = os_strlen(param);
8496 if (len & 1)
8497 return -1;
8498 len /= 2;
8499
8500 buf = os_malloc(len);
8501 if (buf == NULL)
8502 return -1;
8503
8504 if (hexstr2bin(param, buf, len) < 0) {
8505 os_free(buf);
8506 return -1;
8507 }
8508
8509 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
8510 buf, len, wait_time,
8511 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
8512 os_free(buf);
8513 return res;
8514}
8515
8516
8517static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
8518{
8519 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
8520 offchannel_send_action_done(wpa_s);
8521}
8522
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07008523
Dmitry Shmidt849734c2016-05-27 09:59:01 -07008524static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
8525 char *cmd)
8526{
8527 char *pos, *param;
8528 size_t len;
8529 u8 *buf;
8530 int freq = 0, datarate = 0, ssi_signal = 0;
8531 union wpa_event_data event;
8532
8533 if (!wpa_s->ext_mgmt_frame_handling)
8534 return -1;
8535
8536 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
8537
8538 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
8539
8540 pos = cmd;
8541 param = os_strstr(pos, "freq=");
8542 if (param) {
8543 param += 5;
8544 freq = atoi(param);
8545 }
8546
8547 param = os_strstr(pos, " datarate=");
8548 if (param) {
8549 param += 10;
8550 datarate = atoi(param);
8551 }
8552
8553 param = os_strstr(pos, " ssi_signal=");
8554 if (param) {
8555 param += 12;
8556 ssi_signal = atoi(param);
8557 }
8558
8559 param = os_strstr(pos, " frame=");
8560 if (param == NULL)
8561 return -1;
8562 param += 7;
8563
8564 len = os_strlen(param);
8565 if (len & 1)
8566 return -1;
8567 len /= 2;
8568
8569 buf = os_malloc(len);
8570 if (buf == NULL)
8571 return -1;
8572
8573 if (hexstr2bin(param, buf, len) < 0) {
8574 os_free(buf);
8575 return -1;
8576 }
8577
8578 os_memset(&event, 0, sizeof(event));
8579 event.rx_mgmt.freq = freq;
8580 event.rx_mgmt.frame = buf;
8581 event.rx_mgmt.frame_len = len;
8582 event.rx_mgmt.ssi_signal = ssi_signal;
8583 event.rx_mgmt.datarate = datarate;
8584 wpa_s->ext_mgmt_frame_handling = 0;
8585 wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
8586 wpa_s->ext_mgmt_frame_handling = 1;
8587
8588 os_free(buf);
8589
8590 return 0;
8591}
8592
8593
Paul Stewart092955c2017-02-06 09:13:09 -08008594static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
8595 char *param)
8596{
8597 struct wpa_scan_res *res;
8598 struct os_reltime now;
8599 char *pos, *end;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008600 int ret = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08008601
8602 if (!param)
8603 return -1;
8604
8605 if (os_strcmp(param, "START") == 0) {
8606 wpa_bss_update_start(wpa_s);
8607 return 0;
8608 }
8609
8610 if (os_strcmp(param, "END") == 0) {
8611 wpa_bss_update_end(wpa_s, NULL, 1);
8612 return 0;
8613 }
8614
8615 if (os_strncmp(param, "BSS ", 4) != 0)
8616 return -1;
8617 param += 3;
8618
8619 res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
8620 if (!res)
8621 return -1;
8622
8623 pos = os_strstr(param, " flags=");
8624 if (pos)
8625 res->flags = strtol(pos + 7, NULL, 16);
8626
8627 pos = os_strstr(param, " bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008628 if (pos && hwaddr_aton(pos + 7, res->bssid))
8629 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008630
8631 pos = os_strstr(param, " freq=");
8632 if (pos)
8633 res->freq = atoi(pos + 6);
8634
8635 pos = os_strstr(param, " beacon_int=");
8636 if (pos)
8637 res->beacon_int = atoi(pos + 12);
8638
8639 pos = os_strstr(param, " caps=");
8640 if (pos)
8641 res->caps = strtol(pos + 6, NULL, 16);
8642
8643 pos = os_strstr(param, " qual=");
8644 if (pos)
8645 res->qual = atoi(pos + 6);
8646
8647 pos = os_strstr(param, " noise=");
8648 if (pos)
8649 res->noise = atoi(pos + 7);
8650
8651 pos = os_strstr(param, " level=");
8652 if (pos)
8653 res->level = atoi(pos + 7);
8654
8655 pos = os_strstr(param, " tsf=");
8656 if (pos)
8657 res->tsf = strtoll(pos + 5, NULL, 16);
8658
8659 pos = os_strstr(param, " age=");
8660 if (pos)
8661 res->age = atoi(pos + 5);
8662
8663 pos = os_strstr(param, " est_throughput=");
8664 if (pos)
8665 res->est_throughput = atoi(pos + 16);
8666
8667 pos = os_strstr(param, " snr=");
8668 if (pos)
8669 res->snr = atoi(pos + 5);
8670
8671 pos = os_strstr(param, " parent_tsf=");
8672 if (pos)
8673 res->parent_tsf = strtoll(pos + 7, NULL, 16);
8674
8675 pos = os_strstr(param, " tsf_bssid=");
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008676 if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
8677 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008678
8679 pos = os_strstr(param, " ie=");
8680 if (pos) {
8681 pos += 4;
8682 end = os_strchr(pos, ' ');
8683 if (!end)
8684 end = pos + os_strlen(pos);
8685 res->ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008686 if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
8687 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008688 }
8689
8690 pos = os_strstr(param, " beacon_ie=");
8691 if (pos) {
8692 pos += 11;
8693 end = os_strchr(pos, ' ');
8694 if (!end)
8695 end = pos + os_strlen(pos);
8696 res->beacon_ie_len = (end - pos) / 2;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008697 if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
8698 res->beacon_ie_len))
8699 goto fail;
Paul Stewart092955c2017-02-06 09:13:09 -08008700 }
8701
8702 os_get_reltime(&now);
8703 wpa_bss_update_scan_res(wpa_s, res, &now);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008704 ret = 0;
8705fail:
Paul Stewart092955c2017-02-06 09:13:09 -08008706 os_free(res);
8707
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08008708 return ret;
Paul Stewart092955c2017-02-06 09:13:09 -08008709}
8710
8711
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07008712static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
8713{
8714 char *pos, *param;
8715 union wpa_event_data event;
8716 enum wpa_event_type ev;
8717
8718 /* <event name> [parameters..] */
8719
8720 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
8721
8722 pos = cmd;
8723 param = os_strchr(pos, ' ');
8724 if (param)
8725 *param++ = '\0';
8726
8727 os_memset(&event, 0, sizeof(event));
8728
8729 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
8730 ev = EVENT_INTERFACE_ENABLED;
8731 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
8732 ev = EVENT_INTERFACE_DISABLED;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07008733 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
8734 ev = EVENT_AVOID_FREQUENCIES;
8735 if (param == NULL)
8736 param = "";
8737 if (freq_range_list_parse(&event.freq_range, param) < 0)
8738 return -1;
8739 wpa_supplicant_event(wpa_s, ev, &event);
8740 os_free(event.freq_range.range);
8741 return 0;
Paul Stewart092955c2017-02-06 09:13:09 -08008742 } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
8743 return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07008744 } else {
8745 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
8746 cmd);
8747 return -1;
8748 }
8749
8750 wpa_supplicant_event(wpa_s, ev, &event);
8751
8752 return 0;
8753}
8754
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008755
8756static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
8757{
8758 char *pos;
8759 u8 src[ETH_ALEN], *buf;
8760 int used;
8761 size_t len;
8762
8763 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
8764
8765 pos = cmd;
8766 used = hwaddr_aton2(pos, src);
8767 if (used < 0)
8768 return -1;
8769 pos += used;
8770 while (*pos == ' ')
8771 pos++;
8772
8773 len = os_strlen(pos);
8774 if (len & 1)
8775 return -1;
8776 len /= 2;
8777
8778 buf = os_malloc(len);
8779 if (buf == NULL)
8780 return -1;
8781
8782 if (hexstr2bin(pos, buf, len) < 0) {
8783 os_free(buf);
8784 return -1;
8785 }
8786
8787 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
8788 os_free(buf);
8789
8790 return 0;
8791}
8792
8793
8794static u16 ipv4_hdr_checksum(const void *buf, size_t len)
8795{
8796 size_t i;
8797 u32 sum = 0;
8798 const u16 *pos = buf;
8799
8800 for (i = 0; i < len / 2; i++)
8801 sum += *pos++;
8802
8803 while (sum >> 16)
8804 sum = (sum & 0xffff) + (sum >> 16);
8805
8806 return sum ^ 0xffff;
8807}
8808
8809
8810#define HWSIM_PACKETLEN 1500
8811#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8812
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07008813static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
8814 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008815{
8816 struct wpa_supplicant *wpa_s = ctx;
8817 const struct ether_header *eth;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008818 struct iphdr ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008819 const u8 *pos;
8820 unsigned int i;
Hai Shalom39bc25d2019-02-06 16:32:13 -08008821 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008822
Hai Shalom39bc25d2019-02-06 16:32:13 -08008823 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
8824 wpa_printf(MSG_DEBUG,
8825 "test data: RX - ignore unexpected length %d",
8826 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008827 return;
Hai Shalom39bc25d2019-02-06 16:32:13 -08008828 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008829
8830 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008831 os_memcpy(&ip, eth + 1, sizeof(ip));
8832 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008833
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008834 if (ip.ihl != 5 || ip.version != 4 ||
Hai Shalom39bc25d2019-02-06 16:32:13 -08008835 ntohs(ip.tot_len) > HWSIM_IP_LEN) {
8836 wpa_printf(MSG_DEBUG,
8837 "test data: RX - ignore unexpect IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008838 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008839 }
8840
Hai Shalom39bc25d2019-02-06 16:32:13 -08008841 for (i = 0; i < ntohs(ip.tot_len) - sizeof(ip); i++) {
8842 if (*pos != (u8) i) {
8843 wpa_printf(MSG_DEBUG,
8844 "test data: RX - ignore mismatching payload");
8845 return;
8846 }
8847 pos++;
8848 }
8849 extra[0] = '\0';
8850 if (ntohs(ip.tot_len) != HWSIM_IP_LEN)
8851 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.tot_len));
8852 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
8853 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008854}
8855
8856
8857static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
8858 char *cmd)
8859{
8860 int enabled = atoi(cmd);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008861 char *pos;
8862 const char *ifname;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008863
8864 if (!enabled) {
8865 if (wpa_s->l2_test) {
8866 l2_packet_deinit(wpa_s->l2_test);
8867 wpa_s->l2_test = NULL;
8868 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
8869 }
8870 return 0;
8871 }
8872
8873 if (wpa_s->l2_test)
8874 return 0;
8875
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08008876 pos = os_strstr(cmd, " ifname=");
8877 if (pos)
8878 ifname = pos + 8;
8879 else
8880 ifname = wpa_s->ifname;
8881
8882 wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008883 ETHERTYPE_IP, wpas_data_test_rx,
8884 wpa_s, 1);
8885 if (wpa_s->l2_test == NULL)
8886 return -1;
8887
8888 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
8889
8890 return 0;
8891}
8892
8893
8894static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
8895{
8896 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom39bc25d2019-02-06 16:32:13 -08008897 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008898 int used;
8899 long int val;
8900 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008901 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008902 struct ether_header *eth;
8903 struct iphdr *ip;
8904 u8 *dpos;
8905 unsigned int i;
Hai Shalom39bc25d2019-02-06 16:32:13 -08008906 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008907
8908 if (wpa_s->l2_test == NULL)
8909 return -1;
8910
Hai Shalom39bc25d2019-02-06 16:32:13 -08008911 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008912
8913 pos = cmd;
8914 used = hwaddr_aton2(pos, dst);
8915 if (used < 0)
8916 return -1;
8917 pos += used;
8918 while (*pos == ' ')
8919 pos++;
8920 used = hwaddr_aton2(pos, src);
8921 if (used < 0)
8922 return -1;
8923 pos += used;
8924
Hai Shalom39bc25d2019-02-06 16:32:13 -08008925 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008926 if (val < 0 || val > 0xff)
8927 return -1;
8928 tos = val;
8929
Hai Shalom39bc25d2019-02-06 16:32:13 -08008930 pos = os_strstr(pos2, " len=");
8931 if (pos) {
8932 i = atoi(pos + 5);
8933 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
8934 return -1;
8935 send_len = i;
8936 }
8937
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008938 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008939 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
8940 os_memcpy(eth->ether_shost, src, ETH_ALEN);
8941 eth->ether_type = htons(ETHERTYPE_IP);
8942 ip = (struct iphdr *) (eth + 1);
8943 os_memset(ip, 0, sizeof(*ip));
8944 ip->ihl = 5;
8945 ip->version = 4;
8946 ip->ttl = 64;
8947 ip->tos = tos;
Hai Shalom39bc25d2019-02-06 16:32:13 -08008948 ip->tot_len = htons(send_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008949 ip->protocol = 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008950 ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8951 ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008952 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
8953 dpos = (u8 *) (ip + 1);
Hai Shalom39bc25d2019-02-06 16:32:13 -08008954 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008955 *dpos++ = i;
8956
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008957 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom39bc25d2019-02-06 16:32:13 -08008958 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008959 return -1;
8960
8961 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
8962 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
8963
8964 return 0;
8965}
8966
8967
8968static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
8969 char *cmd)
8970{
8971 u8 *buf;
8972 struct ether_header *eth;
8973 struct l2_packet_data *l2 = NULL;
8974 size_t len;
8975 u16 ethertype;
8976 int res = -1;
8977
8978 len = os_strlen(cmd);
8979 if (len & 1 || len < ETH_HLEN * 2)
8980 return -1;
8981 len /= 2;
8982
8983 buf = os_malloc(len);
8984 if (buf == NULL)
8985 return -1;
8986
8987 if (hexstr2bin(cmd, buf, len) < 0)
8988 goto done;
8989
8990 eth = (struct ether_header *) buf;
8991 ethertype = ntohs(eth->ether_type);
8992
8993 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
8994 wpas_data_test_rx, wpa_s, 1);
8995 if (l2 == NULL)
8996 goto done;
8997
8998 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
8999 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
9000done:
9001 if (l2)
9002 l2_packet_deinit(l2);
9003 os_free(buf);
9004
9005 return res < 0 ? -1 : 0;
9006}
9007
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009008
9009static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
9010{
9011#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009012 char *pos;
9013
9014 wpa_trace_fail_after = atoi(cmd);
9015 pos = os_strchr(cmd, ':');
9016 if (pos) {
9017 pos++;
9018 os_strlcpy(wpa_trace_fail_func, pos,
9019 sizeof(wpa_trace_fail_func));
9020 } else {
9021 wpa_trace_fail_after = 0;
9022 }
9023 return 0;
9024#else /* WPA_TRACE_BFD */
9025 return -1;
9026#endif /* WPA_TRACE_BFD */
9027}
9028
9029
9030static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
9031 char *buf, size_t buflen)
9032{
9033#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08009034 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
9035 wpa_trace_fail_func);
9036#else /* WPA_TRACE_BFD */
9037 return -1;
9038#endif /* WPA_TRACE_BFD */
9039}
9040
Jouni Malinenc4818362015-10-04 11:45:13 +03009041
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009042static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
9043{
9044#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009045 char *pos;
9046
9047 wpa_trace_test_fail_after = atoi(cmd);
9048 pos = os_strchr(cmd, ':');
9049 if (pos) {
9050 pos++;
9051 os_strlcpy(wpa_trace_test_fail_func, pos,
9052 sizeof(wpa_trace_test_fail_func));
9053 } else {
9054 wpa_trace_test_fail_after = 0;
9055 }
9056 return 0;
9057#else /* WPA_TRACE_BFD */
9058 return -1;
9059#endif /* WPA_TRACE_BFD */
9060}
9061
9062
9063static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
9064 char *buf, size_t buflen)
9065{
9066#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009067 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
9068 wpa_trace_test_fail_func);
9069#else /* WPA_TRACE_BFD */
9070 return -1;
9071#endif /* WPA_TRACE_BFD */
9072}
9073
9074
Jouni Malinenc4818362015-10-04 11:45:13 +03009075static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
9076{
9077 struct wpa_supplicant *wpa_s = eloop_ctx;
9078 int i, count = (intptr_t) timeout_ctx;
9079
9080 wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
9081 count);
9082 for (i = 0; i < count; i++) {
9083 wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
9084 i + 1, count);
9085 }
9086}
9087
9088
9089static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
9090{
9091 int count;
9092
9093 count = atoi(cmd);
9094 if (count <= 0)
9095 return -1;
9096
9097 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
9098 (void *) (intptr_t) count);
9099}
9100
Dmitry Shmidt818ea482014-03-10 13:15:21 -07009101
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009102static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
9103 const char *cmd)
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009104{
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009105 struct wpabuf *buf;
9106 size_t len;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009107
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009108 len = os_strlen(cmd);
9109 if (len & 1)
9110 return -1;
9111 len /= 2;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009112
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009113 if (len == 0) {
9114 buf = NULL;
9115 } else {
9116 buf = wpabuf_alloc(len);
9117 if (buf == NULL)
9118 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009119
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009120 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
9121 wpabuf_free(buf);
9122 return -1;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009123 }
9124 }
9125
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009126 wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
9127 return 0;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009128}
9129
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009130
9131static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
9132{
9133 u8 zero[WPA_TK_MAX_LEN];
9134
9135 if (wpa_s->last_tk_alg == WPA_ALG_NONE)
9136 return -1;
9137
9138 wpa_printf(MSG_INFO, "TESTING: Reset PN");
9139 os_memset(zero, 0, sizeof(zero));
9140
9141 /* First, use a zero key to avoid any possible duplicate key avoidance
9142 * in the driver. */
9143 if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9144 wpa_s->last_tk_key_idx, 1, zero, 6,
9145 zero, wpa_s->last_tk_len) < 0)
9146 return -1;
9147
9148 /* Set the previously configured key to reset its TSC/RSC */
9149 return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
9150 wpa_s->last_tk_key_idx, 1, zero, 6,
9151 wpa_s->last_tk, wpa_s->last_tk_len);
9152}
9153
9154
9155static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
9156{
9157 const char *pos = cmd;
9158 int error, pairwise;
9159
9160 error = atoi(pos);
9161 pos = os_strchr(pos, ' ');
9162 if (!pos)
9163 return -1;
9164 pairwise = atoi(pos);
9165 wpa_sm_key_request(wpa_s->wpa, error, pairwise);
9166 return 0;
9167}
9168
9169
9170static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
9171{
9172#ifdef CONFIG_SME
9173 struct wpa_driver_associate_params params;
9174 int ret;
9175
9176 os_memset(&params, 0, sizeof(params));
9177 params.bssid = wpa_s->bssid;
9178 params.ssid = wpa_s->sme.ssid;
9179 params.ssid_len = wpa_s->sme.ssid_len;
9180 params.freq.freq = wpa_s->sme.freq;
9181 if (wpa_s->last_assoc_req_wpa_ie) {
9182 params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
9183 params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
9184 }
9185 params.pairwise_suite = wpa_s->pairwise_cipher;
9186 params.group_suite = wpa_s->group_cipher;
9187 params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
9188 params.key_mgmt_suite = wpa_s->key_mgmt;
9189 params.wpa_proto = wpa_s->wpa_proto;
9190 params.mgmt_frame_protection = wpa_s->sme.mfp;
9191 params.rrm_used = wpa_s->rrm.rrm_used;
9192 if (wpa_s->sme.prev_bssid_set)
9193 params.prev_bssid = wpa_s->sme.prev_bssid;
9194 wpa_printf(MSG_INFO, "TESTING: Resend association request");
9195 ret = wpa_drv_associate(wpa_s, &params);
9196 wpa_s->testing_resend_assoc = 1;
9197 return ret;
9198#else /* CONFIG_SME */
9199 return -1;
9200#endif /* CONFIG_SME */
9201}
9202
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009203#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009204
9205
9206static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
9207{
9208 char *pos = cmd;
9209 int frame;
9210 size_t len;
9211 struct wpabuf *buf;
9212 struct ieee802_11_elems elems;
9213
9214 frame = atoi(pos);
9215 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9216 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009217 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009218
9219 pos = os_strchr(pos, ' ');
9220 if (pos == NULL)
9221 return -1;
9222 pos++;
9223
9224 len = os_strlen(pos);
9225 if (len == 0)
9226 return 0;
9227 if (len & 1)
9228 return -1;
9229 len /= 2;
9230
9231 buf = wpabuf_alloc(len);
9232 if (buf == NULL)
9233 return -1;
9234
9235 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
9236 wpabuf_free(buf);
9237 return -1;
9238 }
9239
9240 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
9241 ParseFailed) {
9242 wpabuf_free(buf);
9243 return -1;
9244 }
9245
9246 if (wpa_s->vendor_elem[frame] == NULL) {
9247 wpa_s->vendor_elem[frame] = buf;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009248 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009249 return 0;
9250 }
9251
9252 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
9253 wpabuf_free(buf);
9254 return -1;
9255 }
9256
9257 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
9258 wpabuf_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009259 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009260
9261 return 0;
9262}
9263
9264
9265static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
9266 char *buf, size_t buflen)
9267{
9268 int frame = atoi(cmd);
9269
9270 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9271 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009272 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009273
9274 if (wpa_s->vendor_elem[frame] == NULL)
9275 return 0;
9276
9277 return wpa_snprintf_hex(buf, buflen,
9278 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
9279 wpabuf_len(wpa_s->vendor_elem[frame]));
9280}
9281
9282
9283static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
9284{
9285 char *pos = cmd;
9286 int frame;
9287 size_t len;
9288 u8 *buf;
9289 struct ieee802_11_elems elems;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009290 int res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009291
9292 frame = atoi(pos);
9293 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
9294 return -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009295 wpa_s = wpas_vendor_elem(wpa_s, frame);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009296
9297 pos = os_strchr(pos, ' ');
9298 if (pos == NULL)
9299 return -1;
9300 pos++;
9301
9302 if (*pos == '*') {
9303 wpabuf_free(wpa_s->vendor_elem[frame]);
9304 wpa_s->vendor_elem[frame] = NULL;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009305 wpas_vendor_elem_update(wpa_s);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009306 return 0;
9307 }
9308
9309 if (wpa_s->vendor_elem[frame] == NULL)
9310 return -1;
9311
9312 len = os_strlen(pos);
9313 if (len == 0)
9314 return 0;
9315 if (len & 1)
9316 return -1;
9317 len /= 2;
9318
9319 buf = os_malloc(len);
9320 if (buf == NULL)
9321 return -1;
9322
9323 if (hexstr2bin(pos, buf, len) < 0) {
9324 os_free(buf);
9325 return -1;
9326 }
9327
9328 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
9329 os_free(buf);
9330 return -1;
9331 }
9332
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009333 res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009334 os_free(buf);
Dmitry Shmidt55840ad2015-12-14 12:45:46 -08009335 return res;
Dmitry Shmidt2e67f062014-07-16 09:55:28 -07009336}
9337
9338
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009339static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
9340{
9341 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009342 size_t len;
9343 const u8 *data;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009344
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009345 /*
9346 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
9347 * BSSID[6]
9348 * BSSID Information[4]
9349 * Operating Class[1]
9350 * Channel Number[1]
9351 * PHY Type[1]
9352 * Optional Subelements[variable]
9353 */
9354#define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
9355
9356 if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009357 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009358 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009359 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009360
9361 data = wpabuf_head_u8(neighbor_rep);
9362 len = wpabuf_len(neighbor_rep);
9363
9364 while (len >= 2 + NR_IE_MIN_LEN) {
9365 const u8 *nr;
9366 char lci[256 * 2 + 1];
9367 char civic[256 * 2 + 1];
9368 u8 nr_len = data[1];
9369 const u8 *pos = data, *end;
9370
9371 if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
9372 nr_len < NR_IE_MIN_LEN) {
9373 wpa_printf(MSG_DEBUG,
9374 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
9375 data[0], nr_len);
9376 goto out;
9377 }
9378
9379 if (2U + nr_len > len) {
9380 wpa_printf(MSG_DEBUG,
9381 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
9382 data[0], len, nr_len);
9383 goto out;
9384 }
9385 pos += 2;
9386 end = pos + nr_len;
9387
9388 nr = pos;
9389 pos += NR_IE_MIN_LEN;
9390
9391 lci[0] = '\0';
9392 civic[0] = '\0';
9393 while (end - pos > 2) {
9394 u8 s_id, s_len;
9395
9396 s_id = *pos++;
9397 s_len = *pos++;
9398 if (s_len > end - pos)
9399 goto out;
9400 if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
9401 /* Measurement Token[1] */
9402 /* Measurement Report Mode[1] */
9403 /* Measurement Type[1] */
9404 /* Measurement Report[variable] */
9405 switch (pos[2]) {
9406 case MEASURE_TYPE_LCI:
9407 if (lci[0])
9408 break;
9409 wpa_snprintf_hex(lci, sizeof(lci),
9410 pos, s_len);
9411 break;
9412 case MEASURE_TYPE_LOCATION_CIVIC:
9413 if (civic[0])
9414 break;
9415 wpa_snprintf_hex(civic, sizeof(civic),
9416 pos, s_len);
9417 break;
9418 }
9419 }
9420
9421 pos += s_len;
9422 }
9423
9424 wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
9425 "bssid=" MACSTR
9426 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
9427 MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
9428 nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
9429 nr[ETH_ALEN + 6],
9430 lci[0] ? " lci=" : "", lci,
9431 civic[0] ? " civic=" : "", civic);
9432
9433 data = end;
9434 len -= 2 + nr_len;
9435 }
9436
9437out:
9438 wpabuf_free(neighbor_rep);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009439}
9440
9441
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009442static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
9443 char *cmd)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009444{
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009445 struct wpa_ssid_value ssid, *ssid_p = NULL;
9446 int ret, lci = 0, civic = 0;
9447 char *ssid_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009448
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009449 ssid_s = os_strstr(cmd, "ssid=");
9450 if (ssid_s) {
9451 if (ssid_parse(ssid_s + 5, &ssid)) {
9452 wpa_printf(MSG_ERROR,
9453 "CTRL: Send Neighbor Report: bad SSID");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009454 return -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009455 }
9456
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009457 ssid_p = &ssid;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009458
9459 /*
9460 * Move cmd after the SSID text that may include "lci" or
9461 * "civic".
9462 */
9463 cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
9464 if (cmd)
9465 cmd++;
9466
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009467 }
9468
Dmitry Shmidt849734c2016-05-27 09:59:01 -07009469 if (cmd && os_strstr(cmd, "lci"))
9470 lci = 1;
9471
9472 if (cmd && os_strstr(cmd, "civic"))
9473 civic = 1;
9474
9475 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009476 wpas_ctrl_neighbor_rep_cb,
9477 wpa_s);
9478
9479 return ret;
9480}
9481
9482
9483static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
9484{
9485 eapol_sm_erp_flush(wpa_s->eapol);
9486 return 0;
9487}
9488
9489
9490static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
9491 char *cmd)
9492{
9493 char *token, *context = NULL;
9494 unsigned int enable = ~0, type = 0;
9495 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
9496 u8 *addr = NULL, *mask = NULL;
9497
9498 while ((token = str_token(cmd, " ", &context))) {
9499 if (os_strcasecmp(token, "scan") == 0) {
9500 type |= MAC_ADDR_RAND_SCAN;
9501 } else if (os_strcasecmp(token, "sched") == 0) {
9502 type |= MAC_ADDR_RAND_SCHED_SCAN;
9503 } else if (os_strcasecmp(token, "pno") == 0) {
9504 type |= MAC_ADDR_RAND_PNO;
9505 } else if (os_strcasecmp(token, "all") == 0) {
9506 type = wpa_s->mac_addr_rand_supported;
9507 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
9508 enable = atoi(token + 7);
9509 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
9510 addr = _addr;
9511 if (hwaddr_aton(token + 5, addr)) {
9512 wpa_printf(MSG_INFO,
9513 "CTRL: Invalid MAC address: %s",
9514 token);
9515 return -1;
9516 }
9517 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
9518 mask = _mask;
9519 if (hwaddr_aton(token + 5, mask)) {
9520 wpa_printf(MSG_INFO,
9521 "CTRL: Invalid MAC address mask: %s",
9522 token);
9523 return -1;
9524 }
9525 } else {
9526 wpa_printf(MSG_INFO,
9527 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
9528 token);
9529 return -1;
9530 }
9531 }
9532
9533 if (!type) {
9534 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
9535 return -1;
9536 }
9537
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009538 if (enable > 1) {
9539 wpa_printf(MSG_INFO,
9540 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
9541 return -1;
9542 }
9543
9544 if (!enable) {
9545 wpas_mac_addr_rand_scan_clear(wpa_s, type);
9546 if (wpa_s->pno) {
9547 if (type & MAC_ADDR_RAND_PNO) {
9548 wpas_stop_pno(wpa_s);
9549 wpas_start_pno(wpa_s);
9550 }
9551 } else if (wpa_s->sched_scanning &&
9552 (type & MAC_ADDR_RAND_SCHED_SCAN)) {
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07009553 wpas_scan_restart_sched_scan(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009554 }
9555 return 0;
9556 }
9557
9558 if ((addr && !mask) || (!addr && mask)) {
9559 wpa_printf(MSG_INFO,
9560 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
9561 return -1;
9562 }
9563
9564 if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) {
9565 wpa_printf(MSG_INFO,
9566 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
9567 return -1;
9568 }
9569
9570 if (type & MAC_ADDR_RAND_SCAN) {
Hai Shalom39bc25d2019-02-06 16:32:13 -08009571 if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
9572 addr, mask))
9573 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009574 }
9575
9576 if (type & MAC_ADDR_RAND_SCHED_SCAN) {
Hai Shalom39bc25d2019-02-06 16:32:13 -08009577 if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
9578 addr, mask))
9579 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009580
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07009581 if (wpa_s->sched_scanning && !wpa_s->pno)
9582 wpas_scan_restart_sched_scan(wpa_s);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009583 }
9584
9585 if (type & MAC_ADDR_RAND_PNO) {
Hai Shalom39bc25d2019-02-06 16:32:13 -08009586 if (wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
9587 addr, mask))
9588 return -1;
9589
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009590 if (wpa_s->pno) {
9591 wpas_stop_pno(wpa_s);
9592 wpas_start_pno(wpa_s);
9593 }
9594 }
9595
9596 return 0;
9597}
9598
9599
Dmitry Shmidte4663042016-04-04 10:07:49 -07009600static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
9601 char *buf, size_t buflen)
9602{
9603 size_t reply_len;
9604
9605 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
9606#ifdef CONFIG_AP
9607 reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
9608 buflen - reply_len);
9609#endif /* CONFIG_AP */
9610 return reply_len;
9611}
9612
9613
9614static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
9615{
9616 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
9617#ifdef CONFIG_AP
9618 wpas_ap_pmksa_cache_flush(wpa_s);
9619#endif /* CONFIG_AP */
9620}
9621
9622
Dmitry Shmidt29333592017-01-09 12:27:11 -08009623#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9624
9625static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
9626 const char *cmd, char *buf, size_t buflen)
9627{
9628 struct rsn_pmksa_cache_entry *entry;
9629 struct wpa_ssid *ssid;
9630 char *pos, *pos2, *end;
9631 int ret;
9632 struct os_reltime now;
9633
9634 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
9635 if (!ssid)
9636 return -1;
9637
9638 pos = buf;
9639 end = buf + buflen;
9640
9641 os_get_reltime(&now);
9642
9643 /*
9644 * Entry format:
9645 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9646 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009647 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -08009648 */
9649
9650 for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
9651 entry = entry->next) {
9652 if (entry->network_ctx != ssid)
9653 continue;
9654
9655 pos2 = pos;
9656 ret = os_snprintf(pos2, end - pos2, MACSTR " ",
9657 MAC2STR(entry->aa));
9658 if (os_snprintf_error(end - pos2, ret))
9659 break;
9660 pos2 += ret;
9661
9662 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
9663 PMKID_LEN);
9664
9665 ret = os_snprintf(pos2, end - pos2, " ");
9666 if (os_snprintf_error(end - pos2, ret))
9667 break;
9668 pos2 += ret;
9669
9670 pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
9671 entry->pmk_len);
9672
9673 ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
9674 (int) (entry->reauth_time - now.sec),
9675 (int) (entry->expiration - now.sec),
9676 entry->akmp,
9677 entry->opportunistic);
9678 if (os_snprintf_error(end - pos2, ret))
9679 break;
9680 pos2 += ret;
9681
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009682 if (entry->fils_cache_id_set) {
9683 ret = os_snprintf(pos2, end - pos2, " %02x%02x",
9684 entry->fils_cache_id[0],
9685 entry->fils_cache_id[1]);
9686 if (os_snprintf_error(end - pos2, ret))
9687 break;
9688 pos2 += ret;
9689 }
9690
Dmitry Shmidt29333592017-01-09 12:27:11 -08009691 ret = os_snprintf(pos2, end - pos2, "\n");
9692 if (os_snprintf_error(end - pos2, ret))
9693 break;
9694 pos2 += ret;
9695
9696 pos = pos2;
9697 }
9698
9699 return pos - buf;
9700}
9701
9702
9703static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
9704 char *cmd)
9705{
9706 struct rsn_pmksa_cache_entry *entry;
9707 struct wpa_ssid *ssid;
9708 char *pos, *pos2;
9709 int ret = -1;
9710 struct os_reltime now;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009711 int reauth_time = 0, expiration = 0, i;
Dmitry Shmidt29333592017-01-09 12:27:11 -08009712
9713 /*
9714 * Entry format:
9715 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9716 * <expiration in seconds> <akmp> <opportunistic>
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009717 * [FILS Cache Identifier]
Dmitry Shmidt29333592017-01-09 12:27:11 -08009718 */
9719
9720 ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
9721 if (!ssid)
9722 return -1;
9723
9724 pos = os_strchr(cmd, ' ');
9725 if (!pos)
9726 return -1;
9727 pos++;
9728
9729 entry = os_zalloc(sizeof(*entry));
9730 if (!entry)
9731 return -1;
9732
9733 if (hwaddr_aton(pos, entry->aa))
9734 goto fail;
9735
9736 pos = os_strchr(pos, ' ');
9737 if (!pos)
9738 goto fail;
9739 pos++;
9740
9741 if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
9742 goto fail;
9743
9744 pos = os_strchr(pos, ' ');
9745 if (!pos)
9746 goto fail;
9747 pos++;
9748
9749 pos2 = os_strchr(pos, ' ');
9750 if (!pos2)
9751 goto fail;
9752 entry->pmk_len = (pos2 - pos) / 2;
9753 if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
9754 hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
9755 goto fail;
9756
9757 pos = os_strchr(pos, ' ');
9758 if (!pos)
9759 goto fail;
9760 pos++;
9761
9762 if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
9763 &entry->akmp, &entry->opportunistic) != 4)
9764 goto fail;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009765 for (i = 0; i < 4; i++) {
9766 pos = os_strchr(pos, ' ');
9767 if (!pos) {
9768 if (i < 3)
9769 goto fail;
9770 break;
9771 }
9772 pos++;
9773 }
9774 if (pos) {
9775 if (hexstr2bin(pos, entry->fils_cache_id,
9776 FILS_CACHE_ID_LEN) < 0)
9777 goto fail;
9778 entry->fils_cache_id_set = 1;
9779 }
Dmitry Shmidt29333592017-01-09 12:27:11 -08009780 os_get_reltime(&now);
9781 entry->expiration = now.sec + expiration;
9782 entry->reauth_time = now.sec + reauth_time;
9783
9784 entry->network_ctx = ssid;
9785
9786 wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
9787 entry = NULL;
9788 ret = 0;
9789fail:
9790 os_free(entry);
9791 return ret;
9792}
9793
Paul Stewart092955c2017-02-06 09:13:09 -08009794
9795#ifdef CONFIG_MESH
9796
9797static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
9798 const char *cmd, char *buf,
9799 size_t buflen)
9800{
9801 u8 spa[ETH_ALEN];
9802
9803 if (!wpa_s->ifmsh)
9804 return -1;
9805
9806 if (os_strcasecmp(cmd, "any") == 0)
9807 return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
9808
9809 if (hwaddr_aton(cmd, spa))
9810 return -1;
9811
9812 return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
9813}
9814
9815
9816static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
9817 char *cmd)
9818{
9819 /*
9820 * We do not check mesh interface existance because PMKSA should be
9821 * stored before wpa_s->ifmsh creation to suppress commit message
9822 * creation.
9823 */
9824 return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
9825}
9826
9827#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -08009828#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9829
9830
Paul Stewart092955c2017-02-06 09:13:09 -08009831#ifdef CONFIG_FILS
9832static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
9833 const char *cmd)
9834{
9835 struct fils_hlp_req *req;
9836 const char *pos;
9837
9838 /* format: <dst> <packet starting from ethertype> */
9839
9840 req = os_zalloc(sizeof(*req));
9841 if (!req)
9842 return -1;
9843
9844 if (hwaddr_aton(cmd, req->dst))
9845 goto fail;
9846
9847 pos = os_strchr(cmd, ' ');
9848 if (!pos)
9849 goto fail;
9850 pos++;
9851 req->pkt = wpabuf_parse_bin(pos);
9852 if (!req->pkt)
9853 goto fail;
9854
9855 dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
9856 return 0;
9857fail:
9858 wpabuf_free(req->pkt);
9859 os_free(req);
9860 return -1;
9861}
9862#endif /* CONFIG_FILS */
9863
9864
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009865static int wpas_ctrl_cmd_debug_level(const char *cmd)
9866{
9867 if (os_strcmp(cmd, "PING") == 0 ||
9868 os_strncmp(cmd, "BSS ", 4) == 0 ||
9869 os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
9870 os_strncmp(cmd, "STATUS", 6) == 0 ||
9871 os_strncmp(cmd, "STA ", 4) == 0 ||
9872 os_strncmp(cmd, "STA-", 4) == 0)
9873 return MSG_EXCESSIVE;
9874 return MSG_DEBUG;
9875}
9876
9877
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009878char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
9879 char *buf, size_t *resp_len)
9880{
9881 char *reply;
9882 const int reply_size = 4096;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009883 int reply_len;
9884
9885 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009886 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
9887 os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
9888 os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009889 if (wpa_debug_show_keys)
9890 wpa_dbg(wpa_s, MSG_DEBUG,
9891 "Control interface command '%s'", buf);
9892 else
9893 wpa_dbg(wpa_s, MSG_DEBUG,
9894 "Control interface command '%s [REMOVED]'",
9895 os_strncmp(buf, WPA_CTRL_RSP,
9896 os_strlen(WPA_CTRL_RSP)) == 0 ?
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07009897 WPA_CTRL_RSP :
9898 (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
9899 "SET_NETWORK" : "key-add"));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009900 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
Dmitry Shmidt21de2142014-04-08 10:50:52 -07009901 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009902 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
9903 (const u8 *) buf, os_strlen(buf));
9904 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009905 int level = wpas_ctrl_cmd_debug_level(buf);
Dmitry Shmidtaa532512012-09-24 10:35:31 -07009906 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009907 }
9908
9909 reply = os_malloc(reply_size);
9910 if (reply == NULL) {
9911 *resp_len = 1;
9912 return NULL;
9913 }
9914
9915 os_memcpy(reply, "OK\n", 3);
9916 reply_len = 3;
9917
9918 if (os_strcmp(buf, "PING") == 0) {
9919 os_memcpy(reply, "PONG\n", 5);
9920 reply_len = 5;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07009921 } else if (os_strcmp(buf, "IFNAME") == 0) {
9922 reply_len = os_strlen(wpa_s->ifname);
9923 os_memcpy(reply, wpa_s->ifname, reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009924 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
9925 if (wpa_debug_reopen_file() < 0)
9926 reply_len = -1;
9927 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
9928 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
9929 } else if (os_strcmp(buf, "MIB") == 0) {
9930 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
9931 if (reply_len >= 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009932 reply_len += eapol_sm_get_mib(wpa_s->eapol,
9933 reply + reply_len,
9934 reply_size - reply_len);
Hai Shalom39bc25d2019-02-06 16:32:13 -08009935#ifdef CONFIG_MACSEC
9936 reply_len += ieee802_1x_kay_get_mib(
9937 wpa_s->kay, reply + reply_len,
9938 reply_size - reply_len);
9939#endif /* CONFIG_MACSEC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009940 }
9941 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
9942 reply_len = wpa_supplicant_ctrl_iface_status(
9943 wpa_s, buf + 6, reply, reply_size);
9944 } else if (os_strcmp(buf, "PMKSA") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -07009945 reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009946 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
Dmitry Shmidte4663042016-04-04 10:07:49 -07009947 wpas_ctrl_iface_pmksa_flush(wpa_s);
Dmitry Shmidt29333592017-01-09 12:27:11 -08009948#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9949 } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
9950 reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
9951 reply, reply_size);
9952 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
9953 if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
9954 reply_len = -1;
Paul Stewart092955c2017-02-06 09:13:09 -08009955#ifdef CONFIG_MESH
9956 } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
9957 reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
9958 reply, reply_size);
9959 } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
9960 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
9961 reply_len = -1;
9962#endif /* CONFIG_MESH */
Dmitry Shmidt29333592017-01-09 12:27:11 -08009963#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009964 } else if (os_strncmp(buf, "SET ", 4) == 0) {
9965 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
9966 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08009967 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
9968 reply_len = wpa_config_dump_values(wpa_s->conf,
9969 reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009970 } else if (os_strncmp(buf, "GET ", 4) == 0) {
9971 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
9972 reply, reply_size);
9973 } else if (os_strcmp(buf, "LOGON") == 0) {
9974 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
9975 } else if (os_strcmp(buf, "LOGOFF") == 0) {
9976 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
9977 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
9978 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
9979 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08009980 else
9981 wpas_request_connection(wpa_s);
Dmitry Shmidt98660862014-03-11 17:26:21 -07009982 } else if (os_strcmp(buf, "REATTACH") == 0) {
9983 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
9984 !wpa_s->current_ssid)
9985 reply_len = -1;
9986 else {
9987 wpa_s->reattach = 1;
9988 wpas_request_connection(wpa_s);
9989 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009990 } else if (os_strcmp(buf, "RECONNECT") == 0) {
9991 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
9992 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08009993 else if (wpa_s->disconnected)
9994 wpas_request_connection(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009995#ifdef IEEE8021X_EAPOL
9996 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
9997 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
9998 reply_len = -1;
9999#endif /* IEEE8021X_EAPOL */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010000#ifdef CONFIG_IEEE80211R
10001 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
10002 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
10003 reply_len = -1;
10004#endif /* CONFIG_IEEE80211R */
10005#ifdef CONFIG_WPS
10006 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
10007 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
10008 if (res == -2) {
10009 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10010 reply_len = 17;
10011 } else if (res)
10012 reply_len = -1;
10013 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
10014 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
10015 if (res == -2) {
10016 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10017 reply_len = 17;
10018 } else if (res)
10019 reply_len = -1;
10020 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
10021 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
10022 reply,
10023 reply_size);
10024 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
10025 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
10026 wpa_s, buf + 14, reply, reply_size);
10027 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
10028 if (wpas_wps_cancel(wpa_s))
10029 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010030#ifdef CONFIG_WPS_NFC
10031 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
10032 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
10033 reply_len = -1;
10034 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
10035 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
10036 reply_len = -1;
Dmitry Shmidtf8623282013-02-20 14:34:59 -080010037 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
10038 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
10039 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010040 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
10041 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
10042 wpa_s, buf + 14, reply, reply_size);
10043 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
10044 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
10045 buf + 17))
10046 reply_len = -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010047 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
10048 reply_len = wpas_ctrl_nfc_get_handover_req(
10049 wpa_s, buf + 21, reply, reply_size);
10050 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
10051 reply_len = wpas_ctrl_nfc_get_handover_sel(
10052 wpa_s, buf + 21, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -080010053 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
10054 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
10055 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010056#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010057 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
10058 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
10059 reply_len = -1;
10060#ifdef CONFIG_AP
10061 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
10062 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
10063 wpa_s, buf + 11, reply, reply_size);
10064#endif /* CONFIG_AP */
10065#ifdef CONFIG_WPS_ER
10066 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
10067 if (wpas_wps_er_start(wpa_s, NULL))
10068 reply_len = -1;
10069 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
10070 if (wpas_wps_er_start(wpa_s, buf + 13))
10071 reply_len = -1;
10072 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010073 wpas_wps_er_stop(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010074 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
10075 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
10076 reply_len = -1;
10077 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
10078 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
10079 if (ret == -2) {
10080 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
10081 reply_len = 17;
10082 } else if (ret == -3) {
10083 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
10084 reply_len = 18;
10085 } else if (ret == -4) {
10086 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
10087 reply_len = 20;
10088 } else if (ret)
10089 reply_len = -1;
10090 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
10091 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
10092 reply_len = -1;
10093 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
10094 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
10095 buf + 18))
10096 reply_len = -1;
10097 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
10098 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
10099 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010100#ifdef CONFIG_WPS_NFC
10101 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
10102 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
10103 wpa_s, buf + 24, reply, reply_size);
10104#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010105#endif /* CONFIG_WPS_ER */
10106#endif /* CONFIG_WPS */
10107#ifdef CONFIG_IBSS_RSN
10108 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
10109 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
10110 reply_len = -1;
10111#endif /* CONFIG_IBSS_RSN */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010112#ifdef CONFIG_MESH
10113 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
10114 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10115 wpa_s, buf + 19, reply, reply_size);
10116 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
10117 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
10118 wpa_s, "", reply, reply_size);
10119 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
10120 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
10121 reply_len = -1;
10122 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
10123 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
10124 buf + 18))
10125 reply_len = -1;
Dmitry Shmidte4663042016-04-04 10:07:49 -070010126 } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
10127 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
10128 reply_len = -1;
10129 } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
10130 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
10131 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010132#endif /* CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010133#ifdef CONFIG_P2P
10134 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010135 if (p2p_ctrl_find(wpa_s, buf + 8))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010136 reply_len = -1;
10137 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
10138 if (p2p_ctrl_find(wpa_s, ""))
10139 reply_len = -1;
10140 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
10141 wpas_p2p_stop_find(wpa_s);
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010142 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
10143 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
10144 reply_len = -1;
10145 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
10146 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
10147 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010148 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
10149 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
10150 reply_size);
10151 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
10152 if (p2p_ctrl_listen(wpa_s, buf + 11))
10153 reply_len = -1;
10154 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
10155 if (p2p_ctrl_listen(wpa_s, ""))
10156 reply_len = -1;
10157 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
10158 if (wpas_p2p_group_remove(wpa_s, buf + 17))
10159 reply_len = -1;
10160 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
Dmitry Shmidta3dc3092015-06-23 11:21:28 -070010161 if (p2p_ctrl_group_add(wpa_s, ""))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010162 reply_len = -1;
10163 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
10164 if (p2p_ctrl_group_add(wpa_s, buf + 14))
10165 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010166 } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
10167 reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
10168 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010169 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
10170 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
10171 reply_len = -1;
10172 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
10173 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
10174 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
10175 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
10176 reply_size);
10177 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
10178 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
10179 reply_len = -1;
10180 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
10181 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
10182 reply_len = -1;
10183 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
10184 wpas_p2p_sd_service_update(wpa_s);
10185 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
10186 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
10187 reply_len = -1;
10188 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
10189 wpas_p2p_service_flush(wpa_s);
10190 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
10191 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
10192 reply_len = -1;
10193 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
10194 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
10195 reply_len = -1;
Dmitry Shmidt216983b2015-02-06 10:50:36 -080010196 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
10197 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
10198 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010199 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
10200 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
10201 reply_len = -1;
10202 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
10203 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
10204 reply_len = -1;
10205 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
10206 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
10207 reply_size);
10208 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
10209 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
10210 reply_len = -1;
10211 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
Dmitry Shmidt444d5672013-04-01 13:08:44 -070010212 p2p_ctrl_flush(wpa_s);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010213 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
10214 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
10215 reply_len = -1;
10216 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
10217 if (wpas_p2p_cancel(wpa_s))
10218 reply_len = -1;
10219 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
10220 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
10221 reply_len = -1;
10222 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
10223 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
10224 reply_len = -1;
10225 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
10226 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
10227 reply_len = -1;
10228 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
10229 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
10230 reply_len = -1;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070010231 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
10232 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
10233 reply_len = -1;
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010234 } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
10235 if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
10236 reply_len = -1;
10237 } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
10238 if (wpas_p2p_lo_stop(wpa_s))
10239 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010240#endif /* CONFIG_P2P */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010241#ifdef CONFIG_WIFI_DISPLAY
10242 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
10243 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
10244 reply_len = -1;
10245 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
10246 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
10247 reply, reply_size);
10248#endif /* CONFIG_WIFI_DISPLAY */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010249#ifdef CONFIG_INTERWORKING
10250 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
10251 if (interworking_fetch_anqp(wpa_s) < 0)
10252 reply_len = -1;
10253 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
10254 interworking_stop_fetch_anqp(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010255 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
10256 if (ctrl_interworking_select(wpa_s, NULL) < 0)
10257 reply_len = -1;
10258 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
10259 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010260 reply_len = -1;
10261 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010262 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010263 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010264 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
10265 int id;
10266
10267 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
10268 if (id < 0)
10269 reply_len = -1;
10270 else {
10271 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
10272 if (os_snprintf_error(reply_size, reply_len))
10273 reply_len = -1;
10274 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010275 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
10276 if (get_anqp(wpa_s, buf + 9) < 0)
10277 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070010278 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
10279 if (gas_request(wpa_s, buf + 12) < 0)
10280 reply_len = -1;
10281 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
10282 reply_len = gas_response_get(wpa_s, buf + 17, reply,
10283 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010284#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt04949592012-07-19 12:16:46 -070010285#ifdef CONFIG_HS20
10286 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
10287 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
10288 reply_len = -1;
10289 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
10290 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
10291 reply_len = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010292 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080010293 if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
10294 reply_len = -1;
10295 } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
10296 if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
10297 reply_len = -1;
10298 } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
10299 reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
10300 } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
10301 if (del_hs20_icon(wpa_s, buf + 14) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010302 reply_len = -1;
10303 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010304 if (hs20_fetch_osu(wpa_s, 0) < 0)
10305 reply_len = -1;
10306 } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
10307 if (hs20_fetch_osu(wpa_s, 1) < 0)
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080010308 reply_len = -1;
10309 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
10310 hs20_cancel_fetch_osu(wpa_s);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010311#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010312 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
10313 {
10314 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
10315 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
10316 reply_len = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -070010317 else {
10318 /*
10319 * Notify response from timeout to allow the control
10320 * interface response to be sent first.
10321 */
10322 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
10323 wpa_s, NULL);
10324 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010325 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
10326 if (wpa_supplicant_reload_configuration(wpa_s))
10327 reply_len = -1;
10328 } else if (os_strcmp(buf, "TERMINATE") == 0) {
10329 wpa_supplicant_terminate_proc(wpa_s->global);
10330 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
10331 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
10332 reply_len = -1;
Dmitry Shmidte19501d2011-03-16 14:32:18 -070010333 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010334 reply_len = wpa_supplicant_ctrl_iface_blacklist(
10335 wpa_s, buf + 9, reply, reply_size);
10336 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
10337 reply_len = wpa_supplicant_ctrl_iface_log_level(
10338 wpa_s, buf + 9, reply, reply_size);
Vinit Deshpandeda134e92014-12-02 10:59:29 -080010339 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
10340 reply_len = wpa_supplicant_ctrl_iface_list_networks(
10341 wpa_s, buf + 14, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010342 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
10343 reply_len = wpa_supplicant_ctrl_iface_list_networks(
Vinit Deshpandeda134e92014-12-02 10:59:29 -080010344 wpa_s, NULL, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010345 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -070010346 wpas_request_disconnection(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010347 } else if (os_strcmp(buf, "SCAN") == 0) {
10348 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
10349 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
10350 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010351 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
10352 reply_len = wpa_supplicant_ctrl_iface_scan_results(
10353 wpa_s, reply, reply_size);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010354 } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
10355 if (wpas_abort_ongoing_scan(wpa_s) < 0)
10356 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010357 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
10358 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
10359 reply_len = -1;
10360 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
10361 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
10362 reply_len = -1;
10363 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
10364 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
10365 reply_len = -1;
10366 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
10367 reply_len = wpa_supplicant_ctrl_iface_add_network(
10368 wpa_s, reply, reply_size);
10369 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
10370 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
10371 reply_len = -1;
10372 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
10373 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
10374 reply_len = -1;
10375 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
10376 reply_len = wpa_supplicant_ctrl_iface_get_network(
10377 wpa_s, buf + 12, reply, reply_size);
Dmitry Shmidt684785c2014-05-12 13:34:29 -070010378 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010379 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
10380 wpa_s))
Dmitry Shmidt684785c2014-05-12 13:34:29 -070010381 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -070010382 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
10383 reply_len = wpa_supplicant_ctrl_iface_list_creds(
10384 wpa_s, reply, reply_size);
10385 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
10386 reply_len = wpa_supplicant_ctrl_iface_add_cred(
10387 wpa_s, reply, reply_size);
10388 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
10389 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
10390 reply_len = -1;
10391 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
10392 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
10393 reply_len = -1;
Dmitry Shmidt0cfd5f72014-04-04 14:48:05 -070010394 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
10395 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
10396 reply,
10397 reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010398#ifndef CONFIG_NO_CONFIG_WRITE
10399 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
10400 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
10401 reply_len = -1;
10402#endif /* CONFIG_NO_CONFIG_WRITE */
10403 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
10404 reply_len = wpa_supplicant_ctrl_iface_get_capability(
10405 wpa_s, buf + 15, reply, reply_size);
10406 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
10407 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
10408 reply_len = -1;
10409 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
10410 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
10411 reply_len = -1;
10412 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
10413 reply_len = wpa_supplicant_global_iface_list(
10414 wpa_s->global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010415 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010416 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010417 wpa_s->global, buf + 10, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010418 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
10419 reply_len = wpa_supplicant_ctrl_iface_bss(
10420 wpa_s, buf + 4, reply, reply_size);
10421#ifdef CONFIG_AP
10422 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
10423 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
10424 } else if (os_strncmp(buf, "STA ", 4) == 0) {
10425 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
10426 reply_size);
10427 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
10428 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
10429 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010430 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
10431 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
10432 reply_len = -1;
10433 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
10434 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
10435 reply_len = -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -080010436 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
10437 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
10438 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -080010439 } else if (os_strcmp(buf, "STOP_AP") == 0) {
10440 if (wpas_ap_stop_ap(wpa_s))
10441 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010442#endif /* CONFIG_AP */
10443 } else if (os_strcmp(buf, "SUSPEND") == 0) {
10444 wpas_notify_suspend(wpa_s->global);
10445 } else if (os_strcmp(buf, "RESUME") == 0) {
10446 wpas_notify_resume(wpa_s->global);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010447#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010448 } else if (os_strcmp(buf, "DROP_SA") == 0) {
10449 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
Dmitry Shmidt21de2142014-04-08 10:50:52 -070010450#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010451 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
10452 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
10453 reply_len = -1;
10454 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010455 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010456 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
10457 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
10458 reply_len = -1;
10459 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
10460 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
10461 buf + 17))
10462 reply_len = -1;
Dmitry Shmidtf48e4f92012-08-24 11:14:44 -070010463 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010464 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010465#ifdef CONFIG_TDLS
10466 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
10467 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
10468 reply_len = -1;
10469 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
10470 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
10471 reply_len = -1;
10472 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
10473 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
10474 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010475 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
10476 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
10477 buf + 17))
10478 reply_len = -1;
10479 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
10480 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
10481 buf + 24))
10482 reply_len = -1;
Dmitry Shmidtcc00d5d2015-05-04 10:34:12 -070010483 } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
10484 reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
10485 wpa_s, buf + 17, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010486#endif /* CONFIG_TDLS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010487 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
10488 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
10489 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
10490 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
10491 reply_len = -1;
10492 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
10493 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
10494 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010495 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
10496 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
10497 reply_size);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080010498 } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
10499 if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
10500 reply_len = -1;
Yuhao Zhengfcd6f212012-07-27 10:37:52 -070010501 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
10502 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
10503 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -070010504#ifdef CONFIG_AUTOSCAN
10505 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
10506 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
10507 reply_len = -1;
10508#endif /* CONFIG_AUTOSCAN */
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -070010509 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
10510 reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
10511 reply_size);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080010512#ifdef ANDROID
Dmitry Shmidtbd567ad2011-05-09 14:17:09 -070010513 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
10514 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
10515 reply_size);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -080010516#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -080010517 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
10518 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
10519 reply_size);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010520 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080010521 pmksa_cache_clear_current(wpa_s->wpa);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080010522 eapol_sm_request_reauth(wpa_s->eapol);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080010523#ifdef CONFIG_WNM
10524 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
10525 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
10526 reply_len = -1;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080010527 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
10528 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
Dmitry Shmidt44c95782013-05-17 09:51:35 -070010529 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -080010530 } else if (os_strncmp(buf, "COLOC_INTF_REPORT ", 18) == 0) {
10531 if (wpas_ctrl_iface_coloc_intf_report(wpa_s, buf + 18))
10532 reply_len = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080010533#endif /* CONFIG_WNM */
Dmitry Shmidt444d5672013-04-01 13:08:44 -070010534 } else if (os_strcmp(buf, "FLUSH") == 0) {
10535 wpa_supplicant_ctrl_iface_flush(wpa_s);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080010536 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
10537 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
10538 reply_size);
Dmitry Shmidt818ea482014-03-10 13:15:21 -070010539#ifdef CONFIG_TESTING_OPTIONS
10540 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
10541 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
10542 reply_len = -1;
10543 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
10544 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010545 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
10546 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
10547 reply_len = -1;
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -070010548 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
10549 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
10550 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010551 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
10552 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
10553 reply_len = -1;
10554 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
10555 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
10556 reply_len = -1;
10557 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
10558 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
10559 reply_len = -1;
10560 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
10561 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
10562 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -080010563 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
10564 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
10565 reply_len = -1;
10566 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
10567 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010568 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
10569 if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
10570 reply_len = -1;
10571 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
10572 reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
Jouni Malinenc4818362015-10-04 11:45:13 +030010573 } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
10574 if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
10575 reply_len = -1;
Dmitry Shmidt55840ad2015-12-14 12:45:46 -080010576 } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
10577 if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
10578 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010579 } else if (os_strcmp(buf, "RESET_PN") == 0) {
10580 if (wpas_ctrl_reset_pn(wpa_s) < 0)
10581 reply_len = -1;
10582 } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
10583 if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
10584 reply_len = -1;
10585 } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
10586 if (wpas_ctrl_resend_assoc(wpa_s) < 0)
10587 reply_len = -1;
Hai Shalom39bc25d2019-02-06 16:32:13 -080010588#ifdef CONFIG_IEEE80211W
10589 } else if (os_strcmp(buf, "UNPROT_DEAUTH") == 0) {
10590 sme_event_unprot_disconnect(
10591 wpa_s, wpa_s->bssid, NULL,
10592 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
10593#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt818ea482014-03-10 13:15:21 -070010594#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt2e67f062014-07-16 09:55:28 -070010595 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
10596 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
10597 reply_len = -1;
10598 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
10599 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
10600 reply_size);
10601 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
10602 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
10603 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010604 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
Dmitry Shmidt849734c2016-05-27 09:59:01 -070010605 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010606 reply_len = -1;
10607 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
10608 wpas_ctrl_iface_erp_flush(wpa_s);
10609 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
10610 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
10611 reply_len = -1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080010612 } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
10613 reply_len = wpas_ctrl_iface_get_pref_freq_list(
10614 wpa_s, buf + 19, reply, reply_size);
Paul Stewart092955c2017-02-06 09:13:09 -080010615#ifdef CONFIG_FILS
10616 } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
10617 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
10618 reply_len = -1;
10619 } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
10620 wpas_flush_fils_hlp_req(wpa_s);
10621#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010622#ifdef CONFIG_DPP
10623 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
10624 int res;
10625
10626 res = wpas_dpp_qr_code(wpa_s, buf + 12);
10627 if (res < 0) {
10628 reply_len = -1;
10629 } else {
10630 reply_len = os_snprintf(reply, reply_size, "%d", res);
10631 if (os_snprintf_error(reply_size, reply_len))
10632 reply_len = -1;
10633 }
10634 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
10635 int res;
10636
10637 res = wpas_dpp_bootstrap_gen(wpa_s, buf + 18);
10638 if (res < 0) {
10639 reply_len = -1;
10640 } else {
10641 reply_len = os_snprintf(reply, reply_size, "%d", res);
10642 if (os_snprintf_error(reply_size, reply_len))
10643 reply_len = -1;
10644 }
10645 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
10646 if (wpas_dpp_bootstrap_remove(wpa_s, buf + 21) < 0)
10647 reply_len = -1;
10648 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
10649 const char *uri;
10650
10651 uri = wpas_dpp_bootstrap_get_uri(wpa_s, atoi(buf + 22));
10652 if (!uri) {
10653 reply_len = -1;
10654 } else {
10655 reply_len = os_snprintf(reply, reply_size, "%s", uri);
10656 if (os_snprintf_error(reply_size, reply_len))
10657 reply_len = -1;
10658 }
10659 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
10660 reply_len = wpas_dpp_bootstrap_info(wpa_s, atoi(buf + 19),
10661 reply, reply_size);
10662 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
10663 if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
10664 reply_len = -1;
10665 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
10666 if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
10667 reply_len = -1;
10668 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -070010669 wpas_dpp_stop(wpa_s);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010670 wpas_dpp_listen_stop(wpa_s);
10671 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
10672 int res;
10673
10674 res = wpas_dpp_configurator_add(wpa_s, buf + 20);
10675 if (res < 0) {
10676 reply_len = -1;
10677 } else {
10678 reply_len = os_snprintf(reply, reply_size, "%d", res);
10679 if (os_snprintf_error(reply_size, reply_len))
10680 reply_len = -1;
10681 }
10682 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
10683 if (wpas_dpp_configurator_remove(wpa_s, buf + 24) < 0)
10684 reply_len = -1;
10685 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom39bc25d2019-02-06 16:32:13 -080010686 if (wpas_dpp_configurator_sign(wpa_s, buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010687 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -070010688 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
10689 reply_len = wpas_dpp_configurator_get_key(wpa_s, atoi(buf + 25),
10690 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070010691 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
10692 int res;
10693
10694 res = wpas_dpp_pkex_add(wpa_s, buf + 12);
10695 if (res < 0) {
10696 reply_len = -1;
10697 } else {
10698 reply_len = os_snprintf(reply, reply_size, "%d", res);
10699 if (os_snprintf_error(reply_size, reply_len))
10700 reply_len = -1;
10701 }
10702 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
10703 if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
10704 reply_len = -1;
10705#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010706 } else {
10707 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
10708 reply_len = 16;
10709 }
10710
10711 if (reply_len < 0) {
10712 os_memcpy(reply, "FAIL\n", 5);
10713 reply_len = 5;
10714 }
10715
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010716 *resp_len = reply_len;
10717 return reply;
10718}
10719
10720
10721static int wpa_supplicant_global_iface_add(struct wpa_global *global,
10722 char *cmd)
10723{
10724 struct wpa_interface iface;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010725 char *pos, *extra;
10726 struct wpa_supplicant *wpa_s;
10727 unsigned int create_iface = 0;
10728 u8 mac_addr[ETH_ALEN];
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010729 enum wpa_driver_if_type type = WPA_IF_STATION;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010730
10731 /*
10732 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010733 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010734 */
10735 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
10736
10737 os_memset(&iface, 0, sizeof(iface));
10738
10739 do {
10740 iface.ifname = pos = cmd;
10741 pos = os_strchr(pos, '\t');
10742 if (pos)
10743 *pos++ = '\0';
10744 if (iface.ifname[0] == '\0')
10745 return -1;
10746 if (pos == NULL)
10747 break;
10748
10749 iface.confname = pos;
10750 pos = os_strchr(pos, '\t');
10751 if (pos)
10752 *pos++ = '\0';
10753 if (iface.confname[0] == '\0')
10754 iface.confname = NULL;
10755 if (pos == NULL)
10756 break;
10757
10758 iface.driver = pos;
10759 pos = os_strchr(pos, '\t');
10760 if (pos)
10761 *pos++ = '\0';
10762 if (iface.driver[0] == '\0')
10763 iface.driver = NULL;
10764 if (pos == NULL)
10765 break;
10766
10767 iface.ctrl_interface = pos;
10768 pos = os_strchr(pos, '\t');
10769 if (pos)
10770 *pos++ = '\0';
10771 if (iface.ctrl_interface[0] == '\0')
10772 iface.ctrl_interface = NULL;
10773 if (pos == NULL)
10774 break;
10775
10776 iface.driver_param = pos;
10777 pos = os_strchr(pos, '\t');
10778 if (pos)
10779 *pos++ = '\0';
10780 if (iface.driver_param[0] == '\0')
10781 iface.driver_param = NULL;
10782 if (pos == NULL)
10783 break;
10784
10785 iface.bridge_ifname = pos;
10786 pos = os_strchr(pos, '\t');
10787 if (pos)
10788 *pos++ = '\0';
10789 if (iface.bridge_ifname[0] == '\0')
10790 iface.bridge_ifname = NULL;
10791 if (pos == NULL)
10792 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010793
10794 extra = pos;
10795 pos = os_strchr(pos, '\t');
10796 if (pos)
10797 *pos++ = '\0';
Dmitry Shmidt83474442015-04-15 13:47:09 -070010798 if (!extra[0])
10799 break;
10800
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010801 if (os_strcmp(extra, "create") == 0) {
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010802 create_iface = 1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010803 if (!pos)
10804 break;
10805
10806 if (os_strcmp(pos, "sta") == 0) {
10807 type = WPA_IF_STATION;
10808 } else if (os_strcmp(pos, "ap") == 0) {
10809 type = WPA_IF_AP_BSS;
10810 } else {
10811 wpa_printf(MSG_DEBUG,
10812 "INTERFACE_ADD unsupported interface type: '%s'",
10813 pos);
10814 return -1;
10815 }
10816 } else {
Dmitry Shmidt83474442015-04-15 13:47:09 -070010817 wpa_printf(MSG_DEBUG,
10818 "INTERFACE_ADD unsupported extra parameter: '%s'",
10819 extra);
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010820 return -1;
Dmitry Shmidt83474442015-04-15 13:47:09 -070010821 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010822 } while (0);
10823
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010824 if (create_iface) {
10825 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
10826 iface.ifname);
10827 if (!global->ifaces)
10828 return -1;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080010829 if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010830 NULL, NULL, NULL, mac_addr, NULL) < 0) {
10831 wpa_printf(MSG_ERROR,
10832 "CTRL_IFACE interface creation failed");
10833 return -1;
10834 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010835
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010836 wpa_printf(MSG_DEBUG,
10837 "CTRL_IFACE interface '%s' created with MAC addr: "
10838 MACSTR, iface.ifname, MAC2STR(mac_addr));
10839 }
10840
10841 if (wpa_supplicant_get_iface(global, iface.ifname))
10842 goto fail;
10843
10844 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
10845 if (!wpa_s)
10846 goto fail;
10847 wpa_s->added_vif = create_iface;
10848 return 0;
10849
10850fail:
10851 if (create_iface)
10852 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
10853 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010854}
10855
10856
10857static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
10858 char *cmd)
10859{
10860 struct wpa_supplicant *wpa_s;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010861 int ret;
10862 unsigned int delete_iface;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010863
10864 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
10865
10866 wpa_s = wpa_supplicant_get_iface(global, cmd);
10867 if (wpa_s == NULL)
10868 return -1;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -070010869 delete_iface = wpa_s->added_vif;
10870 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
10871 if (!ret && delete_iface) {
10872 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
10873 cmd);
10874 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
10875 }
10876 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010877}
10878
10879
10880static void wpa_free_iface_info(struct wpa_interface_info *iface)
10881{
10882 struct wpa_interface_info *prev;
10883
10884 while (iface) {
10885 prev = iface;
10886 iface = iface->next;
10887
10888 os_free(prev->ifname);
10889 os_free(prev->desc);
10890 os_free(prev);
10891 }
10892}
10893
10894
10895static int wpa_supplicant_global_iface_list(struct wpa_global *global,
10896 char *buf, int len)
10897{
10898 int i, res;
10899 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
10900 char *pos, *end;
10901
10902 for (i = 0; wpa_drivers[i]; i++) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -070010903 const struct wpa_driver_ops *drv = wpa_drivers[i];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010904 if (drv->get_interfaces == NULL)
10905 continue;
10906 tmp = drv->get_interfaces(global->drv_priv[i]);
10907 if (tmp == NULL)
10908 continue;
10909
10910 if (last == NULL)
10911 iface = last = tmp;
10912 else
10913 last->next = tmp;
10914 while (last->next)
10915 last = last->next;
10916 }
10917
10918 pos = buf;
10919 end = buf + len;
10920 for (tmp = iface; tmp; tmp = tmp->next) {
10921 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
10922 tmp->drv_name, tmp->ifname,
10923 tmp->desc ? tmp->desc : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010924 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010925 *pos = '\0';
10926 break;
10927 }
10928 pos += res;
10929 }
10930
10931 wpa_free_iface_info(iface);
10932
10933 return pos - buf;
10934}
10935
10936
10937static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010938 const char *input,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010939 char *buf, int len)
10940{
10941 int res;
10942 char *pos, *end;
10943 struct wpa_supplicant *wpa_s;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010944 int show_ctrl = 0;
10945
10946 if (input)
10947 show_ctrl = !!os_strstr(input, "ctrl");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010948
10949 wpa_s = global->ifaces;
10950 pos = buf;
10951 end = buf + len;
10952
10953 while (wpa_s) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080010954 if (show_ctrl)
10955 res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
10956 wpa_s->ifname,
10957 wpa_s->conf->ctrl_interface ?
10958 wpa_s->conf->ctrl_interface : "N/A");
10959 else
10960 res = os_snprintf(pos, end - pos, "%s\n",
10961 wpa_s->ifname);
10962
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080010963 if (os_snprintf_error(end - pos, res)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070010964 *pos = '\0';
10965 break;
10966 }
10967 pos += res;
10968 wpa_s = wpa_s->next;
10969 }
10970 return pos - buf;
10971}
10972
10973
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070010974static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
10975 const char *ifname,
10976 char *cmd, size_t *resp_len)
10977{
10978 struct wpa_supplicant *wpa_s;
10979
10980 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
10981 if (os_strcmp(ifname, wpa_s->ifname) == 0)
10982 break;
10983 }
10984
10985 if (wpa_s == NULL) {
10986 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
10987 if (resp)
10988 *resp_len = os_strlen(resp);
10989 else
10990 *resp_len = 1;
10991 return resp;
10992 }
10993
10994 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
10995}
10996
10997
10998static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
10999 char *buf, size_t *resp_len)
11000{
11001#ifdef CONFIG_P2P
11002 static const char * cmd[] = {
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011003 "LIST_NETWORKS",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011004 "P2P_FIND",
11005 "P2P_STOP_FIND",
11006 "P2P_LISTEN",
11007 "P2P_GROUP_ADD",
11008 "P2P_GET_PASSPHRASE",
11009 "P2P_SERVICE_UPDATE",
11010 "P2P_SERVICE_FLUSH",
11011 "P2P_FLUSH",
11012 "P2P_CANCEL",
11013 "P2P_PRESENCE_REQ",
11014 "P2P_EXT_LISTEN",
Paul Stewart092955c2017-02-06 09:13:09 -080011015#ifdef CONFIG_AP
11016 "STA-FIRST",
11017#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011018 NULL
11019 };
11020 static const char * prefix[] = {
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080011021#ifdef ANDROID
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011022 "DRIVER ",
Dmitry Shmidt9e3f8ee2014-01-17 10:52:01 -080011023#endif /* ANDROID */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070011024 "GET_CAPABILITY ",
Dmitry Shmidt0c18dcd2013-08-16 15:29:47 -070011025 "GET_NETWORK ",
11026 "REMOVE_NETWORK ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011027 "P2P_FIND ",
11028 "P2P_CONNECT ",
11029 "P2P_LISTEN ",
11030 "P2P_GROUP_REMOVE ",
11031 "P2P_GROUP_ADD ",
Dmitry Shmidt849734c2016-05-27 09:59:01 -070011032 "P2P_GROUP_MEMBER ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011033 "P2P_PROV_DISC ",
11034 "P2P_SERV_DISC_REQ ",
11035 "P2P_SERV_DISC_CANCEL_REQ ",
11036 "P2P_SERV_DISC_RESP ",
11037 "P2P_SERV_DISC_EXTERNAL ",
11038 "P2P_SERVICE_ADD ",
11039 "P2P_SERVICE_DEL ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011040 "P2P_SERVICE_REP ",
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011041 "P2P_REJECT ",
11042 "P2P_INVITE ",
11043 "P2P_PEER ",
11044 "P2P_SET ",
11045 "P2P_UNAUTHORIZE ",
11046 "P2P_PRESENCE_REQ ",
11047 "P2P_EXT_LISTEN ",
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070011048 "P2P_REMOVE_CLIENT ",
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080011049 "WPS_NFC_TOKEN ",
11050 "WPS_NFC_TAG_READ ",
Dmitry Shmidt413dde72014-04-11 10:23:22 -070011051 "NFC_GET_HANDOVER_SEL ",
11052 "NFC_GET_HANDOVER_REQ ",
11053 "NFC_REPORT_HANDOVER ",
Dmitry Shmidt216983b2015-02-06 10:50:36 -080011054 "P2P_ASP_PROVISION ",
11055 "P2P_ASP_PROVISION_RESP ",
Paul Stewart092955c2017-02-06 09:13:09 -080011056#ifdef CONFIG_AP
11057 "STA ",
11058 "STA-NEXT ",
11059#endif /* CONFIG_AP */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011060 NULL
11061 };
11062 int found = 0;
11063 int i;
11064
11065 if (global->p2p_init_wpa_s == NULL)
11066 return NULL;
11067
11068 for (i = 0; !found && cmd[i]; i++) {
11069 if (os_strcmp(buf, cmd[i]) == 0)
11070 found = 1;
11071 }
11072
11073 for (i = 0; !found && prefix[i]; i++) {
11074 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
11075 found = 1;
11076 }
11077
11078 if (found)
11079 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11080 buf, resp_len);
11081#endif /* CONFIG_P2P */
11082 return NULL;
11083}
11084
11085
11086static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
11087 char *buf, size_t *resp_len)
11088{
11089#ifdef CONFIG_WIFI_DISPLAY
11090 if (global->p2p_init_wpa_s == NULL)
11091 return NULL;
11092 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
11093 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
11094 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
11095 buf, resp_len);
11096#endif /* CONFIG_WIFI_DISPLAY */
11097 return NULL;
11098}
11099
11100
11101static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
11102 char *buf, size_t *resp_len)
11103{
11104 char *ret;
11105
11106 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
11107 if (ret)
11108 return ret;
11109
11110 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
11111 if (ret)
11112 return ret;
11113
11114 return NULL;
11115}
11116
11117
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011118static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
11119{
11120 char *value;
11121
11122 value = os_strchr(cmd, ' ');
11123 if (value == NULL)
11124 return -1;
11125 *value++ = '\0';
11126
11127 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
11128
11129#ifdef CONFIG_WIFI_DISPLAY
11130 if (os_strcasecmp(cmd, "wifi_display") == 0) {
11131 wifi_display_enable(global, !!atoi(value));
11132 return 0;
11133 }
11134#endif /* CONFIG_WIFI_DISPLAY */
11135
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011136 /* Restore cmd to its original value to allow redirection */
11137 value[-1] = ' ';
11138
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011139 return -1;
11140}
11141
11142
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011143static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
11144 char *cmd)
11145{
11146 struct wpa_supplicant *wpa_s[2]; /* src, dst */
11147 char *p;
11148 unsigned int i;
11149
11150 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
11151 * <variable name> */
11152
11153 for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
11154 p = os_strchr(cmd, ' ');
11155 if (p == NULL)
11156 return -1;
11157 *p = '\0';
11158
11159 wpa_s[i] = global->ifaces;
11160 for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
11161 if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
11162 break;
11163 }
11164
11165 if (!wpa_s[i]) {
11166 wpa_printf(MSG_DEBUG,
11167 "CTRL_IFACE: Could not find iface=%s", cmd);
11168 return -1;
11169 }
11170
11171 cmd = p + 1;
11172 }
11173
11174 return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
11175}
11176
11177
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011178#ifndef CONFIG_NO_CONFIG_WRITE
11179static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
11180{
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011181 int ret = 0, saved = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011182 struct wpa_supplicant *wpa_s;
11183
11184 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11185 if (!wpa_s->conf->update_config) {
11186 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
11187 continue;
11188 }
11189
11190 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
11191 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
11192 ret = 1;
11193 } else {
11194 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011195 saved++;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011196 }
11197 }
11198
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011199 if (!saved && !ret) {
11200 wpa_dbg(wpa_s, MSG_DEBUG,
11201 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
11202 ret = 1;
11203 }
11204
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011205 return ret;
11206}
11207#endif /* CONFIG_NO_CONFIG_WRITE */
11208
11209
11210static int wpas_global_ctrl_iface_status(struct wpa_global *global,
11211 char *buf, size_t buflen)
11212{
11213 char *pos, *end;
11214 int ret;
11215 struct wpa_supplicant *wpa_s;
11216
11217 pos = buf;
11218 end = buf + buflen;
11219
11220#ifdef CONFIG_P2P
11221 if (global->p2p && !global->p2p_disabled) {
11222 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
11223 "\n"
11224 "p2p_state=%s\n",
11225 MAC2STR(global->p2p_dev_addr),
11226 p2p_get_state_txt(global->p2p));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011227 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011228 return pos - buf;
11229 pos += ret;
11230 } else if (global->p2p) {
11231 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011232 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011233 return pos - buf;
11234 pos += ret;
11235 }
11236#endif /* CONFIG_P2P */
11237
11238#ifdef CONFIG_WIFI_DISPLAY
11239 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
11240 !!global->wifi_display);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011241 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011242 return pos - buf;
11243 pos += ret;
11244#endif /* CONFIG_WIFI_DISPLAY */
11245
11246 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
11247 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
11248 "address=" MACSTR "\n",
11249 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011250 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011251 return pos - buf;
11252 pos += ret;
11253 }
11254
11255 return pos - buf;
11256}
11257
11258
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011259#ifdef CONFIG_FST
11260
11261static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
11262 char *cmd, char *buf,
11263 size_t reply_size)
11264{
11265 char ifname[IFNAMSIZ + 1];
11266 struct fst_iface_cfg cfg;
11267 struct wpa_supplicant *wpa_s;
11268 struct fst_wpa_obj iface_obj;
11269
11270 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
11271 wpa_s = wpa_supplicant_get_iface(global, ifname);
11272 if (wpa_s) {
11273 if (wpa_s->fst) {
11274 wpa_printf(MSG_INFO, "FST: Already attached");
11275 return -1;
11276 }
11277 fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
11278 wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
11279 &iface_obj, &cfg);
11280 if (wpa_s->fst)
11281 return os_snprintf(buf, reply_size, "OK\n");
11282 }
11283 }
11284
11285 return -1;
11286}
11287
11288
11289static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
11290 char *cmd, char *buf,
11291 size_t reply_size)
11292{
11293 char ifname[IFNAMSIZ + 1];
11294 struct wpa_supplicant *wpa_s;
11295
11296 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
11297 wpa_s = wpa_supplicant_get_iface(global, ifname);
11298 if (wpa_s) {
11299 if (!fst_iface_detach(ifname)) {
11300 wpa_s->fst = NULL;
11301 return os_snprintf(buf, reply_size, "OK\n");
11302 }
11303 }
11304 }
11305
11306 return -1;
11307}
11308
11309#endif /* CONFIG_FST */
11310
11311
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011312char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
11313 char *buf, size_t *resp_len)
11314{
11315 char *reply;
11316 const int reply_size = 2048;
11317 int reply_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011318 int level = MSG_DEBUG;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011319
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -070011320 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
11321 char *pos = os_strchr(buf + 7, ' ');
11322 if (pos) {
11323 *pos++ = '\0';
11324 return wpas_global_ctrl_iface_ifname(global,
11325 buf + 7, pos,
11326 resp_len);
11327 }
11328 }
11329
11330 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
11331 if (reply)
11332 return reply;
11333
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080011334 if (os_strcmp(buf, "PING") == 0)
11335 level = MSG_EXCESSIVE;
11336 wpa_hexdump_ascii(level, "RX global ctrl_iface",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011337 (const u8 *) buf, os_strlen(buf));
11338
11339 reply = os_malloc(reply_size);
11340 if (reply == NULL) {
11341 *resp_len = 1;
11342 return NULL;
11343 }
11344
11345 os_memcpy(reply, "OK\n", 3);
11346 reply_len = 3;
11347
11348 if (os_strcmp(buf, "PING") == 0) {
11349 os_memcpy(reply, "PONG\n", 5);
11350 reply_len = 5;
11351 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
11352 if (wpa_supplicant_global_iface_add(global, buf + 14))
11353 reply_len = -1;
11354 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
11355 if (wpa_supplicant_global_iface_remove(global, buf + 17))
11356 reply_len = -1;
11357 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
11358 reply_len = wpa_supplicant_global_iface_list(
11359 global, reply, reply_size);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011360 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011361 reply_len = wpa_supplicant_global_iface_interfaces(
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080011362 global, buf + 10, reply, reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011363#ifdef CONFIG_FST
11364 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
11365 reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
11366 reply,
11367 reply_size);
11368 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
11369 reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
11370 reply,
11371 reply_size);
11372 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
11373 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
11374#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011375 } else if (os_strcmp(buf, "TERMINATE") == 0) {
11376 wpa_supplicant_terminate_proc(global);
11377 } else if (os_strcmp(buf, "SUSPEND") == 0) {
11378 wpas_notify_suspend(global);
11379 } else if (os_strcmp(buf, "RESUME") == 0) {
11380 wpas_notify_resume(global);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011381 } else if (os_strncmp(buf, "SET ", 4) == 0) {
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011382 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
11383#ifdef CONFIG_P2P
11384 if (global->p2p_init_wpa_s) {
11385 os_free(reply);
11386 /* Check if P2P redirection would work for this
11387 * command. */
11388 return wpa_supplicant_ctrl_iface_process(
11389 global->p2p_init_wpa_s,
11390 buf, resp_len);
11391 }
11392#endif /* CONFIG_P2P */
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011393 reply_len = -1;
Dmitry Shmidt61593f02014-04-21 16:27:35 -070011394 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080011395 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
11396 if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
11397 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070011398#ifndef CONFIG_NO_CONFIG_WRITE
11399 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
11400 if (wpas_global_ctrl_iface_save_config(global))
11401 reply_len = -1;
11402#endif /* CONFIG_NO_CONFIG_WRITE */
11403 } else if (os_strcmp(buf, "STATUS") == 0) {
11404 reply_len = wpas_global_ctrl_iface_status(global, reply,
11405 reply_size);
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080011406#ifdef CONFIG_MODULE_TESTS
11407 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -080011408 if (wpas_module_tests() < 0)
11409 reply_len = -1;
11410#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080011411 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
11412 if (wpa_debug_reopen_file() < 0)
11413 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011414 } else {
11415 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
11416 reply_len = 16;
11417 }
11418
11419 if (reply_len < 0) {
11420 os_memcpy(reply, "FAIL\n", 5);
11421 reply_len = 5;
11422 }
11423
11424 *resp_len = reply_len;
11425 return reply;
11426}